diff --git a/src/group_gui.cpp b/src/group_gui.cpp index b93a9e5503..f51025e6fc 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -190,7 +190,8 @@ public: this->vehicles.SetListing(*this->sorting); this->vehicles.ForceRebuild(); this->vehicles.NeedResort(); - this->BuildVehicleList(owner, this->group_sel, IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST); + VehicleListIdentifier vli(IsAllGroupID(this->group_sel) ? VL_STANDARD : VL_GROUP_LIST, this->vehicle_type, owner, this->group_sel); + this->BuildVehicleList(vli); this->SortVehicleList(); this->groups.ForceRebuild(); @@ -302,7 +303,8 @@ public: /* 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 */ - this->BuildVehicleList(owner, this->group_sel, IsAllGroupID(this->group_sel) ? VLW_STANDARD : VLW_GROUP_LIST); + VehicleListIdentifier vli(IsAllGroupID(this->group_sel) ? VL_STANDARD : VL_GROUP_LIST, this->vehicle_type, owner, this->group_sel); + this->BuildVehicleList(vli); this->SortVehicleList(); this->BuildGroupList(owner); diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 3b27d7872f..50790c6bf2 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -456,7 +456,8 @@ CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 uint32 id = GB(p2, 16, 16); uint16 window_type = p2 & VLW_MASK; - if (!GenerateVehicleSortList(&list, vehicle_type, _current_company, id, window_type)) return CMD_ERROR; + VehicleListIdentifier vli((VehicleListType)(window_type >> 8), vehicle_type, _current_company, id); + if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR; } else { /* Get the list of vehicles in the depot */ BuildDepotVehicleList(vehicle_type, tile, &list, NULL); @@ -806,25 +807,22 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint /** * Send all vehicles of type to depots - * @param type type of vehicle - * @param flags the flags used for DoCommand() + * @param flags the flags used for DoCommand() * @param service should the vehicles only get service in the depots - * @param owner owner of the vehicles to send - * @param vlw_flag tells what kind of list requested the goto depot - * @param id general purpose id whoms meaning is given by @c vlw_flag; e.g. StationID for station lists + * @param vli identifier of the vehicle list * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot */ -CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id) +CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, const VehicleListIdentifier &vli) { VehicleList list; - if (!GenerateVehicleSortList(&list, type, owner, id, vlw_flag)) return CMD_ERROR; + if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR; /* Send all the vehicles to a depot */ bool had_success = false; for (uint i = 0; i < list.Length(); i++) { const Vehicle *v = list[i]; - CommandCost ret = DoCommand(v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0, flags, GetCmdSendToDepot(type)); + CommandCost ret = DoCommand(v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0, flags, GetCmdSendToDepot(vli.vtype)); if (ret.Succeeded()) { had_success = true; @@ -859,7 +857,8 @@ CommandCost CmdSendVehicleToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1 if (p1 & DEPOT_MASS_SEND) { /* Mass goto depot requested */ if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; - return SendAllVehiclesToDepot((VehicleType)GB(p2, 11, 2), flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), GB(p1, 0, 20)); + VehicleListIdentifier vli((VehicleListType)((p2 & VLW_MASK) >> 8), (VehicleType)GB(p2, 11, 2), _current_company, GB(p1, 0, 20)); + return SendAllVehiclesToDepot(flags, (p2 & DEPOT_SERVICE) != 0, vli); } Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 20)); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 5b6738a34e..694e96a454 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -99,13 +99,13 @@ const StringID BaseVehicleListWindow::vehicle_depot_name[] = { STR_VEHICLE_LIST_SEND_AIRCRAFT_TO_HANGAR }; -void BaseVehicleListWindow::BuildVehicleList(Owner owner, uint16 index, uint16 window_type) +void BaseVehicleListWindow::BuildVehicleList(const VehicleListIdentifier &vli) { if (!this->vehicles.NeedRebuild()) return; - DEBUG(misc, 3, "Building vehicle list for company %d at station %d", owner, index); + DEBUG(misc, 3, "Building vehicle list for company %d at station %d", vli.company, vli.index); - GenerateVehicleSortList(&this->vehicles, this->vehicle_type, owner, index, window_type); + GenerateVehicleSortList(&this->vehicles, vli); uint unitnumber = 0; for (const Vehicle **v = this->vehicles.Begin(); v != this->vehicles.End(); v++) { @@ -1108,7 +1108,8 @@ public: this->vehicles.SetListing(*this->sorting); this->vehicles.ForceRebuild(); this->vehicles.NeedResort(); - this->BuildVehicleList(company, GB(window_number, 16, 16), window_type); + 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 */ @@ -1222,7 +1223,8 @@ public: { const uint16 window_type = this->window_number & VLW_MASK; - this->BuildVehicleList(this->owner, GB(this->window_number, 16, 16), window_type); + VehicleListIdentifier vli((VehicleListType)(window_type >> 8), this->vehicle_type, this->owner, GB(this->window_number, 16, 16)); + this->BuildVehicleList(vli); this->SortVehicleList(); if (this->vehicles.Length() == 0 && this->IsWidgetLowered(VLW_WIDGET_MANAGE_VEHICLES_DROPDOWN)) { diff --git a/src/vehicle_gui_base.h b/src/vehicle_gui_base.h index 2de44727c1..6f7e4004f6 100644 --- a/src/vehicle_gui_base.h +++ b/src/vehicle_gui_base.h @@ -13,6 +13,7 @@ #define VEHICLE_GUI_BASE_H #include "sortlist_type.h" +#include "vehiclelist.h" #include "window_gui.h" #include "widgets/dropdown_type.h" @@ -44,7 +45,7 @@ struct BaseVehicleListWindow : public Window { void DrawVehicleListItems(VehicleID selected_vehicle, int line_height, const Rect &r) const; void SortVehicleList(); - void BuildVehicleList(Owner owner, uint16 index, uint16 window_type); + void BuildVehicleList(const VehicleListIdentifier &identifier); Dimension GetActionDropdownSize(bool show_autoreplace, bool show_group); DropDownList *BuildActionDropdownList(bool show_autoreplace, bool show_group); }; diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp index 6f5ca7c349..20a994e3c0 100644 --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -63,35 +63,25 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine /** * Generate a list of vehicles based on window type. - * @param list Pointer to list to add vehicles to - * @param type Type of vehicle - * @param owner Company to generate list for - * @param index This parameter has different meanings depending on window_type - *