summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2007-12-27 15:47:08 +0000
committerbjarni <bjarni@openttd.org>2007-12-27 15:47:08 +0000
commit6196fa01aba63d03b7dbeafa6a67b271192599ce (patch)
tree82dd8949025a88fd58979849dbca88b4f59846a8
parent2ecb31ae3fa65881352a14577e755446bb691b97 (diff)
downloadopenttd-6196fa01aba63d03b7dbeafa6a67b271192599ce.tar.xz
(svn r11710) -Feature: [build vehicles windows] added sorting for cost, running costs and speed to road vehicles and ships build windows
-rw-r--r--src/build_vehicle_gui.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 628d85804..c9b3661f4 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -268,6 +268,38 @@ static int CDECL TrainEnginesThenWagonsSorter(const void *a, const void *b)
return _internal_sort_order ? -r : r;
}
+/* Road vehicle sorting functions */
+static int CDECL RoadVehEngineCostSorter(const void *a, const void *b)
+{
+ int va = RoadVehInfo(*(const EngineID*)a)->base_cost;
+ int vb = RoadVehInfo(*(const EngineID*)b)->base_cost;
+ int r = va - vb;
+
+ return _internal_sort_order ? -r : r;
+}
+
+static int CDECL RoadVehEngineSpeedSorter(const void *a, const void *b)
+{
+ int va = RoadVehInfo(*(const EngineID*)a)->max_speed;
+ int vb = RoadVehInfo(*(const EngineID*)b)->max_speed;
+ int r = va - vb;
+
+ return _internal_sort_order ? -r : r;
+}
+
+static int CDECL RoadVehEngineRunningCostSorter(const void *a, const void *b)
+{
+ const int va = RoadVehInfo(*(const EngineID*)a)->running_cost;
+ const int vb = RoadVehInfo(*(const EngineID*)b)->running_cost;
+ const 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 RoadVehEngineCapacitySorter(const void *a, const void *b)
{
int va = RoadVehInfo(*(const EngineID*)a)->capacity;
@@ -281,6 +313,38 @@ static int CDECL RoadVehEngineCapacitySorter(const void *a, const void *b)
return _internal_sort_order ? -r : r;
}
+/* Road vehicle sorting functions */
+static int CDECL ShipEngineCostSorter(const void *a, const void *b)
+{
+ int va = ShipVehInfo(*(const EngineID*)a)->base_cost;
+ int vb = ShipVehInfo(*(const EngineID*)b)->base_cost;
+ int r = va - vb;
+
+ return _internal_sort_order ? -r : r;
+}
+
+static int CDECL ShipEngineSpeedSorter(const void *a, const void *b)
+{
+ int va = ShipVehInfo(*(const EngineID*)a)->max_speed;
+ int vb = ShipVehInfo(*(const EngineID*)b)->max_speed;
+ int r = va - vb;
+
+ return _internal_sort_order ? -r : r;
+}
+
+static int CDECL ShipEngineRunningCostSorter(const void *a, const void *b)
+{
+ const int va = ShipVehInfo(*(const EngineID*)a)->running_cost;
+ const int vb = ShipVehInfo(*(const EngineID*)b)->running_cost;
+ const 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;
@@ -366,15 +430,21 @@ static EngList_SortTypeFunction * const _sorter[][10] = {{
}, {
/* Road vehicles */
&EngineNumberSorter,
+ &RoadVehEngineCostSorter,
+ &RoadVehEngineSpeedSorter,
&EngineIntroDateSorter,
&EngineNameSorter,
+ &RoadVehEngineRunningCostSorter,
&EngineReliabilitySorter,
&RoadVehEngineCapacitySorter,
}, {
/* Ships */
&EngineNumberSorter,
+ &ShipEngineCostSorter,
+ &ShipEngineSpeedSorter,
&EngineIntroDateSorter,
&EngineNameSorter,
+ &ShipEngineRunningCostSorter,
&EngineReliabilitySorter,
&ShipEngineCapacitySorter,
}, {
@@ -405,16 +475,22 @@ static const StringID _sort_listing[][11] = {{
}, {
/* Road vehicles */
STR_ENGINE_SORT_ENGINE_ID,
+ STR_ENGINE_SORT_COST,
+ STR_SORT_BY_MAX_SPEED,
STR_ENGINE_SORT_INTRO_DATE,
STR_SORT_BY_DROPDOWN_NAME,
+ STR_ENGINE_SORT_RUNNING_COST,
STR_SORT_BY_RELIABILITY,
STR_ENGINE_SORT_CARGO_CAPACITY,
INVALID_STRING_ID
}, {
/* Ships */
STR_ENGINE_SORT_ENGINE_ID,
+ STR_ENGINE_SORT_COST,
+ STR_SORT_BY_MAX_SPEED,
STR_ENGINE_SORT_INTRO_DATE,
STR_SORT_BY_DROPDOWN_NAME,
+ STR_ENGINE_SORT_RUNNING_COST,
STR_SORT_BY_RELIABILITY,
STR_ENGINE_SORT_CARGO_CAPACITY,
INVALID_STRING_ID