1
0
mirror of https://github.com/veden/Rampant.git synced 2024-12-26 20:54:12 +02:00

ai adjustment for the more frequent running and base fixes

This commit is contained in:
Aaron Veden 2021-02-20 15:31:48 -08:00
parent 5ebc3b2fd1
commit 71727454b9
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
11 changed files with 76 additions and 110 deletions

View File

@ -338,6 +338,7 @@ function upgrade.attempt(universe)
universe.aiPointsScaler = settings.global["rampant--aiPointsScaler"].value
universe.aiNocturnalMode = settings.global["rampant--permanentNocturnal"].value
universe.mapIterator = nil
universe.retreatThreshold = 0
universe.rallyThreshold = 0
universe.formSquadThreshold = 0

View File

@ -20,6 +20,7 @@ Date: 06. 02. 2021
- Increased builder squad cost to 400
- Decreased siege ai state chance to 15% at peak temperament
- Halved AI temperament rate of change
- Increased ai state duration minimum to 10 and maximum to 25 minutes
Bugfixes:
- Fixed suicide and nuclear enemies explosion centered on target instead self
- Fixed process spawners reading missing globals
@ -27,7 +28,8 @@ Date: 06. 02. 2021
- Fixed potential desync in unit group creation event
- Fixed potential desync in building native tables
- Fixed find entity upgrade incorrectly calculating evolution
- Fixed bug with the mod new game+
- Fixed bug with the mod new game+
- Fixed existing spawner upgrading in place over time
---------------------------------------------------------------------------------------------------
Version: 1.0.2

View File

@ -256,7 +256,6 @@ local function prepMap(surface)
end
map.processedChunks = 0
map.mapIterator = nil
map.processQueue = {}
map.processIndex = 1
map.cleanupIndex = 1
@ -365,7 +364,7 @@ local function prepMap(surface)
end
end
processPendingChunks(map, tick, universe)
processPendingChunks(map, tick, true)
end
local function onConfigChanged()
@ -777,7 +776,7 @@ local function onUsedCapsule(event)
map.position2Top.y = event.position.y-0.75
map.position2Bottom.x = event.position.x+0.75
map.position2Bottom.y = event.position.y+0.75
local cliffs = surface.find_entities_filtered(map.cliffQuery)
local cliffs = surface.find_entities_filtered(universe.cliffQuery)
for i=1,#cliffs do
entityForPassScan(map, cliffs[i])
end
@ -959,7 +958,6 @@ local function onForceMerged(event)
end
local function onSurfaceCreated(event)
print("new surface", event.surface_index)
prepMap(game.surfaces[event.surface_index])
end
@ -1009,37 +1007,37 @@ script.on_event(defines.events.on_tick,
end
if (pick == 0) then
processPendingChunks(map, tick, universe)
processPendingChunks(map, tick)
processScanChunks(map)
elseif (pick == 1) then
processPlayers(gameRef.connected_players, map, tick)
cleanUpMapTables(map, tick)
elseif (pick == 2) then
processMap(map, tick)
universe.processedChunks = universe.processedChunks + PROCESS_QUEUE_SIZE
planning(map, gameRef.forces.enemy.evolution_factor, tick)
if universe.NEW_ENEMIES then
recycleBases(map, tick)
end
cleanUpMapTables(map, tick)
elseif (pick == 1) then
processPlayers(gameRef.connected_players, map, tick)
elseif (pick == 2) then
processMap(map, tick)
elseif (pick == 3) then
processStaticMap(map)
disperseVictoryScent(map)
cleanSquads(map)
processVengence(map)
elseif (pick == 4) then
scanResourceMap(map, tick)
processVengence(map)
elseif (pick == 5) then
scanEnemyMap(map, tick)
processSpawners(map, tick)
temperamentPlanner(map)
elseif (pick == 6) then
scanPlayerMap(map, tick)
processNests(map, tick)
temperamentPlanner(map)
end
processActiveNests(map, tick)
-- game.print({"", "--dispatch4 ", profiler, ", ", game.tick, " ", mRandom()})
-- game.print({"", "--dispatch4 ", profiler, ", ", pick, ", ", game.tick, " ", mRandom()})
end)
script.on_event(defines.events.on_surface_deleted, onSurfaceDeleted)

View File

@ -219,7 +219,6 @@ function aiAttackWave.formSettlers(map, chunk)
10,
universe.expansionMaxDistance)
local scaledWaveSize = settlerWaveScaling(universe)
universe.formGroupCommand.group = squad.group
universe.formCommand.unit_count = scaledWaveSize

View File

