Fix: Don't terraform during town generation #8483
Conversation
Prevent rare occurrences of roads and houses being flooded, resulting in disconnected towns.
Wouldn't be better just don't allow to town to build on sea level? I don't know how it affects the growing of town, but for me it doesn't feel like the right approach to disable the whole terraforming because it can occurs 3 times in the case of 12k towns. |
I believe this is probably the wrong fix. A town that has elements at sea level can still flood itself by lowering terrain into the ocean outside of world-generation, so it doesn't fully fix the reported issue, while also being massive overkill. Prevent terraforming of tiles only at sea level, but regardless of worldgen? |
A few observations:
All in all, you managed to fix your use-case, but disregarded any other use-case out there ;) I am pretty sure this PR makes things worse, not better. To put it in numbers: it made 12k out of 12k towns look worse, while fixing 3 out of 12k towns. Pretty sure that is the wrong balance ;) I think the suggestions given in this PR are solid: prevent towns from terraforming below sea-level sounds like a more robust and "this doesn't brake most cases" kind of solution :) I am going to close this PR now, just to close this chapter. Please feel free to create a new PR with a more robust solution; and please take the time to test other use-cases :) Tnx! |
Prevent rare occurrences of roads and houses being flooded, resulting in disconnected towns.
Motivation / Problem
During world generation, town growth algorithm is speed up, allowing the town to perform multiple sequential growth actions, like building houses, roads, and terraforming. If it happens to lower terrain adjacent to sea and then in one of those sequences it builds a road or a house there, it will end up flooded during the "run tile loop" phase of world generation.
The result could be similar to what the screenshot shows: disconnected roads and/or houses.
Description
Bug is solved by preventing towns to terraform during world generation. There is already code preventing town terraforming during world generation like shown below, but this one went missing.
Line 930:
OpenTTD/src/town_cmd.cpp
Lines 930 to 934 in 126f40e
Limitations
This happens very rarely. I tried 12k towns 4096x4096 map, and detected no more than 3 flooded road or house tiles.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.