1
0
mirror of https://github.com/veden/Rampant.git synced 2025-09-16 09:16:43 +02:00

surfaces are begin processing lazily

This commit is contained in:
Aaron Veden
2021-12-07 22:44:22 -08:00
parent 903e4b49d0
commit 0207aa0fe4
5 changed files with 135 additions and 105 deletions

View File

@@ -495,6 +495,8 @@ function upgrade.prepMap(universe, surface)
local map = {}
universe.maps[surfaceIndex] = map
map.activatedMap = false
map.maxAggressiveGroups = 1
map.sentAggressiveGroups = 0
map.processedChunks = 0

View File

@@ -28,6 +28,7 @@ Date: 23. 11. 2021
- AI Planning will now happen on upto 15 surface per cycle
- Spawners not covered by pollution are now processed regardless of current active map
- 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
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

View File

@@ -41,6 +41,8 @@ local ENERGY_THIEF_LOOKUP = constants.ENERGY_THIEF_LOOKUP
-- imported functions
local nextMap = mapUtils.nextMap
local distortPosition = mathUtils.distortPosition
local prepMap = upgrade.prepMap
@@ -561,6 +563,7 @@ local function onEnemyBaseBuild(event)
if not map then
return
end
map.activeSurface = true
local chunk = getChunkByPosition(map, entity.position)
if (chunk ~= -1) then
local base
@@ -758,6 +761,7 @@ local function onEntitySpawned(event)
return
end
if universe.buildingHiveTypeLookup[entity.name] then
map.activeSurface = true
local disPos = distortPosition(universe.random, entity.position, 8)
local chunk = getChunkByPosition(map, disPos)
@@ -800,11 +804,14 @@ local function onUnitGroupCreated(event)
if (group.force.name == "enemy") then
local surface = group.surface
local squad
if not group.is_script_driven then
if group.is_script_driven then
return
end
local map = universe.maps[surface.index]
if not map then
return
end
map.activeSurface = true
if not universe.aiNocturnalMode then
local settler = universe.random() < 0.25 and
canMigrate(map) and
@@ -870,16 +877,18 @@ local function onUnitGroupCreated(event)
end
end
end
end
end
local function onGroupFinishedGathering(event)
local group = event.group
if group.valid and (group.force.name == "enemy") then
if not group.valid or (group.force.name ~= "enemy") then
return
end
local map = universe.maps[group.surface.index]
if not map then
return
end
map.activeSurface = true
local squad = universe.groupNumberToSquad[group.group_number]
if squad then
if squad.settler then
@@ -926,7 +935,6 @@ local function onGroupFinishedGathering(event)
end
squadDispatch(map, squad, event.tick)
end
end
end
local function onForceCreated(event)
@@ -975,6 +983,7 @@ local function onBuilderArrived(event)
if not map then
return
end
map.activeSurface = true
local squad = universe.groupNumberToSquad[builder.group_number]
squad.commandTick = event.tick + COMMAND_TIMEOUT * 10
if universe.aiPointsPrintSpendingToChat then
@@ -995,11 +1004,11 @@ script.on_event(defines.events.on_tick,
local map = universe.activeMap
if (not map) or (universe.processedChunks > (#map.processQueue * 0.05)) then
universe.mapIterator, map = next(universe.maps, universe.mapIterator)
if not map then
universe.mapIterator, map = next(universe.maps, universe.mapIterator)
end
universe.processedChunks = 0
print("b", universe.mapIterator)
map = nextMap(universe)
print("a", universe.mapIterator)
print("----")
universe.activeMap = map
end

View File

@@ -38,6 +38,7 @@ function chunkPropertyUtils.getHiveCount(map, chunk)
end
function chunkPropertyUtils.addTurretCount(map, chunk, unitNumber)
map.activeSurface = true
if not map.chunkToTurretIds[chunk.id] then
map.chunkToTurretIds[chunk.id] = {}
end
@@ -59,6 +60,7 @@ function chunkPropertyUtils.removeTurretCount(map, chunk, unitNumber)
end
function chunkPropertyUtils.addTrapCount(map, chunk, unitNumber)
map.activeSurface = true
if not map.chunkToTrapIds[chunk.id] then
map.chunkToTrapIds[chunk.id] = {}
end
@@ -80,6 +82,7 @@ function chunkPropertyUtils.removeTrapCount(map, chunk, unitNumber)
end
function chunkPropertyUtils.addUtilitiesCount(map, chunk, unitNumber)
map.activeSurface = true
if not map.chunkToUtilityIds[chunk.id] then
map.chunkToUtilityIds[chunk.id] = {}
end
@@ -101,6 +104,7 @@ function chunkPropertyUtils.removeUtilitiesCount(map, chunk, unitNumber)
end
function chunkPropertyUtils.addHiveCount(map, chunk, unitNumber)
map.activeSurface = true
if not map.chunkToHiveIds[chunk.id] then
map.chunkToHiveIds[chunk.id] = {}
end
@@ -122,6 +126,7 @@ function chunkPropertyUtils.removeHiveCount(map, chunk, unitNumber)
end
function chunkPropertyUtils.addNestCount(map, chunk, unitNumber)
map.activeSurface = true
local chunkId = chunk.id
if not map.chunkToNestIds[chunkId] then
map.chunkToNestIds[chunkId] = {}

View File

@@ -65,6 +65,19 @@ function mapUtils.queueGeneratedChunk(universe, event)
universe.eventId = universe.eventId + 1
end
function mapUtils.nextMap(universe)
local mapIterator = universe.mapIterator
repeat
local map
universe.mapIterator, map = next(universe.maps, universe.mapIterator)
if map and map.activeSurface then
return map
elseif map and not map.activeSurface then
print("skipping", universe.mapIterator)
end
until mapIterator == universe.mapIterator
end
--[[
1 2 3
\|/