Mercurial > hg > openttd
changeset 18660:5e577a393319 draft
(svn r23508) -Add: Engine sorter for aircraft range.
author | michi_cc <michi_cc@openttd.org> |
---|---|
date | Tue, 13 Dec 2011 01:18:40 +0000 |
parents | c625331ace43 |
children | 015b5de64509 |
files | src/build_vehicle_gui.cpp src/lang/english.txt |
diffstat | 2 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -403,6 +403,24 @@ 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 @@ &EngineRunningCostSorter, &EngineReliabilitySorter, &AircraftEngineCargoSorter, + &AircraftRangeSorter, }}; static const StringID _sort_listing[][12] = {{ @@ -500,6 +519,7 @@ STR_SORT_BY_RUNNING_COST, STR_SORT_BY_RELIABILITY, STR_SORT_BY_CARGO_CAPACITY, + STR_SORT_BY_RANGE, INVALID_STRING_ID }};
--- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -287,6 +287,7 @@ 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