(svn r13760) -Codechange: With multiple NewGRF engine sets, engine IDs may not be allocated in the order expected by GRF authors, so sort by 'list position' instead of engine ID for all vehicle types.
authorpeter1138
Sun, 20 Jul 2008 21:21:51 +0000
changeset 9671 6f92245afcf1
parent 9670 ce7645fdaed5
child 9672 02fe9b0dc41b
(svn r13760) -Codechange: With multiple NewGRF engine sets, engine IDs may not be allocated in the order expected by GRF authors, so sort by 'list position' instead of engine ID for all vehicle types.
src/autoreplace_gui.cpp
src/build_vehicle_gui.cpp
--- a/src/autoreplace_gui.cpp	Sun Jul 20 19:21:18 2008 +0000
+++ b/src/autoreplace_gui.cpp	Sun Jul 20 21:21:51 2008 +0000
@@ -59,7 +59,7 @@
 	RVW_WIDGET_TRAIN_WAGONREMOVE_TOGGLE,
 };
 
-static int CDECL TrainEngineNumberSorter(const void *a, const void *b)
+static int CDECL EngineNumberSorter(const void *a, const void *b)
 {
 	const EngineID va = *(const EngineID*)a;
 	const EngineID vb = *(const EngineID*)b;
@@ -213,7 +213,7 @@
 			if (eid == this->sel_engine[i]) selected_engine = eid; // The selected engine is still in the list
 		}
 		this->sel_engine[i] = selected_engine; // update which engine we selected (the same or none, if it's not in the list anymore)
-		if (type == VEH_TRAIN) EngList_Sort(list, &TrainEngineNumberSorter);
+		EngList_Sort(list, &EngineNumberSorter);
 	}
 
 	/** Generate the lists */
--- a/src/build_vehicle_gui.cpp	Sun Jul 20 19:21:18 2008 +0000
+++ b/src/build_vehicle_gui.cpp	Sun Jul 20 21:21:51 2008 +0000
@@ -71,7 +71,7 @@
 {
 	const EngineID va = *(const EngineID*)a;
 	const EngineID vb = *(const EngineID*)b;
-	int r = va - vb;
+	int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb);
 
 	return _internal_sort_order ? -r : r;
 }
@@ -193,15 +193,6 @@
 	return _internal_sort_order ? -r : r;
 }
 
-static int CDECL TrainEngineNumberSorter(const void *a, const void *b)
-{
-	const EngineID va = *(const EngineID*)a;
-	const EngineID vb = *(const EngineID*)b;
-	int r = ListPositionOfEngine(va) - ListPositionOfEngine(vb);
-
-	return _internal_sort_order ? -r : r;
-}
-
 static int CDECL TrainEngineCapacitySorter(const void *a, const void *b)
 {
 	int va = RailVehInfo(*(const EngineID*)a)->capacity;
@@ -381,7 +372,7 @@
 
 static EngList_SortTypeFunction * const _sorter[][10] = {{
 	/* Trains */
-	&TrainEngineNumberSorter,
+	&EngineNumberSorter,
 	&TrainEngineCostSorter,
 	&TrainEngineSpeedSorter,
 	&TrainEnginePowerSorter,