mirror of
https://github.com/veden/Rampant.git
synced 2024-12-26 20:54:12 +02:00
FACTO-59: partial work towards independent bases
This commit is contained in:
parent
728b104f5e
commit
597b20b9e5
24
Upgrade.lua
24
Upgrade.lua
@ -572,10 +572,6 @@ function upgrade.attempt(universe)
|
||||
universe.maps[mapId] = nil
|
||||
end
|
||||
end
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
addBasesToAllEnemyStructures(universe, game.tick)
|
||||
end
|
||||
end
|
||||
if global.version < 208 then
|
||||
global.version = 208
|
||||
@ -612,6 +608,22 @@ function upgrade.attempt(universe)
|
||||
|
||||
universe.proxyEntityLookup = {}
|
||||
universe.vanillaEntityLookups = {}
|
||||
end
|
||||
if global.version < 210 then
|
||||
global.version = 210
|
||||
|
||||
addBasesToAllEnemyStructures(universe, game.tick)
|
||||
|
||||
local evoToTierMapping = {}
|
||||
universe.evoToTierMapping = evoToTierMapping
|
||||
|
||||
for i=1,10 do
|
||||
evoToTierMapping[#evoToTierMapping+1] = (((i - 1) * 0.1) ^ 0.5) - 0.05
|
||||
end
|
||||
|
||||
for chunkId in pairs(universe.vengenceQueue) do
|
||||
universe.vengenceQueue[chunkId] = nil
|
||||
end
|
||||
|
||||
game.print("Rampant - Version 2.3.0")
|
||||
end
|
||||
@ -685,8 +697,8 @@ function upgrade.prepMap(universe, surface)
|
||||
|
||||
map.bases = {}
|
||||
map.baseIndex = 1
|
||||
map.baseIncrement = 0
|
||||
map.points = 0
|
||||
-- map.baseIncrement = 0
|
||||
-- map.points = 0
|
||||
map.state = constants.AI_STATE_PEACEFUL
|
||||
map.squads = nil
|
||||
map.pendingAttack = nil
|
||||
|
63
control.lua
63
control.lua
@ -157,15 +157,19 @@ local function onIonCannonFired(event)
|
||||
if not map then
|
||||
return
|
||||
end
|
||||
map.ionCannonBlasts = map.ionCannonBlasts + 1
|
||||
map.points = map.points + 4000
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. 4000 .. ". [Ion Cannon] Total: " .. string.format("%.2f", map.points))
|
||||
end
|
||||
|
||||
local chunk = getChunkByPosition(map, event.position)
|
||||
if (chunk ~= -1) then
|
||||
rallyUnits(chunk, map, event.tick)
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if base then
|
||||
base.ionCannonBlasts = base.ionCannonBlasts + 1
|
||||
rallyUnits(chunk, map, event.tick, base)
|
||||
base.unitPoints = base.unitPoints + 4000
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. 4000 .. ". [Ion Cannon] Total: " ..
|
||||
string.format("%.2f", base.points))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -274,7 +278,6 @@ local function onConfigChanged()
|
||||
|
||||
universe["ENEMY_SEED"] = settings.startup["rampant--enemySeed"].value
|
||||
universe["ENEMY_VARIATIONS"] = settings.startup["rampant--newEnemyVariations"].value
|
||||
local usingNewEnemiesAlready = universe["NEW_ENEMIES"]
|
||||
universe["NEW_ENEMIES"] = settings.startup["rampant--newEnemies"].value
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
@ -313,9 +316,7 @@ local function onConfigChanged()
|
||||
prepMap(universe, surface)
|
||||
end
|
||||
end
|
||||
if (not usingNewEnemiesAlready) and universe.NEW_ENEMIES then
|
||||
addBasesToAllEnemyStructures(universe, game.tick)
|
||||
end
|
||||
end
|
||||
|
||||
local function onBuild(event)
|
||||
@ -405,10 +406,10 @@ local function onDeath(event)
|
||||
end
|
||||
|
||||
map.lostEnemyUnits = map.lostEnemyUnits + 1
|
||||
map.points = map.points - UNIT_DEATH_POINT_COST
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. UNIT_DEATH_POINT_COST .. ". [Unit Lost] Total: " .. string.format("%.2f", map.points))
|
||||
end
|
||||
-- map.points = map.points - UNIT_DEATH_POINT_COST
|
||||
-- if universe.aiPointsPrintSpendingToChat then
|
||||
-- game.print(map.surface.name .. ": Points: -" .. UNIT_DEATH_POINT_COST .. ". [Unit Lost] Total: " .. string.format("%.2f", map.points))
|
||||
-- end
|
||||
|
||||
if (universe.random() < universe.rallyThreshold) and not surface.peaceful_mode then
|
||||
rallyUnits(chunk, map, tick)
|
||||
@ -420,21 +421,23 @@ local function onDeath(event)
|
||||
else
|
||||
if event.force and (event.force.name ~= "enemy") then
|
||||
local rally = false
|
||||
if (chunk ~= -1) then
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if (entityType == "unit-spawner") then
|
||||
map.points = map.points + RECOVER_NEST_COST
|
||||
base.points = base.points + RECOVER_NEST_COST
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. RECOVER_NEST_COST .. ". [Nest Lost] Total: " .. string.format("%.2f", map.points))
|
||||
game.print(map.surface.name .. ": Points: +" .. RECOVER_NEST_COST .. ". [Nest Lost] Total: " .. string.format("%.2f", base.points))
|
||||
end
|
||||
rally = true
|
||||
elseif (entityType == "turret") then
|
||||
map.points = map.points + RECOVER_WORM_COST
|
||||
base.points = base.points + RECOVER_WORM_COST
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. RECOVER_WORM_COST .. ". [Worm Lost] Total: " .. string.format("%.2f", map.points))
|
||||
game.print(map.surface.name .. ": Points: +" .. RECOVER_WORM_COST .. ". [Worm Lost] Total: " .. string.format("%.2f", base.points))
|
||||
end
|
||||
rally = true
|
||||
end
|
||||
if (chunk ~= -1) and rally then
|
||||
rallyUnits(chunk, map, tick)
|
||||
if rally then
|
||||
rallyUnits(chunk, map, tick, base)
|
||||
|
||||
if cause and cause.valid then
|
||||
retreatUnits(chunk,
|
||||
@ -445,6 +448,7 @@ local function onDeath(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if universe.buildingHiveTypeLookup[entity.name] or
|
||||
(entityType == "unit-spawner") or
|
||||
@ -486,9 +490,7 @@ local function onEnemyBaseBuild(event)
|
||||
map.activeSurface = true
|
||||
local chunk = getChunkByPosition(map, entity.position)
|
||||
if (chunk ~= -1) then
|
||||
local base
|
||||
if universe.NEW_ENEMIES then
|
||||
base = findNearbyBase(map, chunk)
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if not base then
|
||||
base = createBase(map,
|
||||
chunk,
|
||||
@ -497,6 +499,7 @@ local function onEnemyBaseBuild(event)
|
||||
|
||||
registerEnemyBaseStructure(map, entity, event.tick, base)
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
upgradeEntity(entity,
|
||||
base,
|
||||
map,
|
||||
@ -620,10 +623,14 @@ local function onRocketLaunch(event)
|
||||
if not map then
|
||||
return
|
||||
end
|
||||
map.rocketLaunched = map.rocketLaunched + 1
|
||||
map.points = map.points + 5000
|
||||
local chunk = getChunkByPosition(entity.position)
|
||||
if (chunk ~= -1) then
|
||||
local base = findNearbyBase(map, chunk)
|
||||
base.rocketLaunched = base.rocketLaunched + 1
|
||||
base.points = base.points + 5000
|
||||
if universe.aiPointsPrintGainsToChat then
|
||||
game.print(map.surface.name .. ": Points: +" .. 5000 .. ". [Rocket Launch] Total: " .. string.format("%.2f", map.points))
|
||||
game.print(map.surface.name .. ": Points: +" .. 5000 .. ". [Rocket Launch] Total: " .. string.format("%.2f", base.points))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -740,12 +747,10 @@ local function onUnitGroupCreated(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
|
||||
@ -774,12 +779,10 @@ local function onUnitGroupCreated(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
|
||||
@ -926,7 +929,7 @@ script.on_event(defines.events.on_tick,
|
||||
if (pick == 0) then
|
||||
processPendingChunks(universe, tick)
|
||||
processMapAIs(universe, gameRef.forces.enemy.evolution_factor, tick)
|
||||
if map and universe.NEW_ENEMIES then
|
||||
if map then
|
||||
recycleBases(map)
|
||||
end
|
||||
cleanUpMapTables(universe, tick)
|
||||
|
@ -97,9 +97,9 @@ local function attackWaveScaling(universe)
|
||||
universe.random))
|
||||
end
|
||||
|
||||
local function attackWaveValidCandidate(chunk, map)
|
||||
local function attackWaveValidCandidate(chunk, map, base)
|
||||
local isValid = getNestActiveness(map, chunk)
|
||||
if (map.state == AI_STATE_RAIDING) or (map.state == AI_STATE_SIEGE) or (map.state == AI_STATE_ONSLAUGHT) then
|
||||
if (base.state == AI_STATE_RAIDING) or (base.state == AI_STATE_SIEGE) or (base.state == AI_STATE_ONSLAUGHT) then
|
||||
isValid = isValid + getRaidNestActiveness(map, chunk)
|
||||
end
|
||||
return (isValid > 0)
|
||||
@ -177,8 +177,8 @@ local function visitPattern(o, cX, cY, distance)
|
||||
return startX, endX, stepX, startY, endY, stepY
|
||||
end
|
||||
|
||||
function aiAttackWave.rallyUnits(chunk, map, tick)
|
||||
if ((tick - getRallyTick(map, chunk) > COOLDOWN_RALLY) and (map.points >= AI_VENGENCE_SQUAD_COST)) then
|
||||
function aiAttackWave.rallyUnits(chunk, map, tick, base)
|
||||
if ((tick - getRallyTick(map, chunk) > COOLDOWN_RALLY) and (base.unitPoints >= AI_VENGENCE_SQUAD_COST)) then
|
||||
setRallyTick(map, chunk, tick)
|
||||
local cX = chunk.x
|
||||
local cY = chunk.y
|
||||
@ -193,7 +193,8 @@ function aiAttackWave.rallyUnits(chunk, map, tick)
|
||||
if not pack then
|
||||
pack = {
|
||||
v = 0,
|
||||
map = map
|
||||
map = map,
|
||||
base = base
|
||||
}
|
||||
vengenceQueue[rallyChunk.id] = pack
|
||||
end
|
||||
@ -207,11 +208,11 @@ function aiAttackWave.rallyUnits(chunk, map, tick)
|
||||
end
|
||||
end
|
||||
|
||||
function aiAttackWave.formSettlers(map, chunk)
|
||||
function aiAttackWave.formSettlers(map, chunk, base)
|
||||
local universe = map.universe
|
||||
if (universe.builderCount < universe.AI_MAX_BUILDER_COUNT) and
|
||||
(map.random() < universe.formSquadThreshold) and
|
||||
((map.points - AI_SETTLER_COST) > 0)
|
||||
((base.unitPoints - AI_SETTLER_COST) > 0)
|
||||
then
|
||||
local surface = map.surface
|
||||
local squadPath, squadDirection
|
||||
@ -244,23 +245,23 @@ function aiAttackWave.formSettlers(map, chunk)
|
||||
universe.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(universe.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
if (map.state == AI_STATE_SIEGE) then
|
||||
map.sentSiegeGroups = map.sentSiegeGroups + 1
|
||||
if (base.state == AI_STATE_SIEGE) then
|
||||
base.sentSiegeGroups = base.sentSiegeGroups + 1
|
||||
end
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
squad.base = findNearbyBase(map, chunk)
|
||||
end
|
||||
squad.base = base
|
||||
local kamikazeThreshold = calculateKamikazeSettlerThreshold(foundUnits, universe)
|
||||
if map.state == AI_STATE_SIEGE then
|
||||
if base.state == AI_STATE_SIEGE then
|
||||
kamikazeThreshold = kamikazeThreshold * 2.5
|
||||
end
|
||||
squad.kamikaze = map.random() < kamikazeThreshold
|
||||
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
map.points = map.points - AI_SETTLER_COST
|
||||
base.unitPoints = base.unitPoints - AI_SETTLER_COST
|
||||
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 .. "]")
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_SETTLER_COST .. ". [Settler] Total: " ..
|
||||
string.format("%.2f", base.unitPoints) .. " [gps=" .. squadPosition.x .. "," ..
|
||||
squadPosition.y .. "]")
|
||||
end
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
else
|
||||
@ -273,11 +274,11 @@ function aiAttackWave.formSettlers(map, chunk)
|
||||
end
|
||||
end
|
||||
|
||||
function aiAttackWave.formVengenceSquad(map, chunk)
|
||||
function aiAttackWave.formVengenceSquad(map, chunk, base)
|
||||
local universe = map.universe
|
||||
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) and
|
||||
(map.random() < universe.formSquadThreshold) and
|
||||
((map.points - AI_VENGENCE_SQUAD_COST) > 0)
|
||||
((base.unitPoints - AI_VENGENCE_SQUAD_COST) > 0)
|
||||
then
|
||||
local surface = map.surface
|
||||
local squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
@ -302,15 +303,14 @@ function aiAttackWave.formVengenceSquad(map, chunk)
|
||||
universe.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(universe.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
if universe.NEW_ENEMIES then
|
||||
squad.base = findNearbyBase(map, chunk)
|
||||
end
|
||||
squad.base = base
|
||||
squad.kamikaze = map.random() < calculateKamikazeSquadThreshold(foundUnits, universe)
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
map.points = map.points - AI_VENGENCE_SQUAD_COST
|
||||
base.unitPoints = base.unitPoints - AI_VENGENCE_SQUAD_COST
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_VENGENCE_SQUAD_COST .. ". [Vengence] Total: " .. string.format("%.2f", map.points) .. " [gps=" .. squadPosition.x .. "," .. squadPosition.y .. "]")
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_VENGENCE_SQUAD_COST .. ". [Vengence] Total: " ..
|
||||
string.format("%.2f", base.unitPoints) .. " [gps=" .. squadPosition.x .. "," .. squadPosition.y .. "]")
|
||||
end
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
@ -322,11 +322,11 @@ function aiAttackWave.formVengenceSquad(map, chunk)
|
||||
end
|
||||
end
|
||||
|
||||
function aiAttackWave.formVengenceSettler(map, chunk)
|
||||
function aiAttackWave.formVengenceSettler(map, chunk, base)
|
||||
local universe = map.universe
|
||||
if (universe.builderCount < universe.AI_MAX_BUILDER_COUNT) and
|
||||
(map.random() < universe.formSquadThreshold) and
|
||||
((map.points - AI_VENGENCE_SQUAD_COST) > 0)
|
||||
((base.unitPoints - AI_VENGENCE_SQUAD_COST) > 0)
|
||||
then
|
||||
local surface = map.surface
|
||||
local squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
@ -351,15 +351,14 @@ function aiAttackWave.formVengenceSettler(map, chunk)
|
||||
universe.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(universe.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
if universe.NEW_ENEMIES then
|
||||
squad.base = findNearbyBase(map, chunk)
|
||||
end
|
||||
squad.base = base
|
||||
squad.kamikaze = map.random() < calculateKamikazeSettlerThreshold(foundUnits, universe)
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
universe.builderCount = universe.builderCount + 1
|
||||
map.points = map.points - AI_VENGENCE_SQUAD_COST
|
||||
base.unitPoints = base.unitPoints - AI_VENGENCE_SQUAD_COST
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_VENGENCE_SQUAD_COST .. ". [Vengence Settlers] Total: " .. string.format("%.2f", map.points) .. " [gps=" .. squadPosition.x .. "," .. squadPosition.y .. "]")
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_VENGENCE_SQUAD_COST .. ". [Vengence Settlers] Total: " ..
|
||||
string.format("%.2f", base.unitPoints) .. " [gps=" .. squadPosition.x .. "," .. squadPosition.y .. "]")
|
||||
end
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
@ -371,12 +370,12 @@ function aiAttackWave.formVengenceSettler(map, chunk)
|
||||
end
|
||||
end
|
||||
|
||||
function aiAttackWave.formSquads(map, chunk)
|
||||
function aiAttackWave.formSquads(map, chunk, base)
|
||||
local universe = map.universe
|
||||
if (universe.squadCount < universe.AI_MAX_SQUAD_COUNT) and
|
||||
attackWaveValidCandidate(chunk, map) and
|
||||
attackWaveValidCandidate(chunk, map, base) and
|
||||
(map.random() < universe.formSquadThreshold) and
|
||||
((map.points - AI_SQUAD_COST) > 0)
|
||||
((base.unitPoints - AI_SQUAD_COST) > 0)
|
||||
then
|
||||
local surface = map.surface
|
||||
local squadPath, squadDirection = scoreNeighborsForFormation(getNeighborChunks(map, chunk.x, chunk.y),
|
||||
@ -401,22 +400,22 @@ function aiAttackWave.formSquads(map, chunk)
|
||||
universe.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(universe.formCommand)
|
||||
if (foundUnits > 0) then
|
||||
if (map.state == AI_STATE_SIEGE) then
|
||||
map.sentSiegeGroups = 0
|
||||
if (base.state == AI_STATE_SIEGE) then
|
||||
base.sentSiegeGroups = 0
|
||||
end
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
squad.base = findNearbyBase(map, chunk)
|
||||
end
|
||||
squad.base = base
|
||||
squad.kamikaze = map.random() < calculateKamikazeSquadThreshold(foundUnits, universe)
|
||||
map.points = map.points - AI_SQUAD_COST
|
||||
base.unitPoints = base.unitPoints - AI_SQUAD_COST
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
universe.groupNumberToSquad[squad.groupNumber] = squad
|
||||
if (map.state == AI_STATE_AGGRESSIVE) then
|
||||
map.sentAggressiveGroups = map.sentAggressiveGroups + 1
|
||||
if (base.state == AI_STATE_AGGRESSIVE) then
|
||||
base.sentAggressiveGroups = base.sentAggressiveGroups + 1
|
||||
end
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_SQUAD_COST .. ". [Squad] Total: " .. string.format("%.2f", map.points) .. " [gps=" .. squadPosition.x .. "," .. squadPosition.y .. "]")
|
||||
game.print(map.surface.name .. ": Points: -" .. AI_SQUAD_COST .. ". [Squad] Total: " ..
|
||||
string.format("%.2f", base.unitPoints) .. " [gps=" .. squadPosition.x .. "," ..
|
||||
squadPosition.y .. "]")
|
||||
end
|
||||
else
|
||||
if (squad.group.valid) then
|
||||
|
@ -98,6 +98,7 @@ local function planning(map, evolution_factor, tick)
|
||||
end
|
||||
|
||||
local maxOverflowPoints = maxPoints * 3
|
||||
universe.maxOverflowPoints = maxOverflowPoints
|
||||
|
||||
local attackWaveMaxSize = universe.attackWaveMaxSize
|
||||
universe.retreatThreshold = linearInterpolation(evolution_factor,
|
||||
|
@ -52,12 +52,15 @@ local BASE_DISTANCE_TO_EVO_INDEX = constants.BASE_DISTANCE_TO_EVO_INDEX
|
||||
|
||||
local CHUNK_SIZE = constants.CHUNK_SIZE
|
||||
|
||||
local BASE_PROCESS_INTERVAL = constants.BASE_PROCESS_INTERVAL
|
||||
|
||||
-- imported functions
|
||||
|
||||
local setPositionXYInQuery = queryUtils.setPositionXYInQuery
|
||||
|
||||
local randomTickEvent = mathUtils.randomTickEvent
|
||||
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
||||
local manhattenDistancePoints = mathUtils.manhattenDistancePoints
|
||||
|
||||
local getChunkByPosition = mapUtils.getChunkByPosition
|
||||
|
||||
@ -106,7 +109,7 @@ function baseUtils.findNearbyBase(map, chunk)
|
||||
local bases = map.bases
|
||||
local closest = MAGIC_MAXIMUM_NUMBER
|
||||
for _, base in pairs(bases) do
|
||||
local distance = euclideanDistancePoints(base.x, base.y, x, y)
|
||||
local distance = manhattenDistancePoints(base.x, base.y, x, y)
|
||||
if (distance <= base.distanceThreshold) and (distance < closest) then
|
||||
closest = distance
|
||||
foundBase = base
|
||||
@ -440,6 +443,10 @@ local function upgradeBaseBasedOnDamage(map, base)
|
||||
end
|
||||
|
||||
function baseUtils.processBase(chunk, map, tick, base)
|
||||
if ((tick - base.tick) <= BASE_PROCESS_INTERVAL) then
|
||||
return
|
||||
end
|
||||
|
||||
if not base.alignment[1] then
|
||||
return
|
||||
end
|
||||
@ -512,10 +519,14 @@ function baseUtils.processBase(chunk, map, tick, base)
|
||||
end
|
||||
|
||||
base.points = base.points + map.baseIncrement
|
||||
base.unitPoints = base.unitPoints + map.baseIncrement
|
||||
|
||||
if (base.points > universe.maxPoints) then
|
||||
base.points = universe.maxPoints
|
||||
end
|
||||
if (base.unitPoints > universe.maxPoints) then
|
||||
base.unitPoints = universe.unitPoints
|
||||
end
|
||||
|
||||
if (base.stateTick <= tick) then
|
||||
local roll = map.random()
|
||||
@ -570,6 +581,7 @@ function baseUtils.createBase(map, chunk, tick)
|
||||
chunkCount = 0,
|
||||
createdTick = tick,
|
||||
points = 0,
|
||||
unitPoints = 0,
|
||||
id = universe.baseId
|
||||
}
|
||||
universe.baseId = universe.baseId + 1
|
||||
@ -586,8 +598,6 @@ function baseUtils.rebuildNativeTables(universe, rg)
|
||||
universe.buildingSpaceLookup = buildingSpaceLookup
|
||||
local enemyAlignmentLookup = {}
|
||||
universe.enemyAlignmentLookup = enemyAlignmentLookup
|
||||
local evoToTierMapping = {}
|
||||
universe.evoToTierMapping = evoToTierMapping
|
||||
local upgradeLookup = {}
|
||||
universe.upgradeLookup = upgradeLookup
|
||||
local buildingEvolveLookup = {}
|
||||
@ -601,10 +611,6 @@ function baseUtils.rebuildNativeTables(universe, rg)
|
||||
local vanillaEntityLookups = {}
|
||||
universe.vanillaEntityTypeLookup = vanillaEntityLookups
|
||||
|
||||
for i=1,10 do
|
||||
evoToTierMapping[#evoToTierMapping+1] = (((i - 1) * 0.1) ^ 0.5) - 0.05
|
||||
end
|
||||
|
||||
buildingHiveTypeLookup["biter-spawner"] = "biter-spawner"
|
||||
buildingHiveTypeLookup["spitter-spawner"] = "spitter-spawner"
|
||||
buildingHiveTypeLookup["small-worm-turret"] = "turret"
|
||||
|
@ -245,12 +245,12 @@ function chunkUtils.initialScan(chunk, map, tick)
|
||||
end
|
||||
|
||||
if (#enemyBuildings > 0) then
|
||||
if universe.NEW_ENEMIES then
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if not base then
|
||||
base = createBase(map, chunk, tick)
|
||||
end
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
local unitList = surface.find_entities_filtered(universe.isFilteredEntitiesUnitQuery)
|
||||
for i=1,#unitList do
|
||||
local unit = unitList[i]
|
||||
@ -271,7 +271,7 @@ function chunkUtils.initialScan(chunk, map, tick)
|
||||
else
|
||||
for i=1,#enemyBuildings do
|
||||
local building = enemyBuildings[i]
|
||||
chunkUtils.registerEnemyBaseStructure(map, building, tick)
|
||||
chunkUtils.registerEnemyBaseStructure(map, building, tick, base)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -347,13 +347,10 @@ function chunkUtils.mapScanEnemyChunk(chunk, map, tick)
|
||||
for i=1,#HIVE_BUILDINGS_TYPES do
|
||||
counts[HIVE_BUILDINGS_TYPES[i]] = 0
|
||||
end
|
||||
local base
|
||||
if universe.NEW_ENEMIES then
|
||||
base = findNearbyBase(map, chunk)
|
||||
local base = findNearbyBase(map, chunk)
|
||||
if not base then
|
||||
base = createBase(map, chunk, tick)
|
||||
end
|
||||
end
|
||||
for i=1,#buildings do
|
||||
local building = buildings[i]
|
||||
|
||||
@ -513,7 +510,6 @@ function chunkUtils.registerEnemyBaseStructure(map, entity, tick, incomingBase,
|
||||
if (chunk ~= -1) then
|
||||
if addFunc(map, chunk, entityUnitNumber) then
|
||||
added = true
|
||||
if universe.NEW_ENEMIES then
|
||||
local base = incomingBase
|
||||
if not base then
|
||||
base = findNearbyBase(map, chunk)
|
||||
@ -523,7 +519,6 @@ function chunkUtils.registerEnemyBaseStructure(map, entity, tick, incomingBase,
|
||||
end
|
||||
setChunkBase(map, chunk, base)
|
||||
end
|
||||
end
|
||||
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
|
||||
processNestActiveness(map, chunk)
|
||||
end
|
||||
@ -572,7 +567,6 @@ function chunkUtils.unregisterEnemyBaseStructure(map, entity, damageType, skipCo
|
||||
end
|
||||
if removeFunc(map, chunk, entityUnitNumber) then
|
||||
removed = true
|
||||
if map.universe.NEW_ENEMIES then
|
||||
local base = getChunkBase(map, chunk)
|
||||
if damageType and not usedBases[base.id] then
|
||||
usedBases[base.id] = true
|
||||
@ -586,7 +580,6 @@ function chunkUtils.unregisterEnemyBaseStructure(map, entity, damageType, skipCo
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if removed and (not skipCount) and (hiveType ~= "trap") then
|
||||
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
|
||||
end
|
||||
|
@ -58,8 +58,6 @@ local COOLDOWN_DRAIN = constants.COOLDOWN_DRAIN
|
||||
local COOLDOWN_RALLY = constants.COOLDOWN_RALLY
|
||||
local COOLDOWN_RETREAT = constants.COOLDOWN_RETREAT
|
||||
|
||||
local BASE_PROCESS_INTERVAL = constants.BASE_PROCESS_INTERVAL
|
||||
|
||||
-- imported functions
|
||||
|
||||
local removeChunkToNest = mapUtils.removeChunkToNest
|
||||
@ -225,6 +223,7 @@ function mapProcessor.processPlayers(players, universe, tick)
|
||||
local playerChunk = getChunkByPosition(map, char.position)
|
||||
|
||||
if (playerChunk ~= -1) then
|
||||
local base = findNearbyBase(map, playerChunk)
|
||||
local vengence = allowingAttacks and
|
||||
(map.points >= AI_VENGENCE_SQUAD_COST) and
|
||||
((getEnemyStructureCount(map, playerChunk) > 0) or
|
||||
@ -247,7 +246,8 @@ function mapProcessor.processPlayers(players, universe, tick)
|
||||
if not pack then
|
||||
pack = {
|
||||
v = 0,
|
||||
map = map
|
||||
map = map,
|
||||
base = base
|
||||
}
|
||||
universe.vengenceQueue[chunk.id] = pack
|
||||
end
|
||||
@ -449,9 +449,9 @@ function mapProcessor.processVengence(universe)
|
||||
end
|
||||
local chunk = getChunkById(vengencePack.map, chunkId)
|
||||
if universe.enabledMigration and (universe.random() < 0.075) then
|
||||
formVengenceSettler(map, chunk)
|
||||
formVengenceSettler(map, chunk, vengencePack.base)
|
||||
else
|
||||
formVengenceSquad(map, chunk)
|
||||
formVengenceSquad(map, chunk, vengencePack.base)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -477,12 +477,10 @@ function mapProcessor.processNests(universe, tick)
|
||||
processNestActiveness(map, chunk)
|
||||
queueNestSpawners(map, chunk, tick)
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
local base = getChunkBase(map, chunk)
|
||||
if base and ((tick - base.tick) > BASE_PROCESS_INTERVAL) then
|
||||
processBase(chunk, map, tick, base)
|
||||
end
|
||||
end
|
||||
processBase(chunk,
|
||||
map,
|
||||
tick,
|
||||
getChunkBase(map, chunk))
|
||||
end
|
||||
end
|
||||
|
||||
@ -508,31 +506,31 @@ local function processSpawnersBody(universe, iterator, chunks)
|
||||
return
|
||||
end
|
||||
local state = chunkPack.map.state
|
||||
if state == AI_STATE_PEACEFUL then
|
||||
if base.state == AI_STATE_PEACEFUL then
|
||||
return
|
||||
end
|
||||
if iterator == "processMigrationIterator" then
|
||||
if (state ~= AI_STATE_MIGRATING) and (state ~= AI_STATE_SIEGE) then
|
||||
if (base.state ~= AI_STATE_MIGRATING) and (state ~= AI_STATE_SIEGE) then
|
||||
return
|
||||
end
|
||||
elseif iterator == "processActiveRaidSpawnerIterator" then
|
||||
if (state == AI_STATE_AGGRESSIVE) or (state == AI_STATE_MIGRATING) then
|
||||
if (base.state == AI_STATE_AGGRESSIVE) or (base.state == AI_STATE_MIGRATING) then
|
||||
return
|
||||
end
|
||||
elseif iterator == "processActiveSpawnerIterator" then
|
||||
if (state == AI_STATE_MIGRATING) then
|
||||
if (base.state == AI_STATE_MIGRATING) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local chunk = getChunkById(map, chunkId)
|
||||
local migrate = canMigrate(map)
|
||||
local attack = canAttack(map)
|
||||
local migrate = canMigrate(map, base)
|
||||
local attack = canAttack(map, base)
|
||||
if migrate then
|
||||
formSettlers(map, chunk)
|
||||
formSettlers(map, chunk, base)
|
||||
end
|
||||
if attack then
|
||||
formSquads(map, chunk)
|
||||
formSquads(map, chunk, base)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -136,7 +136,7 @@ function mathUtils.euclideanDistancePoints(x1, y1, x2, y2)
|
||||
return ((xs * xs) + (ys * ys)) ^ 0.5
|
||||
end
|
||||
|
||||
function mathUtils.mahattenDistancePoints(x1, y1, x2, y2)
|
||||
function mathUtils.manhattenDistancePoints(x1, y1, x2, y2)
|
||||
local xs = x1 - x2
|
||||
local ys = y1 - y2
|
||||
return mAbs(xs + ys)
|
||||
|
@ -143,9 +143,7 @@ function aiDefense.retreatUnits(chunk, cause, map, tick, radius)
|
||||
end
|
||||
|
||||
if created then
|
||||
if universe.NEW_ENEMIES then
|
||||
newSquad.base = findNearbyBase(map, chunk)
|
||||
end
|
||||
universe.groupNumberToSquad[newSquad.groupNumber] = newSquad
|
||||
universe.squadCount = universe.squadCount + 1
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user