@ -71,8 +71,8 @@ function aiPlanning.planning(map, evolution_factor, tick)
local attackWaveMaxSize = universe.attackWaveMaxSize
universe.retreatThreshold = linearInterpolation(evolution_factor,
RETREAT_MOVEMENT_PHEROMONE_LEVEL_MIN,
RETREAT_MOVEMENT_PHEROMONE_LEVEL_MAX)
RETREAT_MOVEMENT_PHEROMONE_LEVEL_MIN,
RETREAT_MOVEMENT_PHEROMONE_LEVEL_MAX)
universe.rallyThreshold = BASE_RALLY_CHANCE + (evolution_factor * BONUS_RALLY_CHANCE)
universe.formSquadThreshold = mMax((0.20 * evolution_factor), 0.05)
@ -87,19 +87,19 @@ function aiPlanning.planning(map, evolution_factor, tick)
end
universe.settlerWaveSize = linearInterpolation(evolution_factor ^ 1.66667,
universe.expansionMinSize,
universe.expansionMaxSize)
universe.expansionMinSize,
universe.expansionMaxSize)
universe.settlerWaveDeviation = (universe.settlerWaveSize * 0.33)
universe.settlerCooldown = mFloor(linearInterpolation(evolution_factor ^ 1.66667,
universe.expansionMaxTime,
universe.expansionMinTime))
universe.expansionMaxTime,
universe.expansionMinTime))
universe.unitRefundAmount = AI_UNIT_REFUND * evolution_factor
universe.kamikazeThreshold = NO_RETREAT_BASE_PERCENT + (evolution_factor * NO_RETREAT_EVOLUTION_BONUS_MAX)
local points = mFloor((AI_POINT_GENERATOR_AMOUNT * mRandom()) + (map.activeNests * 0.25) +
(((AI_POINT_GENERATOR_AMOUNT * 0.7) * (evolution_factor ^ 2.5)) * universe.aiPointsScaler))
local points = mFloor((AI_POINT_GENERATOR_AMOUNT * mRandom()) + (map.activeNests * 0.028702) +
(((AI_POINT_GENERATOR_AMOUNT * 0.080367) * (evolution_factor ^ 2.5)) * universe.aiPointsScaler))
if (map.state == AI_STATE_ONSLAUGHT) then
points = points * 2
@ -128,17 +128,11 @@ function aiPlanning.planning(map, evolution_factor, tick)
if universe.raidAIToggle then
if (roll < 0.85) then
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
else
map.state = AI_STATE_RAIDING
end
else
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
end
end
elseif (map.temperament < 0.20) then -- 0.05 - 0.2
@ -152,26 +146,17 @@ function aiPlanning.planning(map, evolution_factor, tick)
if universe.raidAIToggle then
if (roll < 0.95) then
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
else
map.state = AI_STATE_RAIDING
end
else
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
end
end
elseif (map.temperament < 0.4) then -- 0.2 - 0.4
if (universe.enabledMigration) then
if (roll < 0.2) then
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
elseif (roll < 0.8) then
map.state = AI_STATE_MIGRATING
else
@ -180,28 +165,19 @@ function aiPlanning.planning(map, evolution_factor, tick)
else
if (roll < 0.6) then
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
else
map.state = AI_STATE_PEACEFUL
end
end
elseif (map.temperament < 0.6) then -- 0.4 - 0.6
if (roll < 0.5) then
if (roll < 0.4) then
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
else
map.state = AI_STATE_PEACEFUL
end
elseif (map.temperament < 0.8) then -- 0.6 - 0.8
if (roll < 0.6) then
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
elseif (roll < 0.8) then
map.state = AI_STATE_ONSLAUGHT
else
@ -217,9 +193,6 @@ function aiPlanning.planning(map, evolution_factor, tick)
map.state = AI_STATE_RAIDING
else
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
end
elseif (universe.enabledMigration) then
if (roll < 0.15) then
@ -228,9 +201,6 @@ function aiPlanning.planning(map, evolution_factor, tick)
map.state = AI_STATE_ONSLAUGHT
else
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
end
elseif (universe.raidAIToggle) then
if (roll < 0.4) then
@ -239,18 +209,12 @@ function aiPlanning.planning(map, evolution_factor, tick)
map.state = AI_STATE_RAIDING
else
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
end
else
if (roll < 0.6) then
map.state = AI_STATE_ONSLAUGHT
else
map.state = AI_STATE_AGGRESSIVE
map.canAttackTick = randomTickEvent(tick,
AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION,
AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION)
end
end
end
@ -286,39 +250,39 @@ function aiPlanning.temperamentPlanner(map)
local delta = 0
if activeNests > 0 then
local val = (0.375 * activeNests)
local val = (0.021695 * activeNests)
delta = delta + val
else
delta = delta - 0.25
delta = delta - 0.014463
end
if destroyPlayerBuildings > 0 then
if currentTemperament > 0 then
delta = delta - (0.25 * destroyPlayerBuildings)
delta = delta - (0.014463 * destroyPlayerBuildings)
else
delta = delta + (0.25 * destroyPlayerBuildings)
delta = delta + (0.014463 * destroyPlayerBuildings)
end
end
if activeRaidNests > 0 then
local val = (0.003825 * activeRaidNests)
local val = (0.000221 * activeRaidNests)
delta = delta - val
else
delta = delta - 0.125
delta = delta - 0.007232
end
if lostEnemyUnits > 0 then
local multipler
if map.evolutionLevel < 0.3 then
multipler = 0.0005
multipler = 0.000434
elseif map.evolutionLevel < 0.5 then
multipler = 0.000385
multipler = 0.000217
elseif map.evolutionLevel < 0.7 then
multipler = 0.00025
multipler = 0.000108
elseif map.evolutionLevel < 0.9 then
multipler = 0.00012
multipler = 0.000054
elseif map.evolutionLevel < 0.9 then
multipler = 0.00006
multipler = 0.000027
end
local val = (multipler * lostEnemyUnits)
if (currentTemperament > 0) then
@ -329,7 +293,7 @@ function aiPlanning.temperamentPlanner(map)
end
if lostEnemyBuilding > 0 then
local val = (1.25 * lostEnemyBuilding)
local val = (0.072317 * lostEnemyBuilding)
if (currentTemperament > 0) then
delta = delta - val
else
@ -338,35 +302,33 @@ function aiPlanning.temperamentPlanner(map)
end
if (builtEnemyBuilding > 0) then
local val = (0.075 * builtEnemyBuilding)
local val = (0.004339 * builtEnemyBuilding)
if (currentTemperament > 0) then
delta = delta - val
else
delta = delta + val
end
else
delta = delta - 0.125
delta = delta - 0.007232
end
if (rocketLaunched > 0) then
local val = (5 * rocketLaunched)
local val = (0.289268 * rocketLaunched)
delta = delta + val
end
if (ionCannonBlasts > 0) then
local val = (2.5 * ionCannonBlasts)
local val = (0.144634 * ionCannonBlasts)
delta = delta + val
end
if (artilleryBlasts > 0) then
local val = (2.5 * artilleryBlasts)
local val = (0.144634 * artilleryBlasts)
delta = delta + val
end
-- print("temperament", map.activeNests, map.activeRaidNests, map.destroyPlayerBuildings,
-- map.lostEnemyUnits,
-- map.lostEnemyBuilding, map.rocketLaunched, map.builtEnemyBuilding, map.ionCannonBlasts,
-- map.artilleryBlasts)
map.temperamentScore = mMin(10000, mMax(-10000, currentTemperament + delta))
map.temperament = ((map.temperamentScore + 10000) * 0.00005)
-- map.destroyPlayerBuildings = 0
-- map.lostEnemyUnits = 0
@ -376,11 +338,14 @@ function aiPlanning.temperamentPlanner(map)
-- map.ionCannonBlasts = 0
-- map.artilleryBlasts = 0
map.temperamentScore = mMin(10000, mMax(-10000, currentTemperament + delta))
map.temperament = ((map.temperamentScore + 10000) * 0.00005)
-- if game.tick % 240 == 0 then
-- print("temperament", map.activeNests, map.activeRaidNests, map.destroyPlayerBuildings,
-- map.lostEnemyUnits, map.lostEnemyBuilding, map.rocketLaunched, map.builtEnemyBuilding,
-- map.ionCannonBlasts, map.artilleryBlasts)
-- print("tempResult", map.temperament, map.temperamentScore)
-- print("--")
-- print("tempResult", map.temperament, map.temperamentScore, map.points, map.state, map.surface.index)
-- print("--")
-- end
end
aiPlanningG = aiPlanning

