From 7f8162c324551e87cb2218bd0023fa7cfbe344b0 Mon Sep 17 00:00:00 2001 From: michi_cc Date: Tue, 13 Dec 2011 01:18:40 +0000 Subject: (svn r23508) -Add: Engine sorter for aircraft range. --- src/build_vehicle_gui.cpp | 20 ++++++++++++++++++++ src/lang/english.txt | 1 + 2 files changed, 21 insertions(+) (limited to 'src') 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 -- cgit v1.2.3-70-g09d2