Update to 1.10.0-beta2

This commit is contained in:
dP
2020-01-06 18:49:34 +03:00
parent 599ccf0c2b
commit c7c3966eec
1366 changed files with 2926 additions and 5639 deletions

View File

@@ -1,5 +1,3 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
@@ -1910,38 +1908,41 @@ static void SetDefaultRailGui()
if (_local_company == COMPANY_SPECTATOR || !Company::IsValidID(_local_company)) return;
extern RailType _last_built_railtype;
RailType rt = (RailType)(_settings_client.gui.default_rail_type + RAILTYPE_END);
if (rt == DEF_RAILTYPE_MOST_USED) {
/* Find the most used rail type */
uint count[RAILTYPE_END];
memset(count, 0, sizeof(count));
for (TileIndex t = 0; t < MapSize(); t++) {
if (IsTileType(t, MP_RAILWAY) || IsLevelCrossingTile(t) || HasStationTileRail(t) ||
(IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL)) {
count[GetRailType(t)]++;
RailType rt;
switch (_settings_client.gui.default_rail_type) {
case 2: {
/* Find the most used rail type */
uint count[RAILTYPE_END];
memset(count, 0, sizeof(count));
for (TileIndex t = 0; t < MapSize(); t++) {
if (IsTileType(t, MP_RAILWAY) || IsLevelCrossingTile(t) || HasStationTileRail(t) ||
(IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL)) {
count[GetRailType(t)]++;
}
}
rt = static_cast<RailType>(std::max_element(count + RAILTYPE_BEGIN, count + RAILTYPE_END) - count);
if (count[rt] > 0) break;
/* No rail, just get the first available one */
FALLTHROUGH;
}
rt = RAILTYPE_RAIL;
for (RailType r = RAILTYPE_ELECTRIC; r < RAILTYPE_END; r++) {
if (count[r] >= count[rt]) rt = r;
case 0: {
/* Use first available type */
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;
}
/* No rail, just get the first available one */
if (count[rt] == 0) rt = DEF_RAILTYPE_FIRST;
}
switch (rt) {
case DEF_RAILTYPE_FIRST:
rt = RAILTYPE_RAIL;
while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_company, rt)) rt++;
case 1: {
/* Use last available type */
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;
case DEF_RAILTYPE_LAST:
rt = GetBestRailtype(_local_company);
break;
}
default:
break;
NOT_REACHED();
}
_last_built_railtype = _cur_railtype = rt;