From c7bd75b60d30539287843e2f21bb93f7257bad12 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Wed, 24 Jan 2024 00:35:39 +0200 Subject: [PATCH 1/9] Merc arrival location fix (#263) * User center insertion point for merc arrival instead of initial arrival gridno that is meant only for the very first helidrop arrival at the start of a game. * Prevent possible nullptr dereference --- Ja2/gamescreen.cpp | 7 +++++++ Strategic/strategicmap.cpp | 27 +++++++++++---------------- Tactical/Merc Entering.cpp | 29 +++++++++++++++-------------- Tactical/Merc Hiring.cpp | 21 +++++++++++++-------- 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/Ja2/gamescreen.cpp b/Ja2/gamescreen.cpp index 28fd812d..ba3ceb80 100644 --- a/Ja2/gamescreen.cpp +++ b/Ja2/gamescreen.cpp @@ -628,7 +628,14 @@ UINT32 MainGameScreenHandle(void) InternalLocateGridNo( gGameUBOptions.LOCATEGRIDNO, TRUE ); } #else + if (gfFirstHeliRun) + { InternalLocateGridNo( gGameExternalOptions.iInitialMercArrivalLocation, TRUE ); + } + else + { + InternalLocateGridNo(gMapInformation.sCenterGridNo, TRUE); + } #endif // Flugente: we might have reloaded the game, so we are currently not dropping mercs out of a helicopter gfIngagedInDrop = FALSE; diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index f194853a..5708dfc7 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -3382,27 +3382,22 @@ void UpdateMercInSector( SOLDIERTYPE *pSoldier, INT16 sSectorX, INT16 sSectorY, break; case INSERTION_CODE_ARRIVING_GAME: - // Are we in Omerta! - if ( sSectorX == gWorldSectorX && gWorldSectorX == 9 && sSectorY == gWorldSectorY && gWorldSectorY == 1 && bSectorZ == gbWorldSectorZ && gbWorldSectorZ == 0 ) +#ifdef JA2UB + pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; + pSoldier->sInsertionGridNo = gGameUBOptions.LOCATEGRIDNO; +#else + extern BOOLEAN gfFirstHeliRun; + if (gfFirstHeliRun) { - // TODO.WANNE: Hardcoded grid number - // Try another location and walk into map - pSoldier->sInsertionGridNo = 4379;//dnl!!! + pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; + pSoldier->sInsertionGridNo = gGameExternalOptions.iInitialMercArrivalLocation; } else { -#ifdef JA2UB - //pSoldier->ubStrategicInsertionCode = INSERTION_CODE_NORTH; - //pSoldier->sInsertionGridNo = gMapInformation.sNorthGridNo; - pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; - pSoldier->sInsertionGridNo = gGameUBOptions.LOCATEGRIDNO; -#else - //pSoldier->ubStrategicInsertionCode = INSERTION_CODE_NORTH; - //pSoldier->sInsertionGridNo = gMapInformation.sNorthGridNo; - pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; - pSoldier->sInsertionGridNo = gGameExternalOptions.iInitialMercArrivalLocation; -#endif + pSoldier->ubStrategicInsertionCode = INSERTION_CODE_CENTER; + pSoldier->sInsertionGridNo = gMapInformation.sCenterGridNo; } +#endif break; case INSERTION_CODE_CHOPPER: // Try another location and walk into map diff --git a/Tactical/Merc Entering.cpp b/Tactical/Merc Entering.cpp index 53e74b16..39dc0e7d 100644 --- a/Tactical/Merc Entering.cpp +++ b/Tactical/Merc Entering.cpp @@ -1038,27 +1038,28 @@ UINT8 SpawnAirDropElite( INT32 sGridNo ) // Flugente hack pSoldier = TacticalCreateEliteEnemy( ); + if ( pSoldier == nullptr) + { + return NOBODY; + } //Add soldier strategic info, so it doesn't break the counters! - if ( pSoldier ) + if ( !gbWorldSectorZ ) { - if ( !gbWorldSectorZ ) + SECTORINFO *pSector = &SectorInfo[SECTOR( gWorldSectorX, gWorldSectorY )]; + switch ( pSoldier->ubSoldierClass ) { - SECTORINFO *pSector = &SectorInfo[SECTOR( gWorldSectorX, gWorldSectorY )]; - switch ( pSoldier->ubSoldierClass ) - { - case SOLDIER_CLASS_ADMINISTRATOR: pSector->ubNumAdmins++; pSector->ubAdminsInBattle++; break; - case SOLDIER_CLASS_ARMY: pSector->ubNumTroops++; pSector->ubTroopsInBattle++; break; - case SOLDIER_CLASS_ELITE: pSector->ubNumElites++; pSector->ubElitesInBattle++; break; - } + case SOLDIER_CLASS_ADMINISTRATOR: pSector->ubNumAdmins++; pSector->ubAdminsInBattle++; break; + case SOLDIER_CLASS_ARMY: pSector->ubNumTroops++; pSector->ubTroopsInBattle++; break; + case SOLDIER_CLASS_ELITE: pSector->ubNumElites++; pSector->ubElitesInBattle++; break; } - - pSoldier->ubStrategicInsertionCode = INSERTION_CODE_CHOPPER; - pSoldier->usStrategicInsertionData = sGridNo; // required, otherwise soldiers will spawn in map before jumping out of the heli - UpdateMercInSector( pSoldier, gWorldSectorX, gWorldSectorY, gbWorldSectorZ ); - //AllTeamsLookForAll( NO_INTERRUPTS ); } + pSoldier->ubStrategicInsertionCode = INSERTION_CODE_CHOPPER; + pSoldier->usStrategicInsertionData = sGridNo; // required, otherwise soldiers will spawn in map before jumping out of the heli + UpdateMercInSector( pSoldier, gWorldSectorX, gWorldSectorY, gbWorldSectorZ ); + //AllTeamsLookForAll( NO_INTERRUPTS ); + return pSoldier->ubID; } diff --git a/Tactical/Merc Hiring.cpp b/Tactical/Merc Hiring.cpp index 002926c7..24e98b63 100644 --- a/Tactical/Merc Hiring.cpp +++ b/Tactical/Merc Hiring.cpp @@ -50,6 +50,7 @@ #include "DynamicDialogue.h"// added by Flugente #include "Dialogue Control.h" // added by Flugente #include "connect.h" +#include "Map Information.h" #ifdef JA2UB #include "Soldier Control.h" @@ -534,16 +535,23 @@ void MercArrivesCallback( UINT8 ubSoldierID ) #ifdef JA2UB if ( pSoldier->ubStrategicInsertionCode != INSERTION_CODE_CHOPPER && pSoldier->sSectorX == gGameExternalOptions.ubDefaultArrivalSectorX && pSoldier->sSectorY == gGameExternalOptions.ubDefaultArrivalSectorY && gGameUBOptions.InGameHeli == TRUE ) #else - if ( pSoldier->ubStrategicInsertionCode != INSERTION_CODE_CHOPPER && pSoldier->sSectorX == gGameExternalOptions.ubDefaultArrivalSectorX && pSoldier->sSectorY == gGameExternalOptions.ubDefaultArrivalSectorY ) + if (pSoldier->ubStrategicInsertionCode != INSERTION_CODE_CHOPPER ) #endif { gfTacticalDoHeliRun = TRUE; - SetHelicopterDroppoint(gGameExternalOptions.iInitialMercArrivalLocation); + if (gfFirstHeliRun) + { + SetHelicopterDroppoint(gGameExternalOptions.iInitialMercArrivalLocation); + } + else + { + SetHelicopterDroppoint(gMapInformation.sCenterGridNo); + } // OK, If we are in mapscreen, get out... if ( guiCurrentScreen == MAP_SCREEN ) { - // ATE: Make sure the current one is selected! + // ATE: Make sure the current one is selected! ChangeSelectedMapSector( gWorldSectorX, gWorldSectorY, 0 ); RequestTriggerExitFromMapscreen( MAP_EXIT_TO_TACTICAL ); @@ -554,17 +562,14 @@ void MercArrivesCallback( UINT8 ubSoldierID ) UpdateMercInSector( pSoldier, pSoldier->sSectorX, pSoldier->sSectorY, pSoldier->bSectorZ ); } + // Strategic map arrival to a sector that's not loaded else { - // OK, otherwise, set them in north area, so once we load again, they are here. #ifdef JA2UB - //pSoldier->ubStrategicInsertionCode = INSERTION_CODE_NORTH; pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; pSoldier->usStrategicInsertionData = gGameUBOptions.LOCATEGRIDNO; #else - //pSoldier->ubStrategicInsertionCode = INSERTION_CODE_NORTH; - pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO; - pSoldier->usStrategicInsertionData = gGameExternalOptions.iInitialMercArrivalLocation; + pSoldier->ubStrategicInsertionCode = INSERTION_CODE_CENTER; #endif } 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 2/9] 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 | 65 ++--- sgp/sgp.cpp | 4 + 5 files changed, 194 insertions(+), 480 deletions(-) diff --git a/Editor/editscreen.cpp b/Editor/editscreen.cpp index a62be1e5..1cd2ceb3 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 e799bb23..be83d757 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 c657f62b..78f50b93 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); + MusicPlay(PickRandomSongFromList(MUSICLIST_TACTICAL_CREEPY)); } else { - 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)); + 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 6a6109ff..3a998376 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]; + 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, -} MUSIC_SOUND_VALUES; + 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 121dce70..6686d637 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 5a74323d1f8b074a3142bea288f30d46a90352c4 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:07:25 +0200 Subject: [PATCH 3/9] Disable AI logging by default We only want this on when specifically debugging/working on AI. --- TacticalAI/AIMain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index 0aab1c32..a19a1e77 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -209,7 +209,7 @@ STR szAction[] = { // sevenfm UINT32 guiAIStartCounter = 0, guiAILastCounter = 0; //UINT8 gubAISelectedSoldier = NOBODY; -BOOLEAN gfLogsEnabled = TRUE; +BOOLEAN gfLogsEnabled = FALSE; void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction ) { From 2697a17010ba4937accd56d69aefe4f7fc4768ca Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:08:06 +0200 Subject: [PATCH 4/9] Check if pSoldier is null Prevent nullptr dereference in AI logging function --- TacticalAI/AIMain.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index a19a1e77..f4d0d431 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -217,7 +217,7 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction ) CHAR8 msg[1024]; CHAR8 buf[1024]; - if (!gfLogsEnabled) + if (!gfLogsEnabled || pSoldier == nullptr) return; memset(buf, 0, 1024 * sizeof(char)); @@ -235,17 +235,14 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction ) sprintf(msg, ""); - if (pSoldier) - { - sprintf(buf, "[%d] (%d)", pSoldier->ubID, pSoldier->sGridNo); - strcat(msg, buf); + sprintf(buf, "[%d] (%d)", pSoldier->ubID, pSoldier->sGridNo); + strcat(msg, buf); - if (pSoldier->ubProfile != NO_PROFILE) - { - wcstombs(buf, pSoldier->GetName(), 1024 - 1); - strcat(msg, " "); - strcat(msg, buf); - } + if (pSoldier->ubProfile != NO_PROFILE) + { + wcstombs(buf, pSoldier->GetName(), 1024 - 1); + strcat(msg, " "); + strcat(msg, buf); } strcat(msg, " "); @@ -266,13 +263,10 @@ void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction ) strcat(msg, " "); strcat(msg, szAction[bAction]); - if (pSoldier) - { - sprintf(buf, " %d", pSoldier->aiData.usActionData); - strcat(msg, buf); - } + sprintf(buf, " %d", pSoldier->aiData.usActionData); + strcat(msg, buf); - if (pSoldier && pSoldier->aiData.bNextAction != AI_ACTION_NONE) + if (pSoldier->aiData.bNextAction != AI_ACTION_NONE) { strcat(msg, " "); strcat(msg, szAction[pSoldier->aiData.bNextAction]); 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 5/9] 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 78f50b93..740b5ed1 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 6/9] 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 740b5ed1..0d1361d7 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 3a998376..2d67f5d0 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 7/9] 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 0d1361d7..aa86d29d 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++) { From 0910dba472bba397432b7dd4fae569b001565cf3 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Tue, 30 Jan 2024 11:44:00 +0200 Subject: [PATCH 8/9] Revert "Disable AI logging by default" (#270) This reverts commit 5a74323d1f8b074a3142bea288f30d46a90352c4. --- TacticalAI/AIMain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TacticalAI/AIMain.cpp b/TacticalAI/AIMain.cpp index f4d0d431..a64c4fcd 100644 --- a/TacticalAI/AIMain.cpp +++ b/TacticalAI/AIMain.cpp @@ -209,7 +209,7 @@ STR szAction[] = { // sevenfm UINT32 guiAIStartCounter = 0, guiAILastCounter = 0; //UINT8 gubAISelectedSoldier = NOBODY; -BOOLEAN gfLogsEnabled = FALSE; +BOOLEAN gfLogsEnabled = TRUE; void DebugAI( INT8 bMsgType, SOLDIERTYPE *pSoldier, STR szOutput, INT8 bAction ) { From d2967899290809d8ff2f05030a2e7fbdb595df8d Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Tue, 30 Jan 2024 22:53:19 +0200 Subject: [PATCH 9/9] LOBOT: enemies wear pistol holsters (by Seven) (#271) --- Tactical/Inventory Choosing.cpp | 40 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/Tactical/Inventory Choosing.cpp b/Tactical/Inventory Choosing.cpp index e6c1220e..cbac1179 100644 --- a/Tactical/Inventory Choosing.cpp +++ b/Tactical/Inventory Choosing.cpp @@ -2246,29 +2246,45 @@ void ChooseBombsForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bBombClas void ChooseLBEsForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bLBEClass ) { DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"ChooseLBEsForSoldierCreateStruct"); - //UINT16 i; - //INVTYPE *pItem; - //UINT16 usRandom; - UINT16 usItem = 0; // CHRISL: If we're using the old inventory system, just return if((UsingNewInventorySystem() == false)) return; - usItem = PickARandomItem( LBE, pp->ubSoldierClass, bLBEClass, FALSE ); + UINT16 usItem = PickARandomItem( LBE, pp->ubSoldierClass, bLBEClass, FALSE ); if ( usItem > 0 ) { CreateItem( usItem, (INT8)(80 + Random( 21 )), &gTempObject ); gTempObject.fFlags |= OBJECT_UNDROPPABLE; - // put backpacks into the backpack slot for LOBOT - if ((UsingNewInventorySystem()) && (Item[usItem].usItemClass & IC_LBEGEAR) && (LoadBearingEquipment[Item[usItem].ubClassIndex].lbeClass == BACKPACK)) + + auto isLBEgear = Item[usItem].usItemClass & IC_LBEGEAR; + if (isLBEgear) { - pp->Inv[BPACKPOCKPOS] = gTempObject; - } - else - { - PlaceObjectInSoldierCreateStruct( pp, &gTempObject ); + // put backpacks into the backpack slot for LOBOT + auto lbeClass = LoadBearingEquipment[Item[usItem].ubClassIndex].lbeClass; + if (lbeClass == BACKPACK && !pp->Inv[BPACKPOCKPOS].exists()) + { + pp->Inv[BPACKPOCKPOS] = gTempObject; + return; + } + // same for pistol holster + if (lbeClass == THIGH_PACK) + { + if (!pp->Inv[LTHIGHPOCKPOS].exists()) + { + pp->Inv[LTHIGHPOCKPOS] = gTempObject; + return; + } + if (!pp->Inv[RTHIGHPOCKPOS].exists()) + { + pp->Inv[RTHIGHPOCKPOS] = gTempObject; + return; + } + } } + + // Couldn't find a specific pocket, just stuff it somewhere + PlaceObjectInSoldierCreateStruct( pp, &gTempObject ); } }