2022-01-15 00:08:58 +02:00
|
|
|
-- Copyright (C) 2022 veden
|
|
|
|
|
|
|
|
-- This program is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU General Public License as published by
|
|
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
|
|
|
-- (at your option) any later version.
|
|
|
|
|
|
|
|
-- This program is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU General Public License for more details.
|
|
|
|
|
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
|
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
if MapProcessorG then
|
|
|
|
return MapProcessorG
|
2019-02-16 06:17:30 +02:00
|
|
|
end
|
2023-03-11 22:53:06 +02:00
|
|
|
local MapProcessor = {}
|
2016-08-05 06:47:51 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
--
|
|
|
|
|
|
|
|
local Universe
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
-- imports
|
2017-06-16 03:30:26 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local QueryUtils = require("QueryUtils")
|
|
|
|
local PheromoneUtils = require("PheromoneUtils")
|
|
|
|
local AiAttackWave = require("AIAttackWave")
|
|
|
|
local AiPredicates = require("AIPredicates")
|
|
|
|
local Constants = require("Constants")
|
|
|
|
local MapUtils = require("MapUtils")
|
|
|
|
local PlayerUtils = require("PlayerUtils")
|
|
|
|
local ChunkUtils = require("ChunkUtils")
|
|
|
|
local ChunkPropertyUtils = require("ChunkPropertyUtils")
|
|
|
|
local BaseUtils = require("BaseUtils")
|
2016-09-14 13:16:33 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
-- Constants
|
2020-04-28 05:41:18 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local PLAYER_PHEROMONE_GENERATOR_AMOUNT = Constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT
|
|
|
|
local DURATION_ACTIVE_NEST = Constants.DURATION_ACTIVE_NEST
|
2016-11-04 09:26:19 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local PROCESS_QUEUE_SIZE = Constants.PROCESS_QUEUE_SIZE
|
|
|
|
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-09-14 13:16:33 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local CLEANUP_QUEUE_SIZE = Constants.CLEANUP_QUEUE_SIZE
|
2016-10-15 02:00:18 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local PROCESS_PLAYER_BOUND = Constants.PROCESS_PLAYER_BOUND
|
2020-05-22 20:45:05 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local AI_VENGENCE_SQUAD_COST = Constants.AI_VENGENCE_SQUAD_COST
|
2016-11-04 09:26:19 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local BASE_AI_STATE_AGGRESSIVE = Constants.BASE_AI_STATE_AGGRESSIVE
|
|
|
|
local BASE_AI_STATE_SIEGE = Constants.BASE_AI_STATE_SIEGE
|
|
|
|
local BASE_AI_STATE_PEACEFUL = Constants.BASE_AI_STATE_PEACEFUL
|
|
|
|
local BASE_AI_STATE_MIGRATING = Constants.BASE_AI_STATE_MIGRATING
|
2016-11-04 09:26:19 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local COOLDOWN_DRAIN = Constants.COOLDOWN_DRAIN
|
|
|
|
local COOLDOWN_RALLY = Constants.COOLDOWN_RALLY
|
|
|
|
local COOLDOWN_RETREAT = Constants.COOLDOWN_RETREAT
|
2018-02-12 05:21:28 +02:00
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- imported functions
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local setPositionInQuery = QueryUtils.setPositionInQuery
|
2023-01-08 08:53:47 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local addPlayerGenerator = ChunkPropertyUtils.addPlayerGenerator
|
|
|
|
local findNearbyBase = ChunkPropertyUtils.findNearbyBase
|
2022-02-28 04:45:42 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local removeChunkToNest = MapUtils.removeChunkToNest
|
2022-01-14 21:17:33 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local processPheromone = PheromoneUtils.processPheromone
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local getCombinedDeathGeneratorRating = ChunkPropertyUtils.getCombinedDeathGeneratorRating
|
|
|
|
local processBaseMutation = BaseUtils.processBaseMutation
|
2020-05-20 04:37:16 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local processNestActiveness = ChunkPropertyUtils.processNestActiveness
|
|
|
|
local getChunkBase = ChunkPropertyUtils.getChunkBase
|
2020-05-20 04:37:16 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local formSquads = AiAttackWave.formSquads
|
|
|
|
local formVengenceSquad = AiAttackWave.formVengenceSquad
|
|
|
|
local formVengenceSettler = AiAttackWave.formVengenceSettler
|
|
|
|
local formSettlers = AiAttackWave.formSettlers
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local getChunkByPosition = MapUtils.getChunkByPosition
|
|
|
|
local getChunkByXY = MapUtils.getChunkByXY
|
|
|
|
local getChunkById = MapUtils.getChunkById
|
2016-10-15 02:00:18 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local validPlayer = PlayerUtils.validPlayer
|
2017-11-21 09:27:03 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local mapScanEnemyChunk = ChunkUtils.mapScanEnemyChunk
|
|
|
|
local mapScanPlayerChunk = ChunkUtils.mapScanPlayerChunk
|
|
|
|
local mapScanResourceChunk = ChunkUtils.mapScanResourceChunk
|
2017-12-29 07:38:10 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local getNestCount = ChunkPropertyUtils.getNestCount
|
|
|
|
local getEnemyStructureCount = ChunkPropertyUtils.getEnemyStructureCount
|
|
|
|
local getNestActiveness = ChunkPropertyUtils.getNestActiveness
|
2020-04-28 05:41:18 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local getRaidNestActiveness = ChunkPropertyUtils.getRaidNestActiveness
|
2016-08-20 04:52:27 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local canAttack = AiPredicates.canAttack
|
|
|
|
local canMigrate = AiPredicates.canMigrate
|
2017-05-14 00:32:16 +02:00
|
|
|
|
2021-02-14 06:49:54 +02:00
|
|
|
local tableSize = table_size
|
2017-05-28 06:50:37 +02:00
|
|
|
|
2016-08-29 02:05:28 +02:00
|
|
|
local mMin = math.min
|
2020-05-22 08:57:03 +02:00
|
|
|
local mMax = math.max
|
2016-08-29 02:05:28 +02:00
|
|
|
|
2020-05-20 04:37:16 +02:00
|
|
|
local next = next
|
2017-07-01 06:36:23 +02:00
|
|
|
|
2016-08-20 04:52:27 +02:00
|
|
|
-- module code
|
|
|
|
|
2016-10-15 02:00:18 +02: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-03 08:01:28 +02:00
|
|
|
In theory, this might be fine as smaller bases have less surface to attack and need to have
|
2016-10-15 02:00:18 +02:00
|
|
|
pheromone dissipate at a faster rate.
|
|
|
|
--]]
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.processMap(map, tick)
|
2018-01-14 07:48:21 +02:00
|
|
|
local processQueue = map.processQueue
|
2020-05-22 08:57:03 +02:00
|
|
|
local processQueueLength = #processQueue
|
2018-10-20 07:17:37 +02:00
|
|
|
|
2020-12-05 06:49:51 +02:00
|
|
|
if (processQueueLength == 0) then
|
|
|
|
return
|
|
|
|
end
|
2021-02-14 06:49:54 +02:00
|
|
|
|
2023-03-11 21:10:15 +02:00
|
|
|
local startIndex = mMin(map.processIndex, processQueueLength)
|
2020-05-22 20:45:05 +02:00
|
|
|
local step
|
|
|
|
local endIndex
|
2023-03-11 21:10:15 +02:00
|
|
|
if map.outgoingScanWave then
|
2020-05-22 20:45:05 +02:00
|
|
|
step = 1
|
2023-03-11 21:10:15 +02:00
|
|
|
endIndex = mMin(startIndex + PROCESS_QUEUE_SIZE, processQueueLength)
|
|
|
|
if (endIndex == processQueueLength) then
|
|
|
|
map.outgoingScanWave = false
|
|
|
|
map.processIndex = processQueueLength
|
|
|
|
else
|
|
|
|
map.processIndex = endIndex + 1
|
|
|
|
end
|
2020-05-22 20:45:05 +02:00
|
|
|
else
|
|
|
|
step = -1
|
2023-03-11 21:10:15 +02:00
|
|
|
endIndex = mMax(startIndex - PROCESS_QUEUE_SIZE, 1)
|
|
|
|
if (endIndex == 1) then
|
|
|
|
map.outgoingScanWave = true
|
|
|
|
map.processIndex = 1
|
|
|
|
else
|
|
|
|
map.processIndex = endIndex - 1
|
|
|
|
end
|
2020-05-22 20:45:05 +02:00
|
|
|
end
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.processedChunks = Universe.processedChunks + ((startIndex - endIndex) * step)
|
2020-05-22 20:45:05 +02:00
|
|
|
|
2023-03-11 21:10:15 +02:00
|
|
|
for x=startIndex,endIndex,step do
|
|
|
|
processPheromone(map, processQueue[x], tick)
|
2020-05-22 20:45:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-28 05:41:18 +02:00
|
|
|
local function queueNestSpawners(map, chunk, tick)
|
2023-03-11 22:53:06 +02:00
|
|
|
local processActiveNest = Universe.processActiveNest
|
2020-05-20 04:37:16 +02:00
|
|
|
|
2021-12-06 07:44:19 +02:00
|
|
|
local chunkId = chunk.id
|
|
|
|
if not processActiveNest[chunkId] then
|
2023-03-11 22:53:06 +02:00
|
|
|
if (getNestActiveness(chunk) > 0) or (getRaidNestActiveness(chunk) > 0) then
|
2021-12-08 04:21:27 +02:00
|
|
|
processActiveNest[chunkId] = {
|
|
|
|
map = map,
|
|
|
|
chunk = chunk,
|
|
|
|
tick = tick + DURATION_ACTIVE_NEST
|
|
|
|
}
|
|
|
|
end
|
2020-04-28 05:41:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-15 02:00:18 +02:00
|
|
|
--[[
|
|
|
|
Localized player radius were processing takes place in realtime, doesn't store state
|
|
|
|
between calls.
|
2019-02-03 08:01:28 +02:00
|
|
|
vs
|
2016-10-15 02:00:18 +02:00
|
|
|
the slower passive version processing the entire map in multiple passes.
|
|
|
|
--]]
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.processPlayers(players, tick)
|
2016-10-15 02:00:18 +02:00
|
|
|
-- put down player pheromone for player hunters
|
|
|
|
-- randomize player order to ensure a single player isn't singled out
|
2018-05-26 00:23:22 +02:00
|
|
|
-- not looping everyone because the cost is high enough already in multiplayer
|
2023-01-19 07:49:15 +02:00
|
|
|
local playerCount = #players
|
|
|
|
local playerMaxGenerator = playerCount * PLAYER_PHEROMONE_GENERATOR_AMOUNT
|
|
|
|
for i=1,playerCount do
|
2023-01-08 03:59:21 +02:00
|
|
|
local player = players[i]
|
|
|
|
if validPlayer(player) then
|
|
|
|
local char = player.character
|
2023-03-11 22:53:06 +02:00
|
|
|
local map = Universe.maps[char.surface.index]
|
2023-01-08 03:59:21 +02:00
|
|
|
if map then
|
|
|
|
local playerChunk = getChunkByPosition(map, char.position)
|
|
|
|
|
|
|
|
if (playerChunk ~= -1) then
|
2023-01-19 07:49:15 +02:00
|
|
|
addPlayerGenerator(map, playerChunk, playerMaxGenerator)
|
2023-01-08 03:59:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-07 07:57:20 +02:00
|
|
|
if (#players > 0) then
|
2023-03-11 22:53:06 +02:00
|
|
|
local player = players[Universe.random(#players)]
|
2021-02-20 09:31:36 +02:00
|
|
|
if validPlayer(player) then
|
2021-12-06 03:16:14 +02:00
|
|
|
local char = player.character
|
2023-03-11 22:53:06 +02:00
|
|
|
local map = Universe.maps[char.surface.index]
|
2021-12-06 03:16:14 +02:00
|
|
|
if map then
|
|
|
|
local playerChunk = getChunkByPosition(map, char.position)
|
|
|
|
|
|
|
|
if (playerChunk ~= -1) then
|
2022-02-24 07:04:34 +02:00
|
|
|
local base = findNearbyBase(map, playerChunk)
|
2022-03-20 01:29:12 +02:00
|
|
|
if not base then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local allowingAttacks = canAttack(map, base)
|
2021-12-06 03:16:14 +02:00
|
|
|
local vengence = allowingAttacks and
|
2022-03-20 01:29:12 +02:00
|
|
|
(base.unitPoints >= AI_VENGENCE_SQUAD_COST) and
|
2021-12-06 03:16:14 +02:00
|
|
|
((getEnemyStructureCount(map, playerChunk) > 0) or
|
2023-03-11 22:53:06 +02:00
|
|
|
(getCombinedDeathGeneratorRating(map, playerChunk) < Universe.retreatThreshold))
|
2021-12-06 03:16:14 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2023-03-11 21:10:15 +02:00
|
|
|
if (chunk ~= -1) then
|
|
|
|
processPheromone(map, chunk, tick, true)
|
2021-12-06 03:16:14 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
if (getNestCount(chunk) > 0) then
|
2021-12-06 03:16:14 +02:00
|
|
|
processNestActiveness(map, chunk)
|
|
|
|
queueNestSpawners(map, chunk, tick)
|
|
|
|
|
|
|
|
if vengence then
|
2023-03-11 22:53:06 +02:00
|
|
|
local pack = Universe.vengenceQueue[chunk.id]
|
2021-12-06 05:40:39 +02:00
|
|
|
if not pack then
|
|
|
|
pack = {
|
|
|
|
v = 0,
|
2022-02-24 07:04:34 +02:00
|
|
|
map = map,
|
|
|
|
base = base
|
2021-12-06 05:40:39 +02:00
|
|
|
}
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.vengenceQueue[chunk.id] = pack
|
2021-12-06 05:40:39 +02:00
|
|
|
end
|
|
|
|
pack.v = pack.v + 1
|
2021-12-06 03:16:14 +02:00
|
|
|
end
|
2020-05-20 04:37:16 +02:00
|
|
|
end
|
2019-02-20 08:16:43 +02:00
|
|
|
end
|
2019-10-19 21:13:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-10-15 02:00:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local function processCleanUp(chunks, iterator, tick, duration)
|
|
|
|
local chunkId = Universe[iterator]
|
2021-12-09 08:01:54 +02:00
|
|
|
local chunkPack
|
|
|
|
if not chunkId then
|
|
|
|
chunkId, chunkPack = next(chunks, nil)
|
|
|
|
else
|
|
|
|
chunkPack = chunks[chunkId]
|
|
|
|
end
|
|
|
|
if not chunkId then
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe[iterator] = nil
|
2021-12-09 08:01:54 +02:00
|
|
|
else
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe[iterator] = next(chunks, chunkId)
|
2021-12-09 08:01:54 +02:00
|
|
|
if (tick - chunkPack.tick) > duration then
|
|
|
|
chunks[chunkId] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.cleanUpMapTables(tick)
|
|
|
|
local retreats = Universe.chunkToRetreats
|
|
|
|
local rallys = Universe.chunkToRallys
|
|
|
|
local drained = Universe.chunkToDrained
|
2017-05-24 08:46:23 +02:00
|
|
|
|
2021-12-09 08:13:38 +02:00
|
|
|
for _=1,CLEANUP_QUEUE_SIZE do
|
2023-03-11 22:53:06 +02:00
|
|
|
processCleanUp(retreats, "chunkToRetreatIterator", tick, COOLDOWN_RETREAT)
|
2018-02-12 05:21:28 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
processCleanUp(rallys, "chunkToRallyIterator", tick, COOLDOWN_RALLY)
|
2018-02-12 05:21:28 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
processCleanUp(drained, "chunkToDrainedIterator", tick, COOLDOWN_DRAIN)
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[
|
|
|
|
Passive scan to find entities that have been generated outside the factorio event system
|
|
|
|
--]]
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.scanPlayerMap(map, tick)
|
2021-02-14 06:49:54 +02:00
|
|
|
if (map.nextProcessMap == tick) or (map.nextPlayerScan == tick) or
|
|
|
|
(map.nextEnemyScan == tick) or (map.nextChunkProcess == tick)
|
|
|
|
then
|
2020-05-22 08:57:03 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local index = map.scanPlayerIndex
|
|
|
|
|
|
|
|
local processQueue = map.processQueue
|
2020-12-05 06:49:51 +02:00
|
|
|
local processQueueLength = #processQueue
|
2021-02-14 06:49:54 +02:00
|
|
|
|
2020-12-05 06:49:51 +02:00
|
|
|
local endIndex = mMin(index + PLAYER_QUEUE_SIZE, processQueueLength)
|
|
|
|
|
|
|
|
if (processQueueLength == 0) then
|
|
|
|
return
|
|
|
|
end
|
2020-05-22 08:57:03 +02:00
|
|
|
|
|
|
|
for x=index,endIndex do
|
2021-12-11 20:42:49 +02:00
|
|
|
mapScanPlayerChunk(processQueue[x], map)
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
|
|
|
|
2020-12-05 06:49:51 +02:00
|
|
|
if (endIndex == processQueueLength) then
|
2020-05-22 08:57:03 +02:00
|
|
|
map.scanPlayerIndex = 1
|
|
|
|
else
|
|
|
|
map.scanPlayerIndex = endIndex + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.scanEnemyMap(map, tick)
|
2020-05-22 08:57:03 +02: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-05 06:49:51 +02:00
|
|
|
local processQueueLength = #processQueue
|
2021-02-14 06:49:54 +02:00
|
|
|
|
2020-05-22 08:57:03 +02:00
|
|
|
local endIndex = mMin(index + ENEMY_QUEUE_SIZE, #processQueue)
|
2019-02-19 02:43:01 +02:00
|
|
|
|
2020-12-05 06:49:51 +02:00
|
|
|
if (processQueueLength == 0) then
|
|
|
|
return
|
|
|
|
end
|
2021-02-14 06:49:54 +02:00
|
|
|
|
2020-05-22 08:57:03 +02:00
|
|
|
for x=index,endIndex do
|
2021-12-05 02:46:29 +02:00
|
|
|
mapScanEnemyChunk(processQueue[x], map, tick)
|
2016-08-05 06:47:51 +02:00
|
|
|
end
|
2017-04-22 01:14:04 +02:00
|
|
|
|
2020-12-05 06:49:51 +02:00
|
|
|
if (endIndex == processQueueLength) then
|
2020-05-22 08:57:03 +02:00
|
|
|
map.scanEnemyIndex = 1
|
2016-08-29 02:05:28 +02:00
|
|
|
else
|
2020-05-22 08:57:03 +02:00
|
|
|
map.scanEnemyIndex = endIndex + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.scanResourceMap(map, tick)
|
2021-02-14 06:49:54 +02:00
|
|
|
if (map.nextProcessMap == tick) or (map.nextPlayerScan == tick) or
|
|
|
|
(map.nextEnemyScan == tick) or (map.nextChunkProcess == tick)
|
|
|
|
then
|
2020-05-22 08:57:03 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local index = map.scanResourceIndex
|
|
|
|
|
2021-02-14 06:49:54 +02:00
|
|
|
local processQueue = map.processQueue
|
2020-12-05 06:49:51 +02:00
|
|
|
local processQueueLength = #processQueue
|
2021-02-14 06:49:54 +02:00
|
|
|
|
2020-12-05 06:49:51 +02:00
|
|
|
local endIndex = mMin(index + RESOURCE_QUEUE_SIZE, processQueueLength)
|
2020-05-22 08:57:03 +02:00
|
|
|
|
2020-12-05 06:49:51 +02:00
|
|
|
if (processQueueLength == 0) then
|
|
|
|
return
|
|
|
|
end
|
2021-02-14 06:49:54 +02:00
|
|
|
|
2020-05-22 08:57:03 +02:00
|
|
|
for x=index,endIndex do
|
2021-12-11 20:42:49 +02:00
|
|
|
mapScanResourceChunk(processQueue[x], map)
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
|
|
|
|
2020-12-05 06:49:51 +02:00
|
|
|
if (endIndex == processQueueLength) then
|
2020-05-22 08:57:03 +02:00
|
|
|
map.scanResourceIndex = 1
|
|
|
|
else
|
|
|
|
map.scanResourceIndex = endIndex + 1
|
2016-08-20 04:52:27 +02:00
|
|
|
end
|
2016-08-05 06:47:51 +02:00
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.processActiveNests(tick)
|
|
|
|
local processActiveNest = Universe.processActiveNest
|
|
|
|
local chunkId = Universe.processActiveNestIterator
|
2021-12-06 07:44:19 +02:00
|
|
|
local chunkPack
|
|
|
|
if not chunkId then
|
|
|
|
chunkId, chunkPack = next(processActiveNest, nil)
|
|
|
|
else
|
|
|
|
chunkPack = processActiveNest[chunkId]
|
|
|
|
end
|
|
|
|
if not chunkId then
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.processActiveNestIterator = nil
|
2021-12-06 07:44:19 +02:00
|
|
|
else
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.processActiveNestIterator = next(processActiveNest, chunkId)
|
2021-12-06 07:44:19 +02:00
|
|
|
if chunkPack.tick < tick then
|
2021-12-06 06:56:08 +02:00
|
|
|
local map = chunkPack.map
|
2021-12-08 08:13:32 +02:00
|
|
|
if not map.surface.valid then
|
|
|
|
processActiveNest[chunkId] = nil
|
|
|
|
return
|
|
|
|
end
|
2021-12-06 07:44:19 +02:00
|
|
|
local chunk = chunkPack.chunk
|
|
|
|
processNestActiveness(map, chunk)
|
2023-03-11 22:53:06 +02:00
|
|
|
if (getNestActiveness(chunk) == 0) and (getRaidNestActiveness(chunk) == 0) then
|
2021-12-06 07:44:19 +02:00
|
|
|
processActiveNest[chunkId] = nil
|
2021-12-08 04:21:27 +02:00
|
|
|
else
|
|
|
|
chunkPack.tick = tick + DURATION_ACTIVE_NEST
|
2020-04-28 05:41:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.processVengence()
|
|
|
|
local vengenceQueue = Universe.vengenceQueue
|
|
|
|
local chunkId = Universe.deployVengenceIterator
|
2021-12-06 05:40:39 +02:00
|
|
|
local vengencePack
|
2021-12-05 20:19:04 +02:00
|
|
|
if not chunkId then
|
2021-12-06 05:40:39 +02:00
|
|
|
chunkId, vengencePack = next(vengenceQueue, nil)
|
|
|
|
else
|
|
|
|
vengencePack = vengenceQueue[chunkId]
|
2021-11-25 04:31:28 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
if not chunkId then
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.deployVengenceIterator = nil
|
2021-12-06 05:40:39 +02:00
|
|
|
if (tableSize(vengenceQueue) == 0) then
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.vengenceQueue = {}
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
2020-05-20 04:37:16 +02:00
|
|
|
else
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.deployVengenceIterator = next(vengenceQueue, chunkId)
|
2021-12-15 08:03:29 +02:00
|
|
|
vengenceQueue[chunkId] = nil
|
2021-12-08 08:13:32 +02:00
|
|
|
local map = vengencePack.map
|
|
|
|
if not map.surface.valid then
|
|
|
|
return
|
|
|
|
end
|
2023-03-11 22:53:06 +02:00
|
|
|
local chunk = getChunkById(chunkId)
|
2022-10-26 19:55:00 +02:00
|
|
|
local base = vengencePack.base
|
2023-03-11 22:53:06 +02:00
|
|
|
if canMigrate(map, base) and (Universe.random() < 0.075) then
|
2022-10-26 19:55:00 +02:00
|
|
|
formVengenceSettler(map, chunk, base)
|
2021-12-12 20:19:59 +02:00
|
|
|
else
|
2022-10-26 19:55:00 +02:00
|
|
|
formVengenceSquad(map, chunk, base)
|
2021-12-12 20:19:59 +02:00
|
|
|
end
|
2020-05-20 04:37:16 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.processNests(tick)
|
|
|
|
local chunkId = Universe.processNestIterator
|
2021-12-08 08:13:32 +02:00
|
|
|
local chunkPack
|
|
|
|
if not chunkId then
|
2023-03-11 22:53:06 +02:00
|
|
|
chunkId,chunkPack = next(Universe.chunkToNests, nil)
|
2021-12-08 08:13:32 +02:00
|
|
|
else
|
2023-03-11 22:53:06 +02:00
|
|
|
chunkPack = Universe.chunkToNests[chunkId]
|
2021-12-08 08:13:32 +02:00
|
|
|
end
|
|
|
|
if not chunkId then
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.processNestIterator = nil
|
2021-12-08 08:13:32 +02:00
|
|
|
else
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.processNestIterator = next(Universe.chunkToNests, chunkId)
|
2021-12-08 04:38:02 +02:00
|
|
|
local map = chunkPack.map
|
2021-12-08 08:13:32 +02:00
|
|
|
if not map.surface.valid then
|
2023-03-11 22:53:06 +02:00
|
|
|
removeChunkToNest(chunkId)
|
2021-12-08 08:13:32 +02:00
|
|
|
return
|
|
|
|
end
|
2023-03-11 22:53:06 +02:00
|
|
|
local chunk = getChunkById(chunkId)
|
2021-02-20 07:41:30 +02:00
|
|
|
processNestActiveness(map, chunk)
|
|
|
|
queueNestSpawners(map, chunk, tick)
|
2020-05-20 04:37:16 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
if Universe.NEW_ENEMIES then
|
2022-03-20 01:29:12 +02:00
|
|
|
processBaseMutation(chunk,
|
|
|
|
map,
|
|
|
|
getChunkBase(map, chunk))
|
|
|
|
end
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
local function processSpawnersBody(iterator, chunks)
|
|
|
|
local chunkId = Universe[iterator]
|
2021-12-08 08:13:32 +02:00
|
|
|
local chunkPack
|
|
|
|
if not chunkId then
|
|
|
|
chunkId,chunkPack = next(chunks, nil)
|
|
|
|
else
|
|
|
|
chunkPack = chunks[chunkId]
|
|
|
|
end
|
|
|
|
if not chunkId then
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe[iterator] = nil
|
2021-12-08 08:13:32 +02:00
|
|
|
else
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe[iterator] = next(chunks, chunkId)
|
2021-12-08 07:36:56 +02:00
|
|
|
local map = chunkPack.map
|
2021-12-08 08:13:32 +02:00
|
|
|
if not map.surface.valid then
|
2022-01-14 21:17:33 +02:00
|
|
|
if (iterator == "processMigrationIterator") then
|
2023-03-11 22:53:06 +02:00
|
|
|
removeChunkToNest(chunkId)
|
2022-01-14 21:17:33 +02:00
|
|
|
else
|
|
|
|
chunks[chunkId] = nil
|
|
|
|
end
|
2021-12-08 08:13:32 +02:00
|
|
|
return
|
|
|
|
end
|
2023-03-11 22:53:06 +02:00
|
|
|
local chunk = getChunkById(chunkId)
|
2022-03-20 01:29:12 +02:00
|
|
|
local base = findNearbyBase(map, chunk)
|
|
|
|
if base.stateAI == BASE_AI_STATE_PEACEFUL then
|
2021-12-08 07:36:56 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if iterator == "processMigrationIterator" then
|
2022-03-20 01:29:12 +02:00
|
|
|
if (base.stateAI ~= BASE_AI_STATE_MIGRATING) and (base.stateAI ~= BASE_AI_STATE_SIEGE) then
|
2021-12-08 07:36:56 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
elseif iterator == "processActiveRaidSpawnerIterator" then
|
2022-03-20 01:29:12 +02:00
|
|
|
if (base.stateAI == BASE_AI_STATE_AGGRESSIVE) or (base.stateAI == BASE_AI_STATE_MIGRATING) then
|
2021-12-08 07:36:56 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
elseif iterator == "processActiveSpawnerIterator" then
|
2022-03-20 01:29:12 +02:00
|
|
|
if (base.stateAI == BASE_AI_STATE_MIGRATING) then
|
2021-12-08 07:36:56 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-24 07:04:34 +02:00
|
|
|
local migrate = canMigrate(map, base)
|
|
|
|
local attack = canAttack(map, base)
|
2021-02-20 07:41:30 +02:00
|
|
|
if migrate then
|
2022-02-24 07:04:34 +02:00
|
|
|
formSettlers(map, chunk, base)
|
2021-12-10 21:12:54 +02:00
|
|
|
end
|
|
|
|
if attack then
|
2022-02-24 07:04:34 +02:00
|
|
|
formSquads(map, chunk, base)
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
2020-05-20 04:37:16 +02:00
|
|
|
end
|
|
|
|
end
|
2020-04-28 05:41:18 +02:00
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.processAttackWaves()
|
|
|
|
processSpawnersBody("processActiveSpawnerIterator",
|
|
|
|
Universe.chunkToActiveNest)
|
|
|
|
processSpawnersBody("processActiveRaidSpawnerIterator",
|
|
|
|
Universe.chunkToActiveRaidNest)
|
|
|
|
processSpawnersBody("processMigrationIterator",
|
|
|
|
Universe.chunkToNests)
|
2020-05-20 04:37:16 +02:00
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.processClouds(tick)
|
|
|
|
local len = Universe.settlePurpleCloud.len
|
|
|
|
local builderPack = Universe.settlePurpleCloud[len]
|
2023-01-08 08:53:47 +02:00
|
|
|
if builderPack and (builderPack.tick <= tick) then
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.settlePurpleCloud[len] = nil
|
|
|
|
Universe.settlePurpleCloud.len = len - 1
|
2023-01-08 08:53:47 +02:00
|
|
|
local map = builderPack.map
|
2023-01-08 09:36:04 +02:00
|
|
|
if builderPack.group.valid and map.surface.valid then
|
|
|
|
setPositionInQuery(
|
2023-03-11 22:53:06 +02:00
|
|
|
Universe.obaCreateBuildCloudQuery,
|
2023-01-08 09:36:04 +02:00
|
|
|
builderPack.position
|
|
|
|
)
|
2023-03-11 22:53:06 +02:00
|
|
|
map.surface.create_entity(Universe.obaCreateBuildCloudQuery)
|
2023-01-08 08:53:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-11 22:53:06 +02:00
|
|
|
function MapProcessor.init(universe)
|
|
|
|
Universe = universe
|
|
|
|
end
|
|
|
|
|
|
|
|
MapProcessorG = MapProcessor
|
|
|
|
return MapProcessor
|