From f5128695c54ad634e1ac45ae4271c1db5ed15fad Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 8 Sep 2010 21:37:13 +0000 Subject: [PATCH] (svn r20772) -Codechange: use packed VehicleListIdentifiers as window numbers --- src/depot.cpp | 12 +++++---- src/depot_cmd.cpp | 12 +++++---- src/group_cmd.cpp | 15 ++++++----- src/group_gui.cpp | 15 +++++------ src/station.cpp | 11 ++++---- src/station_gui.cpp | 12 ++++----- src/vehicle.cpp | 7 ++--- src/vehicle_gui.cpp | 64 +++++++++++++++++++++----------------------- src/vehiclelist.cpp | 49 +++++++++++++++++++++++++++++---- src/vehiclelist.h | 8 ++++++ src/waypoint_gui.cpp | 3 ++- 11 files changed, 129 insertions(+), 79 deletions(-) diff --git a/src/depot.cpp b/src/depot.cpp index 039ab5b34a..a1893c8ef2 100644 --- a/src/depot.cpp +++ b/src/depot.cpp @@ -16,6 +16,7 @@ #include "window_func.h" #include "core/pool_func.hpp" #include "vehicle_gui.h" +#include "vehiclelist.h" DepotPool _depot_pool("Depot"); INSTANTIATE_POOL_METHODS(Depot) @@ -37,13 +38,14 @@ Depot::~Depot() DeleteWindowById(WC_VEHICLE_DEPOT, this->xy); /* Delete the depot list */ - WindowNumber wno = (this->index << 16) | VLW_DEPOT_LIST | GetTileOwner(this->xy); + VehicleType vt; switch (GetTileType(this->xy)) { - default: break; // It can happen there is no depot here anymore (TTO/TTD savegames) - case MP_RAILWAY: DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11)); break; - case MP_ROAD: DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11)); break; - case MP_WATER: DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11)); break; + default: return; // It can happen there is no depot here anymore (TTO/TTD savegames) + case MP_RAILWAY: vt = VEH_TRAIN; break; + case MP_ROAD: vt = VEH_ROAD; break; + case MP_WATER: vt = VEH_SHIP; break; } + DeleteWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).Pack()); } void InitializeDepots() diff --git a/src/depot_cmd.cpp b/src/depot_cmd.cpp index bf4d0201c5..2c507f73f1 100644 --- a/src/depot_cmd.cpp +++ b/src/depot_cmd.cpp @@ -16,6 +16,7 @@ #include "string_func.h" #include "town.h" #include "vehicle_gui.h" +#include "vehiclelist.h" #include "window_func.h" #include "table/strings.h" @@ -71,13 +72,14 @@ CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 SetWindowDirty(WC_VEHICLE_DEPOT, d->xy); /* Update the depot list */ - WindowNumber wno = (d->index << 16) | VLW_DEPOT_LIST | GetTileOwner(d->xy); + VehicleType vt; switch (GetTileType(d->xy)) { - default: break; - case MP_RAILWAY: SetWindowDirty(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11)); break; - case MP_ROAD: SetWindowDirty(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11)); break; - case MP_WATER: SetWindowDirty(WC_SHIPS_LIST, wno | (VEH_SHIP << 11)); break; + default: NOT_REACHED(); + case MP_RAILWAY: vt = VEH_TRAIN; break; + case MP_ROAD: vt = VEH_ROAD; break; + case MP_WATER: vt = VEH_SHIP; break; } + SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).Pack()); } return CommandCost(); } diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 9b954d6b46..8f34d3f7fb 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -15,6 +15,7 @@ #include "group.h" #include "train.h" #include "vehicle_gui.h" +#include "vehiclelist.h" #include "window_func.h" #include "vehicle_func.h" #include "autoreplace_base.h" @@ -95,7 +96,7 @@ CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 _new_group_id = g->index; - InvalidateWindowData(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | _current_company); + InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack()); } return CommandCost(); @@ -145,7 +146,7 @@ CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 DeleteWindowById(WC_REPLACE_VEHICLE, g->vehicle_type); delete g; - InvalidateWindowData(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | _current_company); + InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack()); } return CommandCost(); @@ -190,7 +191,7 @@ CommandCost CmdRenameGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 /* Assign the new one */ g->name = reset ? NULL : strdup(text); - InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_company); + InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack()); } return CommandCost(); @@ -241,7 +242,7 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u /* Update the Replace Vehicle Windows */ SetWindowDirty(WC_REPLACE_VEHICLE, v->type); - InvalidateWindowData(GetWindowClassForVehicleType(v->type), (v->type << 11) | VLW_GROUP_LIST | _current_company); + InvalidateWindowData(GetWindowClassForVehicleType(v->type), VehicleListIdentifier(VL_GROUP_LIST, v->type, _current_company).Pack()); } return CommandCost(); @@ -279,7 +280,7 @@ CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 } } - InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_company); + InvalidateWindowData(GetWindowClassForVehicleType(type), VehicleListIdentifier(VL_GROUP_LIST, type, _current_company).Pack()); } return CommandCost(); @@ -317,7 +318,7 @@ CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint3 } } - InvalidateWindowData(GetWindowClassForVehicleType(type), (type << 11) | VLW_GROUP_LIST | _current_company); + InvalidateWindowData(GetWindowClassForVehicleType(type), VehicleListIdentifier(VL_GROUP_LIST, type, _current_company).Pack()); } return CommandCost(); @@ -343,7 +344,7 @@ CommandCost CmdSetGroupReplaceProtection(TileIndex tile, DoCommandFlag flags, ui if (flags & DC_EXEC) { g->replace_protection = HasBit(p2, 0); - InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_company); + InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), VehicleListIdentifier(VL_GROUP_LIST, g->vehicle_type, _current_company).Pack()); InvalidateWindowData(WC_REPLACE_VEHICLE, g->vehicle_type); } diff --git a/src/group_gui.cpp b/src/group_gui.cpp index f51025e6fc..f413046a2e 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -173,7 +173,8 @@ public: this->vscroll = this->GetScrollbar(GRP_WIDGET_LIST_VEHICLE_SCROLLBAR); this->group_sb = this->GetScrollbar(GRP_WIDGET_LIST_GROUP_SCROLLBAR); - this->vehicle_type = (VehicleType)GB(window_number, 11, 5); + VehicleListIdentifier vli(window_number); + this->vehicle_type = vli.vtype; switch (this->vehicle_type) { default: NOT_REACHED(); case VEH_TRAIN: this->sorting = &_sorting.train; break; @@ -186,11 +187,9 @@ public: this->vehicle_sel = INVALID_VEHICLE; this->group_rename = INVALID_GROUP; - const Owner owner = (Owner)GB(window_number, 0, 8); this->vehicles.SetListing(*this->sorting); this->vehicles.ForceRebuild(); this->vehicles.NeedResort(); - VehicleListIdentifier vli(IsAllGroupID(this->group_sel) ? VL_STANDARD : VL_GROUP_LIST, this->vehicle_type, owner, this->group_sel); this->BuildVehicleList(vli); this->SortVehicleList(); @@ -208,7 +207,7 @@ public: this->GetWidget(GRP_WIDGET_REPLACE_PROTECTION)->widget_data += this->vehicle_type; this->FinishInitNested(desc, window_number); - this->owner = owner; + this->owner = vli.company; } ~VehicleGroupWindow() @@ -299,11 +298,11 @@ public: virtual void OnPaint() { - const Owner owner = (Owner)GB(this->window_number, 0, 8); + VehicleListIdentifier vli(this->window_number); + const Owner owner = vli.company; /* If we select the all vehicles, this->list will contain all vehicles of the owner * else this->list will contain all vehicles which belong to the selected group */ - VehicleListIdentifier vli(IsAllGroupID(this->group_sel) ? VL_STANDARD : VL_GROUP_LIST, this->vehicle_type, owner, this->group_sel); this->BuildVehicleList(vli); this->SortVehicleList(); @@ -659,7 +658,7 @@ void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type) { if (!Company::IsValidID(company)) return; - WindowNumber num = (vehicle_type << 11) | VLW_GROUP_LIST | company; + WindowNumber num = VehicleListIdentifier(VL_GROUP_LIST, vehicle_type, company).Pack(); if (vehicle_type == VEH_TRAIN) { AllocateWindowDescFront(&_train_group_desc, num); } else { @@ -676,7 +675,7 @@ void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type) */ static inline VehicleGroupWindow *FindVehicleGroupWindow(VehicleType vt, Owner owner) { - return (VehicleGroupWindow *)FindWindowById(GetWindowClassForVehicleType(vt), (vt << 11) | VLW_GROUP_LIST | owner); + return (VehicleGroupWindow *)FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack()); } /** diff --git a/src/station.cpp b/src/station.cpp index 05be87526b..70deb7de47 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -19,7 +19,7 @@ #include "command_func.h" #include "news_func.h" #include "aircraft.h" -#include "vehicle_gui.h" +#include "vehiclelist.h" #include "core/pool_func.hpp" #include "station_base.h" #include "roadstop_base.h" @@ -40,11 +40,10 @@ BaseStation::~BaseStation() Owner owner = this->owner; if (!Company::IsValidID(owner)) owner = _local_company; - WindowNumber wno = (this->index << 16) | VLW_STATION_LIST | owner; - DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11)); - DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11)); - DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11)); - DeleteWindowById(WC_AIRCRAFT_LIST, wno | (VEH_AIRCRAFT << 11)); + DeleteWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, owner, this->index).Pack()); + DeleteWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, owner, this->index).Pack()); + DeleteWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, owner, this->index).Pack()); + DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, owner, this->index).Pack()); this->sign.MarkDirty(); } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index a2b85a287e..37ff622d3a 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -28,6 +28,7 @@ #include "company_base.h" #include "sortlist_type.h" #include "core/geometry_func.hpp" +#include "vehiclelist.h" #include "table/strings.h" @@ -903,12 +904,11 @@ struct StationViewWindow : public Window { ~StationViewWindow() { - WindowNumber wno = (this->window_number << 16) | VLW_STATION_LIST | Station::Get(this->window_number)->owner; - - DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11), false); - DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11), false); - DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11), false); - DeleteWindowById(WC_AIRCRAFT_LIST, wno | (VEH_AIRCRAFT << 11), false); + Owner owner = Station::Get(this->window_number)->owner; + DeleteWindowById(WC_TRAINS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_TRAIN, owner, this->window_number).Pack(), false); + DeleteWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, owner, this->window_number).Pack(), false); + DeleteWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, owner, this->window_number).Pack(), false); + DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, owner, this->window_number).Pack(), false); } virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index f54aefbf6a..642a780238 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -49,6 +49,7 @@ #include "sound_func.h" #include "effectvehicle_func.h" #include "effectvehicle_base.h" +#include "vehiclelist.h" #include "table/strings.h" @@ -1888,7 +1889,7 @@ void Vehicle::RemoveFromShared() /* Remember if we were first and the old window number before RemoveVehicle() * as this changes first if needed. */ bool were_first = (this->FirstShared() == this); - uint32 old_window_number = (this->FirstShared()->index << 16) | (this->type << 11) | VLW_SHARED_ORDERS | this->owner; + VehicleListIdentifier vli(VL_SHARED_ORDERS, this->type, this->owner, this->FirstShared()->index); this->orders.list->RemoveVehicle(this); @@ -1902,12 +1903,12 @@ void Vehicle::RemoveFromShared() if (this->orders.list->GetNumVehicles() == 1) { /* When there is only one vehicle, remove the shared order list window. */ - DeleteWindowById(GetWindowClassForVehicleType(this->type), old_window_number); + DeleteWindowById(GetWindowClassForVehicleType(this->type), vli.Pack()); InvalidateVehicleOrder(this->FirstShared(), 0); } 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), old_window_number, (this->FirstShared()->index << 16) | (1 << 15)); + InvalidateWindowData(GetWindowClassForVehicleType(this->type), vli.Pack(), this->FirstShared()->index | (1U << 31)); } this->next_shared = NULL; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 694e96a454..a5d5fef1fe 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1085,10 +1085,8 @@ private: public: VehicleListWindow(const WindowDesc *desc, WindowNumber window_number) : BaseVehicleListWindow() { - uint16 window_type = window_number & VLW_MASK; - CompanyID company = (CompanyID)GB(window_number, 0, 8); - - this->vehicle_type = (VehicleType)GB(window_number, 11, 5); + VehicleListIdentifier vli(window_number); + this->vehicle_type = vli.vtype; /* Set up sorting. Make the window-specific _sorting variable * point to the correct global _sorting struct so we are freed @@ -1108,21 +1106,20 @@ public: this->vehicles.SetListing(*this->sorting); this->vehicles.ForceRebuild(); this->vehicles.NeedResort(); - VehicleListIdentifier vli((VehicleListType)(window_type >> 8), this->vehicle_type, owner, GB(window_number, 16, 16)); this->BuildVehicleList(vli); this->SortVehicleList(); /* Set up the window widgets */ this->GetWidget(VLW_WIDGET_LIST)->tool_tip = STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vehicle_type; - if (window_type == VLW_SHARED_ORDERS) { + if (vli.type == VL_SHARED_ORDERS) { this->GetWidget(VLW_WIDGET_CAPTION)->widget_data = STR_VEHICLE_LIST_SHARED_ORDERS_LIST_CAPTION; } else { this->GetWidget(VLW_WIDGET_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vehicle_type; } this->FinishInitNested(desc, window_number); - this->owner = company; + this->owner = vli.company; if (this->vehicle_type == VEH_TRAIN) ResizeWindow(this, 65, 0); } @@ -1152,7 +1149,7 @@ public: break; case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN: { - Dimension d = this->GetActionDropdownSize((this->window_number & VLW_MASK) == VLW_STANDARD, false); + Dimension d = this->GetActionDropdownSize(VehicleListIdentifier(this->window_number).type == VL_STANDARD, false); d.height += padding.height; d.width += padding.width; *size = maxdim(*size, d); @@ -1169,9 +1166,9 @@ public: break; case VLW_WIDGET_CAPTION: { - const uint16 index = GB(this->window_number, 16, 16); - switch (this->window_number & VLW_MASK) { - case VLW_SHARED_ORDERS: // Shared Orders + VehicleListIdentifier vli(this->window_number); + switch (vli.type) { + case VL_SHARED_ORDERS: // Shared Orders if (this->vehicles.Length() == 0) { /* We can't open this window without vehicles using this order * and we should close the window when deleting the order */ @@ -1180,22 +1177,22 @@ public: SetDParam(0, this->vscroll->GetCount()); break; - case VLW_STANDARD: // Company Name + case VL_STANDARD: // Company Name SetDParam(0, STR_COMPANY_NAME); - SetDParam(1, index); + SetDParam(1, vli.index); SetDParam(3, this->vscroll->GetCount()); break; - case VLW_STATION_LIST: // Station/Waypoint Name - SetDParam(0, Station::IsExpected(BaseStation::Get(index)) ? STR_STATION_NAME : STR_WAYPOINT_NAME); - SetDParam(1, index); + case VL_STATION_LIST: // Station/Waypoint Name + SetDParam(0, Station::IsExpected(BaseStation::Get(vli.index)) ? STR_STATION_NAME : STR_WAYPOINT_NAME); + SetDParam(1, vli.index); SetDParam(3, this->vscroll->GetCount()); break; - case VLW_DEPOT_LIST: + case VL_DEPOT_LIST: SetDParam(0, STR_DEPOT_CAPTION); SetDParam(1, this->vehicle_type); - SetDParam(2, index); + SetDParam(2, vli.index); SetDParam(3, this->vscroll->GetCount()); break; default: NOT_REACHED(); @@ -1221,9 +1218,8 @@ public: virtual void OnPaint() { - const uint16 window_type = this->window_number & VLW_MASK; + VehicleListIdentifier vli(this->window_number); - VehicleListIdentifier vli((VehicleListType)(window_type >> 8), this->vehicle_type, this->owner, GB(this->window_number, 16, 16)); this->BuildVehicleList(vli); this->SortVehicleList(); @@ -1240,7 +1236,7 @@ public: nwi->SetDirty(this); } if (this->owner == _local_company) { - this->SetWidgetDisabledState(VLW_WIDGET_AVAILABLE_VEHICLES, window_type != VLW_STANDARD); + this->SetWidgetDisabledState(VLW_WIDGET_AVAILABLE_VEHICLES, vli.type != VL_STANDARD); this->SetWidgetsDisabledState(this->vehicles.Length() == 0, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN, VLW_WIDGET_STOP_ALL, @@ -1281,7 +1277,7 @@ public: break; case VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN: { - DropDownList *list = this->BuildActionDropdownList((this->window_number & VLW_MASK) == VLW_STANDARD, false); + DropDownList *list = this->BuildActionDropdownList(VehicleListIdentifier(this->window_number).type == VL_STANDARD, false); ShowDropDownList(this, list, 0, VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN); break; } @@ -1327,7 +1323,8 @@ public: { if (_pause_mode != PM_UNPAUSED) return; if (this->vehicles.NeedResort()) { - StationID station = ((this->window_number & VLW_MASK) == VLW_STATION_LIST) ? GB(this->window_number, 16, 16) : INVALID_STATION; + VehicleListIdentifier vli(this->window_number); + StationID station = (vli.type == VL_STATION_LIST) ? vli.index : INVALID_STATION; DEBUG(misc, 3, "Periodic resort %d list company %d at station %d", this->vehicle_type, this->owner, station); this->SetDirty(); @@ -1342,8 +1339,10 @@ public: virtual void OnInvalidateData(int data) { - if (HasBit(data, 15) && (this->window_number & VLW_MASK) == VLW_SHARED_ORDERS) { - SB(this->window_number, 16, 16, GB(data, 16, 16)); + VehicleListIdentifier vli(this->window_number); + if (HasBit(data, 31) && vli.type == VL_SHARED_ORDERS) { + vli.index = GB(data, 0, 20); + this->window_number = vli.Pack(); this->vehicles.ForceRebuild(); return; } @@ -1363,7 +1362,7 @@ static WindowDesc _vehicle_list_desc( _nested_vehicle_list, lengthof(_nested_vehicle_list) ); -static void ShowVehicleListWindowLocal(CompanyID company, uint16 VLW_flag, VehicleType vehicle_type, uint16 unique_number) +static void ShowVehicleListWindowLocal(CompanyID company, VehicleListType vlt, VehicleType vehicle_type, uint16 unique_number) { if (!Company::IsValidID(company)) { company = _local_company; @@ -1377,8 +1376,7 @@ static void ShowVehicleListWindowLocal(CompanyID company, uint16 VLW_flag, Vehic } _vehicle_list_desc.cls = GetWindowClassForVehicleType(vehicle_type); - WindowNumber num = (unique_number << 16) | (vehicle_type << 11) | VLW_flag | company; - AllocateWindowDescFront(&_vehicle_list_desc, num); + AllocateWindowDescFront(&_vehicle_list_desc, VehicleListIdentifier(vlt, vehicle_type, company, unique_number).Pack()); } void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type) @@ -1391,18 +1389,18 @@ void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type) if ((_settings_client.gui.advanced_vehicle_list > (uint)(company != _local_company)) != _ctrl_pressed) { ShowCompanyGroup(company, vehicle_type); } else { - ShowVehicleListWindowLocal(company, VLW_STANDARD, vehicle_type, company); + ShowVehicleListWindowLocal(company, VL_STANDARD, vehicle_type, company); } } void ShowVehicleListWindow(const Vehicle *v) { - ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->FirstShared()->index); + ShowVehicleListWindowLocal(v->owner, VL_SHARED_ORDERS, v->type, v->FirstShared()->index); } void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, StationID station) { - ShowVehicleListWindowLocal(company, VLW_STATION_LIST, vehicle_type, station); + ShowVehicleListWindowLocal(company, VL_STATION_LIST, vehicle_type, station); } void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, TileIndex depot_tile) @@ -1414,7 +1412,7 @@ void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, TileInde } else { depot_airport_index = GetDepotIndex(depot_tile); } - ShowVehicleListWindowLocal(company, VLW_DEPOT_LIST, vehicle_type, depot_airport_index); + ShowVehicleListWindowLocal(company, VL_DEPOT_LIST, vehicle_type, depot_airport_index); } @@ -2263,7 +2261,7 @@ public: } case VVW_WIDGET_GOTO_DEPOT: // goto hangar - DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0U, GetCmdSendToDepot(v)); + DoCommandP(v->tile, v->index | (_ctrl_pressed ? DEPOT_SERVICE : 0U), 0, GetCmdSendToDepot(v)); break; case VVW_WIDGET_REFIT_VEH: // refit ShowVehicleRefitWindow(v, INVALID_VEH_ORDER_ID, this); diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp index 20a994e3c0..a0415969bd 100644 --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -14,6 +14,45 @@ #include "train.h" #include "vehiclelist.h" +/** + * Pack a VehicleListIdentifier in a single uint32. + * @return The packed identifier. + */ +uint32 VehicleListIdentifier::Pack() +{ + assert(this->company < (1 << 4)); + assert(this->type < (1 << 3)); + assert(this->vtype < (1 << 2)); + assert(this->index < (1 << 20)); + + return this->company << 28 | this->type << 23 | this->vtype << 26 | this->index; +} + +/** + * Unpack a VehicleListIdentifier from a single uint32. + * @param data The data to unpack. + * @return true iff the data was valid (enough). + */ +bool VehicleListIdentifier::Unpack(uint32 data) +{ + this->company = (CompanyID)GB(data, 28, 4); + this->type = (VehicleListType)GB(data, 23, 3); + this->vtype = (VehicleType)GB(data, 26, 2); + this->index = GB(data, 0, 20); + + return this->type < VLT_END; +} + +/** + * Decode a packed vehicle list identifier into a new one. + * @param data The data to unpack. + */ +VehicleListIdentifier::VehicleListIdentifier(uint32 data) +{ + bool ret = this->Unpack(data); + assert(ret); +} + /** * Generate a list of vehicles inside a depot. * @param type Type of vehicle @@ -76,7 +115,7 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli switch (vli.type) { case VL_STATION_LIST: FOR_ALL_VEHICLES(v) { - if (v->type == vli.type && v->IsPrimaryVehicle()) { + if (v->type == vli.vtype && v->IsPrimaryVehicle()) { const Order *order; FOR_VEHICLE_ORDERS(v, order) { @@ -93,7 +132,7 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli case VL_SHARED_ORDERS: /* Add all vehicles from this vehicle's shared order list */ v = Vehicle::GetIfValid(vli.index); - if (v == NULL || v->type != vli.type || !v->IsPrimaryVehicle()) return false; + if (v == NULL || v->type != vli.vtype || !v->IsPrimaryVehicle()) return false; for (; v != NULL; v = v->NextShared()) { *list->Append() = v; @@ -102,7 +141,7 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli case VL_STANDARD: FOR_ALL_VEHICLES(v) { - if (v->type == vli.type && v->owner == vli.company && v->IsPrimaryVehicle()) { + if (v->type == vli.vtype && v->owner == vli.company && v->IsPrimaryVehicle()) { *list->Append() = v; } } @@ -110,7 +149,7 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli case VL_DEPOT_LIST: FOR_ALL_VEHICLES(v) { - if (v->type == vli.type && v->IsPrimaryVehicle()) { + if (v->type == vli.vtype && v->IsPrimaryVehicle()) { const Order *order; FOR_VEHICLE_ORDERS(v, order) { @@ -125,7 +164,7 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli case VL_GROUP_LIST: FOR_ALL_VEHICLES(v) { - if (v->type == vli.type && v->IsPrimaryVehicle() && + if (v->type == vli.vtype && v->IsPrimaryVehicle() && v->owner == vli.company && v->group_id == vli.index) { *list->Append() = v; } diff --git a/src/vehiclelist.h b/src/vehiclelist.h index 5c13f326b9..af984f451a 100644 --- a/src/vehiclelist.h +++ b/src/vehiclelist.h @@ -34,6 +34,9 @@ struct VehicleListIdentifier { CompanyID company; ///< The company associated with this list. uint32 index; ///< A vehicle list type specific index. + uint32 Pack(); + bool Unpack(uint32 data); + /** * Create a simple vehicle list. * @param type List type. @@ -43,6 +46,11 @@ struct VehicleListIdentifier { */ VehicleListIdentifier(VehicleListType type, VehicleType vtype, CompanyID company, uint index = 0) : type(type), vtype(vtype), company(company), index(index) {} + + VehicleListIdentifier(uint32 data); + + /** Simple empty constructor. In this case you must set everything! */ + VehicleListIdentifier() {} }; typedef SmallVector VehicleList; diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp index 430a1cf372..f6965eb985 100644 --- a/src/waypoint_gui.cpp +++ b/src/waypoint_gui.cpp @@ -13,6 +13,7 @@ #include "window_gui.h" #include "gui.h" #include "textbuf_gui.h" +#include "vehiclelist.h" #include "vehicle_gui.h" #include "viewport_func.h" #include "strings_func.h" @@ -65,7 +66,7 @@ public: { Owner owner = this->owner; if (!Company::IsValidID(owner)) owner = _local_company; - DeleteWindowById(GetWindowClassForVehicleType(this->vt), (this->window_number << 16) | (this->vt << 11) | VLW_STATION_LIST | owner, false); + DeleteWindowById(GetWindowClassForVehicleType(this->vt), VehicleListIdentifier(VL_STATION_LIST, this->vt, owner, this->window_number).Pack(), false); } virtual void SetStringParameters(int widget) const