FS#5377 - AITile.IsRiverTile() need and AITile.IsBuildable change to add !AITile.IsRiverTile condition

Attached to Project: OpenTTD
Opened by pagnon stephane (krinn) - Saturday, 01 December 2012, 03:07 GMT
Last edited by andythenorth (andythenorth) - Saturday, 02 September 2017, 12:12 GMT
Type Feature Request
Category Script
Status With patch
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version other
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


We cannot detect river tiles, currently openttd consider them a bit like roads, could be destroy, but cannot built on them until you removed them.

But noai/nogo API doesn't consider rivers at all. So we need AITile.IsRiverTile to detect them and AITile.IsBuildable should also be change to not return true for river tiles.
And because it wouldn't be fun if it was too easy, many functions should have a better error handling for rivers failure, AIAirport.BuildAirport return ERR_TUNNEL_CANNOT_BUILD_ON_WATER error, i suppose an ERR_CANNOT_BUILD_ON_WATER or ERR_AREA_NOT_CLEAR should be somehow a better error to return.

I'm using 1.2.1 still so maybe it has been changed for AITile.IsBuildable already, but i don't see a way to test for river tiles in trunk noai doc, except using tricky tests with AITestMode

This task depends upon

Comment by pagnon stephane (krinn) - Tuesday, 04 December 2012, 21:25 GMT
Here a patch that will :
- Add (AI/GS)Tile.IsRiverTile(tile)
- Add BT_CLEAR_RIVER to AI/GS enum BuildType
- Modify (AI/GS)Tile.GetBuildCost() to answer cost to remove a river tile
- Add AITile.GetBuildCost(AITile.BT_CLEAR_RIVER) to regression.nut : i didn't add the regression test against a tile to check river, because the regression.sav file didn't have any river to test against, and i assume it was over me to modify the testing savegame.

Better get review twice time by someone who knows openttd source, c++ and squirrel (hehe someone not as me so).
   diff.txt (1.6 KiB)
Comment by frosch (frosch) - Tuesday, 04 December 2012, 22:22 GMT
Please always create unified diff (using "diff -u").
Comment by pagnon stephane (krinn) - Tuesday, 04 December 2012, 23:56 GMT
here comes (sorry)