New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature : New Trees Placement Algorithm "Forest". #6848
Conversation
Without looking at the actual code, a couple of things are immediately obvious:
See CONTRIBUTING.md for more details |
Thanks very much! I'd recommend using rebase to squash everything together - the build system will have a go at building it then, once it's happy with the commit messages! I'm not sure about that last commit, the one about docker complaining about lack of newline at EoL - the git diff looks much like you've removed them rather than added them. Regardless, try not to touch stuff that's unrelated to the PR |
Hello LordAro,
But there is still an issue with docker. `[commit-checker] Running shell script
|
Weird. Regardless, if you rebase your PR (something like |
Well, I really Don't understand how to do. |
Yeah, you're rewriting the commit history, so you'll need to "force-push" when pushing to a remote - just add -f to the command |
Oh, ok. |
Update: Translations from eints
src/tree_cmd.cpp
Outdated
@@ -305,6 +333,7 @@ void GenerateTrees() | |||
|
|||
switch (_settings_game.game_creation.tree_placer) { | |||
case TP_ORIGINAL: i = _settings_game.game_creation.landscape == LT_ARCTIC ? 15 : 6; break; | |||
case TP_FOREST: /* FALL THROUGH */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a proper macro for this now (FALLTHROUGH
), to take advantage of some C++17 stuff if supported.
In general, you shouldn't have merges in PRs. We will always squash or rebase a PR anyway to keep a linear history. A merge only complicates reviewing as it can make the changes less clear and harder to check if the resulting rebase/squash will result in a working state. GitHub checks for conflicts, but this is is invariably only a textual check and not a logical one. |
Hello michicc, I Added the FALLTHROUGH macro instead of the comment. |
Those screenshots makes it look a bit strange, forests forming in perfect rectangles. The rest of the land also looks unnecessarily barren. Can I suggest adding some more fuzziness so forest spread can be more uneven, and also have a minimal chance trees can spring up in the middle of nowhere to jumpstart new forests occasionally? |
Hi Sylvain! Thanks for this, trees do need some love. I'm not a core dev, but I tested your PR, and here are my observations :)
I hope you can keep contributing and the end result is nicer trees for the game! |
Hello andythenorth and nielsmh, Thank you for your feedback. I agree "Improved" and "Forest" are quite confusing. So I updated the "Improved" feature instead of creating a new one. From my point of view, the initial "Improved" and "Original" features were not making big difference as the trees were planted on all tiles of the map after a few décades. So I changed this:
As a result, you can see now a few trees appearing in meadows, but they won't spread to cover the whole map. For the diamond aspect of forests, if you look closely to the original "improved" forests, you'll see they were already diamonds. It was less ugly as there were also many random trees everywhere, so the forests limits were not much visible. The problem is located in the function PlaceTreeGroups that I didn't changed. It chooses a tile, then plant many trees arround, but there is no "shape", so the result produces a square. |
I added some randomness to the forest tree placement. It looks like to produce something better. |
src/table/settings.ini
Outdated
@@ -2216,7 +2216,7 @@ from = 30 | |||
guiflags = SGF_MULTISTRING | SGF_NEWGAME_ONLY | SGF_SCENEDIT_TOO | |||
def = 2 | |||
min = 0 | |||
max = 2 | |||
max = 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this is a remainder of a past version now? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you happen to have a screenshot how the latest result looks? :D
src/tree_cmd.cpp
Outdated
@@ -193,11 +220,16 @@ static void PlaceTreeGroups(uint num_groups) | |||
int x = GB(r, 0, 5) - 16; | |||
int y = GB(r, 8, 5) - 16; | |||
uint dist = abs(x) + abs(y); | |||
uint max_dist = (_settings_newgame.game_creation.tree_placer == TP_IMPROVED) ? GB(r, 0, 3) + 8 : MAX_DISTANCE_FROM_CENTER; | |||
|
|||
if (dist > max_dist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please either put this on a single line, or add {} around it. This form only leads to errors over time :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I splitted this line, now it's more clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think TrueBrain meant the coding style for the if
. Either make it a single line without any linebreaks, or use {}
.
Codechange: Added some alone trees during generation. Codechange: Added some randomness to the tree placement distance around forests.
Looks better to me. What's it like in sub-tropic and arctic climates? Sub-tropic has extra complication, no trees in desert :) |
src/tree_cmd.cpp
Outdated
uint max_dist = MAX_DISTANCE_FROM_CENTER; | ||
|
||
if (_settings_newgame.game_creation.tree_placer == TP_IMPROVED) | ||
max_dist = GB(r, 16, 3) + 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly what @michicc said; coding style, please never put a if statement with a single line body over two lines without {}. So either:
if (_settings_newgame.game_creation.tree_placer == TP_IMPROVED) max_dist = GB(r, 16, 3) + 8;
or
if (_settings_newgame.game_creation.tree_placer == TP_IMPROVED) {
max_dist = GB(r, 16, 3) + 8;
}
Same goes for the line below :)
This to prevent future errors, where someone mistakes the indentation for a start of a new scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok, got it!
Thx ;) I tested this some more. I think the game is now not replacing trees that have died. I tested this by running the game on fast forward for a while. On my test map, most of the trees were gone (and not replaced) after about 50 years, with no replacements. I didn't screenshot before/after, but I can run this again if that helps. |
@andythenorth is there a way to "really fast forward" a game ? When running in fast mode, one year still takes several minutes so it's very hard to check the effects of the patch on the long term |
Integrate the frame rate window changes that were merged a few days ago and check why it's running slow :) |
As nielsm mentioned, I place the view in a corner of the map. I also disable 'full animation' as it slows fast-forward on some platforms. I also close all game windows (minimap etc). It took around 10 minutes to run 50 years for me. |
… on their own tile.
Here is a quick fix for the "alone" tree disapearing. |
I've tested this again.
Is this better than trunk 'improved' algorithm?
|
We recently switched from Jenkins as CI to Azure Pipelines as CI. This means you need to rebase before this Pull Request will pass its checks. Sorry for the troubles! |
Thanks for this. There's been no activity on this for some time, and as it stands, it doesn't look likely that it will go any further. I'm closing it as we try to keep the open PR count low for OpenTTD, it helps us focus on things that are important and fun. Feel free to discuss in irc or request re-opening if you disagree. Thanks for contributing! |
It creates new trees only in existing forest, preserving meadows.