1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Mods in multiplayer?

Discussion in 'Communitas Expansion Pack' started by secondcircle, Aug 22, 2013.

  1. secondcircle

    secondcircle Chieftain

    Joined:
    Aug 4, 2013
    Messages:
    10
    Am I going crazy, or is the multiplayer lit up in mod'ed games now? This is huge.. When did this change happen?
     
  2. Resok

    Resok Chieftain

    Joined:
    Aug 9, 2013
    Messages:
    9
    Holy crap, yup... just confirmed.

    However it only works with mods that have been identified in the ModInfo as 'WorksInMultiplayer' = 1
     
  3. Anvari

    Anvari Warlord

    Joined:
    Jun 21, 2012
    Messages:
    132
    Location:
    Berlin, Germany
    Uh wait what? Really?
     
  4. Resok

    Resok Chieftain

    Joined:
    Aug 9, 2013
    Messages:
    9
    Yup, the MP option is available when the mods you enabled are marked MP Compatible (set in .modinfo XML). Just tried it out with my wife on a LAN game and seems to work fine.
     
  5. secondcircle

    secondcircle Chieftain

    Joined:
    Aug 4, 2013
    Messages:
    10
  6. Hawawaa

    Hawawaa Prime

    Joined:
    Mar 31, 2012
    Messages:
    549
    Location:
    Michigan
    Yep go into mods, activate ur mods and then multiplayer option is there and as resok said Worksinmultiplayer = 1 your good otherwise its greyed out. (PARTY)

    damn I got ninja'd real good. :D
     
  7. Anvari

    Anvari Warlord

    Joined:
    Jun 21, 2012
    Messages:
    132
    Location:
    Berlin, Germany
    how long we've wished for this :) Can't wait to play CEP with my friends.
     
  8. Inua

    Inua Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    9
    I tried playing the map Communitas. It loaded fine but resynced after the first turn and the non-host players position got reset, just like before when you manually added the map to the Maps Folder. Something is still not synced properly at least there.
     
  9. Resok

    Resok Chieftain

    Joined:
    Aug 9, 2013
    Messages:
    9
    That one in particular I saw when playing with my wife also. It seems to be going through the full end to end world creation script separately on each player.

    I was able to work around it simply by starting the game with PitBoss enabled and then having the player join up on the first turn so they synced up the host's copy of the map instead of creating their own.
     
  10. Bobert13

    Bobert13 Prince

    Joined:
    Feb 25, 2013
    Messages:
    345
    I've been working on some multiplayer-friendly random functions for PW3 (Communitas uses these). If some folks want to try them out in a HotSeat game to see if they avoid issues with spawning desychronized maps, I'd really appreciate it. To implement this, comment out the random functions currently in Communitas and paste the following below them:

    Edit: These have been tested and the RNG has pretty much been debunked as the source of the desynchronization issues. I'm going to leave the code here as It has an example of a 32 bit precision random using Map.Rand and an example of a low-high integer random using Map.Rand.
    Spoiler :
    Code:
    -------------------------------------------------------------------------------------------
    function PWRand()
    	if not Game:IsNetworkMultiPlayer() then
    		return math.random()
    	else 
    		return ((Map.Rand(65535,"") * 65536) + Map.Rand(65535,""))/4294967295 --32 bit floating point precision random for multiplayer.
    	end
    end
    -------------------------------------------------------------------------------------------
    function PWRandSeed(fixedseed)
    	if not Game:IsNetworkMultiPlayer() then
    		local seed
    		if fixedseed == nil then
    			seed = (Map.Rand(32767,"") * 65536) + Map.Rand(65535,"")
    		else
    			seed = fixedseed
    		end
    		math.randomseed(seed) --This function caps at 2,147,483,647, if you set it any higher, or try to trick it with multiple RNGs that can end up with a value above this, it will break randomization.
    		print("Random seed for this map is " .. seed)
    		
    		PWRand() --Trash the first random to avoid issues on non-Windows systems.
    	else
    		print("Multiplayer game detected, using Map.Rand instead of a seeded lua random.")
    	end
    end
    -------------------------------------------------------------------------------------------
    --range is inclusive, low and high are possible results
    function PWRandint(low, high)
    	if not Game:IsNetworkMultiPlayer() then
    		return math.random(low, high)
    	else
    		return Map.Rand(high-low,"")+low --the maximum difference between high and low is 65,535 as Map.Rand is limited to returning a 16 bit integer.
    	end
    end


    Please note that both players must have the exact same copy of Communitas (with these randoms) and the exact same constants for this to work.

    This still needs a slight optimization (I'd replace the function call Game:isNetworkMultiplayer() that keeps getting called with a Global that only gets set once and then reference that Global during these functions). For proof of concept testing purposes, the code above should work fine.
     
  11. Resok

    Resok Chieftain

    Joined:
    Aug 9, 2013
    Messages:
    9
    I'll give it a shot later tonight or tomorrow.
     
  12. Bobert13

    Bobert13 Prince

    Joined:
    Feb 25, 2013
    Messages:
    345
    Ope, I renamed PWRandint() to PWRandInt() to match the general format for functions (note the capitalization). I'm pretty sure Communitas is expecting the lower-case "i". I'll change it in the post above but if you've already copied and pasted it, just change the capital "i" or it will cause a crash. :mischief:
     
  13. Inua

    Inua Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    9
    I just tried it out, the game still resynced after 1 turn. My non-host computers Cultural Borders and Warrior was moved about 3 spaces right and 3 spaces up, though the map itself seemed unchanged. I tried a couple of more games after that. It seems the map is unchanged on the client and host computer, although I don't know if they are the same since I never start close enough, but it always seem to resync 1 or 2 turns after start and move the clients cultural borders somewhere else.
     
  14. Bobert13

    Bobert13 Prince

    Joined:
    Feb 25, 2013
    Messages:
    345
    Do you have the Civ V SDK installed? If so, you can use FireTuner to reveal the map on the first turn. FireTuner is a multi-function tool but it's primary purpose is to act as a console between a tinkering developer and the game itself. I believe the reveal map button is on the map tab of FireTuner.

    Also, could you tell me if you're seeing either the following message:
    Code:
    "Multiplayer game detected, using Map.Rand instead of a seeded lua random."
    or:
    Code:
    "Random seed for this map is ##########"
    These can be viewed either in FireTuner's output console or in an Lua.log from when the map was generated. They should be one of the first few lines printed during the script.

    If you need any information on this stuff, I'd be happy to provide a link or two on enabling logging etc. If you can't do anything else but get me an Lua.log from the host and one from the client during a single (bootup->join MP game-> Spawn map->play until resync->completely close civ V) cycle, that could provide valuable information and would be greatly appreciated.
     
  15. Horem

    Horem Emperor

    Joined:
    Apr 1, 2010
    Messages:
    1,720
    Location:
    Wales, UK
    Where in the modinfo would one add this?
     
  16. Inua

    Inua Chieftain

    Joined:
    Feb 23, 2011
    Messages:
    9
    I started a couple of more games, I recopied all the code from the comment, edited the Communitas.lua file and started the firetuner and civ. Firetuner does not seem to work in LAN multiplayer games unfortunately, or I am doing something wrong.

    The game did not resync for about 25 turns and the maps seemed to match. Earlier I never got past 2 turns until it resynced. I'm not sure why it worked this time, it might've been I chose the wrong map or something... I then shut down firetuner and enabled logging instead. I restarted the game. Recopied the mod file for both computers so they matched and started another map. This time it resynced at the first turn and I saved the LUA.log files from both computers.

    "Multiplayer game detected, using Map.Rand instead of a seeded lua random." shows up in both files.

    I've been looking through them and they should be identical but I can see differences here and there... First thing I notice is differing Double values, all whole numbers are identical but double values seem to differ at about the 7th decimal. What is probably more relevant though is that values below row 494 in the log differs more, after "INFO Turn 0 RestoreLakes" where there starts to be larger differences. Different number of lakes target number, different flowing rivers, different placement tries for natural wonders.

    Logs pasted to pastebin:
    Client Log: http://pastebin.com/a6LS2xwK
    Host Log: http://pastebin.com/MMMPL8nQ
     
  17. Bobert13

    Bobert13 Prince

    Joined:
    Feb 25, 2013
    Messages:
    345
    This all means that my fix is essentially a bust. Somewhere something in the script is behaving differently every time it's ran regarding all of the float calculations and comparisons and the fact that it's happening beyond the 7th digit after the decimal is a sign that it may have something to do with single vs. double. Either there's an issue with something that affects essentially everything (normalization comes to mind here but it could be any number of things) or there's an inherent flaw in the lua compiler (that also exists in the JIT compiler) which seems unlikely.

    These floats have to be exactly the same every time the same set of RNGs is applied to the script, and they aren't (you just ruled out the possibility that the RNG is differing, thank you). If the floats vary at all, it can potentially cause the whole map to shift differently which is bad. I'm going to look into implementing a different normalization function and if that doesn't work, I'll have to look into the possibility of forcing a resync some time before handling start locations. I don't like forcing a resync, because it's a band-aid fix, but I may not be able to track down where these floats are getting broken.

    I'll go ahead and advise you to switch back to the normal Communitas random functions if you haven't already as the ones shown above did not resolve the issue.
     
  18. Bobert13

    Bobert13 Prince

    Joined:
    Feb 25, 2013
    Messages:
    345
    I'm pretty sure that the line already exists though it's set to zero if the flag wasn't checked during the creation of the modinfo.

    To answer your question though, this belongs under the Properties tag as shown here:
    Code:
    <Properties>
        <Name>blah</Name>
        <Teaser>mooo</Teaser>
        <Description>blah moo blah</Description>
        <Authors>aliens</Authors>
        <SpecialThanks>cows</SpecialThanks>
        <HideSetupGame>0</HideSetupGame>
        <AffectsSavedGames>0</AffectsSavedGames>
        <SupportsSinglePlayer>1</SupportsSinglePlayer>
        [COLOR="SeaGreen"]<SupportsMultiplayer>1</SupportsMultiplayer>[/COLOR]
        <SupportsHotSeat>1</SupportsHotSeat>
        <SupportsMac>1</SupportsMac>
        <ReloadLandmarkSystem>0</ReloadLandmarkSystem>
        <ReloadStrategicViewSystem>0</ReloadStrategicViewSystem>
        <ReloadUnitSystem>0</ReloadUnitSystem>
      </Properties>
     
  19. Bobert13

    Bobert13 Prince

    Joined:
    Feb 25, 2013
    Messages:
    345
    Well, I found an issue in normalization (whowouldathunkit)... The problem stems from multiplying two high precision doubles. I did the same operation some number of times and got 3 different products!!! I'm looking into a few different options to get consistent numbers from normalization.

    Option A) cutting the inputs of the multiplication down to 7 digits after the decimal (you can represent some digits in the 8th decimal with full precision with a single-precision float, but not all of them). This should result in a consistent multiplication as multiplying two numbers with full precision requires twice as many bits as the inputs began with. Never Tested, could possibly be faster than freeing the exponent, scaling, and then adding the exponent back. It wouldn't produce the exact same results as method C, but it should be consistent with itself which is what matters.

    Option B) reworking normalization to divide instead of multiply. I have no clue if this will result in consistent numbers or not as I'm not sure of the specifics when it comes to division and precision in floats. Tested, doesn't work.

    Option C) reworking normalization completely to use math.frexp and math.ldexp. I have no idea how I'd really go about getting this to only output numbers between zero and one though as there's a lot of complications with the freed exponent. Tested, and works! Normalization produces consistent results!

    Multiplying doubles happens in multiple places throughout the script so there's probably a number of areas that need attention if this lossy operation is resulting in inconsistencies all over the place. Normalization is key and small inconsistencies in elevation early on will often be amplified by a few orders of magnitude throughout the course of the script...

    Edit: I sent a PM to Inua if he'd like to test my reworked normalization to see if it gets rid of the desynchronized maps. I'll quit mucking this thread up now :lol: so you guys can get back to discussing other matters.
     

    Attached Files:

  20. Kurobane

    Kurobane Chieftain

    Joined:
    Dec 21, 2012
    Messages:
    9
    Hopefully it would become possible to get all of Thals mods working in multiplayer.
     

Share This Page