Skip to content
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

Allow scripts to check for river tiles #5377 #6751

Closed
wants to merge 2 commits into from

Conversation

Leffe108
Copy link
Contributor

Adds these two methods for AIs and Game Scripts

  • ScriptTile::IsRiverTile(tile): Checks if a tile is a river
  • ScriptTile::GetBuildCost(ScriptTile.BT_CLEAR_RIVER): Provides the cost to demolish a river tile.

Based on FlySpray patch by krinn (#5377)

@Leffe108
Copy link
Contributor Author

I forgot to add to src/script/api/ai_changelog.hpp and src/script/api/game_changelog.hpp. I'll fix that.

@frosch123
Copy link
Member

ScriptTile::IsWaterTile seems to return true for sea, canal and river.
The new ScriptTile::IsRiverTile return true for river.

What is so special about rivers, that they need a specific check, while sea and canal do not?

Same question holds for GetBuildCost()

@LordAro
Copy link
Member

LordAro commented Apr 27, 2018

Maybe an API change - GetWaterTile that returns none, sea, canal or river ?

@Leffe108
Copy link
Contributor Author

I don't know the reasoning why you need only this but not IsCanalTile. Both river and canal share the property that it can be deleted. For a path finder it may be useful to get to know of both canal and river tiles if you like to destroy them. If you want to bridge, then the IsWaterTile should probably be sufficient.

The PR is based on a patch that seemed valid, but I don't know all the details of the use case that caused it to be written.

@frosch123
Copy link
Member

frosch123 commented Apr 28, 2018

Apparently there is ScriptMarine::IsCanalTile.

Suggestion:

  • Add ScriptTile::IsRiverTile, ScriptTile::IsSeaTile
  • Add ScriptTile.BT_CLEAR_RIVER, ScriptTile.BT_CLEAR_SEA

Ideally the docs should link between them :)

@frosch123
Copy link
Member

Closed until there is an usecase.

@SamuXarick
Copy link
Contributor

SamuXarick commented Mar 7, 2020

It's still possible to properly detect a river tile with the current API, but it required me to read OpenTTD source to understand how the functions do their things.

function IsRiverTile(tile)
{
    if (!AITile.IsWaterTile(tile)) return false;
    if (AITile.GetMaxHeight(tile) == 0) return false;
    if (AIMarine.IsWaterDepotTile(tile)) return false;
    if (AIMarine.IsCanalTile(tile)) return false;
    if (AIMarine.IsLockTile(tile)) return false;
    return true;
}

@James103
Copy link
Contributor

James103 commented Mar 7, 2020

@SamuXarick Looking at the code above, it looks like your version of ScriptTile.IsRiverTile may return a false negative for rivers that are on tile height 0 (possible in the scenario editor) as well as rivers that have locks or water depots (both currently possible ingame).

@SamuXarick
Copy link
Contributor

SamuXarick commented Mar 7, 2020

Oops, I wasn't aware it was possible to have rivers on tile height 0 via scenario editor.

Rivers that have locks or water depots don't count. The submitted code was also not considering them.

/* static */ bool ScriptTile::IsRiverTile(TileIndex tile)
{
	if (!::IsValidTile(tile)) return false;
	return ::IsTileType(tile, MP_WATER) && ::IsRiver(tile);
}

So, it seems that there isn't a way to detect river tiles in all case scenarios. I can't think of a workaround atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants