mirror of
https://github.com/veden/Rampant.git
synced 2025-03-17 20:58:35 +02:00
FACTO-255: separated activeMaps from inactive maps
This commit is contained in:
parent
fd383b9dc7
commit
77d5fb48b6
47
control.lua
47
control.lua
@ -64,7 +64,8 @@ local split = Utils.split
|
||||
|
||||
local planning = BaseUtils.planning
|
||||
|
||||
local addBasesToAllEnemyStructures = ChunkUtils.addBasesToAllEnemyStructures
|
||||
local addExcludeSurface = MapUtils.addExcludedSurface
|
||||
local removeExcludeSurface = MapUtils.removeExcludedSurface
|
||||
|
||||
local setPointAreaInQuery = Utils.setPointAreaInQuery
|
||||
|
||||
@ -75,7 +76,8 @@ local processClouds = Processor.processClouds
|
||||
local distortPosition = MathUtils.distortPosition
|
||||
local linearInterpolation = MathUtils.linearInterpolation
|
||||
local gaussianRandomRangeRG = MathUtils.gaussianRandomRangeRG
|
||||
local prepMap = Upgrade.prepMap
|
||||
local prepMap = MapUtils.prepMap
|
||||
local activateMap = MapUtils.activateMap
|
||||
|
||||
local findBaseInitialAlignment = BaseUtils.findBaseInitialAlignment
|
||||
|
||||
@ -131,8 +133,6 @@ local createBase = BaseUtils.createBase
|
||||
local findNearbyBaseByPosition = ChunkPropertyUtils.findNearbyBaseByPosition
|
||||
local findNearbyBase = ChunkPropertyUtils.findNearbyBase
|
||||
|
||||
local processActiveNests = Processor.processActiveNests
|
||||
|
||||
local removeDrainPylons = ChunkPropertyUtils.removeDrainPylons
|
||||
local getDrainPylonPair = ChunkPropertyUtils.getDrainPylonPair
|
||||
|
||||
@ -216,9 +216,9 @@ local function initializeLibraries()
|
||||
Squad.init(Universe)
|
||||
BaseUtils.init(Universe)
|
||||
Processor.init(Universe)
|
||||
ChunkPropertyUtils.init(Universe)
|
||||
ChunkUtils.init(Universe)
|
||||
MapUtils.init(Universe)
|
||||
ChunkPropertyUtils.init(Universe, MapUtils)
|
||||
ChunkUtils.init(Universe)
|
||||
end
|
||||
|
||||
local function onLoad()
|
||||
@ -347,7 +347,7 @@ local function onEnemyBaseBuild(event)
|
||||
if not map then
|
||||
return
|
||||
end
|
||||
map.activeSurface = true
|
||||
activateMap(map)
|
||||
local chunk = getChunkByPosition(map, entity.position)
|
||||
if (chunk ~= -1) then
|
||||
local base = findNearbyBase(chunk)
|
||||
@ -669,7 +669,7 @@ local function onEntitySpawned(entity, tick)
|
||||
return
|
||||
end
|
||||
if BUILDING_HIVE_TYPE_LOOKUP[entity.name] then
|
||||
map.activeSurface = true
|
||||
activateMap(map)
|
||||
local disPos = distortPosition(Universe.random, entity.position, 8)
|
||||
|
||||
local chunk = getChunkByPosition(map, disPos)
|
||||
@ -772,7 +772,7 @@ local function onUnitGroupCreated(event)
|
||||
if not map then
|
||||
return
|
||||
end
|
||||
map.activeSurface = true
|
||||
activateMap(map)
|
||||
local position = group.position
|
||||
local chunk = getChunkByPosition(map, position)
|
||||
local base
|
||||
@ -852,7 +852,7 @@ local function onGroupFinishedGathering(event)
|
||||
if not map then
|
||||
return
|
||||
end
|
||||
map.activeSurface = true
|
||||
activateMap(map)
|
||||
local squad = Universe.groupNumberToSquad[group.group_number]
|
||||
if squad then
|
||||
if squad.settler then
|
||||
@ -934,7 +934,10 @@ end
|
||||
local function onSurfaceDeleted(event)
|
||||
local surfaceIndex = event.surface_index
|
||||
if (Universe.mapIterator == surfaceIndex) then
|
||||
Universe.mapIterator, Universe.activeMap = next(Universe.maps, Universe.mapIterator)
|
||||
Universe.mapIterator, Universe.currentMap = next(
|
||||
Universe.activeMaps,
|
||||
Universe.mapIterator
|
||||
)
|
||||
end
|
||||
if (Universe.processMapAIIterator == surfaceIndex) then
|
||||
Universe.processMapAIIterator = nil
|
||||
@ -981,7 +984,7 @@ local function onBuilderArrived(event)
|
||||
if not map then
|
||||
return
|
||||
end
|
||||
map.activeSurface = true
|
||||
activateMap(map)
|
||||
if not usingUnit then
|
||||
local squad = Universe.groupNumberToSquad[builder.group_number]
|
||||
squad.commandTick = event.tick + COMMAND_TIMEOUT * 10
|
||||
@ -1008,12 +1011,7 @@ script.on_event(defines.events.on_tick,
|
||||
local pick = tick % 8
|
||||
-- local profiler = game.create_profiler()
|
||||
|
||||
local map = Universe.activeMap
|
||||
if (not map) or (Universe.processedChunks > (#map.processQueue * 0.05)) then
|
||||
Universe.processedChunks = 0
|
||||
map = nextMap()
|
||||
Universe.activeMap = map
|
||||
end
|
||||
local map = nextMap()
|
||||
|
||||
if (pick == 0) then
|
||||
processPendingChunks(tick)
|
||||
@ -1142,19 +1140,6 @@ remote.add_interface("rampantTests",
|
||||
}
|
||||
)
|
||||
|
||||
local function addExcludeSurface(surfaceName)
|
||||
Universe.excludedSurfaces[surfaceName] = true
|
||||
Upgrade.excludeSurface()
|
||||
end
|
||||
|
||||
local function removeExcludeSurface(surfaceName)
|
||||
Universe.excludedSurfaces[surfaceName] = nil
|
||||
local surface = game.get_surface(surfaceName)
|
||||
if surface then
|
||||
prepMap(surface)
|
||||
end
|
||||
end
|
||||
|
||||
local function removeNewEnemies()
|
||||
game.print({"description.rampant--removeNewEnemies"})
|
||||
Universe.NEW_ENEMIES = false
|
||||
|
@ -50,6 +50,8 @@ local MAGIC_MAXIMUM_NUMBER = Constants.MAGIC_MAXIMUM_NUMBER
|
||||
|
||||
-- imported functions
|
||||
|
||||
local activateMap
|
||||
|
||||
local manhattenDistancePoints = MathUtils.manhattenDistancePoints
|
||||
local tableSize = table_size
|
||||
|
||||
@ -117,7 +119,7 @@ local function unregisterActiveRaidNest(chunk)
|
||||
end
|
||||
|
||||
local function addEnemyStructure(chunk, unitNumber, ids, counts, register)
|
||||
chunk.map.activeSurface = true
|
||||
activateMap(chunk.map)
|
||||
local chunkId = chunk.id
|
||||
local entityIds = chunk[ids]
|
||||
if not entityIds then
|
||||
@ -615,9 +617,10 @@ function ChunkPropertyUtils.processNestActiveness(chunk, tick)
|
||||
end
|
||||
end
|
||||
|
||||
function ChunkPropertyUtils.init(universe)
|
||||
function ChunkPropertyUtils.init(universe, mapUtils)
|
||||
Universe = universe
|
||||
Position = universe.chunkPropertyUtilsQueries.position
|
||||
activateMap = mapUtils.activateMap
|
||||
end
|
||||
|
||||
ChunkPropertyUtilsG = ChunkPropertyUtils
|
||||
|
@ -74,6 +74,7 @@ local mFloor = math.floor
|
||||
local getPassable = ChunkPropertyUtils.getPassable
|
||||
local tRemove = table.remove
|
||||
local mCeil = math.ceil
|
||||
local sFind = string.find
|
||||
|
||||
-- module code
|
||||
|
||||
@ -112,15 +113,149 @@ function MapUtils.queueGeneratedChunk(event)
|
||||
Universe.pendingChunks[event.id] = event
|
||||
end
|
||||
|
||||
function MapUtils.activateMap(map)
|
||||
local mapId = map.id
|
||||
if Universe.activeMaps[mapId] then
|
||||
return
|
||||
end
|
||||
|
||||
Universe.activeMaps[mapId] = map
|
||||
end
|
||||
|
||||
function MapUtils.deactivateMap(map)
|
||||
local mapId = map.id
|
||||
if not Universe.activeMaps[mapId] then
|
||||
return
|
||||
end
|
||||
|
||||
Universe.activeMaps[mapId] = nil
|
||||
end
|
||||
|
||||
function MapUtils.excludeSurface()
|
||||
for mapId,map in pairs(Universe.maps) do
|
||||
local toBeRemoved = not map.surface.valid
|
||||
or MapUtils.isExcludedSurface(map.surface.name)
|
||||
or Universe.excludedSurfaces[map.surface.name]
|
||||
|
||||
if toBeRemoved then
|
||||
if Universe.mapIterator == mapId then
|
||||
Universe.mapIterator, Universe.currentMap = next(
|
||||
Universe.activeMaps,
|
||||
Universe.mapIterator
|
||||
)
|
||||
end
|
||||
if Universe.processMapAIIterator == mapId then
|
||||
Universe.processMapAIIterator = nil
|
||||
end
|
||||
Universe.maps[mapId] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function MapUtils.addExcludedSurface(surfaceName)
|
||||
Universe.excludedSurfaces[surfaceName] = true
|
||||
MapUtils.excludeSurface()
|
||||
end
|
||||
|
||||
function MapUtils.removeExcludedSurface(surfaceName)
|
||||
Universe.excludedSurfaces[surfaceName] = nil
|
||||
local surface = game.get_surface(surfaceName)
|
||||
if surface then
|
||||
MapUtils.prepMap(surface)
|
||||
end
|
||||
end
|
||||
|
||||
function MapUtils.isExcludedSurface(surfaceName)
|
||||
return
|
||||
(surfaceName == "aai-signals") or
|
||||
(surfaceName == "RTStasisRealm") or
|
||||
(surfaceName == "minime_dummy_dungeon") or
|
||||
(surfaceName == "minime-preview-character") or
|
||||
(surfaceName == "pipelayer") or
|
||||
(surfaceName == "beltlayer") or
|
||||
|
||||
sFind(surfaceName, "Factory floor") or
|
||||
sFind(surfaceName, " Orbit") or
|
||||
sFind(surfaceName, "clonespace") or
|
||||
sFind(surfaceName, "BPL_TheLabplayer") or
|
||||
sFind(surfaceName, "starmap%-") or
|
||||
sFind(surfaceName, "NiceFill") or
|
||||
sFind(surfaceName, "Asteroid Belt") or
|
||||
sFind(surfaceName, "Vault ") or
|
||||
sFind(surfaceName, "spaceship") or
|
||||
sFind(surfaceName, "bpsb%-lab%-")
|
||||
end
|
||||
|
||||
function MapUtils.prepMap(surface)
|
||||
if Universe.maps[surface.index] then
|
||||
return Universe.maps[surface.index]
|
||||
end
|
||||
|
||||
local surfaceName = surface.name
|
||||
if MapUtils.isExcludedSurface(surfaceName) or Universe.excludedSurfaces[surfaceName] then
|
||||
return
|
||||
end
|
||||
|
||||
game.print("Rampant - Indexing surface:" .. surfaceName .. ", index:" .. tostring(surface.index) .. ", please wait.")
|
||||
|
||||
local map = {
|
||||
id = surface.index,
|
||||
processedChunks = 0,
|
||||
processQueue = {},
|
||||
processIndex = 1,
|
||||
scanPlayerIndex = 1,
|
||||
scanResourceIndex = 1,
|
||||
scanEnemyIndex = 1,
|
||||
outgoingScanWave = true,
|
||||
outgoingStaticScanWave = true,
|
||||
|
||||
drainPylons = {},
|
||||
|
||||
surface = surface,
|
||||
|
||||
bases = {}
|
||||
}
|
||||
|
||||
Universe.maps[map.id] = map
|
||||
|
||||
-- queue all current chunks that wont be generated during play
|
||||
local tick = game.tick
|
||||
for chunk in surface.get_chunks() do
|
||||
if surface.is_chunk_generated(chunk) then
|
||||
MapUtils.queueGeneratedChunk({
|
||||
surface = surface,
|
||||
tick = tick,
|
||||
area = {
|
||||
left_top = {
|
||||
x = chunk.x * 32,
|
||||
y = chunk.y * 32
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
return map
|
||||
end
|
||||
|
||||
function MapUtils.nextMap()
|
||||
local map = Universe.currentMap
|
||||
if map and (Universe.processedChunks < (#map.processQueue * 0.05)) then
|
||||
return map
|
||||
end
|
||||
|
||||
local mapIterator = Universe.mapIterator
|
||||
repeat
|
||||
local map
|
||||
Universe.mapIterator, map = next(Universe.maps, Universe.mapIterator)
|
||||
if map and map.activeSurface then
|
||||
Universe.mapIterator, map = next(Universe.activeMaps, Universe.mapIterator)
|
||||
if map then
|
||||
Universe.processedChunks = 0
|
||||
Universe.currentMap = map
|
||||
return map
|
||||
end
|
||||
until mapIterator == Universe.mapIterator
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
function MapUtils.removeChunkToNest(chunkId)
|
||||
|
143
libs/Upgrade.lua
143
libs/Upgrade.lua
@ -19,7 +19,6 @@ local Upgrade = {}
|
||||
-- imports
|
||||
|
||||
local Constants = require("libs/Constants")
|
||||
local Processor = require("libs/Processor")
|
||||
local ChunkPropertyUtils = require("libs/ChunkPropertyUtils")
|
||||
local MapUtils = require("libs/MapUtils")
|
||||
|
||||
@ -48,41 +47,14 @@ local DEFINES_DISTRACTION_BY_ANYTHING = defines.distraction.by_anything
|
||||
local CHUNK_SIZE = Constants.CHUNK_SIZE
|
||||
local TRIPLE_CHUNK_SIZE = Constants.TRIPLE_CHUNK_SIZE
|
||||
|
||||
local ENEMY_PHEROMONE = Constants.ENEMY_PHEROMONE
|
||||
local CHUNK_TICK = Constants.CHUNK_TICK
|
||||
|
||||
local TICKS_A_MINUTE = Constants.TICKS_A_MINUTE
|
||||
|
||||
-- imported functions
|
||||
|
||||
local addBaseResourceChunk = ChunkPropertyUtils.addBaseResourceChunk
|
||||
local sFind = string.find
|
||||
local queueGeneratedChunk = MapUtils.queueGeneratedChunk
|
||||
local processPendingChunks = Processor.processPendingChunks
|
||||
|
||||
-- module code
|
||||
|
||||
function Upgrade.isExcludedSurface(surfaceName)
|
||||
return
|
||||
(surfaceName == "aai-signals") or
|
||||
(surfaceName == "RTStasisRealm") or
|
||||
(surfaceName == "minime_dummy_dungeon") or
|
||||
(surfaceName == "minime-preview-character") or
|
||||
(surfaceName == "pipelayer") or
|
||||
(surfaceName == "beltlayer") or
|
||||
|
||||
sFind(surfaceName, "Factory floor") or
|
||||
sFind(surfaceName, " Orbit") or
|
||||
sFind(surfaceName, "clonespace") or
|
||||
sFind(surfaceName, "BPL_TheLabplayer") or
|
||||
sFind(surfaceName, "starmap%-") or
|
||||
sFind(surfaceName, "NiceFill") or
|
||||
sFind(surfaceName, "Asteroid Belt") or
|
||||
sFind(surfaceName, "Vault ") or
|
||||
sFind(surfaceName, "spaceship") or
|
||||
sFind(surfaceName, "bpsb%-lab%-")
|
||||
end
|
||||
|
||||
local function addCommandSet(queriesAndCommands)
|
||||
-- preallocating memory to be used in code, making it fast by reducing garbage generated.
|
||||
queriesAndCommands.neighbors = {
|
||||
@ -419,21 +391,6 @@ local function addCommandSet(queriesAndCommands)
|
||||
}
|
||||
end
|
||||
|
||||
function Upgrade.excludeSurface()
|
||||
for mapId,map in pairs(Universe.maps) do
|
||||
local toBeRemoved = not map.surface.valid or Upgrade.isExcludedSurface(map.surface.name) or Universe.excludedSurfaces[map.surface.name]
|
||||
if toBeRemoved then
|
||||
if Universe.mapIterator == mapId then
|
||||
Universe.mapIterator, Universe.activeMap = next(Universe.maps, Universe.mapIterator)
|
||||
end
|
||||
if Universe.processMapAIIterator == mapId then
|
||||
Universe.processMapAIIterator = nil
|
||||
end
|
||||
Universe.maps[mapId] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Upgrade.setCommandForces(npcForces, enemyForces)
|
||||
for force in pairs(Universe.playerForces) do
|
||||
Universe.playerForces[force] = nil
|
||||
@ -512,13 +469,14 @@ function Upgrade.addUniverseProperties()
|
||||
Universe.eventId = 0
|
||||
Universe.chunkId = 0
|
||||
Universe.maps = {}
|
||||
Universe.activeMaps = {}
|
||||
Universe.groupNumberToSquad = {}
|
||||
Universe.pendingChunks = {}
|
||||
Universe.squadIterator = nil
|
||||
Universe.processMapAIIterator = nil
|
||||
Universe.processNestIterator = nil
|
||||
Universe.vengenceQueue = {}
|
||||
Universe.activeMap = nil
|
||||
Universe.currentMap = nil
|
||||
Universe.mapIterator = nil
|
||||
Universe.builderCount = 0
|
||||
Universe.squadCount = 0
|
||||
@ -551,16 +509,6 @@ function Upgrade.addUniverseProperties()
|
||||
|
||||
Universe.processBaseAIIterator = nil
|
||||
|
||||
for _,map in pairs(Universe.maps) do
|
||||
local processQueue = map.processQueue
|
||||
for i=1,#processQueue do
|
||||
local chunk = processQueue[i]
|
||||
chunk[CHUNK_TICK] = chunk[ENEMY_PHEROMONE]
|
||||
chunk[ENEMY_PHEROMONE] = 0
|
||||
chunk.map = map
|
||||
end
|
||||
end
|
||||
|
||||
Universe.excludedSurfaces = {}
|
||||
|
||||
Universe.pendingUpgrades = {}
|
||||
@ -591,22 +539,8 @@ function Upgrade.attempt()
|
||||
|
||||
Universe.evolutionLevel = game.forces.enemy.evolution_factor
|
||||
|
||||
for _,map in pairs(Universe.maps) do
|
||||
if (map.surface.valid) then
|
||||
local entities = map.surface.find_entities_filtered({type="land-mine"})
|
||||
for i=1,#entities do
|
||||
local entity = entities[i]
|
||||
if entity.valid and string.find(entity.name, "entity-proxy-") then
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Universe.random = game.create_random_generator(Constants.ENEMY_SEED)
|
||||
|
||||
Upgrade.excludeSurface()
|
||||
|
||||
local minDiffuse = game.map_settings.pollution.min_to_diffuse
|
||||
Universe.pollutionDiffuseMinimum = minDiffuse * 0.75
|
||||
|
||||
@ -621,82 +555,9 @@ function Upgrade.attempt()
|
||||
Universe.expansionMediumTargetDistance = (Universe.expansionMaxDistance + MINIMUM_EXPANSION_DISTANCE) * 0.50
|
||||
Universe.expansionHighTargetDistance = (Universe.expansionMaxDistance + MINIMUM_EXPANSION_DISTANCE) * 0.75
|
||||
Universe.expansionDistanceDeviation = Universe.expansionMediumTargetDistance * 0.33
|
||||
|
||||
for _,map in pairs(Universe.maps) do
|
||||
if (map.surface.valid) then
|
||||
for _, chunk in pairs(map.processQueue) do
|
||||
if chunk.resourceGenerator then
|
||||
local base = chunk.base
|
||||
if base then
|
||||
addBaseResourceChunk(base, chunk)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
map.chunkToPlayerGenerator = {}
|
||||
map.chunkToPermanentDeathGenerator = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Upgrade.prepMap(surface)
|
||||
local surfaceName = surface.name
|
||||
if Upgrade.isExcludedSurface(surfaceName) then
|
||||
return
|
||||
end
|
||||
|
||||
game.print("Rampant - Indexing surface:" .. surfaceName .. ", index:" .. tostring(surface.index) .. ", please wait.")
|
||||
|
||||
local surfaceIndex = surface.index
|
||||
|
||||
if not Universe.maps then
|
||||
Universe.maps = {}
|
||||
end
|
||||
|
||||
local map = {}
|
||||
Universe.maps[surfaceIndex] = map
|
||||
|
||||
map.activatedMap = false
|
||||
|
||||
map.processedChunks = 0
|
||||
map.processQueue = {}
|
||||
map.processIndex = 1
|
||||
map.scanPlayerIndex = 1
|
||||
map.scanResourceIndex = 1
|
||||
map.scanEnemyIndex = 1
|
||||
map.outgoingScanWave = true
|
||||
map.outgoingStaticScanWave = true
|
||||
|
||||
map.drainPylons = {}
|
||||
|
||||
map.surface = surface
|
||||
|
||||
map.bases = {}
|
||||
|
||||
-- queue all current chunks that wont be generated during play
|
||||
local tick = game.tick
|
||||
for chunk in surface.get_chunks() do
|
||||
if surface.is_chunk_generated(chunk) then
|
||||
queueGeneratedChunk({
|
||||
surface = surface,
|
||||
tick = tick,
|
||||
area = {
|
||||
left_top = {
|
||||
x = chunk.x * 32,
|
||||
y = chunk.y * 32
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
processPendingChunks(tick, true)
|
||||
|
||||
return map
|
||||
end
|
||||
|
||||
function Upgrade.init(universe)
|
||||
Universe = universe
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user