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-21 23:48:55 +02:00
|
|
|
local pheromoneUtils = require("PheromoneUtils")
|
|
|
|
local aiBuilding = require("AIBuilding")
|
2016-08-18 07:55:08 +02:00
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- imported functions
|
|
|
|
|
2016-08-21 23:48:55 +02:00
|
|
|
local scents = pheromoneUtils.scents
|
|
|
|
local processPheromone = pheromoneUtils.processPheromone
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2016-08-21 23:48:55 +02:00
|
|
|
local sendScouts = aiBuilding.sendScouts
|
|
|
|
local formSquads = aiBuilding.formSquads
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2016-08-21 23:48:55 +02:00
|
|
|
local getCardinalChunks = mapUtils.getCardinalChunks
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2016-08-21 23:48:55 +02:00
|
|
|
local mRandom = math.random
|
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-25 01:30:45 +02:00
|
|
|
local roll = regionMap.pR
|
|
|
|
local index = regionMap.pP
|
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
if (regionMap.pP == 1) then
|
|
|
|
regionMap.pR = mRandom()
|
2016-08-25 01:30:45 +02:00
|
|
|
roll = regionMap.pR
|
2016-08-20 04:52:27 +02:00
|
|
|
end
|
|
|
|
|
2016-08-25 01:30:45 +02:00
|
|
|
local chunkQueue = regionMap.pQ[index]
|
|
|
|
for x,chunk in ipairs(chunkQueue) do
|
2016-08-21 23:48:55 +02:00
|
|
|
|
2016-08-25 01:30:45 +02:00
|
|
|
scents(chunk)
|
2016-08-21 23:48:55 +02:00
|
|
|
|
|
|
|
if (0.05 <= roll) and (roll <= 0.10) then
|
2016-08-25 01:30:45 +02:00
|
|
|
sendScouts(surface, natives, chunk, evolution_factor)
|
2016-08-21 23:48:55 +02:00
|
|
|
end
|
|
|
|
if (0.11 <= roll) and (roll <= 0.25) then
|
2016-08-25 01:30:45 +02:00
|
|
|
formSquads(regionMap, surface, natives, chunk, evolution_factor)
|
2016-08-05 06:47:51 +02:00
|
|
|
end
|
2016-08-21 23:48:55 +02:00
|
|
|
|
2016-08-25 01:30:45 +02:00
|
|
|
processPheromone(chunk, getCardinalChunks(regionMap, chunk.cX, chunk.cY))
|
2016-08-05 06:47:51 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
return mapProcessor
|