diff options
author | rubidium <rubidium@openttd.org> | 2010-09-08 21:28:50 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-09-08 21:28:50 +0000 |
commit | 881c6c679ff2606111cb890847147556142c3451 (patch) | |
tree | 2e4aa38f456a4510380f6614c93ccdba46590c47 | |
parent | 0e840f7360895ae9759a556b011759fc4662b213 (diff) | |
download | openttd-881c6c679ff2606111cb890847147556142c3451.tar.xz |
(svn r20771) -Add: concept of vehicle list identifiers to identify a vehicle list instead of a string of parameters
-rw-r--r-- | src/group_gui.cpp | 6 | ||||
-rw-r--r-- | src/vehicle_cmd.cpp | 19 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 12 | ||||
-rw-r--r-- | src/vehicle_gui_base.h | 3 | ||||
-rw-r--r-- | src/vehiclelist.cpp | 46 | ||||
-rw-r--r-- | src/vehiclelist.h | 30 |
6 files changed, 69 insertions, 47 deletions
diff --git a/src/group_gui.cpp b/src/group_gui.cpp index b93a9e550..f51025e6f 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 3b27d7872..50790c6bf 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 5b6738a34..694e96a45 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 2de44727c..6f7e4004f 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 6f5ca7c34..20a994e3c 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 - * <ul> - * <li>VLW_STATION_LIST: index of station/waypoint to generate a list for</li> - * <li>VLW_SHARED_ORDERS: index of order to generate a list for<li> - * <li>VLW_STANDARD: not used<li> - * <li>VLW_DEPOT_LIST: TileIndex of the depot/hangar to make the list for</li> - * <li>VLW_GROUP_LIST: index of group to generate a list for</li> - * </ul> - * @param window_type The type of window the list is for, using the VLW_ flags in vehicle_gui.h + * @param list Pointer to list to add vehicles to + * @param vli The identifier of this vehicle list. * @return false if invalid list is requested */ -bool GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, uint32 index, uint16 window_type) +bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli) { list->Clear(); const Vehicle *v; - switch (window_type) { - case VLW_STATION_LIST: + switch (vli.type) { + case VL_STATION_LIST: FOR_ALL_VEHICLES(v) { - if (v->type == type && v->IsPrimaryVehicle()) { + if (v->type == vli.type && v->IsPrimaryVehicle()) { const Order *order; FOR_VEHICLE_ORDERS(v, order) { if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) - && order->GetDestination() == index) { + && order->GetDestination() == vli.index) { *list->Append() = v; break; } @@ -100,31 +90,31 @@ bool GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, u } break; - case VLW_SHARED_ORDERS: + case VL_SHARED_ORDERS: /* Add all vehicles from this vehicle's shared order list */ - v = Vehicle::GetIfValid(index); - if (v == NULL || v->type != type || !v->IsPrimaryVehicle()) return false; + v = Vehicle::GetIfValid(vli.index); + if (v == NULL || v->type != vli.type || !v->IsPrimaryVehicle()) return false; for (; v != NULL; v = v->NextShared()) { *list->Append() = v; } break; - case VLW_STANDARD: + case VL_STANDARD: FOR_ALL_VEHICLES(v) { - if (v->type == type && v->owner == owner && v->IsPrimaryVehicle()) { + if (v->type == vli.type && v->owner == vli.company && v->IsPrimaryVehicle()) { *list->Append() = v; } } break; - case VLW_DEPOT_LIST: + case VL_DEPOT_LIST: FOR_ALL_VEHICLES(v) { - if (v->type == type && v->IsPrimaryVehicle()) { + if (v->type == vli.type && v->IsPrimaryVehicle()) { const Order *order; FOR_VEHICLE_ORDERS(v, order) { - if (order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == index) { + if (order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == vli.index) { *list->Append() = v; break; } @@ -133,10 +123,10 @@ bool GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, u } break; - case VLW_GROUP_LIST: + case VL_GROUP_LIST: FOR_ALL_VEHICLES(v) { - if (v->type == type && v->IsPrimaryVehicle() && - v->owner == owner && v->group_id == index) { + if (v->type == vli.type && 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 18357b941..5c13f326b 100644 --- a/src/vehiclelist.h +++ b/src/vehiclelist.h @@ -17,9 +17,37 @@ #include "company_type.h" #include "tile_type.h" +/** Vehicle List type flags */ +enum VehicleListType { + VL_STANDARD, + VL_SHARED_ORDERS, + VL_STATION_LIST, + VL_DEPOT_LIST, + VL_GROUP_LIST, + VLT_END +}; + +/** The information about a vehicle list. */ +struct VehicleListIdentifier { + VehicleListType type; ///< The type of vehicle list. + VehicleType vtype; ///< The vehicle type associated with this list. + CompanyID company; ///< The company associated with this list. + uint32 index; ///< A vehicle list type specific index. + + /** + * Create a simple vehicle list. + * @param type List type. + * @param vtype Vehicle type associated with this list. + * @param company Company associated with this list. + * @param index Optional type specific index. + */ + VehicleListIdentifier(VehicleListType type, VehicleType vtype, CompanyID company, uint index = 0) : + type(type), vtype(vtype), company(company), index(index) {} +}; + typedef SmallVector<const Vehicle *, 32> VehicleList; -bool GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, uint32 index, uint16 window_type); +bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &identifier); void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine_list, VehicleList *wagon_list, bool individual_wagons = false); #endif /* VEHICLELIST_H */ |