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:
parent
903e4b49d0
commit
0207aa0fe4
@ -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
|
||||
|
@ -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
|
||||
|
219
control.lua
219
control.lua
@ -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,110 +804,15 @@ local function onUnitGroupCreated(event)
|
||||
if (group.force.name == "enemy") then
|
||||
local surface = group.surface
|
||||
local squad
|
||||
if not group.is_script_driven then
|
||||
local map = universe.maps[surface.index]
|
||||
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
|
||||
if group.is_script_driven then
|
||||
return
|
||||
end
|
||||
end
|
||||
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]
|
||||
local map = universe.maps[surface.index]
|
||||
if not map then
|
||||
return
|
||||
end
|
||||
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
|
||||
map.activeSurface = true
|
||||
if not universe.aiNocturnalMode then
|
||||
local settler = universe.random() < 0.25 and
|
||||
canMigrate(map) and
|
||||
(universe.builderCount < universe.AI_MAX_BUILDER_COUNT)
|
||||
@ -919,16 +828,115 @@ local function onGroupFinishedGathering(event)
|
||||
|
||||
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
|
||||
squadDispatch(map, squad, event.tick)
|
||||
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)
|
||||
universe.playerForces[#universe.playerForces+1] = event.force.name
|
||||
end
|
||||
@ -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
|
||||
|
||||
|
@ -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] = {}
|
||||
|
@ -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
|
||||
\|/
|
||||
|
Loading…
x
Reference in New Issue
Block a user