1
0
mirror of https://github.com/veden/Rampant.git synced 2025-02-05 13:14:51 +02:00

FACTO-256: Code cleanup and minor optimizations

This commit is contained in:
Aaron Veden 2023-03-12 13:02:31 -07:00
parent e143f4bbbe
commit fd383b9dc7
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
7 changed files with 185 additions and 266 deletions

View File

@ -327,15 +327,11 @@ local function onConfigChanged()
Upgrade.setCommandForces(npcForces, enemyForces)
if not Universe.maps then
Universe.maps = {}
end
for _,surface in pairs(game.surfaces) do
if not Universe.maps[surface.index] then
prepMap(surface)
end
end
-- addBasesToAllEnemyStructures(game.tick)
if not Universe.ranIncompatibleMessage and Universe.newEnemies and
(game.active_mods["bobenemies"] or game.active_mods["Natural_Evolution_Enemies"]) then
@ -361,7 +357,7 @@ local function onEnemyBaseBuild(event)
event.tick)
end
registerEnemyBaseStructure(map, entity, base, event.tick)
registerEnemyBaseStructure(entity, base, event.tick)
if Universe.NEW_ENEMIES then
queueUpgrade(entity,
@ -1210,7 +1206,7 @@ local function removeNewEnemies()
chunk,
tick)
end
registerEnemyBaseStructure(map, newEntity, base, tick)
registerEnemyBaseStructure(newEntity, base, tick)
end
end
end
@ -1306,7 +1302,7 @@ local function removeFaction(cmd)
chunk,
tick)
end
registerEnemyBaseStructure(map, newEntity, base, tick)
registerEnemyBaseStructure(newEntity, base, tick)
end
end
end

View File

@ -62,7 +62,8 @@ local function getActiveTick(chunk)
end
local function registerActiveSpawner(chunk, register, activeType, tick)
if Universe[register][chunk.id] then
local chunkId = chunk.id
if Universe[register][chunkId] then
return
end
@ -70,11 +71,12 @@ local function registerActiveSpawner(chunk, register, activeType, tick)
local base = chunk.base
base[activeType] = base[activeType] + 1
Universe[register][chunk.id] = chunk
Universe[register][chunkId] = chunk
end
local function unregisterActiveSpawner(chunk, register, activeType)
if not Universe[register][chunk.id] then
local function unregisterActiveSpawner(chunk, register, iterator, activeType)
local chunkId = chunk.id
if not Universe[register][chunkId] then
return
end
@ -82,10 +84,10 @@ local function unregisterActiveSpawner(chunk, register, activeType)
local base = chunk.base
base[activeType] = base[activeType] - 1
if (Universe.processActiveSpawnerIterator == chunk.id) then
Universe.processActiveSpawnerIterator = nil
Universe[register][chunkId] = nil
if (Universe[iterator] == chunkId) then
Universe[iterator] = nil
end
Universe[register][chunk.id] = nil
end
local function registerActiveNest(chunk, tick)
@ -97,11 +99,21 @@ local function registerActiveRaidNest(chunk, tick)
end
local function unregisterActiveNest(chunk)
unregisterActiveSpawner(chunk, "chunkToActiveNest", "activeNests")
unregisterActiveSpawner(
chunk,
"chunkToActiveNest",
"processActiveSpawnerIterator",
"activeNests"
)
end
local function unregisterActiveRaidNest(chunk)
unregisterActiveSpawner(chunk, "chunkToActiveRaidNest", "activeRaidNests")
unregisterActiveSpawner(
chunk,
"chunkToActiveRaidNest",
"processActiveRaidSpawnerIterator",
"activeRaidNests"
)
end
local function addEnemyStructure(chunk, unitNumber, ids, counts, register)
@ -112,41 +124,48 @@ local function addEnemyStructure(chunk, unitNumber, ids, counts, register)
entityIds = {}
chunk[ids] = entityIds
end
if not entityIds[unitNumber] then
entityIds[unitNumber] = true
chunk[counts] = (chunk[counts] or 0) + 1
if register then
Universe[register][chunkId] = chunk
end
return true
if entityIds[unitNumber] then
return false
end
return false
entityIds[unitNumber] = true
chunk[counts] = (chunk[counts] or 0) + 1
if register then
Universe[register][chunkId] = chunk
end
return true
end
local function removeEnemyStructure(chunk, unitNumber, ids, counts, register)
local chunkId = chunk.id
local entityIds = chunk[ids]
if entityIds and entityIds[unitNumber] then
entityIds[unitNumber] = nil
chunk[counts] = chunk[counts] - 1
if chunk[counts] > 0 then
return true
end
if not (entityIds and entityIds[unitNumber]) then
return false
end
chunk[ids] = nil
chunk[counts] = nil
if register then
Universe[register][chunkId] = nil
end
entityIds[unitNumber] = nil
chunk[counts] = chunk[counts] - 1
if chunk[counts] > 0 then
return true
end
chunk[ids] = nil
chunk[counts] = nil
if register then
Universe[register][chunkId] = nil
end
if (ids == "nestIds") then
unregisterActiveNest(chunk)
unregisterActiveRaidNest(chunk)
if (Universe.processMigrationIterator == chunkId) then
Universe.processMigrationIterator = nil
end
if (Universe.processNestIterator == chunkId) then
Universe.processNestIterator = nil
end
return true
end
return false
return true
end
function ChunkPropertyUtils.addTurretCount(chunk, unitNumber)

