1
0
mirror of https://github.com/veden/Rampant.git synced 2025-02-05 13:14:51 +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
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
5 changed files with 135 additions and 105 deletions

View File

@ -495,6 +495,8 @@ function upgrade.prepMap(universe, surface)
local map = {} local map = {}
universe.maps[surfaceIndex] = map universe.maps[surfaceIndex] = map
map.activatedMap = false
map.maxAggressiveGroups = 1 map.maxAggressiveGroups = 1
map.sentAggressiveGroups = 0 map.sentAggressiveGroups = 0
map.processedChunks = 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 - AI Planning will now happen on upto 15 surface per cycle
- Spawners not covered by pollution are now processed regardless of current active map - Spawners not covered by pollution are now processed regardless of current active map
- Attack waves are 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: Tweaks:
- Increase chance to upgrade an enemy structure from 5% to 30% - 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 - 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 -- imported functions
local nextMap = mapUtils.nextMap
local distortPosition = mathUtils.distortPosition local distortPosition = mathUtils.distortPosition
local prepMap = upgrade.prepMap local prepMap = upgrade.prepMap
@ -561,6 +563,7 @@ local function onEnemyBaseBuild(event)
if not map then if not map then
return return
end end
map.activeSurface = true
local chunk = getChunkByPosition(map, entity.position) local chunk = getChunkByPosition(map, entity.position)
if (chunk ~= -1) then if (chunk ~= -1) then
local base local base
@ -758,6 +761,7 @@ local function onEntitySpawned(event)
return return
end end
if universe.buildingHiveTypeLookup[entity.name] then if universe.buildingHiveTypeLookup[entity.name] then
map.activeSurface = true
local disPos = distortPosition(universe.random, entity.position, 8) local disPos = distortPosition(universe.random, entity.position, 8)
local chunk = getChunkByPosition(map, disPos) local chunk = getChunkByPosition(map, disPos)
@ -800,110 +804,15 @@ local function onUnitGroupCreated(event)
if (group.force.name == "enemy") then if (group.force.name == "enemy") then
local surface = group.surface local surface = group.surface
local squad local squad
if not group.is_script_driven then if group.is_script_driven then
local map = universe.maps[surface.index] return
if not map then
return
end
if not universe.aiNocturnalMode then
local settler = universe.random() < 0.25 and
canMigrate(map) and
(universe.builderCount < universe.AI_MAX_BUILDER_COUNT)
if not settler and universe.squadCount > universe.AI_MAX_SQUAD_COUNT then
group.destroy()
map.points = map.points + AI_SQUAD_COST
if universe.aiPointsPrintGainsToChat then
game.print(map.surface.name .. ": Points: +" .. AI_SQUAD_COST .. ". [Squad Refund] Total: " .. string.format("%.2f", map.points))
end
return
end
squad = createSquad(nil, map, group, settler)
universe.groupNumberToSquad[group.group_number] = squad
if universe.NEW_ENEMIES then
local chunk = getChunkByPosition(map, group.position)
if (chunk ~= -1) then
squad.base = findNearbyBase(map, chunk)
end
end
if settler then
universe.builderCount = universe.builderCount + 1
else
universe.squadCount = universe.squadCount + 1
end
else
if not (surface.darkness > 0.65) then
group.destroy()
return
end
local settler = universe.random() < 0.25 and
canMigrate(map) and
(universe.builderCount < universe.AI_MAX_BUILDER_COUNT)
if not settler and universe.squadCount > universe.AI_MAX_SQUAD_COUNT then
group.destroy()
map.points = map.points + AI_SQUAD_COST
if universe.aiPointsPrintGainsToChat then
game.print(map.surface.name .. ": Points: +" .. AI_SQUAD_COST .. ". [Squad Refund] Total: " .. string.format("%.2f", map.points))
end
return
end
squad = createSquad(nil, map, group, settler)
universe.groupNumberToSquad[group.group_number] = squad
if universe.NEW_ENEMIES then
local chunk = getChunkByPosition(group.position)
if (chunk ~= -1) then
squad.base = findNearbyBase(map, chunk)
end
end
if settler then
universe.builderCount = universe.builderCount + 1
else
universe.squadCount = universe.squadCount + 1
end
end
end end
end local map = universe.maps[surface.index]
end
local function onGroupFinishedGathering(event)
local group = event.group
if group.valid and (group.force.name == "enemy") then
local map = universe.maps[group.surface.index]
if not map then if not map then
return return
end end
local squad = universe.groupNumberToSquad[group.group_number] map.activeSurface = true
if squad then if not universe.aiNocturnalMode then
if squad.settler then
if (universe.builderCount < universe.AI_MAX_BUILDER_COUNT) then
squadDispatch(map, squad, event.tick)
else
group.destroy()
map.points = map.points + AI_SETTLER_COST
if universe.aiPointsPrintGainsToChat then
game.print(map.surface.name .. ": Points: +" .. AI_SETTLER_COST .. ". [Settler Refund] Total: " .. string.format("%.2f", map.points))
end
end
else
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) then
squadDispatch(map, squad, event.tick)
else
group.destroy()
map.points = map.points + AI_SQUAD_COST
if universe.aiPointsPrintGainsToChat then
game.print(map.surface.name .. ": Points: +" .. AI_SQUAD_COST .. ". [Squad Refund] Total: " .. string.format("%.2f", map.points))
end
end
end
else
local settler = universe.random() < 0.25 and local settler = universe.random() < 0.25 and
canMigrate(map) and canMigrate(map) and
(universe.builderCount < universe.AI_MAX_BUILDER_COUNT) (universe.builderCount < universe.AI_MAX_BUILDER_COUNT)
@ -919,16 +828,115 @@ local function onGroupFinishedGathering(event)
squad = createSquad(nil, map, group, settler) squad = createSquad(nil, map, group, settler)
universe.groupNumberToSquad[group.group_number] = squad universe.groupNumberToSquad[group.group_number] = squad
if universe.NEW_ENEMIES then
local chunk = getChunkByPosition(map, group.position)
if (chunk ~= -1) then
squad.base = findNearbyBase(map, chunk)
end
end
if settler then
universe.builderCount = universe.builderCount + 1
else
universe.squadCount = universe.squadCount + 1
end
else
if not (surface.darkness > 0.65) then
group.destroy()
return
end
local settler = universe.random() < 0.25 and
canMigrate(map) and
(universe.builderCount < universe.AI_MAX_BUILDER_COUNT)
if not settler and universe.squadCount > universe.AI_MAX_SQUAD_COUNT then
group.destroy()
map.points = map.points + AI_SQUAD_COST
if universe.aiPointsPrintGainsToChat then
game.print(map.surface.name .. ": Points: +" .. AI_SQUAD_COST .. ". [Squad Refund] Total: " .. string.format("%.2f", map.points))
end
return
end
squad = createSquad(nil, map, group, settler)
universe.groupNumberToSquad[group.group_number] = squad
if universe.NEW_ENEMIES then
local chunk = getChunkByPosition(group.position)
if (chunk ~= -1) then
squad.base = findNearbyBase(map, chunk)
end
end
if settler then if settler then
universe.builderCount = universe.builderCount + 1 universe.builderCount = universe.builderCount + 1
else else
universe.squadCount = universe.squadCount + 1 universe.squadCount = universe.squadCount + 1
end end
squadDispatch(map, squad, event.tick)
end end
end end
end end
local function onGroupFinishedGathering(event)
local group = event.group
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
if (universe.builderCount < universe.AI_MAX_BUILDER_COUNT) then
squadDispatch(map, squad, event.tick)
else
group.destroy()
map.points = map.points + AI_SETTLER_COST
if universe.aiPointsPrintGainsToChat then
game.print(map.surface.name .. ": Points: +" .. AI_SETTLER_COST .. ". [Settler Refund] Total: " .. string.format("%.2f", map.points))
end
end
else
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) then
squadDispatch(map, squad, event.tick)
else
group.destroy()
map.points = map.points + AI_SQUAD_COST
if universe.aiPointsPrintGainsToChat then
game.print(map.surface.name .. ": Points: +" .. AI_SQUAD_COST .. ". [Squad Refund] Total: " .. string.format("%.2f", map.points))
end
end
end
else
local settler = universe.random() < 0.25 and
canMigrate(map) and
(universe.builderCount < universe.AI_MAX_BUILDER_COUNT)
if not settler and universe.squadCount > universe.AI_MAX_SQUAD_COUNT then
group.destroy()
map.points = map.points + AI_SQUAD_COST
if universe.aiPointsPrintGainsToChat then
game.print(map.surface.name .. ": Points: +" .. AI_SQUAD_COST .. ". [Squad Refund] Total: " .. string.format("%.2f", map.points))
end
return
end
squad = createSquad(nil, map, group, settler)
universe.groupNumberToSquad[group.group_number] = squad
if settler then
universe.builderCount = universe.builderCount + 1
else
universe.squadCount = universe.squadCount + 1
end
squadDispatch(map, squad, event.tick)
end
end
local function onForceCreated(event) local function onForceCreated(event)
universe.playerForces[#universe.playerForces+1] = event.force.name universe.playerForces[#universe.playerForces+1] = event.force.name
end end
@ -975,6 +983,7 @@ local function onBuilderArrived(event)
if not map then if not map then
return return
end end
map.activeSurface = true
local squad = universe.groupNumberToSquad[builder.group_number] local squad = universe.groupNumberToSquad[builder.group_number]
squad.commandTick = event.tick + COMMAND_TIMEOUT * 10 squad.commandTick = event.tick + COMMAND_TIMEOUT * 10
if universe.aiPointsPrintSpendingToChat then if universe.aiPointsPrintSpendingToChat then
@ -995,11 +1004,11 @@ script.on_event(defines.events.on_tick,
local map = universe.activeMap local map = universe.activeMap
if (not map) or (universe.processedChunks > (#map.processQueue * 0.05)) then 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 universe.processedChunks = 0
print("b", universe.mapIterator)
map = nextMap(universe)
print("a", universe.mapIterator)
print("----")
universe.activeMap = map universe.activeMap = map
end end

View File

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

View File

@ -65,6 +65,19 @@ function mapUtils.queueGeneratedChunk(universe, event)
universe.eventId = universe.eventId + 1 universe.eventId = universe.eventId + 1
end 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 1 2 3
\|/ \|/