[Solved] how does a map script detect custom world sizes in GetMapInitData()?

Scrum Lord

Warlord
Joined
Jul 2, 2017
Messages
226
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:
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.
 
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.
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.
 
Did you ever figure this out, Scrum Lord?
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.
 
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
 
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
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.
 
Update: I now get non-nil hashes from current versions of YnAMP, Larger Worlds, and PerfectWorld, and I am therefore able to determine custom grid sizes inside GetMapInitData(). So I consider this topic solved.
 
Back
Top Bottom