Codechange: change DestinationID into class with conversion helpers

A DestinationID is either a DepotID or StationID, where the aircraft hangar
being conceptually a depot is actually a StationID. When making those types
stronger, a lot of casts would need to be added, but this shows the intent
much better.
This commit is contained in:
Rubidium
2025-02-02 21:48:07 +01:00
committed by rubidium42
parent 8ca03a3766
commit e937c4dcfd
23 changed files with 84 additions and 64 deletions

View File

@@ -252,15 +252,15 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
/* We don't know where the nearest depot is... (yet) */
if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) return INVALID_TILE;
if (v->type != VEH_AIRCRAFT) return ::Depot::Get(order->GetDestination())->xy;
if (v->type != VEH_AIRCRAFT) return ::Depot::Get(order->GetDestination().ToDepotID())->xy;
/* Aircraft's hangars are referenced by StationID, not DepotID */
const Station *st = ::Station::Get(order->GetDestination());
const Station *st = ::Station::Get(order->GetDestination().ToStationID());
if (!st->airport.HasHangar()) return INVALID_TILE;
return st->airport.GetHangarTile(0);
}
case OT_GOTO_STATION: {
const Station *st = ::Station::Get(order->GetDestination());
const Station *st = ::Station::Get(order->GetDestination().ToStationID());
if (st->train_station.tile != INVALID_TILE) {
for (TileIndex t : st->train_station) {
if (st->TileBelongsToRailStation(t)) return t;
@@ -282,7 +282,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
}
case OT_GOTO_WAYPOINT: {
const Waypoint *wp = ::Waypoint::Get(order->GetDestination());
const Waypoint *wp = ::Waypoint::Get(order->GetDestination().ToStationID());
if (wp->train_station.tile != INVALID_TILE) {
for (TileIndex t : wp->train_station) {
if (wp->TileBelongsToRailStation(t)) return t;