--- a/src/build_vehicle_gui.cpp Thu Dec 27 15:05:46 2007 +0000
+++ b/src/build_vehicle_gui.cpp Thu Dec 27 15:47:08 2007 +0000
@@ -268,6 +268,38 @@
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 @@
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 @@
}, {
/* Road vehicles */
&EngineNumberSorter,
+ &RoadVehEngineCostSorter,
+ &RoadVehEngineSpeedSorter,
&EngineIntroDateSorter,
&EngineNameSorter,
+ &RoadVehEngineRunningCostSorter,
&EngineReliabilitySorter,
&RoadVehEngineCapacitySorter,
}, {
/* Ships */
&EngineNumberSorter,
+ &ShipEngineCostSorter,
+ &ShipEngineSpeedSorter,
&EngineIntroDateSorter,
&EngineNameSorter,
+ &ShipEngineRunningCostSorter,
&EngineReliabilitySorter,
&ShipEngineCapacitySorter,
}, {
@@ -405,16 +475,22 @@
}, {
/* 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