From 643de0c922473f9ee721be207a024676121294de Mon Sep 17 00:00:00 2001 From: Remie Richards Date: Sat, 7 Mar 2015 18:46:02 +0000 Subject: [PATCH] Hostile mobs no longer run all their hostile targeting/hunting code if there is nobody (or item, for those that hunt items) near them, they simply move to a simpler loop that decides whether to let the main loop continue. --- code/__DEFINES/combat.dm | 7 ++++ .../living/simple_animal/hostile/hostile.dm | 38 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/code/__DEFINES/combat.dm b/code/__DEFINES/combat.dm index e9b5c883731..bee34b9d2c9 100644 --- a/code/__DEFINES/combat.dm +++ b/code/__DEFINES/combat.dm @@ -44,12 +44,19 @@ #define GRAB_UPGRADING 4 #define GRAB_KILL 5 + +//Hostile Mob Stances #define HOSTILE_STANCE_IDLE 1 //#define HOSTILE_STANCE_ALERT 2 //Was only used by bears #define HOSTILE_STANCE_ATTACK 3 #define HOSTILE_STANCE_ATTACKING 4 //#define HOSTILE_STANCE_TIRED 5 //Was also only used by bears +//Hostile Mob AI Status +#define AI_ON 1 +#define AI_SLEEP 2 +#define AI_OFF 3 + //Embedded objects #define EMBEDDED_PAIN_CHANCE 15 //Chance for embedded objects to cause pain (damage user) diff --git a/code/modules/mob/living/simple_animal/hostile/hostile.dm b/code/modules/mob/living/simple_animal/hostile/hostile.dm index 3828dbdce6c..7d1b74fe07a 100644 --- a/code/modules/mob/living/simple_animal/hostile/hostile.dm +++ b/code/modules/mob/living/simple_animal/hostile/hostile.dm @@ -30,6 +30,8 @@ var/stat_exclusive = 0 //Mobs with this set to 1 will exclusively attack things defined by stat_attack, stat_attack 2 means they will only attack corpses var/attack_same = 0 //Set us to 1 to allow us to attack our own faction, or 2, to only ever attack our own faction + var/AIStatus = AI_ON //The Status of our AI, can be set to AI_ON (On, usual processing), AI_SLEEP (Will not process, but will return to AI_ON if an enemy comes near), AI_OFF (Off, Not processing ever) + /mob/living/simple_animal/hostile/Life() . = ..() @@ -40,6 +42,8 @@ ranged_cooldown-- if(client) return 0 + if(!AICanContinue()) + return 0 if(!stat) switch(stance) if(HOSTILE_STANCE_IDLE) @@ -56,6 +60,9 @@ AttackTarget() DestroySurroundings() + if(AIShouldSleep()) + AIStatus = AI_SLEEP + //////////////HOSTILE MOB TARGETTING AND AGGRESSION//////////// @@ -313,4 +320,33 @@ if(ranged && ranged_cooldown <= 0) target = A OpenFire(A) - ..() \ No newline at end of file + ..() + + + +////// AI Status /////// +/mob/living/simple_animal/hostile/proc/AICanContinue() + switch(AIStatus) + if(AI_ON) + . = 1 + if(AI_SLEEP) + if(AIShouldWake()) + . = 1 + AIStatus = AI_ON //Wake up for more than one Life() cycle. + else + . = 0 + if(AI_OFF) + . = 0 + + +//Returns 1 if the AI should wake up +//Returns 0 if the AI should remain asleep +/mob/living/simple_animal/hostile/proc/AIShouldWake() + . = 0 + if(FindTarget()) + . = 1 + + +//Convenience +/mob/living/simple_animal/hostile/proc/AIShouldSleep() + . = !(AIShouldWake()) \ No newline at end of file