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-29 02:05:28 +02:00
|
|
|
local constants = require("Constants")
|
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-26 00:20:06 +02:00
|
|
|
local makeScouts = aiBuilding.makeScouts
|
2016-08-21 23:48:55 +02:00
|
|
|
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-29 02:05:28 +02:00
|
|
|
local mMin = math.min
|
|
|
|
|
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-29 02:05:28 +02:00
|
|
|
function mapProcessor.processMap(regionMap, surface, natives, pheromoneTotals, evolution_factor)
|
|
|
|
local roll = regionMap.processRoll
|
|
|
|
local index = regionMap.processPointer
|
2016-08-26 00:20:06 +02:00
|
|
|
local scouts = false
|
|
|
|
local squads = false
|
2016-08-25 01:30:45 +02:00
|
|
|
|
2016-08-29 02:05:28 +02:00
|
|
|
if (index == 1) then
|
2016-08-26 00:20:06 +02:00
|
|
|
roll = math.random()
|
2016-08-29 02:05:28 +02:00
|
|
|
regionMap.processRoll = roll
|
2016-08-26 00:20:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if (0.05 <= roll) and (roll <= 0.10) then
|
|
|
|
scouts = true
|
|
|
|
end
|
|
|
|
|
2016-08-26 00:41:17 +02:00
|
|
|
if (0.11 <= roll) and (roll <= 0.35) then
|
2016-08-26 00:20:06 +02:00
|
|
|
squads = true
|
2016-08-20 04:52:27 +02:00
|
|
|
end
|
|
|
|
|
2016-08-29 02:05:28 +02:00
|
|
|
local processQueue = regionMap.processQueue
|
|
|
|
local endIndex = mMin(index + constants.PROCESS_QUEUE_SIZE, #processQueue)
|
|
|
|
for x=index,endIndex do
|
|
|
|
local chunk = processQueue[x]
|
2016-08-21 23:48:55 +02:00
|
|
|
|
2016-08-29 02:05:28 +02:00
|
|
|
scents(chunk, pheromoneTotals)
|
2016-08-21 23:48:55 +02:00
|
|
|
|
2016-08-26 00:20:06 +02:00
|
|
|
if scouts then
|
|
|
|
makeScouts(surface, natives, chunk, evolution_factor)
|
2016-08-21 23:48:55 +02:00
|
|
|
end
|
2016-08-26 00:20:06 +02:00
|
|
|
if squads 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-29 02:05:28 +02:00
|
|
|
processPheromone(chunk, getCardinalChunks(regionMap, chunk.cX, chunk.cY), pheromoneTotals)
|
|
|
|
end
|
|
|
|
|
|
|
|
if (endIndex == #processQueue) then
|
|
|
|
regionMap.processPointer = 1
|
|
|
|
else
|
|
|
|
regionMap.processPointer = endIndex + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function mapProcessor.scanMap(regionMap, surface)
|
|
|
|
local index = regionMap.scanPointer
|
|
|
|
|
|
|
|
local processQueue = regionMap.processQueue
|
|
|
|
local endIndex = mMin(index + constants.SCAN_QUEUE_SIZE, #processQueue)
|
|
|
|
for x=index,endIndex do
|
|
|
|
local chunk = processQueue[x]
|
|
|
|
|
|
|
|
local spawners = surface.count_entities_filtered({area = {{chunk.pX, chunk.pY},
|
|
|
|
{chunk.pX + constants.CHUNK_SIZE, chunk.pY + constants.CHUNK_SIZE}},
|
|
|
|
type = "unit-spawner",
|
|
|
|
force = "enemy"})
|
|
|
|
chunk[constants.ENEMY_BASE_GENERATOR] = spawners * constants.ENEMY_BASE_PHEROMONE_GENERATOR_AMOUNT
|
2016-08-05 06:47:51 +02:00
|
|
|
end
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2016-08-29 02:05:28 +02:00
|
|
|
if (endIndex == #processQueue) then
|
|
|
|
regionMap.scanPointer = 1
|
|
|
|
else
|
|
|
|
regionMap.scanPointer = endIndex + 1
|
2016-08-20 04:52:27 +02:00
|
|
|
end
|
2016-08-05 06:47:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return mapProcessor
|