Skip to content

Commit

Permalink
Footstep refactor and update (#12915)
Browse files Browse the repository at this point in the history
* working draft

* funny range stuff

* clean up

* various sound tweaks

* autodoc

* hover bugfix
  • Loading branch information
Lumipharon authored May 11, 2023
1 parent 9d95ad2 commit 5b6422b
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 111 deletions.
37 changes: 28 additions & 9 deletions code/__DEFINES/footsteps.dm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ GLOBAL_LIST_INIT(barefootstep, list(
'sound/effects/footstep/woodbarefoot3.ogg',
'sound/effects/footstep/woodbarefoot4.ogg',
'sound/effects/footstep/woodbarefoot5.ogg'), 80, -1),
FOOTSTEP_PLATING = list(list(
'sound/effects/footstep/hardbarefoot1.ogg',
'sound/effects/footstep/hardbarefoot2.ogg',
'sound/effects/footstep/hardbarefoot3.ogg',
'sound/effects/footstep/hardbarefoot4.ogg',
'sound/effects/footstep/hardbarefoot5.ogg'), 80, -1),
FOOTSTEP_HARD = list(list(
'sound/effects/footstep/hardbarefoot1.ogg',
'sound/effects/footstep/hardbarefoot2.ogg',
Expand Down Expand Up @@ -161,46 +167,59 @@ GLOBAL_LIST_INIT(xenomediumstep, list(
FOOTSTEP_WOOD = list(list(
'sound/effects/footstep/woodclaw1.ogg',
'sound/effects/footstep/woodclaw2.ogg',
'sound/effects/footstep/woodclaw3.ogg'), 90, 1),
'sound/effects/footstep/woodclaw3.ogg'), 60, 1),
FOOTSTEP_PLATING = list(list(
'sound/effects/footstep/hardclaw1.ogg',
'sound/effects/footstep/hardclaw2.ogg',
'sound/effects/footstep/hardclaw3.ogg',
'sound/effects/footstep/hardclaw4.ogg'), 70, 1),
FOOTSTEP_FLOOR = list(list(
'sound/effects/footstep/hardclaw1.ogg',
'sound/effects/footstep/hardclaw2.ogg',
'sound/effects/footstep/hardclaw3.ogg',
'sound/effects/footstep/hardclaw4.ogg'), 70, 1),
FOOTSTEP_HARD = list(list(
'sound/effects/footstep/hardclaw1.ogg',
'sound/effects/footstep/hardclaw2.ogg',
'sound/effects/footstep/hardclaw3.ogg',
'sound/effects/footstep/hardclaw4.ogg'), 90, 1),
'sound/effects/footstep/hardclaw4.ogg'), 70, 1),
FOOTSTEP_CARPET = list(list(
'sound/effects/footstep/carpetbarefoot1.ogg',
'sound/effects/footstep/carpetbarefoot2.ogg',
'sound/effects/footstep/carpetbarefoot3.ogg',
'sound/effects/footstep/carpetbarefoot4.ogg',
'sound/effects/footstep/carpetbarefoot5.ogg'), 75, -1),
'sound/effects/footstep/carpetbarefoot5.ogg'), 55, -1),
FOOTSTEP_SAND = list(list(
'sound/effects/footstep/asteroid1.ogg',
'sound/effects/footstep/asteroid2.ogg',
'sound/effects/footstep/asteroid3.ogg',
'sound/effects/footstep/asteroid4.ogg',
'sound/effects/footstep/asteroid5.ogg'), 75, 1),
'sound/effects/footstep/asteroid5.ogg'), 55, 1),
FOOTSTEP_GRASS = list(list(
'sound/effects/footstep/grass1.ogg',
'sound/effects/footstep/grass2.ogg',
'sound/effects/footstep/grass3.ogg',
'sound/effects/footstep/grass4.ogg'), 75, 1),
'sound/effects/footstep/grass4.ogg'), 65, 1),
FOOTSTEP_WATER = list(list(
'sound/effects/footstep/water1.ogg',
'sound/effects/footstep/water2.ogg',
'sound/effects/footstep/water3.ogg',
'sound/effects/footstep/water4.ogg'), 100, 1),
'sound/effects/footstep/water4.ogg'), 50, 1),
FOOTSTEP_RESIN = list(list(
'sound/effects/footstep/alien_resin_move1.ogg',
'sound/effects/footstep/alien_resin_move2.ogg',), 15, -4),
FOOTSTEP_CATWALK = list(list(
'sound/effects/footstep/catwalk1.ogg',
'sound/effects/footstep/catwalk2.ogg',
'sound/effects/footstep/catwalk3.ogg',
'sound/effects/footstep/catwalk4.ogg',
'sound/effects/footstep/catwalk5.ogg'), 90, 1),
'sound/effects/footstep/catwalk5.ogg'), 70, 1),
FOOTSTEP_SNOW = list(list(
'sound/effects/footstep/snow1.ogg',
'sound/effects/footstep/snow2.ogg',
'sound/effects/footstep/snow3.ogg',
'sound/effects/footstep/snow4.ogg',
'sound/effects/footstep/snow5.ogg'), 90, 1),
'sound/effects/footstep/snow5.ogg'), 70, 1),
FOOTSTEP_ICE = list(list(
'sound/effects/footstep/ice1.ogg',
'sound/effects/footstep/ice2.ogg',
Expand All @@ -212,7 +231,7 @@ GLOBAL_LIST_INIT(xenomediumstep, list(
'sound/effects/footstep/concrete2.ogg',
'sound/effects/footstep/concrete3.ogg',
'sound/effects/footstep/concrete4.ogg',
'sound/effects/footstep/concrete5.ogg'), 90, 1),
'sound/effects/footstep/concrete5.ogg'), 70, 1),
))

