Skip to content

Commit

Permalink
Emote pitch
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMelbert committed Jan 27, 2025
1 parent 34090ec commit 24be637
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
26 changes: 24 additions & 2 deletions code/datums/emotes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
var/sound
/// Used for the honk borg emote.
var/vary = FALSE
/// If this emote's sound is affected by TTS pitch
var/affected_by_pitch = TRUE
/// Can only code call this event instead of the player.
var/only_forced_audio = FALSE
/// The cooldown between the uses of the emote.
Expand Down Expand Up @@ -103,10 +105,30 @@

user.log_message(msg, LOG_EMOTE)

var/tmp_sound = get_sound(user)
var/sound/tmp_sound = get_sound(user)
if(tmp_sound && should_play_sound(user, intentional) && TIMER_COOLDOWN_FINISHED(user, type))
var/do_vary = vary
if(do_vary && affected_by_pitch && isliving(user))
if(!istype(tmp_sound))
tmp_sound = sound(get_sfx(tmp_sound))
var/mob/living/emoter = user
var/user_mod = 1
if(emoter.speech_sound_pitch_modifier != 1)
user_mod = round(sqrt(emoter.speech_sound_pitch_modifier), 0.1)
if(emoter.speech_sound_frequency_modifier != 1)
user_mod = round(sqrt(emoter.speech_sound_frequency_modifier), 0.1)
// here is where variation is factored in
user_mod = clamp(user_mod + pick(-0.1, 0, 0.1), 0.5, 2)
// so subtypes can set custom frequencies
tmp_sound.frequency ||= 1
// regardless of pitch or frequency, we will always use frequency,
// because it sounds better for these quick sounds
tmp_sound.frequency *= user_mod
// otherwise it will override what we just set
do_vary = FALSE

TIMER_COOLDOWN_START(user, type, audio_cooldown)
playsound(user, tmp_sound, 50, vary)
playsound(user, tmp_sound, 50, do_vary)

var/is_important = emote_type & EMOTE_IMPORTANT
var/is_visual = emote_type & EMOTE_VISIBLE
Expand Down
5 changes: 3 additions & 2 deletions code/modules/mob/living/carbon/emote.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
emote_type = EMOTE_AUDIBLE | EMOTE_VISIBLE
audio_cooldown = 5 SECONDS
vary = TRUE
affected_by_pitch = FALSE

/datum/emote/living/carbon/clap/get_sound(mob/living/user)
if(!user.get_bodypart(BODY_ZONE_L_ARM) || !user.get_bodypart(BODY_ZONE_R_ARM))
Expand Down Expand Up @@ -176,6 +177,8 @@
emote_type = EMOTE_AUDIBLE | EMOTE_VISIBLE
hands_use_check = TRUE
muzzle_ignore = TRUE
vary = TRUE
affected_by_pitch = FALSE

/datum/emote/living/carbon/snap/get_sound(mob/living/user)
if(ishuman(user))
Expand Down Expand Up @@ -219,6 +222,4 @@
emote_type = EMOTE_AUDIBLE | EMOTE_VISIBLE

/datum/emote/living/carbon/whistle/get_sound(mob/living/user)
if(!istype(user))
return
return 'sound/voice/human/whistle1.ogg'
3 changes: 3 additions & 0 deletions code/modules/mob/living/emote.dm
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
message_mime = "gasps silently!"
emote_type = EMOTE_VISIBLE | EMOTE_AUDIBLE
stat_allowed = HARD_CRIT
vary = TRUE

/datum/emote/living/gasp/get_sound(mob/living/carbon/human/user)
if(!istype(user))
Expand Down Expand Up @@ -279,6 +280,7 @@
key_third_person = "jumps"
message = "jumps!"
hands_use_check = TRUE
affected_by_pitch = FALSE

/datum/emote/living/jump/run_emote(mob/living/user, params, type_override, intentional)
. = ..()
Expand Down Expand Up @@ -469,6 +471,7 @@
message_mime = "sleeps soundly."
emote_type = EMOTE_VISIBLE | EMOTE_AUDIBLE
stat_allowed = UNCONSCIOUS
vary = TRUE

// eventually we want to give species their own "snoring" sounds
/datum/emote/living/snore/get_sound(mob/living/carbon/human/user)
Expand Down

0 comments on commit 24be637

Please sign in to comment.