diff --git a/src/deh_soc.c b/src/deh_soc.c index b4482daa2..a7726200c 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -2142,6 +2142,7 @@ void reademblemdata(MYFILE *f, INT32 num) else if (fastcmp(word, "MAPNAME")) { emblemlocations[num-1].level = Z_StrDup(word2); + emblemlocations[num-1].levelCache = NEXTMAP_INVALID; } else if (fastcmp(word, "SPRITE")) { diff --git a/src/m_cond.c b/src/m_cond.c index de31176ea..9c0448ba6 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -656,7 +656,7 @@ static const char *M_GetConditionString(condition_t *cn) INT32 checkLevel; i = cn->requirement-1; - checkLevel = G_MapNumber(emblemlocations[i].level); + checkLevel = M_EmblemMapNum(&emblemlocations[i]); if (checkLevel >= nummapheaders || !mapheaderinfo[checkLevel]) return va("INVALID MEDAL MAP \"%d:%d\"", cn->requirement, checkLevel); @@ -952,7 +952,7 @@ UINT8 M_CheckLevelEmblems(void) if (emblemlocations[i].type < ET_TIME || gamedata->collected[i]) continue; - checkLevel = G_MapNumber(emblemlocations[i].level); + checkLevel = M_EmblemMapNum(&emblemlocations[i]); if (checkLevel >= nummapheaders || !mapheaderinfo[checkLevel]) continue; @@ -992,7 +992,7 @@ UINT8 M_CompletionEmblems(void) // Bah! Duplication sucks, but it's for a separa if (emblemlocations[i].type < ET_TIME || gamedata->collected[i]) continue; - checkLevel = G_MapNumber(emblemlocations[i].level); + checkLevel = M_EmblemMapNum(&emblemlocations[i]); if (checkLevel >= nummapheaders || !mapheaderinfo[checkLevel]) continue; @@ -1339,7 +1339,12 @@ UINT16 M_UnlockableMapNum(unlockable_t *unlock) { if (unlock->stringVarCache == -1) { - unlock->stringVarCache = G_MapNumber(unlock->stringVar); + INT32 result = G_MapNumber(unlock->stringVar); + + if (result >= nummapheaders) + return result; + + unlock->stringVarCache = result; } return unlock->stringVarCache; @@ -1352,6 +1357,21 @@ UINT16 M_UnlockableMapNum(unlockable_t *unlock) // Misc Emblem shit // ---------------- +UINT16 M_EmblemMapNum(emblem_t *emblem) +{ + if (emblem->levelCache == NEXTMAP_INVALID) + { + UINT16 result = G_MapNumber(emblem->level); + + if (result >= nummapheaders) + return result; + + emblem->levelCache = result; + } + + return emblem->levelCache; +} + // Returns pointer to an emblem if an emblem exists for that level. // Pass -1 mapnum to continue from last emblem. // NULL if not found. @@ -1369,7 +1389,7 @@ emblem_t *M_GetLevelEmblems(INT32 mapnum) while (--i >= 0) { - INT32 checkLevel = G_MapNumber(emblemlocations[i].level); + INT32 checkLevel = M_EmblemMapNum(&emblemlocations[i]); if (checkLevel >= nummapheaders || !mapheaderinfo[checkLevel]) continue; diff --git a/src/m_cond.h b/src/m_cond.h index 045772f12..af4bd4fc8 100644 --- a/src/m_cond.h +++ b/src/m_cond.h @@ -71,7 +71,8 @@ struct emblem_t { UINT8 type; ///< Emblem type INT16 tag; ///< Tag of emblem mapthing - char * level; ///< Level on which this emblem can be found. + char *level; ///< Level on which this emblem can be found. + INT16 levelCache; ///< Stored G_MapNumber()+1 result UINT8 sprite; ///< emblem sprite to use, 0 - 25 UINT16 color; ///< skincolor to use INT32 flags; ///< GE or ME constants @@ -229,5 +230,6 @@ cupheader_t *M_UnlockableCup(unlockable_t *unlock); UINT16 M_UnlockableMapNum(unlockable_t *unlock); INT32 M_EmblemSkinNum(emblem_t *emblem); +UINT16 M_EmblemMapNum(emblem_t *emblem); #define M_Achieved(a) ((a) >= MAXCONDITIONSETS || gamedata->achieved[a])