mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-24 04:34:16 +01:00
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:
@@ -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;
|
||||
|
||||
@@ -35,7 +35,7 @@ ScriptStationList_Vehicle::ScriptStationList_Vehicle(VehicleID vehicle_id)
|
||||
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||
|
||||
for (Order *o = v->GetFirstOrder(); o != nullptr; o = o->next) {
|
||||
if (o->IsType(OT_GOTO_STATION)) this->AddItem(o->GetDestination());
|
||||
if (o->IsType(OT_GOTO_STATION)) this->AddItem(o->GetDestination().ToStationID());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,6 @@ ScriptWaypointList_Vehicle::ScriptWaypointList_Vehicle(VehicleID vehicle_id)
|
||||
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||
|
||||
for (const Order *o = v->GetFirstOrder(); o != nullptr; o = o->next) {
|
||||
if (o->IsType(OT_GOTO_WAYPOINT)) this->AddItem(o->GetDestination());
|
||||
if (o->IsType(OT_GOTO_WAYPOINT)) this->AddItem(o->GetDestination().ToStationID());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user