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`.