Re-seed getMapRand() ???

Lutefisk Mafia

Inscrutable Enforcer
Joined
Jun 15, 2007
Messages
544
Location
Minnesota
How does one reseed the getMapRand() function from within the python? I have been using this to generate a randomized terrain effect in a mod map, but the seed only seems to get randomized once, right at the beginning of a new game.

Is there a workaround? What type of information does this function return anyway? Could I substitute a more generalized randome number generator?
 
To get around this you have to cheat by using getSorenRand to run a FOR loop requesting a random number of getMapRands. But honestly, both of them just return a random number. I am not 100% certain why they have 2 functions, but I would suspect it was for precisely what you are running into: allow many game functions to be random on reload with the right gameoption selected, while maintaining others as definitive results (though MapRand is only used in functions called immediately on the start of the game for the most part, but that would hold true. If you select New Random on Reload then having MapRand NOT re-seed means that the map layout will be the same if you reload your initial autosave and have it regenerate the map for you)
 
The reason for two random number generators is to avoid OOS problems.

You use one for shared random numbers--every human player in the game must run the same code, acquiring the same next random number on each machine, to keep the sequences in-sync. If any machine fails to grab the number along with the other machines, their sequences will go OOS. This may not immediately cause an OOS error message, but it will result in some machines possibly seeing different results.

You use the second generator for cases where only one machine needs to acquire a random number: perhaps for a UI element (like the BUG "margin of error" in the vote poll which is just to be cute) or visual effect that only some players will see. This sequence should never be used for any game elements or effects.

As for seeding the first sequence when you start a game, I don't understand why you'd need to. It should continue from where it left off in the previous game. As long as Civ seeds it randomly when you start Civ itself, it should continue to produce random values no matter how many games you start.

Certainly, loading a saved game without the Re-Seed game option checked will result in the same sequence of numbers, but that should be left up to the player to decide. And starting a new game should result . . . oh, I suppose if you load game A and then immediately start a new game, then reload game A and again start a new game, you'll see the same new game with the same map, assuming all settings are the same. In that case, just restart Civ.
 
I don't think that it is for OOS reasons. Both Soren & Map seeds are checked when doing the CalcSyncSum. As such I would have assumed you WOULD see immediate OOS issues by calling one of them within an IF (anything about activeplayer/team) statement.


Also, your seed will be different for each game you start, even if you load game A without re-seed option, then exit & start a new game. As the game starts, the program requests the current time from your computer and seeds the random generators with that number (relatively certain it is a number accurate to at least the nearest second).
 
Thank you for the pointers! I did figure out a kludgey work-around: I substituted SorenRands for a few of the MapRands I was using. Having done so, I now have a workable code chunk.

Cheers!
 
Both Soren & Map seeds are checked when doing the CalcSyncSum.

Oh, $&##$! Really? So this will be a cause of OOS in BUG. :( Now I can't remember if I read that part about the different sequences somewhere or just assumed it.

As such I would have assumed you WOULD see immediate OOS issues by calling one of them within an IF (anything about activeplayer/team) statement.

I didn't know they were included in the check. I assumed that using one on only one computer would eventually send you OOS as the different computers would start making different decisions, causing deviation. Good to know they are checked immediately.

As the game starts, the program requests the current time from your computer and seeds the random generators with that number.

By "the game" do you mean Civ or the game you're starting within Civ? By the original question, I assumed it wasn't doing this in the latter case. I would have assumed it was, though. It probably uses the millisecond clock for seeding the sequence, but I suppose it doesn't matter much since it takes longer than a second to start a game. ;)
 
I think the seed was done in CvGame, so it would mean each individual game. If it was instead done in CvInitCore, then it would mean launching Civ.


You know you can run Multiplayer on a single computer right? Great for checking if something you just coded will cause guaranteed OOS issues (should do it anytime you ever use Active(Player/Team) really)
 
Do I need to install two copies of Civ, or can I just launch a second app instance? I've never tried Civ multiplayer. :blush: I would love to be able to do testing for BUG to ensure it is MP-compatible.
 
You just set up your shortcut to launch multiple instances.

"C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Civ4BeyondSword.exe"

This one runs your game, no mods loaded.

"C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Civ4BeyondSword.exe" mod=\Fall Further

This one loads the game with your mod up and going immediately.


"C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Civ4BeyondSword.exe" multiple

This one allows you to open another instance of Civ while the other one is still up.


"C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Civ4BeyondSword.exe" multiple mod=\Fall Further


And this one loads your mod and lets you have multiple instances of it. Go to Multiplayer->LAN Game to play against yourself and test for OOS issues.


Do be careful not to over-click your shortcut though, quick way to bog down your system ;)
 
"C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Beyond the Sword\Civ4BeyondSword.exe" multiple

Ahh, that would do it. Thanks!
 
Top Bottom