From 556391163479ef375e8d6f4449dfe1d41d40a781 Mon Sep 17 00:00:00 2001 From: Aaron Veden Date: Mon, 27 Dec 2021 13:27:41 -0800 Subject: [PATCH] fixed turrets and hives not being registered when enabling new enemies in active save --- Upgrade.lua | 19 +++++------------ changelog.txt | 1 + control.lua | 14 ++---------- libs/ChunkUtils.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/Upgrade.lua b/Upgrade.lua index 7f51678..a3da614 100644 --- a/Upgrade.lua +++ b/Upgrade.lua @@ -7,6 +7,7 @@ local chunkProcessor = require("libs/ChunkProcessor") local mapUtils = require("libs/MapUtils") local chunkPropertyUtils = require("libs/ChunkPropertyUtils") local baseUtils = require("libs/BaseUtils") +local chunkUtils = require("libs/ChunkUtils") -- constants @@ -36,6 +37,7 @@ local setChunkBase = chunkPropertyUtils.setChunkBase local createBase = baseUtils.createBase local findNearbyBase = baseUtils.findNearbyBase +local addBasesToAllEnemyStructures = chunkUtils.addBasesToAllEnemyStructures local sFind = string.find local queueGeneratedChunk = mapUtils.queueGeneratedChunk @@ -532,22 +534,11 @@ function upgrade.attempt(universe) addCommandSet(universe) end - if global.version < 206 then - global.version = 206 + if global.version < 207 then + global.version = 207 if universe.NEW_ENEMIES then - local tick = game.tick - for chunkId, chunkPack in pairs(universe.chunkToNests) do - local map = chunkPack.map - if map.surface.valid then - local chunk = getChunkById(map, chunkId) - local base = findNearbyBase(map, chunk) - if not base then - base = createBase(map, chunk, tick) - end - setChunkBase(map, chunk, base) - end - end + addBasesToAllEnemyStructures(universe, game.tick) end game.print("Rampant - Version 2.0.4") diff --git a/changelog.txt b/changelog.txt index d66e27d..f1b1f69 100644 --- a/changelog.txt +++ b/changelog.txt @@ -9,6 +9,7 @@ Date: 17. 12. 2021 - Fixed adding player to chunk crash - Fixed surface deletion with chunk processor indexing nil - Fixed enemy structures not being counted for faction adaptation + - Fixed when new enemies is enabled partway through game that all enemy structures are registered correctly --------------------------------------------------------------------------------------------------- Version: 2.0.3 diff --git a/control.lua b/control.lua index 6565046..cd89f21 100644 --- a/control.lua +++ b/control.lua @@ -37,6 +37,7 @@ local RETREAT_SPAWNER_GRAB_RADIUS = constants.RETREAT_SPAWNER_GRAB_RADIUS -- imported functions +local addBasesToAllEnemyStructures = chunkUtils.addBasesToAllEnemyStructures local getChunkById = mapUtils.getChunkById local setChunkBase = chunkPropertyUtils.setChunkBase @@ -297,18 +298,7 @@ local function onConfigChanged() end end if (not usingNewEnemiesAlready) and universe.NEW_ENEMIES then - local tick = game.tick - for chunkId, chunkPack in pairs(universe.chunkToNests) do - local map = chunkPack.map - if map.surface.valid then - local chunk = getChunkById(map, chunkId) - local base = findNearbyBase(map, chunk) - if not base then - base = createBase(map, chunk, tick) - end - setChunkBase(map, chunk, base) - end - end + addBasesToAllEnemyStructures(universe, game.tick) end end diff --git a/libs/ChunkUtils.lua b/libs/ChunkUtils.lua index a4e4cf1..9c8d93f 100644 --- a/libs/ChunkUtils.lua +++ b/libs/ChunkUtils.lua @@ -69,9 +69,9 @@ local addUtilityCount = chunkPropertyUtils.addUtilityCount local removeUtilityCount = chunkPropertyUtils.removeUtilityCount local getPlayerBaseGenerator = chunkPropertyUtils.getPlayerBaseGenerator -local getNestCount = chunkPropertyUtils.getNestCount local setRaidNestActiveness = chunkPropertyUtils.setRaidNestActiveness local setNestActiveness = chunkPropertyUtils.setNestActiveness +local getChunkById = mapUtils.getChunkById local processNestActiveness = chunkPropertyUtils.processNestActiveness @@ -343,6 +343,56 @@ function chunkUtils.mapScanEnemyChunk(chunk, map, tick) end end +function chunkUtils.addBasesToAllEnemyStructures(universe, tick) + for chunkId, chunkPack in pairs(universe.chunkToNests) do + local map = chunkPack.map + if map.surface.valid then + local chunk = getChunkById(map, chunkId) + local base = findNearbyBase(map, chunk) + if not base then + base = createBase(map, chunk, tick) + end + setChunkBase(map, 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(map, chunkId) + local base = findNearbyBase(map, chunk) + if not base then + base = createBase(map, chunk, tick) + end + setChunkBase(map, chunk, base) + end + for chunkId in pairs(map.chunkToHives) do + local chunk = getChunkById(map, chunkId) + local base = findNearbyBase(map, chunk) + if not base then + base = createBase(map, chunk, tick) + end + setChunkBase(map, chunk, base) + end + for chunkId in pairs(map.chunkToUtilities) do + local chunk = getChunkById(map, chunkId) + local base = findNearbyBase(map, chunk) + if not base then + base = createBase(map, chunk, tick) + end + setChunkBase(map, chunk, base) + end + for chunkId in pairs(map.chunkToTraps) do + local chunk = getChunkById(map, chunkId) + local base = findNearbyBase(map, chunk) + if not base then + base = createBase(map, chunk, tick) + end + setChunkBase(map, chunk, base) + end + end + end +end + function chunkUtils.entityForPassScan(map, entity) local overlapArray = getEntityOverlapChunks(map, entity)