1
0
mirror of https://github.com/veden/Rampant.git synced 2024-12-28 21:08:22 +02:00

FACTO-292: Fixed hives deregister count and hive death

This commit is contained in:
Aaron Veden 2023-04-06 19:49:09 -07:00
parent 006564faf3
commit 583c3c6094
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
5 changed files with 59 additions and 3 deletions

View File

@ -15,6 +15,8 @@ Version: 3.3.0
- Fixed squad creation didn't take into account chunk pathing from nest to squad - Fixed squad creation didn't take into account chunk pathing from nest to squad
- Fixed chunk being invalid on unit group finished gathering - Fixed chunk being invalid on unit group finished gathering
- Fixed squad being able to teleport short distance when first assembling - Fixed squad being able to teleport short distance when first assembling
- Fixed hives didn't properly decrement counts of entities spawned when spawned entites were destroyed
- Fixed hives didn't get unregistered properly
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 3.2.2 Version: 3.2.2

View File

@ -112,6 +112,7 @@ local scanResourceMap = Processor.scanResourceMap
local processNests = Processor.processNests local processNests = Processor.processNests
local processHives = Processor.processHives local processHives = Processor.processHives
local cleanHivesData = Processor.cleanHivesData
local rallyUnits = Squad.rallyUnits local rallyUnits = Squad.rallyUnits
@ -983,6 +984,7 @@ script.on_event(defines.events.on_tick,
cleanUpMapTables(tick) cleanUpMapTables(tick)
planning(gameRef.forces.enemy.evolution_factor) planning(gameRef.forces.enemy.evolution_factor)
processHives(tick) processHives(tick)
cleanHivesData()
elseif (pick == 1) then elseif (pick == 1) then
processPlayers(gameRef.connected_players, tick) processPlayers(gameRef.connected_players, tick)
elseif (pick == 2) then elseif (pick == 2) then

View File

@ -520,6 +520,14 @@ local function unregisterHive(entityUnitNumber, hiveType)
else else
local hiveData = Universe.hiveData[entityUnitNumber] local hiveData = Universe.hiveData[entityUnitNumber]
if hiveData then if hiveData then
if Universe.hiveDataIterator == entityUnitNumber then
Universe.hiveDataIterator = nil
end
if not Universe.hives[hiveData.hiveId] then
Universe.hiveData[entityUnitNumber] = nil
return
end
Universe.activeHives[hiveData.hiveId] = hiveData Universe.activeHives[hiveData.hiveId] = hiveData
local adjustedHiveType = ( local adjustedHiveType = (
( (
@ -528,7 +536,7 @@ local function unregisterHive(entityUnitNumber, hiveType)
) )
and "nest" and "nest"
) or hiveType ) or hiveType
hiveData[adjustedHiveType] = hiveData.nest - 1 hiveData[adjustedHiveType] = hiveData[adjustedHiveType] - 1
if hiveData[adjustedHiveType] < 0 then if hiveData[adjustedHiveType] < 0 then
hiveData[adjustedHiveType] = 0 hiveData[adjustedHiveType] = 0
end end

View File

@ -541,6 +541,25 @@ function Processor.processHives(tick)
end end
end end
function Processor.cleanHivesData()
local entityId = Universe.hiveDataIterator
local hiveData
if not entityId then
entityId, hiveData = next(Universe.hiveData, nil)
else
hiveData = Universe.hiveData[entityId]
end
if not entityId then
Universe.hiveDataIterator = nil
return
end
Universe.hiveDataIterator = next(Universe.hiveData, entityId)
if not Universe.hives[hiveData.id] then
Universe.hiveData[entityId] = nil
end
end
function Processor.processPendingChunks(tick, flush) function Processor.processPendingChunks(tick, flush)
local pendingChunks = Universe.pendingChunks local pendingChunks = Universe.pendingChunks
local eventId, event = next(pendingChunks, nil) local eventId, event = next(pendingChunks, nil)

View File

@ -535,6 +535,8 @@ function Upgrade.addUniverseProperties()
if global.universePropertyVersion < 2 then if global.universePropertyVersion < 2 then
global.universePropertyVersion = 2 global.universePropertyVersion = 2
addCommandSet() addCommandSet()
Universe.hiveDataIterator = nil
end end
end end
@ -542,8 +544,6 @@ function Upgrade.attempt()
if not global.gameVersion then if not global.gameVersion then
global.gameVersion = 1 global.gameVersion = 1
game.forces.enemy.kill_all_units()
Universe.evolutionLevel = game.forces.enemy.evolution_factor Universe.evolutionLevel = game.forces.enemy.evolution_factor
Universe.random = game.create_random_generator(Constants.ENEMY_SEED) Universe.random = game.create_random_generator(Constants.ENEMY_SEED)
@ -572,7 +572,17 @@ function Upgrade.attempt()
squad.canBeCompressed = 0 squad.canBeCompressed = 0
end end
game.forces.enemy.kill_all_units()
local lookup = {}
for _, map in pairs(Universe.maps) do for _, map in pairs(Universe.maps) do
local entities = map.surface.find_entities_filtered({
type = "unit-spawner",
force = "enemy"
})
for i = 1, #entities do
lookup[entities[i].unit_number] = true
end
for _, chunk in pairs(map.processQueue) do for _, chunk in pairs(map.processQueue) do
chunk[CHUNK_TICK] = 0 chunk[CHUNK_TICK] = 0
chunk[BASE_PHEROMONE] = 0 chunk[BASE_PHEROMONE] = 0
@ -582,6 +592,21 @@ function Upgrade.attempt()
chunk[KAMIKAZE_PHEROMONE] = 0 chunk[KAMIKAZE_PHEROMONE] = 0
end end
end end
for entityId in pairs(Universe.activeHives) do
if not lookup[entityId] then
Universe.activeHives[entityId] = nil
Universe.hives[entityId] = nil
end
end
for entityId in pairs(Universe.hives) do
if not lookup[entityId] then
Universe.activeHives[entityId] = nil
Universe.hives[entityId] = nil
end
end
Universe.hiveIterator = nil
end end
end end