From d51fcdc9c8fe1dcf9e55b3ec6dd1b3c031cf04d6 Mon Sep 17 00:00:00 2001 From: Iajret Creature <122297233+Steals-The-PRs@users.noreply.github.com> Date: Thu, 15 Feb 2024 13:23:50 +0300 Subject: [PATCH] [MIRROR] Yeets CONSIG_ORGAN_WAG_TAIL (#1974) * Yeets CONSIG_ORGAN_WAG_TAIL (#81400) ## About The Pull Request It was dumb. LITERALLY just a proc. So let's replace it with a proc then, as a helper at least. I'll take this chance to disambiguate tail code to make it a bit less messy, and hand back usable args in case we want to react to our change in tail status ## Why It's Good For The Game Code's less shit (slightly) * Yeets CONSIG_ORGAN_WAG_TAIL * Removes some extra procs, fixes upstream bug * Update emote.dm --------- Co-authored-by: NovaBot <154629622+NovaBot13@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: Mal <13398309+vinylspiders@users.noreply.github.com> --- .../signals/signals_mob/signals_mob_living.dm | 2 - .../mood_events/generic_negative_events.dm | 4 +- code/game/objects/items/hand_items.dm | 6 +-- code/modules/mob/living/carbon/carbon.dm | 17 +++++++ code/modules/mob/living/carbon/human/emote.dm | 6 ++- code/modules/surgery/organs/external/tails.dm | 47 +++++++++--------- code/modules/unit_tests/tail_wag.dm | 18 +++---- .../mob/living/carbon/carbon_defense.dm | 2 +- .../mob/living/carbon/human/species.dm | 48 ++----------------- modular_nova/modules/customization/readme.md | 2 +- 10 files changed, 66 insertions(+), 86 deletions(-) diff --git a/code/__DEFINES/dcs/signals/signals_mob/signals_mob_living.dm b/code/__DEFINES/dcs/signals/signals_mob/signals_mob_living.dm index 2b113f853da..533ad2e1ae8 100644 --- a/code/__DEFINES/dcs/signals/signals_mob/signals_mob_living.dm +++ b/code/__DEFINES/dcs/signals/signals_mob/signals_mob_living.dm @@ -12,8 +12,6 @@ #define COMSIG_ORGAN_BEING_REPLACED "organ_being_replaced" /// Called when an organ gets surgically removed (mob/living/user, mob/living/carbon/old_owner, target_zone, obj/item/tool) #define COMSIG_ORGAN_SURGICALLY_REMOVED "organ_surgically_removed" -/// Called when using the *wag emote -#define COMSIG_ORGAN_WAG_TAIL "wag_tail" ///from base of mob/update_transform() #define COMSIG_LIVING_POST_UPDATE_TRANSFORM "living_post_update_transform" diff --git a/code/datums/mood_events/generic_negative_events.dm b/code/datums/mood_events/generic_negative_events.dm index cc3af071eef..afcb5d688ed 100644 --- a/code/datums/mood_events/generic_negative_events.dm +++ b/code/datums/mood_events/generic_negative_events.dm @@ -112,8 +112,8 @@ /datum/mood_event/table/add_effects() if(isfelinid(owner)) //Holy snowflake batman! - var/mob/living/carbon/human/H = owner - SEND_SIGNAL(H, COMSIG_ORGAN_WAG_TAIL, TRUE, 3 SECONDS) + var/mob/living/carbon/human/feline = owner + feline.wag_tail(3 SECONDS) description = "They want to play on the table!" mood_change = 2 diff --git a/code/game/objects/items/hand_items.dm b/code/game/objects/items/hand_items.dm index c6dc9cb7a2f..2255afe1054 100644 --- a/code/game/objects/items/hand_items.dm +++ b/code/game/objects/items/hand_items.dm @@ -219,9 +219,9 @@ /obj/item/hand_item/slapper/attack(mob/living/slapped, mob/living/carbon/human/user) SEND_SIGNAL(user, COMSIG_LIVING_SLAP_MOB, slapped) - if(ishuman(slapped)) - var/mob/living/carbon/human/human_slapped = slapped - SEND_SIGNAL(human_slapped, COMSIG_ORGAN_WAG_TAIL, FALSE) + if(iscarbon(slapped)) + var/mob/living/carbon/potential_tailed = slapped + potential_tailed.unwag_tail() user.do_attack_animation(slapped) var/slap_volume = 50 diff --git a/code/modules/mob/living/carbon/carbon.dm b/code/modules/mob/living/carbon/carbon.dm index 3e787525c2e..6d4e864238e 100644 --- a/code/modules/mob/living/carbon/carbon.dm +++ b/code/modules/mob/living/carbon/carbon.dm @@ -1444,3 +1444,20 @@ if(item && ((item in organs) || (item in bodyparts))) //let's not do this, aight? return FALSE return ..() + +/// Helper to cleanly trigger tail wagging +/// Accepts an optional timeout after which we remove the tail wagging +/// Returns true if successful, false otherwise +/mob/living/carbon/proc/wag_tail(timeout = INFINITY) + var/obj/item/organ/external/tail/wagged = get_organ_slot(ORGAN_SLOT_EXTERNAL_TAIL) + if(!wagged) + return FALSE + return wagged.start_wag(src, timeout) + +/// Helper to cleanly stop all tail wagging +/// Returns true if successful, false otherwise +/mob/living/carbon/proc/unwag_tail() // can't unwag a tail + var/obj/item/organ/external/tail/unwagged = get_organ_slot(ORGAN_SLOT_EXTERNAL_TAIL) + if(!unwagged) + return FALSE + return unwagged.stop_wag(src) diff --git a/code/modules/mob/living/carbon/human/emote.dm b/code/modules/mob/living/carbon/human/emote.dm index e3bbca427b2..00cf9c6802c 100644 --- a/code/modules/mob/living/carbon/human/emote.dm +++ b/code/modules/mob/living/carbon/human/emote.dm @@ -136,10 +136,12 @@ if(!.) return var/obj/item/organ/external/tail/oranges_accessory = user.get_organ_slot(ORGAN_SLOT_EXTERNAL_TAIL) + //I am so sorry my son + //We bypass helpers here cause we already have the tail if(oranges_accessory.wag_flags & WAG_WAGGING) //We verified the tail exists in can_run_emote() - SEND_SIGNAL(user, COMSIG_ORGAN_WAG_TAIL, FALSE) + oranges_accessory.stop_wag(src) else - SEND_SIGNAL(user, COMSIG_ORGAN_WAG_TAIL, TRUE) + oranges_accessory.start_wag(src) /datum/emote/living/carbon/human/wag/select_message_type(mob/user, intentional) . = ..() diff --git a/code/modules/surgery/organs/external/tails.dm b/code/modules/surgery/organs/external/tails.dm index 1e8cf71b5f0..5a9ffad05d3 100644 --- a/code/modules/surgery/organs/external/tails.dm +++ b/code/modules/surgery/organs/external/tails.dm @@ -23,7 +23,6 @@ /obj/item/organ/external/tail/Insert(mob/living/carbon/receiver, special, movement_flags) . = ..() if(.) - RegisterSignal(receiver, COMSIG_ORGAN_WAG_TAIL, PROC_REF(wag)) original_owner ||= WEAKREF(receiver) receiver.clear_mood_event("tail_lost") @@ -74,54 +73,58 @@ . = ..() if(wag_flags & WAG_WAGGING) - wag(organ_owner, start = FALSE) - - UnregisterSignal(organ_owner, COMSIG_ORGAN_WAG_TAIL) + stop_wag(organ_owner) if(type in organ_owner.dna.species.external_organs) organ_owner.add_mood_event("tail_lost", /datum/mood_event/tail_lost) organ_owner.add_mood_event("tail_balance_lost", /datum/mood_event/tail_balance_lost) -/obj/item/organ/external/tail/proc/wag(mob/living/carbon/organ_owner, start = TRUE, stop_after = 0) - if(!(wag_flags & WAG_ABLE)) - return - - if(start) - if(start_wag(organ_owner) && stop_after) - addtimer(CALLBACK(src, PROC_REF(wag), organ_owner, FALSE), stop_after, TIMER_STOPPABLE|TIMER_DELETE_ME) - else - stop_wag(organ_owner) - ///We need some special behaviour for accessories, wrapped here so we can easily add more interactions later -/obj/item/organ/external/tail/proc/start_wag(mob/living/carbon/organ_owner) - if(wag_flags & WAG_WAGGING) // we are already wagging +///Accepts an optional timeout after which we remove the tail wagging +///Returns false if the wag worked, true otherwise +/obj/item/organ/external/tail/proc/start_wag(mob/living/carbon/organ_owner, stop_after = INFINITY) + if(wag_flags & WAG_WAGGING || !(wag_flags & WAG_ABLE)) // we are already wagging return FALSE if(organ_owner.stat == DEAD || organ_owner != owner) // no wagging when owner is dead or tail has been disembodied return FALSE + if(stop_after != INFINITY) + addtimer(CALLBACK(src, PROC_REF(stop_wag), organ_owner), stop_after, TIMER_STOPPABLE|TIMER_DELETE_ME) + var/datum/bodypart_overlay/mutant/tail/accessory = bodypart_overlay wag_flags |= WAG_WAGGING accessory.wagging = TRUE if(tail_spines_overlay) //if there are spines, they should wag with the tail tail_spines_overlay.wagging = TRUE organ_owner.update_body_parts() - RegisterSignal(organ_owner, COMSIG_LIVING_DEATH, PROC_REF(stop_wag)) + RegisterSignal(organ_owner, COMSIG_LIVING_DEATH, PROC_REF(owner_died)) return TRUE +/obj/item/organ/external/tail/proc/owner_died(mob/living/carbon/organ_owner) // Resisting the urge to replace owner with daddy + SIGNAL_HANDLER + stop_wag(organ_owner) + ///We need some special behaviour for accessories, wrapped here so we can easily add more interactions later +///Returns false if the wag stopping worked, true otherwise /obj/item/organ/external/tail/proc/stop_wag(mob/living/carbon/organ_owner) - SIGNAL_HANDLER + if(!(wag_flags & WAG_ABLE)) + return FALSE - var/datum/bodypart_overlay/mutant/tail/accessory = bodypart_overlay - wag_flags &= ~WAG_WAGGING - accessory.wagging = FALSE + var/succeeded = FALSE + if(wag_flags & WAG_WAGGING) + wag_flags &= ~WAG_WAGGING + succeeded = TRUE + + var/datum/bodypart_overlay/mutant/tail/tail_overlay = bodypart_overlay + tail_overlay.wagging = FALSE if(tail_spines_overlay) //if there are spines, they should stop wagging with the tail tail_spines_overlay.wagging = FALSE if(isnull(organ_owner)) - return + return succeeded organ_owner.update_body_parts() UnregisterSignal(organ_owner, COMSIG_LIVING_DEATH) + return succeeded ///Tail parent type, with wagging functionality /datum/bodypart_overlay/mutant/tail diff --git a/code/modules/unit_tests/tail_wag.dm b/code/modules/unit_tests/tail_wag.dm index ceb82e98c0d..3868bb2c0e0 100644 --- a/code/modules/unit_tests/tail_wag.dm +++ b/code/modules/unit_tests/tail_wag.dm @@ -11,12 +11,12 @@ // SANITY TEST // start wagging - SEND_SIGNAL(dummy, COMSIG_ORGAN_WAG_TAIL, TRUE) + dummy.wag_tail() if(!(dummy_tail.wag_flags & WAG_WAGGING)) TEST_FAIL("Tail did not start wagging when it should have!") // stop wagging - SEND_SIGNAL(dummy, COMSIG_ORGAN_WAG_TAIL, FALSE) + dummy.unwag_tail() if(dummy_tail.wag_flags & WAG_WAGGING) TEST_FAIL("Tail did not stop wagging when it should have!") @@ -26,7 +26,7 @@ dummy_tail.wag_flags &= ~WAG_ABLE // try to wag it again - SEND_SIGNAL(dummy, COMSIG_ORGAN_WAG_TAIL, TRUE) + dummy.wag_tail() if(dummy_tail.wag_flags & WAG_WAGGING) TEST_FAIL("Tail should not have the ability to wag, yet it did!") @@ -34,19 +34,19 @@ dummy_tail.wag_flags |= WAG_ABLE // start wagging again - SEND_SIGNAL(dummy, COMSIG_ORGAN_WAG_TAIL, TRUE) + dummy.wag_tail() if(!(dummy_tail.wag_flags & WAG_WAGGING)) TEST_FAIL("Tail did not start wagging when it should have!") // TESTING STOP_AFTER // stop wagging - SEND_SIGNAL(dummy, COMSIG_ORGAN_WAG_TAIL, FALSE) + dummy.unwag_tail() if(dummy_tail.wag_flags & WAG_WAGGING) TEST_FAIL("Tail did not stop wagging when it should have!") // start wagging, stop after 0.1 seconds - SEND_SIGNAL(dummy, COMSIG_ORGAN_WAG_TAIL, TRUE, 0.1 SECONDS) + dummy.wag_tail(0.1 SECONDS) // because timers are a pain addtimer(VARSET_CALLBACK(src, timer_finished, TRUE), 0.2 SECONDS) if(!(dummy_tail.wag_flags & WAG_WAGGING)) @@ -67,7 +67,7 @@ TEST_FAIL("Tail was still wagging after being removed!") // try to wag the removed tail - SEND_SIGNAL(dummy, COMSIG_ORGAN_WAG_TAIL, TRUE) + dummy.wag_tail() if(dummy_tail.wag_flags & WAG_WAGGING) TEST_FAIL("A disembodied tail was able to start wagging!") @@ -75,7 +75,7 @@ // put it back and start wagging again dummy_tail.Insert(dummy, special = TRUE, movement_flags = DELETE_IF_REPLACED) - SEND_SIGNAL(dummy, COMSIG_ORGAN_WAG_TAIL, TRUE) + dummy.wag_tail() if(!(dummy_tail.wag_flags & WAG_WAGGING)) TEST_FAIL("Tail did not start wagging when it should have!") @@ -85,6 +85,6 @@ TEST_FAIL("A mob's tail was still wagging after being killed!") // check if we are still able to wag the tail after death - SEND_SIGNAL(dummy, COMSIG_ORGAN_WAG_TAIL, TRUE) + dummy.wag_tail() if(dummy_tail.wag_flags & WAG_WAGGING) TEST_FAIL("A dead mob was able to wag their tail!") diff --git a/modular_nova/master_files/code/modules/mob/living/carbon/carbon_defense.dm b/modular_nova/master_files/code/modules/mob/living/carbon/carbon_defense.dm index 85ae11babda..89120849497 100644 --- a/modular_nova/master_files/code/modules/mob/living/carbon/carbon_defense.dm +++ b/modular_nova/master_files/code/modules/mob/living/carbon/carbon_defense.dm @@ -11,7 +11,7 @@ visible_message("[src] slaps [target] in the face!", "You slap [target] in the face! ",\ "You hear a slap.") - target.dna?.species?.stop_wagging_tail(target) + target.unwag_tail() return if(zone_selected == BODY_ZONE_PRECISE_GROIN && target.dir == src.dir) if(HAS_TRAIT(target, TRAIT_PERSONALSPACE) && (target.stat != UNCONSCIOUS) && (!target.handcuffed)) //You need to be conscious and uncuffed to use Personal Space diff --git a/modular_nova/modules/customization/modules/mob/living/carbon/human/species.dm b/modular_nova/modules/customization/modules/mob/living/carbon/human/species.dm index 31b0dd14e20..e7ba998c769 100644 --- a/modular_nova/modules/customization/modules/mob/living/carbon/human/species.dm +++ b/modular_nova/modules/customization/modules/mob/living/carbon/human/species.dm @@ -202,50 +202,10 @@ GLOBAL_LIST_EMPTY(customizable_races) species_human.apply_overlay(BODY_LAYER) handle_mutant_bodyparts(species_human) -/datum/species/spec_stun(mob/living/carbon/human/H,amount) - if(H) - stop_wagging_tail(H) - . = ..() - -/* -* TAIL WAGGING -*/ - -/datum/species/proc/can_wag_tail(mob/living/carbon/human/H) - if(!H) //Somewhere in the core code we're getting those procs with H being null - return FALSE - var/obj/item/organ/external/tail/T = H.get_organ_slot(ORGAN_SLOT_EXTERNAL_TAIL) - if(!T) - return FALSE - if(T.can_wag) - return TRUE - return FALSE - -/datum/species/proc/is_wagging_tail(mob/living/carbon/human/H) - if(!H) //Somewhere in the core code we're getting those procs with H being null - return FALSE - var/obj/item/organ/external/tail/T = H.get_organ_slot(ORGAN_SLOT_EXTERNAL_TAIL) - if(!T) - return FALSE - return T.wagging - -/datum/species/proc/start_wagging_tail(mob/living/carbon/human/H) - if(!H) //Somewhere in the core code we're getting those procs with H being null - return - var/obj/item/organ/external/tail/T = H.get_organ_slot(ORGAN_SLOT_EXTERNAL_TAIL) - if(!T) - return FALSE - T.wagging = TRUE - H.update_body() - -/datum/species/proc/stop_wagging_tail(mob/living/carbon/human/H) - if(!H) //Somewhere in the core code we're getting those procs with H being null - return - var/obj/item/organ/external/tail/T = H.get_organ_slot(ORGAN_SLOT_EXTERNAL_TAIL) - if(!T) - return - T.wagging = FALSE - H.update_body() +/datum/species/spec_stun(mob/living/carbon/human/target, amount) + if(istype(target)) + target.unwag_tail() + return ..() /datum/species/regenerate_organs(mob/living/carbon/target, datum/species/old_species, replace_current = TRUE, list/excluded_zones, visual_only = FALSE) . = ..() diff --git a/modular_nova/modules/customization/readme.md b/modular_nova/modules/customization/readme.md index c7de94bda2a..e3a25b86796 100644 --- a/modular_nova/modules/customization/readme.md +++ b/modular_nova/modules/customization/readme.md @@ -22,7 +22,7 @@ Re-writes how mutant bodyparts exist and how they're handled. Adds in a per limb ./code/modules/mob/living/carbon/human/emote.dm > /datum/emote/living/carbon/human/wag/run_emote(), /datum/emote/living/carbon/human/wag/can_run_emote() ./code/modules/mob/living/carbon/human/examine.dm > /mob/living/carbon/human/examine() ./code/modules/mob/living/carbon/human/human_update_icons.dm > /mob/living/carbon/human/update_inv_w_uniform(), /mob/living/carbon/human/update_inv_glasses(), /mob/living/carbon/human/update_inv_shoes(), /mob/living/carbon/human/update_inv_wear_suit(), /obj/item/proc/build_worn_icon(), /mob/living/carbon/human/generate_icon_render_key() - ./code/modules/mob/living/carbon/human/species.dm > /datum/species/proc/on_species_gain(), /datum/species/proc/handle_body(), /datum/species/proc/handle_mutant_bodyparts(), /datum/species/proc/can_equip(), /datum/species/proc/can_wag_tail(), /datum/species/proc/stop_wagging_tail(), /datum/species/proc/start_wagging_tail(), /datum/species/proc/is_wagging_tail(), /datum/species/proc/handle_hair() + ./code/modules/mob/living/carbon/human/species.dm > /datum/species/proc/on_species_gain(), /datum/species/proc/handle_body(), /datum/species/proc/handle_mutant_bodyparts(), /datum/species/proc/can_equip(), /datum/species/proc/handle_hair() ./code/modules/mob/living/carbon/human/species_types/felinid.dm > the 5 procs related to wagging tail ./code/modules/mob/living/carbon/human/species_types/lizardpeople.dm the 5 procs related to wagging tail and - /datum/species/lizard/on_species_gain() ./code/modules/surgery/bodyparts/_bodyparts.dm > /obj/item/bodypart/proc/get_limb_icon()