diff options
author | michi_cc <michi_cc@openttd.org> | 2011-12-13 01:18:40 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2011-12-13 01:18:40 +0000 |
commit | 7f8162c324551e87cb2218bd0023fa7cfbe344b0 (patch) | |
tree | eabfb6a3a3c17389f1b677c7fb3c004a3ac430b7 | |
parent | 2a776a6ca3ae911fe6f801684e12312b7ee7f998 (diff) | |
download | openttd-7f8162c324551e87cb2218bd0023fa7cfbe344b0.tar.xz |
(svn r23508) -Add: Engine sorter for aircraft range.
-rw-r--r-- | src/build_vehicle_gui.cpp | 20 | ||||
-rw-r--r-- | src/lang/english.txt | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 43b109030..886f38c93 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -403,6 +403,24 @@ static int CDECL AircraftEngineCargoSorter(const EngineID *a, const EngineID *b) return _internal_sort_order ? -r : r; } +/** + * Determines order of aircraft by range. + * @param *a first engine to compare. + * @param *b second engine to compare. + * @return for descending order: returns < 0 if a < b and > 0 for a > b. Vice versa for ascending order and 0 for equal. + */ +static int CDECL AircraftRangeSorter(const EngineID *a, const EngineID *b) +{ + uint16 r_a = Engine::Get(*a)->GetRange(); + uint16 r_b = Engine::Get(*b)->GetRange(); + + int r = r_a - r_b; + + /* Use EngineID to sort instead since we want consistent sorting */ + if (r == 0) return EngineNumberSorter(a, b); + return _internal_sort_order ? -r : r; +} + static EngList_SortTypeFunction * const _sorter[][11] = {{ /* Trains */ &EngineNumberSorter, @@ -449,6 +467,7 @@ static EngList_SortTypeFunction * const _sorter[][11] = {{ &EngineRunningCostSorter, &EngineReliabilitySorter, &AircraftEngineCargoSorter, + &AircraftRangeSorter, }}; static const StringID _sort_listing[][12] = {{ @@ -500,6 +519,7 @@ static const StringID _sort_listing[][12] = {{ STR_SORT_BY_RUNNING_COST, STR_SORT_BY_RELIABILITY, STR_SORT_BY_CARGO_CAPACITY, + STR_SORT_BY_RANGE, INVALID_STRING_ID }}; diff --git a/src/lang/english.txt b/src/lang/english.txt index dc81d5968..565568f01 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -287,6 +287,7 @@ STR_SORT_BY_INTRO_DATE :Introduction Da STR_SORT_BY_RUNNING_COST :Running Cost STR_SORT_BY_POWER_VS_RUNNING_COST :Power/Running Cost STR_SORT_BY_CARGO_CAPACITY :Cargo Capacity +STR_SORT_BY_RANGE :Range # Tooltips for the main toolbar STR_TOOLBAR_TOOLTIP_PAUSE_GAME :{BLACK}Pause game |