diff --git a/Editor/editscreen.cpp b/Editor/editscreen.cpp index dc16bc35..fbc10abe 100644 --- a/Editor/editscreen.cpp +++ b/Editor/editscreen.cpp @@ -1611,7 +1611,7 @@ void HandleKeyboardShortcuts( ) break; case F4: - MusicPlay( giMusicID ); + MusicPlay( giMusicID, MUSIC_OLD_TYPE, FALSE ); ScreenMsg( FONT_YELLOW, MSG_DEBUG, L"%S", szMusicList[giMusicID] ); giMusicID++; if( giMusicID >= NUM_MUSIC ) diff --git a/Init.cpp b/Init.cpp index 0fb77b9e..17a5a619 100644 --- a/Init.cpp +++ b/Init.cpp @@ -1330,6 +1330,29 @@ BackupBRandEncyclopedia ( gBriefingRoomData, gBriefingRoomDataBackup, 0); { gAimOldArchives[p-1].FaceID=-1; } + + + UINT32 iloop; + UINT32 zloop; + for(iloop=0; iloop<256; iloop++) + { + for(zloop=0; zloop<4; zloop++) + { + MusicSoundValues[iloop].uiIndex = iloop; + MusicSoundValues[iloop].SoundTacticalVictory[zloop] = -1; + MusicSoundValues[iloop].SoundTacticalBattle[zloop] = -1; + MusicSoundValues[iloop].SoundTacticalNothing[zloop] = -1; + MusicSoundValues[iloop].SoundTacticalTensor[zloop] = -1; + MusicSoundValues[iloop].SoundTacticalDeath[zloop] = -1; + } + } + + CHAR8 zFileName[255]; + sprintf( zFileName, "scripts\\Music.lua" ); + if (FileExists( zFileName ) ) + { + LetLuaMusicControl(0); + } LuaState::INIT(lua::LUA_STATE_STRATEGIC_MINES_AND_UNDERGROUND, true); g_luaUnderground.LoadScript(GetLanguagePrefix()); diff --git a/SaveLoadGame.cpp b/SaveLoadGame.cpp index e487bd00..82f1dfdd 100644 --- a/SaveLoadGame.cpp +++ b/SaveLoadGame.cpp @@ -3983,6 +3983,15 @@ if( !SaveNewEmailDataToSaveGameFile( hFile ) ) } //restore the music mode + if ( GetMusicMode() == MUSIC_TACTICAL_NOTHING && MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] != -1 ) + SetMusicModeID( GetMusicMode(), MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] ); + else if ( GetMusicMode() == MUSIC_TACTICAL_ENEMYPRESENT && MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] != -1 ) + SetMusicModeID( GetMusicMode(), MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] ); + else if ( GetMusicMode() == MUSIC_TACTICAL_BATTLE && MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ] != -1 ) + SetMusicModeID( GetMusicMode(), MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ] ); + else if ( GetMusicMode() == MUSIC_TACTICAL_VICTORY && MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalVictory[gbWorldSectorZ] != -1 ) + SetMusicModeID( GetMusicMode(), MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalVictory[gbWorldSectorZ] ); + else SetMusicMode( GetMusicMode() ); //Unset the fact that we are saving a game @@ -5870,7 +5879,23 @@ BOOLEAN LoadSavedGame( int ubSavedGameID ) RemoveLoadingScreenProgressBar(); + //if( SaveGameHeader.fWorldLoaded ) + //{ + if ( gMusicModeToPlay == MUSIC_TACTICAL_NOTHING && MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] != -1 ) + SetMusicModeID( gMusicModeToPlay, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] ); + else if ( gMusicModeToPlay == MUSIC_TACTICAL_ENEMYPRESENT && MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] != -1 ) + SetMusicModeID( gMusicModeToPlay, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] ); + else if ( gMusicModeToPlay == MUSIC_TACTICAL_BATTLE && MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ] != -1 ) + SetMusicModeID( gMusicModeToPlay, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ] ); + else if ( gMusicModeToPlay == MUSIC_TACTICAL_VICTORY && MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalVictory[gbWorldSectorZ] != -1 ) + SetMusicModeID( gMusicModeToPlay, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalVictory[gbWorldSectorZ] ); + else SetMusicMode( gMusicModeToPlay ); + //} + //else + //{ + // SetMusicMode( gMusicModeToPlay ); + //} #ifndef JA2TESTVERSION RESET_CHEAT_LEVEL( ); diff --git a/Strategic/LuaInitNPCs.cpp b/Strategic/LuaInitNPCs.cpp index 2ca53681..3df3cfc2 100644 --- a/Strategic/LuaInitNPCs.cpp +++ b/Strategic/LuaInitNPCs.cpp @@ -519,8 +519,12 @@ static int l_AnimMercPtsrusStrategicInsertionData (lua_State *L); static int l_SetMusicMode (lua_State *L); static int l_MusicPlay (lua_State *L); +static int l_MusicPlayId (lua_State *L); static int l_MusicSetVolume (lua_State *L); static int l_MusicGetVolume (lua_State *L); +static int l_gAddMusic(lua_State *L); +static int l_SetMusicID (lua_State *L); +static int l_GetMusicID (lua_State *L); //static int l_MusicStop (lua_State *L); //static int l_MusicFadeOut (lua_State *L); //static int l_MusicFadeIn (lua_State *L); @@ -787,6 +791,7 @@ BOOLEAN LuaInternalQuest( UINT8 ubQuest, INT16 sSectorX, INT16 sSectorY, BOOLEAN static int l_GiveQuestRewardPoint(lua_State *L); BOOLEAN LuaExecuteStrategicEvent( UINT8 EventCallbackID, UINT32 uiTimeStamp, UINT32 uiTimeOffset, UINT8 ubEventType, UINT8 ubFlags, UINT32 EventParam, UINT32 Init); BOOLEAN LuaIDScripts(UINT8 Init, UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum); +BOOLEAN LetLuaMusicControl(UINT8 Init); static int l_CurrentSquad (lua_State *L); static int l_SetgfTacticalTraversal (lua_State *L); @@ -1281,6 +1286,12 @@ void IniFunction(lua_State *L, BOOLEAN bQuests ) lua_register(L, "PlayJA2Sample", l_PlayJA2Sample); lua_register(L, "SetMusicMode", l_SetMusicMode ); lua_register(L, "MusicPlay", l_MusicPlay ); + lua_register(L, "MusicIdPlay", l_MusicPlayId ); + lua_register(L, "AddMusic", l_gAddMusic ); + + lua_register(L, "SetMusicID", l_SetMusicID ); + lua_register(L, "GetMusicID", l_GetMusicID ); + lua_register(L, "MusicSetVolume", l_MusicSetVolume ); lua_register(L, "MusicGetVolume", l_MusicGetVolume ); //lua_register(L, "MusicStop", l_MusicStop ); @@ -1591,6 +1602,25 @@ void IniFunction(lua_State *L, BOOLEAN bQuests ) } +BOOLEAN LetLuaMusicControl(UINT8 Init) +{ + const char* filename = "scripts\\Music.lua"; + + LuaScopeState _LS(true); + + IniFunction( _LS.L(), TRUE ); + IniGlobalGameSetting( _LS.L() ); + + SGP_THROW_IFFALSE( _LS.L.EvalFile(filename), _BS("Cannot open file: ") << filename << _BS::cget ); + + if ( Init == 0 ) + { + LuaFunction(_LS.L, "Music" ).Call(0); + } + + return true; +} + //------------------- intro ----------- BOOLEAN LuaIntro(UINT8 Init, UINT32 uiCurrentVideo, INT8 bIntroType, UINT32 iStringToUse ) @@ -5219,13 +5249,146 @@ static int l_MusicSetVolume (lua_State *L) return 0; } +static int l_SetMusicID (lua_State *L) +{ + if ( lua_gettop(L) >= 4 ) + { + INT16 x = lua_tointeger(L,1); + INT16 y = lua_tointeger(L,2); + INT16 z = lua_tointeger(L,3); + UINT8 MusicType = lua_tointeger(L,4); + + if ( MusicType == 1 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + SetMusicModeID( MUSIC_TACTICAL_NOTHING, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalNothing[z] ); + } + else if ( MusicType == 2 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + SetMusicModeID( MUSIC_TACTICAL_ENEMYPRESENT, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalTensor[z] ); + } + else if ( MusicType == 3 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + SetMusicModeID( MUSIC_TACTICAL_BATTLE, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalBattle[z] ); + } + else if ( MusicType == 4 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + SetMusicModeID( MUSIC_TACTICAL_VICTORY, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalVictory[z] ); + } + else if ( MusicType == 5 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + SetMusicModeID( MUSIC_TACTICAL_DEATH, MusicSoundValues[ SECTOR( x, y ) ].SoundTacticalDeath[z] ); + } + } + +return 0; +} + +static int l_GetMusicID (lua_State *L) +{ + +INT32 SoundID = -1; + + if ( lua_gettop(L) >= 4 ) + { + INT16 x = lua_tointeger(L,1); + INT16 y = lua_tointeger(L,2); + INT16 z = lua_tointeger(L,3); + UINT8 MusicType = lua_tointeger(L,4); + + if ( MusicType == 1 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + SoundID = MusicSoundValues[SECTOR( x, y )].SoundTacticalNothing[z]; + } + else if ( MusicType == 2 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + SoundID = MusicSoundValues[SECTOR( x, y )].SoundTacticalTensor[z]; + } + else if ( MusicType == 3 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + SoundID = MusicSoundValues[SECTOR( x, y )].SoundTacticalBattle[z]; + } + else if ( MusicType == 4 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + SoundID = MusicSoundValues[SECTOR( x, y )].SoundTacticalVictory[z]; + } + } + + lua_pushinteger(L, SoundID); + +return 1; +} + +static int l_gAddMusic(lua_State *L) +{ + if ( lua_gettop(L) >= 5 ) + { + INT16 x = lua_tointeger(L,1); + INT16 y = lua_tointeger(L,2); + INT16 z = lua_tointeger(L,3); + UINT8 MusicType = lua_tointeger(L,4); + INT32 SoundId = lua_tointeger(L,5); + + /* + MUSIC_NONE 0 + MUSIC_TACTICAL_NOTHING, 1 + MUSIC_TACTICAL_ENEMYPRESENT,2 + MUSIC_TACTICAL_BATTLE,3 + MUSIC_TACTICAL_VICTORY,4 + */ + if ( MusicType == 1 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + MusicSoundValues[SECTOR( x, y )].SoundTacticalNothing[z] = SoundId; + } + else if ( MusicType == 2 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + MusicSoundValues[SECTOR( x, y )].SoundTacticalTensor[z] = SoundId; + } + else if ( MusicType == 3 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + MusicSoundValues[SECTOR( x, y )].SoundTacticalBattle[z] = SoundId; + } + else if ( MusicType == 4 ) + { + if ((x>=1 || x<=16) && (y>=1 || y<=16) && (z>=0 || z<=3) ) + MusicSoundValues[SECTOR( x, y )].SoundTacticalVictory[z] = SoundId; + } + } + + return 0; +} + static int l_MusicPlay (lua_State *L) { if ( lua_gettop(L) >= 1 ) { UINT32 uiNum = lua_tointeger(L,1); - MusicPlay( uiNum ); + MusicPlay( uiNum, MUSIC_OLD_TYPE, FALSE); + } +return 0; +} + +static int l_MusicPlayId (lua_State *L) +{ + if ( lua_gettop(L) >= 2 ) + { + UINT32 uiNum = lua_tointeger(L,1); + UINT32 uiType = lua_tointeger(L,2); + + if (uiType>=1 || uiType<=5 ) + MusicPlay( uiNum, uiType, TRUE); } return 0; } diff --git a/Strategic/LuaInitNPCs.h b/Strategic/LuaInitNPCs.h index d448fd45..ff2977d4 100644 --- a/Strategic/LuaInitNPCs.h +++ b/Strategic/LuaInitNPCs.h @@ -82,4 +82,5 @@ extern BOOLEAN LetLuaMakeBadSectorListFromMapsOnHardDrive(UINT8 Init); extern BOOLEAN LuaIntro(UINT8 Init, UINT32 uiCurrentVideo, INT8 bIntroType, UINT32 iStringToUse); extern BOOLEAN LuaIDScripts(UINT8 Init, UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum); +extern BOOLEAN LetLuaMusicControl(UINT8 Init); #endif diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index 45b6e564..9cddc930 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -2282,6 +2282,10 @@ BOOLEAN SetCurrentWorldSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ ) // ATE; Fade FA.T.... SetMusicFadeSpeed( 5 ); + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_NOTHING, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] ); + else SetMusicMode( MUSIC_TACTICAL_NOTHING ); } @@ -4464,6 +4468,11 @@ void AllMercsHaveWalkedOffSector( ) // ATE; Fade FAST.... SetMusicFadeSpeed( 5 ); + + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_NOTHING, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] ); + else SetMusicMode( MUSIC_TACTICAL_NOTHING ); } } diff --git a/Tactical/Merc Entering.cpp b/Tactical/Merc Entering.cpp index 4834a8bb..96953cf2 100644 --- a/Tactical/Merc Entering.cpp +++ b/Tactical/Merc Entering.cpp @@ -46,6 +46,7 @@ #include "ub_config.h" #endif +#include "Music Control.h" //forward declarations of common classes to eliminate includes class OBJECTTYPE; @@ -909,14 +910,23 @@ void HandleFirstHeliDropOfGame( ) #ifdef ENABLE_ZOMBIES UseCreatureMusic(HostileZombiesPresent()); #endif + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_ENEMYPRESENT, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] ); + else + SetMusicMode( MUSIC_TACTICAL_ENEMYPRESENT ); - SetMusicMode( MUSIC_TACTICAL_ENEMYPRESENT ); } else { // Say quote..... SayQuoteFromAnyBodyInSector( QUOTE_MERC_REACHED_DESTINATION ); // Start music + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] != -1 ) + //SetMusicMode( MUSIC_TACTICAL_VICTORY ); + SetMusicModeID( MUSIC_TACTICAL_NOTHING, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] ); + else SetMusicMode( MUSIC_TACTICAL_NOTHING ); } diff --git a/Tactical/Overhead.cpp b/Tactical/Overhead.cpp index 1e3b88f5..4b89a734 100644 --- a/Tactical/Overhead.cpp +++ b/Tactical/Overhead.cpp @@ -117,6 +117,7 @@ #include "LuaInitNPCs.h" #include "Interface.h" #include "Vehicles.h" +#include "Music Control.h" #ifdef JA2UB #include "Ja25 Strategic Ai.h" #include "Ja25_Tactical.h" @@ -5885,6 +5886,10 @@ void CommonEnterCombatModeCode( ) // Say quote..... // Change music modes + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_BATTLE, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ]); + else SetMusicMode( MUSIC_TACTICAL_BATTLE ); DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"CommonEnterCombatMode done"); @@ -6047,6 +6052,10 @@ void ExitCombatMode( ) UseCreatureMusic(HostileZombiesPresent()); #endif + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_ENEMYPRESENT, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] ); + else SetMusicMode( MUSIC_TACTICAL_ENEMYPRESENT ); BetweenTurnsVisibilityAdjustments(); @@ -6109,8 +6118,12 @@ void SetEnemyPresence( ) #ifdef ENABLE_ZOMBIES UseCreatureMusic(HostileZombiesPresent()); #endif + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_ENEMYPRESENT, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] ); + else + SetMusicMode( MUSIC_TACTICAL_ENEMYPRESENT ); - SetMusicMode( MUSIC_TACTICAL_ENEMYPRESENT ); DebugMsg(TOPIC_JA2,DBG_LEVEL_3,String("SetEnemyPresence: warnings = false")); sniperwarning = FALSE; biggunwarning = FALSE; @@ -6450,7 +6463,10 @@ BOOLEAN CheckForEndOfCombatMode( BOOLEAN fIncrementTurnsNotSeen ) #ifdef ENABLE_ZOMBIES UseCreatureMusic(HostileZombiesPresent()); #endif - + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_ENEMYPRESENT, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalTensor[gbWorldSectorZ] ); + else SetMusicMode( MUSIC_TACTICAL_ENEMYPRESENT ); return( TRUE ); @@ -6905,6 +6921,10 @@ BOOLEAN CheckForEndOfBattle( BOOLEAN fAnEnemyRetreated ) } // Play death music + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalDeath[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalDeath[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_DEATH, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalDeath[gbWorldSectorZ] ); + else SetMusicMode( MUSIC_TACTICAL_DEATH ); SetCustomizableTimerCallbackAndDelay( 10000, DeathNoMessageTimerCallback, FALSE ); @@ -7058,6 +7078,10 @@ BOOLEAN CheckForEndOfBattle( BOOLEAN fAnEnemyRetreated ) // Change music modes if ( gfLastMercTalkedAboutKillingID == NOBODY || ( gfLastMercTalkedAboutKillingID != NOBODY && !( MercPtrs[ gfLastMercTalkedAboutKillingID ]->flags.uiStatusFlags & SOLDIER_MONSTER ) ) ) { + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalVictory[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalVictory[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_VICTORY, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalVictory[gbWorldSectorZ] ); + else SetMusicMode( MUSIC_TACTICAL_VICTORY ); // OJW - 20081222 - dont auto-bandage if networked @@ -7107,6 +7131,10 @@ BOOLEAN CheckForEndOfBattle( BOOLEAN fAnEnemyRetreated ) else { // Change to nothing music... + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_NOTHING, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalNothing[gbWorldSectorZ] ); + else SetMusicMode( MUSIC_TACTICAL_NOTHING ); // OJW - 20081222 - dont auto bandage if networked if (!is_networked) diff --git a/Tactical/opplist.cpp b/Tactical/opplist.cpp index 7e4e2cab..e5b346b3 100644 --- a/Tactical/opplist.cpp +++ b/Tactical/opplist.cpp @@ -54,6 +54,8 @@ #include "Ja25_Tactical.h" #endif +#include "Music Control.h" + #include "connect.h" #include "../ModularizedTacticalAI/include/Plan.h" #include "../ModularizedTacticalAI/include/PlanFactoryLibrary.h" @@ -3620,6 +3622,10 @@ void OurTeamSeesSomeone( SOLDIERTYPE * pSoldier, INT8 bNumReRevealed, INT8 bNumN // If we are NOT in any music mode... if ( GetMusicMode() == MUSIC_NONE ) { + GlobalSoundID = MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ]; + if ( MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ] != -1 ) + SetMusicModeID( MUSIC_TACTICAL_BATTLE, MusicSoundValues[ SECTOR( gWorldSectorX, gWorldSectorY ) ].SoundTacticalBattle[gbWorldSectorZ] ); + else SetMusicMode( MUSIC_TACTICAL_BATTLE ); } } diff --git a/Utils/Music Control.cpp b/Utils/Music Control.cpp index f15021fc..f37faf92 100644 --- a/Utils/Music Control.cpp +++ b/Utils/Music Control.cpp @@ -29,9 +29,14 @@ static UINT8 gubOldMusicMode = 0; static INT8 gbVictorySongCount = 0; static INT8 gbDeathSongCount = 0; -static INT8 bNothingModeSong; -static INT8 bEnemyModeSong; -static INT8 bBattleModeSong; +static INT32 bNothingModeSong; +static INT32 bEnemyModeSong; +static INT32 bBattleModeSong; + +static INT32 NewSoundID; +static BOOLEAN SetSoundID = FALSE; + +static INT32 gubOldMusicMode2 = 0; static BOOLEAN gfUseCreatureMusic = FALSE; @@ -59,6 +64,7 @@ CHAR8 *szMusicList[NUM_MUSIC]= "MUSIC\\tensor B", "MUSIC\\creepy", "MUSIC\\creature battle", + "MUSIC", }; BOOLEAN StartMusicBasedOnMode(void); @@ -68,6 +74,9 @@ BOOLEAN MusicStop(void); BOOLEAN MusicFadeOut(void); BOOLEAN MusicFadeIn(void); +MUSIC_SOUND_VALUES MusicSoundValues[256]; +INT32 GlobalSoundID; + //extern void HandleEndDemoInCreatureLevel( ); //BOOLEAN NoEnemiesInSight( ) @@ -104,7 +113,7 @@ BOOLEAN MusicFadeIn(void); // Returns: TRUE if the music was started, FALSE if an error occurred // //******************************************************************************** -BOOLEAN MusicPlay(UINT32 uiNum) +BOOLEAN MusicPlay(UINT32 uiNum, UINT32 MusicMode, BOOLEAN NewSound ) { // WANNE: We want music in windowed mode //if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/ @@ -126,9 +135,40 @@ BOOLEAN MusicPlay(UINT32 uiNum) //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "About to call SoundPlayStreamedFile" ); // Lesh: patch to allow playback ogg files + if ( NewSound == FALSE && MusicMode == MUSIC_OLD_TYPE ) + { sprintf( zFileName, "%s.ogg", szMusicList[uiNum] ); if ( !FileExists( zFileName ) ) sprintf( zFileName, "%s.wav", szMusicList[uiNum] ); + } + else if ( NewSound == TRUE ) + { + //sprintf( zFileName, szMusicList[15] ); + if ( MusicMode == MUSIC_TACTICAL_NOTHING ) + { + sprintf( zFileName, "%s\\NOTHING_%d.ogg", szMusicList[15], uiNum); + if ( !FileExists( zFileName ) ) + sprintf( zFileName, "%s\\NOTHING_%d.wav", szMusicList[15], uiNum ); + } + else if ( MusicMode == MUSIC_TACTICAL_ENEMYPRESENT ) + { + sprintf( zFileName, "%s\\TENSOR_%d.ogg", szMusicList[15], uiNum); + if ( !FileExists( zFileName ) ) + sprintf( zFileName, "%s\\TENSOR_%d.wav", szMusicList[15], uiNum ); + } + else if ( MusicMode == MUSIC_TACTICAL_BATTLE ) + { + sprintf( zFileName, "%s\\BATTLE_%d.ogg", szMusicList[15], uiNum); + if ( !FileExists( zFileName ) ) + sprintf( zFileName, "%s\\BATTLE_%d.wav", szMusicList[15], uiNum ); + } + else if ( MusicMode == MUSIC_TACTICAL_VICTORY ) + { + sprintf( zFileName, "%s\\TRIUMPH_%d.ogg", szMusicList[15], uiNum); + if ( !FileExists( zFileName ) ) + sprintf( zFileName, "%s\\TRIUMPH_%d.wav", szMusicList[15], uiNum ); + } + } uiMusicHandle = SoundPlayStreamedFile(zFileName, &spParms); @@ -370,11 +410,74 @@ BOOLEAN MusicPoll(BOOLEAN /*fForce*/) return TRUE; } +static BOOLEAN SetMusicModeID(UINT8 ubMusicMode, INT32 SoundID, BOOLEAN fForce) +{ + static INT8 bPreviousMode = 0; + + static INT32 bPreviousMusic = 0; + + // OK, check if we want to restore + if (ubMusicMode == MUSIC_RESTORE) + { + if (bPreviousMode == MUSIC_TACTICAL_VICTORY || bPreviousMode == MUSIC_TACTICAL_DEATH) + { + bPreviousMode = MUSIC_TACTICAL_NOTHING; + } + + ubMusicMode = bPreviousMode; + SoundID = bPreviousMusic; + GlobalSoundID = SoundID; + } + else + { + // Save previous mode... + bPreviousMode = gubOldMusicMode; + bPreviousMusic = SoundID; + GlobalSoundID = SoundID; + } + + // if different, start a new music song + //if ( ( fForce || gubOldMusicMode != ubMusicMode ) && SoundID != -1) + if ( fForce || SoundID != -1 ) + { + // Set mode.... + gubMusicMode = ubMusicMode; + NewSoundID = SoundID; + GlobalSoundID = SoundID; + + //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music New Mode %d %d", uiMusicHandle, gubMusicMode ) ); + + gbVictorySongCount = 0; + gbDeathSongCount = 0; + + if(uiMusicHandle != NO_SAMPLE) + { + // Fade out old music + MusicFadeOut(); + } + else + { + // Change music! + StartMusicBasedOnMode(); + } + } + + gubOldMusicMode = gubMusicMode; + gubOldMusicMode2 = SoundID; + + return TRUE; +} static BOOLEAN SetMusicMode(UINT8 ubMusicMode, BOOLEAN fForce) { static INT8 bPreviousMode = 0; + SetSoundID = FALSE; + //GlobalSoundID = -1; + + if ( SetSoundID == FALSE ) + NewSoundID = -1; + // OK, check if we want to restore if (ubMusicMode == MUSIC_RESTORE) { @@ -383,7 +486,22 @@ static BOOLEAN SetMusicMode(UINT8 ubMusicMode, BOOLEAN fForce) bPreviousMode = MUSIC_TACTICAL_NOTHING; } + if ( GlobalSoundID == -1 ) + { + SetSoundID = FALSE; + GlobalSoundID = -1; + NewSoundID = -1; + } + else if ( GlobalSoundID != -1) + { + SetSoundID = TRUE; + NewSoundID = gubOldMusicMode2; + GlobalSoundID = NewSoundID; + } + ubMusicMode = bPreviousMode; + + } else { @@ -392,7 +510,7 @@ static BOOLEAN SetMusicMode(UINT8 ubMusicMode, BOOLEAN fForce) } // if different, start a new music song - if (fForce || gubOldMusicMode != ubMusicMode) + if (fForce || gubOldMusicMode != ubMusicMode || GlobalSoundID == -1 || SetSoundID == TRUE ) { // Set mode.... gubMusicMode = ubMusicMode; @@ -442,12 +560,12 @@ static BOOLEAN StartMusicBasedOnMode(void) case MUSIC_MAIN_MENU: // ATE: Don't fade in gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(MENUMIX_MUSIC); + MusicPlay(MENUMIX_MUSIC,MUSIC_OLD_TYPE,FALSE); break; case MUSIC_LAPTOP: gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(MARIMBAD2_MUSIC); + MusicPlay(MARIMBAD2_MUSIC,MUSIC_OLD_TYPE,FALSE); break; case MUSIC_TACTICAL_NOTHING: @@ -455,11 +573,30 @@ static BOOLEAN StartMusicBasedOnMode(void) gbFadeSpeed = (INT8)uiMusicVolume; if(gfUseCreatureMusic) { - MusicPlay(CREEPY_MUSIC); + if ( NewSoundID == -1) + { + SetSoundID = FALSE; + MusicPlay(CREEPY_MUSIC,MUSIC_OLD_TYPE,FALSE); + } + else + { + SetSoundID = TRUE; + MusicPlay(NewSoundID,MUSIC_TACTICAL_NOTHING,TRUE); + } } else { - MusicPlay(bNothingModeSong); + if ( NewSoundID == -1) + { + SetSoundID = FALSE; + MusicPlay(bNothingModeSong,MUSIC_OLD_TYPE,FALSE); + } + else + { + SetSoundID = TRUE; + MusicPlay(NewSoundID,MUSIC_TACTICAL_NOTHING,TRUE); + } + bNothingModeSong = (INT8) (NOTHING_A_MUSIC + Random(4)); } break; @@ -469,11 +606,29 @@ static BOOLEAN StartMusicBasedOnMode(void) gbFadeSpeed = (INT8)uiMusicVolume; if(gfUseCreatureMusic) { - MusicPlay(CREEPY_MUSIC); + if ( NewSoundID == -1) + { + SetSoundID = FALSE; + MusicPlay(CREEPY_MUSIC,MUSIC_OLD_TYPE,FALSE); } else { - MusicPlay(bEnemyModeSong); + SetSoundID = TRUE; + MusicPlay(NewSoundID,MUSIC_TACTICAL_ENEMYPRESENT,TRUE); + } + } + else + { + if ( NewSoundID == -1) + { + SetSoundID = FALSE; + MusicPlay(bEnemyModeSong,MUSIC_OLD_TYPE,FALSE); + } + else + { + SetSoundID = TRUE; + MusicPlay(NewSoundID,MUSIC_TACTICAL_ENEMYPRESENT,TRUE); + } bEnemyModeSong = (INT8) (TENSOR_A_MUSIC + Random(3)); } break; @@ -483,11 +638,29 @@ static BOOLEAN StartMusicBasedOnMode(void) gbFadeSpeed = (INT8)uiMusicVolume; if(gfUseCreatureMusic) { - MusicPlay(CREATURE_BATTLE_MUSIC); + if ( NewSoundID == -1) + { + SetSoundID = FALSE; + MusicPlay(CREATURE_BATTLE_MUSIC,MUSIC_OLD_TYPE,FALSE); + } + else + { + SetSoundID = TRUE; + MusicPlay(NewSoundID,MUSIC_TACTICAL_BATTLE,TRUE); + } } else { - MusicPlay(bBattleModeSong); + if ( NewSoundID == -1) + { + SetSoundID = FALSE; + MusicPlay(bBattleModeSong,MUSIC_OLD_TYPE,FALSE); + } + else + { + SetSoundID = TRUE; + MusicPlay(NewSoundID,MUSIC_TACTICAL_BATTLE,TRUE); + } } bBattleModeSong = (INT8) (BATTLE_A_MUSIC + Random(2)); break; @@ -496,7 +669,16 @@ static BOOLEAN StartMusicBasedOnMode(void) // ATE: Don't fade in EnemyPresent... gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(TRIUMPH_MUSIC); + if ( NewSoundID == -1) + { + SetSoundID = FALSE; + MusicPlay(TRIUMPH_MUSIC,MUSIC_OLD_TYPE,FALSE); + } + else + { + SetSoundID = TRUE; + MusicPlay(NewSoundID,MUSIC_TACTICAL_VICTORY,TRUE); + } gbVictorySongCount++; if(gfUseCreatureMusic && !gbWorldSectorZ) @@ -510,7 +692,16 @@ static BOOLEAN StartMusicBasedOnMode(void) // ATE: Don't fade in EnemyPresent... gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(DEATH_MUSIC); + if ( NewSoundID == -1) + { + SetSoundID = FALSE; + MusicPlay(DEATH_MUSIC,MUSIC_OLD_TYPE,FALSE); + } + else + { + SetSoundID = TRUE; + MusicPlay(NewSoundID,MUSIC_TACTICAL_DEATH,TRUE); + } gbDeathSongCount++; break; @@ -527,6 +718,11 @@ BOOLEAN SetMusicMode(UINT8 ubMusicMode) return SetMusicMode(ubMusicMode, FALSE); } +BOOLEAN SetMusicModeID(UINT8 ubMusicMode, INT32 SoundID) +{ + return SetMusicModeID(ubMusicMode, SoundID, FALSE); +} + static void MusicStopCallback(void *pData) { //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music EndCallback %d %d", uiMusicHandle, gubMusicMode ) ); diff --git a/Utils/Music Control.h b/Utils/Music Control.h index f6b9c16b..a0c0cbd6 100644 --- a/Utils/Music Control.h +++ b/Utils/Music Control.h @@ -18,6 +18,7 @@ enum MusicList BATTLE_B_MUSIC, //same as tensor B CREEPY_MUSIC, CREATURE_BATTLE_MUSIC, + MUSIC_DIR, NUM_MUSIC }; @@ -32,8 +33,23 @@ enum MusicMode MUSIC_TACTICAL_VICTORY, MUSIC_TACTICAL_DEATH, MUSIC_LAPTOP, + MUSIC_OLD_TYPE, }; +typedef struct +{ + UINT16 uiIndex; + INT32 SoundTacticalVictory[4]; + INT32 SoundTacticalBattle[4]; + INT32 SoundTacticalNothing[4]; + INT32 SoundTacticalTensor[4]; + INT32 SoundTacticalDeath[4]; + +} MUSIC_SOUND_VALUES; + +extern MUSIC_SOUND_VALUES MusicSoundValues[256]; +extern INT32 GlobalSoundID; + //extern UINT32 uiMusicHandle; //extern BOOLEAN fMusicPlaying; //extern UINT8 gubMusicMode; @@ -43,7 +59,9 @@ UINT8 GetMusicMode(void); BOOLEAN SetMusicMode(UINT8 ubMusicMode); // only for editor (editscreen.cpp) -BOOLEAN MusicPlay(UINT32 uiNum); +BOOLEAN MusicPlay(UINT32 uiNum, UINT32 MusicMode, BOOLEAN NewSound); + +BOOLEAN SetMusicModeID(UINT8 ubMusicMode, INT32 SoundID); UINT32 MusicGetVolume(void); BOOLEAN MusicSetVolume(UINT32 uiVolume);