1
0
mirror of https://github.com/veden/Rampant.git synced 2024-12-30 21:19:46 +02:00

scaling no retreat squads

This commit is contained in:
veden 2016-08-27 17:57:20 -07:00
parent af1f6654fe
commit b4b851436f
3 changed files with 17 additions and 16 deletions

View File

@ -22,8 +22,6 @@ local SQUAD_HUNTING = constants.SQUAD_HUNTING
local SQUAD_GUARDING = constants.SQUAD_GUARDING
local SQUAD_SUICIDE_HUNT = constants.SQUAD_SUICIDE_HUNT
local AI_TUNNEL_COST = constants.AI_TUNNEL_COST
local ENEMY_BASE_GENERATOR = constants.ENEMY_BASE_GENERATOR
local MAGIC_MAXIMUM_NUMBER = constants.MAGIC_MAXIMUM_NUMBER
@ -36,8 +34,8 @@ local PLAYER_DEFENSE_GENERATOR = constants.PLAYER_DEFENSE_GENERATOR
-- imported functions
local getCardinalChunksWithDirection = mapUtils.getCardinalChunksWithDirection
local positionToChunk = mapUtils.getChunkByPosition
local canMove = mapUtils.canMoveChunkDirectionCardinal
local getChunkByPosition = mapUtils.getChunkByPosition
local canMoveChunkDirectionCardinal = mapUtils.canMoveChunkDirectionCardinal
local addSquadMovementPenalty = unitGroupUtils.addSquadMovementPenalty
local lookupSquadMovementPenalty = unitGroupUtils.lookupSquadMovementPenalty
local positionFromDirectionAndChunkCardinal = mapUtils.positionFromDirectionAndChunkCardinal
@ -46,10 +44,12 @@ local playersWithinProximityToPosition = playerUtils.playersWithinProximityToPos
local scoreNeighborsWithDirection = neighborUtils.scoreNeighborsWithDirection
local mMax = math.max
-- module code
local function validLocation(x, chunk, neighborChunk)
return canMove(x, chunk, neighborChunk)
return canMoveChunkDirectionCardinal(x, chunk, neighborChunk)
end
local function scoreAttackLocation(position, squad, neighborChunk, surface)
@ -62,7 +62,7 @@ end
local function scoreHuntPlayerLocation(position, squad, neighborChunk, surface)
local squadMovementPenalty = lookupSquadMovementPenalty(squad, neighborChunk.cX, neighborChunk.cY)
local damageScore = neighborChunk[PLAYER_PHEROMONE]
local avoidScore = neighborChunk[DEATH_PHEROMONE] + neighborChunk[ENEMY_BASE_PHEROMONE]
local avoidScore = neighborChunk[DEATH_PHEROMONE] + neighborChunk[ENEMY_BASE_PHEROMONE] + neighborChunk[PLAYER_DEFENSE_GENERATOR]
return damageScore - avoidScore - squadMovementPenalty
end
@ -73,7 +73,7 @@ function aiAttack.squadAttackLocation(regionMap, surface, natives)
local group = squad.group
if group.valid and ((squad.status == SQUAD_RAIDING) or (squad.status == SQUAD_SUICIDE_RAID)) then
if (group.state == defines.group_state.finished) or (group.state == defines.group_state.gathering) then
local chunk = positionToChunk(regionMap, group.position.x, group.position.y)
local chunk = getChunkByPosition(regionMap, group.position.x, group.position.y)
if (chunk ~= nil) then
addSquadMovementPenalty(squad, chunk.cX, chunk.cY)
local attackChunk, attackDirection = scoreNeighborsWithDirection(chunk,
@ -108,7 +108,7 @@ function aiAttack.squadAttackPlayer(regionMap, surface, natives)
local group = squad.group
if (group.valid) and ((squad.status == SQUAD_HUNTING) or (squad.status == SQUAD_SUICIDE_HUNT)) then
if (group.state == defines.group_state.finished) or (group.state == defines.group_state.gathering) then
local chunk = positionToChunk(regionMap, group.position.x, group.position.y)
local chunk = getChunkByPosition(regionMap, group.position.x, group.position.y)
if (chunk ~= nil) then
addSquadMovementPenalty(squad, chunk.cX, chunk.cY)
local attackChunk, attackDirection = scoreNeighborsWithDirection(chunk,
@ -138,13 +138,15 @@ end
function aiAttack.squadBeginAttack(natives, players, evolution_factor)
local squads = natives.squads
local groupSizeThreshold = (evolution_factor * constants.AI_MAX_SQUAD_SIZE)
local threshold = 0.05 + (evolution_factor * 0.20)
local groupSizeThreshold = mMax((evolution_factor * constants.AI_MAX_SQUAD_SIZE) + 1, 20)
for i=1,#squads do
local squad = squads[i]
if (squad.status == SQUAD_GUARDING) and squad.group.valid then
-- check to hunt player
if (math.random() < 0.30) and playersWithinProximityToPosition(players, squad.group.position, 100) then
if (math.random() < 0.05) or (groupSizeThreshold <= #squad.group.members) then
print("player hunt")
if (math.random() < threshold) or (groupSizeThreshold <= #squad.group.members) then
squad.status = SQUAD_SUICIDE_HUNT
else
squad.status = SQUAD_HUNTING
@ -153,7 +155,8 @@ function aiAttack.squadBeginAttack(natives, players, evolution_factor)
-- check to raid base
if (squad.status == SQUAD_GUARDING) and (math.random() < 0.70) then
if (math.random() < 0.05) or (groupSizeThreshold <= #squad.group.members) then
print("raid")
if (math.random() < threshold) or (groupSizeThreshold <= #squad.group.members) then
squad.status = SQUAD_SUICIDE_RAID
else
squad.status = SQUAD_RAIDING

View File

@ -21,7 +21,7 @@ constants.AI_SETTLER_COST = 75
constants.AI_BASE_BUILDING_COST = 500
constants.AI_TUNNEL_COST = 100
constants.AI_MAX_SQUAD_SIZE = 120
constants.AI_MAX_SQUAD_SIZE = 150
constants.AI_MAX_SQUAD_COUNT = 30
-- chunk properties

View File

@ -30,8 +30,6 @@ local STANDARD_PHEROMONE_PERSISTANCE = constants.STANDARD_PHEROMONE_PERSISTANCE
local getChunkByPosition = mapUtils.getChunkByPosition
local mFloor = math.floor
-- module code
function pheromoneUtils.scents(chunk)
@ -61,7 +59,7 @@ end
function pheromoneUtils.playerScent(regionMap, players)
for i=1,#players do
local player = players[i]
if (player ~= nil) and player.connected and (player.character ~= nil) and player.character.valid and (player.surface.index == 1) then
if (player ~= nil) and player.connected and (player.character ~= nil) and player.character.valid and (player.character.surface.index == 1) then
local playerPosition = player.character.position
local playerChunk = getChunkByPosition(regionMap, playerPosition.x, playerPosition.y)
if (playerChunk ~= nil) then
@ -74,7 +72,7 @@ end
function pheromoneUtils.processPheromone(chunk, neighbors)
local diffusionAmount
local persistence
for x=1,6 do
for x=1,6 do -- pheromone level indexes on chunks are 1 - 6
if (x == DEATH_PHEROMONE) then
diffusionAmount = DEATH_PHEROMONE_DIFFUSION_AMOUNT
persistence = DEATH_PHEROMONE_PERSISTANCE