diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vehicle_cmd.cpp | 4 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 2 | ||||
-rw-r--r-- | src/vehicle_gui_base.h | 2 | ||||
-rw-r--r-- | src/vehiclelist.cpp | 8 | ||||
-rw-r--r-- | src/vehiclelist.h | 5 |
5 files changed, 12 insertions, 9 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 3b664defb..9670fa05d 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -606,7 +606,7 @@ CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 bool vehicle_list_window = HasBit(p1, 1); VehicleListIdentifier vli; - if (!vli.Unpack(p2)) return CMD_ERROR; + if (!vli.UnpackIfValid(p2)) return CMD_ERROR; if (!IsCompanyBuildableVehicleType(vli.vtype)) return CMD_ERROR; if (vehicle_list_window) { @@ -1001,7 +1001,7 @@ CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1 if (p1 & DEPOT_MASS_SEND) { /* Mass goto depot requested */ VehicleListIdentifier vli; - if (!vli.Unpack(p2)) return CMD_ERROR; + if (!vli.UnpackIfValid(p2)) return CMD_ERROR; return SendAllVehiclesToDepot(flags, (p1 & DEPOT_SERVICE) != 0, vli); } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 6617929c6..8ea8cda4c 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1638,7 +1638,7 @@ public: break; case WID_VL_MANAGE_VEHICLES_DROPDOWN: { - DropDownList *list = this->BuildActionDropdownList(VehicleListIdentifier(this->window_number).type == VL_STANDARD, false); + DropDownList *list = this->BuildActionDropdownList(VehicleListIdentifier::UnPack(this->window_number).type == VL_STANDARD, false); ShowDropDownList(this, list, 0, WID_VL_MANAGE_VEHICLES_DROPDOWN); break; } diff --git a/src/vehicle_gui_base.h b/src/vehicle_gui_base.h index 1c03f7b34..5755c7fa8 100644 --- a/src/vehicle_gui_base.h +++ b/src/vehicle_gui_base.h @@ -38,7 +38,7 @@ struct BaseVehicleListWindow : public Window { static const StringID vehicle_sorter_names[]; static GUIVehicleList::SortFunction * const vehicle_sorter_funcs[]; - BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno) : Window(desc), vli(wno) + BaseVehicleListWindow(WindowDesc *desc, WindowNumber wno) : Window(desc), vli(VehicleListIdentifier::UnPack(wno)) { this->vehicles.SetSortFuncs(this->vehicle_sorter_funcs); } diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp index 7e42b25aa..f1f5d0424 100644 --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -37,7 +37,7 @@ uint32 VehicleListIdentifier::Pack() const * @param data The data to unpack. * @return true iff the data was valid (enough). */ -bool VehicleListIdentifier::Unpack(uint32 data) +bool VehicleListIdentifier::UnpackIfValid(uint32 data) { byte c = GB(data, 28, 4); this->company = c == 0xF ? OWNER_NONE : (CompanyID)c; @@ -52,10 +52,12 @@ bool VehicleListIdentifier::Unpack(uint32 data) * Decode a packed vehicle list identifier into a new one. * @param data The data to unpack. */ -VehicleListIdentifier::VehicleListIdentifier(uint32 data) +/* static */ VehicleListIdentifier VehicleListIdentifier::UnPack(uint32 data) { - bool ret = this->Unpack(data); + VehicleListIdentifier result; + bool ret = result.UnpackIfValid(data); assert(ret); + return result; } /** diff --git a/src/vehiclelist.h b/src/vehiclelist.h index c96fb692a..996c8c007 100644 --- a/src/vehiclelist.h +++ b/src/vehiclelist.h @@ -35,7 +35,8 @@ struct VehicleListIdentifier { uint32 index; ///< A vehicle list type specific index. uint32 Pack() const; - bool Unpack(uint32 data); + bool UnpackIfValid(uint32 data); + static VehicleListIdentifier UnPack(uint32 data); /** * Create a simple vehicle list. @@ -47,7 +48,7 @@ struct VehicleListIdentifier { VehicleListIdentifier(VehicleListType type, VehicleType vtype, CompanyID company, uint index = 0) : type(type), vtype(vtype), company(company), index(index) {} - VehicleListIdentifier(uint32 data = 0); + VehicleListIdentifier() : type(), vtype(), company(), index() {} }; /** A list of vehicles. */ |