1
0
mirror of https://github.com/veden/Rampant.git synced 2024-12-26 20:54:12 +02:00
Rampant/libs/MapProcessor.lua

58 lines
1.8 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
2016-08-20 21:04:04 +02:00
-- processing is not consistant as it depends on the number of chunks that have been generated
-- so 200 chunks is processed 3 times a second and 1200 chunks is processed once a second
-- In theory, this might be fine as smaller bases have less surface to attack and need to have
-- pheromone dissipate at a faster rate.
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