Fix: Don't allow towns to terraform certain floodable tiles
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.
This happens very rarely. I tried 12k towns 4096x4096 map, and detected no more than 3 flooded road or house tiles.
Description
Prevent rare occurrences of roads and houses being flooded, resulting in disconnected towns.
If the terraform command finds a certain floodable tile, the terraform fails. This works even for a sequence of commands during town generation. So far, the tests have not yet produced any flooded houses or roads.
Limitations
Void tiles were a problem. Terraform command ignores them. If the town terraformed one of the tiles at the edges of the map, there was no checking happening for the void tiles, and it could result in a flood coming in the direction of the void tile. I added checks coming from the edge tiles. Terraform command shall fail if the resulting slope on an edge tile is flat and has a height of zero.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.
- The bug fix is important enough to be backported? (label: 'backport requested')
- This PR affects the save game format? (label 'savegame upgrade')
- This PR affects the GS/AI API? (label 'needs review: Script API')
- ai_changelog.hpp, gs_changelog.hpp need updating.
- The compatibility wrappers (compat_*.nut) need updating.
- This PR affects the NewGRF API? (label 'needs review: NewGRF')
You can use this commit https://github.com/SamuXarick/OpenTTD/commit/39390976e1d408fa94900a682ffdfb761718440a for debugging purposes, to check the existance of flooded tiles after a world is generated.
@SamuXarick You mentioned on Discord that this may have been broken by my fix to wide river terraforming. Is this ready for review?
This is ready for review, but... Wide river generator needs to water the tiles that terraform left behind for my fix to work properly.