From 276cba46415143f0ca92be971c91c3fcd0fd0be5 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Wed, 8 Feb 2023 22:11:37 -0600 Subject: [PATCH] Basic alt music mapheaderinfo's musname field is now a 2 dimensional array, it can take up to 3 tracks and will randomly select between them on level load. --- src/deh_soc.c | 11 ++++++++--- src/doomstat.h | 2 +- src/m_random.h | 2 ++ src/p_setup.c | 9 +++++++-- src/s_sound.c | 5 +++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 4a5a6a5fd..a4645b518 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -1165,11 +1165,16 @@ void readlevelheader(MYFILE *f, char * name) else if (fastcmp(word, "MUSIC")) { if (fastcmp(word2, "NONE")) - mapheaderinfo[num]->musname[0] = 0; // becomes empty string + mapheaderinfo[num]->musname[0][0] = 0; // becomes empty string else { - deh_strlcpy(mapheaderinfo[num]->musname, word2, - sizeof(mapheaderinfo[num]->musname), va("Level header %d: music", num)); + UINT8 i = 0; + tmp = strtok(word2, ","); + do { + deh_strlcpy(mapheaderinfo[num]->musname[i], tmp, + sizeof(mapheaderinfo[num]->musname[i]), va("Level header %d: music", num)); + i += 1; + } while ((tmp = strtok(NULL,",")) != NULL); } } else if (fastcmp(word, "MUSICSLOT")) diff --git a/src/doomstat.h b/src/doomstat.h index 9a5b2f893..37bab32ea 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -410,7 +410,7 @@ struct mapheader_t fixed_t gravity; ///< Map-wide gravity. // Music information - char musname[7]; ///< Music track to play. "" for no music. + char musname[3][7]; ///< Music tracks to play. First dimension is the track number, second is the music string. "" for no music. UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore. UINT32 muspos; ///< Music position to jump to. diff --git a/src/m_random.h b/src/m_random.h index e9591970d..6f70e5847 100644 --- a/src/m_random.h +++ b/src/m_random.h @@ -67,6 +67,8 @@ typedef enum PR_SPARKLE, // Endsign and/or Emerald PR_MOVINGTARGET, // Randomised moving targets + + PR_MUSICSELECT, // Randomized music selection PRNUMCLASS } pr_class_t; diff --git a/src/p_setup.c b/src/p_setup.c index 2d4e2d54d..6184be712 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -378,6 +378,8 @@ void P_DeleteFlickies(INT16 i) */ static void P_ClearSingleMapHeaderInfo(INT16 num) { + UINT8 i = 0; + mapheaderinfo[num]->lvlttl[0] = '\0'; mapheaderinfo[num]->subttl[0] = '\0'; mapheaderinfo[num]->zonttl[0] = '\0'; @@ -385,8 +387,11 @@ static void P_ClearSingleMapHeaderInfo(INT16 num) mapheaderinfo[num]->typeoflevel = 0; mapheaderinfo[num]->gravity = DEFAULT_GRAVITY; mapheaderinfo[num]->keywords[0] = '\0'; - sprintf(mapheaderinfo[num]->musname, "%.5sM", G_BuildMapName(num+1)); - mapheaderinfo[num]->musname[6] = 0; + for (i = 0; i < 3; i++) + { + sprintf(mapheaderinfo[num]->musname[i], "%.5sM", G_BuildMapName(num+1)); + mapheaderinfo[num]->musname[i][6] = 0; + } mapheaderinfo[num]->mustrack = 0; mapheaderinfo[num]->muspos = 0; mapheaderinfo[num]->weather = PRECIP_NONE; diff --git a/src/s_sound.c b/src/s_sound.c index e146e5dd6..a483bbeb5 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2431,7 +2431,8 @@ void S_StartEx(boolean reset) if (mapmusflags & MUSIC_RELOADRESET) { - strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname, 7); + UINT32 i = P_RandomKey(PR_MUSICSELECT, 2); + strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname[i], 7); mapmusname[6] = 0; mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); mapmusposition = mapheaderinfo[gamemap-1]->muspos; @@ -2514,7 +2515,7 @@ static void Command_Tunes_f(void) } else if (!strcasecmp(tunearg, "-default")) { - tunearg = mapheaderinfo[gamemap-1]->musname; + tunearg = mapheaderinfo[gamemap-1]->musname[0]; track = mapheaderinfo[gamemap-1]->mustrack; }