1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

Question: how does a map script detect custom world sizes in GetMapInitData()?

Discussion in 'Mod Creation Help' started by Scrum Lord, Dec 30, 2017.

  1. Scrum Lord

    Scrum Lord Chieftain

    Joined:
    Jul 2, 2017
    Messages:
    64
    Gender:
    Male
    Does anyone know if there is a way to detect custom world sizes in a map script's GetMapInitData() function using the passed-in worldSize hash? I can't just look-up the grid size because my map script (Got Lakes) has other options that affect the height of the map, such as worlds with cropped N/S poles. In other words, my map script needs to know the world size by name/type so that I can dynamically set the grid size.

    But I've run into a problem. I have the following snippet of code for determining the world size:
    Code:
    function GetMapInitData(worldSize)
        -- ...
        local mapSizeType;
        for row in GameInfo.Maps() do  
            if(worldSize == row.Hash) then
                mapSizeType = row.MapSizeType;
                break;
            end
        end
        -- ...
    end
    For some reason, only the standard map sizes have a non-nil hash. Custom map sizes, such as the ones from Larger Map Sizes or Yet (not) Another Maps Pack, have rows but each of those rows has a nil value for row.Hash.

    On a related note, the Inland Sea map script has similar world-size lookup logic, and that map type crashes when run with a custom map size. I haven't confirmed this, but I suspect that Inland Sea is running into the same problem.

    So is this a configuration/database issue or is this a bug in the map generator API? Any help/tips would be greatly appreciated.
     
    Last edited: Dec 30, 2017
  2. Scrum Lord

    Scrum Lord Chieftain

    Joined:
    Jul 2, 2017
    Messages:
    64
    Gender:
    Male
    This also happens with the Rise and Fall expansion.
     
  3. pokiehl

    pokiehl Chieftain

    Joined:
    Mar 5, 2017
    Messages:
    296
    Did you ever figure this out, Scrum Lord?
     
  4. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    5,612
    Location:
    Illinois, USA
    The only occurance of the text string "GetMapInitData" in any of the Vanilla lua files is within InlandSea.lua

    The function is defined as
    Code:
    -- Input a Hash; Export width, height, and wrapX
    function GetMapInitData(MapSize)
    	local MapSizeTypes = {};
    	local Width = 0;
    	local Height = 0;
    
    	for row in GameInfo.Maps() do
    		if(MapSize == row.Hash) then
    			Width = row.GridWidth;
    			Height = row.GridHeight;
    		end
    	end
    
    	local WrapX = false;
    
    	return {Width = Width, Height = Height, WrapX = WrapX,}
    end
    But I don't via a RanSack search see where this function is actually ever executed anywhere in any lua file.

    Inlandsea.lua is still using
    Code:
    g_iW, g_iH = Map.GetGridSize()
    within the GenerateMap function.
     
  5. Gedemon

    Gedemon Modder Moderator

    Joined:
    Oct 4, 2004
    Messages:
    7,730
    Location:
    France
    GetMapInitData and GetMapScriptInfo are called by the application side (Dll, exe ?) just before generating the map (ie before the Lua scripts are executed), which allows, for example, to change the grid size in a script independently of the selected size in the setup screen.
     
  6. Scrum Lord

    Scrum Lord Chieftain

    Joined:
    Jul 2, 2017
    Messages:
    64
    Gender:
    Male
    Nope. But I no longer consider this a blocker for Got Lakes running custom-size maps. There are just a few quirks: east-west wrap for World Wrap = Region, and "cropped" climates pretending that the grid height was already cropped.
     
  7. pokiehl

    pokiehl Chieftain

    Joined:
    Mar 5, 2017
    Messages:
    296
    Well this was all much ado about nothing..the only reason custom map sizes don't have hashes is if the mod doesn't add the map sizes to the Types table. Like I forgot for months. Oops :p
     
  8. Scrum Lord

    Scrum Lord Chieftain

    Joined:
    Jul 2, 2017
    Messages:
    64
    Gender:
    Male
    So this is fixable/already-fixed by authors of custom-size mods?

    In case anyone's wondering how I managed to work around the issue, the GetMapInitData() function can return void instead of { width, height, wrapX, wrapY }, which effectively resets the map init data back to default grid size with wrapX = true. Then in GenerateMap() I just call Map.GetGridSize() to determine the size of the map.
     

Share This Page

Ebates: Get Paid to Shop