Changeset - r16068:f32ba8cfc408
[Not reviewed]
master
0 6 0
rubidium - 14 years ago 2010-09-08 21:28:50
rubidium@openttd.org
(svn r20771) -Add: concept of vehicle list identifiers to identify a vehicle list instead of a string of parameters
6 files changed with 69 insertions and 47 deletions:
0 comments (0 inline, 0 general)
src/group_gui.cpp
Show inline comments
 
@@ -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);
src/vehicle_cmd.cpp
Show inline comments
 
@@ -456,7 +456,8 @@ CommandCost CmdMassStartStopVehicle(Tile
 
		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 ti
 

	
 
/**
 
 * 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(TileIn
 
	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));
src/vehicle_gui.cpp
Show inline comments
 
@@ -99,13 +99,13 @@ const StringID BaseVehicleListWindow::ve
 
	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)) {
src/vehicle_gui_base.h
Show inline comments
 
@@ -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 Wi
 

	
 
	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);
 
};
src/vehiclelist.cpp
Show inline comments
 
@@ -63,35 +63,25 @@ void BuildDepotVehicleList(VehicleType t
 

	
 
/**
 
 * 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
 
			}
 
			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
 
			}
 
			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;
 
				}
 
			}
src/vehiclelist.h
Show inline comments
 
@@ -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 */
0 comments (0 inline, 0 general)