From 76dbc8363e8a2a2b1037ac74cf076dc6bb4b6acb Mon Sep 17 00:00:00 2001 From: Aaron Veden Date: Thu, 9 Dec 2021 22:38:50 -0800 Subject: [PATCH] chunk passing scanning happens regardless of active map --- Upgrade.lua | 4 ++-- changelog.txt | 1 + control.lua | 11 +++++++---- libs/ChunkProcessor.lua | 27 ++++++++++++++++----------- libs/ChunkUtils.lua | 7 +++++-- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Upgrade.lua b/Upgrade.lua index ca8848d..eb6504c 100644 --- a/Upgrade.lua +++ b/Upgrade.lua @@ -468,6 +468,8 @@ function upgrade.attempt(universe) universe.chunkToRetreats = {} universe.chunkToRallyIterator = nil universe.chunkToRallys = {} + universe.chunkToPassScan = {} + universe.chunkToPassScanIterator = nil game.print("Rampant - Version 2.0.0") end @@ -531,14 +533,12 @@ function upgrade.prepMap(universe, surface) map.chunkToPlayerCount = {} map.playerToChunk = {} - map.chunkToPassScan = {} map.chunkToSquad = {} map.chunkToPassable = {} map.chunkToPathRating = {} map.chunkToDeathGenerator = {} - map.chunkToPassScanIterator = nil map.recycleBaseIterator = nil map.chunkScanCounts = {} diff --git a/changelog.txt b/changelog.txt index 9b24764..ccd775d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -31,6 +31,7 @@ Date: 23. 11. 2021 - Attack waves are processed regardless of current active map - Surfaces are allocated but don't begin processing until the first enemy structure or unit group is found - Map cleanup is now processed regardless of current active map + - Chunk pass scanning is now processed regardless of current active map Tweaks: - Increase chance to upgrade an enemy structure from 5% to 30% - New enemy regional bases that have two factions now do 75% on one faction and 25% on the faction for building and upgrading enemy structures diff --git a/control.lua b/control.lua index 9f57dae..142b933 100644 --- a/control.lua +++ b/control.lua @@ -538,7 +538,12 @@ local function processSurfaceTile(map, position, chunks, tick) local chunk = getChunkByPosition(map, position) if (chunk ~= -1) then - map.chunkToPassScan[chunk.id] = chunk + if not map.universe.chunkToPassScan[chunk.id] then + map.universe.chunkToPassScan[chunk.id] = { + map=map, + chunk=chunk + } + end else local x,y = positionToChunkXY(position) local addMe = true @@ -961,9 +966,7 @@ script.on_event(defines.events.on_tick, processNests(universe, tick) elseif (pick == 7) then processPendingChunks(universe, tick) - if map then - processScanChunks(map) - end + processScanChunks(universe) end processActiveNests(universe, tick) diff --git a/libs/ChunkProcessor.lua b/libs/ChunkProcessor.lua index 218b66e..fc2c4b9 100644 --- a/libs/ChunkProcessor.lua +++ b/libs/ChunkProcessor.lua @@ -178,26 +178,31 @@ function chunkProcessor.processPendingUpgrades(universe, tick) end -function chunkProcessor.processScanChunks(map) - local chunkId = map.chunkToPassScanIterator - local chunk +function chunkProcessor.processScanChunks(universe) + local chunkId = universe.chunkToPassScanIterator + local chunkPack if not chunkId then - chunkId, chunk = next(map.chunkToPassScan, nil) + chunkId, chunkPack = next(universe.chunkToPassScan, nil) else - chunk = map.chunkToPassScan[chunkId] + chunkPack = universe.chunkToPassScan[chunkId] end if not chunkId then - map.chunkToPassScanIterator = nil - if (table_size(map.chunkToPassScan) == 0) then + universe.chunkToPassScanIterator = nil + if (table_size(universe.chunkToPassScan) == 0) then -- this is needed as the next command remembers the max length a table has been - map.chunkToPassScan = {} + universe.chunkToPassScan = {} end else - map.chunkToPassScanIterator = next(map.chunkToPassScan, chunkId) - map.chunkToPassScan[chunkId] = nil + universe.chunkToPassScanIterator = next(universe.chunkToPassScan, chunkId) + universe.chunkToPassScan[chunkId] = nil + local map = chunkPack.map + if not map.surface.valid then + return + end + local chunk = chunkPack.chunk - local area = map.universe.area + local area = universe.area local topOffset = area[1] local bottomOffset = area[2] topOffset[1] = chunk.x diff --git a/libs/ChunkUtils.lua b/libs/ChunkUtils.lua index c9de894..760b6b0 100644 --- a/libs/ChunkUtils.lua +++ b/libs/ChunkUtils.lua @@ -350,8 +350,11 @@ function chunkUtils.entityForPassScan(map, entity) for i=1,#overlapArray do local chunk = overlapArray[i] - if (chunk ~= -1) then - map.chunkToPassScan[chunk.id] = chunk + if (chunk ~= -1) and not map.universe.chunkToPassScan[chunk.id] then + map.universe.chunkToPassScan[chunk.id] = { + map = map, + chunk = chunk + } end end end