From 4bb8ad4d6fa1833a3a9a3ac6d352ff2043b958f8 Mon Sep 17 00:00:00 2001 From: Roman Chistokhodov Date: Mon, 25 Nov 2024 18:25:47 +0300 Subject: [PATCH] Add water related Player soundscripts --- dlls/client.cpp | 7 +++---- dlls/common_soundscripts.cpp | 20 ++++++++++++++++++++ dlls/common_soundscripts.h | 3 +++ dlls/player.cpp | 20 +++----------------- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/dlls/client.cpp b/dlls/client.cpp index b29af4a6e..33c69aacc 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -1008,10 +1008,9 @@ void ClientPrecache( void ) PRECACHE_SOUND( "player/pl_tile4.wav" ); PRECACHE_SOUND( "player/pl_tile5.wav" ); - PRECACHE_SOUND( "player/pl_swim1.wav" ); // breathe bubbles - PRECACHE_SOUND( "player/pl_swim2.wav" ); - PRECACHE_SOUND( "player/pl_swim3.wav" ); - PRECACHE_SOUND( "player/pl_swim4.wav" ); + pWorld->RegisterAndPrecacheSoundScript(Player::underwaterExhaleSoundScript); // breathe bubbles + pWorld->RegisterAndPrecacheSoundScript(Player::undrownSoundScript); + pWorld->RegisterAndPrecacheSoundScript(Player::emergeInhaleSoundScript); PRECACHE_SOUND( "player/pl_ladder1.wav" ); // climb ladder rung PRECACHE_SOUND( "player/pl_ladder2.wav" ); diff --git a/dlls/common_soundscripts.cpp b/dlls/common_soundscripts.cpp index 8fb16548f..bdb197c55 100644 --- a/dlls/common_soundscripts.cpp +++ b/dlls/common_soundscripts.cpp @@ -212,4 +212,24 @@ const NamedSoundScript vehicleIgnitionSoundScript = { "Player.VehicleUse" }; +const NamedSoundScript underwaterExhaleSoundScript = { + CHAN_BODY, + {"player/pl_swim1.wav", "player/pl_swim2.wav", "player/pl_swim3.wav", "player/pl_swim4.wav"}, + 0.8f, + ATTN_NORM, + "Player.UnderwaterExhale" +}; + +const NamedSoundScript undrownSoundScript = { + CHAN_VOICE, + {"player/pl_wade1.wav"}, + "Player.Undrown" +}; + +const NamedSoundScript emergeInhaleSoundScript = { + CHAN_VOICE, + {"player/pl_wade2.wav"}, + "Player.EmergeInhale" +}; + } diff --git a/dlls/common_soundscripts.h b/dlls/common_soundscripts.h index 2c7230ef6..95b43525b 100644 --- a/dlls/common_soundscripts.h +++ b/dlls/common_soundscripts.h @@ -53,6 +53,9 @@ namespace Player extern const NamedSoundScript fallBodySplatSoundScript; extern const NamedSoundScript trainUseSoundScript; extern const NamedSoundScript vehicleIgnitionSoundScript; +extern const NamedSoundScript underwaterExhaleSoundScript; +extern const NamedSoundScript undrownSoundScript; +extern const NamedSoundScript emergeInhaleSoundScript; } #endif diff --git a/dlls/player.cpp b/dlls/player.cpp index 5d9287b80..86717cf76 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -1479,9 +1479,9 @@ void CBasePlayer::WaterMove() // play 'up for air' sound if( pev->air_finished < gpGlobals->time ) - EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_wade1.wav", 1, ATTN_NORM ); + EmitSoundScript(Player::undrownSoundScript); else if( pev->air_finished < gpGlobals->time + 9 ) - EMIT_SOUND( ENT( pev ), CHAN_VOICE, "player/pl_wade2.wav", 1, ATTN_NORM ); + EmitSoundScript(Player::emergeInhaleSoundScript); pev->air_finished = gpGlobals->time + AIRTIME; pev->dmg = 2; @@ -1545,21 +1545,7 @@ void CBasePlayer::WaterMove() air = (int)( pev->air_finished - gpGlobals->time ); if( !RANDOM_LONG( 0, 0x1f ) && RANDOM_LONG( 0, AIRTIME - 1 ) >= air ) { - switch( RANDOM_LONG( 0, 3 ) ) - { - case 0: - EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_swim1.wav", 0.8, ATTN_NORM ); - break; - case 1: - EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_swim2.wav", 0.8, ATTN_NORM ); - break; - case 2: - EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_swim3.wav", 0.8, ATTN_NORM ); - break; - case 3: - EMIT_SOUND( ENT( pev ), CHAN_BODY, "player/pl_swim4.wav", 0.8, ATTN_NORM ); - break; - } + EmitSoundScript(Player::underwaterExhaleSoundScript); } }