SECRET_ALTMUSIC

Restricts a map's alt music, in order of music definition.
Supports out-of-order discoveries!
This commit is contained in:
toaster 2023-10-08 21:22:58 +01:00
parent 8fd809f8b1
commit d784f6ad4a
5 changed files with 67 additions and 12 deletions

View file

@ -1219,6 +1219,8 @@ void readlevelheader(MYFILE *f, char * name)
break;
deh_strlcpy(mapheaderinfo[num]->musname[j], tmp,
sizeof(mapheaderinfo[num]->musname[j]), va("Level header %d: music", num));
if (j)
mapheaderinfo[num]->cache_muslock[j - 1] = MAXUNLOCKABLES;
j++;
} while ((tmp = strtok(NULL,",")) != NULL);
@ -2354,6 +2356,8 @@ void readunlockable(MYFILE *f, INT32 num)
unlockables[num].type = SECRET_CUP;
else if (fastcmp(word2, "MAP"))
unlockables[num].type = SECRET_MAP;
else if (fastcmp(word2, "ALTMUSIC"))
unlockables[num].type = SECRET_ALTMUSIC;
else if (fastcmp(word2, "SKIN"))
unlockables[num].type = SECRET_SKIN;
else if (fastcmp(word2, "FOLLOWER"))

View file

@ -495,13 +495,14 @@ struct mapheader_t
char relevantskin[SKINNAMESIZE+1]; ///< Skin to use for tutorial (if not provided, uses Eggman.)
// 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 associatedmus[MAXMUSNAMES][7]; ///< Associated music tracks for sound test unlock.
char positionmus[7]; ///< Custom Position track. Doesn't play in Encore or other fun game-controlled contexts
UINT8 musname_size; ///< Number of music tracks defined
UINT8 associatedmus_size; ///< Number of associated music tracks defined
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.
char musname[MAXMUSNAMES][7]; ///< Music tracks to play. First dimension is the track number, second is the music string. "" for no music.
UINT16 cache_muslock[MAXMUSNAMES-1]; ///< Cached Alt Music IDs
char associatedmus[MAXMUSNAMES][7]; ///< Associated music tracks for sound test unlock.
char positionmus[7]; ///< Custom Position track. Doesn't play in Encore or other fun game-controlled contexts
UINT8 musname_size; ///< Number of music tracks defined
UINT8 associatedmus_size; ///< Number of associated music tracks defined
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.
// Sky information
UINT8 weather; ///< See preciptype_t

View file

@ -679,7 +679,7 @@ void M_ClearSecrets(void)
gamedata->numspraycans = 0;
gamedata->gotspraycans = 0;
UINT16 i;
UINT16 i, j;
for (i = 0; i < nummapheaders; i++)
{
if (!mapheaderinfo[i])
@ -688,6 +688,11 @@ void M_ClearSecrets(void)
mapheaderinfo[i]->cache_spraycan = UINT16_MAX;
mapheaderinfo[i]->cache_maplock = MAXUNLOCKABLES;
for (j = 1; j < mapheaderinfo[i]->musname_size; j++)
{
mapheaderinfo[i]->cache_muslock[j-1] = MAXUNLOCKABLES;
}
}
cupheader_t *cup;
@ -851,6 +856,28 @@ static void M_PrecacheLevelLocks(void)
break;
}
case SECRET_ALTMUSIC:
{
UINT16 map = M_UnlockableMapNum(&unlockables[i]);
if (map < nummapheaders
&& mapheaderinfo[map])
{
for (j = 1; j < mapheaderinfo[map]->musname_size; j++)
{
if (mapheaderinfo[map]->cache_muslock[j - 1] != MAXUNLOCKABLES)
{
continue;
}
mapheaderinfo[map]->cache_muslock[j - 1] = i;
break;
}
if (j == mapheaderinfo[map]->musname_size)
CONS_Alert(CONS_ERROR, "Unlockable %u: Too many SECRET_ALTMUSICs associated with Level %s\n", i, mapheaderinfo[map]->lumpname);
}
break;
}
case SECRET_CUP:
{
cupheader_t *cup = M_UnlockableCup(&unlockables[i]);
@ -2712,7 +2739,7 @@ cupheader_t *M_UnlockableCup(unlockable_t *unlock)
UINT16 M_UnlockableMapNum(unlockable_t *unlock)
{
if (unlock->type != SECRET_MAP)
if (unlock->type != SECRET_MAP && unlock->type != SECRET_ALTMUSIC)
{
// This isn't a map unlockable...
return NEXTMAP_INVALID;

View file

@ -187,6 +187,7 @@ typedef enum
// Level restrictions
SECRET_CUP, // Permit access to entire cup (overrides SECRET_MAP)
SECRET_MAP, // Permit access to single map
SECRET_ALTMUSIC, // Permit access to single map music track
// Player restrictions
SECRET_SKIN, // Permit this character

View file

@ -8055,10 +8055,32 @@ static void P_InitMinimapInfo(void)
void P_ResetLevelMusic(void)
{
mapmusrng = 0;
if (mapheaderinfo[gamemap-1]->musname_size > 1)
mapmusrng = P_RandomKey(PR_MUSICSELECT, mapheaderinfo[gamemap-1]->musname_size);
else
mapmusrng = 0;
{
UINT8 tempmapmus[MAXMUSNAMES], tempmapmus_size = 1, i;
tempmapmus[0] = 0;
for (i = 1; i < mapheaderinfo[gamemap-1]->musname_size; i++)
{
if (mapheaderinfo[gamemap-1]->cache_muslock[i-1] < MAXUNLOCKABLES
&& !M_CheckNetUnlockByID(mapheaderinfo[gamemap-1]->cache_muslock[i-1]))
continue;
//CONS_Printf("TEST - %u\n", i);
tempmapmus[tempmapmus_size++] = i;
}
if (tempmapmus_size > 1)
{
mapmusrng = P_RandomKey(PR_MUSICSELECT, tempmapmus_size);
//CONS_Printf("Rolled position %u, maps to %u\n", mapmusrng, tempmapmus[mapmusrng]);
mapmusrng = tempmapmus[mapmusrng];
}
}
}
void P_LoadLevelMusic(void)