[Change] Unified attack thinking in ai scripts.
This commit is contained in:
parent
c7d85fe6e2
commit
db18dd0516
@ -6,7 +6,11 @@ control_rate = 0.5
|
||||
function control()
|
||||
local task = ai.taskname()
|
||||
|
||||
if task == "none" then
|
||||
-- Think function for attack.
|
||||
if task == "attack" then
|
||||
attack_think()
|
||||
|
||||
elseif task == "none" then
|
||||
local enemy = ai.getenemy()
|
||||
|
||||
if enemey ~= 0 then
|
||||
@ -16,8 +20,6 @@ function control()
|
||||
end
|
||||
elseif task == "hyperspace" then
|
||||
ai.hyperspace()
|
||||
else
|
||||
attack_closestenemy()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -5,11 +5,15 @@ control_rate = 2
|
||||
|
||||
-- Required "control" function.
|
||||
function control()
|
||||
task = ai.taskname()
|
||||
local task = ai.taskname()
|
||||
local enemy = ai.getenemy()
|
||||
|
||||
enemy = ai.getenemy()
|
||||
if task ~= "attack" and enemy ~= nil then
|
||||
ai.hostile(enemy)
|
||||
-- Think for attacking.
|
||||
if task == "attack" then
|
||||
attack_think()
|
||||
|
||||
-- Enemy sighted.
|
||||
elseif enemy ~= nil then
|
||||
ai.pushtask(0, "attack", enemy)
|
||||
|
||||
-- Enter hyperspace if possible.
|
||||
@ -17,7 +21,7 @@ function control()
|
||||
ai.hyperspace() -- Try to hyperspace.
|
||||
|
||||
-- Get new task.
|
||||
elseif task == "none" then
|
||||
else
|
||||
planet = ai.landplanet()
|
||||
-- Planet needs to exist..
|
||||
if planet == nil then
|
||||
|
@ -6,16 +6,21 @@
|
||||
--]]
|
||||
|
||||
--[[
|
||||
-- Replaces the current target with a closer one if possible.
|
||||
-- Should be run when the pilot is in attack mode, something like:
|
||||
-- if task == "attack" then attack_think() end
|
||||
-- in control().
|
||||
--]]
|
||||
function attack_closestenemy()
|
||||
local task = ai.taskname()
|
||||
function attack_think()
|
||||
local enemy = ai.getenemy()
|
||||
local target = ai.targetid()
|
||||
|
||||
if task == "attack" then
|
||||
local enemy = ai.getenemy()
|
||||
local target = ai.targetid()
|
||||
-- Get new target if it's closer.
|
||||
if enemy ~= target then
|
||||
local dist = ai.dist(ai.pos(target))
|
||||
local range = ai.getweaprange()
|
||||
|
||||
if enemy ~= target then
|
||||
-- Shouldn't switch targets if close.
|
||||
if dist > range * 1.3 then
|
||||
ai.poptask()
|
||||
ai.pushtask(0, "attack", enemy)
|
||||
end
|
||||
|
@ -7,7 +7,14 @@ control_rate = 2
|
||||
function control()
|
||||
task = ai.taskname()
|
||||
|
||||
if task == "hyperspace" then
|
||||
if task == "attack" then
|
||||
if ai.parmour() < 80 then
|
||||
ai.pushtask(0, "runaway", ai.targetid())
|
||||
else
|
||||
attack_think()
|
||||
end
|
||||
|
||||
elseif task == "hyperspace" then
|
||||
ai.hyperspace() -- Try to hyperspace.
|
||||
|
||||
-- Running pilot has healed up some.
|
||||
@ -19,30 +26,12 @@ function control()
|
||||
ai.hyperspace()
|
||||
end
|
||||
|
||||
-- Hurt pilot wants to run away.
|
||||
elseif task == "attack" then
|
||||
if ai.parmour() < 80 then
|
||||
ai.pushtask(0, "runaway", ai.targetid())
|
||||
end
|
||||
|
||||
-- Nothing to do.
|
||||
elseif task ~= "attack" and task ~= "runaway" then
|
||||
-- Nothing to do.
|
||||
else
|
||||
-- If getenemy() is 0, there is no enemy around.
|
||||
enemy = ai.getenemy()
|
||||
if ai.parmour() == 100 and enemy ~= 0 then
|
||||
-- Taunts.
|
||||
num = rnd.int(0,5)
|
||||
if num == 0 then msg = "Prepare to be boarded!"
|
||||
elseif num == 1 then msg = "Whoa! Lookie what we found here!"
|
||||
elseif num == 2 then msg = "What's a ship like you doing in a place like this?"
|
||||
end
|
||||
ai.comm(enemy,msg)
|
||||
|
||||
-- Make hostile to the enemy (mainly, player! YOU!).
|
||||
ai.hostile(enemy)
|
||||
|
||||
-- Go ahead and attack.
|
||||
ai.combat() -- Set to be in combat.
|
||||
taunt(enemy, true)
|
||||
ai.pushtask(0, "attack", enemy) -- Begin the attack.
|
||||
-- Nothing to attack.
|
||||
else
|
||||
@ -57,7 +46,7 @@ function attacked(attacker)
|
||||
|
||||
-- Pirate isn't fighting or fleeing already.
|
||||
if task ~= "attack" and task ~= "runaway" then
|
||||
taunt(attacker)
|
||||
taunt(attacker, false)
|
||||
ai.pushtask(0, "attack", attacker)
|
||||
-- Pirate is fighting bit switches to new target (doesn't forget the old on though).
|
||||
elseif task == "attack" then
|
||||
@ -73,24 +62,27 @@ function create()
|
||||
end
|
||||
end
|
||||
|
||||
function taunt(target)
|
||||
function taunt(target, offense)
|
||||
-- Only 50$ of actually taunting.
|
||||
if rnd.int(0,1) == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
-- Some taunts.
|
||||
taunts = {
|
||||
"How dare you attack me?!",
|
||||
"Aha! You think you can best me!?",
|
||||
"JUST! DIE!",
|
||||
"Ohh, I'm going to enjoy this!"
|
||||
}
|
||||
if offense then
|
||||
taunts = {
|
||||
"Prepare to be boarded!",
|
||||
"Yohoho!",
|
||||
"What's a pretty ship like you doing in a place like this?!"
|
||||
}
|
||||
else
|
||||
taunts = {
|
||||
"You dare attack me?!",
|
||||
"You think that you can take me on?!",
|
||||
"JUST!! DIE!!",
|
||||
"You'll regret this!"
|
||||
}
|
||||
end
|
||||
ai.comm(target, taunts[rnd.int(1, #taunts)])
|
||||
end
|
||||
|
||||
-- Fly to the player. Pointless until hyperspace is implemented.
|
||||
function fly()
|
||||
target = player
|
||||
dir = ai.face(target)
|
||||
dist = ai.dist(ai.pos(target))
|
||||
if dir < 10 and dist > 300 then
|
||||
ai.accel()
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user