//heavy footsteps list
Expand Down
6 changes: 6 additions & 0 deletions code/__DEFINES/traits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@
#define TRAIT_LEASHED "leashed"
#define TRAIT_CAN_VENTCRAWL "can_ventcrawl"
#define TRAIT_WORKED_OUT "worked_out" //user has a cqc buff from working out
///Makes no footsteps at all
#define TRAIT_SILENT_FOOTSTEPS "silent_footsteps"
///quieter footsteps
#define TRAIT_LIGHT_STEP "light_step"
///noisier footsteps
#define TRAIT_HEAVY_STEP "heavy_step"

/// Prevents usage of manipulation appendages (picking, holding or using items, manipulating storage).
#define TRAIT_HANDS_BLOCKED "handsblocked"
Expand Down
100 changes: 0 additions & 100 deletions code/datums/components/footstep.dm

This file was deleted.

180 changes: 180 additions & 0 deletions code/datums/elements/footstep.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#define DEFAULT_FOOTSTEP_SOUND_RANGE 11

///Footstep element. Plays footsteps at parents location when it is appropriate.
/datum/element/footstep
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY|ELEMENT_BESPOKE
argument_hash_start_idx = 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 = 0, 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_REF(play_humanstep))
steps_for_living[target] = 0
return
if(FOOTSTEP_MOB_SHOE)
footstep_sounds = GLOB.shoefootstep
if(FOOTSTEP_MOB_BAREFOOT)
footstep_sounds = GLOB.barefootstep
if(FOOTSTEP_XENO_MEDIUM)
footstep_sounds = GLOB.xenomediumstep
if(FOOTSTEP_XENO_HEAVY)
footstep_sounds = GLOB.xenoheavystep
RegisterSignal(target, COMSIG_MOVABLE_MOVED, PROC_REF(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)
if(HAS_TRAIT(source, TRAIT_SILENT_FOOTSTEPS))
return

var/turf/open/turf = get_turf(source)
if(!istype(turf))
return

if(source.buckled || source.throwing || source.is_ventcrawling || source.lying_angle || CHECK_MULTIPLE_BITFIELDS(source.flags_pass, HOVERING) || HAS_TRAIT(source, TRAIT_IMMOBILE))
return

if(ishuman(source))
var/mob/living/carbon/human/human_source = source
if(!human_source.get_limb(BODY_ZONE_L_LEG) && !human_source.get_limb(BODY_ZONE_R_LEG))
return

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

return turf

///Plays footsteps for anything that isn't human
/datum/element/footstep/proc/play_simplestep(mob/living/source)
SIGNAL_HANDLER

var/turf/open/source_loc = prepare_step(source)
if(!source_loc)
return

var/volume_multiplier = 1
var/range_adjustment = 0

if(HAS_TRAIT(source, TRAIT_HEAVY_STEP))
volume_multiplier += 0.3
range_adjustment = 3

if(HAS_TRAIT(source, TRAIT_LIGHT_STEP))
volume_multiplier -= 0.5
range_adjustment = -3

if(source.m_intent == MOVE_INTENT_WALK)
volume_multiplier -= 0.5
range_adjustment = -3


if(isfile(footstep_sounds) || istext(footstep_sounds))
playsound(source_loc, footstep_sounds, volume * volume_multiplier, sound_vary, DEFAULT_FOOTSTEP_SOUND_RANGE + e_range + range_adjustment)
return

var/turf_footstep
if(locate(/obj/alien/weeds) in source_loc) //TODO replace this horribleness
turf_footstep = FOOTSTEP_RESIN
else switch(footstep_type)
if(FOOTSTEP_XENO_MEDIUM)
turf_footstep = source_loc.mediumxenofootstep
if(FOOTSTEP_XENO_HEAVY)
turf_footstep = source_loc.heavyxenofootstep
if(FOOTSTEP_MOB_BAREFOOT)
turf_footstep = source_loc.barefootstep
if(FOOTSTEP_MOB_SHOE)
turf_footstep = source_loc.shoefootstep
if(!turf_footstep)
return
playsound(
source_loc,
pick(footstep_sounds[turf_footstep][1]),
footstep_sounds[turf_footstep][2] * volume * volume_multiplier,
sound_vary,
DEFAULT_FOOTSTEP_SOUND_RANGE + footstep_sounds[turf_footstep][3] + e_range + range_adjustment,
)

///Plays footsteps for humans
/datum/element/footstep/proc/play_humanstep(mob/living/carbon/human/source, atom/oldloc, direction, forced, list/old_locs, momentum_change)
SIGNAL_HANDLER

var/turf/open/source_loc = prepare_step(source)
if(!source_loc)
return

var/volume_multiplier = 1
var/range_adjustment = 0

if(HAS_TRAIT(source, TRAIT_HEAVY_STEP))
volume_multiplier += 0.3
range_adjustment = 3

if(HAS_TRAIT(source, TRAIT_LIGHT_STEP))
volume_multiplier -= 0.5
range_adjustment = -3

if(source.m_intent == MOVE_INTENT_WALK)
volume_multiplier -= 0.5
range_adjustment = -3

if(locate(/obj/alien/weeds) in source_loc) //TODO replace this horrible snowflake check
playsound(
source_loc,
pick(GLOB.barefootstep[FOOTSTEP_RESIN][1]),
GLOB.barefootstep[FOOTSTEP_RESIN][2] * volume * volume_multiplier,
sound_vary,
DEFAULT_FOOTSTEP_SOUND_RANGE + GLOB.barefootstep[FOOTSTEP_RESIN][3] + e_range + range_adjustment,
)
return

if((source.wear_suit?.flags_armor_protection | source.w_uniform?.flags_armor_protection | source.shoes?.flags_armor_protection) & FEET) //We are not disgusting barefoot bandits
var/static/list/footstep_sounds = GLOB.shoefootstep //static is faster
playsound(
source_loc,
pick(footstep_sounds[source_loc.shoefootstep][1]),
footstep_sounds[source_loc.shoefootstep][2] * volume * volume_multiplier,
sound_vary,
DEFAULT_FOOTSTEP_SOUND_RANGE + footstep_sounds[source_loc.shoefootstep][3] + e_range + range_adjustment,
)
else
var/static/list/bare_footstep_sounds = GLOB.barefootstep
playsound(
source_loc,
pick(GLOB.barefootstep[source_loc.barefootstep][1]),
GLOB.barefootstep[source_loc.barefootstep][2] * volume * volume_multiplier,
sound_vary,
DEFAULT_FOOTSTEP_SOUND_RANGE + GLOB.barefootstep[source_loc.barefootstep][3] + e_range + range_adjustment,
)
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/human/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
RegisterSignal(src, COMSIG_KB_UNIQUEACTION, PROC_REF(do_unique_action))
RegisterSignal(src, COMSIG_GRAB_SELF_ATTACK, PROC_REF(fireman_carry_grabbed)) // Fireman carry
RegisterSignal(src, COMSIG_KB_GIVE, PROC_REF(give_signal_handler))
AddComponent(/datum/component/footstep, FOOTSTEP_MOB_HUMAN)
AddComponent(/datum/component/bump_attack, FALSE, FALSE)
AddElement(/datum/element/footstep, isrobot(src) ? FOOTSTEP_MOB_SHOE : FOOTSTEP_MOB_HUMAN, 1)
AddElement(/datum/element/ridable, /datum/component/riding/creature/human)

/mob/living/carbon/human/proc/human_z_changed(datum/source, old_z, new_z)
Expand Down
Loading

0 comments on commit 5b6422b

Please sign in to comment.