From 8cbad06f3543e43607b72e17af7f5d98856643a8 Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Mon, 18 Dec 2017 03:35:37 +0200 Subject: [PATCH 1/4] Advanced mob laziness --- code/__DEFINES/mobs.dm | 1 + code/_globalvars/lists/mobs.dm | 2 +- code/controllers/subsystem/idlenpcpool.dm | 16 +++++++++- code/modules/mob/living/living.dm | 7 +++++ .../living/simple_animal/hostile/hostile.dm | 29 +++++++++++++++++-- .../mob/living/simple_animal/simple_animal.dm | 23 +++++++++++++-- 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/code/__DEFINES/mobs.dm b/code/__DEFINES/mobs.dm index 49e3c996fe..1cc5f7021d 100644 --- a/code/__DEFINES/mobs.dm +++ b/code/__DEFINES/mobs.dm @@ -108,6 +108,7 @@ #define AI_ON 1 #define AI_IDLE 2 #define AI_OFF 3 +#define AI_Z_OFF 4 //determines if a mob can smash through it #define ENVIRONMENT_SMASH_NONE 0 diff --git a/code/_globalvars/lists/mobs.dm b/code/_globalvars/lists/mobs.dm index 89e4481284..c2acea2753 100644 --- a/code/_globalvars/lists/mobs.dm +++ b/code/_globalvars/lists/mobs.dm @@ -22,7 +22,7 @@ GLOBAL_LIST_EMPTY(carbon_list) //all instances of /mob/living/carbon and subt GLOBAL_LIST_EMPTY(ai_list) GLOBAL_LIST_EMPTY(pai_list) GLOBAL_LIST_EMPTY(available_ai_shells) -GLOBAL_LIST_INIT(simple_animals, list(list(),list(),list())) // One for each AI_* status define +GLOBAL_LIST_INIT(simple_animals, list(list(),list(),list(),list())) // One for each AI_* status define GLOBAL_LIST_EMPTY(spidermobs) //all sentient spider mobs GLOBAL_LIST_EMPTY(bots_list) diff --git a/code/controllers/subsystem/idlenpcpool.dm b/code/controllers/subsystem/idlenpcpool.dm index 49846e6c9d..18c3b3cf30 100644 --- a/code/controllers/subsystem/idlenpcpool.dm +++ b/code/controllers/subsystem/idlenpcpool.dm @@ -1,15 +1,26 @@ SUBSYSTEM_DEF(idlenpcpool) name = "Idling NPC Pool" +<<<<<<< HEAD flags = SS_POST_FIRE_TIMING|SS_NO_INIT|SS_BACKGROUND priority = 10 +======= + flags = SS_POST_FIRE_TIMING|SS_BACKGROUND + priority = FIRE_PRIORITY_IDLE_NPC +>>>>>>> d03e4ef... Advanced mob laziness (#33574) wait = 60 runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME var/list/currentrun = list() + var/static/list/idle_mobs_by_zlevel[][] /datum/controller/subsystem/idlenpcpool/stat_entry() var/list/idlelist = GLOB.simple_animals[AI_IDLE] - ..("IdleNPCS:[idlelist.len]") + var/list/zlist = GLOB.simple_animals[AI_Z_OFF] + ..("IdleNPCS:[idlelist.len]|Z:[zlist.len]") + +/datum/controller/subsystem/idlenpcpool/Initialize(start_timeofday) + idle_mobs_by_zlevel = new /list(world.maxz,0) + return ..() /datum/controller/subsystem/idlenpcpool/fire(resumed = FALSE) @@ -24,6 +35,9 @@ SUBSYSTEM_DEF(idlenpcpool) while(currentrun.len) var/mob/living/simple_animal/SA = currentrun[currentrun.len] --currentrun.len + if (!SA) + GLOB.simple_animals[AI_IDLE] -= SA + continue if(!SA.ckey) if(SA.stat != DEAD) diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index f589ecbb20..04c9fef63b 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -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 diff --git a/code/modules/mob/living/simple_animal/hostile/hostile.dm b/code/modules/mob/living/simple_animal/hostile/hostile.dm index 10d9fd93d7..f5e69dc7a0 100644 --- a/code/modules/mob/living/simple_animal/hostile/hostile.dm +++ b/code/modules/mob/living/simple_animal/hostile/hostile.dm @@ -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 diff --git a/code/modules/mob/living/simple_animal/simple_animal.dm b/code/modules/mob/living/simple_animal/simple_animal.dm index a4851bb432..020e105d9a 100644 --- a/code/modules/mob/living/simple_animal/simple_animal.dm +++ b/code/modules/mob/living/simple_animal/simple_animal.dm @@ -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) \ No newline at end of file + 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)) \ No newline at end of file From 2205500863c8023e82e14698518e2ec53b8d2d1c Mon Sep 17 00:00:00 2001 From: LetterJay Date: Mon, 18 Dec 2017 15:15:21 -0600 Subject: [PATCH 2/4] Update idlenpcpool.dm --- code/controllers/subsystem/idlenpcpool.dm | 5 ----- 1 file changed, 5 deletions(-) diff --git a/code/controllers/subsystem/idlenpcpool.dm b/code/controllers/subsystem/idlenpcpool.dm index 18c3b3cf30..a15237e5a7 100644 --- a/code/controllers/subsystem/idlenpcpool.dm +++ b/code/controllers/subsystem/idlenpcpool.dm @@ -1,12 +1,7 @@ SUBSYSTEM_DEF(idlenpcpool) name = "Idling NPC Pool" -<<<<<<< HEAD - flags = SS_POST_FIRE_TIMING|SS_NO_INIT|SS_BACKGROUND - priority = 10 -======= flags = SS_POST_FIRE_TIMING|SS_BACKGROUND priority = FIRE_PRIORITY_IDLE_NPC ->>>>>>> d03e4ef... Advanced mob laziness (#33574) wait = 60 runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME From 8fde63e016f8bc0d65288c7020b4fb64242758e9 Mon Sep 17 00:00:00 2001 From: LetterJay Date: Mon, 18 Dec 2017 15:15:34 -0600 Subject: [PATCH 3/4] Update simple_animal.dm --- code/modules/mob/living/simple_animal/simple_animal.dm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/code/modules/mob/living/simple_animal/simple_animal.dm b/code/modules/mob/living/simple_animal/simple_animal.dm index 020e105d9a..04735178d3 100644 --- a/code/modules/mob/living/simple_animal/simple_animal.dm +++ b/code/modules/mob/living/simple_animal/simple_animal.dm @@ -88,12 +88,8 @@ //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() . = ..() @@ -576,4 +572,4 @@ ..() if (AIStatus == AI_Z_OFF) SSidlenpcpool[old_z] -= src - toggle_ai(initial(AIStatus)) \ No newline at end of file + toggle_ai(initial(AIStatus)) From e395cded9d2d71a10a21e0272a44f9bf126632d4 Mon Sep 17 00:00:00 2001 From: LetterJay Date: Tue, 2 Jan 2018 04:34:21 -0600 Subject: [PATCH 4/4] cl --- html/changelogs/AutoChangeLog-pr-4628.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 html/changelogs/AutoChangeLog-pr-4628.yml diff --git a/html/changelogs/AutoChangeLog-pr-4628.yml b/html/changelogs/AutoChangeLog-pr-4628.yml new file mode 100644 index 0000000000..08311f545a --- /dev/null +++ b/html/changelogs/AutoChangeLog-pr-4628.yml @@ -0,0 +1,4 @@ +author: "deathride58" +delete-after: True +changes: + - bugfix: "Vore is now actually fixed. Fuck."