Merge branch 'tolfix' into 'master'

Don't freeslot TOL_ twice

See merge request STJr/SRB2!779
This commit is contained in:
James R 2020-02-16 23:52:45 -05:00
commit 7ed7e53c81
3 changed files with 74 additions and 58 deletions

View File

@ -585,21 +585,30 @@ static void readfreeslots(MYFILE *f)
continue; continue;
// Copy in the spr2 name and increment free_spr2. // Copy in the spr2 name and increment free_spr2.
if (free_spr2 < NUMPLAYERSPRITES) { if (free_spr2 < NUMPLAYERSPRITES) {
CONS_Printf("Sprite SPR2_%s allocated.\n",word);
strncpy(spr2names[free_spr2],word,4); strncpy(spr2names[free_spr2],word,4);
spr2defaults[free_spr2] = 0; spr2defaults[free_spr2] = 0;
spr2names[free_spr2++][4] = 0; spr2names[free_spr2++][4] = 0;
} else } else
CONS_Alert(CONS_WARNING, "Ran out of free SPR2 slots!\n"); deh_warning("Ran out of free SPR2 slots!\n");
} }
else if (fastcmp(type, "TOL")) else if (fastcmp(type, "TOL"))
{ {
if (lastcustomtol > 31) // Search if we already have a typeoflevel by that name...
CONS_Alert(CONS_WARNING, "Ran out of free typeoflevel slots!\n"); for (i = 0; TYPEOFLEVEL[i].name; i++)
if (fastcmp(word, TYPEOFLEVEL[i].name))
break;
// We found it? Then don't allocate another one.
if (TYPEOFLEVEL[i].name)
continue;
// We don't, so freeslot it.
if (lastcustomtol == (UINT32)MAXTOL) // Unless you have way too many, since they're flags.
deh_warning("Ran out of free typeoflevel slots!\n");
else else
{ {
G_AddTOL((1<<lastcustomtol), word); G_AddTOL(lastcustomtol, word);
lastcustomtol++; lastcustomtol <<= 1;
} }
} }
else else
@ -1105,38 +1114,7 @@ static void readsprite2(MYFILE *f, INT32 num)
Z_Free(s); Z_Free(s);
} }
INT32 numtolinfo = NUMBASETOL; // copypasted from readPlayer :]
UINT32 lastcustomtol = 13;
tolinfo_t TYPEOFLEVEL[NUMMAXTOL] = {
{"SOLO",TOL_SP},
{"SP",TOL_SP},
{"SINGLEPLAYER",TOL_SP},
{"SINGLE",TOL_SP},
{"COOP",TOL_COOP},
{"CO-OP",TOL_COOP},
{"COMPETITION",TOL_COMPETITION},
{"RACE",TOL_RACE},
{"MATCH",TOL_MATCH},
{"TAG",TOL_TAG},
{"CTF",TOL_CTF},
{"2D",TOL_2D},
{"MARIO",TOL_MARIO},
{"NIGHTS",TOL_NIGHTS},
{"OLDBRAK",TOL_ERZ3},
{"XMAS",TOL_XMAS},
{"CHRISTMAS",TOL_XMAS},
{"WINTER",TOL_XMAS},
{NULL, 0}
};
// copypasted from readPlayer :sleep:
static const char *const GAMETYPERULE_LIST[]; static const char *const GAMETYPERULE_LIST[];
static void readgametype(MYFILE *f, char *gtname) static void readgametype(MYFILE *f, char *gtname)
{ {
@ -10468,16 +10446,23 @@ static inline int lib_freeslot(lua_State *L)
} }
else if (fastcmp(type, "TOL")) else if (fastcmp(type, "TOL"))
{ {
if (lastcustomtol > 31) // Search if we already have a typeoflevel by that name...
CONS_Alert(CONS_WARNING, "Ran out of free typeoflevel slots!\n"); int i;
else for (i = 0; TYPEOFLEVEL[i].name; i++)
{ if (fastcmp(word, TYPEOFLEVEL[i].name))
UINT32 newtol = (1<<lastcustomtol); break;
CONS_Printf("TypeOfLevel TOL_%s allocated.\n",word);
G_AddTOL(newtol, word); // We don't, so allocate a new one.
lua_pushinteger(L, newtol); if (TYPEOFLEVEL[i].name == NULL) {
lastcustomtol++; if (lastcustomtol == (UINT32)MAXTOL) // Unless you have way too many, since they're flags.
r++; CONS_Alert(CONS_WARNING, "Ran out of free typeoflevel slots!\n");
else {
CONS_Printf("TypeOfLevel TOL_%s allocated.\n",word);
G_AddTOL(lastcustomtol, word);
lua_pushinteger(L, lastcustomtol);
lastcustomtol <<= 1;
r++;
}
} }
} }
Z_Free(s); Z_Free(s);

