From a803b21a6c7b3f9ff8c578f4f4ebe911100cfec2 Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Fri, 11 Aug 2023 11:40:15 -0700 Subject: [PATCH] Adds Source Count Macro (#77519) ## About The Pull Request I prefer this to having people manually read the list, plus it seems like reasonable information to expose, especially if we're gonna start using it in this pattern. ## Why It's Good For The Game Less futzing with internals --- code/__DEFINES/traits.dm | 4 +++- code/datums/elements/sticker.dm | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/code/__DEFINES/traits.dm b/code/__DEFINES/traits.dm index 38afa0e9c0b..67c2ea402b5 100644 --- a/code/__DEFINES/traits.dm +++ b/code/__DEFINES/traits.dm @@ -115,7 +115,9 @@ #define HAS_TRAIT_NOT_FROM(target, trait, source) (HAS_TRAIT(target, trait) && (length(target._status_traits[trait] - source) > 0)) /// Returns a list of trait sources for this trait. Only useful for wacko cases and internal futzing /// You should not be using this -#define GET_TRAIT_SOURCES(target, trait) target._status_traits?[trait] || list() +#define GET_TRAIT_SOURCES(target, trait) (target._status_traits?[trait] || list()) +/// Returns the amount of sources for a trait. useful if you don't want to have a "thing counter" stuck around all the time +#define COUNT_TRAIT_SOURCES(target, trait) length(GET_TRAIT_SOURCES(target, trait)) /// A simple helper for checking traits in a mob's mind #define HAS_MIND_TRAIT(target, trait) (HAS_TRAIT(target, trait) || (target.mind ? HAS_TRAIT(target.mind, trait) : FALSE)) diff --git a/code/datums/elements/sticker.dm b/code/datums/elements/sticker.dm index 57b63dad894..3cc8e977daf 100644 --- a/code/datums/elements/sticker.dm +++ b/code/datums/elements/sticker.dm @@ -39,7 +39,7 @@ ///Add our stick_type to the target with px and py as pixel x and pixel y respectively /datum/element/sticker/proc/do_stick(obj/item/source, atom/target, mob/living/user, px, py) - if(length(GET_TRAIT_SOURCES(target, TRAIT_STICKERED)) >= MAX_ALLOWED_STICKERS) + if(COUNT_TRAIT_SOURCES(target, TRAIT_STICKERED) >= MAX_ALLOWED_STICKERS) source.balloon_alert_to_viewers("sticker won't stick!") return FALSE target.AddComponent(stick_type, px, py, source, user, washable)