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