2016-08-05 06:47:51 +02:00
|
|
|
local mapProcessor = {}
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- imports
|
|
|
|
|
2016-08-18 07:55:08 +02:00
|
|
|
local mapUtils = require("MapUtils")
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- imported functions
|
|
|
|
|
|
|
|
local getCardinalChunks = mapUtils.getCardinalChunks
|
|
|
|
|
2016-08-19 04:02:13 +02:00
|
|
|
local mRandom = math.random
|
2016-08-20 04:52:27 +02:00
|
|
|
|
|
|
|
-- premade tables
|
|
|
|
|
2016-08-05 06:47:51 +02:00
|
|
|
local processors = {}
|
2016-08-19 04:02:13 +02:00
|
|
|
local processorsProbabilityLow = {}
|
|
|
|
local processorsProbabilityHigh = {}
|
2016-08-05 06:47:51 +02:00
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- 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.
|
2016-08-20 04:52:27 +02:00
|
|
|
function mapProcessor.processMap(regionMap, surface, natives, evolution_factor)
|
2016-08-05 06:47:51 +02:00
|
|
|
local count = 0
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
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)
|
2016-08-05 06:47:51 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-20 04:52:27 +02:00
|
|
|
|
|
|
|
regionMap.pP = regionMap.pP + 1
|
|
|
|
if (regionMap.pP > regionMap.pI) then
|
|
|
|
regionMap.pP = 1
|
|
|
|
end
|
2016-08-05 06:47:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-08-19 04:02:13 +02:00
|
|
|
function mapProcessor.install(processor, useProbabilityLow, useProbabilityHigh)
|
2016-08-05 06:47:51 +02:00
|
|
|
processors[#processors+1] = processor
|
2016-08-19 04:02:13 +02:00
|
|
|
processorsProbabilityLow[#processorsProbabilityLow+1] = useProbabilityLow
|
|
|
|
processorsProbabilityHigh[#processorsProbabilityHigh+1] = useProbabilityHigh
|
2016-08-05 06:47:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return mapProcessor
|