diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index 7e1a83486d..f006caf1c1 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -452,6 +452,9 @@ #define COMPONENT_TWOHANDED_BLOCK_WIELD 1 #define COMSIG_TWOHANDED_UNWIELD "twohanded_unwield" //from base of datum/component/two_handed/proc/unwield(mob/living/carbon/user): (/mob/user) +// /datum/component/squeak signals +#define COMSIG_CROSS_SQUEAKED "cross_squeaked" // sent when a squeak component squeaks from crossing something, to delay anything else crossing that might squeak to prevent ear hurt. + // /datum/action signals #define COMSIG_ACTION_TRIGGER "action_trigger" //from base of datum/action/proc/Trigger(): (datum/action) #define COMPONENT_ACTION_BLOCK_TRIGGER 1 diff --git a/code/datums/components/squeak.dm b/code/datums/components/squeak.dm index 792222b27b..df44aef4de 100644 --- a/code/datums/components/squeak.dm +++ b/code/datums/components/squeak.dm @@ -11,6 +11,13 @@ // This is to stop squeak spam from inhand usage var/last_use = 0 var/use_delay = 20 + + // squeak cooldowns + var/last_squeak = 0 + var/squeak_delay = 5 + + /// chance we'll be stopped from squeaking by cooldown when something crossing us squeaks + var/cross_squeak_delay_chance = 33 // about 3 things can squeak at a time /datum/component/squeak/Initialize(custom_sounds, volume_override, chance_override, step_delay_override, use_delay_override) if(!isatom(parent)) @@ -19,6 +26,7 @@ if(ismovable(parent)) RegisterSignal(parent, list(COMSIG_MOVABLE_BUMP, COMSIG_MOVABLE_IMPACT), .proc/play_squeak) RegisterSignal(parent, list(COMSIG_MOVABLE_CROSSED, COMSIG_ITEM_WEARERCROSSED), .proc/play_squeak_crossed) + RegisterSignal(parent, COMSIG_CROSS_SQUEAKED, .proc/delay_squeak) RegisterSignal(parent, COMSIG_MOVABLE_DISPOSING, .proc/disposing_react) if(isitem(parent)) RegisterSignal(parent, list(COMSIG_ITEM_ATTACK, COMSIG_ITEM_ATTACK_OBJ, COMSIG_ITEM_HIT_REACT), .proc/play_squeak) @@ -39,20 +47,28 @@ use_delay = use_delay_override /datum/component/squeak/proc/play_squeak() + do_play_squeak() + +/datum/component/squeak/proc/do_play_squeak(bypass_cooldown = FALSE) + if(!bypass_cooldown && ((last_squeak + squeak_delay) >= world.time)) + return FALSE if(prob(squeak_chance)) if(!override_squeak_sounds) playsound(parent, pickweight(default_squeak_sounds), volume, 1, -1) else playsound(parent, pickweight(override_squeak_sounds), volume, 1, -1) + last_squeak = world.time + return TRUE + return FALSE /datum/component/squeak/proc/step_squeak() if(steps > step_delay) - play_squeak() + do_play_squeak(TRUE) steps = 0 else steps++ -/datum/component/squeak/proc/play_squeak_crossed(atom/movable/AM) +/datum/component/squeak/proc/play_squeak_crossed(datum/source, atom/movable/AM) if(isitem(AM)) var/obj/item/I = AM if(I.item_flags & ABSTRACT) @@ -63,13 +79,18 @@ return var/atom/current_parent = parent if(isturf(current_parent.loc)) - play_squeak() + if(do_play_squeak()) + SEND_SIGNAL(AM, COMSIG_CROSS_SQUEAKED) /datum/component/squeak/proc/use_squeak() if(last_use + use_delay < world.time) last_use = world.time play_squeak() +/datum/component/squeak/proc/delay_squeak() + if(prob(cross_squeak_delay_chance)) + last_squeak = world.time + /datum/component/squeak/proc/on_equip(datum/source, mob/equipper, slot) RegisterSignal(equipper, COMSIG_MOVABLE_DISPOSING, .proc/disposing_react, TRUE)