1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-26 03:20:07 +02:00

refactored squad attack to single function

This commit is contained in:
veden 2016-08-28 13:48:19 -07:00
parent bd2b8e731b
commit 58f831e1e9
6 changed files with 22 additions and 47 deletions

View File

@ -29,6 +29,8 @@ Base Expansion
# Version History
0.0.9 -
0.0.8 - fixed retreat oscillations (https://forums.factorio.com/viewtopic.php?f=94&t=31445&start=10#p198750)
added scaling for kamikaze attack (https://forums.factorio.com/viewtopic.php?f=94&t=31445&start=10#p199401)
increased squad size max from 125 to 150, (larger waves)

View File

@ -27,8 +27,7 @@ local deathScent = pheromoneUtils.deathScent
local regroupSquads = unitGroupUtils.regroupSquads
local convertUnitGroupToSquad = unitGroupUtils.convertUnitGroupToSquad
local squadAttackPlayer = aiAttack.squadAttackPlayer
local squadAttackLocation = aiAttack.squadAttackLocation
local squadAttack = aiAttack.squadAttack
local squadBeginAttack = aiAttack.squadBeginAttack
local retreatUnits = aiDefense.retreatUnits
@ -78,7 +77,7 @@ function onConfigChanged()
global.version = constants.VERSION_5
end
if (global.version < constants.VERSION_8) then
if (global.version < constants.VERSION_9) then
-- queue all current chunks that wont be generated during play
local surface = game.surfaces[1]
@ -87,7 +86,7 @@ function onConfigChanged()
area = { left_top = { x = chunk.x * 32,
y = chunk.y * 32 }}})
end
global.version = constants.VERSION_8
global.version = constants.VERSION_9
end
end
@ -115,8 +114,7 @@ function onTick(event)
-- scouting(regionMap, natives)
squadBeginAttack(natives, game.players, game.evolution_factor)
squadAttackLocation(regionMap, surface, natives)
squadAttackPlayer(regionMap, surface, natives)
squadAttack(regionMap, surface, natives)
end
processPendingChunks(regionMap, surface, natives, pendingChunks)
@ -199,5 +197,6 @@ remote.add_interface("rampant", {
test7 = tests.test7,
test8 = tests.test8,
test9 = tests.test9,
test10 = tests.test10
test10 = tests.test10,
test11 = tests.test11
})

View File

@ -1,7 +1,7 @@
{
"name" : "Rampant",
"factorio_version" : "0.14",
"version" : "0.0.8",
"version" : "0.0.9",
"title" : "Rampant AI",
"author" : "Veden",
"homepage" : "https://forums.factorio.com/viewtopic.php?f=94&t=31445",

View File

@ -66,47 +66,22 @@ local function scoreHuntPlayerLocation(position, squad, neighborChunk, surface)
return damageScore - avoidScore - squadMovementPenalty
end
function aiAttack.squadAttackLocation(regionMap, surface, natives)
function aiAttack.squadAttack(regionMap, surface, natives)
local squads = natives.squads
for i=1,#squads do
local squad = squads[i]
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 = getChunkByPosition(regionMap, group.position.x, group.position.y)
if (chunk ~= nil) then
addSquadMovementPenalty(squad, chunk.cX, chunk.cY)
local attackChunk, attackDirection = scoreNeighborsWithDirection(chunk,
getCardinalChunksWithDirection(regionMap, chunk.cX, chunk.cY),
validLocation,
scoreAttackLocation,
squad,
surface)
if (attackChunk ~= nil) then
if ((attackChunk[PLAYER_BASE_GENERATOR] == 0) and (attackChunk[PLAYER_DEFENSE_GENERATOR] == 0)) or
((group.state == defines.group_state.finished) or (group.state == defines.group_state.gathering)) then
attackPosition = positionFromDirectionAndChunkCardinal(attackDirection, attackChunk)
group.set_command({type=defines.command.attack_area,
destination=attackPosition,
radius=32,
distraction=defines.distraction.by_anything})
group.start_moving()
end
end
end
end
local raiding = false
local hunting = false
local scoreLocation
if (squad.status == SQUAD_RAIDING) or (squad.status == SQUAD_SUICIDE_RAID) then
raiding = true
scoreLocation = scoreAttackLocation
elseif (squad.status == SQUAD_HUNTING) or (squad.status == SQUAD_SUICIDE_HUNT) then
hunting = true
scoreLocation = scoreHuntPlayerLocation
end
end
end
function aiAttack.squadAttackPlayer(regionMap, surface, natives)
local squads = natives.squads
for i=1,#squads do
local squad = squads[i]
local group = squad.group
if (group.valid) and ((squad.status == SQUAD_HUNTING) or (squad.status == SQUAD_SUICIDE_HUNT)) then
if group.valid and (raiding or hunting) then
if (group.state == defines.group_state.finished) or (group.state == defines.group_state.gathering) then
local chunk = getChunkByPosition(regionMap, group.position.x, group.position.y)
if (chunk ~= nil) then
@ -114,7 +89,7 @@ function aiAttack.squadAttackPlayer(regionMap, surface, natives)
local attackChunk, attackDirection = scoreNeighborsWithDirection(chunk,
getCardinalChunksWithDirection(regionMap, chunk.cX, chunk.cY),
validLocation,
scoreHuntPlayerLocation,
scoreLocation,
squad,
surface)
if (attackChunk ~= nil) then

View File

@ -97,7 +97,6 @@ function aiBuilding.scouting(regionMap, natives)
for i=1,#scouts do
local scout = scouts[i]
if scout.valid then
-- print("scout", i, game.tick, scout, scout.has_command())
scout.set_command({type=defines.command.attack_area,
destination={0,0},
radius=32,

View File

@ -3,7 +3,7 @@ local constants = {}
-- versions
constants.VERSION_5 = 5
constants.VERSION_8 = 8
constants.VERSION_9 = 9
-- misc