mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
Fix: Setting the default railtype to 'first/last available' did not work with NewGRF defined railtypes.
This commit is contained in:
parent
6fa217dfc8
commit
b769eb30c4
15
src/rail.cpp
15
src/rail.cpp
@ -208,21 +208,6 @@ bool ValParamRailtype(const RailType rail)
|
||||
return rail < RAILTYPE_END && HasRailtypeAvail(_current_company, rail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "best" railtype a company can build.
|
||||
* As the AI doesn't know what the BEST one is, we have our own priority list
|
||||
* here. When adding new railtypes, modify this function
|
||||
* @param company the company "in action"
|
||||
* @return The "best" railtype a company has available
|
||||
*/
|
||||
RailType GetBestRailtype(const CompanyID company)
|
||||
{
|
||||
if (HasRailtypeAvail(company, RAILTYPE_MAGLEV)) return RAILTYPE_MAGLEV;
|
||||
if (HasRailtypeAvail(company, RAILTYPE_MONO)) return RAILTYPE_MONO;
|
||||
if (HasRailtypeAvail(company, RAILTYPE_ELECTRIC)) return RAILTYPE_ELECTRIC;
|
||||
return RAILTYPE_RAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the rail types that are to be introduced at the given date.
|
||||
* @param current The currently available railtypes.
|
||||
|
@ -452,7 +452,6 @@ bool ValParamRailtype(const RailType rail);
|
||||
|
||||
RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date);
|
||||
|
||||
RailType GetBestRailtype(const CompanyID company);
|
||||
RailTypes GetCompanyRailtypes(CompanyID company, bool introduces = true);
|
||||
RailTypes GetRailTypes(bool introduces);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user