summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-05-24 12:12:02 +0000
committerpeter1138 <peter1138@openttd.org>2008-05-24 12:12:02 +0000
commitc34b458ace0695fd89116dc29de4e1bec5fca89b (patch)
treeaf19fee07344e442e38fd97e1a537fa0879445e1 /src
parent68bb5a08c50e6c25a26625fc324609d2fd93989a (diff)
downloadopenttd-c34b458ace0695fd89116dc29de4e1bec5fca89b.tar.xz
(svn r13232) -Codechange: Simplify BuildDepotVehicleList()
Diffstat (limited to 'src')
-rw-r--r--src/vehicle.cpp64
1 files changed, 20 insertions, 44 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 90354da3b..8796eca34 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1333,8 +1333,6 @@ static inline void ExtendVehicleListSize(const Vehicle ***engine_list, uint16 *e
*/
void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_list, uint16 *engine_list_length, uint16 *engine_count, Vehicle ***wagon_list, uint16 *wagon_list_length, uint16 *wagon_count)
{
- Vehicle *v;
-
/* This function should never be called without an array to store results */
assert(!(engine_list == NULL && type != VEH_TRAIN));
assert(!(type == VEH_TRAIN && engine_list == NULL && wagon_list == NULL));
@@ -1349,53 +1347,31 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, Vehicle ***engine_l
if (engine_count != NULL) *engine_count = 0;
if (wagon_count != NULL) *wagon_count = 0;
- switch (type) {
- case VEH_TRAIN:
- FOR_ALL_VEHICLES(v) {
- if (v->tile == tile && v->type == VEH_TRAIN && v->u.rail.track == TRACK_BIT_DEPOT) {
- if (IsFrontEngine(v)) {
- if (engine_list == NULL) continue;
- if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25);
- (*engine_list)[(*engine_count)++] = v;
- } else if (IsFreeWagon(v)) {
- if (wagon_list == NULL) continue;
- if (*wagon_count == *wagon_list_length) ExtendVehicleListSize((const Vehicle***)wagon_list, wagon_list_length, 25);
- (*wagon_list)[(*wagon_count)++] = v;
- }
- }
- }
- break;
+ Vehicle *v;
+ FOR_ALL_VEHICLES(v) {
+ /* General tests for all vehicle types */
+ if (v->type != type) continue;
+ if (v->tile != tile) continue;
- case VEH_ROAD:
- FOR_ALL_VEHICLES(v) {
- if (v->tile == tile && v->type == VEH_ROAD && v->IsInDepot() && IsRoadVehFront(v)) {
- if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25);
- (*engine_list)[(*engine_count)++] = v;
+ switch (type) {
+ case VEH_TRAIN:
+ if (v->u.rail.track != TRACK_BIT_DEPOT) continue;
+ if (wagon_list != NULL && IsFreeWagon(v)) {
+ if (*wagon_count == *wagon_list_length) ExtendVehicleListSize((const Vehicle***)wagon_list, wagon_list_length, 25);
+ (*wagon_list)[(*wagon_count)++] = v;
+ continue;
}
- }
- break;
+ break;
- case VEH_SHIP:
- FOR_ALL_VEHICLES(v) {
- if (v->tile == tile && v->type == VEH_SHIP && v->IsInDepot()) {
- if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25);
- (*engine_list)[(*engine_count)++] = v;
- }
- }
- break;
+ default:
+ if (!v->IsInDepot()) continue;
+ break;
+ }
- case VEH_AIRCRAFT:
- FOR_ALL_VEHICLES(v) {
- if (v->tile == tile &&
- v->type == VEH_AIRCRAFT && IsNormalAircraft(v) &&
- v->IsInDepot()) {
- if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25);
- (*engine_list)[(*engine_count)++] = v;
- }
- }
- break;
+ if (!v->IsPrimaryVehicle()) continue;
- default: NOT_REACHED();
+ if (*engine_count == *engine_list_length) ExtendVehicleListSize((const Vehicle***)engine_list, engine_list_length, 25);
+ (*engine_list)[(*engine_count)++] = v;
}
}