diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index c1bb851064..3e79621ee9 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -842,7 +842,7 @@ CommandCost CmdSetAutoReplace(DoCommandFlag flags, GroupID id_g, EngineID old_en if (IsLocalCompany()) SetWindowDirty(WC_REPLACE_VEHICLE, Engine::Get(old_engine_type)->type); const VehicleType vt = Engine::Get(old_engine_type)->type; - SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack()); + SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).ToWindowNumber()); } if ((flags & DC_EXEC) && IsLocalCompany()) InvalidateAutoreplaceWindow(old_engine_type, id_g); diff --git a/src/depot.cpp b/src/depot.cpp index 13317e8a35..16656ae300 100644 --- a/src/depot.cpp +++ b/src/depot.cpp @@ -45,5 +45,5 @@ Depot::~Depot() /* Delete the depot list */ VehicleType vt = GetDepotVehicleType(this->xy); - CloseWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).Pack()); + CloseWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).ToWindowNumber()); } diff --git a/src/depot_cmd.cpp b/src/depot_cmd.cpp index 2ac1f190cd..3106928f0f 100644 --- a/src/depot_cmd.cpp +++ b/src/depot_cmd.cpp @@ -72,7 +72,7 @@ CommandCost CmdRenameDepot(DoCommandFlag flags, DepotID depot_id, const std::str /* Update the depot list */ VehicleType vt = GetDepotVehicleType(d->xy); - SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).Pack()); + SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).ToWindowNumber()); } return CommandCost(); } diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 9096067294..4cb1acb7a7 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()).Pack(), false); + CloseWindowById(GetWindowClassForVehicleType(this->type), VehicleListIdentifier(VL_DEPOT_LIST, this->type, this->owner, this->GetDepotIndex()).ToWindowNumber(), false); OrderBackup::Reset(TileIndex(this->window_number)); this->Window::Close(); } diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index aebb38ad34..0494c3d37e 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -363,7 +363,7 @@ std::tuple CmdCreateGroup(DoCommandFlag flags, VehicleType g->flags = pg->flags; } - InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack()); + InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).ToWindowNumber()); InvalidateWindowData(WC_COMPANY_COLOUR, g->owner, g->vehicle_type); return { CommandCost(), g->index }; @@ -415,7 +415,7 @@ CommandCost CmdDeleteGroup(DoCommandFlag flags, GroupID group_id) CloseWindowById(WC_REPLACE_VEHICLE, g->vehicle_type); delete g; - InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack()); + InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).ToWindowNumber()); InvalidateWindowData(WC_COMPANY_COLOUR, _current_company, vt); } @@ -485,7 +485,7 @@ CommandCost CmdAlterGroup(DoCommandFlag flags, AlterGroupMode mode, GroupID grou if (flags & DC_EXEC) { InvalidateWindowData(WC_REPLACE_VEHICLE, g->vehicle_type, 1); - InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack()); + InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).ToWindowNumber()); InvalidateWindowData(WC_COMPANY_COLOUR, g->owner, g->vehicle_type); InvalidateWindowClassesData(WC_VEHICLE_VIEW); InvalidateWindowClassesData(WC_VEHICLE_DETAILS); @@ -590,7 +590,7 @@ std::tuple CmdAddVehicleGroup(DoCommandFlag flags, GroupID /* Update the Replace Vehicle Windows */ SetWindowDirty(WC_REPLACE_VEHICLE, vtype); - InvalidateWindowData(GetWindowClassForVehicleType(vtype), VehicleListIdentifier(VL_GROUP_LIST, vtype, _current_company).Pack()); + InvalidateWindowData(GetWindowClassForVehicleType(vtype), VehicleListIdentifier(VL_GROUP_LIST, vtype, _current_company).ToWindowNumber()); } return { CommandCost(), new_g }; @@ -621,7 +621,7 @@ CommandCost CmdAddSharedVehicleGroup(DoCommandFlag flags, GroupID id_g, VehicleT } } - InvalidateWindowData(GetWindowClassForVehicleType(type), VehicleListIdentifier(VL_GROUP_LIST, type, _current_company).Pack()); + InvalidateWindowData(GetWindowClassForVehicleType(type), VehicleListIdentifier(VL_GROUP_LIST, type, _current_company).ToWindowNumber()); } return CommandCost(); @@ -651,7 +651,7 @@ CommandCost CmdRemoveAllVehiclesGroup(DoCommandFlag flags, GroupID group_id) } } - InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack()); + InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).ToWindowNumber()); } return CommandCost(); @@ -729,7 +729,7 @@ CommandCost CmdSetGroupFlag(DoCommandFlag flags, GroupID group_id, GroupFlag fla if (flags & DC_EXEC) { SetGroupFlag(g, flag, value, recursive); - SetWindowDirty(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack()); + SetWindowDirty(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).ToWindowNumber()); InvalidateWindowData(WC_REPLACE_VEHICLE, g->vehicle_type); } diff --git a/src/group_gui.cpp b/src/group_gui.cpp index ae20b3d5e5..f6611ae306 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -1191,7 +1191,7 @@ static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type assert(vehicle_type < std::size(_vehicle_group_desc)); VehicleListIdentifier vli(VL_GROUP_LIST, vehicle_type, company); - VehicleGroupWindow *w = AllocateWindowDescFront(_vehicle_group_desc[vehicle_type], vli.Pack(), vli); + VehicleGroupWindow *w = AllocateWindowDescFront(_vehicle_group_desc[vehicle_type], vli.ToWindowNumber(), vli); if (w != nullptr) w->SelectGroup(group); } @@ -1223,7 +1223,7 @@ void ShowCompanyGroupForVehicle(const Vehicle *v) */ static inline VehicleGroupWindow *FindVehicleGroupWindow(VehicleType vt, Owner owner) { - return dynamic_cast(FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack())); + return dynamic_cast(FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).ToWindowNumber())); } /** diff --git a/src/station.cpp b/src/station.cpp index c3fd3c02fa..ba2049adfd 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -52,10 +52,10 @@ BaseStation::~BaseStation() { if (CleaningPool()) return; - CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).Pack()); - CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).Pack()); - CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).Pack()); - CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack()); + CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->index).ToWindowNumber()); + CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->index).ToWindowNumber()); + CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->index).ToWindowNumber()); + CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).ToWindowNumber()); this->sign.MarkDirty(); } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 89d1b6d6d7..2e336e86fa 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1375,10 +1375,10 @@ struct StationViewWindow : public Window { void Close([[maybe_unused]] int data = 0) override { - CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).Pack(), false); - CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).Pack(), false); - CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).Pack(), false); - CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).Pack(), false); + CloseWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, this->owner, this->window_number).ToWindowNumber(), false); + CloseWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).ToWindowNumber(), false); + CloseWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).ToWindowNumber(), false); + CloseWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).ToWindowNumber(), false); SetViewportCatchmentStation(Station::Get(this->window_number), false); this->Window::Close(); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 9b7817766f..a368c722ba 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -3005,12 +3005,12 @@ void Vehicle::RemoveFromShared() if (this->orders->GetNumVehicles() == 1) { /* When there is only one vehicle, remove the shared order list window. */ - CloseWindowById(GetWindowClassForVehicleType(this->type), vli.Pack()); + CloseWindowById(GetWindowClassForVehicleType(this->type), vli.ToWindowNumber()); InvalidateVehicleOrder(this->FirstShared(), VIWD_MODIFY_ORDERS); } else if (were_first) { /* If we were the first one, update to the new first one. * Note: FirstShared() is already the new first */ - InvalidateWindowData(GetWindowClassForVehicleType(this->type), vli.Pack(), this->FirstShared()->index | (1U << 31)); + InvalidateWindowData(GetWindowClassForVehicleType(this->type), vli.ToWindowNumber(), this->FirstShared()->index | (1U << 31)); } this->next_shared = nullptr; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 5842e06ddb..40ec8bf3ec 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2281,7 +2281,7 @@ public: if (!gui_scope && HasBit(data, 31) && this->vli.type == VL_SHARED_ORDERS) { /* Needs to be done in command-scope, so everything stays valid */ this->vli.index = GB(data, 0, 20); - this->window_number = this->vli.Pack(); + this->window_number = this->vli.ToWindowNumber(); this->vehgroups.ForceRebuild(); return; } @@ -2328,7 +2328,7 @@ static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, V assert(vehicle_type < std::size(_vehicle_list_desc)); VehicleListIdentifier vli(vlt, vehicle_type, company, unique_number); - AllocateWindowDescFront(_vehicle_list_desc[vehicle_type], vli.Pack(), vli); + AllocateWindowDescFront(_vehicle_list_desc[vehicle_type], vli.ToWindowNumber(), vli); } void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type) diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp index f4d661c1ad..0be67c7edf 100644 --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -17,10 +17,10 @@ #include "safeguards.h" /** - * Pack a VehicleListIdentifier in a single uint32. - * @return The packed identifier. + * Pack a VehicleListIdentifier in 32 bits so it can be used as unique WindowNumber. + * @return The window number. */ -uint32_t VehicleListIdentifier::Pack() const +WindowNumber VehicleListIdentifier::ToWindowNumber() const { uint8_t c = this->company == OWNER_NONE ? 0xF : (uint8_t)this->company; assert(c < (1 << 4)); diff --git a/src/vehiclelist.h b/src/vehiclelist.h index b1c415d668..b23cc9e005 100644 --- a/src/vehiclelist.h +++ b/src/vehiclelist.h @@ -13,6 +13,7 @@ #include "vehicle_type.h" #include "company_type.h" #include "tile_type.h" +#include "window_type.h" /** Vehicle List type flags */ enum VehicleListType : uint8_t { @@ -31,7 +32,7 @@ struct VehicleListIdentifier { CompanyID company; ///< The company associated with this list. uint32_t index; ///< A vehicle list type specific index. - uint32_t Pack() const; + WindowNumber ToWindowNumber() const; bool Valid() const { return this->type < VLT_END; } diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp index 4217368564..aa3821e6fa 100644 --- a/src/waypoint_gui.cpp +++ b/src/waypoint_gui.cpp @@ -104,7 +104,7 @@ public: void Close([[maybe_unused]] int data = 0) override { - CloseWindowById(GetWindowClassForVehicleType(this->vt), VehicleListIdentifier(VL_STATION_LIST, this->vt, this->owner, this->window_number).Pack(), false); + CloseWindowById(GetWindowClassForVehicleType(this->vt), VehicleListIdentifier(VL_STATION_LIST, this->vt, this->owner, this->window_number).ToWindowNumber(), false); SetViewportCatchmentWaypoint(Waypoint::Get(this->window_number), false); this->Window::Close(); }