Fractal.BuildRidges (Civ5 API): Difference between revisions

From Civilization Modding Wiki
Jump to navigationJump to search
(Bot update)
 
(initial research)
Line 5: Line 5:


{{TypeInfos5|Function.png|This function is a member of {{Type5|Fractal}}.<br/>
{{TypeInfos5|Function.png|This function is a member of {{Type5|Fractal}}.<br/>
This is an instance method, invoke it with a colon.
This is an instance method, invoke it with a colon.<br/>
Modifies a fractal to have randomized ridges.
}}
}}


Line 17: Line 18:
|-
|-
|valign="top" style="padding-right:6px;"|numPlates:
|valign="top" style="padding-right:6px;"|numPlates:
|valign="top"| ''No description available.''
|valign="top"| ''The number of tectonic plates to use in generating the ridges. Where plates come into contact with each other, ridges are formed there.''
|-
|-
|valign="top" style="padding-right:6px;"|flags:
|valign="top" style="padding-right:6px;"|flags:
|valign="top"| ''No description available.''
|valign="top"| ''A table that holds certain additional options used in creating the fractal. See Fractal.Create().''
|-
|-
|valign="top" style="padding-right:6px;"|arg2:
|valign="top" style="padding-right:6px;"|arg2:
Line 28: Line 29:
|valign="top"| ''No description available.''
|valign="top"| ''No description available.''
|}
|}
'''Example'''
This example will create a fractal and use it to build ridges based on the size of the map. It then loops through each value in the 2D fractal array and creates mountains if the value is greater than the highest 3% of all the values.
<syntaxhighlight lang="lua" class="civ5-example">
local iW, iH = Map.GetGridSize()
local mountains = Fractal.Create(iW, iH, 3, {FRAC_WRAP_X = true}, -1, -1)
mountains:BuildRidges((iW * iH) / 200, {}, 1, 1)
local mountainThreshold = mountains:GetHeight(97);
for y = 0, iH - 1 do
for x = 0, iW - 1 do
local height = mountains:GetHeight(x, y)
--print (x .. ", " .. y .. ": " .. height)
if height >= mountainThreshold then
local plot = Map.GetPlot(x, y)
plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN, false, false)
end
end
end
</syntaxhighlight>





Revision as of 23:44, 25 January 2014

This page is a part of the Lua and UI Reference (Civ5).


Function.png This function is a member of Fractal.

This is an instance method, invoke it with a colon.
Modifies a fractal to have randomized ridges.


Usage

void Fractal:BuildRidges(int numPlates, table flags, int arg2, int arg3)


Parameters

numPlates: The number of tectonic plates to use in generating the ridges. Where plates come into contact with each other, ridges are formed there.
flags: A table that holds certain additional options used in creating the fractal. See Fractal.Create().
arg2: No description available.
arg3: No description available.

Example This example will create a fractal and use it to build ridges based on the size of the map. It then loops through each value in the 2D fractal array and creates mountains if the value is greater than the highest 3% of all the values.

local iW, iH = Map.GetGridSize()
local mountains = Fractal.Create(iW, iH, 3, {FRAC_WRAP_X = true}, -1, -1)
mountains:BuildRidges((iW * iH) / 200, {}, 1, 1)
local mountainThreshold = mountains:GetHeight(97);
for y = 0, iH - 1 do
	for x = 0, iW - 1 do
		local height = mountains:GetHeight(x, y)
		--print (x .. ", " .. y .. ": " .. height)
		if height >= mountainThreshold then
			local plot = Map.GetPlot(x, y)
			plot:SetPlotType(PlotTypes.PLOT_MOUNTAIN, false, false)
		end
	end
end


Source code samples

Redundant occurences have been removed.

Boreal.lua (G&K)

DLC/Expansion/Maps/Boreal.lua
0129
hillsFrac:BuildRidges(numPlates, iFlags, 1, 2);
0130
mountainsFrac:BuildRidges((numPlates * 0.75), iFlags, 6, 1);


ContinentsWorld.lua

Gameplay/Lua/ContinentsWorld.lua
0100
self.hillsFrac:BuildRidges(numPlates, {FRAC_WRAP_X = true}, 1, 2);
0104
self.mountainsFrac:BuildRidges((numPlates * 2) / 3, {}, 6, 1);


FractalWorld.lua

Gameplay/Lua/FractalWorld.lua
0090
self.continentsFrac:BuildRidges(numPlates, ridge_flags, 1, 2);
0674
self.hillsFrac:BuildRidges(numPlates, hills_ridge_flags, 1, 2);
0676
self.mountainsFrac:BuildRidges((numPlates * 2) / 3, peaks_ridge_flags, 6, 1);


Highlands.lua

Maps/Highlands.lua
0174
mountain_passFrac:BuildRidges(numPlates, iFlags, 1, 2);
0176
terrainFrac:BuildRidges(numPlates, iFlags, 6, 1);



The initial version of this page was created by the Civ5 API Bot, see the Civ5 API Reference FAQ. Some of the texts come from the 2kgames' wiki and most of code samples are copyrighted to Firaxis.
Functions' signatures were either copied from the 2kgames' wiki, or infered from the Lua source files and the binaries. Errors are possible.
Contributors may find help in the Contributors guide to the Civ5 API.