View File

@ -37,7 +37,6 @@ local Utils = require("Utils")
local VANILLA_ENTITY_TYPE_LOOKUP = Constants.VANILLA_ENTITY_TYPE_LOOKUP
local BUILDING_HIVE_TYPE_LOOKUP = Constants.BUILDING_HIVE_TYPE_LOOKUP
local HIVE_BUILDINGS_TYPES = Constants.HIVE_BUILDINGS_TYPES
local DEFINES_WIRE_TYPE_RED = defines.wire_type.red
local DEFINES_WIRE_TYPE_GREEN = defines.wire_type.green
@ -217,6 +216,24 @@ local function scorePlayerBuildings(map, chunk)
return 0
end
local registerTypeToAddFn = {
["spitter-spawner"] = addNestCount,
["biter-spawner"] = addNestCount,
["turret"] = addTurretCount,
["utility"] = addUtilityCount,
["hive"] = addHiveCount,
["unit-spawner"] = addNestCount
}
local unregisterTypeToRemoveFn = {
["spitter-spawner"] = removeNestCount,
["biter-spawner"] = removeNestCount,
["turret"] = removeTurretCount,
["utility"] = removeUtilityCount,
["hive"] = removeHiveCount,
["unit-spawner"] = removeNestCount
}
function ChunkUtils.initialScan(chunk, map, tick)
local surface = map.surface
setAreaInQueryChunkSize(Universe.isFilteredTilesQuery, chunk)
@ -243,11 +260,6 @@ function ChunkUtils.initialScan(chunk, map, tick)
local resources = surface.count_entities_filtered(Universe.isCountResourcesQuery) * RESOURCE_NORMALIZER
setResourceGenerator(chunk, resources)
local counts = map.chunkScanCounts
for i=1,#HIVE_BUILDINGS_TYPES do
counts[HIVE_BUILDINGS_TYPES[i]] = 0
end
if (#enemyBuildings > 0) then
local base = findNearbyBase(chunk)
if not base then
@ -265,7 +277,7 @@ function ChunkUtils.initialScan(chunk, map, tick)
for i = 1, #enemyBuildings do
local enemyBuilding = enemyBuildings[i]
ChunkUtils.registerEnemyBaseStructure(map, enemyBuilding, base, tick)
ChunkUtils.registerEnemyBaseStructure(enemyBuilding, base, tick)
local entityName = enemyBuilding.name
local isVanilla = VANILLA_ENTITY_TYPE_LOOKUP[entityName]
if isVanilla or (not isVanilla and not BUILDING_HIVE_TYPE_LOOKUP[entityName]) then
@ -279,7 +291,7 @@ function ChunkUtils.initialScan(chunk, map, tick)
else
for i=1,#enemyBuildings do
local building = enemyBuildings[i]
ChunkUtils.registerEnemyBaseStructure(map, building, base, tick)
ChunkUtils.registerEnemyBaseStructure(building, base, tick)
end
end
end
@ -337,10 +349,6 @@ end
function ChunkUtils.mapScanEnemyChunk(chunk, map, tick)
setAreaInQueryChunkSize(Universe.msecFilteredEntitiesEnemyStructureQuery, chunk)
local buildings = map.surface.find_entities_filtered(Universe.msecFilteredEntitiesEnemyStructureQuery)
local counts = map.chunkScanCounts
for i=1,#HIVE_BUILDINGS_TYPES do
counts[HIVE_BUILDINGS_TYPES[i]] = 0
end
if (#buildings > 0) then
local base = findNearbyBase(chunk)
if not base then
@ -349,61 +357,11 @@ function ChunkUtils.mapScanEnemyChunk(chunk, map, tick)
for i=1,#buildings do
local building = buildings[i]
ChunkUtils.registerEnemyBaseStructure(map, building, base, tick)
ChunkUtils.registerEnemyBaseStructure(building, base, tick)
end
end
end
-- function ChunkUtils.addBasesToAllEnemyStructures(tick)
-- for chunkId, chunkPack in pairs(Universe.chunkToNests) do
-- local map = chunkPack.map
-- if map.surface.valid then
-- local chunk = getChunkById(chunkId)
-- local base = findNearbyBase(chunk)
-- if not base then
-- base = createBase(map, chunk, tick)
-- end
-- setChunkBase(chunk, base)
-- end
-- end
-- for _, map in pairs(Universe.maps) do
-- if map.surface.valid then
-- for chunkId in pairs(map.chunkToTurrets) do
-- local chunk = getChunkById(chunkId)
-- local base = findNearbyBase(chunk)
-- if not base then
-- base = createBase(map, chunk, tick)
-- end
-- setChunkBase(chunk, base)
-- end
-- for chunkId in pairs(map.chunkToHives) do
-- local chunk = getChunkById(chunkId)
-- local base = findNearbyBase(chunk)
-- if not base then
-- base = createBase(map, chunk, tick)
-- end
-- setChunkBase(chunk, base)
-- end
-- for chunkId in pairs(map.chunkToUtilities) do
-- local chunk = getChunkById(chunkId)
-- local base = findNearbyBase(chunk)
-- if not base then
-- base = createBase(map, chunk, tick)
-- end
-- setChunkBase(chunk, base)
-- end
-- for chunkId in pairs(map.chunkToTraps) do
-- local chunk = getChunkById(chunkId)
-- local base = findNearbyBase(chunk)
-- if not base then
-- base = createBase(map, chunk, tick)
-- end
-- setChunkBase(chunk, base)
-- end
-- end
-- end
-- end
function ChunkUtils.entityForPassScan(map, entity)
local overlapArray = getEntityOverlapChunks(map, entity)
@ -472,32 +430,17 @@ function ChunkUtils.colorXY(x, y, surface, color)
})
end
function ChunkUtils.registerEnemyBaseStructure(map, entity, base, tick, skipCount)
local entityType = entity.type
local addFunc
function ChunkUtils.registerEnemyBaseStructure(entity, base, tick, skipCount)
local hiveType = BUILDING_HIVE_TYPE_LOOKUP[entity.name]
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
addFunc = addNestCount
elseif (hiveType == "turret") then
addFunc = addTurretCount
elseif (hiveType == "trap") then
addFunc = addTrapCount
elseif (hiveType == "utility") then
addFunc = addUtilityCount
elseif (hiveType == "hive") then
addFunc = addHiveCount
else
if (entityType == "turret") then
addFunc = addTurretCount
else
addFunc = addNestCount
end
end
local addFunc =
registerTypeToAddFn[hiveType]
or registerTypeToAddFn[entity.type]
or addNestCount
local added = false
local entityUnitNumber = entity.unit_number
local chunks = getEntityOverlapChunks(map, entity)
local chunks = getEntityOverlapChunks(base.map, entity)
for i=1,#chunks do
local chunk = chunks[i]
if (chunk ~= -1) then
@ -505,9 +448,9 @@ function ChunkUtils.registerEnemyBaseStructure(map, entity, base, tick, skipCoun
added = true
setChunkBase(chunk, base)
addBaseResourceChunk(base, chunk)
end
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
processNestActiveness(chunk, tick)
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
processNestActiveness(chunk, tick)
end
end
end
end
@ -517,28 +460,12 @@ function ChunkUtils.registerEnemyBaseStructure(map, entity, base, tick, skipCoun
end
function ChunkUtils.unregisterEnemyBaseStructure(map, entity, damageTypeName, skipCount)
local entityType = entity.type
local removeFunc
local hiveType = BUILDING_HIVE_TYPE_LOOKUP[entity.name]
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
removeFunc = removeNestCount
elseif (hiveType == "turret") then
removeFunc = removeTurretCount
elseif (hiveType == "trap") then
removeFunc = removeTrapCount
elseif (hiveType == "utility") then
removeFunc = removeUtilityCount
elseif (hiveType == "hive") then
removeFunc = removeHiveCount
else
if (entityType == "turret") then
removeFunc = removeTurretCount
else
hiveType = "biter-spawner"
removeFunc = removeNestCount
end
end
local removeFunc =
unregisterTypeToRemoveFn[hiveType]
or unregisterTypeToRemoveFn[entity.type]
or removeNestCount
local entityUnitNumber = entity.unit_number
local usedBases = {}
@ -548,13 +475,14 @@ function ChunkUtils.unregisterEnemyBaseStructure(map, entity, damageTypeName, sk
if (chunk ~= -1) then
if removeFunc(chunk, entityUnitNumber) then
local base = chunk.base
if not usedBases[base.id] then
usedBases[base.id] = true
local baseId = base.id
if not usedBases[baseId] then
usedBases[baseId] = true
if damageTypeName then
base.damagedBy[damageTypeName] = (base.damagedBy[damageTypeName] or 0) + 3
base.deathEvents = base.deathEvents + 3
end
if (not skipCount) and (hiveType ~= "trap") then
if (not skipCount) then
base.lostEnemyBuilding = base.lostEnemyBuilding + 1
end
end

View File

@ -94,10 +94,6 @@ function MapUtils.getChunkByPosition(map, position)
return -1
end
function MapUtils.getChunkById(chunkId)
return Universe.chunkIdToChunk[chunkId] or -1
end
function MapUtils.positionToChunkXY(position)
local chunkX = mFloor(position.x * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE
local chunkY = mFloor(position.y * CHUNK_SIZE_DIVIDER) * CHUNK_SIZE
@ -170,12 +166,17 @@ function MapUtils.removeProcessQueueChunk(processQueue, chunk)
end
function MapUtils.removeChunkFromMap(map, chunk)
local chunkId = chunk.id
local x = chunk.x
local y = chunk.y
MapUtils.removeProcessQueueChunk(map.processQueue, chunk)
if not map[x][y] then
return
end
map[x][y] = nil
Universe.chunkIdToChunk[chunkId] = nil
local chunkId = chunk.id
MapUtils.removeProcessQueueChunk(map.processQueue, chunk)
Universe.chunkToActiveNest[chunkId] = nil
Universe.chunkToActiveRaidNest[chunkId] = nil
Universe.chunkToDrained[chunkId] = nil
@ -187,17 +188,13 @@ function MapUtils.removeChunkFromMap(map, chunk)
Universe.chunkToUtilities[chunkId] = nil
Universe.chunkToHives[chunkId] = nil
Universe.vengenceQueue[chunkId] = nil
Universe.processActiveNest[chunkId] = nil
Universe.chunkToVictory[chunkId] = nil
local base = map.chunkToBase[chunkId]
local base = chunk.base
if base then
base.chunkCount = base.chunkCount - 1
map.chunkToBase[chunkId] = nil
end
if Universe.processActiveNestIterator == chunkId then
Universe.processActiveNestIterator = nil
end
if Universe.processNestIterator == chunkId then
Universe.processNestIterator = nil
end

View File

@ -49,11 +49,6 @@ local PROCESS_PLAYER_BOUND = Constants.PROCESS_PLAYER_BOUND
local AI_VENGENCE_SQUAD_COST = Constants.AI_VENGENCE_SQUAD_COST
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
local COOLDOWN_DRAIN = Constants.COOLDOWN_DRAIN
local COOLDOWN_RALLY = Constants.COOLDOWN_RALLY
local COOLDOWN_RETREAT = Constants.COOLDOWN_RETREAT
@ -97,7 +92,6 @@ local formSettlers = Squad.formSettlers
local getChunkByPosition = MapUtils.getChunkByPosition
local getChunkByXY = MapUtils.getChunkByXY
local getChunkById = MapUtils.getChunkById
local validPlayer = Utils.validPlayer
@ -204,7 +198,7 @@ function Processor.processPlayers(players, tick)
if not base then
return
end
local allowingAttacks = canAttack(map, base)
local allowingAttacks = canAttack(base)
local vengence = allowingAttacks and
(base.unitPoints >= AI_VENGENCE_SQUAD_COST) and
((getEnemyStructureCount(playerChunk) > 0) or
@ -261,11 +255,6 @@ end
Passive scan to find entities that have been generated outside the factorio event system
--]]
function Processor.scanPlayerMap(map, tick)
if (map.nextProcessMap == tick) or (map.nextPlayerScan == tick) or
(map.nextEnemyScan == tick) or (map.nextChunkProcess == tick)
then
return
end
local index = map.scanPlayerIndex
local processQueue = map.processQueue
@ -350,7 +339,7 @@ function Processor.processVengence()
return
end
local base = chunk.base
if canMigrate(map, base) and (Universe.random() < 0.075) then
if canMigrate(base) and (Universe.random() < 0.075) then
formVengenceSettler(chunk, base)
else
formVengenceSquad(chunk, base)
@ -359,105 +348,97 @@ end
function Processor.processNests(tick)
local chunkId = Universe.processNestIterator
local chunkPack
local chunk
if not chunkId then
chunkId,chunkPack = next(Universe.chunkToNests, nil)
chunkId,chunk = next(Universe.chunkToNests, nil)
else
chunkPack = Universe.chunkToNests[chunkId]
chunk = Universe.chunkToNests[chunkId]
end
if not chunkId then
Universe.processNestIterator = nil
else
Universe.processNestIterator = next(Universe.chunkToNests, chunkId)
local map = chunkPack.map
if not map.surface.valid then
removeChunkToNest(chunkId)
return
end
local chunk = getChunkById(chunkId)
processNestActiveness(chunk, tick)
return
end
if Universe.NEW_ENEMIES then
processBaseMutation(chunk,
map,
chunk.base)
end
Universe.processNestIterator = next(Universe.chunkToNests, chunkId)
local map = chunk.map
if not map.surface.valid then
removeChunkToNest(chunkId)
return
end
processNestActiveness(chunk, tick)
if Universe.NEW_ENEMIES then
processBaseMutation(chunk,
map,
chunk.base)
end
end
local function processSpawnersBody(iterator, chunks)
local chunkId = Universe[iterator]
local chunkPack
local chunk
if not chunkId then
chunkId,chunkPack = next(chunks, nil)
chunkId,chunk = next(chunks, nil)
else
chunkPack = chunks[chunkId]
chunk = chunks[chunkId]
end
if not chunkId then
Universe[iterator] = nil
else
Universe[iterator] = next(chunks, chunkId)
local map = chunkPack.map -- error
if not map.surface.valid then
if (iterator == "processMigrationIterator") then
removeChunkToNest(chunkId)
else
chunks[chunkId] = nil
end
return
end
local chunk = getChunkById(chunkId)
local base = findNearbyBase(chunk)
if base.stateAI == BASE_AI_STATE_PEACEFUL then
return
end
if iterator == "processMigrationIterator" then
if (base.stateAI ~= BASE_AI_STATE_MIGRATING) and (base.stateAI ~= BASE_AI_STATE_SIEGE) then
return
end
elseif iterator == "processActiveRaidSpawnerIterator" then
if (base.stateAI == BASE_AI_STATE_AGGRESSIVE) or (base.stateAI == BASE_AI_STATE_MIGRATING) then
return
end
elseif iterator == "processActiveSpawnerIterator" then
if (base.stateAI == BASE_AI_STATE_MIGRATING) then
return
end
end
local migrate = canMigrate(base)
local attack = canAttack(base)
if migrate then
formSettlers(chunk, base)
end
if attack then
formSquads(chunk, base)
return
end
Universe[iterator] = next(chunks, chunkId)
local map = chunk.map
if not map.surface.valid then
if (iterator == "processMigrationIterator") then
removeChunkToNest(chunkId)
else
chunks[chunkId] = nil
end
return
end
local base = chunk.base
local migrate = canMigrate(base)
local attack = canAttack(base)
if migrate then
formSettlers(chunk)
end
if attack then
formSquads(chunk)
end
end
function Processor.processAttackWaves()
processSpawnersBody("processActiveSpawnerIterator",
Universe.chunkToActiveNest)
processSpawnersBody("processActiveRaidSpawnerIterator",
Universe.chunkToActiveRaidNest)
processSpawnersBody("processMigrationIterator",
Universe.chunkToNests)
processSpawnersBody(
"processActiveSpawnerIterator",
Universe.chunkToActiveNest
)
processSpawnersBody(
"processActiveRaidSpawnerIterator",
Universe.chunkToActiveRaidNest
)
processSpawnersBody(
"processMigrationIterator",
Universe.chunkToNests
)
end
function Processor.processClouds(tick)
local eventId, builderPack = next(Universe.settlePurpleCloud, nil)
if builderPack and (builderPack.tick <= tick) then
Universe.settlePurpleCloud[eventId] = nil
local map = builderPack.map
if builderPack.group.valid and map.surface.valid then
setPositionInQuery(
Universe.obaCreateBuildCloudQuery,
builderPack.group.position
)
map.surface.create_entity(Universe.obaCreateBuildCloudQuery)
end
if not builderPack or (builderPack.tick > tick) then
return
end
Universe.settlePurpleCloud[eventId] = nil
local map = builderPack.map
if not builderPack.group.valid or not map.surface.valid then
return
end
setPositionInQuery(
Universe.obaCreateBuildCloudQuery,
builderPack.group.position
)
map.surface.create_entity(Universe.obaCreateBuildCloudQuery)
end
@ -505,7 +486,6 @@ function Processor.processPendingChunks(tick, flush)
else
local initialChunk = createChunk(map, x, y)
map[x][y] = initialChunk
Universe.chunkIdToChunk[initialChunk.id] = initialChunk
local chunk = initialScan(initialChunk, map, tick)
if (chunk ~= -1) then
tableInsert(
@ -515,7 +495,6 @@ function Processor.processPendingChunks(tick, flush)
)
else
map[x][y] = nil
Universe.chunkIdToChunk[initialChunk.id] = nil
end
end
@ -598,7 +577,7 @@ function Processor.processPendingUpgrades(tick)
})
if createdEntity and createdEntity.valid then
if entityData.register then
registerEnemyBaseStructure(map, createdEntity, base, tick, true)
registerEnemyBaseStructure(createdEntity, base, tick, true)
end
if not entityData.evolve and Universe.printBaseUpgrades then
surface.print("["..base.id.."]:"..surface.name.." Upgrading ".. entityName .. " to " .. name .. " [gps=".. position.x ..",".. position.y .."]")

View File

@ -900,10 +900,11 @@ local function attackWaveScaling()
Universe.random))
end
local function attackWaveValidCandidate(chunk, base)
local function attackWaveValidCandidate(chunk)
if isActiveNest(chunk) then
return true
end
local base = chunk.base
if (base.stateAI == BASE_AI_STATE_RAIDING) or
(base.stateAI == BASE_AI_STATE_SIEGE) or
(base.stateAI == BASE_AI_STATE_ONSLAUGHT)
@ -1055,7 +1056,8 @@ function Squad.rallyUnits(chunk, tick, base)
end
end
function Squad.formSettlers(chunk, base)
function Squad.formSettlers(chunk)
local base = chunk.base
if (Universe.builderCount < Universe.AI_MAX_BUILDER_COUNT)
and (base.sentExpansionGroups < base.maxExpansionGroups)
and ((base.unitPoints - AI_SETTLER_COST) > 0)
@ -1210,9 +1212,10 @@ function Squad.formVengenceSettler(chunk, base)
end
end
function Squad.formSquads(chunk, base)
function Squad.formSquads(chunk)
local base = chunk.base
if (Universe.squadCount < Universe.AI_MAX_SQUAD_COUNT)
and attackWaveValidCandidate(chunk, base)
and attackWaveValidCandidate(chunk)
and ((base.unitPoints - AI_SQUAD_COST) > 0)
and (Universe.random() < Universe.formSquadThreshold)
then

