From b314a922b3117f6128247f3eb08c7adfdf433a5e Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Mon, 10 Mar 2014 16:55:21 +0000
Subject: [PATCH] [Fix] AI shouldn't be fleeing when enemy has more health.

---
 scripts/ai/tpl/generic.lua | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/scripts/ai/tpl/generic.lua b/scripts/ai/tpl/generic.lua
index 4e29671..0bfdda2 100644
--- a/scripts/ai/tpl/generic.lua
+++ b/scripts/ai/tpl/generic.lua
@@ -33,9 +33,12 @@ function control()
 
   -- Think for attacking.
   elseif task == "attack" then
+    target = ai.target()
     -- Runaway if needed.
-    if(shield_run > 0 and ai.pshield() < shield_run) or
-        (armour_run > 0 and ai.parmour() < armour_run) then
+    if(shield_run > 0 and ai.pshield() < shield_run
+      and ai.pshield() < ai.pshield(target)) or
+        (armour_run > 0 and ai.parmour() < armour_run
+        and ai.parmour() < ai.parmour(target)) then
       ai.pushtask(0, "runaway", ai.target())
 
     -- Think like normal.