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.

This commit is contained in:
Remie Richards
2015-03-07 18:46:02 +00:00
parent 04dcfaddcf
commit 643de0c922
2 changed files with 44 additions and 1 deletions

View File

@@ -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)

View File

@@ -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)
..()
..()
////// 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())