[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()
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.
if enemy ~= target and enemy ~= nil then
dist = ai.dist(ai.pos(target))
dist = ai.dist(target)
range = ai.getweaprange()
-- Shouldn't switch targets if close.
@ -32,19 +38,21 @@ end
function atk_g()
target = ai.target()
-- Make sure pilot exists.
if not ai.exists(target) then
ai.poptask()
return
end
-- Check if is bribed by target.
if ai.isbribed(target) then
ai.poptask()
return
end
-- Targetting stuff.
ai.hostile(target) -- Mark as hostile.
-- Make sure pilot exists.
if not ai.exists(target) then
ai.poptask()
return
end
ai.settarget(target)
-- Get stats about enemy.

View File

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