PDA

View Full Version : getting a map size


theturtle
04-10-2004, 17:35
hello all

i'd like to get the size of a map (in counter strike, but i don't think it is mod specific...).
that is to say i'd like to code (or use somebody's code) to make something like that :
int map_height = getCurrentMapHeight();
int map_width = getCurrentMapWidth();

does someone has an idea on how to do this ? or do someone has a piece of code which does it ?
thanks

Pierre-Marie Baty
04-10-2004, 19:56
yep

The map size is the size of the bounding box of the first entity (worldspawn) in the BSP file.

void LookDownOnTheWorld (void)
{
// this function loads and interprets the map BSP file at server boot start. It opens the map
// file named filename, reads its contents, parses through the different BSP lumps and fills
// the map BSP data structure "map", so that we can access to much more geometric info about
// the virtual world than the engine would lets us know normally. The BSP loading code comes
// with heavy simplification and major rewriting from Zoner's Half-Life tools source code.

char bsp_file_path[256];
char *mfile;
int bsp_file_size;

// do some cleanup first
FreeMapData ();
memset (&bsp_file, 0, sizeof (bsp_file));
memset (&map, 0, sizeof (map));

// load the bsp file and get its actual size (can't fail to do this, the map already booted)
sprintf (bsp_file_path, "maps/%s.bsp", server.map_name); // build BSP file path
mfile = (char *) LOAD_FILE_FOR_ME (bsp_file_path, &bsp_file_size); // load bsp file

// read the MODELS, VERTEXES, PLANES, FACES, SURFEDGES and EDGES lumps of the BSP file
memcpy (bsp_file.dmodels, mfile + ((bsp_dheader_t *) mfile)->lumps[LUMP_MODELS].fileofs, ((bsp_dheader_t *) mfile)->lumps[LUMP_MODELS].filelen);
memcpy (bsp_file.dvertexes, mfile + ((bsp_dheader_t *) mfile)->lumps[LUMP_VERTEXES].fileofs, ((bsp_dheader_t *) mfile)->lumps[LUMP_VERTEXES].filelen);
memcpy (bsp_file.dplanes, mfile + ((bsp_dheader_t *) mfile)->lumps[LUMP_PLANES].fileofs, ((bsp_dheader_t *) mfile)->lumps[LUMP_PLANES].filelen);
memcpy (bsp_file.dfaces, mfile + ((bsp_dheader_t *) mfile)->lumps[LUMP_FACES].fileofs, ((bsp_dheader_t *) mfile)->lumps[LUMP_FACES].filelen);
memcpy (bsp_file.dsurfedges, mfile + ((bsp_dheader_t *) mfile)->lumps[LUMP_SURFEDGES].fileofs, ((bsp_dheader_t *) mfile)->lumps[LUMP_SURFEDGES].filelen);
memcpy (bsp_file.dedges, mfile + ((bsp_dheader_t *) mfile)->lumps[LUMP_EDGES].fileofs, ((bsp_dheader_t *) mfile)->lumps[LUMP_EDGES].filelen);

FREE_FILE (mfile); // everything is loaded, free the BSP file

// get a quick access to the world's bounding box
map.v_worldmins = bsp_file.dmodels[0].mins;
map.v_worldmaxs = bsp_file.dmodels[0].maxs;

[...]


WHAT THE HELL DID THE ADMINS DO TO MY [ CODE ] TAGS ????
:'(