mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Clean up M_UpdateUnlockablesAndExtraEmblems and related
* `gamedata->unlockpending[MAXUNLOCKABLES]` stores info to prevent the same unlock causing multiple sounds, and simplify `M_GetNextAchievedUnlock` * Remove the DEVELOP cechotext * Each unlock on the challenges menu updates all the unlockables, rather than just `M_CheckUnlockConditions` * The unlock update function handles the incoming unlock sound itself if `loud` is true. This will allow us to quickly replace every sound at once when we've made a decision what to use Also: * Fixes the size of the savebuffer allocation in `G_SaveGame` to account for the challengegrid array.
This commit is contained in:
parent
0211bed1eb
commit
f179a3523f
8 changed files with 50 additions and 47 deletions
|
|
@ -1078,9 +1078,7 @@ void F_GameEvaluationTicker(void)
|
|||
{
|
||||
++gamedata->timesBeaten;
|
||||
|
||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||
S_StartSound(NULL, sfx_s3k68);
|
||||
|
||||
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||
G_SaveGameData();
|
||||
}
|
||||
else
|
||||
|
|
|
|||
41
src/g_game.c
41
src/g_game.c
|
|
@ -590,10 +590,7 @@ static void G_UpdateRecordReplays(void)
|
|||
if ((earnedEmblems = M_CheckLevelEmblems()))
|
||||
CONS_Printf(M_GetText("\x82" "Earned %hu medal%s for Record Attack records.\n"), (UINT16)earnedEmblems, earnedEmblems > 1 ? "s" : "");
|
||||
|
||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||
S_StartSound(NULL, sfx_ncitem);
|
||||
|
||||
// SRB2Kart - save here so you NEVER lose your earned times/medals.
|
||||
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||
G_SaveGameData();
|
||||
}
|
||||
|
||||
|
|
@ -2185,8 +2182,7 @@ static inline void G_PlayerFinishLevel(INT32 player)
|
|||
if (legitimateexit && !demo.playback && !mapreset) // (yes you're allowed to unlock stuff this way when the game is modified)
|
||||
{
|
||||
gamedata->matchesplayed++;
|
||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||
S_StartSound(NULL, sfx_ncitem);
|
||||
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||
G_SaveGameData();
|
||||
}
|
||||
|
||||
|
|
@ -3686,8 +3682,7 @@ static void G_UpdateVisited(void)
|
|||
if ((earnedEmblems = M_CompletionEmblems()))
|
||||
CONS_Printf(M_GetText("\x82" "Earned %hu emblem%s for level completion.\n"), (UINT16)earnedEmblems, earnedEmblems > 1 ? "s" : "");
|
||||
|
||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||
S_StartSound(NULL, sfx_ncitem);
|
||||
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||
G_SaveGameData();
|
||||
}
|
||||
|
||||
|
|
@ -4393,6 +4388,13 @@ void G_LoadGameData(void)
|
|||
gamedata->unlocked[j+i] = ((rtemp >> j) & 1);
|
||||
i += j;
|
||||
}
|
||||
for (i = 0; i < MAXUNLOCKABLES;)
|
||||
{
|
||||
rtemp = READUINT8(save_p);
|
||||
for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j)
|
||||
gamedata->unlockpending[j+i] = ((rtemp >> j) & 1);
|
||||
i += j;
|
||||
}
|
||||
for (i = 0; i < MAXCONDITIONSETS;)
|
||||
{
|
||||
rtemp = READUINT8(save_p);
|
||||
|
|
@ -4510,7 +4512,11 @@ void G_SaveGameData(void)
|
|||
return;
|
||||
}
|
||||
|
||||
length = (4+4+4+1+(MAXEMBLEMS+MAXUNLOCKABLES+MAXCONDITIONSETS)+4+4);
|
||||
length = (4+4+4+1+(MAXEMBLEMS+(MAXUNLOCKABLES*2)+MAXCONDITIONSETS)+4+4+2);
|
||||
if (gamedata->challengegrid)
|
||||
{
|
||||
length += gamedata->challengegridwidth * CHALLENGEGRIDHEIGHT;
|
||||
}
|
||||
length += nummapheaders * (MAXMAPLUMPNAME+1+4+4);
|
||||
|
||||
save_p = savebuffer = (UINT8 *)malloc(length);
|
||||
|
|
@ -4536,7 +4542,9 @@ void G_SaveGameData(void)
|
|||
WRITEUINT8(save_p, btemp);
|
||||
i += j;
|
||||
}
|
||||
for (i = 0; i < MAXUNLOCKABLES;) // MAXUNLOCKABLES * 1;
|
||||
|
||||
// MAXUNLOCKABLES * 2;
|
||||
for (i = 0; i < MAXUNLOCKABLES;)
|
||||
{
|
||||
btemp = 0;
|
||||
for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j)
|
||||
|
|
@ -4544,6 +4552,15 @@ void G_SaveGameData(void)
|
|||
WRITEUINT8(save_p, btemp);
|
||||
i += j;
|
||||
}
|
||||
for (i = 0; i < MAXUNLOCKABLES;)
|
||||
{
|
||||
btemp = 0;
|
||||
for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j)
|
||||
btemp |= (gamedata->unlockpending[j+i] << j);
|
||||
WRITEUINT8(save_p, btemp);
|
||||
i += j;
|
||||
}
|
||||
|
||||
for (i = 0; i < MAXCONDITIONSETS;) // MAXCONDITIONSETS * 1;
|
||||
{
|
||||
btemp = 0;
|
||||
|
|
@ -4553,7 +4570,7 @@ void G_SaveGameData(void)
|
|||
i += j;
|
||||
}
|
||||
|
||||
if (gamedata->challengegrid)
|
||||
if (gamedata->challengegrid) // 2 + gamedata->challengegridwidth * CHALLENGEGRIDHEIGHT
|
||||
{
|
||||
WRITEUINT16(save_p, gamedata->challengegridwidth);
|
||||
for (i = 0; i < (gamedata->challengegridwidth * CHALLENGEGRIDHEIGHT); i++)
|
||||
|
|
@ -4561,7 +4578,7 @@ void G_SaveGameData(void)
|
|||
WRITEUINT8(save_p, gamedata->challengegrid[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
else // 2
|
||||
{
|
||||
WRITEUINT16(save_p, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7097,6 +7097,8 @@ void M_ChallengesTick(void)
|
|||
{
|
||||
// Unlock animation... also tied directly to the actual unlock!
|
||||
gamedata->unlocked[challengesmenu.currentunlock] = true;
|
||||
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||
|
||||
challengesmenu.unlockcount[CC_TALLY]++;
|
||||
challengesmenu.unlockcount[CC_ANIM]++;
|
||||
|
||||
|
|
|
|||
|
|
@ -418,11 +418,7 @@ void K_CashInPowerLevels(void)
|
|||
{
|
||||
pr->powerlevels[powerType] = clientpowerlevels[i][powerType];
|
||||
|
||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||
{
|
||||
S_StartSound(NULL, sfx_ncitem);
|
||||
}
|
||||
|
||||
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||
G_SaveGameData();
|
||||
}
|
||||
}
|
||||
|
|
@ -642,11 +638,7 @@ void K_PlayerForfeit(UINT8 playerNum, boolean pointLoss)
|
|||
{
|
||||
pr->powerlevels[powerType] = yourPower + inc;
|
||||
|
||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||
{
|
||||
S_StartSound(NULL, sfx_ncitem);
|
||||
}
|
||||
|
||||
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||
G_SaveGameData();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
31
src/m_cond.c
31
src/m_cond.c
|
|
@ -22,6 +22,7 @@
|
|||
#include "r_skins.h" // numskins
|
||||
#include "k_follower.h"
|
||||
#include "r_draw.h" // R_GetColorByName
|
||||
#include "s_sound.h" // S_StartSound
|
||||
|
||||
#include "k_pwrlv.h"
|
||||
#include "k_profiles.h"
|
||||
|
|
@ -443,7 +444,7 @@ void M_ClearSecrets(void)
|
|||
for (i = 0; i < MAXEMBLEMS; ++i)
|
||||
gamedata->collected[i] = false;
|
||||
for (i = 0; i < MAXUNLOCKABLES; ++i)
|
||||
gamedata->unlocked[i] = netUnlocked[i] = false;
|
||||
gamedata->unlocked[i] = gamedata->unlockpending[i] = netUnlocked[i] = false;
|
||||
for (i = 0; i < MAXCONDITIONSETS; ++i)
|
||||
gamedata->achieved[i] = false;
|
||||
|
||||
|
|
@ -562,8 +563,7 @@ void M_CheckUnlockConditions(void)
|
|||
boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud)
|
||||
{
|
||||
INT32 i;
|
||||
char cechoText[992] = "";
|
||||
UINT8 cechoLines = 0;
|
||||
UINT8 response = 0;
|
||||
|
||||
if (!loud)
|
||||
{
|
||||
|
|
@ -583,7 +583,8 @@ boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (gamedata->unlocked[i] == true)
|
||||
if (gamedata->unlocked[i] == true
|
||||
|| gamedata->unlockpending[i] == true)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -593,21 +594,17 @@ boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (loud)
|
||||
{
|
||||
strcat(cechoText, va("\"%s\" unlocked!\n", unlockables[i].name));
|
||||
}
|
||||
++cechoLines;
|
||||
gamedata->unlockpending[i] = true;
|
||||
response++;
|
||||
}
|
||||
|
||||
// Announce
|
||||
if (cechoLines && loud)
|
||||
if (response)
|
||||
{
|
||||
strcat(cechoText, "Return to main menu to see");
|
||||
#ifdef DEVELOP
|
||||
// todo make debugmode
|
||||
CONS_Printf("%s\n", cechoText);
|
||||
#endif
|
||||
if (loud)
|
||||
{
|
||||
S_StartSound(NULL, sfx_ncitem);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -617,8 +614,6 @@ UINT8 M_GetNextAchievedUnlock(void)
|
|||
{
|
||||
UINT8 i;
|
||||
|
||||
M_CheckUnlockConditions();
|
||||
|
||||
// Go through unlockables
|
||||
for (i = 0; i < MAXUNLOCKABLES; ++i)
|
||||
{
|
||||
|
|
@ -632,7 +627,7 @@ UINT8 M_GetNextAchievedUnlock(void)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (M_Achieved(unlockables[i].conditionset - 1) == false)
|
||||
if (gamedata->unlockpending[i] == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ struct gamedata_t
|
|||
|
||||
// UNLOCKABLES UNLOCKED
|
||||
boolean unlocked[MAXUNLOCKABLES];
|
||||
boolean unlockpending[MAXUNLOCKABLES];
|
||||
|
||||
// CHALLENGE GRID
|
||||
UINT16 challengegridwidth;
|
||||
|
|
@ -188,7 +189,7 @@ void M_ClearSecrets(void);
|
|||
// Updating conditions and unlockables
|
||||
void M_CheckUnlockConditions(void);
|
||||
UINT8 M_CheckCondition(condition_t *cn);
|
||||
boolean M_UpdateUnlockablesAndExtraEmblems(boolean silent);
|
||||
boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud);
|
||||
UINT8 M_GetNextAchievedUnlock(void);
|
||||
UINT8 M_CheckLevelEmblems(void);
|
||||
UINT8 M_CompletionEmblems(void);
|
||||
|
|
|
|||
|
|
@ -7566,8 +7566,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
|
|||
{
|
||||
mapheaderinfo[gamemap-1]->mapvisited |= MV_VISITED;
|
||||
|
||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||
S_StartSound(NULL, sfx_ncitem);
|
||||
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||
G_SaveGameData();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2765,7 +2765,6 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec)
|
|||
// Unlocked something?
|
||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||
{
|
||||
S_StartSound(NULL, sfx_s3k68);
|
||||
G_SaveGameData(); // only save if unlocked something
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue