Weird bug with lakes when editing the pangea.lua script

10101100

Chieftain
Joined
Oct 14, 2019
Messages
52
I wanted to get rid of mountains in the pangea map so I edited the script in dlc/expansion 2/maps


Before the end of the GenerateMap() function I added this:
Spoiler :

Code:
    local x;
    local y;
    for x = 0, g_iW - 1 do
        for y = 0, g_iH - 1 do
            local i = y * g_iW + x;
            pPlot = Map.GetPlotByIndex(i);
            TerrainBuilder.SetTerrainType(pPlot, ConvertMountainToHills(terrainTypes[i]));

        end
    end

What this does is go through every single tile, check if the tile is a mountain, if it is convert it to hill




Spoiler ConvertMountainToHills() function :

Code:
function ConvertMountainToHills(type)

    print("ConvertMountainToHills running");

    local rtnValue = type;

    if (type == g_TERRAIN_TYPE_SNOW_MOUNTAIN) then
        rtnValue = g_TERRAIN_TYPE_SNOW_HILLS;
    elseif (type == g_TERRAIN_TYPE_TUNDRA_MOUNTAIN) then
        rtnValue = g_TERRAIN_TYPE_TUNDRA_HILLS;
    elseif (type == g_TERRAIN_TYPE_DESERT_MOUNTAIN) then
        rtnValue = g_TERRAIN_TYPE_DESERT_HILLS;
    elseif (type == g_TERRAIN_TYPE_GRASS_MOUNTAIN) then
        rtnValue = g_TERRAIN_TYPE_GRASS_HILLS;
    elseif (type == g_TERRAIN_TYPE_PLAINS_MOUNTAIN) then
        rtnValue = g_TERRAIN_TYPE_PLAINS_HILLS;
    end

    return rtnValue;
end





However I'm getting a really strange bug, this is how lakes appear in the world:
Spoiler :
upload_2020-8-18_0-28-21.png

I can build farms/mines/districts on those tiles and they count as fresh water too!


Spoiler :
upload_2020-8-18_0-29-44.png
 
The bug is in your code.

The AddLakes function is executed by GenerateMap() after base terrain is generated and there is no more need for the cached data in lua table "terrainTypes". So AddLakes(args) does not update the "terrainTypes" table. AddLakes(args) randomly selects plots to be transformed into lakes, paying no attention whatever to what the previous condition of the plot was re Flatlands, Hills, or Mountains.

So when you use
Code:
terrainTypes[i]
you are using outdated information for the designated plot. This is why some of your lakes were converted to hills and others were not.

You need to access the actual plot object at the point your code executes and check whether the plot is a Mountain, has a feature (ie,, is a Volcano or Natural Wonder), or is adjacent to a Natural Wonder.

This should cure the issue
Code:
for x = 0, g_iW - 1 do
	for y = 0, g_iH - 1 do
		local i = y * g_iW + x;
		pPlot = Map.GetPlotByIndex(i);
		if pPlot:IsMountain() and (pPlot:IsNaturalWonder() == false) and (pPlot:GetFeatureType() ~= g_FEATURE_VOLCANO) and (AdjacentToNaturalWonder(pPlot) == false) then
			TerrainBuilder.SetTerrainType(pPlot, ConvertMountainToHills(pPlot:GetTerrainType()));
		end
	end
end
The AdjacentToNaturalWonder() function is part of the built-in toolkit stuff in the RiversLakes.lua file that is "included" into the code of the Pangea.lua file at the top of the file:
Code:
include "MapEnums"
include "MapUtilities"
include "MountainsCliffs"
include "RiversLakes"
include "FeatureGenerator"
include "TerrainGenerator"
include "NaturalWonderGenerator"
include "ResourceGenerator"
include "CoastalLowlands"
include "AssignStartingPlots"
You want to avoid changing terrain that is adjacent to a Natural Wonder because doing so can cause the game engine to not properly render the Natural Wonder graphically.

You want to not alter a Volcano tile because while you can change the underlying base terrain (ie, it's a mountain) this does not allow removal of the fact that the plot is a Volcano and you get both odd graphical representation as well as the fact the game still thinks it is a Volcano plot.

Volcano and Lake plots especially seem not susceptible to alteration once they have been marked by the game engine as being lakes or Volcanos. So even though you can alter the tile, the game in most ways still "sees" the tile as being either a lake or a volcano if it ever was such a tile.
 
Last edited:
Thank you, I realized something was amiss when printing out all the values of the terrainTypes array revealed a massive discrepancy between the map in game and the array values. Your solution works perfectly
 
Top Bottom