1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-16 02:33:53 +02:00
Rampant/libs/MapProcessor.lua

54 lines
1.4 KiB
Lua
Raw Normal View History

local mapProcessor = {}
-- imports
local mapUtils = require("MapUtils")
-- imported functions
local getCardinalChunks = mapUtils.getCardinalChunks
2016-08-19 04:02:13 +02:00
local mRandom = math.random
-- premade tables
local processors = {}
2016-08-19 04:02:13 +02:00
local processorsProbabilityLow = {}
local processorsProbabilityHigh = {}
-- module code
function mapProcessor.processMap(regionMap, surface, natives, evolution_factor)
local count = 0
if (regionMap.pP == 1) then
regionMap.pR = mRandom()
end
local roll = regionMap.pR
local chunkQueue = regionMap.pQ[regionMap.pP]
for x=1, #chunkQueue do
local chunk = chunkQueue[x]
local cardinalArray = getCardinalChunks(regionMap, chunk.cX, chunk.cY)
for i=1, #processors do
if (processorsProbabilityLow[i] <= roll) and (roll <= processorsProbabilityHigh[i]) then
processors[i](regionMap, surface, natives, chunk, cardinalArray, evolution_factor)
end
end
end
regionMap.pP = regionMap.pP + 1
if (regionMap.pP > regionMap.pI) then
regionMap.pP = 1
end
end
2016-08-19 04:02:13 +02:00
function mapProcessor.install(processor, useProbabilityLow, useProbabilityHigh)
processors[#processors+1] = processor
2016-08-19 04:02:13 +02:00
processorsProbabilityLow[#processorsProbabilityLow+1] = useProbabilityLow
processorsProbabilityHigh[#processorsProbabilityHigh+1] = useProbabilityHigh
end
return mapProcessor