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

57 lines
1.7 KiB
Lua
Raw Normal View History

local mapProcessor = {}
-- imports
local mapUtils = require("MapUtils")
2016-08-21 23:48:55 +02:00
local pheromoneUtils = require("PheromoneUtils")
local aiBuilding = require("AIBuilding")
-- imported functions
2016-08-21 23:48:55 +02:00
local scents = pheromoneUtils.scents
local processPheromone = pheromoneUtils.processPheromone
2016-08-21 23:48:55 +02:00
local sendScouts = aiBuilding.sendScouts
local formSquads = aiBuilding.formSquads
2016-08-21 23:48:55 +02:00
local getCardinalChunks = mapUtils.getCardinalChunks
2016-08-21 23:48:55 +02:00
local mRandom = math.random
-- 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 roll = regionMap.pR
local index = regionMap.pP
if (regionMap.pP == 1) then
regionMap.pR = mRandom()
roll = regionMap.pR
end
local chunkQueue = regionMap.pQ[index]
for x,chunk in ipairs(chunkQueue) do
2016-08-21 23:48:55 +02:00
scents(chunk)
2016-08-21 23:48:55 +02:00
if (0.05 <= roll) and (roll <= 0.10) then
sendScouts(surface, natives, chunk, evolution_factor)
2016-08-21 23:48:55 +02:00
end
if (0.11 <= roll) and (roll <= 0.25) then
formSquads(regionMap, surface, natives, chunk, evolution_factor)
end
2016-08-21 23:48:55 +02:00
processPheromone(chunk, getCardinalChunks(regionMap, chunk.cX, chunk.cY))
end
regionMap.pP = regionMap.pP + 1
if (regionMap.pP > regionMap.pI) then
regionMap.pP = 1
end
end
return mapProcessor