View File

@ -437,6 +437,7 @@ extern const char *Gametype_ConstantNames[NUMGAMETYPES];
extern INT32 pointlimits[NUMGAMETYPES]; extern INT32 pointlimits[NUMGAMETYPES];
extern INT32 timelimits[NUMGAMETYPES]; extern INT32 timelimits[NUMGAMETYPES];
// TypeOfLevel things
enum TypeOfLevel enum TypeOfLevel
{ {
TOL_SP = 0x01, ///< Single Player TOL_SP = 0x01, ///< Single Player
@ -461,16 +462,16 @@ enum TypeOfLevel
TOL_XMAS = 0x1000, ///< Christmas NiGHTS TOL_XMAS = 0x1000, ///< Christmas NiGHTS
}; };
#define NUMBASETOL 18 #define MAXTOL (1<<31)
#define NUMMAXTOL (18 + NUMGAMETYPEFREESLOTS) #define NUMBASETOLNAMES (19)
#define NUMTOLNAMES (NUMBASETOLNAMES + NUMGAMETYPEFREESLOTS)
typedef struct typedef struct
{ {
const char *name; const char *name;
UINT32 flag; UINT32 flag;
} tolinfo_t; } tolinfo_t;
extern tolinfo_t TYPEOFLEVEL[NUMMAXTOL]; extern tolinfo_t TYPEOFLEVEL[NUMTOLNAMES];
extern INT32 numtolinfo;
extern UINT32 lastcustomtol; extern UINT32 lastcustomtol;
extern tic_t totalplaytime; extern tic_t totalplaytime;

View File

@ -3384,6 +3384,36 @@ UINT32 gametypetol[NUMGAMETYPES] =
TOL_CTF, // CTF TOL_CTF, // CTF
}; };
tolinfo_t TYPEOFLEVEL[NUMTOLNAMES] = {
{"SOLO",TOL_SP},
{"SP",TOL_SP},
{"SINGLEPLAYER",TOL_SP},
{"SINGLE",TOL_SP},
{"COOP",TOL_COOP},
{"CO-OP",TOL_COOP},
{"COMPETITION",TOL_COMPETITION},
{"RACE",TOL_RACE},
{"MATCH",TOL_MATCH},
{"TAG",TOL_TAG},
{"CTF",TOL_CTF},
{"2D",TOL_2D},
{"MARIO",TOL_MARIO},
{"NIGHTS",TOL_NIGHTS},
{"OLDBRAK",TOL_ERZ3},
{"XMAS",TOL_XMAS},
{"CHRISTMAS",TOL_XMAS},
{"WINTER",TOL_XMAS},
{NULL, 0}
};
UINT32 lastcustomtol = (TOL_XMAS<<1);
// //
// G_AddTOL // G_AddTOL
// //
@ -3391,16 +3421,16 @@ UINT32 gametypetol[NUMGAMETYPES] =
// //
void G_AddTOL(UINT32 newtol, const char *tolname) void G_AddTOL(UINT32 newtol, const char *tolname)
{ {
TYPEOFLEVEL[numtolinfo].name = Z_StrDup(tolname); INT32 i;
TYPEOFLEVEL[numtolinfo].flag = newtol; for (i = 0; TYPEOFLEVEL[i].name; i++)
numtolinfo++; ;
TYPEOFLEVEL[numtolinfo].name = NULL; TYPEOFLEVEL[i].name = Z_StrDup(tolname);
TYPEOFLEVEL[numtolinfo].flag = 0; TYPEOFLEVEL[i].flag = newtol;
} }
// //
// G_AddTOL // G_AddGametypeTOL
// //
// Assigns a type of level to a gametype. // Assigns a type of level to a gametype.
// //