summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2009-01-08 21:48:59 +0000
committerpeter1138 <peter1138@openttd.org>2009-01-08 21:48:59 +0000
commit0052c85002e8e5631fa09a0b726b0c65c6350b93 (patch)
tree69dff3195c0a8d9add54b6bf42a8f9adb078ff94 /src
parentb522f73ba8f6c53f75639fc4f5d6b2a078827513 (diff)
downloadopenttd-0052c85002e8e5631fa09a0b726b0c65c6350b93.tar.xz
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp34
-rw-r--r--src/engine_func.h1
-rw-r--r--src/newgrf.cpp2
3 files changed, 30 insertions, 7 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index c8a256f10..dfe24168b 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -32,10 +32,9 @@
DEFINE_OLD_POOL_GENERIC(Engine, Engine)
-enum {
- YEAR_ENGINE_AGING_STOPS = 2050,
-};
-
+/** Year that engine aging stops. Engines will not reduce in reliability
+ * and no more engines will be introduced */
+Year _year_engine_aging_stops;
/** Number of engines of each vehicle type in original engine data */
const uint8 _engine_counts[4] = {
@@ -231,11 +230,32 @@ static void CalcEngineReliability(Engine *e)
InvalidateWindowClasses(WC_REPLACE_VEHICLE);
}
+void SetYearEngineAgingStops()
+{
+ /* Determine last engine aging year, default to 2050 as previously. */
+ _year_engine_aging_stops = 2050;
+
+ const Engine *e;
+ FOR_ALL_ENGINES(e) {
+ const EngineInfo *ei = &e->info;
+
+ /* Exclude certain engines */
+ if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue;
+ if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue;
+
+ /* Base year ending date on half the model life */
+ YearMonthDay ymd;
+ ConvertDateToYMD(ei->base_intro + (ei->lifelength * 366) / 2, &ymd);
+
+ _year_engine_aging_stops = max(_year_engine_aging_stops, ymd.year);
+ }
+}
+
void StartupEngines()
{
Engine *e;
/* Aging of vehicles stops, so account for that when starting late */
- const Date aging_date = min(_date, ConvertYMDToDate(YEAR_ENGINE_AGING_STOPS, 0, 1));
+ const Date aging_date = min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
FOR_ALL_ENGINES(e) {
const EngineInfo *ei = &e->info;
@@ -336,7 +356,7 @@ static CompanyID GetBestCompany(uint8 pp)
void EnginesDailyLoop()
{
- if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return;
+ if (_cur_year >= _year_engine_aging_stops) return;
Engine *e;
FOR_ALL_ENGINES(e) {
@@ -447,7 +467,7 @@ static void NewVehicleAvailable(Engine *e)
void EnginesMonthlyLoop()
{
- if (_cur_year < YEAR_ENGINE_AGING_STOPS) {
+ if (_cur_year < _year_engine_aging_stops) {
Engine *e;
FOR_ALL_ENGINES(e) {
/* Age the vehicle */
diff --git a/src/engine_func.h b/src/engine_func.h
index 942f90d1a..12d7514e7 100644
--- a/src/engine_func.h
+++ b/src/engine_func.h
@@ -29,5 +29,6 @@ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
bool IsEngineRefittable(EngineID engine);
CargoID GetEngineCargoType(EngineID engine);
void SetCachedEngineCounts();
+void SetYearEngineAgingStops();
#endif /* ENGINE_H */
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index e0cff5836..915cd3f99 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -6039,6 +6039,8 @@ static void AfterLoadGRFs()
}
}
+ SetYearEngineAgingStops();
+
/* Deallocate temporary loading data */
free(_gted);
_grm_sprites.clear();