[Fix] Fix the occasional AI warnings.

This commit is contained in:
Allanis 2014-05-18 21:43:51 +01:00
parent 6500acabfb
commit 8af9fa830e
2 changed files with 22 additions and 7 deletions

View File

@ -13,9 +13,15 @@ function atk_g_think()
enemy = ai.getenemy() enemy = ai.getenemy()
target = ai.target() target = ai.target()
-- Stop attacking if it doesn't exist.
if not ai.exists(target) then
ai.poptask()
return
end
-- Get new target if it's closer. -- Get new target if it's closer.
if enemy ~= target and enemy ~= nil then if enemy ~= target and enemy ~= nil then
dist = ai.dist(ai.pos(target)) dist = ai.dist(target)
range = ai.getweaprange() range = ai.getweaprange()
-- Shouldn't switch targets if close. -- Shouldn't switch targets if close.
@ -32,19 +38,21 @@ end
function atk_g() function atk_g()
target = ai.target() target = ai.target()
-- Make sure pilot exists.
if not ai.exists(target) then
ai.poptask()
return
end
-- Check if is bribed by target. -- Check if is bribed by target.
if ai.isbribed(target) then if ai.isbribed(target) then
ai.poptask() ai.poptask()
return return
end end
-- Targetting stuff.
ai.hostile(target) -- Mark as hostile. ai.hostile(target) -- Mark as hostile.
-- Make sure pilot exists.
if not ai.exists(target) then
ai.poptask()
return
end
ai.settarget(target) ai.settarget(target)
-- Get stats about enemy. -- Get stats about enemy.

View File

@ -34,6 +34,12 @@ function control()
-- Think for attacking. -- Think for attacking.
elseif task == "attack" then elseif task == "attack" then
target = ai.target() target = ai.target()
-- Needs to have a target.
if target == nil then
ai.poptask()
end
-- Runaway if needed. -- Runaway if needed.
if(shield_run > 0 and ai.pshield() < shield_run if(shield_run > 0 and ai.pshield() < shield_run
and ai.pshield() < ai.pshield(target)) or and ai.pshield() < ai.pshield(target)) or
@ -48,7 +54,8 @@ function control()
-- Pilot is running away. -- Pilot is running away.
elseif task == "runaway" then elseif task == "runaway" then
dist = ai.dist(ai.pos(ai.target())) target = ai.target()
dist = ai.dist(target)
if aggressive and((shield_return > 0 and ai.pshield() >= shield_return) or if aggressive and((shield_return > 0 and ai.pshield() >= shield_return) or
(armour_return > 0 and ai.parmour() >= armour_return)) then (armour_return > 0 and ai.parmour() >= armour_return)) then