1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-24 12:44:10 +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

@@ -359,14 +359,6 @@ void Ship::UpdateDeltaXY()
}
}
/**
* Test-procedure for HasVehicleOnPos to check for any ships which are moving.
*/
static Vehicle *EnsureNoMovingShipProc(Vehicle *v, void *)
{
return v->type == VEH_SHIP && v->cur_speed != 0 ? v : nullptr;
}
static bool CheckReverseShip(const Ship *v, Trackdir *trackdir = nullptr)
{
/* Ask pathfinder for best direction */
@@ -392,7 +384,9 @@ static bool CheckShipLeaveDepot(Ship *v)
/* Don't leave depot if another vehicle is already entering/leaving */
/* This helps avoid CPU load if many ships are set to start at the same time */
if (HasVehicleOnPos(v->tile, nullptr, &EnsureNoMovingShipProc)) return true;
if (HasVehicleOnTile(v->tile, [](const Vehicle *u) {
return u->type == VEH_SHIP && u->cur_speed != 0;
})) return true;
TileIndex tile = v->tile;
Axis axis = GetShipDepotAxis(tile);