From d48279ea476f208a6cfd579521cb87e57c0338fa Mon Sep 17 00:00:00 2001 From: Gaxeer <44334376+Gaxeer@users.noreply.github.com> Date: Fri, 15 Dec 2023 21:14:21 +0200 Subject: [PATCH] fix: remove `owner` requiring dependencies from `/datum/antagonist` only if `owner` is present (#23509) * fix: remove `owner` requiring dependencies from `/datum/antagonist` only if `owner` is present * refactor: move owner related dependencies removal into separate proc --- .../antagonists/_common/antag_datum.dm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/code/modules/antagonists/_common/antag_datum.dm b/code/modules/antagonists/_common/antag_datum.dm index 339fde58bbc..9dbe8cd3914 100644 --- a/code/modules/antagonists/_common/antag_datum.dm +++ b/code/modules/antagonists/_common/antag_datum.dm @@ -42,19 +42,30 @@ GLOBAL_LIST_EMPTY(antagonists) /datum/antagonist/Destroy(force, ...) qdel(objective_holder) - remove_owner_from_gamemode() GLOB.antagonists -= src + if(!QDELETED(owner)) + detach_from_owner() + + return ..() + +/** + * Removes owner's dependencies on this antag datum. + * For example: removal of antag datum from owner's `antag_datums`, antag datum related teams etc. + * If your `/datum/antagonist` subtype adds more dependencies on `owner` - they should be cleared there. + */ +/datum/antagonist/proc/detach_from_owner() + SHOULD_CALL_PARENT(TRUE) + + remove_owner_from_gamemode() if(!silent) farewell() remove_innate_effects() antag_memory = null var/datum/team/team = get_team() team?.remove_member(owner) - if(owner) - LAZYREMOVE(owner.antag_datums, src) + LAZYREMOVE(owner.antag_datums, src) restore_last_hud_and_role() owner = null - return ..() /** * Adds the owner to their respective gamemode's list. For example `SSticker.mode.traitors |= owner`.