diff --git a/code/datums/datum.dm b/code/datums/datum.dm index e74e30b5366a..cdb195dd821b 100644 --- a/code/datums/datum.dm +++ b/code/datums/datum.dm @@ -2,6 +2,7 @@ var/gc_destroyed //Time when this object was destroyed. var/list/active_timers //for SStimer var/list/datum_components //for /datum/components + var/list/status_traits var/list/comp_lookup //it used to be for looking up components which had registered a signal but now anything can register var/list/signal_procs var/signal_enabled = FALSE diff --git a/code/datums/traits.dm b/code/datums/traits.dm new file mode 100644 index 000000000000..c105865b11ea --- /dev/null +++ b/code/datums/traits.dm @@ -0,0 +1,75 @@ +/datum/proc/add_trait(trait, source) + LAZYINITLIST(status_traits) + + if(!status_traits[trait]) + status_traits[trait] = list(source) + else + status_traits[trait] |= list(source) + + +/datum/proc/remove_trait(trait, list/sources, force) + if(!status_traits) + return //nothing to remove + + if(!status_traits[trait]) + return + + if(locate(ROUNDSTART_TRAIT) in status_traits[trait] && !force) //mob traits applied through roundstart cannot normally be removed + return + + if(!sources) // No defined source cures the trait entirely. + status_traits -= trait + return + + if(!islist(sources)) + sources = list(sources) + + if(LAZYLEN(sources)) + for(var/S in sources) + if(S in status_traits[trait]) + status_traits[trait] -= S + else + status_traits[trait] = list() + + if(!LAZYLEN(status_traits[trait])) + status_traits -= trait + +/datum/proc/has_trait(trait, list/sources) + if(!status_traits) + return FALSE //well of course it doesn't have the trait + + if(!status_traits[trait]) + return FALSE + + . = FALSE + + if(sources && !islist(sources)) + sources = list(sources) + if(LAZYLEN(sources)) + for(var/S in sources) + if(S in status_traits[trait]) + return TRUE + else if(LAZYLEN(status_traits[trait])) + return TRUE + +/datum/proc/remove_all_traits(remove_species_traits = FALSE, remove_organ_traits = FALSE, remove_quirks = FALSE) + if(!status_traits) + return //nothing to remove + + var/list/blacklisted_sources = list() + if(!remove_species_traits) + blacklisted_sources += SPECIES_TRAIT + if(!remove_organ_traits) + blacklisted_sources += ORGAN_TRAIT + if(!remove_quirks) + blacklisted_sources += ROUNDSTART_TRAIT + + for(var/kebab in status_traits) + var/skip + for(var/S in blacklisted_sources) + if(S in status_traits[kebab]) + skip = TRUE + break + if(!skip) + remove_trait(kebab, null, TRUE) + CHECK_TICK \ No newline at end of file diff --git a/code/game/objects/items/weaponry.dm b/code/game/objects/items/weaponry.dm index 74e649a09dab..8b1766722ec1 100644 --- a/code/game/objects/items/weaponry.dm +++ b/code/game/objects/items/weaponry.dm @@ -114,10 +114,10 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301 /obj/item/claymore/highlander/pickup(mob/living/user) to_chat(user, "The power of Scotland protects you! You are shielded from all stuns and knockdowns.") user.add_stun_absorption("highlander", INFINITY, 1, " is protected by the power of Scotland!", "The power of Scotland absorbs the stun!", " is protected by the power of Scotland!") - user.add_trait(TRAIT_IGNORESLOWDOWN, HIGHLANDER) + user.ignore_slowdown(HIGHLANDER) /obj/item/claymore/highlander/dropped(mob/living/user) - user.remove_trait(TRAIT_IGNORESLOWDOWN, HIGHLANDER) + user.unignore_slowdown(HIGHLANDER) if(!QDELETED(src)) qdel(src) //If this ever happens, it's because you lost an arm diff --git a/code/modules/mob/living/living_defines.dm b/code/modules/mob/living/living_defines.dm index 309e9d9fe427..1e90894fff82 100644 --- a/code/modules/mob/living/living_defines.dm +++ b/code/modules/mob/living/living_defines.dm @@ -33,8 +33,6 @@ var/incorporeal_move = FALSE //FALSE is off, INCORPOREAL_MOVE_BASIC is normal, INCORPOREAL_MOVE_SHADOW is for ninjas //and INCORPOREAL_MOVE_JAUNT is blocked by holy water/salt - var/list/status_traits = list() - var/list/roundstart_quirks = list() var/list/surgeries = list() //a list of surgery datums. generally empty, they're added when the player wants them. diff --git a/code/modules/mob/living/status_procs.dm b/code/modules/mob/living/status_procs.dm index be98d1bfabd0..5baa42ffa23a 100644 --- a/code/modules/mob/living/status_procs.dm +++ b/code/modules/mob/living/status_procs.dm @@ -139,18 +139,6 @@ return TRUE /////////////////////////////////// DISABILITIES //////////////////////////////////// - -/mob/living/proc/add_trait(trait, source) - if(!status_traits[trait]) - status_traits[trait] = list(source) - on_add_trait(trait, source) - else - status_traits[trait] |= list(source) - -/mob/living/proc/on_add_trait(trait, source) - if(trait == TRAIT_IGNORESLOWDOWN) - update_movespeed(FALSE) - /mob/living/proc/add_quirk(quirk, spawn_effects) //separate proc due to the way these ones are handled if(has_trait(quirk)) return @@ -160,80 +148,15 @@ new T (src, spawn_effects) return TRUE -/mob/living/proc/remove_trait(trait, list/sources, force) - if(!status_traits[trait]) - return - - if(locate(ROUNDSTART_TRAIT) in status_traits[trait] && !force) //mob traits applied through roundstart cannot normally be removed - return - - if(!sources) // No defined source cures the trait entirely. - status_traits -= trait - on_remove_trait(trait, sources, force) - return - - if(!islist(sources)) - sources = list(sources) - - if(LAZYLEN(sources)) - for(var/S in sources) - if(S in status_traits[trait]) - status_traits[trait] -= S - else - status_traits[trait] = list() - - if(!LAZYLEN(status_traits[trait])) - status_traits -= trait - on_remove_trait(trait, sources, force) - -/mob/living/proc/on_remove_trait(trait, list/sources, force) - if(trait == TRAIT_IGNORESLOWDOWN) - update_movespeed(FALSE) - /mob/living/proc/remove_quirk(quirk) var/datum/quirk/T = roundstart_quirks[quirk] if(T) qdel(T) return TRUE -/mob/living/proc/has_trait(trait, list/sources) - if(!status_traits[trait]) - return FALSE - - . = FALSE - - if(sources && !islist(sources)) - sources = list(sources) - if(LAZYLEN(sources)) - for(var/S in sources) - if(S in status_traits[trait]) - return TRUE - else if(LAZYLEN(status_traits[trait])) - return TRUE - /mob/living/proc/has_quirk(quirk) return roundstart_quirks[quirk] -/mob/living/proc/remove_all_traits(remove_species_traits = FALSE, remove_organ_traits = FALSE, remove_quirks = FALSE) - - var/list/blacklisted_sources = list() - if(!remove_species_traits) - blacklisted_sources += SPECIES_TRAIT - if(!remove_organ_traits) - blacklisted_sources += ORGAN_TRAIT - if(!remove_quirks) - blacklisted_sources += ROUNDSTART_TRAIT - - for(var/kebab in status_traits) - var/skip - for(var/S in blacklisted_sources) - if(S in status_traits[kebab]) - skip = TRUE - break - if(!skip) - remove_trait(kebab, null, TRUE) - CHECK_TICK - /////////////////////////////////// TRAIT PROCS //////////////////////////////////// /mob/living/proc/cure_blind(list/sources) @@ -283,4 +206,12 @@ add_trait(TRAIT_FAKEDEATH, source) add_trait(TRAIT_DEATHCOMA, source) tod = station_time_timestamp() - update_stat() \ No newline at end of file + update_stat() + +/mob/living/proc/unignore_slowdown(list/sources) + remove_trait(TRAIT_IGNORESLOWDOWN, sources) + update_movespeed(FALSE) + +/mob/living/proc/ignore_slowdown(source) + add_trait(TRAIT_IGNORESLOWDOWN, source) + update_movespeed(FALSE) \ No newline at end of file diff --git a/code/modules/reagents/chemistry/reagents/medicine_reagents.dm b/code/modules/reagents/chemistry/reagents/medicine_reagents.dm index aaa7e30de068..6ffe15143f47 100644 --- a/code/modules/reagents/chemistry/reagents/medicine_reagents.dm +++ b/code/modules/reagents/chemistry/reagents/medicine_reagents.dm @@ -623,10 +623,10 @@ /datum/reagent/medicine/morphine/on_mob_add(mob/living/L) ..() - L.add_trait(TRAIT_IGNORESLOWDOWN, id) + L.ignore_slowdown(id) /datum/reagent/medicine/morphine/on_mob_delete(mob/living/L) - L.remove_trait(TRAIT_IGNORESLOWDOWN, id) + L.unignore_slowdown(id) ..() /datum/reagent/medicine/morphine/on_mob_life(mob/living/carbon/M) @@ -1189,11 +1189,11 @@ /datum/reagent/medicine/muscle_stimulant/on_mob_add(mob/living/M) . = ..() - M.add_trait(TRAIT_IGNORESLOWDOWN, id) + M.ignore_slowdown(id) /datum/reagent/medicine/muscle_stimulant/on_mob_delete(mob/living/M) . = ..() - M.remove_trait(TRAIT_IGNORESLOWDOWN, id) + M.unignore_slowdown(id) /datum/reagent/medicine/modafinil name = "Modafinil" diff --git a/code/modules/research/xenobiology/crossbreeding/_status_effects.dm b/code/modules/research/xenobiology/crossbreeding/_status_effects.dm index ca334497a761..430a9ee5cdba 100644 --- a/code/modules/research/xenobiology/crossbreeding/_status_effects.dm +++ b/code/modules/research/xenobiology/crossbreeding/_status_effects.dm @@ -588,11 +588,11 @@ datum/status_effect/stabilized/blue/on_remove() colour = "red" /datum/status_effect/stabilized/red/on_apply() - owner.add_trait(TRAIT_IGNORESLOWDOWN,"slimestatus") + owner.ignore_slowdown("slimestatus") return ..() /datum/status_effect/stabilized/red/on_remove() - owner.remove_trait(TRAIT_IGNORESLOWDOWN,"slimestatus") + owner.unignore_slowdown("slimestatus") /datum/status_effect/stabilized/green id = "stabilizedgreen" diff --git a/tgstation.dme b/tgstation.dme index b741b0b899e4..a1c3ea90e079 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -309,6 +309,7 @@ #include "code\datums\shuttles.dm" #include "code\datums\soullink.dm" #include "code\datums\spawners_menu.dm" +#include "code\datums\traits.dm" #include "code\datums\verbs.dm" #include "code\datums\weakrefs.dm" #include "code\datums\world_topic.dm"