1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-12 16:02:07 +01:00

Codechange: Replace HasVehicleOnPos and callbacks with HasVehicleOnTile and lambda-predicates.

This commit is contained in:
frosch
2025-04-22 14:23:43 +02:00
committed by frosch
parent dacd77b2bd
commit 06c399b79e
7 changed files with 61 additions and 90 deletions

View File

@@ -3032,14 +3032,6 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, DoCommandFlags flags,
return cost;
}
/**
* Test-procedure for HasVehicleOnPos to check for a ship.
*/
static Vehicle *EnsureNoShipProc(Vehicle *v, void *)
{
return v->type == VEH_SHIP ? v : nullptr;
}
static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
{
auto [tileh_old, z_old] = GetTileSlopeZ(tile);
@@ -3049,7 +3041,9 @@ static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlags flags, int
bool was_water = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old));
/* Allow clearing the water only if there is no ship */
if (was_water && HasVehicleOnPos(tile, nullptr, &EnsureNoShipProc)) return CommandCost(STR_ERROR_SHIP_IN_THE_WAY);
if (was_water && HasVehicleOnTile(tile, [](const Vehicle *v) {
return v->type == VEH_SHIP;
})) return CommandCost(STR_ERROR_SHIP_IN_THE_WAY);
/* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */
CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_bits);