diff options
Diffstat (limited to 'src/cl_locs.c')
-rw-r--r-- | src/cl_locs.c | 170 |
1 files changed, 89 insertions, 81 deletions
diff --git a/src/cl_locs.c b/src/cl_locs.c index 31c842d..05b9b99 100644 --- a/src/cl_locs.c +++ b/src/cl_locs.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -30,7 +30,7 @@ typedef struct { char name[1]; } location_t; -static LIST_DECL( cl_locations ); +static LIST_DECL(cl_locations); static cvar_t *loc_draw; static cvar_t *loc_trace; @@ -41,17 +41,18 @@ static cvar_t *loc_dist; LOC_Alloc ============== */ -static location_t *LOC_Alloc( const char *name ) { +static location_t *LOC_Alloc(const char *name) +{ location_t *loc; char buffer[MAX_QPATH]; size_t len; - Q_strlcpy( buffer, name, sizeof( buffer ) ); - len = COM_strclr( buffer ); + Q_strlcpy(buffer, name, sizeof(buffer)); + len = COM_strclr(buffer); - loc = Z_Malloc( sizeof( *loc ) + len ); - memcpy( loc->name, buffer, len + 1 ); - List_Append( &cl_locations, &loc->entry ); + loc = Z_Malloc(sizeof(*loc) + len); + memcpy(loc->name, buffer, len + 1); + List_Append(&cl_locations, &loc->entry); return loc; } @@ -61,7 +62,8 @@ static location_t *LOC_Alloc( const char *name ) { LOC_LoadLocations ============== */ -void LOC_LoadLocations( void ) { +void LOC_LoadLocations(void) +{ char path[MAX_OSPATH]; char *buffer, *s, *p; int line, count; @@ -70,48 +72,48 @@ void LOC_LoadLocations( void ) { qerror_t ret; // load from main directory - Q_concat( path, sizeof( path ), "locs/", cl.mapname, ".loc", NULL ); + Q_concat(path, sizeof(path), "locs/", cl.mapname, ".loc", NULL); - ret = FS_LoadFile( path, (void **)&buffer ); - if( !buffer ) { - if( ret != Q_ERR_NOENT ) { - Com_EPrintf( "Couldn't load %s: %s\n", path, Q_ErrorString( ret ) ); + ret = FS_LoadFile(path, (void **)&buffer); + if (!buffer) { + if (ret != Q_ERR_NOENT) { + Com_EPrintf("Couldn't load %s: %s\n", path, Q_ErrorString(ret)); } return; } s = buffer; line = count = 0; - while( *s ) { - p = strchr( s, '\n' ); - if( p ) { + while (*s) { + p = strchr(s, '\n'); + if (p) { *p = 0; } - Cmd_TokenizeString( s, qfalse ); + Cmd_TokenizeString(s, qfalse); line++; argc = Cmd_Argc(); - if( argc != 0 && argc < 4 ) { - Com_WPrintf( "Line %i is incomplete in %s\n", line, path ); + if (argc != 0 && argc < 4) { + Com_WPrintf("Line %i is incomplete in %s\n", line, path); } else { - loc = LOC_Alloc( Cmd_RawArgsFrom( 3 ) ); - loc->origin[0] = atof( Cmd_Argv( 0 ) ) * 0.125f; - loc->origin[1] = atof( Cmd_Argv( 1 ) ) * 0.125f; - loc->origin[2] = atof( Cmd_Argv( 2 ) ) * 0.125f; + loc = LOC_Alloc(Cmd_RawArgsFrom(3)); + loc->origin[0] = atof(Cmd_Argv(0)) * 0.125f; + loc->origin[1] = atof(Cmd_Argv(1)) * 0.125f; + loc->origin[2] = atof(Cmd_Argv(2)) * 0.125f; count++; } - if( !p ) { + if (!p) { break; } s = p + 1; } - Com_DPrintf( "Loaded %i locations from %s\n", count, path ); + Com_DPrintf("Loaded %i locations from %s\n", count, path); - FS_FreeFile( buffer ); + FS_FreeFile(buffer); } /* @@ -119,13 +121,14 @@ void LOC_LoadLocations( void ) { LOC_FreeLocations ============== */ -void LOC_FreeLocations( void ) { +void LOC_FreeLocations(void) +{ location_t *loc, *next; - LIST_FOR_EACH_SAFE( location_t, loc, next, &cl_locations, entry ) { - Z_Free( loc ); + LIST_FOR_EACH_SAFE(location_t, loc, next, &cl_locations, entry) { + Z_Free(loc); } - List_Init( &cl_locations ); + List_Init(&cl_locations); } /* @@ -133,7 +136,8 @@ void LOC_FreeLocations( void ) { LOC_FindClosest ============== */ -static location_t *LOC_FindClosest( vec3_t pos ) { +static location_t *LOC_FindClosest(vec3_t pos) +{ location_t *loc, *nearest; vec3_t dir; float dist, minDist; @@ -141,23 +145,23 @@ static location_t *LOC_FindClosest( vec3_t pos ) { minDist = 99999; nearest = NULL; - LIST_FOR_EACH( location_t, loc, &cl_locations, entry ) { - VectorSubtract( pos, loc->origin, dir ); - dist = VectorLength( dir ); + LIST_FOR_EACH(location_t, loc, &cl_locations, entry) { + VectorSubtract(pos, loc->origin, dir); + dist = VectorLength(dir); - if( dist > loc_dist->value ) { + if (dist > loc_dist->value) { continue; } - if( loc_trace->integer ) { - CM_BoxTrace( &trace, pos, loc->origin, vec3_origin, vec3_origin, - cl.bsp->nodes, MASK_SOLID ); - if( trace.fraction != 1.0f ) { + if (loc_trace->integer) { + CM_BoxTrace(&trace, pos, loc->origin, vec3_origin, vec3_origin, + cl.bsp->nodes, MASK_SOLID); + if (trace.fraction != 1.0f) { continue; } } - - if( dist < minDist ) { + + if (dist < minDist) { minDist = dist; nearest = loc; } @@ -171,41 +175,42 @@ static location_t *LOC_FindClosest( vec3_t pos ) { LOC_AddLocationsToScene ============== */ -void LOC_AddLocationsToScene( void ) { +void LOC_AddLocationsToScene(void) +{ location_t *loc, *nearest; vec3_t dir; float dist; entity_t ent; - if( !loc_draw->integer ) { + if (!loc_draw->integer) { return; } - memset( &ent, 0, sizeof( ent ) ); - ent.model = R_RegisterModel( "models/items/c_head/tris.md2" ); - ent.skin = R_RegisterSkin( "models/items/c_head/skin.pcx" ); + memset(&ent, 0, sizeof(ent)); + ent.model = R_RegisterModel("models/items/c_head/tris.md2"); + ent.skin = R_RegisterSkin("models/items/c_head/skin.pcx"); - nearest = LOC_FindClosest( cl.playerEntityOrigin ); - if( !nearest ) { + nearest = LOC_FindClosest(cl.playerEntityOrigin); + if (!nearest) { return; } - LIST_FOR_EACH( location_t, loc, &cl_locations, entry ) { - VectorSubtract( cl.playerEntityOrigin, loc->origin, dir ); - dist = VectorLength( dir ); + LIST_FOR_EACH(location_t, loc, &cl_locations, entry) { + VectorSubtract(cl.playerEntityOrigin, loc->origin, dir); + dist = VectorLength(dir); - if( dist > loc_dist->integer ) { + if (dist > loc_dist->integer) { continue; } - VectorCopy( loc->origin, ent.origin ); + VectorCopy(loc->origin, ent.origin); - if( loc == nearest ) { - ent.origin[2] += 10.0f * sin( cl.time * 0.01f ); - V_AddLight( loc->origin, 200, 1, 1, 1 ); + if (loc == nearest) { + ent.origin[2] += 10.0f * sin(cl.time * 0.01f); + V_AddLight(loc->origin, 200, 1, 1, 1); } - V_AddEntity( &ent ); + V_AddEntity(&ent); } @@ -216,18 +221,19 @@ void LOC_AddLocationsToScene( void ) { LOC_Here_m ============== */ -static size_t LOC_Here_m( char *buffer, size_t size ) { +static size_t LOC_Here_m(char *buffer, size_t size) +{ location_t *loc; size_t ret; - ret = Q_strlcpy( buffer, "unknown", size ); - if( cls.state != ca_active ) { + ret = Q_strlcpy(buffer, "unknown", size); + if (cls.state != ca_active) { return ret; } - loc = LOC_FindClosest( cl.playerEntityOrigin ); - if( loc ) { - ret = Q_strlcpy( buffer, loc->name, size ); + loc = LOC_FindClosest(cl.playerEntityOrigin); + if (loc) { + ret = Q_strlcpy(buffer, loc->name, size); } return ret; } @@ -237,24 +243,25 @@ static size_t LOC_Here_m( char *buffer, size_t size ) { LOC_There_m ============== */ -static size_t LOC_There_m( char *buffer, size_t size ) { +static size_t LOC_There_m(char *buffer, size_t size) +{ location_t *loc; vec3_t pos; trace_t trace; int ret; - ret = Q_strlcpy( buffer, "unknown", size ); - if( cls.state != ca_active ) { + ret = Q_strlcpy(buffer, "unknown", size); + if (cls.state != ca_active) { return ret; } - VectorMA( cl.playerEntityOrigin, 8192, cl.v_forward, pos ); - CM_BoxTrace( &trace, cl.playerEntityOrigin, pos, vec3_origin, vec3_origin, - cl.bsp->nodes, MASK_SOLID ); + VectorMA(cl.playerEntityOrigin, 8192, cl.v_forward, pos); + CM_BoxTrace(&trace, cl.playerEntityOrigin, pos, vec3_origin, vec3_origin, + cl.bsp->nodes, MASK_SOLID); - loc = LOC_FindClosest( trace.endpos ); - if( loc ) { - ret = Q_strlcpy( buffer, loc->name, size ); + loc = LOC_FindClosest(trace.endpos); + if (loc) { + ret = Q_strlcpy(buffer, loc->name, size); } return ret; } @@ -264,13 +271,14 @@ static size_t LOC_There_m( char *buffer, size_t size ) { LOC_Init ============== */ -void LOC_Init( void ) { -// loc_enable = Cvar_Get( "loc_enable", "0", 0 ); - loc_trace = Cvar_Get( "loc_trace", "0", 0 ); - loc_draw = Cvar_Get( "loc_draw", "0", 0 ); - loc_dist = Cvar_Get( "loc_dist", "500", 0 ); - - Cmd_AddMacro( "loc_here", LOC_Here_m ); - Cmd_AddMacro( "loc_there", LOC_There_m ); +void LOC_Init(void) +{ +// loc_enable = Cvar_Get("loc_enable", "0", 0); + loc_trace = Cvar_Get("loc_trace", "0", 0); + loc_draw = Cvar_Get("loc_draw", "0", 0); + loc_dist = Cvar_Get("loc_dist", "500", 0); + + Cmd_AddMacro("loc_here", LOC_Here_m); + Cmd_AddMacro("loc_there", LOC_There_m); } |