1
0
Fork 0
forked from fte/fteqw

Support proquake-style loc files too. Hoepfully the heuristics to parse them will be okay...

Uses radial distance from the nearest point on the box, rather than simply the loc point, so QW logs should be unaffected, and the code doesn't really have to care whether its a box or a point.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4165 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2012-12-15 19:20:33 +00:00
parent 8ba7a5b9f7
commit 6f539b77fa

View file

@ -1247,6 +1247,13 @@ static char *TP_ParseMacroString (char *s)
case 'X': macro_string = Macro_Took(); break; case 'X': macro_string = Macro_Took(); break;
case 'y': macro_string = Macro_PointLocation(); break; case 'y': macro_string = Macro_PointLocation(); break;
case 'Y': macro_string = Macro_TookLoc(); break; case 'Y': macro_string = Macro_TookLoc(); break;
case 'n': //vicinity
case 'N': //hides from you
case 'g': //bonus timers.
case 'C': //colour
case 'z': //nearest waypoint (looking)
case 'Z': //nearest waypoint (moving)
default: default:
buf[i++] = *s++; buf[i++] = *s++;
continue; continue;
@ -1361,7 +1368,8 @@ skip:
*/ */
typedef struct locdata_s { typedef struct locdata_s {
vec3_t coord; vec3_t min;
vec3_t max;
char name[MAX_LOC_NAME]; char name[MAX_LOC_NAME];
} locdata_t; } locdata_t;
@ -1379,6 +1387,7 @@ static void TP_LoadLocFile (char *filename, qbool quiet)
int i, argc; int i, argc;
int errorcount = 0; int errorcount = 0;
locdata_t *loc; locdata_t *loc;
char *comma, *space;
if (!*filename) if (!*filename)
return; return;
@ -1387,7 +1396,8 @@ static void TP_LoadLocFile (char *filename, qbool quiet)
COM_DefaultExtension (fullpath, ".loc", sizeof(fullpath)); COM_DefaultExtension (fullpath, ".loc", sizeof(fullpath));
buf = (char *) COM_LoadTempFile (fullpath); buf = (char *) COM_LoadTempFile (fullpath);
if (!buf) { if (!buf)
{
if (!quiet) if (!quiet)
Com_Printf ("Could not load %s\n", fullpath); Com_Printf ("Could not load %s\n", fullpath);
return; return;
@ -1398,12 +1408,14 @@ static void TP_LoadLocFile (char *filename, qbool quiet)
// parse the file // parse the file
// we rely on the fact that FS_Load*File always appends a 0 at the end // we rely on the fact that FS_Load*File always appends a 0 at the end
p = buf; p = buf;
while (1) { while (1)
{
if (!*p) if (!*p)
break; // end of file break; // end of file
// get a line out // get a line out
for (i = 0; i < sizeof(line)-1; ) { for (i = 0; i < sizeof(line)-1; )
{
char c = *p++; char c = *p++;
if (!c || c == 10) if (!c || c == 10)
break; break;
@ -1412,38 +1424,113 @@ static void TP_LoadLocFile (char *filename, qbool quiet)
} }
line[i] = 0; line[i] = 0;
Cmd_TokenizeString (line, true, false); comma = strchr(line, ',');
space = strchr(line, ' ');
argc = Cmd_Argc(); if (comma && (comma < space || !space))
if (!argc) {
continue; vec3_t min, max;
min[0] = strtod(line, &comma);
if (*comma++ == ',')
{
while(*comma == ' ' || *comma == '\t')
comma++;
min[1] = strtod(comma, &comma);
if (*comma++ == ',')
{
while(*comma == ' ' || *comma == '\t')
comma++;
min[2] = strtod(comma, &comma);
if (*comma++ == ',')
{
while(*comma == ' ' || *comma == '\t')
comma++;
max[0] = strtod(comma, &comma);
if (*comma++ == ',')
{
while(*comma == ' ' || *comma == '\t')
comma++;
max[1] = strtod(comma, &comma);
if (*comma++ == ',')
{
while(*comma == ' ' || *comma == '\t')
comma++;
max[2] = strtod(comma, &comma);
if (*comma++ == ',')
{
if (loc_numentries >= MAX_LOC_ENTRIES)
continue;
loc = &locdata[loc_numentries];
loc_numentries++;
while(*comma == ' ' || *comma == '\t')
comma++;
if (*comma == '\"')
COM_ParseOut(comma, loc->name, sizeof(loc->name));
else
Q_strncpyz(loc->name, comma, sizeof(loc->name));
for (i = 0; i < 3; i++)
{
if (min[i] > max[i])
{
loc->min[i] = max[i];
loc->max[i] = min[i];
}
else
{
loc->min[i] = min[i];
loc->max[i] = max[i];
}
}
}
}
}
}
}
}
if (argc < 4) {
errorcount++; errorcount++;
continue;
} }
else
{
Cmd_TokenizeString (line, true, false);
if (atoi(Cmd_Argv(0)) == 0 && Cmd_Argv(0)[0] != '0') { argc = Cmd_Argc();
// first token is not a number if (!argc)
errorcount++; continue;
continue;
}
if (loc_numentries >= MAX_LOC_ENTRIES) if (argc < 4)
continue; {
errorcount++;
continue;
}
loc = &locdata[loc_numentries]; if (atoi(Cmd_Argv(0)) == 0 && Cmd_Argv(0)[0] != '0')
loc_numentries++; {
// first token is not a number
errorcount++;
continue;
}
for (i = 0; i < 3; i++) if (loc_numentries >= MAX_LOC_ENTRIES)
loc->coord[i] = atoi(Cmd_Argv(i)) / 8.0; continue;
loc->name[0] = 0; loc = &locdata[loc_numentries];
loc->name[sizeof(loc->name)-1] = 0; // can't rely on strncat loc_numentries++;
for (i = 3; i < argc; i++) {
if (i != 3) for (i = 0; i < 3; i++)
strncat (loc->name, " ", sizeof(loc->name)-1); loc->min[i] = loc->max[i] = atoi(Cmd_Argv(i)) / 8.0;
strncat (loc->name, Cmd_Argv(i), sizeof(loc->name)-1);
loc->name[0] = 0;
loc->name[sizeof(loc->name)-1] = 0; // can't rely on strncat
for (i = 3; i < argc; i++)
{
if (i != 3)
strncat (loc->name, " ", sizeof(loc->name)-1);
strncat (loc->name, Cmd_Argv(i), sizeof(loc->name)-1);
}
} }
} }
@ -1464,7 +1551,7 @@ static void TP_LoadLocFile_f (void)
char *TP_LocationName (vec3_t location) char *TP_LocationName (vec3_t location)
{ {
int i, minnum; int i, j, minnum;
float dist, mindist; float dist, mindist;
vec3_t vec; vec3_t vec;
static qbool recursive; static qbool recursive;
@ -1479,12 +1566,21 @@ char *TP_LocationName (vec3_t location)
minnum = 0; minnum = 0;
mindist = 9999999; mindist = 9999999;
for (i = 0; i < loc_numentries; i++) { for (i = 0; i < loc_numentries; i++)
VectorSubtract (location, locdata[i].coord, vec); {
//clip the point to the box, to find the nearest point within it.
for (j = 0; j < 3; j++)
vec[j] = bound(locdata[i].min[j], location[j], locdata[i].max[j]);
VectorSubtract (location, vec, vec);
dist = VectorLength (vec); dist = VectorLength (vec);
if (dist < mindist) { if (dist < mindist)
{
minnum = i; minnum = i;
mindist = dist; mindist = dist;
//break out if we're actually inside it, to always favour the first.
if (dist < 0.01)
break;
} }
} }
@ -1958,7 +2054,7 @@ void TP_NewMap (void)
if (strcmp(host_mapname.string, last_map)) if (strcmp(host_mapname.string, last_map))
{ // map name has changed { // map name has changed
loc_numentries = 0; // clear loc file loc_numentries = 0; // clear loc file
if (tp_loadlocs.value && cl.deathmatch && !cls.demoplayback) if (tp_loadlocs.value && cl.allocated_client_slots > 1 && !cls.demoplayback)
{ {
Q_snprintfz (locname, sizeof(locname), "%s.loc", host_mapname.string); Q_snprintfz (locname, sizeof(locname), "%s.loc", host_mapname.string);
TP_LoadLocFile (locname, true); TP_LoadLocFile (locname, true);