This is what I have done with this patch

Added editloc to change the description of the closest location
Added delloc to remove closest location
Added dumploc to place locs in memory into a .loc file (required for
editloc and delloc)
Added zdumploc to place locs in memory into a .loc.gz file (requred for
markloc, editloc and delloc)
Added loc.gz saving support to markloc, editloc and delloc (via
zdumploc)

Altered locs_load to use _Com_FOpenFile instead of Com_FOpenFile
Fixed potentual bug in locs_markloc
Fixed bug in Team_ParseSay that cause wierd behaviour if $ or % was last
charactor in line.

patch created from a development tree via diff -ur ../newtree ./
newtree and development tree were up-to-date at time of creating the
patch


Please let me know what you change so I may learn from it

Chris Ison (WildCode)
This commit is contained in:
Bill Currie 2000-12-19 19:47:15 +00:00
parent 5163916a4d
commit 0e268f9ca7
3 changed files with 148 additions and 13 deletions

View file

@ -41,5 +41,9 @@ location_t *locs_find(vec3_t target);
void locs_load(char *mapname); void locs_load(char *mapname);
void locs_reset(); void locs_reset();
void locs_add(vec3_t location, char *name); void locs_add(vec3_t location, char *name);
extern location_t **locations;
extern int locations_count;
#ifdef HAVE_ZLIB
extern int locisgz;
#endif
#endif // __locs_h #endif // __locs_h

View file

