diff options
author | rubidium <rubidium@openttd.org> | 2011-01-18 21:30:59 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-01-18 21:30:59 +0000 |
commit | b8c9988d9fce02a3bfb958b0ebc7cf39961ef10c (patch) | |
tree | 6ace877720369defc6a552ea53b731d8bd42c982 /src/rail.cpp | |
parent | 6371b75bcc0789d4895e5c157237cbeaf332a99a (diff) | |
download | openttd-b8c9988d9fce02a3bfb958b0ebc7cf39961ef10c.tar.xz |
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
Diffstat (limited to 'src/rail.cpp')
-rw-r--r-- | src/rail.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/rail.cpp b/src/rail.cpp index a2285ef16..2a308c547 100644 --- a/src/rail.cpp +++ b/src/rail.cpp @@ -192,6 +192,40 @@ RailType GetBestRailtype(const CompanyID company) return RAILTYPE_RAIL; } +/** + * Add the rail types that are to be introduced at the given date. + * @param current The currently available railtypes. + * @param date The date for the introduction comparisions. + * @return The rail types that should be available when date + * introduced rail types are taken into account as well. + */ +RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date) +{ + RailTypes rts = current; + + for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) { + const RailtypeInfo *rti = GetRailTypeInfo(rt); + /* Unused rail type. */ + if (rti->label == 0) continue; + + /* Not date introduced. */ + if (!IsInsideMM(rti->introduction_date, 0, MAX_DAY)) continue; + + /* Not yet introduced at this date. */ + if (rti->introduction_date > date) continue; + + /* Have we introduced all required railtypes? */ + RailTypes required = rti->introduction_required_railtypes; + if ((rts & required) != required) continue; + + rts |= rti->introduces_railtypes; + } + + /* When we added railtypes we need to run this method again; the added + * railtypes might enable more rail types to become introduced. */ + return rts == current ? rts : AddDateIntroducedRailTypes(rts, date); +} + RailTypes GetCompanyRailtypes(CompanyID company) { RailTypes rts = RAILTYPES_NONE; @@ -211,7 +245,7 @@ RailTypes GetCompanyRailtypes(CompanyID company) } } - return rts; + return AddDateIntroducedRailTypes(rts, _date); } RailType GetRailTypeByLabel(RailTypeLabel label) |