View File

@ -32,13 +32,11 @@ end
function aiPredicates.canMigrate(map)
local surface = map.surface
local nocturalMode = map.universe.aiNocturnalMode
local goodAI = ((map.state == AI_STATE_MIGRATING) or (map.state == AI_STATE_SIEGE))
local noctural = ((not nocturalMode) or (nocturalMode and surface.darkness > 0.65))
return goodAI
and map.expansion
and not surface.peaceful_mode
and noctural
local universe = map.universe
local nocturalMode = universe.aiNocturnalMode
local goodAI = (map.state == AI_STATE_MIGRATING) or (map.state == AI_STATE_SIEGE)
local noctural = (not nocturalMode) or (nocturalMode and surface.darkness > 0.65)
return goodAI and universe.expansion and not surface.peaceful_mode and noctural
end
aiPredicatesG = aiPredicates

View File

@ -343,22 +343,24 @@ function baseUtils.processBase(chunk, map, tick, base)
end
local surface = map.surface
local point = map.position
local universe = map.universe
local point = universe.position
point.x = chunk.x + (CHUNK_SIZE * mRandom())
point.y = chunk.y + (CHUNK_SIZE * mRandom())
if (base.state == BASE_AI_STATE_ACTIVE) then
local entity = surface.find_entities_filtered(map.filteredEntitiesPointQueryLimited)
local cost = (universe.costLookup[entity.name] or MAGIC_MAXIMUM_NUMBER)
if entity and (base.points >= cost) then
local newEntity = baseUtils.upgradeEntity(entity,
surface,
base.alignment,
map)
if newEntity then
base.points = base.points - cost
local entities = surface.find_entities_filtered(universe.filteredEntitiesPointQueryLimited)
if #entities ~= 0 then
local entity = entities[1]
local cost = (universe.costLookup[entity.name] or MAGIC_MAXIMUM_NUMBER)
if (base.points >= cost) then
local newEntity = baseUtils.upgradeEntity(entity,
base.alignment,
map)
if newEntity then
base.points = base.points - cost
end
end
end
elseif (base.state == BASE_AI_STATE_MUTATE) then

