OpenTTD icon indicating copy to clipboard operation
OpenTTD copied to clipboard

Fix: Don't allow towns to terraform certain floodable tiles

Open SamuXarick opened this issue 5 years ago • 3 comments

Motivation / Problem

road and house flooded 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')

SamuXarick avatar Jan 03 '21 22:01 SamuXarick

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 avatar Jun 12 '22 15:06 SamuXarick

@SamuXarick You mentioned on Discord that this may have been broken by my fix to wide river terraforming. Is this ready for review?

2TallTyler avatar Dec 28 '22 20:12 2TallTyler

This is ready for review, but... Wide river generator needs to water the tiles that terraform left behind for my fix to work properly.

SamuXarick avatar Jan 13 '23 23:01 SamuXarick