From 94b7d5611d531c200e353578a95121d7c8c00744 Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Sun, 16 Jan 2022 13:33:11 +0000 Subject: [PATCH] Improved door noise sound playing: only play sound if merc opening/closing door is visible on screen or if player team hears noise from door. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9259 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Handle Doors.cpp | 19 ++++++++++++++----- Tactical/opplist.cpp | 15 ++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Tactical/Handle Doors.cpp b/Tactical/Handle Doors.cpp index 978838256..5d0df347e 100644 --- a/Tactical/Handle Doors.cpp +++ b/Tactical/Handle Doors.cpp @@ -51,7 +51,7 @@ #endif BOOLEAN gfSetPerceivedDoorState = FALSE; - +extern BOOLEAN gfPlayerMercHeardNoise; BOOLEAN HandleDoorsOpenClose( SOLDIERTYPE *pSoldier, INT32 sGridNo, STRUCTURE * pStructure, BOOLEAN fNoAnimations ); @@ -1161,6 +1161,9 @@ BOOLEAN HandleDoorsOpenClose( SOLDIERTYPE *pSoldier, INT32 sGridNo, STRUCTURE * cnt++; }; + // sevenfm: reset code to detect heard noise + gfPlayerMercHeardNoise = FALSE; + if (pSoldier && pSoldier->ubDoorOpeningNoise > 0) { //shadooow: noise handling moved here so we can work with modified value of pSoldier->ubDoorOpeningNoise @@ -1281,8 +1284,11 @@ BOOLEAN HandleDoorsOpenClose( SOLDIERTYPE *pSoldier, INT32 sGridNo, STRUCTURE * uiSoundID = METAL_DOOR_OPEN; } - // OK, We must know what sound to play, for now use same sound for all doors... - PlayJA2Sample( uiSoundID, RATE_11025, SoundVolume( MIDVOLUME, sGridNo ), 1, SoundDir( sGridNo ) ); + if (pSoldier && pSoldier->bVisible == TRUE || gfPlayerMercHeardNoise) + { + // OK, We must know what sound to play, for now use same sound for all doors... + PlayJA2Sample(uiSoundID, RATE_11025, SoundVolume(MIDVOLUME, sGridNo), 1, SoundDir(sGridNo)); + } } if (((gWorldSectorX == gModSettings.ubInitialPOWSectorX && gWorldSectorY == gModSettings.ubInitialPOWSectorY) || @@ -1408,8 +1414,11 @@ BOOLEAN HandleDoorsOpenClose( SOLDIERTYPE *pSoldier, INT32 sGridNo, STRUCTURE * uiSoundID = METAL_DOOR_CLOSE; } - // OK, We must know what sound to play, for now use same sound for all doors... - PlayJA2Sample(uiSoundID, RATE_11025, SoundVolume(MIDVOLUME, sGridNo), 1, SoundDir(sGridNo)); + if (pSoldier && pSoldier->bVisible == TRUE || gfPlayerMercHeardNoise) + { + // OK, We must know what sound to play, for now use same sound for all doors... + PlayJA2Sample(uiSoundID, RATE_11025, SoundVolume(MIDVOLUME, sGridNo), 1, SoundDir(sGridNo)); + } } } diff --git a/Tactical/opplist.cpp b/Tactical/opplist.cpp index bc9c26a4f..2cd84d82f 100644 --- a/Tactical/opplist.cpp +++ b/Tactical/opplist.cpp @@ -5784,7 +5784,7 @@ void TheirNoise(UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrType // else if noiseMaker's NOBODY, no opplist changes or interrupts are possible } - +BOOLEAN gfPlayerMercHeardNoise = FALSE; void ProcessNoise(UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrType, UINT8 ubBaseVolume, UINT8 ubNoiseType, STR16 zNoiseMessage ) { @@ -6019,6 +6019,15 @@ void ProcessNoise(UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrTy continue; } + // Can the listener hear noise of that volume given his circumstances? + ubEffVolume = CalcEffVolume(pSoldier, sGridNo, bLevel, ubNoiseType, ubBaseVolume, bCheckTerrain, pSoldier->bOverTerrainType, ubSourceTerrType); + + // sevenfm: indicate that player team heard noise + if (bTeam == gbPlayerNum && ubEffVolume > 0) + { + gfPlayerMercHeardNoise = TRUE; + } + // if a the noise maker is a person, not just NOBODY if (ubNoiseMaker < TOTAL_SOLDIERS) { @@ -6147,15 +6156,11 @@ void ProcessNoise(UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrTy pSoldier->ubMiscSoldierFlags |= SOLDIER_MISC_HEARD_GUNSHOT; } - // Can the listener hear noise of that volume given his circumstances? - ubEffVolume = CalcEffVolume(pSoldier,sGridNo,bLevel,ubNoiseType,ubBaseVolume,bCheckTerrain,pSoldier->bOverTerrainType,ubSourceTerrType); - #ifdef RECORDOPPLIST fprintf(OpplistFile,"PN: guy %d - effVol=%d,chkTer=%d,pSoldier->tType=%d,srcTType=%d\n", bLoop,effVolume,bCheckTerrain,pSoldier->terrtype,ubSourceTerrType); #endif - if (ubEffVolume > 0) { // ALL RIGHT! Passed all the tests, this listener hears this noise!!!