From 7546a23d0d469ed823c53553dbf4c75a9f3c79e8 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 27 Jan 2024 01:39:44 +0200 Subject: [PATCH 1/4] Allow custom music to be added Additional music can be added by placing sound files into Dataa/Music folder following this naming convention musicmode_runningNumber.fileformat, so for example: Mainmenu_001.mp3 Mainmenu_002.ogg Laptop_002.ogg Tactical_003.wav ***************************************************************** Different musicmodes are Mainmenu_ <-- Mainmenu music Laptop_ <-- Laptop music Tactical_ <-- Tactical with nothing special going on Enemy_ <-- Tactical, enemy present Battle_ <-- Tactical, enemy present and visible Victory_ <-- Tactical, battle victory Death_ <-- Tactical, battle defeat Creepy_ <-- Tactical, creatures present CreepyBattle_ <-- Tactical, creatures present and visible Music files can be .mp3, .ogg or .wav formats and 100 songs in each category is supported. The running numbering starts from 000 ***************************************************************** A few filenames are treated in a special way to facilitate easy replacement of original music. To replace original music, insert the following named files into this folder "menumix1" <-- Mainmenu music "marimbad 2" <-- Laptop music "nothing A" <-- Tactical with nothing special going on "nothing B" "nothing C" "nothing D" "tensor A" <-- Tactical, enemy present "tensor B" "tensor C" "triumph" "death" "battle A" <-- Tactical, enemy present and visible "tensor B" <-- This file is also used as battle music "creepy" <-- Tactical, creatures present "creature battle" <-- Tactical, creatures present and visible --- Editor/editscreen.cpp | 28 +- Strategic/LuaInitNPCs.cpp | 29 +- Utils/Music Control.cpp | 548 +++++++++++--------------------------- Utils/Music Control.h | 67 ++--- sgp/sgp.cpp | 4 + 5 files changed, 195 insertions(+), 481 deletions(-) diff --git a/Editor/editscreen.cpp b/Editor/editscreen.cpp index a62be1e59..1cd2ceb39 100644 --- a/Editor/editscreen.cpp +++ b/Editor/editscreen.cpp @@ -79,8 +79,6 @@ class OBJECTTYPE; class SOLDIERTYPE; -extern CHAR8 *szMusicList[NUM_MUSIC]; - BOOLEAN gfCorruptMap = FALSE; BOOLEAN gfCorruptSchedules = FALSE; BOOLEAN gfProfileDataLoaded = FALSE; @@ -169,6 +167,7 @@ LEVELNODE *gCursorNode = NULL; INT32 gsCursorGridNo; INT32 giMusicID = 0; +NewMusicList gMusicMode = MUSICLIST_MAIN_MENU; void EraseWorldData( ); @@ -1616,16 +1615,27 @@ void HandleKeyboardShortcuts( ) break; case F4: -#ifdef NEWMUSIC - MusicPlay( giMusicID, MUSIC_OLD_TYPE, FALSE ); -#else - MusicPlay( giMusicID ); -#endif + MusicPlay(gMusicMode, giMusicID); + ScreenMsg( FONT_YELLOW, MSG_INTERFACE, L"%S", MusicLists[gMusicMode][giMusicID] ); - ScreenMsg( FONT_YELLOW, MSG_DEBUG, L"%S", szMusicList[giMusicID] ); + // Select next track giMusicID++; - if( giMusicID >= NUM_MUSIC ) + if (giMusicID >= MusicLists[gMusicMode].size()) + { giMusicID = 0; + for (size_t i = 0; i < MAX_MUSIC; i++) + { + if (gMusicMode == i) + { + gMusicMode = static_cast(i + 1); + if (gMusicMode == MAX_MUSIC) + { + gMusicMode = MUSICLIST_MAIN_MENU; + } + break; + } + } + } break; case F5: diff --git a/Strategic/LuaInitNPCs.cpp b/Strategic/LuaInitNPCs.cpp index e799bb236..be83d7576 100644 --- a/Strategic/LuaInitNPCs.cpp +++ b/Strategic/LuaInitNPCs.cpp @@ -570,9 +570,6 @@ static int l_AnimMercPtsrusStrategicInsertionData (lua_State *L); static int l_SetMusicMode (lua_State *L); static int l_MusicPlay (lua_State *L); -#ifdef NEWMUSIC -static int l_MusicPlayId (lua_State *L); -#endif static int l_MusicSetVolume (lua_State *L); static int l_MusicGetVolume (lua_State *L); #ifdef NEWMUSIC @@ -1398,7 +1395,6 @@ void IniFunction(lua_State *L, BOOLEAN bQuests ) lua_register(L, "SetMusicMode", l_SetMusicMode ); lua_register(L, "MusicPlay", l_MusicPlay ); #ifdef NEWMUSIC - lua_register(L, "MusicIdPlay", l_MusicPlayId ); lua_register(L, "AddMusic", l_gAddMusic ); lua_register(L, "SetMusicID", l_SetMusicID ); @@ -5715,33 +5711,16 @@ static int l_gAddMusic(lua_State *L) } #endif static int l_MusicPlay (lua_State *L) -{ - if ( lua_gettop(L) >= 1 ) - { - UINT32 uiNum = lua_tointeger(L,1); - #ifdef NEWMUSIC - MusicPlay( uiNum, MUSIC_OLD_TYPE, FALSE); - #else - MusicPlay( uiNum ); - #endif - } -return 0; -} - -#ifdef NEWMUSIC -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); + UINT32 musicMode = lua_tointeger(L, 1); + UINT32 song = lua_tointeger(L,2); + MusicPlay( static_cast(musicMode), song ); } return 0; } -#endif + static int l_SetMusicMode (lua_State *L) { if ( lua_gettop(L) >= 1 ) diff --git a/Utils/Music Control.cpp b/Utils/Music Control.cpp index c657f62bf..78f50b935 100644 --- a/Utils/Music Control.cpp +++ b/Utils/Music Control.cpp @@ -8,7 +8,6 @@ #include "strategicmap.h" #include "Overhead Types.h" -//extern int iScreenMode; static UINT32 uiMusicHandle = NO_SAMPLE; static BOOLEAN fMusicPlaying = FALSE; @@ -26,31 +25,36 @@ static UINT8 gubOldMusicMode = 0; static INT8 gbVictorySongCount = 0; static INT8 gbDeathSongCount = 0; -#ifdef NEWMUSIC -static INT32 bNothingModeSong = NOTHING_A_MUSIC; -static INT32 bEnemyModeSong = TENSOR_A_MUSIC; -static INT32 bBattleModeSong = BATTLE_A_MUSIC; - -static INT32 NewSoundID = -1; -static BOOLEAN SetSoundID = FALSE; - -static INT32 gubOldMusicMode2 = 0; -#else -static INT8 bNothingModeSong; -static INT8 bEnemyModeSong; -static INT8 bBattleModeSong; -#endif - static BOOLEAN gfUseCreatureMusic = FALSE; static INT8 gbFadeSpeed = 1; static BOOLEAN gfDontRestartSong = FALSE; -// unused -//BOOLEAN gfForceMusicToTense = FALSE; -CHAR8 *szMusicList[NUM_MUSIC]= +// Original music and their hardcoded paths +enum MusicList +{ + MARIMBAD2_MUSIC, + MENUMIX_MUSIC, + NOTHING_A_MUSIC, + NOTHING_B_MUSIC, + NOTHING_C_MUSIC, + NOTHING_D_MUSIC, + TENSOR_A_MUSIC, + TENSOR_B_MUSIC, + TENSOR_C_MUSIC, + TRIUMPH_MUSIC, + DEATH_MUSIC, + BATTLE_A_MUSIC, + BATTLE_B_MUSIC, //same as tensor B + CREEPY_MUSIC, + CREATURE_BATTLE_MUSIC, + MUSIC_DIR, + NUM_MUSIC +}; + +CHAR8* szMusicList[NUM_MUSIC] = { "MUSIC\\marimbad 2", "MUSIC\\menumix1", @@ -70,6 +74,110 @@ CHAR8 *szMusicList[NUM_MUSIC]= "MUSIC", }; + +std::vector MusicLists[MAX_MUSIC]; + +static void AddMusicToList(STR fileName, NewMusicList mode) +{ + UINT8 constexpr buf = 64; + CHAR8 musicFile[buf]; + + if (SoundFileExists(fileName, musicFile)) + { + STR music = (STR)MemAlloc(buf * sizeof(CHAR8)); + Assert(music); + memset(music, 0, sizeof(CHAR8) * buf); + strcpy(music, musicFile); + + MusicLists[mode].push_back(music); + } +} + +void InitializeMusicLists() +{ + // Special casing original music so they can be easily replaced with new files + AddMusicToList(szMusicList[MENUMIX_MUSIC], MUSICLIST_MAIN_MENU); + AddMusicToList(szMusicList[MARIMBAD2_MUSIC], MUSICLIST_LAPTOP); + + AddMusicToList(szMusicList[NOTHING_A_MUSIC], MUSICLIST_TACTICAL_NOTHING); + AddMusicToList(szMusicList[NOTHING_B_MUSIC], MUSICLIST_TACTICAL_NOTHING); + AddMusicToList(szMusicList[NOTHING_C_MUSIC], MUSICLIST_TACTICAL_NOTHING); + AddMusicToList(szMusicList[NOTHING_D_MUSIC], MUSICLIST_TACTICAL_NOTHING); + + AddMusicToList(szMusicList[TENSOR_A_MUSIC], MUSICLIST_TACTICAL_ENEMYPRESENT); + AddMusicToList(szMusicList[TENSOR_B_MUSIC], MUSICLIST_TACTICAL_ENEMYPRESENT); + AddMusicToList(szMusicList[TENSOR_C_MUSIC], MUSICLIST_TACTICAL_ENEMYPRESENT); + + AddMusicToList(szMusicList[BATTLE_A_MUSIC], MUSICLIST_TACTICAL_BATTLE); + AddMusicToList(szMusicList[BATTLE_B_MUSIC], MUSICLIST_TACTICAL_BATTLE); + + AddMusicToList(szMusicList[TRIUMPH_MUSIC], MUSICLIST_TACTICAL_VICTORY); + AddMusicToList(szMusicList[DEATH_MUSIC], MUSICLIST_TACTICAL_DEATH); + AddMusicToList(szMusicList[CREEPY_MUSIC], MUSICLIST_TACTICAL_CREEPY); + AddMusicToList(szMusicList[CREATURE_BATTLE_MUSIC], MUSICLIST_TACTICAL_CREEPY_BATTLE); + + + UINT8 constexpr buf = 64; + CHAR8 fileName[buf]; + // Read music files into list + for (size_t j = MUSICLIST_MAIN_MENU; j < MAX_MUSIC; j++) + { + STR baseFilename; + switch (j) + { + case MUSICLIST_MAIN_MENU: + baseFilename = "MUSIC\\Mainmenu_"; + break; + case MUSICLIST_LAPTOP: + baseFilename = "MUSIC\\Laptop_"; + break; + case MUSICLIST_TACTICAL_NOTHING: + baseFilename = "MUSIC\\Tactical_"; + break; + case MUSICLIST_TACTICAL_ENEMYPRESENT: + baseFilename = "MUSIC\\Enemy_"; + break; + case MUSICLIST_TACTICAL_BATTLE: + baseFilename = "MUSIC\\Battle_"; + break; + case MUSICLIST_TACTICAL_VICTORY: + baseFilename = "MUSIC\\Victory_"; + break; + case MUSICLIST_TACTICAL_DEATH: + baseFilename = "MUSIC\\Death_"; + break; + case MUSICLIST_TACTICAL_CREEPY: + baseFilename = "MUSIC\\Creepy_"; + break; + case MUSICLIST_TACTICAL_CREEPY_BATTLE: + baseFilename = "MUSIC\\CreepyBattle_"; + break; + default: + break; + } + + for (size_t i = 0; i < 100; i++) + { + if (i < 10) + { + sprintf(fileName, "%s00%d", baseFilename, i); + } + else if (i < 100) + { + sprintf(fileName, "%s0%d", baseFilename, i); + } + + AddMusicToList(fileName, static_cast(j)); + } + } +} + +static STR PickRandomSongFromList(NewMusicList mode) +{ + return MusicLists[mode][Random(MusicLists[mode].size())]; +} + + BOOLEAN StartMusicBasedOnMode(void); void DoneFadeOutDueToEndMusic(void); void MusicStopCallback(void *pData); @@ -77,37 +185,6 @@ BOOLEAN MusicStop(void); BOOLEAN MusicFadeOut(void); BOOLEAN MusicFadeIn(void); -#ifdef NEWMUSIC -MUSIC_SOUND_VALUES MusicSoundValues[256]; -INT32 GlobalSoundID = -1; -#endif -//extern void HandleEndDemoInCreatureLevel( ); - -//BOOLEAN NoEnemiesInSight( ) -//{ -// SOLDIERTYPE *pSoldier; -// INT32 cnt; -// -// // Loop through our guys -// // End the turn of player charactors -// cnt = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; -// -// // look for all mercs on the same team, -// for ( pSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; cnt++, pSoldier++ ) -// { -// if ( pSoldier->bActive && pSoldier->stats.bLife >= OKLIFE ) -// { -// if ( pSoldier->aiData.bOppCnt != 0 ) -// { -// return( FALSE ); -// } -// } -// } -// -// return( TRUE ); -//} - - //******************************************************************************** // MusicPlay @@ -117,65 +194,22 @@ INT32 GlobalSoundID = -1; // Returns: TRUE if the music was started, FALSE if an error occurred // //******************************************************************************** -#ifdef NEWMUSIC -BOOLEAN MusicPlay(UINT32 uiNum, UINT32 MusicMode, BOOLEAN NewSound ) -#else -BOOLEAN MusicPlay(UINT32 uiNum) -#endif +static BOOLEAN MusicPlay(STR zFileName) { - // WANNE: We want music in windowed mode - //if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/ - //return FALSE; - - static CHAR8 zFileName[164]; SOUNDPARMS spParms; - if(fMusicPlaying) + if (fMusicPlaying) MusicStop(); memset(&spParms, 0xff, sizeof(SOUNDPARMS)); spParms.uiPriority = PRIORITY_MAX; spParms.uiVolume = 0; - spParms.uiLoop = 1; // Lesh: only 1 line added - + spParms.uiLoop = 1; spParms.EOSCallback = MusicStopCallback; - //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "About to call SoundPlayStreamedFile" ); - - // Lesh: patch to allow playback ogg files -#ifdef NEWMUSIC - if ( NewSound == FALSE && MusicMode == MUSIC_OLD_TYPE ) - { -#endif - SoundFileExists( szMusicList[uiNum], zFileName ); -#ifdef NEWMUSIC - } - else if ( NewSound == TRUE ) - { - CHAR8 modstr[32] = ""; - CHAR8 modstr2[164] = ""; - - switch ( MusicMode ) - { - case MUSIC_TACTICAL_NOTHING: sprintf( modstr, "NOTHING_" ); break; - case MUSIC_TACTICAL_ENEMYPRESENT: sprintf( modstr, "TENSOR_" ); break; - case MUSIC_TACTICAL_BATTLE: sprintf( modstr, "BATTLE_" ); break; - case MUSIC_TACTICAL_VICTORY: sprintf( modstr, "TRIUMPH_" ); break; - case MUSIC_TACTICAL_BATTLE_MUSIC: sprintf( modstr, "CREATURE_BATTLE_" ); break; - case MUSIC_TACTICAL_CREEPY_MUSIC: sprintf( modstr, "CREEPY_" ); break; - default: break; - } - - sprintf( modstr2, "%s\\%s%d", szMusicList[15], modstr, uiNum ); - - SoundFileExists( modstr2, zFileName ); - } -#endif uiMusicHandle = SoundPlayStreamedFile(zFileName, &spParms); - - if(uiMusicHandle != SOUND_ERROR) + if (uiMusicHandle != SOUND_ERROR) { - //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music PLay %d %d", uiMusicHandle, gubMusicMode ) ); gfMusicEnded = FALSE; fMusicPlaying = TRUE; @@ -183,10 +217,19 @@ BOOLEAN MusicPlay(UINT32 uiNum) return TRUE; } - //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music PLay %d %d", uiMusicHandle, gubMusicMode ) ); return FALSE; } +BOOLEAN MusicPlay(NewMusicList mode, UINT8 songIndex) +{ + if (mode >= MAX_MUSIC || songIndex >= MusicLists[mode].size()) + { + return FALSE; + } + + MusicPlay(MusicLists[mode][songIndex]); +} + //******************************************************************************** // MusicSetVolume // @@ -410,78 +453,11 @@ BOOLEAN MusicPoll(BOOLEAN /*fForce*/) //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll done"); return TRUE; } -#ifdef NEWMUSIC -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; -} -#endif static BOOLEAN SetMusicMode(UINT8 ubMusicMode, BOOLEAN fForce) { static INT8 bPreviousMode = 0; - #ifdef NEWMUSIC - SetSoundID = FALSE; - //GlobalSoundID = -1; - - if ( SetSoundID == FALSE ) - NewSoundID = -1; - #endif - // OK, check if we want to restore if (ubMusicMode == MUSIC_RESTORE) { @@ -489,24 +465,7 @@ static BOOLEAN SetMusicMode(UINT8 ubMusicMode, BOOLEAN fForce) { bPreviousMode = MUSIC_TACTICAL_NOTHING; } - - #ifdef NEWMUSIC - if ( GlobalSoundID == -1 ) - { - SetSoundID = FALSE; - GlobalSoundID = -1; - NewSoundID = -1; - } - else if ( GlobalSoundID != -1) - { - SetSoundID = TRUE; - NewSoundID = gubOldMusicMode2; - GlobalSoundID = NewSoundID; - } - #endif ubMusicMode = bPreviousMode; - - } else { @@ -515,11 +474,7 @@ static BOOLEAN SetMusicMode(UINT8 ubMusicMode, BOOLEAN fForce) } // if different, start a new music song - #ifdef NEWMUSIC - if (fForce || gubOldMusicMode != ubMusicMode || GlobalSoundID == -1 || SetSoundID == TRUE ) - #else if (fForce || gubOldMusicMode != ubMusicMode) - #endif { // Set mode.... gubMusicMode = ubMusicMode; @@ -546,36 +501,19 @@ static BOOLEAN SetMusicMode(UINT8 ubMusicMode, BOOLEAN fForce) return TRUE; } -#ifdef NEWMUSIC static BOOLEAN StartMusicBasedOnMode(void) { - static BOOLEAN fFirstTime = TRUE; - - - if (fFirstTime) - { - fFirstTime = FALSE; - - bNothingModeSong = (INT8) (NOTHING_A_MUSIC + Random(4)); - bEnemyModeSong = (INT8) (TENSOR_A_MUSIC + Random(3)); - bBattleModeSong = (INT8) (BATTLE_A_MUSIC + Random(2)); - } - - - //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "StartMusicBasedOnMode() %d %d", uiMusicHandle, gubMusicMode ) ); - - // Setup a song based on mode we're in! switch(gubMusicMode) { case MUSIC_MAIN_MENU: // ATE: Don't fade in gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(MENUMIX_MUSIC,MUSIC_OLD_TYPE,FALSE); + MusicPlay(PickRandomSongFromList(MUSICLIST_MAIN_MENU)); break; case MUSIC_LAPTOP: gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(MARIMBAD2_MUSIC,MUSIC_OLD_TYPE,FALSE); + MusicPlay(PickRandomSongFromList(MUSICLIST_LAPTOP)); break; case MUSIC_TACTICAL_NOTHING: @@ -583,31 +521,11 @@ static BOOLEAN StartMusicBasedOnMode(void) gbFadeSpeed = (INT8)uiMusicVolume; if(gfUseCreatureMusic) { - if ( NewSoundID == -1) - { - SetSoundID = FALSE; - MusicPlay(CREEPY_MUSIC,MUSIC_OLD_TYPE,FALSE); - } - else - { - SetSoundID = TRUE; - MusicPlay(NewSoundID,MUSIC_TACTICAL_CREEPY_MUSIC,TRUE); - } + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_CREEPY)); } else { - 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)); + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_NOTHING)); } break; @@ -616,30 +534,11 @@ static BOOLEAN StartMusicBasedOnMode(void) gbFadeSpeed = (INT8)uiMusicVolume; if(gfUseCreatureMusic) { - if ( NewSoundID == -1) - { - SetSoundID = FALSE; - MusicPlay(CREEPY_MUSIC,MUSIC_OLD_TYPE,FALSE); - } - else - { - SetSoundID = TRUE; - MusicPlay(NewSoundID,MUSIC_TACTICAL_ENEMYPRESENT,TRUE); - } + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_CREEPY)); } 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)); + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_ENEMYPRESENT)); } break; @@ -648,47 +547,19 @@ static BOOLEAN StartMusicBasedOnMode(void) gbFadeSpeed = (INT8)uiMusicVolume; if(gfUseCreatureMusic) { - if ( NewSoundID == -1) - { - SetSoundID = FALSE; - MusicPlay(CREATURE_BATTLE_MUSIC,MUSIC_OLD_TYPE,FALSE); - } - else - { - SetSoundID = TRUE; - MusicPlay(NewSoundID,MUSIC_TACTICAL_BATTLE_MUSIC,TRUE); - } + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_CREEPY_BATTLE)); } else { - if ( NewSoundID == -1) - { - SetSoundID = FALSE; - MusicPlay(bBattleModeSong,MUSIC_OLD_TYPE,FALSE); + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_BATTLE)); } - else - { - SetSoundID = TRUE; - MusicPlay(NewSoundID,MUSIC_TACTICAL_BATTLE,TRUE); - } - } - bBattleModeSong = (INT8) (BATTLE_A_MUSIC + Random(2)); break; case MUSIC_TACTICAL_VICTORY: // ATE: Don't fade in EnemyPresent... gbFadeSpeed = (INT8)uiMusicVolume; - if ( NewSoundID == -1) - { - SetSoundID = FALSE; - MusicPlay(TRIUMPH_MUSIC,MUSIC_OLD_TYPE,FALSE); - } - else - { - SetSoundID = TRUE; - MusicPlay(NewSoundID,MUSIC_TACTICAL_VICTORY,TRUE); - } + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_VICTORY)); gbVictorySongCount++; if(gfUseCreatureMusic && !gbWorldSectorZ) @@ -702,16 +573,7 @@ static BOOLEAN StartMusicBasedOnMode(void) // ATE: Don't fade in EnemyPresent... gbFadeSpeed = (INT8)uiMusicVolume; - if ( NewSoundID == -1) - { - SetSoundID = FALSE; - MusicPlay(DEATH_MUSIC,MUSIC_OLD_TYPE,FALSE); - } - else - { - SetSoundID = TRUE; - MusicPlay(NewSoundID,MUSIC_TACTICAL_DEATH,TRUE); - } + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_DEATH)); gbDeathSongCount++; break; @@ -722,121 +584,13 @@ static BOOLEAN StartMusicBasedOnMode(void) return TRUE; } -#else -static BOOLEAN StartMusicBasedOnMode(void) -{ - static BOOLEAN fFirstTime = TRUE; - if (fFirstTime) - { - fFirstTime = FALSE; - - bNothingModeSong = (INT8) (NOTHING_A_MUSIC + Random(4)); - bEnemyModeSong = (INT8) (TENSOR_A_MUSIC + Random(3)); - bBattleModeSong = (INT8) (BATTLE_A_MUSIC + Random(2)); - } - - - //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "StartMusicBasedOnMode() %d %d", uiMusicHandle, gubMusicMode ) ); - - // Setup a song based on mode we're in! - switch(gubMusicMode) - { - case MUSIC_MAIN_MENU: - // ATE: Don't fade in - gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(MENUMIX_MUSIC); - break; - - case MUSIC_LAPTOP: - gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(MARIMBAD2_MUSIC); - break; - - case MUSIC_TACTICAL_NOTHING: - // ATE: Don't fade in - gbFadeSpeed = (INT8)uiMusicVolume; - if(gfUseCreatureMusic) - { - MusicPlay(CREEPY_MUSIC); - } - else - { - MusicPlay(bNothingModeSong); - bNothingModeSong = (INT8) (NOTHING_A_MUSIC + Random(4)); - } - break; - - case MUSIC_TACTICAL_ENEMYPRESENT: - // ATE: Don't fade in EnemyPresent... - gbFadeSpeed = (INT8)uiMusicVolume; - if(gfUseCreatureMusic) - { - MusicPlay(CREEPY_MUSIC); - } - else - { - MusicPlay(bEnemyModeSong); - bEnemyModeSong = (INT8) (TENSOR_A_MUSIC + Random(3)); - } - break; - - case MUSIC_TACTICAL_BATTLE: - // ATE: Don't fade in - gbFadeSpeed = (INT8)uiMusicVolume; - if(gfUseCreatureMusic) - { - MusicPlay(CREATURE_BATTLE_MUSIC); - } - else - { - MusicPlay(bBattleModeSong); - } - bBattleModeSong = (INT8) (BATTLE_A_MUSIC + Random(2)); - break; - - case MUSIC_TACTICAL_VICTORY: - - // ATE: Don't fade in EnemyPresent... - gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(TRIUMPH_MUSIC); - gbVictorySongCount++; - - if(gfUseCreatureMusic && !gbWorldSectorZ) - { - //We just killed all the creatures that just attacked the town. - gfUseCreatureMusic = FALSE; - } - break; - - case MUSIC_TACTICAL_DEATH: - - // ATE: Don't fade in EnemyPresent... - gbFadeSpeed = (INT8)uiMusicVolume; - MusicPlay(DEATH_MUSIC); - gbDeathSongCount++; - break; - - default: - MusicFadeOut(); - break; - } - - return TRUE; -} -#endif BOOLEAN SetMusicMode(UINT8 ubMusicMode) { return SetMusicMode(ubMusicMode, FALSE); } -#ifdef NEWMUSIC -BOOLEAN SetMusicModeID(UINT8 ubMusicMode, INT32 SoundID) -{ - return SetMusicModeID(ubMusicMode, SoundID, FALSE); -} -#endif static void MusicStopCallback(void *pData) { diff --git a/Utils/Music Control.h b/Utils/Music Control.h index 6a6109ff7..3a9983765 100644 --- a/Utils/Music Control.h +++ b/Utils/Music Control.h @@ -3,27 +3,6 @@ #include "Overhead Types.h" -enum MusicList -{ - MARIMBAD2_MUSIC, - MENUMIX_MUSIC, - NOTHING_A_MUSIC, - NOTHING_B_MUSIC, - NOTHING_C_MUSIC, - NOTHING_D_MUSIC, - TENSOR_A_MUSIC, - TENSOR_B_MUSIC, - TENSOR_C_MUSIC, - TRIUMPH_MUSIC, - DEATH_MUSIC, - BATTLE_A_MUSIC, - BATTLE_B_MUSIC, //same as tensor B - CREEPY_MUSIC, - CREATURE_BATTLE_MUSIC, - MUSIC_DIR, - NUM_MUSIC -}; - enum MusicMode { MUSIC_NONE, @@ -42,43 +21,31 @@ enum MusicMode MUSIC_TACTICAL_CIV_GROUP_BATTLE, }; -#ifdef NEWMUSIC -typedef struct +enum NewMusicList { - UINT16 uiIndex; - INT32 SoundTacticalVictory[4]; - INT32 SoundTacticalBattle[4]; - INT32 SoundTacticalNothing[4]; - INT32 SoundTacticalTensor[4]; - INT32 SoundTacticalDeath[4]; - INT32 SoundTacticalBattleCreature[4]; - INT32 SoundTacticalBattleCreepy[4]; - INT32 SoundTacticalBattleGroup[NUM_CIV_GROUPS]; - -} MUSIC_SOUND_VALUES; + MUSICLIST_MAIN_MENU, + MUSICLIST_LAPTOP, + MUSICLIST_TACTICAL_NOTHING, + MUSICLIST_TACTICAL_ENEMYPRESENT, + MUSICLIST_TACTICAL_BATTLE, + MUSICLIST_TACTICAL_VICTORY, + MUSICLIST_TACTICAL_DEATH, + MUSICLIST_TACTICAL_CREEPY, + MUSICLIST_TACTICAL_CREEPY_BATTLE, + + MAX_MUSIC, +}; -extern MUSIC_SOUND_VALUES MusicSoundValues[256]; -extern INT32 GlobalSoundID; -#endif +extern std::vector MusicLists[MAX_MUSIC]; -//extern UINT32 uiMusicHandle; -//extern BOOLEAN fMusicPlaying; -//extern UINT8 gubMusicMode; -//extern BOOLEAN gfForceMusicToTense; +void InitializeMusicLists(); UINT8 GetMusicMode(void); BOOLEAN SetMusicMode(UINT8 ubMusicMode); -// only for editor (editscreen.cpp) -#ifdef NEWMUSIC -BOOLEAN MusicPlay(UINT32 uiNum, UINT32 MusicMode, BOOLEAN NewSound); -#else -BOOLEAN MusicPlay(UINT32 uiNum); -#endif +// Used in lua scripting and editscreen.cpp +BOOLEAN MusicPlay(NewMusicList mode, UINT8 songIndex); -#ifdef NEWMUSIC -BOOLEAN SetMusicModeID(UINT8 ubMusicMode, INT32 SoundID); -#endif UINT32 MusicGetVolume(void); BOOLEAN MusicSetVolume(UINT32 uiVolume); diff --git a/sgp/sgp.cpp b/sgp/sgp.cpp index 121dce70f..6686d6378 100644 --- a/sgp/sgp.cpp +++ b/sgp/sgp.cpp @@ -56,6 +56,7 @@ #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif +#include static void MAGIC(std::string const& aarrrrgggh = "") @@ -574,6 +575,9 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow) return FALSE; } + FastDebugMsg("Initializing Music"); + InitializeMusicLists(); + FastDebugMsg("Initializing Game Manager"); // Initialize the Game if (InitializeGame() == FALSE) From 51c3967c4268dce2720eab43d01522a909e3eb56 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Mon, 29 Jan 2024 15:15:04 +0200 Subject: [PATCH 2/4] Smarter string formatting Accept filenames with two digit running number --- Utils/Music Control.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Utils/Music Control.cpp b/Utils/Music Control.cpp index 78f50b935..740b5ed17 100644 --- a/Utils/Music Control.cpp +++ b/Utils/Music Control.cpp @@ -158,15 +158,7 @@ void InitializeMusicLists() for (size_t i = 0; i < 100; i++) { - if (i < 10) - { - sprintf(fileName, "%s00%d", baseFilename, i); - } - else if (i < 100) - { - sprintf(fileName, "%s0%d", baseFilename, i); - } - + sprintf(fileName, "%s%02d", baseFilename, i); AddMusicToList(fileName, static_cast(j)); } } From e93dc3fb6d1e7947fce4ef6b7956e4c42a270955 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Mon, 29 Jan 2024 15:40:59 +0200 Subject: [PATCH 3/4] Allow separate enemy present & battle music for nighttime Defaults to regular enemypresent and battle music if no nighttime music tracks are found --- Utils/Music Control.cpp | 15 +++++++++++++++ Utils/Music Control.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/Utils/Music Control.cpp b/Utils/Music Control.cpp index 740b5ed17..0d1361d77 100644 --- a/Utils/Music Control.cpp +++ b/Utils/Music Control.cpp @@ -8,6 +8,7 @@ #include "strategicmap.h" #include "Overhead Types.h" +#include static UINT32 uiMusicHandle = NO_SAMPLE; static BOOLEAN fMusicPlaying = FALSE; @@ -140,6 +141,12 @@ void InitializeMusicLists() case MUSICLIST_TACTICAL_BATTLE: baseFilename = "MUSIC\\Battle_"; break; + case MUSICLIST_TACTICAL_ENEMYPRESENT_NIGHT: + baseFilename = "MUSIC\\EnemyNight_"; + break; + case MUSICLIST_TACTICAL_BATTLE_NIGHT: + baseFilename = "MUSIC\\BattleNight_"; + break; case MUSICLIST_TACTICAL_VICTORY: baseFilename = "MUSIC\\Victory_"; break; @@ -528,6 +535,10 @@ static BOOLEAN StartMusicBasedOnMode(void) { MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_CREEPY)); } + else if (NightTime() && MusicLists[MUSICLIST_TACTICAL_ENEMYPRESENT_NIGHT].size() > 0) + { + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_ENEMYPRESENT_NIGHT)); + } else { MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_ENEMYPRESENT)); @@ -541,6 +552,10 @@ static BOOLEAN StartMusicBasedOnMode(void) { MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_CREEPY_BATTLE)); } + else if (NightTime() && MusicLists[MUSICLIST_TACTICAL_BATTLE_NIGHT].size() > 0) + { + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_BATTLE_NIGHT)); + } else { MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_BATTLE)); diff --git a/Utils/Music Control.h b/Utils/Music Control.h index 3a9983765..2d67f5d04 100644 --- a/Utils/Music Control.h +++ b/Utils/Music Control.h @@ -28,6 +28,8 @@ enum NewMusicList MUSICLIST_TACTICAL_NOTHING, MUSICLIST_TACTICAL_ENEMYPRESENT, MUSICLIST_TACTICAL_BATTLE, + MUSICLIST_TACTICAL_ENEMYPRESENT_NIGHT, + MUSICLIST_TACTICAL_BATTLE_NIGHT, MUSICLIST_TACTICAL_VICTORY, MUSICLIST_TACTICAL_DEATH, MUSICLIST_TACTICAL_CREEPY, From a80fea00e2194d48dedb519938bc1475daabb8eb Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:19:32 +0200 Subject: [PATCH 4/4] Rename 2nd original battle music If "Battle B" music file is found, use it instead of tensor B for the second original battle music. Allows us to replace either the enemy present or battle version of the same track instead of always both when "tensor B" is replaced. --- Utils/Music Control.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Utils/Music Control.cpp b/Utils/Music Control.cpp index 0d1361d77..aa86d29da 100644 --- a/Utils/Music Control.cpp +++ b/Utils/Music Control.cpp @@ -69,7 +69,7 @@ CHAR8* szMusicList[NUM_MUSIC] = "MUSIC\\triumph", "MUSIC\\death", "MUSIC\\battle A", - "MUSIC\\tensor B", + "MUSIC\\battle B", "MUSIC\\creepy", "MUSIC\\creature battle", "MUSIC", @@ -96,6 +96,9 @@ static void AddMusicToList(STR fileName, NewMusicList mode) void InitializeMusicLists() { + UINT8 constexpr buf = 64; + CHAR8 fileName[buf]; + // Special casing original music so they can be easily replaced with new files AddMusicToList(szMusicList[MENUMIX_MUSIC], MUSICLIST_MAIN_MENU); AddMusicToList(szMusicList[MARIMBAD2_MUSIC], MUSICLIST_LAPTOP); @@ -110,7 +113,14 @@ void InitializeMusicLists() AddMusicToList(szMusicList[TENSOR_C_MUSIC], MUSICLIST_TACTICAL_ENEMYPRESENT); AddMusicToList(szMusicList[BATTLE_A_MUSIC], MUSICLIST_TACTICAL_BATTLE); - AddMusicToList(szMusicList[BATTLE_B_MUSIC], MUSICLIST_TACTICAL_BATTLE); + if (SoundFileExists(szMusicList[BATTLE_B_MUSIC], fileName)) + { + AddMusicToList(szMusicList[BATTLE_B_MUSIC], MUSICLIST_TACTICAL_BATTLE); + } + else + { + AddMusicToList(szMusicList[TENSOR_B_MUSIC], MUSICLIST_TACTICAL_BATTLE); + } AddMusicToList(szMusicList[TRIUMPH_MUSIC], MUSICLIST_TACTICAL_VICTORY); AddMusicToList(szMusicList[DEATH_MUSIC], MUSICLIST_TACTICAL_DEATH); @@ -118,8 +128,6 @@ void InitializeMusicLists() AddMusicToList(szMusicList[CREATURE_BATTLE_MUSIC], MUSICLIST_TACTICAL_CREEPY_BATTLE); - UINT8 constexpr buf = 64; - CHAR8 fileName[buf]; // Read music files into list for (size_t j = MUSICLIST_MAIN_MENU; j < MAX_MUSIC; j++) {