Skip to content

Commit

Permalink
[MIRROR] Fixes a hard del in monkey AI [MDB IGNORE] (#1194)
Browse files Browse the repository at this point in the history
* Fixes a hard del in monkey AI (#80425)

---------

Co-authored-by: SkyratBot <[email protected]>
Co-authored-by: Bloop <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent 1456625 commit df34db7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion code/datums/ai/_ai_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion code/datums/ai/monkey/monkey_behaviors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions code/datums/ai/monkey/monkey_controller.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df34db7

Please sign in to comment.