diff --git a/src/doomstat.h b/src/doomstat.h index bf3c8576d..d8a591b12 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -42,6 +42,7 @@ extern char mapmusname[7]; extern UINT16 mapmusflags; extern UINT32 mapmusposition; extern UINT32 mapmusresume; +extern UINT32 mapmusrng; #define MUSIC_TRACKMASK 0x0FFF // ----************ #define MUSIC_RELOADRESET 0x8000 // *--------------- #define MUSIC_FORCERESET 0x4000 // -*-------------- @@ -412,7 +413,7 @@ struct mapheader_t fixed_t gravity; ///< Map-wide gravity. // Music information - char musname[MAXMUSNAMES][7]; ///< Music tracks to play. First dimension is the track number, second is the music string. "" for no music. + char musname[MAXMUSNAMES][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. UINT8 musname_size; ///< Number of music tracks defined diff --git a/src/g_game.c b/src/g_game.c index 0e723c9dd..9a70ea79f 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -93,6 +93,7 @@ char mapmusname[7]; // Music name UINT16 mapmusflags; // Track and reset bit UINT32 mapmusposition; // Position to jump to UINT32 mapmusresume; +UINT32 mapmusrng; // Random selection result INT16 gamemap = 1; UINT32 maptol; diff --git a/src/lua_script.c b/src/lua_script.c index be6fed523..fd1dcb9e1 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -309,6 +309,9 @@ int LUA_PushGlobals(lua_State *L, const char *word) } else if (fastcmp(word,"mapmusposition")) { lua_pushinteger(L, mapmusposition); return 1; + } else if (fastcmp(word,"mapmusrng")) { + lua_pushinteger(L, mapmusrng); + return 1; // local player variables, by popular request } else if (fastcmp(word,"consoleplayer")) { // player controlling console (aka local player 1) if (!addedtogame || consoleplayer < 0 || !playeringame[consoleplayer]) @@ -429,6 +432,8 @@ int LUA_WriteGlobals(lua_State *L, const char *word) } else if (fastcmp(word, "mapmusflags")) mapmusflags = (UINT16)luaL_checkinteger(L, 2); + else if (fastcmp(word, "mapmusrng")) + mapmusrng = (UINT32)luaL_checkinteger(L, 2); // SRB2Kart else if (fastcmp(word,"racecountdown")) racecountdown = (tic_t)luaL_checkinteger(L, 2); diff --git a/src/p_saveg.c b/src/p_saveg.c index 47a85c3df..c3620f19b 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -4881,6 +4881,8 @@ static void P_NetArchiveMisc(savebuffer_t *save, boolean resending) } WRITEUINT8(save->p, encoremode); + + WRITEUINT32(save->p, mapmusrng); WRITEUINT32(save->p, leveltime); WRITEINT16(save->p, lastmap); @@ -5045,6 +5047,8 @@ static inline boolean P_NetUnArchiveMisc(savebuffer_t *save, boolean reloading) } encoremode = (boolean)READUINT8(save->p); + + mapmusrng = READUINT32(save->p); if (!P_LoadLevel(true, reloading)) { diff --git a/src/p_setup.c b/src/p_setup.c index 7410b985b..52fac78c5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -7640,10 +7640,9 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) S_StartSound(NULL, sfx_s3k73); } - // As oddly named as this is, this handles music only. - // We should be fine starting it here. + // We should be fine starting music here. // Don't do this during titlemap, because the menu code handles music by itself. - S_Start(); + S_InitLevelMusic(fromnetsave); } if (gametyperules & GTR_SPECIALSTART) diff --git a/src/s_sound.c b/src/s_sound.c index 536601200..f6ccaae82 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2426,14 +2426,19 @@ boolean S_FadeOutStopMusic(UINT32 ms) // Kills playing sounds at start of level, // determines music if any, changes music. // -void S_StartEx(boolean reset) +void S_InitLevelMusic(boolean fromnetsave) { - (void)reset; if (mapmusflags & MUSIC_RELOADRESET) { - UINT32 t = P_RandomKey(PR_MUSICSELECT, mapheaderinfo[gamemap-1]->musname_size); - strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname[t], 7); + if (!fromnetsave) + { + if (mapheaderinfo[gamemap-1]->musname_size > 1) + mapmusrng = P_RandomKey(PR_MUSICSELECT, mapheaderinfo[gamemap-1]->musname_size); + else + mapmusrng = 0; + } + strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname[mapmusrng], 7); mapmusname[6] = 0; mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); mapmusposition = mapheaderinfo[gamemap-1]->muspos; diff --git a/src/s_sound.h b/src/s_sound.h index 14192b377..5e29e960f 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -123,8 +123,7 @@ void S_InitSfxChannels(INT32 sfxVolume); // void S_StopSounds(void); void S_ClearSfx(void); -void S_StartEx(boolean reset); -#define S_Start() S_StartEx(false) +void S_InitLevelMusic(boolean reset); // // Basically a W_GetNumForName that adds "ds" at the beginning of the string. Returns a lumpnum.