mirror of
https://github.com/veden/Rampant.git
synced 2025-02-05 13:14:51 +02:00
uniform squad processing
This commit is contained in:
parent
15c140b728
commit
926ef9e383
11
Upgrade.lua
11
Upgrade.lua
@ -419,10 +419,15 @@ function upgrade.attempt(universe)
|
||||
|
||||
addCommandSet(universe)
|
||||
universe.eventId = 0
|
||||
universe.chunkId = 0
|
||||
universe.randomGenerator = nil
|
||||
universe.random = game.create_random_generator(settings.startup["rampant--enemySeed"].value+game.default_map_gen_settings.seed)
|
||||
game.forces.enemy.kill_all_units()
|
||||
universe.maps = {}
|
||||
universe.groupNumberToSquad = {}
|
||||
universe.deployVengenceIterator = nil
|
||||
universe.squadIterator = nil
|
||||
universe.vengenceQueue = {}
|
||||
universe.activeMap = nil
|
||||
universe.mapIterator = nil
|
||||
universe.builderCount = 0
|
||||
@ -461,7 +466,6 @@ function upgrade.prepMap(universe, surface)
|
||||
universe.maps[surfaceIndex] = map
|
||||
|
||||
map.eventId = 1
|
||||
map.chunkId = 1
|
||||
map.maxAggressiveGroups = 1
|
||||
map.sentAggressiveGroups = 0
|
||||
map.processedChunks = 0
|
||||
@ -512,9 +516,6 @@ function upgrade.prepMap(universe, surface)
|
||||
|
||||
map.chunkToPassScanIterator = nil
|
||||
map.pendingUpgradeIterator = nil
|
||||
map.squadIterator = nil
|
||||
map.regroupIterator = nil
|
||||
map.deployVengenceIterator = nil
|
||||
map.recycleBaseIterator = nil
|
||||
map.processActiveSpawnerIterator = nil
|
||||
map.processActiveRaidSpawnerIterator = nil
|
||||
@ -533,7 +534,6 @@ function upgrade.prepMap(universe, surface)
|
||||
map.surface = surface
|
||||
map.universe = universe
|
||||
|
||||
map.vengenceQueue = {}
|
||||
map.bases = {}
|
||||
map.baseIndex = 1
|
||||
map.baseIncrement = 0
|
||||
@ -547,7 +547,6 @@ function upgrade.prepMap(universe, surface)
|
||||
map.evolutionLevel = game.forces.enemy.evolution_factor
|
||||
map.canAttackTick = 0
|
||||
map.drainPylons = {}
|
||||
map.groupNumberToSquad = {}
|
||||
map.activeRaidNests = 0
|
||||
map.activeNests = 0
|
||||
map.destroyPlayerBuildings = 0
|
||||
|
@ -15,6 +15,7 @@ Date: 23. 11. 2021
|
||||
- Optimized energy thief faction
|
||||
- Factorissimo, Space Exploration Orbits, asteroid belts, secret maps, starmap, AAI-signal, NiceFill, Blueprint lab surfaces are no longer processed
|
||||
- Map processing around player now changes to the surface the player is standing on
|
||||
- Squads now get processed regardless of the current active surface being processed
|
||||
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
|
||||
|
24
control.lua
24
control.lua
@ -369,7 +369,7 @@ local function onDeath(event)
|
||||
local group = entity.unit_group
|
||||
if group then
|
||||
local damageType = event.damage_type
|
||||
local squad = map.groupNumberToSquad[group.group_number]
|
||||
local squad = universe.groupNumberToSquad[group.group_number]
|
||||
if damageType and squad then
|
||||
local base = squad.base
|
||||
if base then
|
||||
@ -795,8 +795,8 @@ local function onUnitGroupCreated(event)
|
||||
return
|
||||
end
|
||||
|
||||
squad = createSquad(nil, nil, group, settler)
|
||||
map.groupNumberToSquad[group.group_number] = squad
|
||||
squad = createSquad(nil, map, group, settler)
|
||||
universe.groupNumberToSquad[group.group_number] = squad
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
local chunk = getChunkByPosition(map, group.position)
|
||||
@ -829,8 +829,8 @@ local function onUnitGroupCreated(event)
|
||||
return
|
||||
end
|
||||
|
||||
squad = createSquad(nil, nil, group, settler)
|
||||
map.groupNumberToSquad[group.group_number] = squad
|
||||
squad = createSquad(nil, map, group, settler)
|
||||
universe.groupNumberToSquad[group.group_number] = squad
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
local chunk = getChunkByPosition(group.position)
|
||||
@ -856,7 +856,7 @@ local function onGroupFinishedGathering(event)
|
||||
if not map then
|
||||
return
|
||||
end
|
||||
local squad = map.groupNumberToSquad[group.group_number]
|
||||
local squad = universe.groupNumberToSquad[group.group_number]
|
||||
if squad then
|
||||
if squad.settler then
|
||||
if (universe.builderCount < universe.AI_MAX_BUILDER_COUNT) then
|
||||
@ -893,8 +893,8 @@ local function onGroupFinishedGathering(event)
|
||||
return
|
||||
end
|
||||
|
||||
squad = createSquad(nil, nil, group, settler)
|
||||
map.groupNumberToSquad[group.group_number] = squad
|
||||
squad = createSquad(nil, map, group, settler)
|
||||
universe.groupNumberToSquad[group.group_number] = squad
|
||||
if settler then
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
else
|
||||
@ -948,12 +948,12 @@ local function onBuilderArrived(event)
|
||||
if not map then
|
||||
return
|
||||
end
|
||||
local squad = map.groupNumberToSquad[builder.group_number]
|
||||
local squad = universe.groupNumberToSquad[builder.group_number]
|
||||
squad.commandTick = event.tick + COMMAND_TIMEOUT * 10
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print("Settled: [gps=" .. targetPosition.x .. "," .. targetPosition.y .."]")
|
||||
end
|
||||
builder.surface.create_entity(universe.createBuildCloudQuery)
|
||||
map.surface.create_entity(universe.createBuildCloudQuery)
|
||||
end
|
||||
|
||||
-- hooks
|
||||
@ -990,7 +990,7 @@ script.on_event(defines.events.on_tick,
|
||||
elseif (pick == 3) then
|
||||
processStaticMap(map)
|
||||
disperseVictoryScent(map)
|
||||
processVengence(map)
|
||||
processVengence(universe)
|
||||
elseif (pick == 4) then
|
||||
scanResourceMap(map, tick)
|
||||
scanEnemyMap(map, tick)
|
||||
@ -1009,7 +1009,7 @@ script.on_event(defines.events.on_tick,
|
||||
processActiveNests(map, tick)
|
||||
processPendingUpgrades(map, tick)
|
||||
processPendingUpgrades(map, tick)
|
||||
cleanSquads(map, tick)
|
||||
cleanSquads(universe, tick)
|
||||
|
||||
-- game.print({"", "--dispatch4 ", profiler, ", ", pick, ", ", game.tick, " ", universe.random()})
|
||||
end)
|
||||
|
@ -169,18 +169,21 @@ function aiAttackWave.rallyUnits(chunk, map, tick)
|
||||
local cX = chunk.x
|
||||
local cY = chunk.y
|
||||
local startX, endX, stepX, startY, endY, stepY = visitPattern(tick % 4, cX, cY, RALLY_CRY_DISTANCE)
|
||||
local vengenceQueue = map.vengenceQueue
|
||||
local vengenceQueue = map.universe.vengenceQueue
|
||||
for x=startX, endX, stepX do
|
||||
for y=startY, endY, stepY do
|
||||
if (x ~= cX) and (y ~= cY) then
|
||||
local rallyChunk = getChunkByXY(map, x, y)
|
||||
if (rallyChunk ~= -1) and (getNestCount(map, rallyChunk) > 0) then
|
||||
local count = vengenceQueue[rallyChunk.id]
|
||||
if not count then
|
||||
count = 0
|
||||
vengenceQueue[rallyChunk.id] = count
|
||||
local pack = vengenceQueue[rallyChunk.id]
|
||||
if not pack then
|
||||
pack = {
|
||||
v = 0,
|
||||
map = map
|
||||
}
|
||||
vengenceQueue[rallyChunk.id] = pack
|
||||
end
|
||||
vengenceQueue[rallyChunk.id] = count + 1
|
||||
pack.v = pack.v + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -221,7 +224,7 @@ function aiAttackWave.formSettlers(map, chunk)
|
||||
4,
|
||||
true)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface, nil, true)
|
||||
local squad = createSquad(squadPosition, map, nil, true)
|
||||
|
||||
squad.maxDistance = gaussianRandomRangeRG(universe.expansionMaxDistance * 0.5,
|
||||
universe.expansionMaxDistanceDerivation,
|
||||
@ -243,7 +246,7 @@ function aiAttackWave.formSettlers(map, chunk)
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_SETTLER_COST .. ". [Settler] Total: " .. string.format("%.2f", map.points) .. " [gps=" .. squadPosition.x .. "," .. squadPosition.y .. "]")
|
||||
end
|
||||
map.groupNumberToSquad[squad.groupNumber] = squad
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
squad.group.destroy()
|
||||
@ -275,7 +278,7 @@ function aiAttackWave.formVengenceSquad(map, chunk)
|
||||
4,
|
||||
true)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface)
|
||||
local squad = createSquad(squadPosition, map)
|
||||
|
||||
squad.rabid = map.random() < 0.03
|
||||
|
||||
@ -288,7 +291,7 @@ function aiAttackWave.formVengenceSquad(map, chunk)
|
||||
squad.base = findNearbyBase(map, chunk)
|
||||
end
|
||||
squad.kamikaze = map.random() < calculateKamikazeThreshold(foundUnits, universe)
|
||||
map.groupNumberToSquad[squad.groupNumber] = squad
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
map.points = map.points - AI_VENGENCE_SQUAD_COST
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
@ -326,7 +329,7 @@ function aiAttackWave.formSquads(map, chunk)
|
||||
4,
|
||||
true)
|
||||
if squadPosition then
|
||||
local squad = createSquad(squadPosition, surface)
|
||||
local squad = createSquad(squadPosition, map)
|
||||
|
||||
squad.rabid = map.random() < 0.03
|
||||
|
||||
@ -341,7 +344,7 @@ function aiAttackWave.formSquads(map, chunk)
|
||||
squad.kamikaze = map.random() < calculateKamikazeThreshold(foundUnits, universe)
|
||||
map.points = map.points - AI_SQUAD_COST
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
map.groupNumberToSquad[squad.groupNumber] = squad
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
if (map.state == AI_STATE_AGGRESSIVE) then
|
||||
map.sentAggressiveGroups = map.sentAggressiveGroups + 1
|
||||
end
|
||||
|
@ -356,9 +356,9 @@ function chunkUtils.entityForPassScan(map, entity)
|
||||
end
|
||||
end
|
||||
|
||||
function chunkUtils.newChunkId(map)
|
||||
local id = map.chunkId
|
||||
map.chunkId = map.chunkId + 1
|
||||
local function newChunkId(universe)
|
||||
local id = universe.chunkId
|
||||
universe.chunkId = universe.chunkId + 1
|
||||
return id
|
||||
end
|
||||
|
||||
@ -367,7 +367,7 @@ function chunkUtils.createChunk(map, topX, topY)
|
||||
x = topX,
|
||||
y = topY,
|
||||
dOrigin = euclideanDistancePoints(topX, topY, 0, 0),
|
||||
id = chunkUtils.newChunkId(map)
|
||||
id = newChunkId(map.universe)
|
||||
}
|
||||
chunk[BASE_PHEROMONE] = 0
|
||||
chunk[PLAYER_PHEROMONE] = 0
|
||||
|
@ -254,7 +254,15 @@ function mapProcessor.processPlayers(players, universe, tick)
|
||||
queueNestSpawners(map, chunk, tick)
|
||||
|
||||
if vengence then
|
||||
map.vengenceQueue[chunk.id] = (map.vengenceQueue[chunk.id] or 0) + 1
|
||||
local pack = universe.vengenceQueue[chunk.id]
|
||||
if not pack then
|
||||
pack = {
|
||||
v = 0,
|
||||
map = map
|
||||
}
|
||||
universe.vengenceQueue[chunk.id] = pack
|
||||
end
|
||||
pack.v = pack.v + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -453,21 +461,24 @@ function mapProcessor.processActiveNests(map, tick)
|
||||
end
|
||||
end
|
||||
|
||||
function mapProcessor.processVengence(map)
|
||||
local vengence = map.vengenceQueue
|
||||
local chunkId = map.deployVengenceIterator
|
||||
function mapProcessor.processVengence(universe)
|
||||
local vengenceQueue = universe.vengenceQueue
|
||||
local chunkId = universe.deployVengenceIterator
|
||||
local vengencePack
|
||||
if not chunkId then
|
||||
chunkId = next(vengence, nil)
|
||||
chunkId, vengencePack = next(vengenceQueue, nil)
|
||||
else
|
||||
vengencePack = vengenceQueue[chunkId]
|
||||
end
|
||||
if not chunkId then
|
||||
map.deployVengenceIterator = nil
|
||||
if (tableSize(vengence) == 0) then
|
||||
map.vengenceQueue = {}
|
||||
universe.deployVengenceIterator = nil
|
||||
if (tableSize(vengenceQueue) == 0) then
|
||||
universe.vengenceQueue = {}
|
||||
end
|
||||
else
|
||||
map.deployVengenceIterator = next(vengence, chunkId)
|
||||
formVengenceSquad(map, getChunkById(map, chunkId))
|
||||
vengence[chunkId] = nil
|
||||
universe.deployVengenceIterator = next(vengenceQueue, chunkId)
|
||||
formVengenceSquad(vengencePack.map, getChunkById(vengencePack.map, chunkId))
|
||||
vengenceQueue[chunkId] = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -330,9 +330,9 @@ local function buildMove(map, squad)
|
||||
group.set_command(universe.compoundSettleCommand)
|
||||
end
|
||||
|
||||
function squadAttack.cleanSquads(map, tick)
|
||||
local squads = map.groupNumberToSquad
|
||||
local groupId = map.squadIterator
|
||||
function squadAttack.cleanSquads(universe, tick)
|
||||
local squads = universe.groupNumberToSquad
|
||||
local groupId = universe.squadIterator
|
||||
local squad
|
||||
if not groupId then
|
||||
groupId, squad = next(squads, groupId)
|
||||
@ -340,23 +340,19 @@ function squadAttack.cleanSquads(map, tick)
|
||||
squad = squads[groupId]
|
||||
end
|
||||
if not groupId then
|
||||
map.squadIterator = nil
|
||||
universe.squadIterator = nil
|
||||
if (table_size(squads) == 0) then
|
||||
-- this is needed as the next command remembers the max length a table has been
|
||||
map.groupNumberToSquad = {}
|
||||
universe.groupNumberToSquad = {}
|
||||
end
|
||||
else
|
||||
map.squadIterator = next(squads, groupId)
|
||||
universe.squadIterator = next(squads, groupId)
|
||||
local group = squad.group
|
||||
if not group.valid then
|
||||
if squad.chunk ~= -1 then
|
||||
addDeathGenerator(map, squad.chunk, FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT)
|
||||
addDeathGenerator(squad.map, squad.chunk, FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT)
|
||||
end
|
||||
removeSquadFromChunk(map, squad)
|
||||
if (map.regroupIterator == groupId) then
|
||||
map.regroupIterator = nil
|
||||
end
|
||||
local universe = map.universe
|
||||
removeSquadFromChunk(squad.map, squad)
|
||||
if squad.settlers then
|
||||
universe.builderCount = universe.builderCount - 1
|
||||
else
|
||||
@ -365,13 +361,13 @@ function squadAttack.cleanSquads(map, tick)
|
||||
squads[groupId] = nil
|
||||
elseif (group.state == 4) then
|
||||
squad.wanders = 0
|
||||
squadAttack.squadDispatch(map, squad, tick)
|
||||
squadAttack.squadDispatch(squad.map, squad, tick)
|
||||
elseif (squad.commandTick and (squad.commandTick < tick)) then
|
||||
if squad.wanders > 5 then
|
||||
squad.group.destroy()
|
||||
else
|
||||
squad.wanders = squad.wanders + 1
|
||||
local cmd = map.universe.wander2Command
|
||||
local cmd = universe.wander2Command
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
group.set_command(cmd)
|
||||
group.start_moving()
|
||||
|
@ -94,7 +94,7 @@ function aiDefense.retreatUnits(chunk, cause, map, tick, radius)
|
||||
if not newSquad then
|
||||
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) then
|
||||
created = true
|
||||
newSquad = createSquad(position, surface)
|
||||
newSquad = createSquad(position, map)
|
||||
else
|
||||
return
|
||||
end
|
||||
@ -118,7 +118,7 @@ function aiDefense.retreatUnits(chunk, cause, map, tick, radius)
|
||||
if universe.NEW_ENEMIES then
|
||||
newSquad.base = findNearbyBase(map, chunk)
|
||||
end
|
||||
map.groupNumberToSquad[newSquad.groupNumber] = newSquad
|
||||
universe.groupNumberToSquad[newSquad.groupNumber] = newSquad
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
end
|
||||
|
||||
|
@ -73,8 +73,8 @@ function unitGroupUtils.findNearbySquad(map, chunk)
|
||||
return nil
|
||||
end
|
||||
|
||||
function unitGroupUtils.createSquad(position, surface, group, settlers)
|
||||
local unitGroup = group or surface.create_unit_group({position=position})
|
||||
function unitGroupUtils.createSquad(position, map, group, settlers)
|
||||
local unitGroup = group or map.surface.create_unit_group({position=position})
|
||||
|
||||
local squad = {
|
||||
group = unitGroup,
|
||||
@ -83,6 +83,7 @@ function unitGroupUtils.createSquad(position, surface, group, settlers)
|
||||
penalties = {},
|
||||
base = nil,
|
||||
frenzy = false,
|
||||
map = map,
|
||||
wanders = 0,
|
||||
settlers = settlers or false,
|
||||
kamikaze = false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user