Skip to content

Commit

Permalink
Add Single Player > Levels menu
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Sep 12, 2022
1 parent 84c64f6 commit 7e9ad54
Show file tree
Hide file tree
Showing 10 changed files with 1,051 additions and 72 deletions.
1 change: 1 addition & 0 deletions Misc/pak/Makefile
@@ -1,6 +1,7 @@
INPUT := gfx/conback.lmp \
gfx/menumods.lmp \
gfx/skillmenu.lmp \
gfx/sp_maps.lmp \
default.cfg

OUTPUT := ironwail.pak
Expand Down
Binary file added Misc/pak/gfx/sp_maps.lmp
Binary file not shown.
2 changes: 2 additions & 0 deletions Quake/cl_main.c
Expand Up @@ -55,6 +55,7 @@ cvar_t cl_startdemos = {"cl_startdemos", "1", CVAR_ARCHIVE};
cvar_t cl_confirmquit = {"cl_confirmquit", "0", CVAR_ARCHIVE};

cvar_t cl_mousemenu = {"cl_mousemenu", "1", CVAR_ARCHIVE};
cvar_t cl_menusearchtimeout = {"cl_menusearchtimeout", "1", CVAR_ARCHIVE};

client_static_t cls;
client_state_t cl;
Expand Down Expand Up @@ -969,6 +970,7 @@ void CL_Init (void)
Cvar_RegisterVariable (&cl_confirmquit);

Cvar_RegisterVariable (&cl_mousemenu);
Cvar_RegisterVariable (&cl_menusearchtimeout);

Cmd_AddCommand ("entities", CL_PrintEntities_f);
Cmd_AddCommand ("disconnect", CL_Disconnect_f);
Expand Down
133 changes: 133 additions & 0 deletions Quake/gl_model.c
Expand Up @@ -2408,6 +2408,139 @@ void Mod_LoadBrushModel (qmodel_t *mod, void *buffer)
}
}

/*
=================
Mod_LoadMapDescription
Parses the entity lump in the given map to find its worldspawn message
Writes at most maxchars bytes to dest, including the NUL terminator
Returns true if map is playable, false otherwise
=================
*/
qboolean Mod_LoadMapDescription (char *desc, size_t maxchars, const char *map)
{
static char buf[16 * 1024];
char path[MAX_QPATH];
const char *data;
FILE *f;
lump_t *entlump;
dheader_t header;
int i, filesize;
qboolean ret = false;

if (!maxchars)
return false;
*desc = '\0';

if ((size_t) q_snprintf (path, sizeof (path), "maps/%s.bsp", map) >= sizeof (path))
return false;

filesize = COM_FOpenFile (path, &f, NULL);
if (filesize <= sizeof (header))
return false;

if (fread (&header, sizeof (header), 1, f) != 1)
{
fclose (f);
return false;
}

header.version = LittleLong (header.version);

switch (header.version)
{
case BSPVERSION:
case BSP2VERSION_2PSB:
case BSP2VERSION_BSP2:
case BSPVERSION_QUAKE64:
break;
default:
fclose (f);
return false;
}

for (i = 1; i < (int) (sizeof (header) / sizeof (int)); i++)
((int *)&header)[i] = LittleLong ( ((int *)&header)[i]);

entlump = &header.lumps[LUMP_ENTITIES];
if (entlump->filelen < 0 || entlump->filelen >= filesize ||
entlump->fileofs < 0 || entlump->fileofs + entlump->filelen > filesize)
{
fclose (f);
return false;
}

// if the entity lump is large enough we assume the map is playable
// and only try to parse the first entity (worldspawn) for the map title
if (entlump->filelen >= sizeof (buf))
{
ret = true;
entlump->filelen = sizeof (buf) - 1;
}

fseek (f, entlump->fileofs - sizeof (header), SEEK_CUR);
i = fread (buf, 1, entlump->filelen, f);
fclose (f);

if (i <= 0)
return false;
buf[i] = '\0';

for (i = 0, data = buf; data; i++)
{
data = COM_Parse (data);
if (!data || com_token[0] != '{')
return ret;

while (1)
{
qboolean is_message;
qboolean is_classname;

// parse key
data = COM_Parse (data);
if (!data)
return ret;
if (com_token[0] == '}')
break;

is_message = i == 0 && !strcmp (com_token, "message");
is_classname = i != 0 && !strcmp (com_token, "classname");

// parse value
data = COM_Parse (data);
if (!data)
return ret;

if (is_message)
{
q_strlcpy (desc, com_token, maxchars);
if (ret)
return true;
}
else if (is_classname)
{
#define CLASSNAME_STARTS_WITH(str) (!strncmp (com_token, str, strlen (str)))
#define CLASSNAME_IS(str) (!strcmp (com_token, str))

if (CLASSNAME_STARTS_WITH ("info_player_") ||
CLASSNAME_STARTS_WITH ("ammo_") ||
CLASSNAME_STARTS_WITH ("weapon_") ||
CLASSNAME_STARTS_WITH ("monster_") ||
CLASSNAME_IS ("trigger_changelevel"))
{
return true;
}

#undef CLASSNAME_IS
#undef CLASSNAME_STARTS_WITH
}
}
}

return ret;
}

/*
==============================================================================
Expand Down
1 change: 1 addition & 0 deletions Quake/gl_model.h
Expand Up @@ -525,5 +525,6 @@ byte *Mod_LeafPVS (mleaf_t *leaf, qmodel_t *model);
byte *Mod_NoVisPVS (qmodel_t *model);

void Mod_SetExtraFlags (qmodel_t *mod);
qboolean Mod_LoadMapDescription (char *desc, size_t maxchars, const char *map);

#endif // __MODEL__

0 comments on commit 7e9ad54

Please sign in to comment.