View File

@ -225,7 +225,7 @@ function chunkUtils.initialScan(chunk, map, tick)
end
if (#enemyBuildings > 0) then
if universe.newEnemies then
if universe.NEW_ENEMIES then
local base = findNearbyBase(map, chunk)
if base then
setChunkBase(map, chunk, base)
@ -245,7 +245,7 @@ function chunkUtils.initialScan(chunk, map, tick)
for i = 1, #enemyBuildings do
local enemyBuilding = enemyBuildings[i]
if not buildingHiveTypeLookup[enemyBuilding.name] then
local newEntity = upgradeEntity(enemyBuilding, surface, alignment, map, nil, true)
local newEntity = upgradeEntity(enemyBuilding, alignment, map, nil, true)
if newEntity then
local hiveType = buildingHiveTypeLookup[newEntity.name]
counts[hiveType] = counts[hiveType] + 1

View File

@ -116,7 +116,7 @@ constants.MAX_TICKS_BEFORE_SORT_CHUNKS = 60 * 60 * 30 -- 1 tick = 1/60 sec * 60
constants.RESOURCE_MINIMUM_FORMATION_DELTA = 15
constants.MINIMUM_AI_POINTS = 100
constants.AI_POINT_GENERATOR_AMOUNT = 6
constants.AI_POINT_GENERATOR_AMOUNT = 0.688863
constants.AI_SQUAD_COST = 175
constants.RECOVER_NEST_COST = constants.AI_SQUAD_COST
constants.RECOVER_WORM_COST = constants.AI_SQUAD_COST * 0.5
@ -153,8 +153,8 @@ constants.BASE_AI_STATE_MUTATE = 3
constants.AGGRESSIVE_CAN_ATTACK_WAIT_MIN_DURATION = 0.5
constants.AGGRESSIVE_CAN_ATTACK_WAIT_MAX_DURATION = 3
constants.AI_MIN_STATE_DURATION = 7
constants.AI_MAX_STATE_DURATION = 17
constants.AI_MIN_STATE_DURATION = 10
constants.AI_MAX_STATE_DURATION = 25
constants.AI_MIN_TEMPERAMENT_DURATION = 25
constants.AI_MAX_TEMPERAMENT_DURATION = 32

View File

@ -490,7 +490,7 @@ function mapProcessor.processNests(map, tick)
processNestActiveness(map, chunk)
queueNestSpawners(map, chunk, tick)
if map.universe.newEnemies then
if map.universe.NEW_ENEMIES then
local base = bases[chunk]
if base and ((tick - base.tick) > BASE_PROCESS_INTERVAL) then
processBase(chunk, map, tick, base)

View File

@ -305,7 +305,8 @@ end
local function buildMove(map, squad)
local group = squad.group
local position = map.universe.position
local universe = map.universe
local position = universe.position
local groupPosition = findMovementPosition(map.surface, group.position)
if not groupPosition then
@ -315,7 +316,7 @@ local function buildMove(map, squad)
position.x = groupPosition.x
position.y = groupPosition.y
group.set_command(map.compoundSettleCommand)
group.set_command(universe.compoundSettleCommand)
end
function squadAttack.cleanSquads(map)