From 0048e75c801c33b15da3c45c19ea9ef7c3c05f65 Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Fri, 24 Jan 2020 10:06:06 +0000 Subject: [PATCH] Added new options: - ENABLE_TA enables fire ambient sound - VOLUME_TA controls fire ambient sound volume Fire ambient sound is played in a loop when there is active fire effect on screen. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8738 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- GameSettings.cpp | 2 + GameSettings.h | 2 + TileEngine/Ambient Control.cpp | 113 ++++++++++++++++++++++++++++++++- TileEngine/Ambient Control.h | 3 + TileEngine/SmokeEffects.cpp | 27 ++++++++ TileEngine/SmokeEffects.h | 3 + gameloop.cpp | 15 ++++- 7 files changed, 162 insertions(+), 3 deletions(-) diff --git a/GameSettings.cpp b/GameSettings.cpp index 645fc9ff..afc10eb5 100644 --- a/GameSettings.cpp +++ b/GameSettings.cpp @@ -932,6 +932,8 @@ void LoadGameExternalOptions() gGameExternalOptions.guiWeaponSoundEffectsVolume = iniReader.ReadInteger("Sound Settings","WEAPON_SOUND_EFFECTS_VOLUME", 0, 0, 1000 /*1000 = 10x?*/); gGameExternalOptions.gubMaxPercentNoiseSilencedSound = iniReader.ReadInteger("Sound Settings","MAX_PERCENT_NOISE_SILENCED_SOUND", 35, 0, 100 ); + gGameExternalOptions.fEnableTA = iniReader.ReadBoolean("Sound Settings", "ENABLE_TA", TRUE, false); + gGameExternalOptions.ubVolumeTA = iniReader.ReadInteger("Sound Settings", "VOLUME_TA", 50, 1, 127); //################# Tactical Interface Settings ################# diff --git a/GameSettings.h b/GameSettings.h index ad71dacf..3ebfdaa1 100644 --- a/GameSettings.h +++ b/GameSettings.h @@ -465,6 +465,8 @@ typedef struct //Sound settings UINT32 guiWeaponSoundEffectsVolume; UINT8 gubMaxPercentNoiseSilencedSound; + BOOLEAN fEnableTA; + UINT8 ubVolumeTA; // WDS - Option to turn off stealing BOOLEAN fStealingDisabled; diff --git a/TileEngine/Ambient Control.cpp b/TileEngine/Ambient Control.cpp index 7baeb619..78948a6b 100644 --- a/TileEngine/Ambient Control.cpp +++ b/TileEngine/Ambient Control.cpp @@ -12,12 +12,17 @@ #include "Game Events.h" #include "Ambient Control.h" #include "lighting.h" - #include "Random.h" + #include "Random.h" + #include "SmokeEffects.h" // sevenfm #endif AMBIENTDATA_STRUCT gAmbData[ MAX_AMBIENT_SOUNDS ]; -INT16 gsNumAmbData = 0; +INT16 gsNumAmbData = 0; +// sevenfm +UINT32 guiAmbientFire = NO_SAMPLE; +UINT8 gubAmbientFutureFireVolume = 0; +UINT32 guiFireAmbientLastUpdate = 0; UINT8 gubCurrentSteadyStateAmbience = SSA_NONE; UINT8 gubCurrentSteadyStateSound = 0; @@ -310,3 +315,107 @@ BOOLEAN SetSteadyStateAmbience( UINT8 ubAmbience ) return( TRUE ); } + +void UpdateFireAmbient(void) +{ + INT32 iVolume; + UINT32 uiClock; + + if (!gGameExternalOptions.fEnableTA) + { + return; + } + + if (guiCurrentScreen != GAME_SCREEN) + { + return; + } + + uiClock = GetJA2Clock(); + + if (uiClock - guiFireAmbientLastUpdate < 50) + { + return; + } + + guiFireAmbientLastUpdate = uiClock; + + if (FindVisibleSmokeEffect(BURNABLEGAS_SMOKE_EFFECT)) + { + gubAmbientFutureFireVolume = gGameExternalOptions.ubVolumeTA; + + if (guiAmbientFire == NO_SAMPLE) + { + StartFireAmbient(); + } + + // check if successfully started + if (guiAmbientFire != NO_SAMPLE) + { + iVolume = SoundGetVolume(guiAmbientFire); + + if (iVolume != gubAmbientFutureFireVolume) + { + // increase volume until it reaches desired level + iVolume = min((INT32)gubAmbientFutureFireVolume, iVolume + 4); + SoundSetVolume(guiAmbientFire, iVolume); + } + } + } + else + { + gubAmbientFutureFireVolume = 0; + + // check if ambient sound is playing + if (guiAmbientFire != NO_SAMPLE) + { + iVolume = SoundGetVolume(guiAmbientFire); + + if (iVolume != gubAmbientFutureFireVolume) + { + // increase volume until it reaches desired level + iVolume = max((INT32)gubAmbientFutureFireVolume, iVolume - 4); + SoundSetVolume(guiAmbientFire, iVolume); + } + + if (iVolume == 0) + { + StopFireAmbient(); + } + } + } +} + +void StopFireAmbient(void) +{ + if (guiAmbientFire != NO_SAMPLE) + { + SoundStop(guiAmbientFire); + guiAmbientFire = NO_SAMPLE; + } +} + +void StartFireAmbient(void) +{ + CHAR8 filename[1024]; + SOUNDPARMS spParms; + + // Stop ambient + if (guiAmbientFire != NO_SAMPLE) + { + return; + } + + strcpy(filename, "Sounds\\ambient\\fire.ogg"); + //gubAmbientFireVolume = LOWVOLUME; + + // start sound + memset(&spParms, 0xff, sizeof(SOUNDPARMS)); + //spParms.uiVolume = CalculateSoundEffectsVolume( LOWVOLUME ); + spParms.uiVolume = 0; + spParms.uiLoop = 0; + spParms.uiPriority = GROUP_AMBIENT; + + //guiAmbientFire = SoundPlay( zFileName, &spParms ); + guiAmbientFire = SoundPlayStreamedFile(filename, &spParms); +} diff --git a/TileEngine/Ambient Control.h b/TileEngine/Ambient Control.h index 67fc3428..a793dc66 100644 --- a/TileEngine/Ambient Control.h +++ b/TileEngine/Ambient Control.h @@ -18,6 +18,9 @@ extern INT16 gsNumAmbData; BOOLEAN SetSteadyStateAmbience( UINT8 ubAmbience ); +void UpdateFireAmbient(void); +void StopFireAmbient(void); +void StartFireAmbient(void); #define SOUND_NAME_SIZE 256 #define NUM_SOUNDS_PER_TIMEFRAME 8 diff --git a/TileEngine/SmokeEffects.cpp b/TileEngine/SmokeEffects.cpp index c82764e7..865387d5 100644 --- a/TileEngine/SmokeEffects.cpp +++ b/TileEngine/SmokeEffects.cpp @@ -1063,3 +1063,30 @@ BOOL GetRandomSignalSmokeGridNo(INT32* psGridNo) return TRUE; } + +BOOLEAN FindVisibleSmokeEffect(INT8 bType) +{ + UINT32 uiCnt; + INT8 bSmokeEffectLevel; + + //loop through all smoke effects + for (uiCnt = 0; uiCnt < guiNumSmokeEffects; uiCnt++) + { + if (gSmokeEffectData[uiCnt].fAllocated && + gSmokeEffectData[uiCnt].bType == bType) + { + if (gSmokeEffectData[uiCnt].bFlags & SMOKE_EFFECT_ON_ROOF) + bSmokeEffectLevel = 1; + else + bSmokeEffectLevel = 0; + + if (!TileIsOutOfBounds(gSmokeEffectData[uiCnt].sGridNo) && + GridNoOnScreen(gSmokeEffectData[uiCnt].sGridNo)) + { + return TRUE; + } + } + } + + return FALSE; +} diff --git a/TileEngine/SmokeEffects.h b/TileEngine/SmokeEffects.h index 8cec4bc4..ee601c25 100644 --- a/TileEngine/SmokeEffects.h +++ b/TileEngine/SmokeEffects.h @@ -73,4 +73,7 @@ void UpdateSmokeEffectGraphics( ); // Flugente: get the gridno and blevel of a random smoke signal, if one exists BOOL GetRandomSignalSmokeGridNo(INT32* psGridNo); +// find smoke effect on visible screen +BOOLEAN FindVisibleSmokeEffect(INT8 bType); + #endif \ No newline at end of file diff --git a/gameloop.cpp b/gameloop.cpp index a0c28095..55e5fafe 100644 --- a/gameloop.cpp +++ b/gameloop.cpp @@ -30,7 +30,8 @@ #include "Tactical Placement GUI.h"//dnl ch45 071009 #include "Map Screen Interface Map Inventory.h"//dnl ch51 081009 #include "World Items.h"//dnl ch77 191113 - #include "Overhead.h" // added by Flugente + #include "Overhead.h" // added by Flugente + #include "Ambient Control.h" // sevenfm #endif #include "SaveLoadScreen.h" @@ -409,6 +410,12 @@ void GameLoop(void) // rain RenderRain(); + // sevenfm: update tactical ambients + if (guiCurrentScreen == GAME_SCREEN) + { + UpdateFireAmbient(); + } + // Flugente: dynamic opinions: Dialogue Boxes need to be refreshed RefreshBoxes( ); @@ -533,6 +540,12 @@ void HandleNewScreenChange( UINT32 uiNewScreen, UINT32 uiOldScreen ) } } // end rain + + if (uiNewScreen != MSG_BOX_SCREEN) + { + // stop ambients + StopFireAmbient(); + } } void HandleShortCutExitState( void )