@ -45,6 +45,7 @@ location_t **locations = NULL;
int locations_alloced = 0; int locations_alloced = 0;
int locations_count = 0; int locations_count = 0;
int location_blocks = 0; int location_blocks = 0;
int locisgz = 0;
void locs_add (vec3_t location, char *name); void locs_add (vec3_t location, char *name);
void locs_load (char *mapname); void locs_load (char *mapname);
@ -99,14 +100,23 @@ locs_load (char *mapname)
char *line, *t1, *t2; char *line, *t1, *t2;
vec3_t loc; vec3_t loc;
char tmp[PATH_MAX]; char tmp[PATH_MAX];
char foundname[MAX_OSPATH];
char *tmpfndnme;
int templength = 0;
snprintf (tmp, sizeof (tmp), "maps/%s.loc", mapname); snprintf (tmp, sizeof (tmp), "maps/%s.loc", mapname);
COM_FOpenFile (tmp, &file); templength = _COM_FOpenFile (tmp, &file, foundname, 1);
if (!file) { if (!file) {
Con_Printf ("Couldn't load %s\n", tmp); Con_Printf ("Couldn't load %s\n", tmp);
return; return;
} }
#ifdef HAVE_ZLIB
tmpfndnme = foundname;
if (strncmp(tmpfndnme + strlen(foundname) - 3,".gz",3) == 0)
locisgz = 1;
else
locisgz = 0;
#endif
while ((line = Qgetline (file))) { while ((line = Qgetline (file))) {
if (line[0] == '#') if (line[0] == '#')
continue; continue;

View file

@ -46,7 +46,6 @@ cvar_t *cl_nofake;
static qboolean died = false, recorded_location = false; static qboolean died = false, recorded_location = false;
static vec3_t death_location, last_recorded_location; static vec3_t death_location, last_recorded_location;
void void
Team_BestWeaponImpulse (void) Team_BestWeaponImpulse (void)
{ {
@ -116,7 +115,7 @@ Team_ParseSay (char *s)
i = 0; i = 0;
while (*s && (i <= sizeof (buf))) { while (*s && (i <= sizeof (buf))) {
if (*s == '$') { if ((*s == '$') && (s[1] != '\0')) {
c = 0; c = 0;
switch (s[1]) { switch (s[1]) {
case '\\': case '\\':
@ -147,7 +146,7 @@ Team_ParseSay (char *s)
s += 2; s += 2;
continue; continue;
} }
} else if (*s == '%') { } else if ((*s == '%') && (s[1] != '\0')) {
t1 = NULL; t1 = NULL;
memset (t2, '\0', sizeof (t2)); memset (t2, '\0', sizeof (t2));
memset (t3, '\0', sizeof (t3)); memset (t3, '\0', sizeof (t3));
@ -336,9 +335,7 @@ Team_Init_Cvars (void)
* locs_markloc * locs_markloc
* *
* Record the current co-ords plus description into a loc file for current map * Record the current co-ords plus description into a loc file for current map
* */ */
// FIXME: No gzip'd loc file support
void void
locs_markloc () locs_markloc ()
@ -355,6 +352,12 @@ locs_markloc ()
} }
VectorCopy (cl.simorg, loc); VectorCopy (cl.simorg, loc);
locs_add (loc, Cmd_Argv (1)); locs_add (loc, Cmd_Argv (1));
#ifdef HAVE_ZLIB
if(locisgz) {
Cmd_ExecuteString ("zdumploc");
return;
}
#endif
loc[0] *= 8; loc[0] *= 8;
loc[1] *= 8; loc[1] *= 8;
loc[2] *= 8; loc[2] *= 8;
@ -363,15 +366,15 @@ locs_markloc ()
Sys_Error ("Can't duplicate mapname!"); Sys_Error ("Can't duplicate mapname!");
t1 = strrchr (mapname, '.'); t1 = strrchr (mapname, '.');
if (!t1) if (!t1)
Sys_Error ("Can't find / or .!"); Sys_Error ("Can't find .!");
t1++; // skip over / t1++; // skip over .
t1[0] = 'l'; t1[0] = 'l';
t1[1] = 'o'; t1[1] = 'o';
t1[2] = 'c'; t1[2] = 'c';
snprintf (locfile, sizeof (locfile), "%s/%s", com_gamedir, mapname); snprintf (locfile, sizeof (locfile), "%s/%s", com_gamedir, mapname);
locfd = Qopen (locfile, "a+"); locfd = Qopen (locfile, "a+");
if (locfd == 0) { if (locfd == 0) {
Qopen (locfile, "w+"); locfd = Qopen (locfile, "w+");
if (locfd == 0) { if (locfd == 0) {
Con_Printf ("ERROR: Unable to open %s : %s\n", mapname, Con_Printf ("ERROR: Unable to open %s : %s\n", mapname,
strerror (errno)); strerror (errno));
@ -382,11 +385,129 @@ locs_markloc ()
Qprintf (locfd, "%.0f %.0f %.0f %s\n", loc[0], loc[1], loc[2], Qprintf (locfd, "%.0f %.0f %.0f %s\n", loc[0], loc[1], loc[2],
Cmd_Argv (1)); Cmd_Argv (1));
Qclose (locfd); Qclose (locfd);
Con_Printf("Marked Current Location: %s\n",Cmd_Argv(1));
free (mapname); free (mapname);
} }
/*
* locs_dumploc
*
* copies the entire loc data from memory to disk
* supports zgip files via zdumploc
*/
void
locs_dumploc ()
{
char *mapname, *t1;
QFile *locfd;
char locfile[MAX_OSPATH];
int i;
if (Cmd_Argc () != 1) {
Con_Printf
("markloc <description> :marks the current location with the description and records the information into a loc file.\n");
return;
}
mapname = strdup (cl.worldmodel->name);
if (!mapname)
Sys_Error ("Can't duplicate mapname!");
t1 = strrchr (mapname, '.');
if (!t1)
Sys_Error ("Can't find .!");
t1++; // skip over .
t1[0] = 'l';
t1[1] = 'o';
t1[2] = 'c';
if (strncasecmp(Cmd_Argv(0),"dumploc",7) == 0) {
snprintf (locfile, sizeof (locfile), "%s/%s", com_gamedir, mapname);
locfd = Qopen (locfile, "w+");
#ifdef HAVE_ZLIB
} else {
snprintf (locfile, sizeof (locfile), "%s/%s.gz", com_gamedir, mapname);
locfd = Qopen (locfile, "z9w+");
#endif
}
if (locfd == 0) {
Con_Printf ("ERROR: Unable to open %s : %s\n", mapname,
strerror (errno));
free (mapname);
return;
}
for(i=0; i < locations_count ;i++)
Qprintf (locfd, "%.0f %.0f %.0f %s\n",
locations[i]->loc[0] * 8,
locations[i]->loc[1] * 8,
locations[i]->loc[2] * 8,
locations[i]->name);
Qclose (locfd);
free(mapname);
}
/*
* locs_delloc
*
* removes a loc mark from memory and file
*/
void
locs_delloc ()
{
vec3_t loc;
location_t *best = NULL, *cur;
float best_distance = 9999999, distance;
int i, j=0;
if (locations_count) {
if ((strncasecmp(Cmd_Argv(0),"editloc",7) == 0) && (Cmd_Argc () != 2)) {
Con_Printf("editloc <description> :changed the description of the nearest location marker\n");
return;
}
if ((strncasecmp(Cmd_Argv(0),"delloc",6) == 0) && (Cmd_Argc () != 1)) {
Con_Printf("delloc :removes the nearest location marker\n");
return;
}
VectorCopy (cl.simorg, loc);
for (i = 0; i < locations_count; i++) {
cur = locations[i];
distance = VectorDistance_fast (loc, cur->loc);
if ((distance < best_distance) || !best) {
best = cur;
best_distance = distance;
j = i;
}
}
if (strncasecmp(Cmd_Argv(0),"delloc",6) == 0) {
Con_Printf("Removing Location Marker for %s\n",
locations[j]->name);
free ((void *) locations[j]->name);
free ((void *) locations[j]);
locations_count--;
for (i = j; i < locations_count; i++)
locations[i] = locations[i+1];
locations[locations_count] = NULL;
} else {
Con_Printf("Changing Location Marker from %s to %s\n",
locations[j]->name,
Cmd_Argv(1));
free ((void *) locations[j]->name);
locations[j]->name = strdup (Cmd_Argv(1));
}
#ifdef HAVE_ZLIB
if (locisgz)
Cmd_ExecuteString ("zdumploc");
else
#endif
Cmd_ExecuteString ("dumploc");
}
}
void void
Locs_Init () Locs_Init ()
{ {
Cmd_AddCommand ("markloc", locs_markloc); Cmd_AddCommand ("markloc", locs_markloc);
Cmd_AddCommand ("dumploc", locs_dumploc);
#ifdef HAVE_ZLIB
Cmd_AddCommand ("zdumploc", locs_dumploc);
#endif
Cmd_AddCommand ("delloc",locs_delloc);
Cmd_AddCommand ("editloc",locs_delloc);
} }