2019-02-15 20:17:30 -08:00
|
|
|
if mapProcessorG then
|
|
|
|
return mapProcessorG
|
|
|
|
end
|
2016-08-04 21:47:51 -07:00
|
|
|
local mapProcessor = {}
|
|
|
|
|
2016-08-19 19:52:27 -07:00
|
|
|
-- imports
|
|
|
|
|
2016-08-21 14:48:55 -07:00
|
|
|
local pheromoneUtils = require("PheromoneUtils")
|
2017-06-12 20:16:43 -07:00
|
|
|
local aiAttackWave = require("AIAttackWave")
|
2017-05-19 00:47:24 -07:00
|
|
|
local aiPredicates = require("AIPredicates")
|
2016-08-28 17:05:28 -07:00
|
|
|
local constants = require("Constants")
|
2016-10-14 17:00:18 -07:00
|
|
|
local mapUtils = require("MapUtils")
|
2017-05-19 00:47:24 -07:00
|
|
|
local playerUtils = require("PlayerUtils")
|
2017-11-20 23:27:03 -08:00
|
|
|
local chunkUtils = require("ChunkUtils")
|
2018-01-14 23:41:55 -08:00
|
|
|
local chunkPropertyUtils = require("ChunkPropertyUtils")
|
2018-01-20 23:42:47 -08:00
|
|
|
local baseUtils = require("BaseUtils")
|
2017-06-15 18:30:26 -07:00
|
|
|
|
2016-09-14 04:16:33 -07:00
|
|
|
-- constants
|
|
|
|
|
2020-04-27 20:41:18 -07:00
|
|
|
local DURATION_ACTIVE_NEST = constants.DURATION_ACTIVE_NEST
|
|
|
|
|
2016-09-14 04:16:33 -07:00
|
|
|
local PROCESS_QUEUE_SIZE = constants.PROCESS_QUEUE_SIZE
|
2020-05-21 23:57:03 -07:00
|
|
|
local RESOURCE_QUEUE_SIZE = constants.RESOURCE_QUEUE_SIZE
|
|
|
|
local ENEMY_QUEUE_SIZE = constants.ENEMY_QUEUE_SIZE
|
|
|
|
local PLAYER_QUEUE_SIZE = constants.PLAYER_QUEUE_SIZE
|
2016-11-04 00:26:19 -07:00
|
|
|
|
2020-05-21 23:57:03 -07:00
|
|
|
local CLEANUP_QUEUE_SIZE = constants.CLEANUP_QUEUE_SIZE
|
2016-09-14 04:16:33 -07:00
|
|
|
|
2016-10-14 17:00:18 -07:00
|
|
|
local PROCESS_PLAYER_BOUND = constants.PROCESS_PLAYER_BOUND
|
|
|
|
local CHUNK_TICK = constants.CHUNK_TICK
|
|
|
|
|
2020-05-22 11:45:05 -07:00
|
|
|
local PROCESS_STATIC_QUEUE_SIZE = constants.PROCESS_STATIC_QUEUE_SIZE
|
|
|
|
|
2016-11-04 00:26:19 -07:00
|
|
|
local AI_VENGENCE_SQUAD_COST = constants.AI_VENGENCE_SQUAD_COST
|
|
|
|
|
2021-12-12 09:56:31 -08:00
|
|
|
local AI_STATE_AGGRESSIVE = constants.AI_STATE_AGGRESSIVE
|
|
|
|
local AI_STATE_SIEGE = constants.AI_STATE_SIEGE
|
2021-02-13 20:49:54 -08:00
|
|
|
local AI_STATE_PEACEFUL = constants.AI_STATE_PEACEFUL
|
|
|
|
local AI_STATE_MIGRATING = constants.AI_STATE_MIGRATING
|
2016-11-04 00:26:19 -07:00
|
|
|
|
2021-12-08 22:01:54 -08:00
|
|
|
local COOLDOWN_DRAIN = constants.COOLDOWN_DRAIN
|
2020-05-19 19:37:16 -07:00
|
|
|
local COOLDOWN_RALLY = constants.COOLDOWN_RALLY
|
|
|
|
local COOLDOWN_RETREAT = constants.COOLDOWN_RETREAT
|
2018-02-11 19:21:28 -08:00
|
|
|
|
2018-01-19 23:15:13 -08:00
|
|
|
local BASE_PROCESS_INTERVAL = constants.BASE_PROCESS_INTERVAL
|
|
|
|
|
2016-08-19 19:52:27 -07:00
|
|
|
-- imported functions
|
|
|
|
|
2022-01-14 11:17:33 -08:00
|
|
|
local removeChunkToNest = mapUtils.removeChunkToNest
|
|
|
|
|
2020-05-22 11:45:05 -07:00
|
|
|
local processStaticPheromone = pheromoneUtils.processStaticPheromone
|
2016-08-21 14:48:55 -07:00
|
|
|
local processPheromone = pheromoneUtils.processPheromone
|
2016-08-19 19:52:27 -07:00
|
|
|
|
2020-05-23 21:17:18 -07:00
|
|
|
local getDeathGenerator = chunkPropertyUtils.getDeathGenerator
|
2020-05-19 19:37:16 -07:00
|
|
|
local processBase = baseUtils.processBase
|
|
|
|
|
|
|
|
local processNestActiveness = chunkPropertyUtils.processNestActiveness
|
2021-11-30 19:48:52 -08:00
|
|
|
local getChunkBase = chunkPropertyUtils.getChunkBase
|
2020-05-19 19:37:16 -07:00
|
|
|
|
2017-06-12 20:16:43 -07:00
|
|
|
local formSquads = aiAttackWave.formSquads
|
2019-02-19 22:16:43 -08:00
|
|
|
local formVengenceSquad = aiAttackWave.formVengenceSquad
|
2021-12-12 10:19:59 -08:00
|
|
|
local formVengenceSettler = aiAttackWave.formVengenceSettler
|
2020-05-19 19:37:16 -07:00
|
|
|
local formSettlers = aiAttackWave.formSettlers
|
2016-08-19 19:52:27 -07:00
|
|
|
|
2016-10-14 17:00:18 -07:00
|
|
|
local getChunkByPosition = mapUtils.getChunkByPosition
|
2017-12-28 21:38:10 -08:00
|
|
|
local getChunkByXY = mapUtils.getChunkByXY
|
2021-12-05 10:19:04 -08:00
|
|
|
local getChunkById = mapUtils.getChunkById
|
2016-10-14 17:00:18 -07:00
|
|
|
|
2017-11-20 23:27:03 -08:00
|
|
|
local validPlayer = playerUtils.validPlayer
|
|
|
|
|
2020-05-21 23:57:03 -07:00
|
|
|
local addPlayerToChunk = chunkPropertyUtils.addPlayerToChunk
|
|
|
|
|
|
|
|
local mapScanEnemyChunk = chunkUtils.mapScanEnemyChunk
|
|
|
|
local mapScanPlayerChunk = chunkUtils.mapScanPlayerChunk
|
|
|
|
local mapScanResourceChunk = chunkUtils.mapScanResourceChunk
|
2017-12-28 21:38:10 -08:00
|
|
|
|
2018-01-14 23:41:55 -08:00
|
|
|
local getNestCount = chunkPropertyUtils.getNestCount
|
|
|
|
local getEnemyStructureCount = chunkPropertyUtils.getEnemyStructureCount
|
2019-02-19 22:16:43 -08:00
|
|
|
local getNestActiveness = chunkPropertyUtils.getNestActiveness
|
2020-04-27 20:41:18 -07:00
|
|
|
|
2019-02-19 22:16:43 -08:00
|
|
|
local getRaidNestActiveness = chunkPropertyUtils.getRaidNestActiveness
|
2016-08-19 19:52:27 -07:00
|
|
|
|
2017-05-19 00:47:24 -07:00
|
|
|
local canAttack = aiPredicates.canAttack
|
2018-02-14 00:28:42 -08:00
|
|
|
local canMigrate = aiPredicates.canMigrate
|
2017-05-13 15:32:16 -07:00
|
|
|
|
2021-02-13 20:49:54 -08:00
|
|
|
local tableSize = table_size
|
2017-05-27 21:50:37 -07:00
|
|
|
|
2016-08-28 17:05:28 -07:00
|
|
|
local mMin = math.min
|
2020-05-21 23:57:03 -07:00
|
|
|
local mMax = math.max
|
2016-08-28 17:05:28 -07:00
|
|
|
|
2020-05-19 19:37:16 -07:00
|
|
|
local next = next
|
2017-06-30 21:36:23 -07:00
|
|
|
|
2016-08-19 19:52:27 -07:00
|
|
|
-- module code
|
|
|
|
|
2016-10-14 17:00:18 -07:00
|
|
|
--[[
|
|
|
|
processing is not consistant as it depends on the number of chunks that have been generated
|
|
|
|
so if we process 400 chunks an iteration and 200 chunks have been generated than these are
|
|
|
|
processed 3 times a second and 1200 generated chunks would be processed once a second
|
2019-02-02 22:01:28 -08:00
|
|
|
In theory, this might be fine as smaller bases have less surface to attack and need to have
|
2016-10-14 17:00:18 -07:00
|
|
|
pheromone dissipate at a faster rate.
|
|
|
|
--]]
|
2021-02-13 20:49:54 -08:00
|
|
|
function mapProcessor.processMap(map, tick)
|
2020-05-21 23:57:03 -07:00
|
|
|
local outgoingWave = map.outgoingScanWave
|
2018-01-13 21:48:21 -08:00
|
|
|
local processQueue = map.processQueue
|
2020-05-21 23:57:03 -07:00
|
|
|
local processQueueLength = #processQueue
|
2021-12-31 23:52:26 -08:00
|
|
|
local index = mMin(map.processIndex, processQueueLength)
|
2020-05-19 19:37:16 -07:00
|
|
|
|
2020-05-21 23:57:03 -07:00
|
|
|
local step
|
|
|
|
local endIndex
|
|
|
|
if outgoingWave then
|
|
|
|
step = 1
|
|
|
|
endIndex = mMin(index + PROCESS_QUEUE_SIZE, processQueueLength)
|
|
|
|
else
|
|
|
|
step = -1
|
|
|
|
endIndex = mMax(index - PROCESS_QUEUE_SIZE, 1)
|
2018-10-19 22:17:37 -07:00
|
|
|
end
|
|
|
|
|
2020-12-04 20:49:51 -08:00
|
|
|
if (processQueueLength == 0) then
|
|
|
|
return
|
|
|
|
end
|
2021-02-13 20:49:54 -08:00
|
|
|
|
2020-05-21 23:57:03 -07:00
|
|
|
for x=index,endIndex,step do
|
2019-10-19 12:13:48 -07:00
|
|
|
local chunk = processQueue[x]
|
2021-12-04 16:44:59 -08:00
|
|
|
if chunk[CHUNK_TICK] ~= tick then
|
2020-05-21 23:57:03 -07:00
|
|
|
chunk[CHUNK_TICK] = tick
|
|
|
|
processPheromone(map, chunk)
|
2019-10-19 12:13:48 -07:00
|
|
|
end
|
2016-08-28 17:05:28 -07:00
|
|
|
end
|
2019-02-02 22:01:28 -08:00
|
|
|
|
2020-05-21 23:57:03 -07:00
|
|
|
if (endIndex == processQueueLength) then
|
|
|
|
map.outgoingScanWave = false
|
|
|
|
elseif (endIndex == 1) then
|
|
|
|
map.outgoingScanWave = true
|
|
|
|
elseif outgoingWave then
|
2018-01-13 21:48:21 -08:00
|
|
|
map.processIndex = endIndex + 1
|
2020-05-21 23:57:03 -07:00
|
|
|
else
|
|
|
|
map.processIndex = endIndex - 1
|
2016-08-28 17:05:28 -07:00
|
|
|
end
|
2021-12-04 14:57:23 -08:00
|
|
|
map.universe.processedChunks = map.universe.processedChunks + PROCESS_QUEUE_SIZE
|
2016-08-28 17:05:28 -07:00
|
|
|
end
|
|
|
|
|
2021-02-13 20:49:54 -08:00
|
|
|
function mapProcessor.processStaticMap(map)
|
2020-05-22 11:45:05 -07:00
|
|
|
local outgoingWave = map.outgoingStaticScanWave
|
|
|
|
local processQueue = map.processQueue
|
|
|
|
local processQueueLength = #processQueue
|
2021-12-31 23:52:26 -08:00
|
|
|
local index = mMin(map.processStaticIndex, processQueueLength)
|
2020-05-22 11:45:05 -07:00
|
|
|
|
|
|
|
local step
|
|
|
|
local endIndex
|
|
|
|
if outgoingWave then
|
|
|
|
step = 1
|
|
|
|
endIndex = mMin(index + PROCESS_STATIC_QUEUE_SIZE, processQueueLength)
|
|
|
|
else
|
|
|
|
step = -1
|
|
|
|
endIndex = mMax(index - PROCESS_STATIC_QUEUE_SIZE, 1)
|
|
|
|
end
|
|
|
|
|
2020-12-04 20:49:51 -08:00
|
|
|
if (processQueueLength == 0) then
|
|
|
|
return
|
|
|
|
end
|
2021-02-13 20:49:54 -08:00
|
|
|
|
2020-05-22 11:45:05 -07:00
|
|
|
for x=index,endIndex,step do
|
2021-12-11 10:44:55 -08:00
|
|
|
processStaticPheromone(map, processQueue[x])
|
2020-05-22 11:45:05 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
if (endIndex == processQueueLength) then
|
|
|
|
map.outgoingStaticScanWave = false
|
|
|
|
elseif (endIndex == 1) then
|
|
|
|
map.outgoingStaticScanWave = true
|
|
|
|
elseif outgoingWave then
|
|
|
|
map.processStaticIndex = endIndex + 1
|
|
|
|
else
|
|
|
|
map.processStaticIndex = endIndex - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-27 20:41:18 -07:00
|
|
|
local function queueNestSpawners(map, chunk, tick)
|
2021-12-05 20:56:08 -08:00
|
|
|
local processActiveNest = map.universe.processActiveNest
|
2020-05-19 19:37:16 -07:00
|
|
|
|
2021-12-05 21:44:19 -08:00
|
|
|
local chunkId = chunk.id
|
|
|
|
if not processActiveNest[chunkId] then
|
2021-12-07 18:21:27 -08:00
|
|
|
if (getNestActiveness(map, chunk) > 0) or (getRaidNestActiveness(map, chunk) > 0) then
|
|
|
|
processActiveNest[chunkId] = {
|
|
|
|
map = map,
|
|
|
|
chunk = chunk,
|
|
|
|
tick = tick + DURATION_ACTIVE_NEST
|
|
|
|
}
|
|
|
|
end
|
2020-04-27 20:41:18 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-14 17:00:18 -07:00
|
|
|
--[[
|
|
|
|
Localized player radius were processing takes place in realtime, doesn't store state
|
|
|
|
between calls.
|
2019-02-02 22:01:28 -08:00
|
|
|
vs
|
2016-10-14 17:00:18 -07:00
|
|
|
the slower passive version processing the entire map in multiple passes.
|
|
|
|
--]]
|
2021-12-05 17:16:14 -08:00
|
|
|
function mapProcessor.processPlayers(players, universe, tick)
|
2016-10-14 17:00:18 -07:00
|
|
|
-- put down player pheromone for player hunters
|
|
|
|
-- randomize player order to ensure a single player isn't singled out
|
2018-05-25 15:23:22 -07:00
|
|
|
-- not looping everyone because the cost is high enough already in multiplayer
|
2019-12-06 21:57:20 -08:00
|
|
|
if (#players > 0) then
|
2021-12-05 17:16:14 -08:00
|
|
|
local player = players[universe.random(#players)]
|
2021-02-19 23:31:36 -08:00
|
|
|
if validPlayer(player) then
|
2021-12-05 17:16:14 -08:00
|
|
|
local char = player.character
|
|
|
|
local map = universe.maps[char.surface.index]
|
|
|
|
if map then
|
|
|
|
local allowingAttacks = canAttack(map)
|
|
|
|
local playerChunk = getChunkByPosition(map, char.position)
|
|
|
|
|
|
|
|
if (playerChunk ~= -1) then
|
|
|
|
local vengence = allowingAttacks and
|
|
|
|
(map.points >= AI_VENGENCE_SQUAD_COST) and
|
|
|
|
((getEnemyStructureCount(map, playerChunk) > 0) or
|
|
|
|
(-getDeathGenerator(map, playerChunk) < -universe.retreatThreshold))
|
|
|
|
|
|
|
|
for x=playerChunk.x - PROCESS_PLAYER_BOUND, playerChunk.x + PROCESS_PLAYER_BOUND, 32 do
|
|
|
|
for y=playerChunk.y - PROCESS_PLAYER_BOUND, playerChunk.y + PROCESS_PLAYER_BOUND, 32 do
|
|
|
|
local chunk = getChunkByXY(map, x, y)
|
|
|
|
|
|
|
|
if (chunk ~= -1) and (chunk[CHUNK_TICK] ~= tick) then
|
|
|
|
chunk[CHUNK_TICK] = tick
|
|
|
|
processPheromone(map, chunk, true)
|
|
|
|
|
|
|
|
if (getNestCount(map, chunk) > 0) then
|
|
|
|
processNestActiveness(map, chunk)
|
|
|
|
queueNestSpawners(map, chunk, tick)
|
|
|
|
|
|
|
|
if vengence then
|
2021-12-05 19:40:39 -08:00
|
|
|
local pack = universe.vengenceQueue[chunk.id]
|
|
|
|
if not pack then
|
|
|
|
pack = {
|
|
|
|
v = 0,
|
|
|
|
map = map
|
|
|
|
}
|
|
|
|
universe.vengenceQueue[chunk.id] = pack
|
|
|
|
end
|
|
|
|
pack.v = pack.v + 1
|
2021-12-05 17:16:14 -08:00
|
|
|
end
|
2020-05-19 19:37:16 -07:00
|
|
|
end
|
2019-02-19 22:16:43 -08:00
|
|
|
end
|
2019-10-19 12:13:48 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-10-14 17:00:18 -07:00
|
|
|
end
|
2019-03-05 22:18:03 -08:00
|
|
|
|
2019-12-06 21:57:20 -08:00
|
|
|
for i=1,#players do
|
|
|
|
local player = players[i]
|
2021-02-19 23:31:36 -08:00
|
|
|
if validPlayer(player) then
|
2021-12-05 17:16:14 -08:00
|
|
|
local char = player.character
|
|
|
|
local map = universe.maps[char.surface.index]
|
|
|
|
if map then
|
|
|
|
local playerChunk = getChunkByPosition(map, char.position)
|
2019-10-19 12:13:48 -07:00
|
|
|
|
2021-12-05 17:16:14 -08:00
|
|
|
if (playerChunk ~= -1) then
|
|
|
|
addPlayerToChunk(map, playerChunk, player.name)
|
|
|
|
end
|
2019-10-19 12:13:48 -07:00
|
|
|
end
|
|
|
|
end
|
2019-03-05 22:18:03 -08:00
|
|
|
end
|
2016-10-14 17:00:18 -07:00
|
|
|
end
|
|
|
|
|
2021-12-08 22:01:54 -08:00
|
|
|
local function processCleanUp(universe, chunks, iterator, tick, duration)
|
|
|
|
local chunkId = universe[iterator]
|
|
|
|
local chunkPack
|
|
|
|
if not chunkId then
|
|
|
|
chunkId, chunkPack = next(chunks, nil)
|
|
|
|
else
|
|
|
|
chunkPack = chunks[chunkId]
|
|
|
|
end
|
|
|
|
if not chunkId then
|
|
|
|
universe[iterator] = nil
|
|
|
|
else
|
|
|
|
universe[iterator] = next(chunks, chunkId)
|
|
|
|
if (tick - chunkPack.tick) > duration then
|
|
|
|
chunks[chunkId] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-08 22:13:38 -08:00
|
|
|
function mapProcessor.cleanUpMapTables(universe, tick)
|
|
|
|
local retreats = universe.chunkToRetreats
|
|
|
|
local rallys = universe.chunkToRallys
|
|
|
|
local drained = universe.chunkToDrained
|
2017-05-23 23:46:23 -07:00
|
|
|
|
2021-12-08 22:13:38 -08:00
|
|
|
for _=1,CLEANUP_QUEUE_SIZE do
|
|
|
|
processCleanUp(universe, retreats, "chunkToRetreatIterator", tick, COOLDOWN_RETREAT)
|
2018-02-11 19:21:28 -08:00
|
|
|
|
2021-12-08 22:13:38 -08:00
|
|
|
processCleanUp(universe, rallys, "chunkToRallyIterator", tick, COOLDOWN_RALLY)
|
2018-02-11 19:21:28 -08:00
|
|
|
|
2021-12-08 22:01:54 -08:00
|
|
|
processCleanUp(universe, drained, "chunkToDrainedIterator", tick, COOLDOWN_DRAIN)
|
2020-05-21 23:57:03 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[
|
|
|
|
Passive scan to find entities that have been generated outside the factorio event system
|
|
|
|
--]]
|
2021-02-19 21:41:30 -08:00
|
|
|
function mapProcessor.scanPlayerMap(map, tick)
|
2021-02-13 20:49:54 -08:00
|
|
|
if (map.nextProcessMap == tick) or (map.nextPlayerScan == tick) or
|
|
|
|
(map.nextEnemyScan == tick) or (map.nextChunkProcess == tick)
|
|
|
|
then
|
2020-05-21 23:57:03 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local index = map.scanPlayerIndex
|
|
|
|
|
|
|
|
local processQueue = map.processQueue
|
2020-12-04 20:49:51 -08:00
|
|
|
local processQueueLength = #processQueue
|
2021-02-13 20:49:54 -08:00
|
|
|
|
2020-12-04 20:49:51 -08:00
|
|
|
local endIndex = mMin(index + PLAYER_QUEUE_SIZE, processQueueLength)
|
|
|
|
|
|
|
|
if (processQueueLength == 0) then
|
|
|
|
return
|
|
|
|
end
|
2020-05-21 23:57:03 -07:00
|
|
|
|
|
|
|
for x=index,endIndex do
|
2021-12-11 10:42:49 -08:00
|
|
|
mapScanPlayerChunk(processQueue[x], map)
|
2020-05-21 23:57:03 -07:00
|
|
|
end
|
|
|
|
|
2020-12-04 20:49:51 -08:00
|
|
|
if (endIndex == processQueueLength) then
|
2020-05-21 23:57:03 -07:00
|
|
|
map.scanPlayerIndex = 1
|
|
|
|
else
|
|
|
|
map.scanPlayerIndex = endIndex + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-19 21:41:30 -08:00
|
|
|
function mapProcessor.scanEnemyMap(map, tick)
|
2020-05-21 23:57:03 -07:00
|
|
|
if (map.nextProcessMap == tick) or (map.nextPlayerScan == tick) or (map.nextChunkProcess == tick) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local index = map.scanEnemyIndex
|
|
|
|
|
|
|
|
local processQueue = map.processQueue
|
2020-12-04 20:49:51 -08:00
|
|
|
local processQueueLength = #processQueue
|
2021-02-13 20:49:54 -08:00
|
|
|
|
2020-05-21 23:57:03 -07:00
|
|
|
local endIndex = mMin(index + ENEMY_QUEUE_SIZE, #processQueue)
|
2019-02-18 16:43:01 -08:00
|
|
|
|
2020-12-04 20:49:51 -08:00
|
|
|
if (processQueueLength == 0) then
|
|
|
|
return
|
|
|
|
end
|
2021-02-13 20:49:54 -08:00
|
|
|
|
2020-05-21 23:57:03 -07:00
|
|
|
for x=index,endIndex do
|
2021-12-04 16:46:29 -08:00
|
|
|
mapScanEnemyChunk(processQueue[x], map, tick)
|
2016-08-04 21:47:51 -07:00
|
|
|
end
|
2017-04-21 16:14:04 -07:00
|
|
|
|
2020-12-04 20:49:51 -08:00
|
|
|
if (endIndex == processQueueLength) then
|
2020-05-21 23:57:03 -07:00
|
|
|
map.scanEnemyIndex = 1
|
2016-08-28 17:05:28 -07:00
|
|
|
else
|
2020-05-21 23:57:03 -07:00
|
|
|
map.scanEnemyIndex = endIndex + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-19 21:41:30 -08:00
|
|
|
function mapProcessor.scanResourceMap(map, tick)
|
2021-02-13 20:49:54 -08:00
|
|
|
if (map.nextProcessMap == tick) or (map.nextPlayerScan == tick) or
|
|
|
|
(map.nextEnemyScan == tick) or (map.nextChunkProcess == tick)
|
|
|
|
then
|
2020-05-21 23:57:03 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local index = map.scanResourceIndex
|
|
|
|
|
2021-02-13 20:49:54 -08:00
|
|
|
local processQueue = map.processQueue
|
2020-12-04 20:49:51 -08:00
|
|
|
local processQueueLength = #processQueue
|
2021-02-13 20:49:54 -08:00
|
|
|
|
2020-12-04 20:49:51 -08:00
|
|
|
local endIndex = mMin(index + RESOURCE_QUEUE_SIZE, processQueueLength)
|
2020-05-21 23:57:03 -07:00
|
|
|
|
2020-12-04 20:49:51 -08:00
|
|
|
if (processQueueLength == 0) then
|
|
|
|
return
|
|
|
|
end
|
2021-02-13 20:49:54 -08:00
|
|
|
|
2020-05-21 23:57:03 -07:00
|
|
|
for x=index,endIndex do
|
2021-12-11 10:42:49 -08:00
|
|
|
mapScanResourceChunk(processQueue[x], map)
|
2020-05-21 23:57:03 -07:00
|
|
|
end
|
|
|
|
|
2020-12-04 20:49:51 -08:00
|
|
|
if (endIndex == processQueueLength) then
|
2020-05-21 23:57:03 -07:00
|
|
|
map.scanResourceIndex = 1
|
|
|
|
else
|
|
|
|
map.scanResourceIndex = endIndex + 1
|
2016-08-19 19:52:27 -07:00
|
|
|
end
|
2016-08-04 21:47:51 -07:00
|
|
|
end
|
|
|
|
|
2021-12-05 20:56:08 -08:00
|
|
|
function mapProcessor.processActiveNests(universe, tick)
|
|
|
|
local processActiveNest = universe.processActiveNest
|
2021-12-05 21:44:19 -08:00
|
|
|
local chunkId = universe.processActiveNestIterator
|
|
|
|
local chunkPack
|
|
|
|
if not chunkId then
|
|
|
|
chunkId, chunkPack = next(processActiveNest, nil)
|
|
|
|
else
|
|
|
|
chunkPack = processActiveNest[chunkId]
|
|
|
|
end
|
|
|
|
if not chunkId then
|
|
|
|
universe.processActiveNestIterator = nil
|
|
|
|
else
|
|
|
|
universe.processActiveNestIterator = next(processActiveNest, chunkId)
|
|
|
|
if chunkPack.tick < tick then
|
2021-12-05 20:56:08 -08:00
|
|
|
local map = chunkPack.map
|
2021-12-07 22:13:32 -08:00
|
|
|
if not map.surface.valid then
|
|
|
|
processActiveNest[chunkId] = nil
|
|
|
|
return
|
|
|
|
end
|
2021-12-05 21:44:19 -08:00
|
|
|
local chunk = chunkPack.chunk
|
|
|
|
processNestActiveness(map, chunk)
|
|
|
|
if (getNestActiveness(map, chunk) == 0) and (getRaidNestActiveness(map, chunk) == 0) then
|
|
|
|
processActiveNest[chunkId] = nil
|
2021-12-07 18:21:27 -08:00
|
|
|
else
|
|
|
|
chunkPack.tick = tick + DURATION_ACTIVE_NEST
|
2020-04-27 20:41:18 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-05 19:40:39 -08:00
|
|
|
function mapProcessor.processVengence(universe)
|
|
|
|
local vengenceQueue = universe.vengenceQueue
|
|
|
|
local chunkId = universe.deployVengenceIterator
|
|
|
|
local vengencePack
|
2021-12-05 10:19:04 -08:00
|
|
|
if not chunkId then
|
2021-12-05 19:40:39 -08:00
|
|
|
chunkId, vengencePack = next(vengenceQueue, nil)
|
|
|
|
else
|
|
|
|
vengencePack = vengenceQueue[chunkId]
|
2021-11-24 18:31:28 -08:00
|
|
|
end
|
2021-12-05 10:19:04 -08:00
|
|
|
if not chunkId then
|
2021-12-05 19:40:39 -08:00
|
|
|
universe.deployVengenceIterator = nil
|
|
|
|
if (tableSize(vengenceQueue) == 0) then
|
|
|
|
universe.vengenceQueue = {}
|
2020-05-21 23:57:03 -07:00
|
|
|
end
|
2020-05-19 19:37:16 -07:00
|
|
|
else
|
2021-12-05 19:40:39 -08:00
|
|
|
universe.deployVengenceIterator = next(vengenceQueue, chunkId)
|
2021-12-14 22:03:29 -08:00
|
|
|
vengenceQueue[chunkId] = nil
|
2021-12-07 22:13:32 -08:00
|
|
|
local map = vengencePack.map
|
|
|
|
if not map.surface.valid then
|
|
|
|
return
|
|
|
|
end
|
2021-12-14 22:03:29 -08:00
|
|
|
local chunk = getChunkById(vengencePack.map, chunkId)
|
2021-12-12 10:19:59 -08:00
|
|
|
if universe.enabledMigration and (universe.random() < 0.075) then
|
2021-12-14 22:03:29 -08:00
|
|
|
formVengenceSettler(map, chunk)
|
2021-12-12 10:19:59 -08:00
|
|
|
else
|
2021-12-14 22:03:29 -08:00
|
|
|
formVengenceSquad(map, chunk)
|
2021-12-12 10:19:59 -08:00
|
|
|
end
|
2020-05-19 19:37:16 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-07 18:38:02 -08:00
|
|
|
function mapProcessor.processNests(universe, tick)
|
2021-12-07 22:13:32 -08:00
|
|
|
local chunkId = universe.processNestIterator
|
|
|
|
local chunkPack
|
|
|
|
if not chunkId then
|
|
|
|
chunkId,chunkPack = next(universe.chunkToNests, nil)
|
|
|
|
else
|
|
|
|
chunkPack = universe.chunkToNests[chunkId]
|
|
|
|
end
|
|
|
|
if not chunkId then
|
|
|
|
universe.processNestIterator = nil
|
|
|
|
else
|
|
|
|
universe.processNestIterator = next(universe.chunkToNests, chunkId)
|
2021-12-07 18:38:02 -08:00
|
|
|
local map = chunkPack.map
|
2021-12-07 22:13:32 -08:00
|
|
|
if not map.surface.valid then
|
2022-01-14 11:17:33 -08:00
|
|
|
removeChunkToNest(universe, chunkId)
|
2021-12-07 22:13:32 -08:00
|
|
|
return
|
|
|
|
end
|
2021-12-05 10:19:04 -08:00
|
|
|
local chunk = getChunkById(map, chunkId)
|
2021-02-19 21:41:30 -08:00
|
|
|
processNestActiveness(map, chunk)
|
|
|
|
queueNestSpawners(map, chunk, tick)
|
2020-05-19 19:37:16 -07:00
|
|
|
|
2021-12-07 18:38:02 -08:00
|
|
|
if universe.NEW_ENEMIES then
|
2021-11-30 19:48:52 -08:00
|
|
|
local base = getChunkBase(map, chunk)
|
2021-02-19 21:41:30 -08:00
|
|
|
if base and ((tick - base.tick) > BASE_PROCESS_INTERVAL) then
|
2021-02-19 23:31:36 -08:00
|
|
|
processBase(chunk, map, tick, base)
|
2020-05-19 19:37:16 -07:00
|
|
|
end
|
|
|
|
end
|
2020-05-21 23:57:03 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-07 21:36:56 -08:00
|
|
|
local function processSpawnersBody(universe, iterator, chunks)
|
2021-12-07 22:13:32 -08:00
|
|
|
local chunkId = universe[iterator]
|
|
|
|
local chunkPack
|
|
|
|
if not chunkId then
|
|
|
|
chunkId,chunkPack = next(chunks, nil)
|
|
|
|
else
|
|
|
|
chunkPack = chunks[chunkId]
|
|
|
|
end
|
|
|
|
if not chunkId then
|
|
|
|
universe[iterator] = nil
|
|
|
|
else
|
|
|
|
universe[iterator] = next(chunks, chunkId)
|
2021-12-07 21:36:56 -08:00
|
|
|
local map = chunkPack.map
|
2021-12-07 22:13:32 -08:00
|
|
|
if not map.surface.valid then
|
2022-01-14 11:17:33 -08:00
|
|
|
if (iterator == "processMigrationIterator") then
|
|
|
|
removeChunkToNest(universe, chunkId)
|
|
|
|
else
|
|
|
|
chunks[chunkId] = nil
|
|
|
|
end
|
2021-12-07 22:13:32 -08:00
|
|
|
return
|
|
|
|
end
|
2021-12-07 21:36:56 -08:00
|
|
|
local state = chunkPack.map.state
|
|
|
|
if state == AI_STATE_PEACEFUL then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if iterator == "processMigrationIterator" then
|
2021-12-12 09:56:31 -08:00
|
|
|
if (state ~= AI_STATE_MIGRATING) and (state ~= AI_STATE_SIEGE) then
|
2021-12-07 21:36:56 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
elseif iterator == "processActiveRaidSpawnerIterator" then
|
|
|
|
if (state == AI_STATE_AGGRESSIVE) or (state == AI_STATE_MIGRATING) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
elseif iterator == "processActiveSpawnerIterator" then
|
|
|
|
if (state == AI_STATE_MIGRATING) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-05 10:19:04 -08:00
|
|
|
local chunk = getChunkById(map, chunkId)
|
2021-11-24 19:56:10 -08:00
|
|
|
local migrate = canMigrate(map)
|
2021-11-25 11:11:46 -08:00
|
|
|
local attack = canAttack(map)
|
2021-02-19 21:41:30 -08:00
|
|
|
if migrate then
|
|
|
|
formSettlers(map, chunk)
|
2021-12-10 11:12:54 -08:00
|
|
|
end
|
|
|
|
if attack then
|
2021-11-25 11:11:46 -08:00
|
|
|
formSquads(map, chunk)
|
2020-05-21 23:57:03 -07:00
|
|
|
end
|
2020-05-19 19:37:16 -07:00
|
|
|
end
|
|
|
|
end
|
2020-04-27 20:41:18 -07:00
|
|
|
|
2021-12-07 21:36:56 -08:00
|
|
|
function mapProcessor.processAttackWaves(universe)
|
|
|
|
processSpawnersBody(universe,
|
|
|
|
"processActiveSpawnerIterator",
|
|
|
|
universe.chunkToActiveNest)
|
|
|
|
processSpawnersBody(universe,
|
|
|
|
"processActiveRaidSpawnerIterator",
|
|
|
|
universe.chunkToActiveRaidNest)
|
|
|
|
processSpawnersBody(universe,
|
|
|
|
"processMigrationIterator",
|
|
|
|
universe.chunkToNests)
|
2020-05-19 19:37:16 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
mapProcessorG = mapProcessor
|
|
|
|
return mapProcessor
|