vehicle_gui.c
changeset 2676 59b65b4fb480
parent 2639 eeaefdabfdfd
child 2697 97fc22baf3da
equal deleted inserted replaced
2675:010fe459fc1d 2676:59b65b4fb480
    16 #include "command.h"
    16 #include "command.h"
    17 #include "gfx.h"
    17 #include "gfx.h"
    18 #include "variables.h"
    18 #include "variables.h"
    19 #include "vehicle_gui.h"
    19 #include "vehicle_gui.h"
    20 #include "viewport.h"
    20 #include "viewport.h"
       
    21 #include "train.h"
    21 
    22 
    22 Sorting _sorting;
    23 Sorting _sorting;
    23 
    24 
    24 static uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names
    25 static uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names
    25 static uint32 _last_vehicle_idx;        // cached index to hopefully speed up name-sorting
    26 static uint32 _last_vehicle_idx;        // cached index to hopefully speed up name-sorting
   103 		}
   104 		}
   104 }
   105 }
   105 
   106 
   106 void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID station)
   107 void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID station)
   107 {
   108 {
   108 	uint subtype = (type != VEH_Aircraft) ? TS_Front_Engine : 2;
   109 	uint subtype = (type != VEH_Aircraft) ? Train_Front : 2;
   109 	uint n = 0;
   110 	uint n = 0;
   110 	uint i;
   111 	uint i;
   111 
   112 
   112 	if (!(vl->flags & VL_REBUILD)) return;
   113 	if (!(vl->flags & VL_REBUILD)) return;
   113 
   114 
   120 		owner, station);
   121 		owner, station);
   121 
   122 
   122 	if (station != INVALID_STATION) {
   123 	if (station != INVALID_STATION) {
   123 		const Vehicle *v;
   124 		const Vehicle *v;
   124 		FOR_ALL_VEHICLES(v) {
   125 		FOR_ALL_VEHICLES(v) {
   125 			if (v->type == type && v->subtype <= subtype) {
   126 			if (v->type == type && (
       
   127 				(type == VEH_Train && IsFrontEngine(v)) ||
       
   128 				(type != VEH_Train && v->subtype <= subtype))) {
   126 				const Order *order;
   129 				const Order *order;
   127 
   130 
   128 				FOR_VEHICLE_ORDERS(v, order) {
   131 				FOR_VEHICLE_ORDERS(v, order) {
   129 					if (order->type == OT_GOTO_STATION && order->station == station) {
   132 					if (order->type == OT_GOTO_STATION && order->station == station) {
   130 						_vehicle_sort[n].index = v->index;
   133 						_vehicle_sort[n].index = v->index;
   136 			}
   139 			}
   137 		}
   140 		}
   138 	} else {
   141 	} else {
   139 		const Vehicle *v;
   142 		const Vehicle *v;
   140 		FOR_ALL_VEHICLES(v) {
   143 		FOR_ALL_VEHICLES(v) {
   141 			if (v->type == type && v->subtype <= subtype && v->owner == owner) {
   144 			if (v->type == type && v->owner == owner && (
       
   145 				(type == VEH_Train && IsFrontEngine(v)) ||
       
   146 				(type != VEH_Train && v->subtype <= subtype))) {
   142 				_vehicle_sort[n].index = v->index;
   147 				_vehicle_sort[n].index = v->index;
   143 				_vehicle_sort[n].owner = v->owner;
   148 				_vehicle_sort[n].owner = v->owner;
   144 				++n;
   149 				++n;
   145 			}
   150 			}
   146 		}
   151 		}