vehiclelist.cpp
Go to the documentation of this file.00001
00002
00005 #include "stdafx.h"
00006 #include "vehicle_gui.h"
00007 #include "train.h"
00008 #include "vehiclelist.h"
00009
00018 void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engines, VehicleList *wagons, bool individual_wagons)
00019 {
00020 engines->Clear();
00021 if (wagons != NULL && wagons != engines) wagons->Clear();
00022
00023 const Vehicle *v;
00024 FOR_ALL_VEHICLES(v) {
00025
00026 if (v->type != type) continue;
00027 if (v->tile != tile) continue;
00028
00029 switch (type) {
00030 case VEH_TRAIN:
00031 if (IsArticulatedPart(v) || IsRearDualheaded(v)) continue;
00032 if (v->u.rail.track != TRACK_BIT_DEPOT) continue;
00033 if (wagons != NULL && IsFreeWagon(v->First())) {
00034 if (individual_wagons || IsFreeWagon(v)) *wagons->Append() = v;
00035 continue;
00036 }
00037 break;
00038
00039 default:
00040 if (!v->IsInDepot()) continue;
00041 break;
00042 }
00043
00044 if (!v->IsPrimaryVehicle()) continue;
00045
00046 *engines->Append() = v;
00047 }
00048
00049
00050
00051 engines->Compact();
00052 if (wagons != NULL && wagons != engines) wagons->Compact();
00053 }
00054
00071 void GenerateVehicleSortList(VehicleList *list, VehicleType type, Owner owner, uint32 index, uint16 window_type)
00072 {
00073 list->Clear();
00074
00075 const Vehicle *v;
00076
00077 switch (window_type) {
00078 case VLW_STATION_LIST:
00079 FOR_ALL_VEHICLES(v) {
00080 if (v->type == type && v->IsPrimaryVehicle()) {
00081 const Order *order;
00082
00083 FOR_VEHICLE_ORDERS(v, order) {
00084 if (order->IsType(OT_GOTO_STATION) && order->GetDestination() == index) {
00085 *list->Append() = v;
00086 break;
00087 }
00088 }
00089 }
00090 }
00091 break;
00092
00093 case VLW_SHARED_ORDERS:
00094
00095 for (v = GetVehicle(index); v != NULL; v = v->NextShared()) {
00096 *list->Append() = v;
00097 }
00098 break;
00099
00100 case VLW_STANDARD:
00101 FOR_ALL_VEHICLES(v) {
00102 if (v->type == type && v->owner == owner && v->IsPrimaryVehicle()) {
00103 *list->Append() = v;
00104 }
00105 }
00106 break;
00107
00108 case VLW_DEPOT_LIST:
00109 FOR_ALL_VEHICLES(v) {
00110 if (v->type == type && v->IsPrimaryVehicle()) {
00111 const Order *order;
00112
00113 FOR_VEHICLE_ORDERS(v, order) {
00114 if (order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == index) {
00115 *list->Append() = v;
00116 break;
00117 }
00118 }
00119 }
00120 }
00121 break;
00122
00123 case VLW_WAYPOINT_LIST:
00124 FOR_ALL_VEHICLES(v) {
00125 if (v->type == type && v->IsPrimaryVehicle()) {
00126 const Order *order;
00127
00128 FOR_VEHICLE_ORDERS(v, order) {
00129 if (order->IsType(OT_GOTO_WAYPOINT) && order->GetDestination() == index) {
00130 *list->Append() = v;
00131 break;
00132 }
00133 }
00134 }
00135 }
00136 break;
00137
00138 case VLW_GROUP_LIST:
00139 FOR_ALL_VEHICLES(v) {
00140 if (v->type == type && v->IsPrimaryVehicle() &&
00141 v->owner == owner && v->group_id == index) {
00142 *list->Append() = v;
00143 }
00144 }
00145 break;
00146
00147 default: NOT_REACHED(); break;
00148 }
00149
00150 list->Compact();
00151 }