Advanced mob laziness

This commit is contained in:
vuonojenmustaturska
2017-12-18 03:35:37 +02:00
committed by CitadelStationBot
parent 9a30c288f0
commit 8cbad06f35
6 changed files with 71 additions and 7 deletions
+7
View File
@@ -1048,6 +1048,13 @@
if (client)
if (new_z)
SSmobs.clients_by_zlevel[new_z] += src
for (var/I in length(SSidlenpcpool.idle_mobs_by_zlevel[new_z]) to 1 step -1) //Backwards loop because we're removing (guarantees optimal rather than worst-case performance), it's fine to use .len here but doesn't compile on 511
var/mob/living/simple_animal/SA = SSidlenpcpool.idle_mobs_by_zlevel[new_z][I]
if (SA)
SA.toggle_ai(AI_ON) // Guarantees responsiveness for when appearing right next to mobs
else
SSidlenpcpool.idle_mobs_by_zlevel[new_z] -= SA
registered_z = new_z
else
registered_z = null
@@ -288,7 +288,7 @@
if(search_objects)//Turn off item searching and ignore whatever item we were looking at, we're more concerned with fight or flight
target = null
LoseSearchObjects()
if(AIStatus == AI_IDLE)
if(AIStatus != AI_ON && AIStatus != AI_OFF)
toggle_ai(AI_ON)
FindTarget()
else if(target != null && prob(40))//No more pulling a mob forever and having a second player attack it, it can switch targets now if it finds a more suitable one
@@ -479,6 +479,31 @@ mob/living/simple_animal/hostile/proc/DestroySurroundings() // for use with mega
/mob/living/simple_animal/hostile/consider_wakeup()
..()
if(AIStatus == AI_IDLE && FindTarget(ListTargets(), 1))
var/list/tlist
var/turf/T = get_turf(src)
if (!T)
return
if (!length(SSmobs.clients_by_zlevel[T.z])) // It's fine to use .len here but doesn't compile on 511
toggle_ai(AI_Z_OFF)
return
if (isturf(T) && !(T.z in GLOB.station_z_levels))
tlist = ListTargetsLazy(T.z)
else
tlist = ListTargets()
if(AIStatus == AI_IDLE && FindTarget(tlist, 1))
toggle_ai(AI_ON)
/mob/living/simple_animal/hostile/proc/ListTargetsLazy(var/_Z)//Step 1, find out what we can see
var/static/hostile_machines = typecacheof(list(/obj/machinery/porta_turret, /obj/mecha, /obj/structure/destructible/clockwork/ocular_warden))
. = list()
for (var/I in SSmobs.clients_by_zlevel[_Z])
var/mob/M = I
if (get_dist(M, src) < vision_range)
if (isturf(M.loc))
. += M
else if (M.loc.type in hostile_machines)
. += M.loc
@@ -82,14 +82,18 @@
var/dextrous_hud_type = /datum/hud/dextrous
var/datum/personal_crafting/handcrafting
var/AIStatus = AI_ON //The Status of our AI, can be set to AI_ON (On, usual processing), AI_IDLE (Will not process, but will return to AI_ON if an enemy comes near), AI_OFF (Off, Not processing ever)
var/AIStatus = AI_ON //The Status of our AI, can be set to AI_ON (On, usual processing), AI_IDLE (Will not process, but will return to AI_ON if an enemy comes near), AI_OFF (Off, Not processing ever), AI_Z_OFF (Temporarily off due to nonpresence of players)
var/shouldwakeup = FALSE //convenience var for forcibly waking up an idling AI on next check.
//domestication
var/tame = 0
<<<<<<< HEAD
no_vore = TRUE
=======
var/my_z // I don't want to confuse this with client registered_z
>>>>>>> d03e4ef... Advanced mob laziness (#33574)
/mob/living/simple_animal/Initialize()
. = ..()
@@ -544,7 +548,13 @@
/mob/living/simple_animal/proc/toggle_ai(togglestatus)
if (AIStatus != togglestatus)
if (togglestatus > 0 && togglestatus < 4)
if (togglestatus > 0 && togglestatus < 5)
if (togglestatus == AI_Z_OFF || AIStatus == AI_Z_OFF)
var/turf/T = get_turf(src)
if (AIStatus == AI_Z_OFF)
SSidlenpcpool.idle_mobs_by_zlevel[T.z] -= src
else
SSidlenpcpool.idle_mobs_by_zlevel[T.z] += src
GLOB.simple_animals[AIStatus] -= src
GLOB.simple_animals[togglestatus] += src
AIStatus = togglestatus
@@ -559,4 +569,11 @@
. = ..()
if(!ckey && !stat)//Not unconscious
if(AIStatus == AI_IDLE)
toggle_ai(AI_ON)
toggle_ai(AI_ON)
/mob/living/simple_animal/onTransitZ(old_z, new_z)
..()
if (AIStatus == AI_Z_OFF)
SSidlenpcpool[old_z] -= src
toggle_ai(initial(AIStatus))