diff options
author | belugas <belugas@openttd.org> | 2008-09-17 02:30:24 +0000 |
---|---|---|
committer | belugas <belugas@openttd.org> | 2008-09-17 02:30:24 +0000 |
commit | 217db3cb6171dbe108dfca22adb33b82f607771c (patch) | |
tree | 0b54c6ede73ae0a53b676a90bd8054eef1d82cad /src | |
parent | 9fed67a05a662074cc44a863c02b5c2c84575885 (diff) | |
download | openttd-217db3cb6171dbe108dfca22adb33b82f607771c.tar.xz |
(svn r14352) -Feature: Allow sorting vehicles by remaining life time.
Patch by yorick
Diffstat (limited to 'src')
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt index 01556f754..1c25ac982 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -380,6 +380,7 @@ STR_SORT_BY_MAX_SPEED :Maximum speed STR_SORT_BY_MODEL :Model STR_SORT_BY_VALUE :Value STR_SORT_BY_LENGTH :Length +STR_SORT_BY_LIFE_TIME :Remaining life time STR_SORT_BY_FACILITY :Station type STR_SORT_BY_WAITING :Waiting cargo value STR_SORT_BY_RATING_MAX :Cargo rating diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index c4bcc684a..55ddc2f21 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -57,6 +57,7 @@ static GUIVehicleList::SortFunction VehicleMaxSpeedSorter; static GUIVehicleList::SortFunction VehicleModelSorter; static GUIVehicleList::SortFunction VehicleValueSorter; static GUIVehicleList::SortFunction VehicleLengthSorter; +static GUIVehicleList::SortFunction VehicleTimeToLiveSorter; GUIVehicleList::SortFunction* const BaseVehicleListWindow::vehicle_sorter_funcs[] = { &VehicleNumberSorter, @@ -70,6 +71,7 @@ GUIVehicleList::SortFunction* const BaseVehicleListWindow::vehicle_sorter_funcs[ &VehicleModelSorter, &VehicleValueSorter, &VehicleLengthSorter, + &VehicleTimeToLiveSorter, }; const StringID BaseVehicleListWindow::vehicle_sorter_names[] = { @@ -84,6 +86,7 @@ const StringID BaseVehicleListWindow::vehicle_sorter_names[] = { STR_SORT_BY_MODEL, STR_SORT_BY_VALUE, STR_SORT_BY_LENGTH, + STR_SORT_BY_LIFE_TIME, INVALID_STRING_ID }; @@ -629,6 +632,13 @@ static int CDECL VehicleLengthSorter(const Vehicle* const *a, const Vehicle* con return (r != 0) ? r : VehicleNumberSorter(a, b); } +/** Sort vehicles by the time they can still live */ +static int CDECL VehicleTimeToLiveSorter(const Vehicle* const *a, const Vehicle* const *b) +{ + int r = ClampToI32(((*a)->max_age - (*a)->age) - ((*b)->max_age - (*b)->age)); + return (r != 0) ? r : VehicleNumberSorter(a, b); +} + void InitializeGUI() { MemSetT(&_sorting, 0); |