changeset 4459:d6bbd451288c draft

(svn r6242) -Codechange: made BuildVehicleList static as it is not used in any other files anymore added window_type to arguments and used it to replace an if cascade with a switch case
author bjarni <bjarni@openttd.org>
date Wed, 30 Aug 2006 19:42:20 +0000
parents 90b8f0ff256f
children 2cc317dc208e
files vehicle_gui.c vehicle_gui.h
diffstat 2 files changed, 26 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -119,7 +119,7 @@
 		}
 }
 
-void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID station, OrderID order)
+static void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID station, OrderID order, uint16 window_type)
 {
 	const Vehicle** sort_list;
 	uint subtype = (type != VEH_Aircraft) ? Train_Front : 2;
@@ -136,25 +136,26 @@
 	DEBUG(misc, 1) ("Building vehicle list for player %d station %d...",
 		owner, station);
 
-	if (station != INVALID_STATION) {
-		const Vehicle *v;
-		FOR_ALL_VEHICLES(v) {
-			if (v->type == type && (
-						(type == VEH_Train && IsFrontEngine(v)) ||
-						(type != VEH_Train && v->subtype <= subtype)
-					)) {
-				const Order *order;
+	switch (window_type) {
+		case VLW_STATION_LIST: {
+			const Vehicle *v;
+			FOR_ALL_VEHICLES(v) {
+				if (v->type == type && (
+					(type == VEH_Train && IsFrontEngine(v)) ||
+					(type != VEH_Train && v->subtype <= subtype))) {
+					const Order *order;
 
-				FOR_VEHICLE_ORDERS(v, order) {
-					if (order->type == OT_GOTO_STATION && order->dest.station == station) {
-						sort_list[n++] = v;
-						break;
+					FOR_VEHICLE_ORDERS(v, order) {
+						if (order->type == OT_GOTO_STATION && order->dest.station == station) {
+							sort_list[n++] = v;
+							break;
+						}
 					}
 				}
 			}
-		}
-	} else {
-		if (order != INVALID_ORDER) {
+		} break;
+
+		case VLW_SHARED_ORDERS: {
 			Vehicle *v;
 			FOR_ALL_VEHICLES(v) {
 				/* Find a vehicle with the order in question */
@@ -167,16 +168,20 @@
 					sort_list[n++] = v;
 				}
 			}
-		} else {
+		} break;
+
+		case VLW_STANDARD: {
 			const Vehicle *v;
 			FOR_ALL_VEHICLES(v) {
 				if (v->type == type && v->owner == owner && (
-				    (type == VEH_Train && IsFrontEngine(v)) ||
-				    (type != VEH_Train && v->subtype <= subtype))) {
+					(type == VEH_Train && IsFrontEngine(v)) ||
+					(type != VEH_Train && v->subtype <= subtype))) {
 					sort_list[n++] = v;
 				}
 			}
-		}
+		} break;
+
+		default: NOT_REACHED(); break;
 	}
 
 	free((void*)vl->sort_list);
@@ -1227,7 +1232,7 @@
 			const StationID station = (window_type == VLW_STATION_LIST)  ? GB(w->window_number, 16, 16) : INVALID_STATION;
 			const OrderID order     = (window_type == VLW_SHARED_ORDERS) ? GB(w->window_number, 16, 16) : INVALID_ORDER;
 
-			BuildVehicleList(vl, vehicle_type, owner, station, order);
+			BuildVehicleList(vl, vehicle_type, owner, station, order, window_type);
 			SortVehicleList(vl);
 			SetVScrollCount(w, vl->list_length);
 
--- a/vehicle_gui.h
+++ b/vehicle_gui.h
@@ -17,7 +17,6 @@
 void RebuildVehicleLists(void);
 void ResortVehicleLists(void);
 
-void BuildVehicleList(struct vehiclelist_d* vl, int type, PlayerID, StationID, uint16 order);
 void SortVehicleList(struct vehiclelist_d *vl);
 
 #define PERIODIC_RESORT_DAYS 10