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

FACTO-98: Fixed base recycling on invalid surfaces

This commit is contained in:
Aaron Veden 2022-04-09 19:24:15 -07:00
parent 6402bb52bc
commit dd3b4d959b
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
5 changed files with 29 additions and 15 deletions

View File

@ -554,6 +554,8 @@ function upgrade.attempt(universe)
universe.baseId = 0
universe.awake = false
universe.recycleBaseIterator = nil
universe.maxPoints = 0
universe.maxOverflowPoints = 0
@ -662,8 +664,6 @@ function upgrade.prepMap(universe, surface)
map.chunkToPathRating = {}
map.chunkToDeathGenerator = {}
map.recycleBaseIterator = nil
map.chunkScanCounts = {}
map.emptySquadsOnChunk = {}

View File

@ -27,6 +27,7 @@ Version: 3.0.0
- Fixed enemy map scan creating bases unnecessarily
- 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
---------------------------------------------------------------------------------------------------
Version: 2.2.0

View File

@ -896,6 +896,11 @@ local function onSurfaceDeleted(event)
universe.maps[surfaceIndex] = nil
end
local function onSurfaceCleared(event)
onSurfaceDeleted(event)
onSurfaceCreated(event)
end
local function onBuilderArrived(event)
local builder = event.group
local usingUnit = false
@ -945,7 +950,7 @@ script.on_event(defines.events.on_tick,
if (pick == 0) then
processPendingChunks(universe, tick)
if map then
recycleBases(map)
recycleBases(universe)
end
cleanUpMapTables(universe, tick)
elseif (pick == 1) then
@ -991,7 +996,7 @@ script.on_event(defines.events.on_tick,
end)
script.on_event(defines.events.on_surface_deleted, onSurfaceDeleted)
script.on_event(defines.events.on_surface_cleared, onSurfaceCreated)
script.on_event(defines.events.on_surface_cleared, onSurfaceCleared)
script.on_event(defines.events.on_surface_created, onSurfaceCreated)
script.on_init(onInit)
@ -1102,7 +1107,11 @@ local function rampantSetAIState(event)
return
end
base.stateAI = target
local surface = base.surface
local surface = base.map.surface
if not surface.valid then
game.print("Base is invalid because surface is invalid")
return
end
game.print("id:" .. baseId .. " on surface:" .. surface.name .. " is now in " .. constants.stateEnglish[base.stateAI])
end
end

View File

@ -343,8 +343,8 @@ local function temperamentPlanner(base, evolutionLevel)
base.builtEnemyBuilding .. ", iCB:" .. base.ionCannonBlasts .. ", aB:" ..
base.artilleryBlasts .. ", temp:" .. base.temperament .. ", tempScore:" .. base.temperamentScore ..
", points:" .. base.points .. ", unitPoints:" .. base.unitPoints .. ", state:" ..
constants.stateEnglish[base.stateAI] .. ", surface:" .. base.surface.index .. " [" ..
base.surface.name .. "]" .. ", aS:" .. universe.squadCount .. ", aB:" .. universe.builderCount ..
constants.stateEnglish[base.stateAI] .. ", surface:" .. base.map.surface.index .. " [" ..
base.map.surface.name .. "]" .. ", aS:" .. universe.squadCount .. ", aB:" .. universe.builderCount ..
", atkSize:" .. universe.attackWaveSize .. ", stlSize:" .. universe.settlerWaveSize ..
", formGroup:" .. universe.formSquadThreshold .. ", sAgg:".. base.sentAggressiveGroups ..
", mAgg:" .. base.maxAggressiveGroups .. ", baseState:" .. base.stateGeneration

View File

@ -255,9 +255,9 @@ local function findBaseInitialAlignment(universe, evoIndex)
return result
end
function baseUtils.recycleBases(map)
local bases = map.bases
local id = map.recycleBaseIterator
function baseUtils.recycleBases(universe)
local bases = universe.bases
local id = universe.recycleBaseIterator
local base
if not id then
id, base = next(bases, nil)
@ -265,12 +265,16 @@ function baseUtils.recycleBases(map)
base = bases[id]
end
if not id then
map.recycleBaseIterator = nil
universe.recycleBaseIterator = nil
else
map.recycleBaseIterator = next(bases, id)
if base.chunkCount == 0 then
universe.recycleBaseIterator = next(bases, id)
local map = base.map
if (base.chunkCount == 0) or not map.surface.valid then
print("removing", id)
bases[id] = nil
map.universe.bases[id] = nil
if map.surface.valid then
map.universe.bases[id] = nil
end
end
end
end
@ -502,7 +506,7 @@ function baseUtils.createBase(map, chunk, tick)
temperament = 0.5,
temperamentScore = 0,
universe = universe,
surface = map.surface,
map = map,
id = universe.baseId
}
universe.baseId = universe.baseId + 1