From 0a609c34d4b45f8455fab9b98211bab1b2ca4a80 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 18 Dec 2023 20:01:05 +0100 Subject: [PATCH] [MIRROR] Fixes a hard del in monkey AI [MDB IGNORE] (#25713) * Fixes a hard del in monkey AI (#80425) ## About The Pull Request ![firefox_KI4H4wxvN3](https://github.com/tgstation/tgstation/assets/13398309/6e8c18f3-2413-4eaf-8436-15fd7aea9c51) Fixes this hard del, caused by a del-on-death mob being qdeleted after being victim to the monkey's attack. When a mob gets qdeleted, they remove themselves from the blackboard. Monkey code was then adding it back immediately after, resulting in the hard del. Adds safeties to ensure that won't happen. ## Why It's Good For The Game Less annoying CI failures ## Changelog :cl: fix: monkeys will no longer cause other monkeys to get angry at the mobs they just poofed by attacking /:cl: * Fixes a hard del in monkey AI --------- Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> --- code/datums/ai/_ai_controller.dm | 2 +- code/datums/ai/monkey/monkey_behaviors.dm | 8 +++++++- code/datums/ai/monkey/monkey_controller.dm | 8 ++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/code/datums/ai/_ai_controller.dm b/code/datums/ai/_ai_controller.dm index 06a4aac8358..6bbdabfc50d 100644 --- a/code/datums/ai/_ai_controller.dm +++ b/code/datums/ai/_ai_controller.dm @@ -340,7 +340,7 @@ multiple modular subtrees with behaviors set_ai_status(AI_STATUS_ON) //Can't do anything while player is connected RegisterSignal(pawn, COMSIG_MOB_LOGIN, PROC_REF(on_sentience_gained)) -// Turn the controller off the controller if the pawn has been qdeleted +// Turn the controller off if the pawn has been qdeleted /datum/ai_controller/proc/on_pawn_qdeleted() SIGNAL_HANDLER set_ai_status(AI_STATUS_OFF) diff --git a/code/datums/ai/monkey/monkey_behaviors.dm b/code/datums/ai/monkey/monkey_behaviors.dm index b041ec763a8..d16110cd702 100644 --- a/code/datums/ai/monkey/monkey_behaviors.dm +++ b/code/datums/ai/monkey/monkey_behaviors.dm @@ -221,6 +221,12 @@ // note they might immediately reduce threat and drop from the list. // this is fine, we're just giving them a love tap then leaving them alone. // unless they fight back, then we retaliate + + // Some mobs delete on death. If the target is no longer alive, go back to idle + if(QDELETED(target)) + finish_action(controller, TRUE) + return + if(isnull(controller.blackboard[BB_MONKEY_ENEMIES][target])) controller.set_blackboard_key_assoc(BB_MONKEY_ENEMIES, target, 1) @@ -298,7 +304,7 @@ var/mob/living/living_pawn = controller.pawn for(var/mob/living/nearby_monkey in view(living_pawn, MONKEY_ENEMY_VISION)) - if(!HAS_AI_CONTROLLER_TYPE(nearby_monkey, /datum/ai_controller/monkey)) + if(QDELETED(nearby_monkey) || !HAS_AI_CONTROLLER_TYPE(nearby_monkey, /datum/ai_controller/monkey)) continue if(!SPT_PROB(MONKEY_RECRUIT_PROB, seconds_per_tick)) continue diff --git a/code/datums/ai/monkey/monkey_controller.dm b/code/datums/ai/monkey/monkey_controller.dm index 951147007f9..781bfb70a85 100644 --- a/code/datums/ai/monkey/monkey_controller.dm +++ b/code/datums/ai/monkey/monkey_controller.dm @@ -147,8 +147,12 @@ have ways of interacting with a specific mob and control it. return TRUE ///Reactive events to being hit -/datum/ai_controller/monkey/proc/retaliate(mob/living/L) - add_blackboard_key_assoc(BB_MONKEY_ENEMIES, L, MONKEY_HATRED_AMOUNT) +/datum/ai_controller/monkey/proc/retaliate(mob/living/living_mob) + // just to be safe + if(QDELETED(living_mob)) + return + + add_blackboard_key_assoc(BB_MONKEY_ENEMIES, living_mob, MONKEY_HATRED_AMOUNT) /datum/ai_controller/monkey/proc/on_attacked(datum/source, mob/attacker) SIGNAL_HANDLER