diff options
author | frosch <frosch@openttd.org> | 2019-12-18 00:48:03 +0100 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2019-12-23 17:23:20 +0000 |
commit | b769eb30c43ccbc4e60b8b7df024253ac55d2265 (patch) | |
tree | a2d3b30374e475f588d92cc2b00c20833b081eee /src/rail_gui.cpp | |
parent | 6fa217dfc8afbd06bbc46462a2b6affc35268b5b (diff) | |
download | openttd-b769eb30c43ccbc4e60b8b7df024253ac55d2265.tar.xz |
Fix: Setting the default railtype to 'first/last available' did not work with NewGRF defined railtypes.
Diffstat (limited to 'src/rail_gui.cpp')
-rw-r--r-- | src/rail_gui.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 7917268a1..c0a3f4457 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1927,17 +1927,20 @@ static void SetDefaultRailGui() /* No rail, just get the first available one */ FALLTHROUGH; } - case 0: + case 0: { /* Use first available type */ - rt = RAILTYPE_BEGIN; - while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_company, rt)) rt++; + std::vector<RailType>::const_iterator it = std::find_if(_sorted_railtypes.begin(), _sorted_railtypes.end(), + [](RailType r){ return HasRailtypeAvail(_local_company, r); }); + rt = it != _sorted_railtypes.end() ? *it : RAILTYPE_BEGIN; break; - - case 1: + } + case 1: { /* Use last available type */ - rt = GetBestRailtype(_local_company); + std::vector<RailType>::const_reverse_iterator it = std::find_if(_sorted_railtypes.rbegin(), _sorted_railtypes.rend(), + [](RailType r){ return HasRailtypeAvail(_local_company, r); }); + rt = it != _sorted_railtypes.rend() ? *it : RAILTYPE_BEGIN; break; - + } default: NOT_REACHED(); } |