Discussion in 'Civ4 - Creation & Customization' started by Caesium, Jun 19, 2006.
You can use them, but you shouldn't use them in if cases, if they depend on active player
Exactly as Caesium said. It really doesn't matter, just make sure you keep it similar on all machines. Even if the exact number generated doesn't matter, the fact that you actually went ahead and made the call does. It's probably more safe to use it than not to use it, since most code is probably going to be in the realm of "run on all machines" rather than the little bits of code that are run only on some of the machines. If you find code that is going to only run on one machine (such as if it's located somewhere within an if block that checks the getActivePlayer) then you should use a non-synchronous random number generator.
Caesium had a good idea for the Caesium mod, where if unsure about whether or not it's needed, use a sorenRandNum call, but do it early in the function, before you get into problems of possibly entering into computer-independent code such as if-blocks with getActivePlayer().
Thanks again. Maybe I'll follow all the advice, fix it the best I can, check that it works in hotseat, and then publish a beta for volunteers to test.
Damn, I found a lot of calls to getActivePlayer()
I hope I will be able to find volunteers with a 2+ computer LAN setup.
I've had two instances of civ running, by accident, but problems come up when alt-tabing between them. I can alttab all day long in and out of one instance of civ, but when I do it between to running civ4s thing just start getting weird, missing buttons, lags, hangups, and I have dual proccessors and it maxes both of them..
I think you guys explained the sorenRand instance of CvRandom very well, and I suppose the ASyncRand instance we get from CyGlobalContext.getASyncRand() is fully asynchronous, so I guess I can use it as if it were Python's random number generator, only maybe faster or using less memory. But TheLopez is using CyGame.getMapRand() in his RandomNameUtils.py. What is the mapRand instance of CvRandom all about? Staring at the SDK source is giving me such a headache.
I'm not too sure why the two different sync RNG's, but I would guess that you have two so that the map RNG can have it's seed set to a value if you want to, say, have a game with the same map random seed (thus the map generator script will generate the exact same map) while still having a different synchronous RNG for other purposes, such as combat, random events and AI. I don't think using the map RNG over the soren RNG will make a big difference, as long as all computers use the same one at the same time.
Ah yes the mapRand cannot be serialized (pickled in python parlance) and stored in a Civ4 savegame file, so it is probably synchronized when a new multiplayer game is started only and then either it is not saved at all or the sorenRand is pointed to it once the game has started.
It does not matter which, it won't work for unit naming, so I'll edit the RandomNameUtils.py to change the random number generator to sorenRand. I know that is only step 1.
Actually, the map rand seed is stored in save game. Also interesting is how it works. This is from CvGame::read
[b]// --- SNIP ---[/b]
I guess this explains the difference between the two. On a saved game reload, the map rand will always stay the same, whereas the sorenRand will be reseeded if the option to get a new random seed on game load is on (there is some other place where they might be changed during the load that I don't know about).
[b]// --- SNIP ---[/b]
I can't imagine going through the trouble of maintaining an extra instance of CvRandom just for that.
I looked at the sync check and checksums and it seems like unit names aren't even checked. Maybe it does not even matter if they are different on each client.
I could be barking up the wrong tree trying to fix this.
Sorry, bit old, but while looking through Firaxis site, I found the list of command line options available:
So, I guess if you really want to try it, you can append the "multiple" command line option and have multiple instances : o)
Thanks, it sounds like it might actually work!
Yes, it does. I just tried to start two games in windowed mode and run a multiplayer game, works fine.
But I recommend to have two displays for that.
Depending on your PC it might be very slow.
Yay, now I'm finally able to test my mod for multiplayer compatibility.
could anyone tell me in which "file" should i add this
multiple // allow multiple civ instances to run
You have to start the game with a link like in your start menu.
The link should look like this:
"F:\Sid Meier's Civilization 4\Civilization4.exe" multiple
Or, if you're starting a mod (and using the default install directory...)
"C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Civilization4.exe" multiple mod=\MyModName
Separate names with a comma.