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

93 lines
3.0 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")
2016-08-29 02:05:28 +02:00
local constants = require("Constants")
-- imported functions
2016-08-21 23:48:55 +02:00
local scents = pheromoneUtils.scents
local processPheromone = pheromoneUtils.processPheromone
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-21 23:48:55 +02:00
local getCardinalChunks = mapUtils.getCardinalChunks
2016-08-29 02:05:28 +02:00
local mMin = math.min
-- 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-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
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
formSquads(regionMap, surface, natives, chunk, evolution_factor)
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
end
2016-08-29 02:05:28 +02:00
if (endIndex == #processQueue) then
regionMap.scanPointer = 1
else
regionMap.scanPointer = endIndex + 1
end
end
return mapProcessor