diff --git a/code/__DEFINES/antagonists.dm b/code/__DEFINES/antagonists.dm new file mode 100644 index 00000000000..e69de29bb2d diff --git a/code/datums/antagonists/antag_datum.dm b/code/datums/antagonists/antag_datum.dm new file mode 100644 index 00000000000..1af50313c69 --- /dev/null +++ b/code/datums/antagonists/antag_datum.dm @@ -0,0 +1,64 @@ +var/global/list/antagonists = list() + +/datum/antagonist + var/name = "Antagonist" + var/datum/mind/owner //Mind that owns this datum + var/silent = FALSE //Silent will prevent the gain/lose texts to show + var/can_coexist_with_others = TRUE //Whether or not the person will be able to have more than one datum + var/list/typecache_datum_blacklist = list() //List of datums this type can't coexist with + var/delete_on_mind_deletion = TRUE + +/datum/antagonist/New(datum/mind/new_owner) + antagonists += src + typecache_datum_blacklist = typecacheof(typecache_datum_blacklist) + if(new_owner) + owner = new_owner + +/datum/antagonist/Destroy() + antagonists -= src + if(owner) + LAZYREMOVE(owner.antag_datums, src) + owner = null + return ..() + +/datum/antagonist/proc/can_be_owned(datum/mind/new_owner) + . = TRUE + if(owner.has_antag_datum(type)) + return FALSE + for(var/i in owner.antag_datums) + var/datum/antagonist/A = i + if(is_type_in_typecache(src, A.typecache_datum_blacklist)) + return FALSE + +/datum/antagonist/proc/on_body_transfer(mob/living/old_body, mob/living/new_body) + remove_innate_effects(old_body) + apply_innate_effects(new_body) + +//This handles the application of antag huds/special abilities +/datum/antagonist/proc/apply_innate_effects(mob/living/mob_override) + return + +//This handles the removal of antag huds/special abilities +/datum/antagonist/proc/remove_innate_effects(mob/living/mob_override) + return + +//Proc called when the datum is given to a mind. +/datum/antagonist/proc/on_gain() + if(owner && owner.current) + if(!silent) + greet() + apply_innate_effects() + +/datum/antagonist/proc/on_removal() + remove_innate_effects() + if(owner) + LAZYREMOVE(owner.antag_datums, src) + if(!silent && owner.current) + farewell() + qdel(src) + +/datum/antagonist/proc/greet() + return + +/datum/antagonist/proc/farewell() + return \ No newline at end of file diff --git a/code/datums/mind.dm b/code/datums/mind.dm index 3e1c3207a87..1a1f28ebc31 100644 --- a/code/datums/mind.dm +++ b/code/datums/mind.dm @@ -54,6 +54,7 @@ var/has_been_rev = 0//Tracks if this mind has been a rev or not var/miming = 0 // Mime's vow of silence + var/list/antag_datums = list() var/speech_span // What span any body this mind has talks in. var/datum/faction/faction //associated faction var/datum/changeling/changeling //changeling holder @@ -83,6 +84,7 @@ /datum/mind/proc/transfer_to(mob/living/new_character) var/datum/atom_hud/antag/hud_to_transfer = antag_hud //we need this because leave_hud() will clear this list + var/mob/living/old_current = current if(!istype(new_character)) log_runtime(EXCEPTION("transfer_to(): Some idiot has tried to transfer_to() a non mob/living mob."), src) if(current) //remove ourself from our old body's mind variable @@ -95,6 +97,9 @@ new_character.mind.current = null current = new_character //link ourself to our new body new_character.mind = src //and link our new body to ourself + for(var/a in antag_datums) //Makes sure all antag datums effects are applied in the new body + var/datum/antagonist/A = a + A.on_body_transfer(old_current, current) transfer_antag_huds(hud_to_transfer) //inherit the antag HUD transfer_actions(new_character) @@ -1243,6 +1248,53 @@ */ + +// Datum antag mind procs +/datum/mind/proc/add_antag_datum(datum_type, on_gain = TRUE) + if(!datum_type) + return + if(!can_hold_antag_datum(datum_type)) + return + var/datum/antagonist/A = new datum_type(src) + antag_datums += A + if(on_gain) + A.on_gain() + +/datum/mind/proc/remove_antag_datum(datum_type) + if(!datum_type) + return + var/datum/antagonist/A = has_antag_datum(datum_type) + if(A) + A.on_removal() + +/datum/mind/proc/remove_all_antag_datums() //For the Lazy amongst us. + for(var/a in antag_datums) + var/datum/antagonist/A = a + A.on_removal() + +/datum/mind/proc/has_antag_datum(datum_type, check_subtypes = TRUE) + if(!datum_type) + return + . = FALSE + for(var/a in antag_datums) + var/datum/antagonist/A = a + if(check_subtypes && istype(A, datum_type)) + return A + else if(A.type == datum_type) + return A + +/datum/mind/proc/can_hold_antag_datum(datum_type) + if(!datum_type) + return + . = TRUE + if(has_antag_datum(datum_type)) + return FALSE + for(var/i in antag_datums) + var/datum/antagonist/A = i + if(is_type_in_typecache(A, A.typecache_datum_blacklist)) + return FALSE + + /datum/mind/proc/find_syndicate_uplink() var/list/L = current.get_contents() for(var/obj/item/I in L) diff --git a/paradise.dme b/paradise.dme index d2239b98e70..6149d7f1941 100644 --- a/paradise.dme +++ b/paradise.dme @@ -17,6 +17,7 @@ #include "code\world.dm" #include "code\__DEFINES\_readme.dm" #include "code\__DEFINES\admin.dm" +#include "code\__DEFINES\antagonists.dm" #include "code\__DEFINES\atmospherics.dm" #include "code\__DEFINES\bots.dm" #include "code\__DEFINES\callbacks.dm" @@ -226,6 +227,7 @@ #include "code\datums\uplink_item.dm" #include "code\datums\vision_override.dm" #include "code\datums\vr.dm" +#include "code\datums\antagonists\antag_datum.dm" #include "code\datums\cache\air_alarm.dm" #include "code\datums\cache\apc.dm" #include "code\datums\cache\cache.dm"