mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-27 14:14:27 +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:
@@ -51,7 +51,7 @@ Order::~Order()
|
||||
/* We can visit oil rigs and buoys that are not our own. They will be shown in
|
||||
* the list of stations. So, we need to invalidate that window if needed. */
|
||||
if (this->IsType(OT_GOTO_STATION) || this->IsType(OT_GOTO_WAYPOINT)) {
|
||||
BaseStation *bs = BaseStation::GetIfValid(this->GetDestination());
|
||||
BaseStation *bs = BaseStation::GetIfValid(this->GetDestination().ToStationID());
|
||||
if (bs != nullptr && bs->owner == OWNER_NONE) InvalidateWindowClassesData(WC_STATION_LIST, 0);
|
||||
}
|
||||
}
|
||||
@@ -202,12 +202,12 @@ uint16_t Order::MapOldOrder() const
|
||||
if (this->GetUnloadType() & OUFB_UNLOAD) SetBit(order, 5);
|
||||
if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
|
||||
if (this->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) SetBit(order, 7);
|
||||
order |= GB(this->GetDestination(), 0, 8) << 8;
|
||||
order |= GB(this->GetDestination().value, 0, 8) << 8;
|
||||
break;
|
||||
case OT_GOTO_DEPOT:
|
||||
if (!(this->GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) SetBit(order, 6);
|
||||
SetBit(order, 7);
|
||||
order |= GB(this->GetDestination(), 0, 8) << 8;
|
||||
order |= GB(this->GetDestination().value, 0, 8) << 8;
|
||||
break;
|
||||
case OT_LOADING:
|
||||
if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
|
||||
@@ -434,7 +434,7 @@ StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, const Order *
|
||||
}
|
||||
} while (next->IsType(OT_GOTO_DEPOT) || next->GetDestination() == v->last_station_visited);
|
||||
|
||||
return next->GetDestination();
|
||||
return next->GetDestination().ToStationID();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -469,7 +469,7 @@ void OrderList::InsertOrderAt(Order *new_order, int index)
|
||||
/* We can visit oil rigs and buoys that are not our own. They will be shown in
|
||||
* the list of stations. So, we need to invalidate that window if needed. */
|
||||
if (new_order->IsType(OT_GOTO_STATION) || new_order->IsType(OT_GOTO_WAYPOINT)) {
|
||||
BaseStation *bs = BaseStation::Get(new_order->GetDestination());
|
||||
BaseStation *bs = BaseStation::Get(new_order->GetDestination().ToStationID());
|
||||
if (bs->owner == OWNER_NONE) InvalidateWindowClassesData(WC_STATION_LIST, 0);
|
||||
}
|
||||
|
||||
@@ -630,12 +630,12 @@ TileIndex Order::GetLocation(const Vehicle *v, bool airport) const
|
||||
case OT_GOTO_WAYPOINT:
|
||||
case OT_GOTO_STATION:
|
||||
case OT_IMPLICIT:
|
||||
if (airport && v->type == VEH_AIRCRAFT) return Station::Get(this->GetDestination())->airport.tile;
|
||||
return BaseStation::Get(this->GetDestination())->xy;
|
||||
if (airport && v->type == VEH_AIRCRAFT) return Station::Get(this->GetDestination().ToStationID())->airport.tile;
|
||||
return BaseStation::Get(this->GetDestination().ToStationID())->xy;
|
||||
|
||||
case OT_GOTO_DEPOT:
|
||||
if (this->GetDestination() == INVALID_DEPOT) return INVALID_TILE;
|
||||
return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination())->xy : Depot::Get(this->GetDestination())->xy;
|
||||
return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination().ToStationID())->xy : Depot::Get(this->GetDestination().ToDepotID())->xy;
|
||||
|
||||
default:
|
||||
return INVALID_TILE;
|
||||
@@ -694,7 +694,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
||||
* and has the correct flags if any */
|
||||
switch (new_order.GetType()) {
|
||||
case OT_GOTO_STATION: {
|
||||
const Station *st = Station::GetIfValid(new_order.GetDestination());
|
||||
const Station *st = Station::GetIfValid(new_order.GetDestination().ToStationID());
|
||||
if (st == nullptr) return CMD_ERROR;
|
||||
|
||||
if (st->owner != OWNER_NONE) {
|
||||
@@ -749,7 +749,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
||||
case OT_GOTO_DEPOT: {
|
||||
if ((new_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) == 0) {
|
||||
if (v->type == VEH_AIRCRAFT) {
|
||||
const Station *st = Station::GetIfValid(new_order.GetDestination());
|
||||
const Station *st = Station::GetIfValid(new_order.GetDestination().ToStationID());
|
||||
|
||||
if (st == nullptr) return CMD_ERROR;
|
||||
|
||||
@@ -760,7 +760,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
||||
return CMD_ERROR;
|
||||
}
|
||||
} else {
|
||||
const Depot *dp = Depot::GetIfValid(new_order.GetDestination());
|
||||
const Depot *dp = Depot::GetIfValid(new_order.GetDestination().ToDepotID());
|
||||
|
||||
if (dp == nullptr) return CMD_ERROR;
|
||||
|
||||
@@ -802,7 +802,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
||||
}
|
||||
|
||||
case OT_GOTO_WAYPOINT: {
|
||||
const Waypoint *wp = Waypoint::GetIfValid(new_order.GetDestination());
|
||||
const Waypoint *wp = Waypoint::GetIfValid(new_order.GetDestination().ToStationID());
|
||||
if (wp == nullptr) return CMD_ERROR;
|
||||
|
||||
switch (v->type) {
|
||||
@@ -1536,7 +1536,7 @@ CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID ve
|
||||
/* Allow copying unreachable destinations if they were already unreachable for the source.
|
||||
* This is basically to allow cloning / autorenewing / autoreplacing vehicles, while the stations
|
||||
* are temporarily invalid due to reconstruction. */
|
||||
const Station *st = Station::Get(order->GetDestination());
|
||||
const Station *st = Station::Get(order->GetDestination().ToStationID());
|
||||
if (CanVehicleUseStation(src, st) && !CanVehicleUseStation(dst, st)) {
|
||||
return CommandCost(STR_ERROR_CAN_T_COPY_SHARE_ORDER, GetVehicleCannotUseStationReason(dst, st));
|
||||
}
|
||||
@@ -1583,7 +1583,7 @@ CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID ve
|
||||
* and neither can helicopters and aircraft. */
|
||||
for (const Order *order : src->Orders()) {
|
||||
if (!OrderGoesToStation(dst, order)) continue;
|
||||
Station *st = Station::Get(order->GetDestination());
|
||||
Station *st = Station::Get(order->GetDestination().ToStationID());
|
||||
if (!CanVehicleUseStation(dst, st)) {
|
||||
return CommandCost(STR_ERROR_CAN_T_COPY_SHARE_ORDER, GetVehicleCannotUseStationReason(dst, st));
|
||||
}
|
||||
@@ -1722,7 +1722,7 @@ void CheckOrders(const Vehicle *v)
|
||||
}
|
||||
/* Does station have a load-bay for this vehicle? */
|
||||
if (order->IsType(OT_GOTO_STATION)) {
|
||||
const Station *st = Station::Get(order->GetDestination());
|
||||
const Station *st = Station::Get(order->GetDestination().ToStationID());
|
||||
|
||||
n_st++;
|
||||
if (!CanVehicleUseStation(v, st)) {
|
||||
@@ -1989,7 +1989,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
|
||||
|
||||
switch (order->GetType()) {
|
||||
case OT_GOTO_STATION:
|
||||
v->SetDestTile(v->GetOrderStationLocation(order->GetDestination()));
|
||||
v->SetDestTile(v->GetOrderStationLocation(order->GetDestination().ToStationID()));
|
||||
return true;
|
||||
|
||||
case OT_GOTO_DEPOT:
|
||||
@@ -2035,13 +2035,13 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
|
||||
v->IncrementRealOrderIndex();
|
||||
} else {
|
||||
if (v->type != VEH_AIRCRAFT) {
|
||||
v->SetDestTile(Depot::Get(order->GetDestination())->xy);
|
||||
v->SetDestTile(Depot::Get(order->GetDestination().ToStationID())->xy);
|
||||
} else {
|
||||
Aircraft *a = Aircraft::From(v);
|
||||
DestinationID destination = a->current_order.GetDestination();
|
||||
if (a->targetairport != destination) {
|
||||
/* The aircraft is now heading for a different hangar than the next in the orders */
|
||||
a->SetDestTile(a->GetOrderStationLocation(destination));
|
||||
a->SetDestTile(a->GetOrderStationLocation(destination.ToStationID()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -2049,7 +2049,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
|
||||
break;
|
||||
|
||||
case OT_GOTO_WAYPOINT:
|
||||
v->SetDestTile(Waypoint::Get(order->GetDestination())->xy);
|
||||
v->SetDestTile(Waypoint::Get(order->GetDestination().ToStationID())->xy);
|
||||
return true;
|
||||
|
||||
case OT_CONDITIONAL: {
|
||||
@@ -2144,7 +2144,7 @@ bool ProcessOrders(Vehicle *v)
|
||||
* the train to stop at this 'via' station if the next order
|
||||
* is a no-non-stop order; in that case not setting the last
|
||||
* visited station will cause the vehicle to still stop. */
|
||||
v->last_station_visited = v->current_order.GetDestination();
|
||||
v->last_station_visited = v->current_order.GetDestination().ToStationID();
|
||||
UpdateVehicleTimetable(v, true);
|
||||
v->IncrementImplicitOrderIndex();
|
||||
}
|
||||
@@ -2174,7 +2174,7 @@ bool ProcessOrders(Vehicle *v)
|
||||
|
||||
/* If it is unchanged, keep it. */
|
||||
if (order->Equals(v->current_order) && (v->type == VEH_AIRCRAFT || v->dest_tile != 0) &&
|
||||
(v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || Station::Get(order->GetDestination())->ship_station.tile != INVALID_TILE)) {
|
||||
(v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || Station::Get(order->GetDestination().ToStationID())->ship_station.tile != INVALID_TILE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user