diff --git a/src/f_finale.c b/src/f_finale.c index fb11ee3f2..022524105 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -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 diff --git a/src/g_game.c b/src/g_game.c index 3b6e56c8d..5f5a9f8a7 100644 --- a/src/g_game.c +++ b/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); } diff --git a/src/k_menufunc.c b/src/k_menufunc.c index 6b28385dc..6a7c23007 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -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]++; diff --git a/src/k_pwrlv.c b/src/k_pwrlv.c index e4623281b..6ad088cae 100644 --- a/src/k_pwrlv.c +++ b/src/k_pwrlv.c @@ -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(); } } diff --git a/src/m_cond.c b/src/m_cond.c index b8d3c7066..38df2d4d9 100644 --- a/src/m_cond.c +++ b/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; } diff --git a/src/m_cond.h b/src/m_cond.h index dd72d5976..04be99379 100644 --- a/src/m_cond.h +++ b/src/m_cond.h @@ -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); diff --git a/src/p_setup.c b/src/p_setup.c index 3a4dd06af..e5cbba81e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -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(); } diff --git a/src/p_spec.c b/src/p_spec.c index 70450c576..4988ad881 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -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 } }