diff options
Diffstat (limited to 'src/engine.cpp')
-rw-r--r-- | src/engine.cpp | 79 |
1 files changed, 42 insertions, 37 deletions
diff --git a/src/engine.cpp b/src/engine.cpp index d35e9df54..ef6d63438 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -252,52 +252,57 @@ void SetYearEngineAgingStops() } } -void StartupEngines() +void StartupOneEngine(Engine *e, Date aging_date) { - 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)); - - FOR_ALL_ENGINES(e) { - const EngineInfo *ei = &e->info; - uint32 r; + const EngineInfo *ei = &e->info; + uint32 r; + + e->age = 0; + e->flags = 0; + e->company_avail = 0; + + /* The magic value of 729 days below comes from the NewGRF spec. If the + * base intro date is before 1922 then the random number of days is not + * added. */ + r = Random(); + e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro; + if (e->intro_date <= _date) { + e->age = (aging_date - e->intro_date) >> 5; + e->company_avail = (CompanyMask)-1; + e->flags |= ENGINE_AVAILABLE; + } - e->age = 0; - e->flags = 0; - e->company_avail = 0; + e->reliability_start = GB(r, 16, 14) + 0x7AE0; + r = Random(); + e->reliability_max = GB(r, 0, 14) + 0xBFFF; + e->reliability_final = GB(r, 16, 14) + 0x3FFF; - /* The magic value of 729 days below comes from the NewGRF spec. If the - * base intro date is before 1922 then the random number of days is not - * added. */ - r = Random(); - e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro; - if (e->intro_date <= _date) { - e->age = (aging_date - e->intro_date) >> 5; - e->company_avail = (CompanyMask)-1; - e->flags |= ENGINE_AVAILABLE; - } + r = Random(); + e->duration_phase_1 = GB(r, 0, 5) + 7; + e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96; + e->duration_phase_3 = GB(r, 9, 7) + 120; - e->reliability_start = GB(r, 16, 14) + 0x7AE0; - r = Random(); - e->reliability_max = GB(r, 0, 14) + 0xBFFF; - e->reliability_final = GB(r, 16, 14) + 0x3FFF; + e->reliability_spd_dec = ei->decay_speed << 2; - r = Random(); - e->duration_phase_1 = GB(r, 0, 5) + 7; - e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96; - e->duration_phase_3 = GB(r, 9, 7) + 120; + CalcEngineReliability(e); - e->reliability_spd_dec = ei->decay_speed << 2; + e->lifelength = ei->lifelength + _settings_game.vehicle.extend_vehicle_life; - CalcEngineReliability(e); + /* prevent certain engines from ever appearing. */ + if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) { + e->flags |= ENGINE_AVAILABLE; + e->company_avail = 0; + } +} - e->lifelength = ei->lifelength + _settings_game.vehicle.extend_vehicle_life; +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)); - /* prevent certain engines from ever appearing. */ - if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) { - e->flags |= ENGINE_AVAILABLE; - e->company_avail = 0; - } + FOR_ALL_ENGINES(e) { + StartupOneEngine(e, aging_date); } /* Update the bitmasks for the vehicle lists */ |