From ca98ea1f0d6612efe6495a9d7c3b1fa67320070a Mon Sep 17 00:00:00 2001 From: Rohesie Date: Tue, 31 Mar 2020 05:19:40 -0300 Subject: [PATCH] Adds signals for gaining and losing traits (#50269) * Trait signals * floyd and spooky review --- code/__DEFINES/traits.dm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/code/__DEFINES/traits.dm b/code/__DEFINES/traits.dm index 148187021bf..4f14e08864a 100644 --- a/code/__DEFINES/traits.dm +++ b/code/__DEFINES/traits.dm @@ -1,3 +1,6 @@ +#define SIGNAL_ADDTRAIT(trait_ref) "addtrait [trait_ref]" +#define SIGNAL_REMOVETRAIT(trait_ref) "removetrait [trait_ref]" + // trait accessor defines #define ADD_TRAIT(target, trait, source) \ do { \ @@ -6,12 +9,14 @@ target.status_traits = list(); \ _L = target.status_traits; \ _L[trait] = list(source); \ + SEND_SIGNAL(target, SIGNAL_ADDTRAIT(trait)); \ } else { \ _L = target.status_traits; \ if (_L[trait]) { \ _L[trait] |= list(source); \ } else { \ _L[trait] = list(source); \ + SEND_SIGNAL(target, SIGNAL_ADDTRAIT(trait)); \ } \ } \ } while (0) @@ -31,7 +36,8 @@ } \ };\ if (!length(_L[trait])) { \ - _L -= trait \ + _L -= trait; \ + SEND_SIGNAL(target, SIGNAL_REMOVETRAIT(trait)); \ }; \ if (!length(_L)) { \ target.status_traits = null \ @@ -46,11 +52,13 @@ for (var/_T in _L) { \ _L[_T] &= _S;\ if (!length(_L[_T])) { \ - _L -= _T } \ - };\ - if (!length(_L)) { \ - target.status_traits = null\ + _L -= _T; \ + SEND_SIGNAL(target, SIGNAL_REMOVETRAIT(_T)); \ + }; \ };\ + if (!length(_L)) { \ + target.status_traits = null\ + };\ }\ } while (0) #define HAS_TRAIT(target, trait) (target.status_traits ? (target.status_traits[trait] ? TRUE : FALSE) : FALSE)