From 54f003621bd2c729c8ae04afb8769fec5334a6e8 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Tue, 3 Aug 2021 21:16:35 +0200 Subject: [PATCH] [MIRROR] Converts the footstep component into an element. (#7229) * Converts the footstep component into an element. * Update human.dm Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> Co-authored-by: Gandalf --- .../vending_machine_controller.dm | 4 +- code/datums/components/footstep.dm | 146 ----------------- code/datums/elements/footstep.dm | 155 ++++++++++++++++++ code/modules/mining/minebot.dm | 2 +- .../living/carbon/alien/humanoid/humanoid.dm | 2 +- code/modules/mob/living/carbon/human/human.dm | 3 +- .../simple_animal/friendly/robot_customer.dm | 2 +- .../mob/living/simple_animal/simple_animal.dm | 2 +- tgstation.dme | 2 +- 9 files changed, 163 insertions(+), 155 deletions(-) delete mode 100644 code/datums/components/footstep.dm create mode 100644 code/datums/elements/footstep.dm diff --git a/code/datums/ai/objects/vending_machines/vending_machine_controller.dm b/code/datums/ai/objects/vending_machines/vending_machine_controller.dm index 66a3ff660c9..5ed0a4dea32 100644 --- a/code/datums/ai/objects/vending_machines/vending_machine_controller.dm +++ b/code/datums/ai/objects/vending_machines/vending_machine_controller.dm @@ -15,7 +15,7 @@ var/obj/machinery/vending/vendor_pawn = new_pawn vendor_pawn.tiltable = FALSE //Not manually tiltable by hitting it anymore. We are now agressively doing it ourselves. vendor_pawn.AddElement(/datum/element/waddling) - vendor_pawn.AddComponent(/datum/component/footstep, FOOTSTEP_OBJ_MACHINE, 1, -6, vary = TRUE) + vendor_pawn.AddElement(/datum/element/footstep, FOOTSTEP_OBJ_MACHINE, 1, -6, vary = TRUE) vendor_pawn.squish_damage = 15 return ..() //Run parent at end @@ -24,7 +24,7 @@ vendor_pawn.tiltable = TRUE vendor_pawn.RemoveElement(/datum/element/waddling) vendor_pawn.squish_damage = initial(vendor_pawn.squish_damage) - qdel(vendor_pawn.GetComponent(/datum/component/footstep)) + RemoveElement(/datum/element/footstep, FOOTSTEP_OBJ_MACHINE, 1, -6, vary = TRUE) return ..() //Run parent at end /datum/ai_controller/vending_machine/SelectBehaviors(delta_time) diff --git a/code/datums/components/footstep.dm b/code/datums/components/footstep.dm deleted file mode 100644 index 01be6039a9e..00000000000 --- a/code/datums/components/footstep.dm +++ /dev/null @@ -1,146 +0,0 @@ -///Footstep component. Plays footsteps at parents location when it is appropriate. -/datum/component/footstep - ///How many steps the parent has taken since the last time a footstep was played. - var/steps = 0 - ///volume determines the extra volume of the footstep. This is multiplied by the base volume, should there be one. - var/volume - ///e_range stands for extra range - aka how far the sound can be heard. This is added to the base value and ignored if there isn't a base value. - var/e_range - ///footstep_type is a define which determines what kind of sounds should get chosen. - var/footstep_type - ///This can be a list OR a soundfile OR null. Determines whatever sound gets played. - var/footstep_sounds - ///Whether or not to add variation to the sounds played - var/sound_vary = FALSE - -/datum/component/footstep/Initialize(footstep_type_ = FOOTSTEP_MOB_BAREFOOT, volume_ = 0.5, e_range_ = -8, vary) - if(!ismovable(parent)) - return COMPONENT_INCOMPATIBLE - volume = volume_ - e_range = e_range_ - footstep_type = footstep_type_ - sound_vary = vary - switch(footstep_type) - if(FOOTSTEP_MOB_HUMAN) - if(!ishuman(parent)) - return COMPONENT_INCOMPATIBLE - RegisterSignal(parent, list(COMSIG_MOVABLE_MOVED), .proc/play_humanstep) - return - if(FOOTSTEP_MOB_CLAW) - footstep_sounds = GLOB.clawfootstep - if(FOOTSTEP_MOB_BAREFOOT) - footstep_sounds = GLOB.barefootstep - if(FOOTSTEP_MOB_HEAVY) - footstep_sounds = GLOB.heavyfootstep - if(FOOTSTEP_MOB_SHOE) - footstep_sounds = GLOB.footstep - if(FOOTSTEP_MOB_SLIME) - footstep_sounds = 'sound/effects/footstep/slime1.ogg' - if(FOOTSTEP_OBJ_MACHINE) - footstep_sounds = 'sound/effects/bang.ogg' - RegisterSignal(parent, list(COMSIG_MOVABLE_MOVED), .proc/play_simplestep_machine) //Note that this doesn't get called for humans. - return - if(FOOTSTEP_OBJ_ROBOT) - footstep_sounds = 'sound/effects/tank_treads.ogg' - RegisterSignal(parent, list(COMSIG_MOVABLE_MOVED), .proc/play_simplestep_machine) //Note that this doesn't get called for humans. - return - RegisterSignal(parent, list(COMSIG_MOVABLE_MOVED), .proc/play_simplestep) //Note that this doesn't get called for humans. - -///Prepares a footstep. Determines if it should get played. Returns the turf it should get played on. Note that it is always a /turf/open -/datum/component/footstep/proc/prepare_step() - var/turf/open/T = get_turf(parent) - if(!istype(T)) - return - - var/mob/living/LM = parent - - if(!T.footstep || LM.buckled || LM.throwing || LM.movement_type & (VENTCRAWLING | FLYING) || HAS_TRAIT(LM, TRAIT_IMMOBILIZED)) - return - - if(LM.body_position == LYING_DOWN) //play crawling sound if we're lying - playsound(T, 'sound/effects/footstep/crawl1.ogg', 15 * volume, falloff_distance = 1, vary = sound_vary) - return - - if(iscarbon(LM)) - var/mob/living/carbon/C = LM - if(!C.get_bodypart(BODY_ZONE_L_LEG) && !C.get_bodypart(BODY_ZONE_R_LEG)) - return - if(C.m_intent == MOVE_INTENT_WALK) - return// stealth - steps++ - - if(steps >= 6) - steps = 0 - - if(steps % 2) - return - - if(steps != 0 && !LM.has_gravity(T)) // don't need to step as often when you hop around - return - return T - -/datum/component/footstep/proc/play_simplestep() - SIGNAL_HANDLER - - var/turf/open/T = prepare_step() - if(!T) - return - if(isfile(footstep_sounds) || istext(footstep_sounds)) - playsound(T, footstep_sounds, volume, falloff_distance = 1, vary = sound_vary) - return - var/turf_footstep - switch(footstep_type) - if(FOOTSTEP_MOB_CLAW) - turf_footstep = T.clawfootstep - if(FOOTSTEP_MOB_BAREFOOT) - turf_footstep = T.barefootstep - if(FOOTSTEP_MOB_HEAVY) - turf_footstep = T.heavyfootstep - if(FOOTSTEP_MOB_SHOE) - turf_footstep = T.footstep - if(!turf_footstep) - return - playsound(T, pick(footstep_sounds[turf_footstep][1]), footstep_sounds[turf_footstep][2] * volume, TRUE, footstep_sounds[turf_footstep][3] + e_range, falloff_distance = 1, vary = sound_vary) - -/datum/component/footstep/proc/play_humanstep() - SIGNAL_HANDLER - - if(HAS_TRAIT(parent, TRAIT_SILENT_FOOTSTEPS)) - return - - var/volume_multiplier = 1 - var/range_adjustment = 0 - - if(HAS_TRAIT(parent, TRAIT_LIGHT_STEP)) - volume_multiplier = 0.6 - range_adjustment = -2 - - var/turf/open/T = prepare_step() - if(!T) - return - var/mob/living/carbon/human/H = parent - - if ((H.wear_suit?.body_parts_covered | H.w_uniform?.body_parts_covered | H.shoes?.body_parts_covered) & FEET) - // we are wearing shoes - playsound(T, pick(GLOB.footstep[T.footstep][1]), - GLOB.footstep[T.footstep][2] * volume * volume_multiplier, - TRUE, - GLOB.footstep[T.footstep][3] + e_range + range_adjustment, falloff_distance = 1, vary = sound_vary) - else - if(H.dna.species.special_step_sounds) - playsound(T, pick(H.dna.species.special_step_sounds), 50, TRUE, falloff_distance = 1, vary = sound_vary) - else - playsound(T, pick(GLOB.barefootstep[T.barefootstep][1]), - GLOB.barefootstep[T.barefootstep][2] * volume * volume_multiplier, - TRUE, - GLOB.barefootstep[T.barefootstep][3] + e_range + range_adjustment, falloff_distance = 1, vary = sound_vary) - - -///Prepares a footstep for machine walking -/datum/component/footstep/proc/play_simplestep_machine() - SIGNAL_HANDLER - - var/turf/open/T = get_turf(parent) - if(!istype(T)) - return - playsound(T, footstep_sounds, 50, falloff_distance = 1, vary = sound_vary) diff --git a/code/datums/elements/footstep.dm b/code/datums/elements/footstep.dm new file mode 100644 index 00000000000..0c07ea30b96 --- /dev/null +++ b/code/datums/elements/footstep.dm @@ -0,0 +1,155 @@ +///Footstep element. Plays footsteps at parents location when it is appropriate. +/datum/element/footstep + element_flags = ELEMENT_DETACH|ELEMENT_BESPOKE + id_arg_index = 2 + ///A list containing living mobs and the number of steps they have taken since the last time their footsteps were played. + var/list/steps_for_living = list() + ///volume determines the extra volume of the footstep. This is multiplied by the base volume, should there be one. + var/volume + ///e_range stands for extra range - aka how far the sound can be heard. This is added to the base value and ignored if there isn't a base value. + var/e_range + ///footstep_type is a define which determines what kind of sounds should get chosen. + var/footstep_type + ///This can be a list OR a soundfile OR null. Determines whatever sound gets played. + var/footstep_sounds + ///Whether or not to add variation to the sounds played + var/sound_vary = FALSE + +/datum/element/footstep/Attach(datum/target, footstep_type = FOOTSTEP_MOB_BAREFOOT, volume = 0.5, e_range = -8, sound_vary = FALSE) + . = ..() + if(!ismovable(target)) + return ELEMENT_INCOMPATIBLE + src.volume = volume + src.e_range = e_range + src.footstep_type = footstep_type + src.sound_vary = sound_vary + switch(footstep_type) + if(FOOTSTEP_MOB_HUMAN) + if(!ishuman(target)) + return ELEMENT_INCOMPATIBLE + RegisterSignal(target, COMSIG_MOVABLE_MOVED, .proc/play_humanstep) + steps_for_living[target] = 0 + return + if(FOOTSTEP_MOB_CLAW) + footstep_sounds = GLOB.clawfootstep + if(FOOTSTEP_MOB_BAREFOOT) + footstep_sounds = GLOB.barefootstep + if(FOOTSTEP_MOB_HEAVY) + footstep_sounds = GLOB.heavyfootstep + if(FOOTSTEP_MOB_SHOE) + footstep_sounds = GLOB.footstep + if(FOOTSTEP_MOB_SLIME) + footstep_sounds = 'sound/effects/footstep/slime1.ogg' + if(FOOTSTEP_OBJ_MACHINE) + footstep_sounds = 'sound/effects/bang.ogg' + RegisterSignal(target, COMSIG_MOVABLE_MOVED, .proc/play_simplestep_machine) + return + if(FOOTSTEP_OBJ_ROBOT) + footstep_sounds = 'sound/effects/tank_treads.ogg' + RegisterSignal(target, COMSIG_MOVABLE_MOVED, .proc/play_simplestep_machine) + return + RegisterSignal(target, COMSIG_MOVABLE_MOVED, .proc/play_simplestep) + steps_for_living[target] = 0 + +/datum/element/footstep/Detach(atom/movable/source) + UnregisterSignal(source, COMSIG_MOVABLE_MOVED) + steps_for_living -= source + return ..() + +///Prepares a footstep for living mobs. Determines if it should get played. Returns the turf it should get played on. Note that it is always a /turf/open +/datum/element/footstep/proc/prepare_step(mob/living/source) + var/turf/open/turf = get_turf(source) + if(!istype(turf)) + return + + if(!turf.footstep || source.buckled || source.throwing || source.movement_type & (VENTCRAWLING | FLYING) || HAS_TRAIT(source, TRAIT_IMMOBILIZED)) + return + + if(source.body_position == LYING_DOWN) //play crawling sound if we're lying + playsound(turf, 'sound/effects/footstep/crawl1.ogg', 15 * volume, falloff_distance = 1, vary = sound_vary) + return + + if(iscarbon(source)) + var/mob/living/carbon/carbon_source = source + if(!carbon_source.get_bodypart(BODY_ZONE_L_LEG) && !carbon_source.get_bodypart(BODY_ZONE_R_LEG)) + return + if(carbon_source.m_intent == MOVE_INTENT_WALK) + return// stealth + steps_for_living[source] += 1 + var/steps = steps_for_living[source] + + if(steps >= 6) + steps_for_living[source] = 0 + steps = 0 + + if(steps % 2) + return + + if(steps != 0 && !source.has_gravity(turf)) // don't need to step as often when you hop around + return + return turf + +/datum/element/footstep/proc/play_simplestep(mob/living/source) + SIGNAL_HANDLER + + var/turf/open/source_loc = prepare_step(source) + if(!source_loc) + return + if(isfile(footstep_sounds) || istext(footstep_sounds)) + playsound(source_loc, footstep_sounds, volume, falloff_distance = 1, vary = sound_vary) + return + var/turf_footstep + switch(footstep_type) + if(FOOTSTEP_MOB_CLAW) + turf_footstep = source_loc.clawfootstep + if(FOOTSTEP_MOB_BAREFOOT) + turf_footstep = source_loc.barefootstep + if(FOOTSTEP_MOB_HEAVY) + turf_footstep = source_loc.heavyfootstep + if(FOOTSTEP_MOB_SHOE) + turf_footstep = source_loc.footstep + if(!turf_footstep) + return + playsound(source_loc, pick(footstep_sounds[turf_footstep][1]), footstep_sounds[turf_footstep][2] * volume, TRUE, footstep_sounds[turf_footstep][3] + e_range, falloff_distance = 1, vary = sound_vary) + +/datum/element/footstep/proc/play_humanstep(mob/living/carbon/human/source) + SIGNAL_HANDLER + + if(HAS_TRAIT(source, TRAIT_SILENT_FOOTSTEPS)) + return + + var/volume_multiplier = 1 + var/range_adjustment = 0 + + if(HAS_TRAIT(source, TRAIT_LIGHT_STEP)) + volume_multiplier = 0.6 + range_adjustment = -2 + + var/turf/open/source_loc = prepare_step(source) + if(!source_loc) + return + + if ((source.wear_suit?.body_parts_covered | source.w_uniform?.body_parts_covered | source.shoes?.body_parts_covered) & FEET) + // we are wearing shoes + playsound(source_loc, pick(GLOB.footstep[source_loc.footstep][1]), + GLOB.footstep[source_loc.footstep][2] * volume * volume_multiplier, + TRUE, + GLOB.footstep[source_loc.footstep][3] + e_range + range_adjustment, falloff_distance = 1, vary = sound_vary) + else + if(source.dna.species.special_step_sounds) + playsound(source_loc, pick(source.dna.species.special_step_sounds), 50, TRUE, falloff_distance = 1, vary = sound_vary) + else + playsound(source_loc, pick(GLOB.barefootstep[source_loc.barefootstep][1]), + GLOB.barefootstep[source_loc.barefootstep][2] * volume * volume_multiplier, + TRUE, + GLOB.barefootstep[source_loc.barefootstep][3] + e_range + range_adjustment, falloff_distance = 1, vary = sound_vary) + + +///Prepares a footstep for machine walking +/datum/element/footstep/proc/play_simplestep_machine(atom/movable/source) + SIGNAL_HANDLER + + var/turf/open/source_loc = get_turf(source) + if(!istype(source_loc)) + return + playsound(source_loc, footstep_sounds, 50, falloff_distance = 1, vary = sound_vary) diff --git a/code/modules/mining/minebot.dm b/code/modules/mining/minebot.dm index 6385036508d..0efe4625634 100644 --- a/code/modules/mining/minebot.dm +++ b/code/modules/mining/minebot.dm @@ -44,7 +44,7 @@ /mob/living/simple_animal/hostile/mining_drone/Initialize() . = ..() - AddComponent(/datum/component/footstep, FOOTSTEP_OBJ_ROBOT, 1, -6, vary = TRUE) + AddElement(/datum/element/footstep, FOOTSTEP_OBJ_ROBOT, 1, -6, vary = TRUE) stored_gun = new(src) var/datum/action/innate/minedrone/toggle_light/toggle_light_action = new() diff --git a/code/modules/mob/living/carbon/alien/humanoid/humanoid.dm b/code/modules/mob/living/carbon/alien/humanoid/humanoid.dm index 7b51b8d4ffb..a1ed8dfb766 100644 --- a/code/modules/mob/living/carbon/alien/humanoid/humanoid.dm +++ b/code/modules/mob/living/carbon/alien/humanoid/humanoid.dm @@ -33,7 +33,7 @@ GLOBAL_LIST_INIT(strippable_alien_humanoid_items, create_strippable_list(list( /mob/living/carbon/alien/humanoid/Initialize() . = ..() - AddComponent(/datum/component/footstep, FOOTSTEP_MOB_CLAW, 0.5, -11) + AddElement(/datum/element/footstep, FOOTSTEP_MOB_CLAW, 0.5, -11) AddElement(/datum/element/strippable, GLOB.strippable_alien_humanoid_items) /mob/living/carbon/alien/humanoid/cuff_resist(obj/item/I) diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index cccf244c69e..da26921bfc8 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -20,8 +20,7 @@ RegisterSignal(src, COMSIG_COMPONENT_CLEAN_FACE_ACT, .proc/clean_face) AddComponent(/datum/component/personal_crafting) - //AddComponent(/datum/component/footstep, FOOTSTEP_MOB_HUMAN, 1, -6) //ORIGINAL - AddComponent(/datum/component/footstep, FOOTSTEP_MOB_HUMAN, 0.6, -6) //SKYRAT EDIT CHANGE - AESTHETICS + AddElement(/datum/element/footstep, FOOTSTEP_MOB_HUMAN, 0.6, -6) //SKYRAT EDIT CHANGE - AESTHETICS AddComponent(/datum/component/bloodysoles/feet) AddElement(/datum/element/ridable, /datum/component/riding/creature/human) AddElement(/datum/element/strippable, GLOB.strippable_human_items, /mob/living/carbon/human/.proc/should_strip) diff --git a/code/modules/mob/living/simple_animal/friendly/robot_customer.dm b/code/modules/mob/living/simple_animal/friendly/robot_customer.dm index bc0a964be9c..4ac728daabc 100644 --- a/code/modules/mob/living/simple_animal/friendly/robot_customer.dm +++ b/code/modules/mob/living/simple_animal/friendly/robot_customer.dm @@ -26,7 +26,7 @@ ADD_TRAIT(src, TRAIT_NOMOBSWAP, INNATE_TRAIT) //dont push me bitch ADD_TRAIT(src, TRAIT_NO_TELEPORT, INNATE_TRAIT) //dont teleport me bitch ADD_TRAIT(src, TRAIT_STRONG_GRABBER, INNATE_TRAIT) //strong arms bitch - AddComponent(/datum/component/footstep, FOOTSTEP_OBJ_ROBOT, 1, -6, vary = TRUE) + AddElement(/datum/element/footstep, FOOTSTEP_OBJ_ROBOT, 1, -6, vary = TRUE) var/datum/customer_data/customer_info = SSrestaurant.all_customers[customer_data] clothes_set = pick(customer_info.clothing_sets) ai_controller = customer_info.ai_controller_used diff --git a/code/modules/mob/living/simple_animal/simple_animal.dm b/code/modules/mob/living/simple_animal/simple_animal.dm index 2fd550b0fbc..444edb48488 100644 --- a/code/modules/mob/living/simple_animal/simple_animal.dm +++ b/code/modules/mob/living/simple_animal/simple_animal.dm @@ -192,7 +192,7 @@ if(damage_coeff) damage_coeff = string_assoc_list(damage_coeff) if(footstep_type) - AddComponent(/datum/component/footstep, footstep_type) + AddElement(/datum/element/footstep, footstep_type) if(!isnull(unsuitable_cold_damage)) unsuitable_cold_damage = unsuitable_atmos_damage if(!isnull(unsuitable_heat_damage)) diff --git a/tgstation.dme b/tgstation.dme index 46f32cfb5b9..ebebd36a987 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -559,7 +559,6 @@ #include "code\datums\components\electrified_buckle.dm" #include "code\datums\components\embedded.dm" #include "code\datums\components\explodable.dm" -#include "code\datums\components\footstep.dm" #include "code\datums\components\forensics.dm" #include "code\datums\components\fullauto.dm" #include "code\datums\components\gas_leaker.dm" @@ -757,6 +756,7 @@ #include "code\datums\elements\empprotection.dm" #include "code\datums\elements\eyestab.dm" #include "code\datums\elements\firestacker.dm" +#include "code\datums\elements\footstep.dm" #include "code\datums\elements\forced_gravity.dm" #include "code\datums\elements\haunted.dm" #include "code\datums\elements\item_scaling.dm"