Skip to content

Commit

Permalink
[PORT] Finally Fixes Grilles and Elevators Having No Step Sound (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
RimiNosha authored Nov 20, 2023
1 parent 699d2f9 commit f460a1b
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 91 deletions.
5 changes: 0 additions & 5 deletions code/__DEFINES/dcs/signals/signals_mob/signals_mob_main.dm
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,3 @@

///from living/flash_act(), when a mob is successfully flashed.
#define COMSIG_MOB_FLASHED "mob_flashed"

/// When a mob attempts to play the footstep sound. Called in the foostep component
#define COMSIG_MOB_PLAYS_FOOTSTEP "mob_plays_footstep"
/// Will cancel the attempted footstep playing (most likely after overriding and playing another one)
#define COMPONENT_CANCEL_PLAY_FOOTSTEP (1<<0)
5 changes: 5 additions & 0 deletions code/__DEFINES/dcs/signals/signals_turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@

///from /datum/element/decal/Detach(): (description, cleanable, directional, mutable_appearance/pic)
#define COMSIG_TURF_DECAL_DETACHED "turf_decal_detached"

///from /datum/element/footstep/prepare_step(): (list/steps)
#define COMSIG_TURF_PREPARE_STEP_SOUND "turf_prepare_step_sound"
//stops element/footstep/proc/prepare_step() from returning null if the turf itself has no sound
#define FOOTSTEP_OVERRIDEN (1<<0)
25 changes: 17 additions & 8 deletions code/__DEFINES/footsteps.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@
//misc footstep sounds
#define FOOTSTEP_GENERIC_HEAVY "heavy"


//footstep mob defines
#define FOOTSTEP_MOB_CLAW 1
#define FOOTSTEP_MOB_BAREFOOT 2
#define FOOTSTEP_MOB_HEAVY 3
#define FOOTSTEP_MOB_SHOE 4
#define FOOTSTEP_MOB_HUMAN 5 //Warning: Only works on /mob/living/carbon/human
#define FOOTSTEP_MOB_SLIME 6
#define FOOTSTEP_OBJ_MACHINE 7
#define FOOTSTEP_OBJ_ROBOT 8
#define FOOTSTEP_MOB_CLAW "footstep_claw"
#define FOOTSTEP_MOB_BAREFOOT "footstep_barefoot"
#define FOOTSTEP_MOB_HEAVY "footstep_heavy"
#define FOOTSTEP_MOB_SHOE "footstep_shoe"
#define FOOTSTEP_MOB_HUMAN "footstep_human" //Warning: Only works on /mob/living/carbon/human
#define FOOTSTEP_MOB_SLIME "footstep_slime"
#define FOOTSTEP_OBJ_MACHINE "footstep_machine"
#define FOOTSTEP_OBJ_ROBOT "footstep_robot"

//priority defines for the footstep_override element
#define STEP_SOUND_NO_PRIORITY 0
#define STEP_SOUND_CONVEYOR_PRIORITY 1
#define STEP_SOUND_TABLE_PRIORITY 2

///the name of the index key for priority
#define STEP_SOUND_PRIORITY "step_sound_priority"

/*
Expand Down
65 changes: 26 additions & 39 deletions code/datums/elements/footstep.dm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
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)
if(turf.footstep)
playsound(turf, 'sound/effects/footstep/crawl1.ogg', 15 * volume, falloff_distance = 1, vary = sound_vary)
return

if(iscarbon(source))
Expand All @@ -89,37 +90,30 @@

if(steps != 0 && !source.has_gravity()) // don't need to step as often when you hop around
return
return turf

. = list(FOOTSTEP_MOB_SHOE = turf.footstep, FOOTSTEP_MOB_BAREFOOT = turf.barefootstep, FOOTSTEP_MOB_HEAVY = turf.heavyfootstep, FOOTSTEP_MOB_CLAW = turf.clawfootstep, STEP_SOUND_PRIORITY = STEP_SOUND_NO_PRIORITY)
var/overridden = SEND_SIGNAL(turf, COMSIG_TURF_PREPARE_STEP_SOUND, .)
if(!overridden && isnull(turf.footstep))
return null
return .

/datum/element/footstep/proc/play_simplestep(mob/living/source)
SIGNAL_HANDLER

if (SHOULD_DISABLE_FOOTSTEPS(source))
return

var/turf/open/source_loc = prepare_step(source)
if(!source_loc)
return
if(SEND_SIGNAL(source_loc, COMSIG_MOB_PLAYS_FOOTSTEP, footstep_type, volume, e_range, sound_vary) & COMPONENT_CANCEL_PLAY_FOOTSTEP)
return
if(!source_loc.footstep)
var/list/prepared_steps = prepare_step(source)
if(!prepared_steps)
return
if(isfile(footstep_sounds) || istext(footstep_sounds))
playsound(source_loc, footstep_sounds, volume, falloff_distance = 1, vary = sound_vary)
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

var/turf_footstep = prepared_steps[footstep_type]
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)
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, atom/oldloc, direction, forced, list/old_locs, momentum_change)
SIGNAL_HANDLER
Expand All @@ -134,41 +128,34 @@
volume_multiplier = 0.6
range_adjustment = -2

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

// The sound type to use
var/established_type
//cache for sanic speed (lists are references anyways)
var/static/list/footstep_sounds = GLOB.footstep
///list returned by playsound() filled by client mobs who heard the footstep. given to play_fov_effect()
var/list/heard_clients

if ((source.wear_suit?.body_parts_covered | source.w_uniform?.body_parts_covered | source.shoes?.body_parts_covered) & FEET)
// we are wearing shoes
established_type = FOOTSTEP_MOB_SHOE
else
established_type = FOOTSTEP_MOB_BAREFOOT
if(SEND_SIGNAL(source_loc, COMSIG_MOB_PLAYS_FOOTSTEP, established_type, volume, e_range, sound_vary) & COMPONENT_CANCEL_PLAY_FOOTSTEP)
return
if(!source_loc.footstep)
return
if(established_type == FOOTSTEP_MOB_SHOE)
heard_clients = playsound(source_loc, pick(footstep_sounds[source_loc.footstep][1]),
footstep_sounds[source_loc.footstep][2] * volume * volume_multiplier,

var/shoestep_type = prepared_steps[FOOTSTEP_MOB_SHOE]
heard_clients = playsound(source.loc, pick(footstep_sounds[shoestep_type][1]),
footstep_sounds[shoestep_type][2] * volume * volume_multiplier,
TRUE,
footstep_sounds[source_loc.footstep][3] + e_range + range_adjustment, falloff_distance = 1, vary = sound_vary)
footstep_sounds[shoestep_type][3] + e_range + range_adjustment, falloff_distance = 1, vary = sound_vary)
else
var/barefoot_type = prepared_steps[FOOTSTEP_MOB_BAREFOOT]
if(source.dna.species.special_step_sounds)
heard_clients = playsound(source_loc, pick(source.dna.species.special_step_sounds), 50, TRUE, falloff_distance = 1, vary = sound_vary)
heard_clients = playsound(source.loc, pick(source.dna.species.special_step_sounds), 50, TRUE, falloff_distance = 1, vary = sound_vary)
else
var/static/list/bare_footstep_sounds = GLOB.barefootstep

heard_clients = playsound(source_loc, pick(bare_footstep_sounds[source_loc.barefootstep][1]),
bare_footstep_sounds[source_loc.barefootstep][2] * volume * volume_multiplier,
heard_clients = playsound(source.loc, pick(bare_footstep_sounds[barefoot_type][1]),
bare_footstep_sounds[barefoot_type][2] * volume * volume_multiplier,
TRUE,
bare_footstep_sounds[source_loc.barefootstep][3] + e_range + range_adjustment, falloff_distance = 1, vary = sound_vary)
bare_footstep_sounds[barefoot_type][3] + e_range + range_adjustment, falloff_distance = 1, vary = sound_vary)

if(heard_clients)
play_fov_effect(source, 5, "footstep", direction, ignore_self = TRUE, override_list = heard_clients)
Expand Down
107 changes: 70 additions & 37 deletions code/datums/elements/footstep_override.dm
Original file line number Diff line number Diff line change
@@ -1,48 +1,81 @@
///When attached, the footstep sound played by the footstep element will be replaced by this one's
/datum/element/footstep_override
element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH
element_flags = ELEMENT_BESPOKE|ELEMENT_DETACH
id_arg_index = 2
var/footstep
var/barefootstep
///The sound played for movables with claw step sound type.
var/clawfootstep
///The sound played for movables with barefoot step sound type.
var/barefootstep
///The sound played for movables with heavy step sound type.
var/heavyfootstep
var/static/list/connection_signal = list(
COMSIG_MOB_PLAYS_FOOTSTEP = PROC_REF(on_footstep),
)
///The sound played for movables with shoed step sound type.
var/footstep
///The priority this element has in relation to other elements of the same type attached to other movables on the same turf.
var/priority
/**
* A list of turfs occupied by the movables this element is attached to.
* Needed so it stops listening the turf's signals ONLY when it has no movable with the element.
*/
var/list/occupied_turfs = list()

/datum/element/footstep_override/Attach(datum/target, _footstep, _barefootstep, _clawfootstep, _heavyfootstep)
/datum/element/footstep_override/Attach(atom/movable/target, clawfootstep = FOOTSTEP_HARD_CLAW, barefootstep = FOOTSTEP_HARD_BAREFOOT, heavyfootstep = FOOTSTEP_GENERIC_HEAVY, footstep = FOOTSTEP_FLOOR, priority = STEP_SOUND_NO_PRIORITY)
. = ..()
if(!ismovable(target))
return ELEMENT_INCOMPATIBLE

src.footstep = _footstep
src.barefootstep = _barefootstep
src.clawfootstep = _clawfootstep
src.heavyfootstep = _heavyfootstep

AddElement(/datum/element/connect_loc, target, connection_signal)

/datum/element/footstep_override/proc/on_footstep(datum/source, footstep_type, volume, e_range, sound_vary)
var/played_step
var/sound_ref
switch(footstep_type)
if(FOOTSTEP_MOB_CLAW)
played_step = clawfootstep
sound_ref = GLOB.clawfootstep
if(FOOTSTEP_MOB_BAREFOOT)
played_step = barefootstep
sound_ref = GLOB.barefootstep
if(FOOTSTEP_MOB_HEAVY)
played_step = heavyfootstep
sound_ref = GLOB.heavyfootstep
if(FOOTSTEP_MOB_SHOE)
played_step = footstep
sound_ref = GLOB.footstep
if(!played_step)
src.clawfootstep = clawfootstep
src.barefootstep = barefootstep
src.heavyfootstep = heavyfootstep
src.footstep = footstep
src.priority = priority

RegisterSignal(target, COMSIG_MOVABLE_MOVED, PROC_REF(on_moved))
if(isturf(target.loc))
occupy_turf(target, target.loc)

/datum/element/footstep_override/Detach(atom/movable/source)
if(isturf(source.loc))
vacate_turf(source, source.loc)
return ..()

/datum/element/footstep_override/proc/on_moved(atom/movable/source, atom/oldloc)
SIGNAL_HANDLER
if(isturf(oldloc))
vacate_turf(source, oldloc)
if(isturf(source.loc))
occupy_turf(source, source.loc)

/**
* Adds the movable to the list of movables with the element occupying the turf.
* If the turf was not on the list of occupied turfs before, a signal will be registered
* to it.
*/
/datum/element/footstep_override/proc/occupy_turf(atom/movable/movable, turf/location)
if(occupied_turfs[location])
occupied_turfs[location] |= movable
return
playsound(source, pick(sound_ref[played_step][1]), sound_ref[played_step][2] * volume, TRUE, sound_ref[played_step][3] + e_range, falloff_distance = 1, vary = sound_vary)
return COMPONENT_CANCEL_PLAY_FOOTSTEP
occupied_turfs[location] = list(movable)
RegisterSignal(location, COMSIG_TURF_PREPARE_STEP_SOUND, PROC_REF(prepare_steps))

/datum/element/footstep_override/Detach(datum/target)
. = ..()
if(ismovable(target))
RemoveElement(/datum/element/connect_loc, target, connection_signal)
/**
* Removes the movable from the list of movables with the element occupying the turf.
* If the turf is no longer occupied, it'll be removed from the list, and the signal
* unregistered from it
*/
/datum/element/footstep_override/proc/vacate_turf(atom/movable/movable, turf/location)
LAZYREMOVE(occupied_turfs[location], movable)
if(!occupied_turfs[location])
occupied_turfs -= location
UnregisterSignal(location, COMSIG_TURF_PREPARE_STEP_SOUND)

///Changes the sound types to be played if the element priority is higher than the one in the steps list.
/datum/element/footstep_override/proc/prepare_steps(turf/source, list/steps)
SIGNAL_HANDLER
if(steps[STEP_SOUND_PRIORITY] > priority)
return
steps[FOOTSTEP_MOB_SHOE] = footstep
steps[FOOTSTEP_MOB_BAREFOOT] = barefootstep
steps[FOOTSTEP_MOB_HEAVY] = heavyfootstep
steps[FOOTSTEP_MOB_CLAW] = clawfootstep
steps[STEP_SOUND_PRIORITY] = priority
return FOOTSTEP_OVERRIDEN
3 changes: 2 additions & 1 deletion code/game/objects/structures/industrial_lift.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
if(!id || lift_controller)
return ..()
new lift_controller_type(src)
return ..()
. = ..()
AddElement(/datum/element/footstep_override, footstep = FOOTSTEP_CATWALK)

/obj/structure/industrial_lift/proc/InitializeBlacklist()
type_blacklist = list()
Expand Down
4 changes: 4 additions & 0 deletions code/game/objects/structures/lattice.dm
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
canSmoothWith = list(SMOOTH_GROUP_CATWALK)
obj_flags = CAN_BE_HIT | BLOCK_Z_OUT_DOWN | BLOCK_Z_IN_UP

/obj/structure/lattice/catwalk/Initialize(mapload)
. = ..()
AddElement(/datum/element/footstep_override, footstep = FOOTSTEP_CATWALK)

/obj/structure/lattice/catwalk/deconstruction_hints(mob/user)
return span_notice("The supporting rods look like they could be <b>cut</b>.")

Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/structures/tables_racks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
if(_buildstack)
buildstack = _buildstack
AddElement(/datum/element/climbable)

AddElement(/datum/element/footstep_override, priority = STEP_SOUND_TABLE_PRIORITY)
var/static/list/loc_connections = list(
COMSIG_CARBON_DISARM_COLLIDE = PROC_REF(table_carbon),
)
Expand Down
4 changes: 4 additions & 0 deletions code/modules/recycling/conveyor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ GLOBAL_LIST_EMPTY(conveyors_by_id)
//Direction -> if we have a conveyor belt in that direction
var/list/neighbors

/obj/machinery/conveyor/Initialize(mapload)
. = ..()
AddElement(/datum/element/footstep_override, priority = STEP_SOUND_CONVEYOR_PRIORITY)

/obj/machinery/conveyor/examine(mob/user)
. = ..()
if(inverted)
Expand Down

0 comments on commit f460a1b

Please sign in to comment.