diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 281dc8b47d..0384cf3f2f 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -299,7 +299,7 @@ struct DepotWindow : Window { void Close([[maybe_unused]] int data = 0) override { CloseWindowById(WC_BUILD_VEHICLE, this->window_number); - CloseWindowById(GetWindowClassForVehicleType(this->type), VehicleListIdentifier(VL_DEPOT_LIST, this->type, this->owner, this->GetDepotIndex()).ToWindowNumber(), false); + CloseWindowById(GetWindowClassForVehicleType(this->type), VehicleListIdentifier(VL_DEPOT_LIST, this->type, this->owner, this->GetDestinationIndex().base()).ToWindowNumber(), false); OrderBackup::Reset(TileIndex(this->window_number)); this->Window::Close(); } @@ -428,7 +428,7 @@ struct DepotWindow : Window { if (widget != WID_D_CAPTION) return; SetDParam(0, this->type); - SetDParam(1, this->GetDepotIndex()); + SetDParam(1, this->GetDestinationIndex()); } struct GetDepotVehiclePtData { @@ -823,7 +823,7 @@ struct DepotWindow : Window { /* Only open the confirmation window if there are anything to sell */ if (!this->vehicle_list.empty() || !this->wagon_list.empty()) { SetDParam(0, this->type); - SetDParam(1, this->GetDepotIndex()); + SetDParam(1, this->GetDestinationIndex()); ShowQuery( STR_DEPOT_CAPTION, STR_DEPOT_SELL_CONFIRMATION_TEXT, @@ -849,7 +849,7 @@ struct DepotWindow : Window { if (!str.has_value()) return; /* Do depot renaming */ - Command::Post(STR_ERROR_CAN_T_RENAME_DEPOT, this->GetDepotIndex(), *str); + Command::Post(STR_ERROR_CAN_T_RENAME_DEPOT, this->GetDestinationIndex().ToDepotID(), *str); } bool OnRightClick([[maybe_unused]] Point pt, WidgetID widget) override @@ -1139,9 +1139,9 @@ struct DepotWindow : Window { * In the case of airports, this is the station ID. * @return Depot or station ID of this window. */ - inline uint16_t GetDepotIndex() const + inline DestinationID GetDestinationIndex() const { - return (this->type == VEH_AIRCRAFT) ? ::GetStationIndex(this->window_number) : ::GetDepotIndex(this->window_number); + return GetDepotDestinationIndex(this->window_number); } }; diff --git a/src/depot_map.h b/src/depot_map.h index 87bd915431..cb38fbaf97 100644 --- a/src/depot_map.h +++ b/src/depot_map.h @@ -10,6 +10,7 @@ #ifndef DEPOT_MAP_H #define DEPOT_MAP_H +#include "order_type.h" #include "station_map.h" /** @@ -56,6 +57,18 @@ inline DepotID GetDepotIndex(Tile t) return t.m2(); } +/** + * Get the destination index of a 'depot'. For hangars that's the station index, for the rest a depot index. + * @param t the tile + * @pre IsRailDepotTile(t) || IsRoadDepotTile(t) || IsShipDepotTile(t) || IsHangarTile(t) + * @return DepotID + */ +inline DestinationID GetDepotDestinationIndex(Tile t) +{ + if (IsHangarTile(t)) return GetStationIndex(t); + return GetDepotIndex(t); +} + /** * Get the type of vehicles that can use a depot * @param t The tile diff --git a/src/order_base.h b/src/order_base.h index 2239b80885..b92f8f9050 100644 --- a/src/order_base.h +++ b/src/order_base.h @@ -78,7 +78,7 @@ public: void Free(); void MakeGoToStation(StationID destination); - void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type = ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action = ODATF_SERVICE_ONLY, CargoType cargo = CARGO_NO_REFIT); + void MakeGoToDepot(DestinationID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type = ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action = ODATF_SERVICE_ONLY, CargoType cargo = CARGO_NO_REFIT); void MakeGoToWaypoint(StationID destination); void MakeLoading(bool ordered); void MakeLeaveStation(); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index d1cb513d83..175becfe08 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -87,7 +87,7 @@ void Order::MakeGoToStation(StationID destination) * @param action what to do in the depot? * @param cargo the cargo type to change to. */ -void Order::MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type, OrderDepotActionFlags action, CargoType cargo) +void Order::MakeGoToDepot(DestinationID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type, OrderDepotActionFlags action, CargoType cargo) { this->type = OT_GOTO_DEPOT; this->SetDepotOrderType(order); diff --git a/src/order_gui.cpp b/src/order_gui.cpp index db0f3f363b..cd0c042cd9 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -384,7 +384,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile) /* check depot first */ if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) { - order.MakeGoToDepot(v->type == VEH_AIRCRAFT ? GetStationIndex(tile) : GetDepotIndex(tile), + order.MakeGoToDepot(GetDepotDestinationIndex(tile), ODTFB_PART_OF_ORDERS, (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 4deb4c1555..f1ea95c6c9 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2347,14 +2347,7 @@ void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, StationI void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, TileIndex depot_tile) { - uint16_t depot_airport_index; - - if (vehicle_type == VEH_AIRCRAFT) { - depot_airport_index = GetStationIndex(depot_tile); - } else { - depot_airport_index = GetDepotIndex(depot_tile); - } - ShowVehicleListWindowLocal(company, VL_DEPOT_LIST, vehicle_type, depot_airport_index); + ShowVehicleListWindowLocal(company, VL_DEPOT_LIST, vehicle_type, GetDepotDestinationIndex(depot_tile).base()); }