Mercurial > hg > openttd
changeset 8148:20f4268aa1e4 draft
(svn r11710) -Feature: [build vehicles windows] added sorting for cost, running costs and speed to road vehicles and ships build windows
author | bjarni <bjarni@openttd.org> |
---|---|
date | Thu, 27 Dec 2007 15:47:08 +0000 |
parents | 3bc5b36c9713 |
children | ad7ddb6150dc |
files | src/build_vehicle_gui.cpp |
diffstat | 1 files changed, 76 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -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