Changeset - r26190:d89a21b2f0e7
[Not reviewed]
master
0 2 0
Michael Lutz - 2 years ago 2022-03-13 10:21:40
michi@icosahedron.de
Add: [NewGRF] Map seed as global variable.

This is useful to provide a feature-agnostic, stable random value that differs between games.
One of the possible uses is to e.g. use it to create pseudo-random regions for towns or industries.
2 files changed with 6 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/genworld.cpp
Show inline comments
 
@@ -93,7 +93,6 @@ static void _GenerateWorld()
 
		_generating_world = true;
 
		if (_network_dedicated) Debug(net, 3, "Generating map, please wait...");
 
		/* Set the Random() seed to generation_seed so we produce the same map with the same seed */
 
		if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = _settings_newgame.game_creation.generation_seed = InteractiveRandom();
 
		_random.SetSeed(_settings_game.game_creation.generation_seed);
 
		SetGeneratingWorldProgress(GWP_MAP_INIT, 2);
 
		SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
 
@@ -302,6 +301,8 @@ void GenerateWorld(GenWorldMode mode, ui
 
		_settings_game.construction.map_height_limit = std::max(MAP_HEIGHT_LIMIT_AUTO_MINIMUM, std::min(MAX_MAP_HEIGHT_LIMIT, estimated_height + MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM));
 
	}
 

	
 
	if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = _settings_newgame.game_creation.generation_seed = InteractiveRandom();
 

	
 
	/* Load the right landscape stuff, and the NewGRFs! */
 
	GfxLoadSprites();
 
	LoadStringWidthTable();
src/newgrf.cpp
Show inline comments
 
@@ -7046,6 +7046,10 @@ static uint32 GetPatchVariable(uint8 par
 
		case 0x16:
 
			return SPR_SHORE_BASE;
 

	
 
		/* Game map seed */
 
		case 0x17:
 
			return _settings_game.game_creation.generation_seed;
 

	
 
		default:
 
			grfmsg(2, "ParamSet: Unknown Patch variable 0x%02X.", param);
 
			return 0;
0 comments (0 inline, 0 general)