[Change] Unified attack thinking in ai scripts.

This commit is contained in:
Allanis 2013-11-10 01:41:50 +00:00
parent c7d85fe6e2
commit db18dd0516
4 changed files with 58 additions and 55 deletions

View File

@ -6,7 +6,11 @@ control_rate = 0.5
function control() function control()
local task = ai.taskname() 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() local enemy = ai.getenemy()
if enemey ~= 0 then if enemey ~= 0 then
@ -16,8 +20,6 @@ function control()
end end
elseif task == "hyperspace" then elseif task == "hyperspace" then
ai.hyperspace() ai.hyperspace()
else
attack_closestenemy()
end end
end end

View File

@ -5,11 +5,15 @@ control_rate = 2
-- Required "control" function. -- Required "control" function.
function control() function control()
task = ai.taskname() local task = ai.taskname()
local enemy = ai.getenemy()
enemy = ai.getenemy() -- Think for attacking.
if task ~= "attack" and enemy ~= nil then if task == "attack" then
ai.hostile(enemy) attack_think()
-- Enemy sighted.
elseif enemy ~= nil then
ai.pushtask(0, "attack", enemy) ai.pushtask(0, "attack", enemy)
-- Enter hyperspace if possible. -- Enter hyperspace if possible.
@ -17,7 +21,7 @@ function control()
ai.hyperspace() -- Try to hyperspace. ai.hyperspace() -- Try to hyperspace.
-- Get new task. -- Get new task.
elseif task == "none" then else
planet = ai.landplanet() planet = ai.landplanet()
-- Planet needs to exist.. -- Planet needs to exist..
if planet == nil then if planet == nil then

View File

@ -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() function attack_think()
local task = ai.taskname()
if task == "attack" then
local enemy = ai.getenemy() local enemy = ai.getenemy()
local target = ai.targetid() local target = ai.targetid()
-- Get new target if it's closer.
if enemy ~= target then if enemy ~= target then
local dist = ai.dist(ai.pos(target))
local range = ai.getweaprange()
-- Shouldn't switch targets if close.
if dist > range * 1.3 then
ai.poptask() ai.poptask()
ai.pushtask(0, "attack", enemy) ai.pushtask(0, "attack", enemy)
end end

View File

@ -7,7 +7,14 @@ control_rate = 2
function control() function control()
task = ai.taskname() 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. ai.hyperspace() -- Try to hyperspace.
-- Running pilot has healed up some. -- Running pilot has healed up some.
@ -19,30 +26,12 @@ function control()
ai.hyperspace() ai.hyperspace()
end 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. -- Nothing to do.
elseif task ~= "attack" and task ~= "runaway" then else
-- If getenemy() is 0, there is no enemy around. -- If getenemy() is 0, there is no enemy around.
enemy = ai.getenemy() enemy = ai.getenemy()
if ai.parmour() == 100 and enemy ~= 0 then if ai.parmour() == 100 and enemy ~= 0 then
-- Taunts. taunt(enemy, true)
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.
ai.pushtask(0, "attack", enemy) -- Begin the attack. ai.pushtask(0, "attack", enemy) -- Begin the attack.
-- Nothing to attack. -- Nothing to attack.
else else
@ -57,7 +46,7 @@ function attacked(attacker)
-- Pirate isn't fighting or fleeing already. -- Pirate isn't fighting or fleeing already.
if task ~= "attack" and task ~= "runaway" then if task ~= "attack" and task ~= "runaway" then
taunt(attacker) taunt(attacker, false)
ai.pushtask(0, "attack", attacker) ai.pushtask(0, "attack", attacker)
-- Pirate is fighting bit switches to new target (doesn't forget the old on though). -- Pirate is fighting bit switches to new target (doesn't forget the old on though).
elseif task == "attack" then elseif task == "attack" then
@ -73,24 +62,27 @@ function create()
end end
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. -- Some taunts.
if offense then
taunts = { taunts = {
"How dare you attack me?!", "Prepare to be boarded!",
"Aha! You think you can best me!?", "Yohoho!",
"JUST! DIE!", "What's a pretty ship like you doing in a place like this?!"
"Ohh, I'm going to enjoy 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)]) ai.comm(target, taunts[rnd.int(1, #taunts)])
end 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