Quick question from a non-modder

Sarin

Deity
Joined
Aug 18, 2013
Messages
2,492
So, I'm trying to advance from a simple consumer to someone tinkering with mods. Right now, I'm trying to modify a map script (Planet Generator) to create 2 tile wide coasts.

I looked through script and looks to me that this is the part that needs change:
Code:
function GenerateCoasts(args)
	print("Setting coasts and oceans - Planet Simulator");
	local args = args or {};
	local bExpandCoasts = args.bExpandCoasts or true;
	local expansion_diceroll_table = args.expansion_diceroll_table or {4, 4};

	local shallowWater = GameDefines.SHALLOW_WATER_TERRAIN;
	local deepWater = GameDefines.DEEP_WATER_TERRAIN;

	for i, plot in Plots() do
		if(plot:IsWater()) then
			if(plot:IsAdjacentToLand()) then
				plot:SetTerrainType(shallowWater, false, false);
			else
				plot:SetTerrainType(deepWater, false, false);
			end
		end
	end

	if bExpandCoasts == false then
		return
	end

	-- print("Expanding coasts (MapGenerator.Lua)");
	for loop, iExpansionDiceroll in ipairs(expansion_diceroll_table) do
        local shallowWaterPlots = {};
		for i, plot in Plots() do
			if(plot:GetTerrainType() == deepWater) then
				-- Chance for each eligible plot to become an expansion is 1 / iExpansionDiceroll.
				-- Default is two passes at 1/4 chance per eligible plot on each pass.
				if(plot:IsAdjacentToShallowWater() and PWRandInt(0, iExpansionDiceroll) == 0) then
					table.insert(shallowWaterPlots, plot);
                    -- plot:SetTerrainType(shallowWater, false, false);
				end
			end
		end
        for i, plot in ipairs(shallowWaterPlots) do
            plot:SetTerrainType(shallowWater, false, false);
        end
	end
end

From what I can read, this generates 1 tile wide coasts, and if expanding coasts is enabled (no idea where that comes from though), each ocean tile bordering coastal one gets 1/4 chance of being turned into coast during each of two checks.

Now I'd like to change it to generate 2 tile wide coasts while keeping the expanding coasts part intact. Any idea how to do it? I'm quite at loss.
 
Hey Sarin, you may be interested in:

Code:
local expansion_diceroll_table = args.expansion_diceroll_table or {4, 4};

This argument is usually defined in

Code:
function GeneratePlotTypes()

near the top (generally the 2nd or 3rd function) of the actual mapscript.

The function calls for N rolls of the dice, for each argument passed in. So {x1, x2, x3} will roll 3 times, {x1, x2, x3, x4, x5} will roll 5 times. The smaller the number passed as the argument, the greater the chance of being successful.

You can think of the entire test as roughly "Let's go through all the coast tiles on the map. I am going to roll N number of dices, with each dice having Xn number of sides. Only 1 side (for example, side # 1) is evaluated as true.... in other words, you have 1/Xn chance of evaluating true. If any of the dice rolls yields true, we expand an additional coastal tile from the origin coast tile".

By default (in the code block quoted above), the test is run twice, at 25% each. Archipelago maps (if I remember correctly) runs it 3 times to simulate the coastal pathways between landmasses and islands (or at least, it tries :p).

If you want to expand your continental shelves by a decent amount (without turning the entire ocean into a shallow sea), try something like:

Code:
local args = {expansion_diceroll_table = {8, 5, 4}};

Credits to Whoward69 for kindly explaining this entire thing here in this thread. Best of luck with your modding endeavours :D.

- ThorHammerz
 
I see. That means if I change it to 1,4,10, I'll get full 2 tile wide coasts, 1/4 of tiles at distance 3 of land will be turned to coast, and then all remaining tiles in distance 3 and all tiles in distance 4 that are adjacent to those that were turned to coast in second check will get 10% chance of being turned to coast.

Do I understand it right? No other change will be necessary?
 
I see. That means if I change it to 1,4,10, I'll get full 2 tile wide coasts, 1/4 of tiles at distance 3 of land will be turned to coast, and then all remaining tiles in distance 3 and all tiles in distance 4 that are adjacent to those that were turned to coast in second check will get 10% chance of being turned to coast.

Do I understand it right? No other change will be necessary?

Not sure on the exact math, but the best way to test your theory would be to load a game, save map, and load it in worldbuilder to see if yo have the desired results.
 
Do I understand it right?

That's how I understand it works as well, but ultimately you'll need to test it in WorldBuilder as there may be other functions that run later and undo stuff.
 
Back
Top Bottom