mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-05-10 19:01:50 +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;
|
++gamedata->timesBeaten;
|
||||||
|
|
||||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||||
S_StartSound(NULL, sfx_s3k68);
|
|
||||||
|
|
||||||
G_SaveGameData();
|
G_SaveGameData();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
41
src/g_game.c
41
src/g_game.c
|
|
@ -590,10 +590,7 @@ static void G_UpdateRecordReplays(void)
|
||||||
if ((earnedEmblems = M_CheckLevelEmblems()))
|
if ((earnedEmblems = M_CheckLevelEmblems()))
|
||||||
CONS_Printf(M_GetText("\x82" "Earned %hu medal%s for Record Attack records.\n"), (UINT16)earnedEmblems, earnedEmblems > 1 ? "s" : "");
|
CONS_Printf(M_GetText("\x82" "Earned %hu medal%s for Record Attack records.\n"), (UINT16)earnedEmblems, earnedEmblems > 1 ? "s" : "");
|
||||||
|
|
||||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||||
S_StartSound(NULL, sfx_ncitem);
|
|
||||||
|
|
||||||
// SRB2Kart - save here so you NEVER lose your earned times/medals.
|
|
||||||
G_SaveGameData();
|
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)
|
if (legitimateexit && !demo.playback && !mapreset) // (yes you're allowed to unlock stuff this way when the game is modified)
|
||||||
{
|
{
|
||||||
gamedata->matchesplayed++;
|
gamedata->matchesplayed++;
|
||||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||||
S_StartSound(NULL, sfx_ncitem);
|
|
||||||
G_SaveGameData();
|
G_SaveGameData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3686,8 +3682,7 @@ static void G_UpdateVisited(void)
|
||||||
if ((earnedEmblems = M_CompletionEmblems()))
|
if ((earnedEmblems = M_CompletionEmblems()))
|
||||||
CONS_Printf(M_GetText("\x82" "Earned %hu emblem%s for level completion.\n"), (UINT16)earnedEmblems, earnedEmblems > 1 ? "s" : "");
|
CONS_Printf(M_GetText("\x82" "Earned %hu emblem%s for level completion.\n"), (UINT16)earnedEmblems, earnedEmblems > 1 ? "s" : "");
|
||||||
|
|
||||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||||
S_StartSound(NULL, sfx_ncitem);
|
|
||||||
G_SaveGameData();
|
G_SaveGameData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4393,6 +4388,13 @@ void G_LoadGameData(void)
|
||||||
gamedata->unlocked[j+i] = ((rtemp >> j) & 1);
|
gamedata->unlocked[j+i] = ((rtemp >> j) & 1);
|
||||||
i += j;
|
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;)
|
for (i = 0; i < MAXCONDITIONSETS;)
|
||||||
{
|
{
|
||||||
rtemp = READUINT8(save_p);
|
rtemp = READUINT8(save_p);
|
||||||
|
|
@ -4510,7 +4512,11 @@ void G_SaveGameData(void)
|
||||||
return;
|
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);
|
length += nummapheaders * (MAXMAPLUMPNAME+1+4+4);
|
||||||
|
|
||||||
save_p = savebuffer = (UINT8 *)malloc(length);
|
save_p = savebuffer = (UINT8 *)malloc(length);
|
||||||
|
|
@ -4536,7 +4542,9 @@ void G_SaveGameData(void)
|
||||||
WRITEUINT8(save_p, btemp);
|
WRITEUINT8(save_p, btemp);
|
||||||
i += j;
|
i += j;
|
||||||
}
|
}
|
||||||
for (i = 0; i < MAXUNLOCKABLES;) // MAXUNLOCKABLES * 1;
|
|
||||||
|
// MAXUNLOCKABLES * 2;
|
||||||
|
for (i = 0; i < MAXUNLOCKABLES;)
|
||||||
{
|
{
|
||||||
btemp = 0;
|
btemp = 0;
|
||||||
for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j)
|
for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j)
|
||||||
|
|
@ -4544,6 +4552,15 @@ void G_SaveGameData(void)
|
||||||
WRITEUINT8(save_p, btemp);
|
WRITEUINT8(save_p, btemp);
|
||||||
i += j;
|
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;
|
for (i = 0; i < MAXCONDITIONSETS;) // MAXCONDITIONSETS * 1;
|
||||||
{
|
{
|
||||||
btemp = 0;
|
btemp = 0;
|
||||||
|
|
@ -4553,7 +4570,7 @@ void G_SaveGameData(void)
|
||||||
i += j;
|
i += j;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gamedata->challengegrid)
|
if (gamedata->challengegrid) // 2 + gamedata->challengegridwidth * CHALLENGEGRIDHEIGHT
|
||||||
{
|
{
|
||||||
WRITEUINT16(save_p, gamedata->challengegridwidth);
|
WRITEUINT16(save_p, gamedata->challengegridwidth);
|
||||||
for (i = 0; i < (gamedata->challengegridwidth * CHALLENGEGRIDHEIGHT); i++)
|
for (i = 0; i < (gamedata->challengegridwidth * CHALLENGEGRIDHEIGHT); i++)
|
||||||
|
|
@ -4561,7 +4578,7 @@ void G_SaveGameData(void)
|
||||||
WRITEUINT8(save_p, gamedata->challengegrid[i]);
|
WRITEUINT8(save_p, gamedata->challengegrid[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else // 2
|
||||||
{
|
{
|
||||||
WRITEUINT16(save_p, 0);
|
WRITEUINT16(save_p, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7097,6 +7097,8 @@ void M_ChallengesTick(void)
|
||||||
{
|
{
|
||||||
// Unlock animation... also tied directly to the actual unlock!
|
// Unlock animation... also tied directly to the actual unlock!
|
||||||
gamedata->unlocked[challengesmenu.currentunlock] = true;
|
gamedata->unlocked[challengesmenu.currentunlock] = true;
|
||||||
|
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||||
|
|
||||||
challengesmenu.unlockcount[CC_TALLY]++;
|
challengesmenu.unlockcount[CC_TALLY]++;
|
||||||
challengesmenu.unlockcount[CC_ANIM]++;
|
challengesmenu.unlockcount[CC_ANIM]++;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -418,11 +418,7 @@ void K_CashInPowerLevels(void)
|
||||||
{
|
{
|
||||||
pr->powerlevels[powerType] = clientpowerlevels[i][powerType];
|
pr->powerlevels[powerType] = clientpowerlevels[i][powerType];
|
||||||
|
|
||||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||||
{
|
|
||||||
S_StartSound(NULL, sfx_ncitem);
|
|
||||||
}
|
|
||||||
|
|
||||||
G_SaveGameData();
|
G_SaveGameData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -642,11 +638,7 @@ void K_PlayerForfeit(UINT8 playerNum, boolean pointLoss)
|
||||||
{
|
{
|
||||||
pr->powerlevels[powerType] = yourPower + inc;
|
pr->powerlevels[powerType] = yourPower + inc;
|
||||||
|
|
||||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||||
{
|
|
||||||
S_StartSound(NULL, sfx_ncitem);
|
|
||||||
}
|
|
||||||
|
|
||||||
G_SaveGameData();
|
G_SaveGameData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
src/m_cond.c
31
src/m_cond.c
|
|
@ -22,6 +22,7 @@
|
||||||
#include "r_skins.h" // numskins
|
#include "r_skins.h" // numskins
|
||||||
#include "k_follower.h"
|
#include "k_follower.h"
|
||||||
#include "r_draw.h" // R_GetColorByName
|
#include "r_draw.h" // R_GetColorByName
|
||||||
|
#include "s_sound.h" // S_StartSound
|
||||||
|
|
||||||
#include "k_pwrlv.h"
|
#include "k_pwrlv.h"
|
||||||
#include "k_profiles.h"
|
#include "k_profiles.h"
|
||||||
|
|
@ -443,7 +444,7 @@ void M_ClearSecrets(void)
|
||||||
for (i = 0; i < MAXEMBLEMS; ++i)
|
for (i = 0; i < MAXEMBLEMS; ++i)
|
||||||
gamedata->collected[i] = false;
|
gamedata->collected[i] = false;
|
||||||
for (i = 0; i < MAXUNLOCKABLES; ++i)
|
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)
|
for (i = 0; i < MAXCONDITIONSETS; ++i)
|
||||||
gamedata->achieved[i] = false;
|
gamedata->achieved[i] = false;
|
||||||
|
|
||||||
|
|
@ -562,8 +563,7 @@ void M_CheckUnlockConditions(void)
|
||||||
boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud)
|
boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud)
|
||||||
{
|
{
|
||||||
INT32 i;
|
INT32 i;
|
||||||
char cechoText[992] = "";
|
UINT8 response = 0;
|
||||||
UINT8 cechoLines = 0;
|
|
||||||
|
|
||||||
if (!loud)
|
if (!loud)
|
||||||
{
|
{
|
||||||
|
|
@ -583,7 +583,8 @@ boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gamedata->unlocked[i] == true)
|
if (gamedata->unlocked[i] == true
|
||||||
|
|| gamedata->unlockpending[i] == true)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -593,21 +594,17 @@ boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loud)
|
gamedata->unlockpending[i] = true;
|
||||||
{
|
response++;
|
||||||
strcat(cechoText, va("\"%s\" unlocked!\n", unlockables[i].name));
|
|
||||||
}
|
|
||||||
++cechoLines;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Announce
|
// Announce
|
||||||
if (cechoLines && loud)
|
if (response)
|
||||||
{
|
{
|
||||||
strcat(cechoText, "Return to main menu to see");
|
if (loud)
|
||||||
#ifdef DEVELOP
|
{
|
||||||
// todo make debugmode
|
S_StartSound(NULL, sfx_ncitem);
|
||||||
CONS_Printf("%s\n", cechoText);
|
}
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -617,8 +614,6 @@ UINT8 M_GetNextAchievedUnlock(void)
|
||||||
{
|
{
|
||||||
UINT8 i;
|
UINT8 i;
|
||||||
|
|
||||||
M_CheckUnlockConditions();
|
|
||||||
|
|
||||||
// Go through unlockables
|
// Go through unlockables
|
||||||
for (i = 0; i < MAXUNLOCKABLES; ++i)
|
for (i = 0; i < MAXUNLOCKABLES; ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -632,7 +627,7 @@ UINT8 M_GetNextAchievedUnlock(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (M_Achieved(unlockables[i].conditionset - 1) == false)
|
if (gamedata->unlockpending[i] == false)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,7 @@ struct gamedata_t
|
||||||
|
|
||||||
// UNLOCKABLES UNLOCKED
|
// UNLOCKABLES UNLOCKED
|
||||||
boolean unlocked[MAXUNLOCKABLES];
|
boolean unlocked[MAXUNLOCKABLES];
|
||||||
|
boolean unlockpending[MAXUNLOCKABLES];
|
||||||
|
|
||||||
// CHALLENGE GRID
|
// CHALLENGE GRID
|
||||||
UINT16 challengegridwidth;
|
UINT16 challengegridwidth;
|
||||||
|
|
@ -188,7 +189,7 @@ void M_ClearSecrets(void);
|
||||||
// Updating conditions and unlockables
|
// Updating conditions and unlockables
|
||||||
void M_CheckUnlockConditions(void);
|
void M_CheckUnlockConditions(void);
|
||||||
UINT8 M_CheckCondition(condition_t *cn);
|
UINT8 M_CheckCondition(condition_t *cn);
|
||||||
boolean M_UpdateUnlockablesAndExtraEmblems(boolean silent);
|
boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud);
|
||||||
UINT8 M_GetNextAchievedUnlock(void);
|
UINT8 M_GetNextAchievedUnlock(void);
|
||||||
UINT8 M_CheckLevelEmblems(void);
|
UINT8 M_CheckLevelEmblems(void);
|
||||||
UINT8 M_CompletionEmblems(void);
|
UINT8 M_CompletionEmblems(void);
|
||||||
|
|
|
||||||
|
|
@ -7566,8 +7566,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
|
||||||
{
|
{
|
||||||
mapheaderinfo[gamemap-1]->mapvisited |= MV_VISITED;
|
mapheaderinfo[gamemap-1]->mapvisited |= MV_VISITED;
|
||||||
|
|
||||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
M_UpdateUnlockablesAndExtraEmblems(true);
|
||||||
S_StartSound(NULL, sfx_ncitem);
|
|
||||||
G_SaveGameData();
|
G_SaveGameData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2765,7 +2765,6 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec)
|
||||||
// Unlocked something?
|
// Unlocked something?
|
||||||
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
if (M_UpdateUnlockablesAndExtraEmblems(true))
|
||||||
{
|
{
|
||||||
S_StartSound(NULL, sfx_s3k68);
|
|
||||||
G_SaveGameData(); // only save if unlocked something
|
G_SaveGameData(); // only save if unlocked something
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue