1
0
Fork 0

Change: Add extra random seed to StartupEngines().

This means that calling reset_engines will rerandomise introduction dates
and reliability.

Probably not necessary.
pull/10284/head
Peter Nelson 2022-12-12 11:17:55 +00:00 committed by PeterN
parent 74180efe7f
commit cbf48c4dd9
3 changed files with 8 additions and 6 deletions

View File

@ -648,8 +648,9 @@ void SetYearEngineAgingStops()
* Start/initialise one engine. * Start/initialise one engine.
* @param e The engine to initialise. * @param e The engine to initialise.
* @param aging_date The date used for age calculations. * @param aging_date The date used for age calculations.
* @param seed Random seed.
*/ */
void StartupOneEngine(Engine *e, Date aging_date) void StartupOneEngine(Engine *e, Date aging_date, uint32 seed)
{ {
const EngineInfo *ei = &e->info; const EngineInfo *ei = &e->info;
@ -662,7 +663,7 @@ void StartupOneEngine(Engine *e, Date aging_date)
* Make sure they use the same randomisation of the date. */ * Make sure they use the same randomisation of the date. */
SavedRandomSeeds saved_seeds; SavedRandomSeeds saved_seeds;
SaveRandomSeeds(&saved_seeds); SaveRandomSeeds(&saved_seeds);
SetRandomSeed(_settings_game.game_creation.generation_seed ^ SetRandomSeed(_settings_game.game_creation.generation_seed ^ seed ^
ei->base_intro ^ ei->base_intro ^
e->type ^ e->type ^
e->GetGRFID()); e->GetGRFID());
@ -684,7 +685,7 @@ void StartupOneEngine(Engine *e, Date aging_date)
re = Engine::Get(re->info.variant_id); re = Engine::Get(re->info.variant_id);
} }
SetRandomSeed(_settings_game.game_creation.generation_seed ^ SetRandomSeed(_settings_game.game_creation.generation_seed ^ seed ^
(re->index << 16) ^ (re->info.base_intro << 12) ^ (re->info.decay_speed << 8) ^ (re->index << 16) ^ (re->info.base_intro << 12) ^ (re->info.decay_speed << 8) ^
(re->info.lifelength << 4) ^ re->info.retire_early ^ (re->info.lifelength << 4) ^ re->info.retire_early ^
e->type ^ e->type ^
@ -719,9 +720,10 @@ void StartupEngines()
{ {
/* Aging of vehicles stops, so account for that when starting late */ /* Aging of vehicles stops, so account for that when starting late */
const Date aging_date = std::min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1)); const Date aging_date = std::min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1));
uint32 seed = Random();
for (Engine *e : Engine::Iterate()) { for (Engine *e : Engine::Iterate()) {
StartupOneEngine(e, aging_date); StartupOneEngine(e, aging_date, seed);
} }
for (Engine *e : Engine::Iterate()) { for (Engine *e : Engine::Iterate()) {
CalcEngineReliability(e, false); CalcEngineReliability(e, false);

View File

@ -27,7 +27,7 @@ bool IsEngineRefittable(EngineID engine);
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint cargo_capacity); void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint cargo_capacity);
void SetYearEngineAgingStops(); void SetYearEngineAgingStops();
void CalcEngineReliability(Engine *e, bool new_month); void CalcEngineReliability(Engine *e, bool new_month);
void StartupOneEngine(Engine *e, Date aging_date); void StartupOneEngine(Engine *e, Date aging_date, uint32 seed);
uint GetTotalCapacityOfArticulatedParts(EngineID engine); uint GetTotalCapacityOfArticulatedParts(EngineID engine);

View File

@ -401,7 +401,7 @@ static bool FixTTOEngines()
if (oi == 255) { if (oi == 255) {
/* Default engine is used */ /* Default engine is used */
_date += DAYS_TILL_ORIGINAL_BASE_YEAR; _date += DAYS_TILL_ORIGINAL_BASE_YEAR;
StartupOneEngine(e, aging_date); StartupOneEngine(e, aging_date, 0);
CalcEngineReliability(e, false); CalcEngineReliability(e, false);
e->intro_date -= DAYS_TILL_ORIGINAL_BASE_YEAR; e->intro_date -= DAYS_TILL_ORIGINAL_BASE_YEAR;
_date -= DAYS_TILL_ORIGINAL_BASE_YEAR; _date -= DAYS_TILL_ORIGINAL_BASE_YEAR;