summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-06-02 15:41:37 +0000
committerbjarni <bjarni@openttd.org>2007-06-02 15:41:37 +0000
commit81698422a2806fa9d7ee6f3a32d8b2d4ec9ac8be (patch)
tree4502a2eb7b478208867ec3a6a66a629dc64ea376 /src
parent229e311cb904b43fed1a7cce821c4137ccd87630 (diff)
downloadopenttd-81698422a2806fa9d7ee6f3a32d8b2d4ec9ac8be.tar.xz
(svn r10024) -Feature: [build windows] trains, road vehicles and ships can now be sorted by cargo capacity (planes already had this option)
Diffstat (limited to 'src')
-rw-r--r--src/build_vehicle_gui.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 430ffca67..bfc896810 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -240,6 +240,19 @@ static int CDECL TrainEngineNumberSorter(const void *a, const void *b)
return _internal_sort_order ? -r : r;
}
+static int CDECL TrainEngineCapacitySorter(const void *a, const void *b)
+{
+ int va = RailVehInfo(*(const EngineID*)a)->capacity;
+ int vb = RailVehInfo(*(const EngineID*)b)->capacity;
+ int r = va - vb;
+
+ if (r == 0) {
+ /* Use EngineID to sort instead since we want consistent sorting */
+ return EngineNumberSorter(a, b);
+ }
+ return _internal_sort_order ? -r : r;
+}
+
static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
{
EngineID va = *(const EngineID*)a;
@@ -254,6 +267,32 @@ static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
return _internal_sort_order ? -r : r;
}
+static int CDECL RoadVehEngineCapacitySorter(const void *a, const void *b)
+{
+ int va = RoadVehInfo(*(const EngineID*)a)->capacity;
+ int vb = RoadVehInfo(*(const EngineID*)b)->capacity;
+ int r = va - vb;
+
+ if (r == 0) {
+ /* Use EngineID to sort instead since we want consistent sorting */
+ return EngineNumberSorter(a, b);
+ }
+ return _internal_sort_order ? -r : r;
+}
+
+static int CDECL ShipEngineCapacitySorter(const void *a, const void *b)
+{
+ int va = ShipVehInfo(*(const EngineID*)a)->capacity;
+ int vb = ShipVehInfo(*(const EngineID*)b)->capacity;
+ int r = va - vb;
+
+ if (r == 0) {
+ /* Use EngineID to sort instead since we want consistent sorting */
+ return EngineNumberSorter(a, b);
+ }
+ return _internal_sort_order ? -r : r;
+}
+
/* Aircraft sorting functions */
static int CDECL AircraftEngineCostSorter(const void *a, const void *b)
@@ -304,7 +343,7 @@ static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
return _internal_sort_order ? -r : r;
}
-static EngList_SortTypeFunction * const _sorter[][9] = {{
+static EngList_SortTypeFunction * const _sorter[][10] = {{
/* Trains */
&TrainEngineNumberSorter,
&TrainEngineCostSorter,
@@ -315,18 +354,21 @@ static EngList_SortTypeFunction * const _sorter[][9] = {{
&TrainEngineRunningCostSorter,
&TrainEnginePowerVsRunningCostSorter,
&EngineReliabilitySorter,
+ &TrainEngineCapacitySorter,
}, {
/* Road vehicles */
&EngineNumberSorter,
&EngineIntroDateSorter,
&EngineNameSorter,
&EngineReliabilitySorter,
+ &RoadVehEngineCapacitySorter,
}, {
/* Ships */
&EngineNumberSorter,
&EngineIntroDateSorter,
&EngineNameSorter,
&EngineReliabilitySorter,
+ &ShipEngineCapacitySorter,
}, {
/* Aircraft */
&EngineNumberSorter,
@@ -339,7 +381,7 @@ static EngList_SortTypeFunction * const _sorter[][9] = {{
&AircraftEngineCargoSorter,
}};
-static const StringID _sort_listing[][10] = {{
+static const StringID _sort_listing[][11] = {{
/* Trains */
STR_ENGINE_SORT_ENGINE_ID,
STR_ENGINE_SORT_COST,
@@ -350,6 +392,7 @@ static const StringID _sort_listing[][10] = {{
STR_ENGINE_SORT_RUNNING_COST,
STR_ENGINE_SORT_POWER_VS_RUNNING_COST,
STR_SORT_BY_RELIABILITY,
+ STR_ENGINE_SORT_CARGO_CAPACITY,
INVALID_STRING_ID
}, {
/* Road vehicles */
@@ -357,6 +400,7 @@ static const StringID _sort_listing[][10] = {{
STR_ENGINE_SORT_INTRO_DATE,
STR_SORT_BY_DROPDOWN_NAME,
STR_SORT_BY_RELIABILITY,
+ STR_ENGINE_SORT_CARGO_CAPACITY,
INVALID_STRING_ID
}, {
/* Ships */
@@ -364,6 +408,7 @@ static const StringID _sort_listing[][10] = {{
STR_ENGINE_SORT_INTRO_DATE,
STR_SORT_BY_DROPDOWN_NAME,
STR_SORT_BY_RELIABILITY,
+ STR_ENGINE_SORT_CARGO_CAPACITY,
INVALID_STRING_ID
}, {
/* Aircraft */