1
0
mirror of https://github.com/veden/Rampant.git synced 2025-03-17 20:58:35 +02:00

FACTO-4: Added on_chunk_deleted event

This commit is contained in:
Aaron Veden 2022-04-09 20:15:14 -07:00
parent dd3b4d959b
commit a2526d9ec9
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
4 changed files with 70 additions and 40 deletions

View File

@ -13,6 +13,7 @@ Version: 3.0.0
- Regional bases now have there own aggressive and siege squad counter and cleanup process
- Added beltlayer, pipelayer, minime, and blueprint-sandboxes mod surfaces to surface exclusion list
- Added mod settings to customize factions colors
- Added on_chunk_deleted event for updating map and base stats
Tweaks:
- Increased unit spawner cooldown by 2x
- Added point loss on unit death
@ -28,6 +29,7 @@ Version: 3.0.0
- Fixed base.index reference error in displaying ai state
- Fixed rampantSetAIState command to work with multiple ais per surface
- Fixed base recycling on invalid surfaces
- Fixed base chunk count not being decremented when chunks are removed
---------------------------------------------------------------------------------------------------
Version: 2.2.0

View File

@ -89,6 +89,9 @@ local disperseVictoryScent = pheromoneUtils.disperseVictoryScent
local getChunkByPosition = mapUtils.getChunkByPosition
local removeChunkFromMap = mapUtils.removeChunkFromMap
local getChunkByXY = mapUtils.getChunkByXY
local entityForPassScan = chunkUtils.entityForPassScan
local processPendingChunks = chunkProcessor.processPendingChunks
@ -901,6 +904,23 @@ local function onSurfaceCleared(event)
onSurfaceCreated(event)
end
local function onChunkDeleted(event)
local surfaceIndex = event.surface_index
local map = universe.maps[surfaceIndex]
if map then
local positions = event.positions
for i=1,#positions do
local position = positions[i]
local x = position.x * 32
local y = position.y * 32
local chunk = getChunkByXY(map, x, y)
if chunk ~= -1 then
removeChunkFromMap(map, chunk)
end
end
end
end
local function onBuilderArrived(event)
local builder = event.group
local usingUnit = false
@ -995,6 +1015,7 @@ script.on_event(defines.events.on_tick,
-- game.print({"", "--dispatch4 ", profiler, ", ", pick, ", ", game.tick, " ", universe.random()})
end)
script.on_event(defines.events.on_chunk_deleted, onChunkDeleted)
script.on_event(defines.events.on_surface_deleted, onSurfaceDeleted)
script.on_event(defines.events.on_surface_cleared, onSurfaceCleared)
script.on_event(defines.events.on_surface_created, onSurfaceCreated)

View File

@ -34,6 +34,7 @@ local mapUtils = require("MapUtils")
-- imported functions
local findInsertionPoint = mapUtils.findInsertionPoint
local removeChunkFromMap = mapUtils.removeChunkFromMap
local setPositionInQuery = queryUtils.setPositionInQuery
local registerEnemyBaseStructure = chunkUtils.registerEnemyBaseStructure
@ -46,44 +47,10 @@ local chunkPassScan = chunkUtils.chunkPassScan
local next = next
local table_size = table_size
local tRemove = table.remove
local tInsert = table.insert
local mCeil = math.ceil
-- module code
local function findInsertionPoint(processQueue, chunk)
local low = 1
local high = #processQueue
local pivot
while (low <= high) do
pivot = mCeil((low + high) * 0.5)
local pivotChunk = processQueue[pivot]
if (pivotChunk.dOrigin > chunk.dOrigin) then
high = pivot - 1
elseif (pivotChunk.dOrigin <= chunk.dOrigin) then
low = pivot + 1
end
end
return low
end
local function removeProcessQueueChunk(processQueue, chunk)
local insertionPoint = findInsertionPoint(processQueue, chunk)
if insertionPoint > #processQueue then
insertionPoint = insertionPoint - 1
end
for i=insertionPoint,1,-1 do
local pqChunk = processQueue[i]
if pqChunk.id == chunk.id then
tRemove(processQueue, i)
return
elseif pqChunk.dOrigin < chunk.dOrigin then
return
end
end
end
function chunkProcessor.processPendingChunks(universe, tick, flush)
local pendingChunks = universe.pendingChunks
local eventId = universe.chunkProcessorIterator
@ -132,8 +99,7 @@ function chunkProcessor.processPendingChunks(universe, tick, flush)
local oldChunk = map[x][y]
local chunk = initialScan(oldChunk, map, tick)
if (chunk == -1) then
removeProcessQueueChunk(map.processQueue, oldChunk)
removeChunkFromMap(map, x, y, oldChunk.id)
removeChunkFromMap(map, oldChunk)
end
else
local initialChunk = createChunk(map, x, y)
@ -229,8 +195,7 @@ function chunkProcessor.processScanChunks(universe)
local chunk = chunkPack.chunk
if (chunkPassScan(chunk, map) == -1) then
removeProcessQueueChunk(map.processQueue, chunk)
removeChunkFromMap(map, chunk.x, chunk.y, chunk.id)
removeChunkFromMap(map, chunk)
end
end
end

View File

@ -39,6 +39,8 @@ local CHUNK_SIZE_DIVIDER = constants.CHUNK_SIZE_DIVIDER
local mFloor = math.floor
local getPassable = chunkPropertyUtils.getPassable
local tRemove = table.remove
local mCeil = math.ceil
-- module code
@ -102,7 +104,43 @@ function mapUtils.removeChunkToNest(universe, chunkId)
end
end
function mapUtils.removeChunkFromMap(map, x, y, chunkId)
function mapUtils.findInsertionPoint(processQueue, chunk)
local low = 1
local high = #processQueue
local pivot
while (low <= high) do
pivot = mCeil((low + high) * 0.5)
local pivotChunk = processQueue[pivot]
if (pivotChunk.dOrigin > chunk.dOrigin) then
high = pivot - 1
elseif (pivotChunk.dOrigin <= chunk.dOrigin) then
low = pivot + 1
end
end
return low
end
function mapUtils.removeProcessQueueChunk(processQueue, chunk)
local insertionPoint = mapUtils.findInsertionPoint(processQueue, chunk)
if insertionPoint > #processQueue then
insertionPoint = insertionPoint - 1
end
for i=insertionPoint,1,-1 do
local pqChunk = processQueue[i]
if pqChunk.id == chunk.id then
tRemove(processQueue, i)
return
elseif pqChunk.dOrigin < chunk.dOrigin then
return
end
end
end
function mapUtils.removeChunkFromMap(map, chunk)
local chunkId = chunk.id
local x = chunk.x
local y = chunk.y
mapUtils.removeProcessQueueChunk(map.processQueue, chunk)
local universe = map.universe
map[x][y] = nil
universe.chunkIdToChunk[chunkId] = nil
@ -116,7 +154,11 @@ function mapUtils.removeChunkFromMap(map, x, y, chunkId)
universe.vengenceQueue[chunkId] = nil
universe.processActiveNest[chunkId] = nil
universe.chunkToVictory[chunkId] = nil
map.chunkToBase[chunkId] = nil
local base = map.chunkToBase[chunkId]
if base then
base.chunkCount = base.chunkCount - 1
map.chunkToBase[chunkId] = nil
end
map.chunkToTurrets[chunkId] = nil
map.chunkToTraps[chunkId] = nil
map.chunkToUtilities[chunkId] = nil