(svn r27677) -Codechange: Remove implicit VehicleListIdentifier from uint32 constructor, to make conversions more explicit.

This commit is contained in:
frosch 2016-11-05 19:16:59 +00:00
parent d9bfe88261
commit 476b2b0e8c
5 changed files with 12 additions and 9 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;
}
/**

View File

@ -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. */