View File

@ -512,12 +512,8 @@ function Upgrade.addUniverseProperties()
Universe.eventId = 0
Universe.chunkId = 0
Universe.maps = {}
Universe.chunkIdToChunk = {}
Universe.groupNumberToSquad = {}
Universe.chunkToVictory = {}
Universe.pendingChunks = {}
Universe.processActiveNest = {}
Universe.processActiveNestIterator = nil
Universe.squadIterator = nil
Universe.processMapAIIterator = nil
Universe.processNestIterator = nil
@ -526,18 +522,21 @@ function Upgrade.addUniverseProperties()
Universe.mapIterator = nil
Universe.builderCount = 0
Universe.squadCount = 0
Universe.chunkToNests = {}
Universe.chunkToHives = {}
Universe.chunkToUtilities = {}
Universe.processActiveSpawnerIterator = nil
Universe.processActiveRaidSpawnerIterator = nil
Universe.processMigrationIterator = nil
Universe.chunkToNests = {}
Universe.chunkToHives = {}
Universe.chunkToUtilities = {}
Universe.chunkToVictory = {}
Universe.chunkToActiveNest = {}
Universe.chunkToActiveRaidNest = {}
Universe.chunkToDrained = {}
Universe.chunkToRetreats = {}
Universe.chunkToRallys = {}
Universe.chunkToPassScan = {}
Universe.baseId = 0
Universe.awake = false
@ -671,10 +670,6 @@ function Upgrade.prepMap(surface)
map.drainPylons = {}
map.chunkToSquad = {}
map.chunkScanCounts = {}
map.surface = surface
map.bases = {}
@ -698,6 +693,8 @@ function Upgrade.prepMap(surface)
end
processPendingChunks(tick, true)
return map
end
function Upgrade.init(universe)