diff --git a/src/playsim/actor.h b/src/playsim/actor.h index 745c4be9d..30fdc55e8 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -1411,6 +1411,7 @@ public: bool IsMapActor(); bool SetState (FState *newstate, bool nofunction=false); void SplashCheck(); + void PlayDiveOrSurfaceSounds(int oldlevel = 0); bool UpdateWaterLevel (bool splash=true); bool isFast(); bool isSlow(); diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index 3f08d3a39..d216d30d8 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -2937,7 +2937,7 @@ void AActor::CallFallAndSink(double grav, double oldfloorz) } else { - FallAndSink(grav, oldfloorz); + FallAndSink(grav, oldfloorz); } } @@ -4614,6 +4614,23 @@ void AActor::SplashCheck() return; } +//========================================================================== +// +// AActor::PlayDiveOrSurfaceSounds +// +// Plays diving or surfacing sounds for the player +// +//========================================================================== + +void AActor::PlayDiveOrSurfaceSounds(int oldlevel) +{ + IFVIRTUAL(AActor, PlayDiveOrSurfaceSounds) + { + VMValue params[2] = { (DObject *)this, oldlevel }; + VMCall(func, params, 2, nullptr, 0); + } +} + //========================================================================== // // AActor::UpdateWaterLevel @@ -4637,21 +4654,7 @@ bool AActor::UpdateWaterLevel(bool dosplash) if (player != nullptr) { - if (oldlevel < 3 && waterlevel == 3) - { - // Our head just went under. - S_Sound(this, CHAN_VOICE, 0, "*dive", 1, ATTN_NORM); - } - else if (oldlevel == 3 && waterlevel < 3) - { - // Our head just came up. - if (player->air_finished > Level->maptime) - { - // We hadn't run out of air yet. - S_Sound(this, CHAN_VOICE, 0, "*surface", 1, ATTN_NORM); - } - // If we were running out of air, then ResetAirSupply() will play *gasp. - } + PlayDiveOrSurfaceSounds(oldlevel); } return false; // we did the splash ourselves diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 768837d59..2658a052f 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -1450,6 +1450,25 @@ class Actor : Thinker native } } + virtual void PlayDiveOrSurfaceSounds(int oldlevel) + { + if (oldlevel < 3 && WaterLevel == 3) + { + // Our head just went under. + A_StartSound("*dive", CHAN_VOICE, attenuation: ATTN_NORM); + } + else if (oldlevel == 3 && WaterLevel < 3) + { + // Our head just came up. + if (player.air_finished > Level.maptime) + { + // We hadn't run out of air yet. + A_StartSound("*surface", CHAN_VOICE, attenuation: ATTN_NORM); + } + // If we were running out of air, then ResetAirSupply() will play *gasp. + } + } + //---------------------------------------------------------------------------- // // PROC A_CheckSkullDone