Changeset - r26686:b6b127422918
[Not reviewed]
master
0 3 0
Peter Nelson - 21 months ago 2022-12-12 11:17:55
peter1138@openttd.org
Change: Add extra random seed to StartupEngines().

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

Probably not necessary.
3 files changed with 8 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/engine.cpp
Show inline comments
 
@@ -645,27 +645,28 @@ void SetYearEngineAgingStops()
 
}
 

	
 
/**
 
 * Start/initialise one engine.
 
 * @param e The engine to initialise.
 
 * @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;
 

	
 
	e->age = 0;
 
	e->flags = 0;
 
	e->company_avail = 0;
 
	e->company_hidden = 0;
 

	
 
	/* Vehicles with the same base_intro date shall be introduced at the same time.
 
	 * Make sure they use the same randomisation of the date. */
 
	SavedRandomSeeds saved_seeds;
 
	SaveRandomSeeds(&saved_seeds);
 
	SetRandomSeed(_settings_game.game_creation.generation_seed ^
 
	SetRandomSeed(_settings_game.game_creation.generation_seed ^ seed ^
 
	              ei->base_intro ^
 
	              e->type ^
 
	              e->GetGRFID());
 
	uint32 r = Random();
 

	
 
	/* Don't randomise the start-date in the first two years after gamestart to ensure availability
 
@@ -681,13 +682,13 @@ void StartupOneEngine(Engine *e, Date ag
 
	/* Get parent variant index for syncing reliability via random seed. */
 
	const Engine *re = e;
 
	while (re->info.variant_id != INVALID_ENGINE && re->info.variant_id != re->index && (re->info.extra_flags & ExtraEngineFlags::SyncReliability) != ExtraEngineFlags::None) {
 
		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->info.lifelength << 4) ^ re->info.retire_early ^
 
	              e->type ^
 
	              e->GetGRFID());
 

	
 
	r = Random();
 
@@ -716,15 +717,16 @@ void StartupOneEngine(Engine *e, Date ag
 
 * to the NewGRF config.
 
 */
 
void StartupEngines()
 
{
 
	/* 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));
 
	uint32 seed = Random();
 

	
 
	for (Engine *e : Engine::Iterate()) {
 
		StartupOneEngine(e, aging_date);
 
		StartupOneEngine(e, aging_date, seed);
 
	}
 
	for (Engine *e : Engine::Iterate()) {
 
		CalcEngineReliability(e, false);
 
	}
 

	
 
	/* Update the bitmasks for the vehicle lists */
src/engine_func.h
Show inline comments
 
@@ -24,11 +24,11 @@ extern const uint8 _engine_offsets[4];
 

	
 
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
 
bool IsEngineRefittable(EngineID engine);
 
void GetArticulatedVehicleCargoesAndRefits(EngineID engine, CargoArray *cargoes, CargoTypes *refits, CargoID cargo_type, uint cargo_capacity);
 
void SetYearEngineAgingStops();
 
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);
 

	
 
#endif /* ENGINE_FUNC_H */
src/saveload/oldloader_sl.cpp
Show inline comments
 
@@ -398,13 +398,13 @@ static bool FixTTOEngines()
 
		int oi = ttd_to_tto[i];
 
		Engine *e = GetTempDataEngine(i);
 

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

	
 
			/* Make sure for example monorail and maglev are available when they should be */
 
			if (_date >= e->intro_date && HasBit(e->info.climates, 0)) {
0 comments (0 inline, 0 general)