Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Yeets CONSIG_ORGAN_WAG_TAIL #1974

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions code/__DEFINES/dcs/signals/signals_mob/signals_mob_living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions code/datums/mood_events/generic_negative_events.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions code/game/objects/items/hand_items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions code/modules/mob/living/carbon/carbon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 4 additions & 2 deletions code/modules/mob/living/carbon/human/emote.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
. = ..()
Expand Down
47 changes: 25 additions & 22 deletions code/modules/surgery/organs/external/tails.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions code/modules/unit_tests/tail_wag.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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!")

Expand All @@ -26,27 +26,27 @@
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!")

// flip the wag flag to waggable again
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))
Expand All @@ -67,15 +67,15 @@
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!")

// TESTING MOB DEATH

// 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!")

Expand All @@ -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!")
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
visible_message("<span class='danger'>[src] slaps [target] in the face!</span>",
"<span class='notice'>You slap [target] in the face! </span>",\
"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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
. = ..()
Expand Down
2 changes: 1 addition & 1 deletion modular_nova/modules/customization/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading