codemp/game/g_nav.c

Go to the documentation of this file.
00001 #include "b_local.h"
00002 #include "g_nav.h"
00003 
00004 extern qboolean G_EntIsUnlockedDoor( int entityNum );
00005 extern qboolean G_EntIsDoor( int entityNum );
00006 extern qboolean G_EntIsBreakable( int entityNum );
00007 extern qboolean G_EntIsRemovableUsable( int entNum );
00008 extern qboolean G_FindClosestPointOnLineSegment( const vec3_t start, const vec3_t end, const vec3_t from, vec3_t result );
00009 //For debug graphics
00010 //rwwFIXMEFIXME: Write these at some point for the sake of being able to debug visually
00011 void G_Line( vec3_t start, vec3_t end, vec3_t color, float alpha )
00012 {
00013 
00014 }
00015 
00016 void G_Cube( vec3_t mins, vec3_t maxs, vec3_t color, float alpha )
00017 {
00018 
00019 }
00020 
00021 void G_CubeOutline( vec3_t mins, vec3_t maxs, int time, unsigned int color, float alpha )
00022 {
00023 
00024 }
00025 
00026 void G_DrawEdge( vec3_t start, vec3_t end, int type )
00027 {
00028 
00029 }
00030 
00031 void G_DrawNode( vec3_t origin, int type )
00032 {
00033 
00034 }
00035 
00036 void G_DrawCombatPoint( vec3_t origin, int type )
00037 {
00038 
00039 }
00040 
00041 void TAG_ShowTags( int flags )
00042 {
00043 
00044 }
00045 
00046 qboolean FlyingCreature( gentity_t *ent )
00047 {
00048         if (ent->client && ent->client->ps.gravity <= 0)
00049         {
00050                 return qtrue;
00051         }
00052         return qfalse;
00053 }
00054 
00055 qboolean NAV_CheckAhead( gentity_t *self, vec3_t end, trace_t *trace, int clipmask );
00056 void NAV_StoreWaypoint( gentity_t *ent );
00057 
00058 extern vec3_t NPCDEBUG_RED;
00059 
00060 
00061 /*
00062 -------------------------
00063 NPC_Blocked
00064 -------------------------
00065 */
00066 
00067 
00068 void NPC_Blocked( gentity_t *self, gentity_t *blocker )
00069 {
00070         if ( self->NPC == NULL )
00071                 return;
00072 
00073         //Don't do this too often
00074         if ( self->NPC->blockedSpeechDebounceTime > level.time )
00075                 return;
00076 
00077         //Attempt to run any blocked scripts
00078         if ( G_ActivateBehavior( self, BSET_BLOCKED ) )
00079         {
00080                 return;
00081         }
00082 
00083         //If this is one of our enemies, then just attack him
00084         if ( blocker->client && ( blocker->client->playerTeam == self->client->enemyTeam ) )
00085         {
00086                 G_SetEnemy( self, blocker );
00087                 return;
00088         }
00089 
00090         //Debug_Printf( debugNPCAI, DEBUG_LEVEL_WARNING, "%s: Excuse me, %s %s!\n", self->targetname, blocker->classname, blocker->targetname );
00091         
00092         //If we're being blocked by the player, say something to them
00093         if ( ( blocker->s.number == 0 ) && ( ( blocker->client->playerTeam == self->client->playerTeam ) ) )
00094         {
00095                 //guys in formation are not trying to get to a critical point, 
00096                 //don't make them yell at the player (unless they have an enemy and
00097                 //are in combat because BP thinks it sounds cool during battle)
00098                 //NOTE: only imperials, misc crewmen and hazard team have these wav files now
00099                 //G_AddVoiceEvent( self, Q_irand(EV_BLOCKED1, EV_BLOCKED3), 0 );
00100         }
00101 
00102         self->NPC->blockedSpeechDebounceTime = level.time + MIN_BLOCKED_SPEECH_TIME + ( random() * 4000 );
00103         self->NPC->blockingEntNum = blocker->s.number;
00104 }
00105 
00106 /*
00107 -------------------------
00108 NPC_SetMoveGoal
00109 -------------------------
00110 */
00111 
00112 void NPC_SetMoveGoal( gentity_t *ent, vec3_t point, int radius, qboolean isNavGoal, int combatPoint, gentity_t *targetEnt )
00113 {
00114         //Must be an NPC
00115         if ( ent->NPC == NULL )
00116         {
00117                 return;
00118         }
00119 
00120         if ( ent->NPC->tempGoal == NULL )
00121         {//must still have a goal
00122                 return;
00123         }
00124 
00125         //Copy the origin
00126         //VectorCopy( point, ent->NPC->goalPoint );     //FIXME: Make it use this, and this alone!
00127         VectorCopy( point, ent->NPC->tempGoal->r.currentOrigin );
00128         
00129         //Copy the mins and maxs to the tempGoal
00130         VectorCopy( ent->r.mins, ent->NPC->tempGoal->r.mins );
00131         VectorCopy( ent->r.mins, ent->NPC->tempGoal->r.maxs );
00132 
00133         ent->NPC->tempGoal->target = NULL;
00134         ent->NPC->tempGoal->clipmask = ent->clipmask;
00135         ent->NPC->tempGoal->flags &= ~FL_NAVGOAL;
00136         if ( targetEnt && targetEnt->waypoint >= 0 )
00137         {
00138                 ent->NPC->tempGoal->waypoint = targetEnt->waypoint;
00139         }
00140         else
00141         {
00142                 ent->NPC->tempGoal->waypoint = WAYPOINT_NONE;
00143         }
00144         ent->NPC->tempGoal->noWaypointTime = 0;
00145 
00146         if ( isNavGoal )
00147         {
00148                 assert(ent->NPC->tempGoal->parent);
00149                 ent->NPC->tempGoal->flags |= FL_NAVGOAL;
00150         }
00151 
00152         ent->NPC->tempGoal->combatPoint = combatPoint;
00153         ent->NPC->tempGoal->enemy = targetEnt;
00154 
00155         ent->NPC->goalEntity = ent->NPC->tempGoal;
00156         ent->NPC->goalRadius = radius;
00157 
00158         trap_LinkEntity( ent->NPC->goalEntity );
00159 }
00160 
00161 /*
00162 -------------------------
00163 NAV_HitNavGoal
00164 -------------------------
00165 */
00166 
00167 qboolean NAV_HitNavGoal( vec3_t point, vec3_t mins, vec3_t maxs, vec3_t dest, int radius, qboolean flying )
00168 {
00169         vec3_t  dmins, dmaxs, pmins, pmaxs;
00170 
00171         if ( radius & NAVGOAL_USE_RADIUS )
00172         {
00173                 radius &= ~NAVGOAL_USE_RADIUS;
00174                 //NOTE:  This needs to do a DistanceSquared on navgoals that had
00175                 //                      a radius manually set! We can't do the smaller navgoals against
00176                 //                      walls to get around this because player-sized traces to them
00177                 //                      from angles will not work... - MCG
00178                 if ( !flying )
00179                 {//Allow for a little z difference
00180                         vec3_t  diff;
00181                         VectorSubtract( point, dest, diff );
00182                         if ( fabs(diff[2]) <= 24 )
00183                         {
00184                                 diff[2] = 0;
00185                         }
00186                         return ( VectorLengthSquared( diff ) <= (radius*radius) );
00187                 }
00188                 else
00189                 {//must hit exactly
00190                         return ( DistanceSquared(dest, point) <= (radius*radius) );
00191                 }
00192                 //There is probably a better way to do this, either by preserving the original
00193                 //              mins and maxs of the navgoal and doing this check ONLY if the radius 
00194                 //              is non-zero (like the original implementation) or some boolean to
00195                 //              tell us to do this check rather than the fake bbox overlap check...
00196         }
00197         else
00198         {
00199                 //Construct a dummy bounding box from our radius value
00200                 VectorSet( dmins, -radius, -radius, -radius );
00201                 VectorSet( dmaxs,  radius,  radius,  radius );
00202 
00203                 //Translate it
00204                 VectorAdd( dmins, dest, dmins );
00205                 VectorAdd( dmaxs, dest, dmaxs );
00206 
00207                 //Translate the starting box
00208                 VectorAdd( point, mins, pmins );
00209                 VectorAdd( point, maxs, pmaxs );
00210 
00211                 //See if they overlap
00212                 return G_BoundsOverlap( pmins, pmaxs, dmins, dmaxs );
00213         }
00214 }
00215 
00216 /*
00217 -------------------------
00218 NAV_ClearPathToPoint
00219 -------------------------
00220 */
00221 
00222 qboolean NAV_ClearPathToPoint( gentity_t *self, vec3_t pmins, vec3_t pmaxs, vec3_t point, int clipmask, int okToHitEntNum )
00223 {
00224 //      trace_t trace;
00225 //      return NAV_CheckAhead( self, point, trace, clipmask|CONTENTS_BOTCLIP );
00226 
00227         vec3_t  mins, maxs;
00228         trace_t trace;
00229 
00230         //Test if they're even conceivably close to one another
00231         if ( !trap_InPVS( self->r.currentOrigin, point ) )
00232                 return qfalse;
00233 
00234         if ( self->flags & FL_NAVGOAL )
00235         {
00236                 if ( !self->parent )
00237                 {
00238                         //SHOULD NEVER HAPPEN!!!
00239                         assert(self->parent);
00240                         return qfalse;
00241                 }
00242                 VectorCopy( self->parent->r.mins, mins );
00243                 VectorCopy( self->parent->r.maxs, maxs );
00244         }
00245         else
00246         {
00247                 VectorCopy( pmins, mins );
00248                 VectorCopy( pmaxs, maxs );
00249         }
00250         
00251         if ( self->client || ( self->flags & FL_NAVGOAL ) )
00252         {
00253                 //Clients can step up things, or if this is a navgoal check, a client will be using this info
00254                 mins[2] += STEPSIZE;
00255 
00256                 //don't let box get inverted
00257                 if ( mins[2] > maxs[2] )
00258                 {       
00259                         mins[2] = maxs[2];
00260                 }
00261         }
00262 
00263         if ( self->flags & FL_NAVGOAL )
00264         {
00265                 //Trace from point to navgoal
00266                 trap_Trace( &trace, point, mins, maxs, self->r.currentOrigin, self->parent->s.number, (clipmask|CONTENTS_MONSTERCLIP|CONTENTS_BOTCLIP)&~CONTENTS_BODY );
00267                 if ( trace.startsolid&&(trace.contents&CONTENTS_BOTCLIP) )
00268                 {//started inside do not enter, so ignore them
00269                         clipmask &= ~CONTENTS_BOTCLIP;
00270                         trap_Trace( &trace, point, mins, maxs, self->r.currentOrigin, self->parent->s.number, (clipmask|CONTENTS_MONSTERCLIP)&~CONTENTS_BODY );
00271                 }
00272                 
00273                 if ( trace.startsolid || trace.allsolid )
00274                 {
00275                         return qfalse;
00276                 }
00277                 
00278                 //Made it
00279                 if ( trace.fraction == 1.0 )
00280                 {
00281                         return qtrue;
00282                 }
00283                 
00284                 if ( okToHitEntNum != ENTITYNUM_NONE && trace.entityNum == okToHitEntNum )
00285                 {
00286                         return qtrue;
00287                 }
00288 
00289                 //Okay, didn't get all the way there, let's see if we got close enough:
00290                 if ( NAV_HitNavGoal( self->r.currentOrigin, self->parent->r.mins, self->parent->r.maxs, trace.endpos, NPCInfo->goalRadius, FlyingCreature( self->parent ) ) )
00291                 {
00292                         return qtrue;
00293                 }
00294                 else
00295                 {
00296                         if ( NAVDEBUG_showCollision )
00297                         {
00298                                 if ( trace.entityNum < ENTITYNUM_WORLD && (&g_entities[trace.entityNum] != NULL) && g_entities[trace.entityNum].s.eType != ET_MOVER )
00299                                 {
00300                                         vec3_t  p1, p2;
00301                                         G_DrawEdge( point, trace.endpos, EDGE_PATH );
00302                                         VectorAdd(g_entities[trace.entityNum].r.mins, g_entities[trace.entityNum].r.currentOrigin, p1);
00303                                         VectorAdd(g_entities[trace.entityNum].r.maxs, g_entities[trace.entityNum].r.currentOrigin, p2);
00304                                         G_CubeOutline( p1, p2, FRAMETIME, 0x0000ff, 0.5 );
00305                                 }
00306                                 //FIXME: if it is a bmodel, light up the surf?
00307                         }
00308                 }
00309         }
00310         else
00311         {
00312                 trap_Trace( &trace, self->r.currentOrigin, mins, maxs, point, self->s.number, clipmask|CONTENTS_MONSTERCLIP|CONTENTS_BOTCLIP);
00313                 if ( trace.startsolid&&(trace.contents&CONTENTS_BOTCLIP) )
00314                 {//started inside do not enter, so ignore them
00315                         clipmask &= ~CONTENTS_BOTCLIP;
00316                         trap_Trace( &trace, self->r.currentOrigin, mins, maxs, point, self->s.number, clipmask|CONTENTS_MONSTERCLIP);
00317                 }
00318 
00319                 if( ( ( trace.startsolid == qfalse ) && ( trace.allsolid == qfalse ) ) && ( trace.fraction == 1.0f ) )
00320                 {//FIXME: check for drops
00321                         return qtrue;
00322                 }
00323 
00324                 if ( okToHitEntNum != ENTITYNUM_NONE && trace.entityNum == okToHitEntNum )
00325                 {
00326                         return qtrue;
00327                 }
00328 
00329                 if ( NAVDEBUG_showCollision )
00330                 {
00331                         if ( trace.entityNum < ENTITYNUM_WORLD && (&g_entities[trace.entityNum] != NULL) && g_entities[trace.entityNum].s.eType != ET_MOVER )
00332                         {
00333                                 vec3_t  p1, p2;
00334                                 G_DrawEdge( self->r.currentOrigin, trace.endpos, EDGE_PATH );
00335                                 VectorAdd(g_entities[trace.entityNum].r.mins, g_entities[trace.entityNum].r.currentOrigin, p1);
00336                                 VectorAdd(g_entities[trace.entityNum].r.maxs, g_entities[trace.entityNum].r.currentOrigin, p2);
00337                                 G_CubeOutline( p1, p2, FRAMETIME, 0x0000ff, 0.5 );
00338                         }
00339                         //FIXME: if it is a bmodel, light up the surf?
00340                 }
00341         }
00342 
00343         return qfalse;
00344 }
00345 
00346 /*
00347 -------------------------
00348 NAV_FindClosestWaypointForEnt
00349 -------------------------
00350 */
00351 
00352 int NAV_FindClosestWaypointForEnt( gentity_t *ent, int targWp )
00353 {
00354         //FIXME: Take the target into account
00355         return trap_Nav_GetNearestNode( ent, ent->waypoint, NF_CLEAR_PATH, targWp );
00356 }
00357 
00358 int NAV_FindClosestWaypointForPoint( gentity_t *ent, vec3_t point )
00359 {
00360         int     bestWP;
00361         //FIXME: can we make this a static ent?
00362         gentity_t *marker = G_Spawn();
00363         
00364         if ( !marker )
00365         {
00366                 return WAYPOINT_NONE;
00367         }
00368 
00369         G_SetOrigin( marker, point );
00370 
00371         VectorCopy( ent->r.mins, marker->r.mins );//stepsize?
00372         VectorCopy( ent->r.mins, marker->r.maxs );//crouching?
00373 
00374         marker->clipmask = ent->clipmask;
00375         marker->waypoint = WAYPOINT_NONE;
00376 
00377         bestWP = trap_Nav_GetNearestNode( marker, marker->waypoint, NF_CLEAR_PATH, WAYPOINT_NONE );
00378 
00379         G_FreeEntity( marker );
00380 
00381         return bestWP;
00382 }
00383 
00384 int NAV_FindClosestWaypointForPoint2( vec3_t point )
00385 {
00386         int     bestWP;
00387         //FIXME: can we make this a static ent?
00388         gentity_t *marker = G_Spawn();
00389         
00390         if ( !marker )
00391         {
00392                 return WAYPOINT_NONE;
00393         }
00394 
00395         G_SetOrigin( marker, point );
00396 
00397         VectorSet( marker->r.mins, -16, -16, -6 );//includes stepsize
00398         VectorSet( marker->r.maxs, 16, 16, 32 );
00399 
00400         marker->clipmask = MASK_NPCSOLID;
00401         marker->waypoint = WAYPOINT_NONE;
00402 
00403         bestWP = trap_Nav_GetNearestNode( marker, marker->waypoint, NF_CLEAR_PATH, WAYPOINT_NONE );
00404 
00405         G_FreeEntity( marker );
00406 
00407         return bestWP;
00408 }
00409 
00410 /*
00411 -------------------------
00412 NAV_ClearBlockedInfo
00413 -------------------------
00414 */
00415 
00416 void NAV_ClearBlockedInfo( gentity_t *self )
00417 {
00418         self->NPC->aiFlags &= ~NPCAI_BLOCKED;
00419         self->NPC->blockingEntNum = ENTITYNUM_WORLD;
00420 }
00421 
00422 /*
00423 -------------------------
00424 NAV_SetBlockedInfo
00425 -------------------------
00426 */
00427 
00428 void NAV_SetBlockedInfo( gentity_t *self, int entId )
00429 {
00430         self->NPC->aiFlags |= NPCAI_BLOCKED;
00431         self->NPC->blockingEntNum = entId;
00432 }
00433 
00434 /*
00435 -------------------------
00436 NAV_Steer
00437 -------------------------
00438 */
00439 
00440 int NAV_Steer( gentity_t *self, vec3_t dir, float distance )
00441 {
00442         vec3_t  right_test, left_test;
00443         vec3_t  deviation;
00444         trace_t tr;
00445         float   right_push;
00446         float   left_push;
00447         float   right_ang       = dir[YAW] + 45;
00448         float   left_ang        = dir[YAW] - 45;
00449 
00450         //Get the steering angles
00451         VectorCopy( dir, deviation );
00452         deviation[YAW] = right_ang;
00453 
00454         AngleVectors( deviation, right_test, NULL, NULL );
00455 
00456         deviation[YAW] = left_ang;
00457 
00458         AngleVectors( deviation, left_test, NULL, NULL );
00459 
00460         //Find the end positions
00461         VectorMA( self->r.currentOrigin, distance, right_test, right_test );
00462         VectorMA( self->r.currentOrigin, distance, left_test,  left_test );
00463 
00464         //Draw for debug purposes
00465         if ( NAVDEBUG_showCollision )
00466         {
00467                 G_DrawEdge( self->r.currentOrigin, right_test, EDGE_PATH );
00468                 G_DrawEdge( self->r.currentOrigin, left_test,  EDGE_PATH );
00469         }
00470 
00471         //Find the right influence
00472         NAV_CheckAhead( self, right_test, &tr, self->clipmask|CONTENTS_BOTCLIP );
00473 
00474         right_push = -45 * ( 1.0f - tr.fraction );
00475 
00476         //Find the left influence
00477         NAV_CheckAhead( self, left_test, &tr, self->clipmask|CONTENTS_BOTCLIP );
00478 
00479         left_push = 45 * ( 1.0f - tr.fraction );
00480 
00481         //Influence the mover to respond to the steering
00482         VectorCopy( dir, deviation );
00483         deviation[YAW] += ( left_push + right_push );
00484 
00485         return deviation[YAW];
00486 }
00487 
00488 /*
00489 -------------------------
00490 NAV_CheckAhead
00491 -------------------------
00492 */
00493 
00494 qboolean NAV_CheckAhead( gentity_t *self, vec3_t end, trace_t *trace, int clipmask )
00495 {
00496         vec3_t  mins;
00497         float   radius;
00498         float   dist;
00499         float   tFrac;
00500 
00501         //Offset the step height
00502         VectorSet( mins, self->r.mins[0], self->r.mins[1], self->r.mins[2] + STEPSIZE );
00503         
00504         trap_Trace( trace, self->r.currentOrigin, mins, self->r.maxs, end, self->s.number, clipmask );
00505 
00506         if ( trace->startsolid&&(trace->contents&CONTENTS_BOTCLIP) )
00507         {//started inside do not enter, so ignore them
00508                 clipmask &= ~CONTENTS_BOTCLIP;
00509                 trap_Trace( trace, self->r.currentOrigin, mins, self->r.maxs, end, self->s.number, clipmask );
00510         }
00511         //Do a simple check
00512         if ( ( trace->allsolid == qfalse ) && ( trace->startsolid == qfalse ) && ( trace->fraction == 1.0f ) )
00513                 return qtrue;
00514 
00515         //See if we're too far above
00516         if ( fabs( self->r.currentOrigin[2] - end[2] ) > 48 )
00517                 return qfalse;
00518 
00519         //This is a work around
00520         radius = ( self->r.maxs[0] > self->r.maxs[1] ) ? self->r.maxs[0] : self->r.maxs[1];
00521         dist = Distance( self->r.currentOrigin, end );
00522         tFrac = 1.0f - ( radius / dist );
00523 
00524         if ( trace->fraction >= tFrac )
00525                 return qtrue;
00526 
00527         //Do a special check for doors
00528         if ( trace->entityNum < ENTITYNUM_WORLD )
00529         {
00530                 gentity_t       *blocker = &g_entities[trace->entityNum];
00531                 
00532                 if VALIDSTRING( blocker->classname )
00533                 {
00534                         if ( G_EntIsUnlockedDoor( blocker->s.number ) )
00535                         //if ( Q_stricmp( blocker->classname, "func_door" ) == 0 )
00536                         {
00537                                 //We're too close, try and avoid the door (most likely stuck on a lip)
00538                                 if ( DistanceSquared( self->r.currentOrigin, trace->endpos ) < MIN_DOOR_BLOCK_DIST_SQR )
00539                                         return qfalse;
00540 
00541                                 return qtrue;
00542                         }
00543                 }
00544         }
00545 
00546         return qfalse;
00547 }
00548 
00549 /*
00550 -------------------------
00551 NAV_TestBypass
00552 -------------------------
00553 */
00554 
00555 static qboolean NAV_TestBypass( gentity_t *self, float yaw, float blocked_dist, vec3_t movedir )
00556 {
00557         trace_t tr;
00558         vec3_t  avoidAngles;
00559         vec3_t  block_test, block_pos;
00560 
00561         VectorClear( avoidAngles );
00562         avoidAngles[YAW] = yaw;
00563 
00564         AngleVectors( avoidAngles, block_test, NULL, NULL );
00565         VectorMA( self->r.currentOrigin, blocked_dist, block_test, block_pos );
00566                 
00567         if ( NAVDEBUG_showCollision )
00568         {
00569                 G_DrawEdge( self->r.currentOrigin, block_pos, EDGE_BLOCKED );
00570         }
00571 
00572         //See if we're clear to move in that direction
00573         if ( NAV_CheckAhead( self, block_pos, &tr, ( self->clipmask & ~CONTENTS_BODY )|CONTENTS_BOTCLIP ) )
00574         {
00575                 VectorCopy( block_test, movedir );
00576                 
00577                 return qtrue;
00578         }
00579 
00580         return qfalse;
00581 }
00582 
00583 /*
00584 -------------------------
00585 NAV_Bypass
00586 -------------------------
00587 */
00588 
00589 qboolean NAV_Bypass( gentity_t *self, gentity_t *blocker, vec3_t blocked_dir, float blocked_dist, vec3_t movedir ) 
00590 {
00591         float dot, yaw, avoidRadius, arcAngle;
00592         vec3_t  right;
00593 
00594         //Draw debug info if requested
00595         if ( NAVDEBUG_showCollision )
00596         {
00597                 G_DrawEdge( self->r.currentOrigin, blocker->r.currentOrigin, EDGE_NORMAL );
00598         }
00599 
00600         AngleVectors( self->r.currentAngles, NULL, right, NULL );
00601 
00602         //Get the blocked direction
00603         yaw = vectoyaw( blocked_dir );
00604 
00605         //Get the avoid radius
00606         avoidRadius = sqrt( ( blocker->r.maxs[0] * blocker->r.maxs[0] ) + ( blocker->r.maxs[1] * blocker->r.maxs[1] ) ) + 
00607                                                 sqrt( ( self->r.maxs[0] * self->r.maxs[0] ) + ( self->r.maxs[1] * self->r.maxs[1] ) );
00608 
00609         //See if we're inside our avoidance radius
00610         arcAngle = ( blocked_dist <= avoidRadius ) ? 135 : ( ( avoidRadius / blocked_dist ) * 90 );
00611 
00612         //FIXME: Although the below code will cause the NPC to take the "better" route, it can cause NPCs to become stuck on
00613         //               one another in certain situations where both decide to take the same direction.
00614 
00615         //Check to see what dir the other guy is moving in (if any) and pick the opposite dir
00616         if ( blocker->client && !VectorCompare( blocker->client->ps.velocity, vec3_origin ) )
00617         {
00618                 vec3_t blocker_movedir;
00619                 VectorNormalize2( blocker->client->ps.velocity, blocker_movedir );
00620                 dot = DotProduct( blocker_movedir, blocked_dir );
00621                 if ( dot < 0.35f && dot > -0.35f )
00622                 {//he's moving to the side of me
00623                         vec3_t  block_pos;
00624                         trace_t tr;
00625                         VectorScale( blocker_movedir, -1, blocker_movedir );
00626                         VectorMA( self->r.currentOrigin, blocked_dist, blocker_movedir, block_pos );
00627                         if ( NAV_CheckAhead( self, block_pos, &tr, ( self->clipmask & ~CONTENTS_BODY )|CONTENTS_BOTCLIP ) )
00628                         {
00629                                 VectorCopy( blocker_movedir, movedir );
00630                                 return qtrue;
00631                         }
00632                 }
00633         }
00634 
00635         //FIXME: this makes NPCs stack up and ping-pong like crazy.
00636         //                      Need to keep track of this and stop trying after a while
00637         dot = DotProduct( blocked_dir, right );
00638 
00639         //Go right on the first try if that works better
00640         if ( dot < 0.0f )
00641                 arcAngle *= -1;
00642 
00643         //Test full, best position first
00644         if ( NAV_TestBypass( self, AngleNormalize360( yaw + arcAngle ), blocked_dist, movedir ) )
00645                 return qtrue;
00646 
00647         //Try a smaller arc
00648         if ( NAV_TestBypass( self, AngleNormalize360( yaw + ( arcAngle * 0.5f ) ), blocked_dist, movedir ) )
00649                 return qtrue;
00650 
00651         //Try the other direction
00652         if ( NAV_TestBypass( self, AngleNormalize360( yaw + ( arcAngle * -1 ) ), blocked_dist, movedir ) )
00653                 return qtrue;
00654 
00655         //Try the other direction more precisely
00656         if ( NAV_TestBypass( self, AngleNormalize360( yaw + ( ( arcAngle * -1 ) * 0.5f ) ), blocked_dist, movedir ) )
00657                 return qtrue;
00658 
00659         //Unable to go around
00660         return qfalse;
00661 }
00662 
00663 /*
00664 -------------------------
00665 NAV_MoveBlocker
00666 -------------------------
00667 */
00668 
00669 qboolean NAV_MoveBlocker( gentity_t *self, vec3_t shove_dir )
00670 {
00671         //FIXME: This is a temporary method for making blockers move
00672         
00673         //FIXME: This will, of course, push blockers off of cliffs, into walls and all over the place
00674 
00675         vec3_t  temp_dir, forward;
00676 
00677         vectoangles( shove_dir, temp_dir );
00678 
00679         temp_dir[YAW] += 45;
00680         AngleVectors( temp_dir, forward, NULL, NULL );
00681 
00682         VectorScale( forward, SHOVE_SPEED, self->client->ps.velocity );
00683         self->client->ps.velocity[2] += SHOVE_LIFT;
00684 
00685         //self->NPC->shoveDebounce = level.time + 100;
00686 
00687         return qtrue;
00688 }
00689 
00690 /*
00691 -------------------------
00692 NAV_ResolveBlock
00693 -------------------------
00694 */
00695 
00696 qboolean NAV_ResolveBlock( gentity_t *self, gentity_t *blocker, vec3_t blocked_dir )
00697 {
00698         //Stop double waiting
00699         if ( ( blocker->NPC ) && ( blocker->NPC->blockingEntNum == self->s.number ) )
00700                 return qtrue;
00701 
00702         //For now, just complain about it
00703         NPC_Blocked( self, blocker );
00704         NPC_FaceEntity( blocker, qtrue );
00705 
00706         return qfalse;
00707 }
00708 
00709 /*
00710 -------------------------
00711 NAV_TrueCollision
00712 -------------------------
00713 */
00714 
00715 qboolean NAV_TrueCollision( gentity_t *self, gentity_t *blocker, vec3_t movedir, vec3_t blocked_dir )
00716 {
00717         vec3_t  velocityDir;
00718         float speed, dot;
00719         vec3_t  testPos;
00720         vec3_t  ptmins, ptmaxs, tmins, tmaxs;
00721 
00722         //TODO: Handle all ents
00723         if ( blocker->client == NULL )
00724                 return qfalse;
00725 
00726         //Get the player's move direction and speed
00727         speed = VectorNormalize2( self->client->ps.velocity, velocityDir );
00728 
00729         //See if it's even feasible
00730         dot = DotProduct( movedir, velocityDir );
00731 
00732         if ( dot < 0.85 )
00733                 return qfalse;
00734 
00735         VectorMA( self->r.currentOrigin, speed*FRAMETIME, velocityDir, testPos );
00736 
00737         VectorAdd( blocker->r.currentOrigin, blocker->r.mins, tmins );
00738         VectorAdd( blocker->r.currentOrigin, blocker->r.maxs, tmaxs );
00739 
00740         VectorAdd( testPos, self->r.mins, ptmins );
00741         VectorAdd( testPos, self->r.maxs, ptmaxs );
00742 
00743         if ( G_BoundsOverlap( ptmins, ptmaxs, tmins, tmaxs ) )
00744         {
00745                 VectorCopy( velocityDir, blocked_dir );
00746                 return qtrue;
00747         }
00748 
00749         return qfalse;
00750 }
00751 
00752 /*
00753 -------------------------
00754 NAV_StackedCanyon
00755 -------------------------
00756 */
00757 
00758 qboolean NAV_StackedCanyon( gentity_t *self, gentity_t *blocker, vec3_t pathDir )
00759 {
00760         vec3_t  perp, cross, test;
00761         float   avoidRadius;
00762         int             extraClip = CONTENTS_BOTCLIP;
00763         trace_t tr;
00764 
00765         PerpendicularVector( perp, pathDir );
00766         CrossProduct( pathDir, perp, cross );
00767 
00768         avoidRadius =   sqrt( ( blocker->r.maxs[0] * blocker->r.maxs[0] ) + ( blocker->r.maxs[1] * blocker->r.maxs[1] ) ) + 
00769                                         sqrt( ( self->r.maxs[0] * self->r.maxs[0] ) + ( self->r.maxs[1] * self->r.maxs[1] ) );
00770 
00771         VectorMA( blocker->r.currentOrigin, avoidRadius, cross, test );
00772 
00773         trap_Trace( &tr, test, self->r.mins, self->r.maxs, test, self->s.number, self->clipmask|extraClip );
00774         if ( tr.startsolid&&(tr.contents&CONTENTS_BOTCLIP) )
00775         {//started inside do not enter, so ignore them
00776                 extraClip &= ~CONTENTS_BOTCLIP;
00777                 trap_Trace( &tr, test, self->r.mins, self->r.maxs, test, self->s.number, self->clipmask|extraClip );
00778         }
00779 
00780         if ( NAVDEBUG_showCollision )
00781         {
00782                 vec3_t  mins, maxs;
00783                 vec3_t  RED = { 1.0f, 0.0f, 0.0f };
00784 
00785                 VectorAdd( test, self->r.mins, mins );
00786                 VectorAdd( test, self->r.maxs, maxs );
00787                 G_Cube( mins, maxs, RED, 0.25 );
00788         }
00789 
00790         if ( tr.startsolid == qfalse && tr.allsolid == qfalse )
00791                 return qfalse;
00792 
00793         VectorMA( blocker->r.currentOrigin, -avoidRadius, cross, test );
00794 
00795         trap_Trace( &tr, test, self->r.mins, self->r.maxs, test, self->s.number, self->clipmask|extraClip );
00796         if ( tr.startsolid&&(tr.contents&CONTENTS_BOTCLIP) )
00797         {//started inside do not enter, so ignore them
00798                 extraClip &= ~CONTENTS_BOTCLIP;
00799                 trap_Trace( &tr, test, self->r.mins, self->r.maxs, test, self->s.number, self->clipmask|extraClip );
00800         }
00801 
00802         if ( tr.startsolid == qfalse && tr.allsolid == qfalse )
00803                 return qfalse;
00804 
00805         if ( NAVDEBUG_showCollision )
00806         {
00807                 vec3_t  mins, maxs;
00808                 vec3_t  RED = { 1.0f, 0.0f, 0.0f };
00809 
00810                 VectorAdd( test, self->r.mins, mins );
00811                 VectorAdd( test, self->r.maxs, maxs );
00812                 G_Cube( mins, maxs, RED, 0.25 );
00813         }
00814 
00815         return qtrue;
00816 }
00817 
00818 /*
00819 -------------------------
00820 NAV_ResolveEntityCollision
00821 -------------------------
00822 */
00823 
00824 qboolean NAV_ResolveEntityCollision( gentity_t *self, gentity_t *blocker, vec3_t movedir, vec3_t pathDir )
00825 {
00826         vec3_t  blocked_dir;
00827         float blocked_dist;
00828 
00829         //Doors are ignored
00830         if ( G_EntIsUnlockedDoor( blocker->s.number ) )
00831         //if ( Q_stricmp( blocker->classname, "func_door" ) == 0 )
00832         {
00833                 if ( DistanceSquared( self->r.currentOrigin, blocker->r.currentOrigin ) > MIN_DOOR_BLOCK_DIST_SQR )
00834                         return qtrue;
00835         }
00836 
00837         VectorSubtract( blocker->r.currentOrigin, self->r.currentOrigin, blocked_dir );
00838         blocked_dist = VectorNormalize( blocked_dir );
00839 
00840         //Make sure an actual collision is going to happen
00841 //      if ( NAV_PredictCollision( self, blocker, movedir, blocked_dir ) == qfalse )
00842 //              return qtrue;
00843         
00844         //See if we can get around the blocker at all (only for player!)
00845         if ( blocker->s.number == 0 )
00846         {
00847                 if ( NAV_StackedCanyon( self, blocker, pathDir ) )
00848                 {
00849                         NPC_Blocked( self, blocker );
00850                         NPC_FaceEntity( blocker, qtrue );
00851 
00852                         return qfalse;
00853                 }
00854         }
00855 
00856         //First, attempt to walk around the blocker
00857         if ( NAV_Bypass( self, blocker, blocked_dir, blocked_dist, movedir ) )
00858                 return qtrue;
00859 
00860         //Second, attempt to calculate a good move position for the blocker
00861         if ( NAV_ResolveBlock( self, blocker, blocked_dir ) )
00862                 return qtrue;
00863 
00864         return qfalse;
00865 }
00866 
00867 /*
00868 -------------------------
00869 NAV_TestForBlocked
00870 -------------------------
00871 */
00872 
00873 qboolean NAV_TestForBlocked( gentity_t *self, gentity_t *goal, gentity_t *blocker, float distance, int *flags )
00874 {
00875         if ( goal == NULL )
00876                 return qfalse;
00877 
00878         if ( blocker->s.eType == ET_ITEM )
00879                 return qfalse;
00880 
00881         if ( NAV_HitNavGoal( blocker->r.currentOrigin, blocker->r.mins, blocker->r.maxs, goal->r.currentOrigin, 12, qfalse ) )
00882         {
00883                 *flags |= NIF_BLOCKED;
00884 
00885                 if ( distance <= MIN_STOP_DIST )
00886                 {
00887                         NPC_Blocked( self, blocker );
00888                         NPC_FaceEntity( blocker, qtrue );
00889                         return qtrue;
00890                 }
00891         }
00892 
00893         return qfalse;
00894 }
00895 
00896 /*
00897 -------------------------
00898 NAV_AvoidCollsion
00899 -------------------------
00900 */
00901 
00902 qboolean NAV_AvoidCollision( gentity_t *self, gentity_t *goal, navInfo_t *info )
00903 {
00904         vec3_t  movedir;
00905         vec3_t  movepos;
00906 
00907         //Clear our block info for this frame
00908         NAV_ClearBlockedInfo( NPC );
00909 
00910         //Cap our distance
00911         if ( info->distance > MAX_COLL_AVOID_DIST )
00912         {
00913                 info->distance = MAX_COLL_AVOID_DIST;
00914         }
00915 
00916         //Get an end position
00917         VectorMA( self->r.currentOrigin, info->distance, info->direction, movepos );
00918         VectorCopy( info->direction, movedir );
00919 
00920         if ( self && self->NPC && (self->NPC->aiFlags&NPCAI_NO_COLL_AVOID) )
00921         {//pretend there's no-one in the way
00922                 return qtrue;
00923         }
00924         //Now test against entities
00925         if ( NAV_CheckAhead( self, movepos, &info->trace, CONTENTS_BODY ) == qfalse )
00926         {
00927                 //Get the blocker
00928                 info->blocker = &g_entities[ info->trace.entityNum ];
00929                 info->flags |= NIF_COLLISION;
00930 
00931                 //Ok to hit our goal entity
00932                 if ( goal == info->blocker )
00933                         return qtrue;
00934 
00935                 //See if we're moving along with them
00936                 //if ( NAV_TrueCollision( self, info.blocker, movedir, info.direction ) == qfalse )
00937                 //      return qtrue;
00938 
00939                 //Test for blocking by standing on goal
00940                 if ( NAV_TestForBlocked( self, goal, info->blocker, info->distance, &info->flags ) == qtrue )
00941                         return qfalse;
00942 
00943                 //If the above function said we're blocked, don't do the extra checks
00944                 if ( info->flags & NIF_BLOCKED )
00945                         return qtrue;
00946 
00947                 //See if we can get that entity to move out of our way
00948                 if ( NAV_ResolveEntityCollision( self, info->blocker, movedir, info->pathDirection ) == qfalse )
00949                         return qfalse;
00950 
00951                 VectorCopy( movedir, info->direction );
00952                 
00953                 return qtrue;
00954         }
00955 
00956         //Our path is clear, just move there
00957         if ( NAVDEBUG_showCollision )
00958         {
00959                 G_DrawEdge( self->r.currentOrigin, movepos, EDGE_PATH );
00960         }
00961 
00962         return qtrue;
00963 }
00964 
00965 /*
00966 -------------------------
00967 NAV_TestBestNode
00968 -------------------------
00969 */
00970 
00971 int NAV_TestBestNode( gentity_t *self, int startID, int endID, qboolean failEdge )
00972 {//check only against architectrure
00973         vec3_t  end;
00974         trace_t trace;
00975         vec3_t  mins;
00976         int             clipmask = (NPC->clipmask&~CONTENTS_BODY)|CONTENTS_BOTCLIP;
00977 
00978         //get the position for the test choice
00979         trap_Nav_GetNodePosition( endID, end );
00980 
00981         //Offset the step height
00982         VectorSet( mins, self->r.mins[0], self->r.mins[1], self->r.mins[2] + STEPSIZE );
00983         
00984         trap_Trace( &trace, self->r.currentOrigin, mins, self->r.maxs, end, self->s.number, clipmask );
00985 
00986         if ( trace.startsolid&&(trace.contents&CONTENTS_BOTCLIP) )
00987         {//started inside do not enter, so ignore them
00988                 clipmask &= ~CONTENTS_BOTCLIP;
00989                 trap_Trace( &trace, self->r.currentOrigin, mins, self->r.maxs, end, self->s.number, clipmask );
00990         }
00991         //Do a simple check
00992         if ( ( trace.allsolid == qfalse ) && ( trace.startsolid == qfalse ) && ( trace.fraction == 1.0f ) )
00993         {//it's clear
00994                 return endID;
00995         }
00996 
00997         //See if we're too far above
00998         if ( self->s.weapon != WP_SABER && fabs( self->r.currentOrigin[2] - end[2] ) > 48 )
00999         {
01000         }
01001         else
01002         {
01003                 //This is a work around
01004                 float   radius = ( self->r.maxs[0] > self->r.maxs[1] ) ? self->r.maxs[0] : self->r.maxs[1];
01005                 float   dist = Distance( self->r.currentOrigin, end );
01006                 float   tFrac = 1.0f - ( radius / dist );
01007 
01008                 if ( trace.fraction >= tFrac )
01009                 {//it's clear
01010                         return endID;
01011                 }
01012         }
01013 
01014         //Do a special check for doors
01015         if ( trace.entityNum < ENTITYNUM_WORLD )
01016         {
01017                 gentity_t       *blocker = &g_entities[trace.entityNum];
01018                 
01019                 if VALIDSTRING( blocker->classname )
01020                 {//special case: doors are architecture, but are dynamic, like entitites
01021                         if ( G_EntIsUnlockedDoor( blocker->s.number ) )
01022                         //if ( Q_stricmp( blocker->classname, "func_door" ) == 0 )
01023                         {//it's unlocked, go for it
01024                                 //We're too close, try and avoid the door (most likely stuck on a lip)
01025                                 if ( DistanceSquared( self->r.currentOrigin, trace.endpos ) < MIN_DOOR_BLOCK_DIST_SQR )
01026                                 {
01027                                         return startID;
01028                                 }
01029                                 //we can keep heading to the door, it should open
01030                                 if ( self->s.weapon != WP_SABER && fabs( self->r.currentOrigin[2] - end[2] ) > 48 )
01031                                 {//too far above
01032                                 }
01033                                 else
01034                                 {
01035                                         return endID;
01036                                 }
01037                         }
01038                         else if ( G_EntIsDoor( blocker->s.number ) )
01039                         {//a locked door!
01040                                 //path is blocked by a locked door, mark it as such if instructed to do so
01041                                 if ( failEdge )
01042                                 {
01043                                         trap_Nav_AddFailedEdge( self->s.number, startID, endID );
01044                                 }
01045                         }
01046                         else if ( G_EntIsBreakable( blocker->s.number ) )
01047                         {//do same for breakable brushes/models/glass?
01048                                 //path is blocked by a breakable, mark it as such if instructed to do so
01049                                 if ( failEdge )
01050                                 {
01051                                         trap_Nav_AddFailedEdge( self->s.number, startID, endID );
01052                                 }
01053                         }
01054                         else if ( G_EntIsRemovableUsable( blocker->s.number ) )
01055                         {//and removable usables
01056                                 //path is blocked by a removable usable, mark it as such if instructed to do so
01057                                 if ( failEdge )
01058                                 {
01059                                         trap_Nav_AddFailedEdge( self->s.number, startID, endID );
01060                                 }
01061                         }
01062                         else if ( blocker->targetname && blocker->s.solid == SOLID_BMODEL && ((blocker->r.contents&CONTENTS_MONSTERCLIP)|| (blocker->r.contents&CONTENTS_BOTCLIP)) )
01063                         {//some other kind of do not enter entity brush that will probably be removed
01064                                 //path is blocked by a removable brushent, mark it as such if instructed to do so
01065                                 if ( failEdge )
01066                                 {
01067                                         trap_Nav_AddFailedEdge( self->s.number, startID, endID );
01068                                 }
01069                         }
01070                 }
01071         }
01072         //path is blocked 
01073         //use the fallback choice
01074         return startID;
01075 }
01076 
01077 /*
01078 -------------------------
01079 NAV_GetNearestNode
01080 -------------------------
01081 */
01082 
01083 int NAV_GetNearestNode( gentity_t *self, int lastNode )
01084 {
01085         return trap_Nav_GetNearestNode( self, lastNode, NF_CLEAR_PATH, WAYPOINT_NONE );
01086 }
01087 
01088 /*
01089 -------------------------
01090 NAV_MicroError
01091 -------------------------
01092 */
01093 
01094 qboolean NAV_MicroError( vec3_t start, vec3_t end )
01095 {
01096         if ( VectorCompare( start, end ) )
01097         {
01098                 if ( DistanceSquared( NPC->r.currentOrigin, start ) < (8*8) )
01099                 {
01100                         return qtrue;
01101                 }
01102         }
01103 
01104         return qfalse;
01105 }
01106 
01107 /*
01108 -------------------------
01109 NAV_MoveToGoal
01110 -------------------------
01111 */
01112 
01113 int     NAV_MoveToGoal( gentity_t *self, navInfo_t *info )
01114 {
01115         int bestNode;
01116         vec3_t  origin, end;
01117 
01118         //Must have a goal entity to move there
01119         if( self->NPC->goalEntity == NULL )
01120                 return WAYPOINT_NONE;
01121 
01122         //Check special player optimizations
01123         if ( self->NPC->goalEntity->s.number == 0 )
01124         {
01125                 //If we couldn't find the point, then we won't be able to this turn
01126                 if ( self->NPC->goalEntity->waypoint == WAYPOINT_NONE )
01127                         return WAYPOINT_NONE;
01128 
01129                 //NOTENOTE: Otherwise trust this waypoint for the whole frame (reduce all unnecessary calculations)
01130         }
01131         else
01132         {
01133                 //Find the target's waypoint
01134                 if ( ( self->NPC->goalEntity->waypoint = NAV_GetNearestNode( self->NPC->goalEntity, self->NPC->goalEntity->waypoint ) ) == WAYPOINT_NONE )
01135                         return WAYPOINT_NONE;
01136         }
01137 
01138         //Find our waypoint
01139         if ( ( self->waypoint = NAV_GetNearestNode( self, self->lastWaypoint ) ) == WAYPOINT_NONE )
01140                 return WAYPOINT_NONE;
01141 
01142         bestNode = trap_Nav_GetBestNode( self->waypoint, self->NPC->goalEntity->waypoint, NODE_NONE );
01143 
01144         if ( bestNode == WAYPOINT_NONE )
01145         {
01146                 if ( NAVDEBUG_showEnemyPath )
01147                 {
01148                         vec3_t  origin, torigin;
01149 
01150                         trap_Nav_GetNodePosition( self->NPC->goalEntity->waypoint, torigin );
01151                         trap_Nav_GetNodePosition( self->waypoint, origin );
01152 
01153                         G_DrawNode( torigin, NODE_GOAL );
01154                         G_DrawNode( origin, NODE_GOAL );
01155                         G_DrawNode( self->NPC->goalEntity->r.currentOrigin, NODE_START );
01156                 }
01157                 
01158                 return WAYPOINT_NONE;
01159         }
01160 
01161         //Check this node
01162         bestNode = NAV_TestBestNode( self, bestNode, self->NPC->goalEntity->waypoint, qfalse );
01163 
01164         //trace_t       trace;
01165 
01166         //Get this position
01167         trap_Nav_GetNodePosition( bestNode, origin );
01168         trap_Nav_GetNodePosition( self->waypoint, end );
01169 
01170         //Basically, see if the path we have isn't helping
01171         //if ( NAV_MicroError( origin, end ) )
01172         //      return WAYPOINT_NONE;
01173 
01174         //Test the path connection from our current position to the best node
01175         if ( NAV_CheckAhead( self, origin, &info->trace, (self->clipmask&~CONTENTS_BODY)|CONTENTS_BOTCLIP ) == qfalse )
01176         {
01177                 //First attempt to move to the closest point on the line between the waypoints
01178                 G_FindClosestPointOnLineSegment( origin, end, self->r.currentOrigin, origin );
01179 
01180                 //See if we can go there
01181                 if ( NAV_CheckAhead( self, origin, &info->trace, (self->clipmask&~CONTENTS_BODY)|CONTENTS_BOTCLIP ) == qfalse )
01182                 {
01183                         //Just move towards our current waypoint
01184                         bestNode = self->waypoint;
01185                         trap_Nav_GetNodePosition( bestNode, origin );
01186                 }
01187         }
01188 
01189         //Setup our new move information
01190         VectorSubtract( origin, self->r.currentOrigin, info->direction );
01191         info->distance = VectorNormalize( info->direction );
01192 
01193         VectorSubtract( end, origin, info->pathDirection );
01194         VectorNormalize( info->pathDirection );
01195 
01196         //Draw any debug info, if requested
01197         if ( NAVDEBUG_showEnemyPath )
01198         {
01199                 vec3_t  dest, start;
01200 
01201                 //Get the positions
01202                 trap_Nav_GetNodePosition( self->NPC->goalEntity->waypoint, dest );
01203                 trap_Nav_GetNodePosition( bestNode, start );
01204 
01205                 //Draw the route
01206                 G_DrawNode( start, NODE_START );
01207                 G_DrawNode( dest, NODE_GOAL );
01208                 trap_Nav_ShowPath( self->waypoint, self->NPC->goalEntity->waypoint );
01209         }
01210 
01211         return bestNode;
01212 }
01213 
01214 /*
01215 -------------------------
01216 waypoint_testDirection
01217 -------------------------
01218 */
01219 
01220 unsigned int waypoint_testDirection( vec3_t origin, float yaw, unsigned int minDist )
01221 {
01222         vec3_t  trace_dir, test_pos;
01223         vec3_t  maxs, mins;
01224         vec3_t  angles;
01225         trace_t tr;
01226 
01227         //Setup the mins and max
01228         VectorSet( maxs, 15, 15, DEFAULT_MAXS_2 );
01229         VectorSet( mins, -15, -15, DEFAULT_MINS_2 + STEPSIZE );
01230 
01231         //Get our test direction
01232         VectorSet(angles, 0, yaw, 0 );
01233         AngleVectors( angles, trace_dir, NULL, NULL );
01234 
01235         //Move ahead
01236 //      VectorMA( origin, MAX_RADIUS_CHECK, trace_dir, test_pos );
01237         VectorMA( origin, minDist, trace_dir, test_pos );
01238 
01239         trap_Trace( &tr, origin, mins, maxs, test_pos, ENTITYNUM_NONE, ( CONTENTS_SOLID | CONTENTS_MONSTERCLIP | CONTENTS_BOTCLIP ) );
01240 
01241         //return (unsigned int) ( (float) MAX_RADIUS_CHECK * tr.fraction );
01242         return (unsigned int) ( (float) minDist * tr.fraction );
01243 }
01244 
01245 /*
01246 -------------------------
01247 waypoint_getRadius
01248 -------------------------
01249 */
01250 
01251 unsigned int waypoint_getRadius( gentity_t *ent )
01252 {
01253         unsigned int    minDist = MAX_RADIUS_CHECK + 1; // (unsigned int) -1;
01254         unsigned int    dist;
01255         int                             i;
01256 
01257         for ( i = 0; i < YAW_ITERATIONS; i++ )
01258         {
01259                 dist = waypoint_testDirection( ent->r.currentOrigin, ((360.0f/YAW_ITERATIONS) * i), minDist );
01260 
01261                 if ( dist < minDist )
01262                         minDist = dist;
01263         }
01264 
01265         return minDist;
01266 }
01267 
01268 /*QUAKED waypoint  (0.7 0.7 0) (-16 -16 -24) (16 16 32) SOLID_OK
01269 a place to go.
01270 
01271 SOLID_OK - only use if placing inside solid is unavoidable in map, but may be clear in-game (ie: at the bottom of a tall, solid lift that starts at the top position)
01272 
01273 radius is automatically calculated in-world.
01274 */
01275 void SP_waypoint ( gentity_t *ent )
01276 {
01277         if ( navCalculatePaths )
01278         {
01279                 unsigned int radius;
01280 
01281                 VectorSet(ent->r.mins, -15, -15, DEFAULT_MINS_2);
01282                 VectorSet(ent->r.maxs, 15, 15, DEFAULT_MAXS_2);
01283                 
01284                 ent->r.contents = CONTENTS_TRIGGER;
01285                 ent->clipmask = MASK_DEADSOLID;
01286 
01287                 trap_LinkEntity( ent );
01288 
01289                 ent->count = -1;
01290                 ent->classname = "waypoint";
01291 
01292                 if( !(ent->spawnflags&1) && G_CheckInSolid (ent, qtrue))
01293                 {//if not SOLID_OK, and in solid
01294                         ent->r.maxs[2] = CROUCH_MAXS_2;
01295                         if(G_CheckInSolid (ent, qtrue))
01296                         {
01297                                 Com_Printf(S_COLOR_RED"ERROR: Waypoint %s at %s in solid!\n", ent->targetname, vtos(ent->r.currentOrigin));
01298                                 assert(0 && "Waypoint in solid!");
01299                                 G_FreeEntity(ent);
01300                                 return;
01301                         }
01302                 }
01303 
01304                 radius = waypoint_getRadius( ent );
01305 
01306                 ent->health = trap_Nav_AddRawPoint( ent->r.currentOrigin, ent->spawnflags, radius );
01307                 NAV_StoreWaypoint( ent );
01308                 G_FreeEntity(ent);
01309                 return;
01310         }
01311 
01312         G_FreeEntity(ent);
01313 }
01314 
01315 /*QUAKED waypoint_small  (0.7 0.7 0) (-2 -2 -24) (2 2 32) SOLID_OK
01316 SOLID_OK - only use if placing inside solid is unavoidable in map, but may be clear in-game (ie: at the bottom of a tall, solid lift that starts at the top position)
01317 */
01318 void SP_waypoint_small (gentity_t *ent)
01319 {
01320         if ( navCalculatePaths )
01321         {
01322                 VectorSet(ent->r.mins, -2, -2, DEFAULT_MINS_2);
01323                 VectorSet(ent->r.maxs, 2, 2, DEFAULT_MAXS_2);
01324 
01325                 ent->r.contents = CONTENTS_TRIGGER;
01326                 ent->clipmask = MASK_DEADSOLID;
01327 
01328                 trap_LinkEntity( ent );
01329 
01330                 ent->count = -1;
01331                 ent->classname = "waypoint";
01332 
01333                 if ( !(ent->spawnflags&1) && G_CheckInSolid( ent, qtrue ) )
01334                 {
01335                         ent->r.maxs[2] = CROUCH_MAXS_2;
01336                         if ( G_CheckInSolid( ent, qtrue ) )
01337                         {
01338                                 Com_Printf(S_COLOR_RED"ERROR: Waypoint_small %s at %s in solid!\n", ent->targetname, vtos(ent->r.currentOrigin));
01339                                 assert(0);
01340                                 G_FreeEntity(ent);
01341                                 return;
01342                         }
01343                 }
01344 
01345                 ent->health = trap_Nav_AddRawPoint( ent->r.currentOrigin, ent->spawnflags, 2 );
01346                 NAV_StoreWaypoint( ent );
01347                 G_FreeEntity(ent);
01348                 return;
01349         }
01350 
01351         G_FreeEntity(ent);
01352 }
01353 
01354 
01355 /*QUAKED waypoint_navgoal (0.3 1 0.3) (-16 -16 -24) (16 16 32) SOLID_OK
01356 A waypoint for script navgoals
01357 Not included in navigation data
01358 
01359 SOLID_OK - only use if placing inside solid is unavoidable in map, but may be clear in-game (ie: at the bottom of a tall, solid lift that starts at the top position)
01360 
01361 targetname - name you would use in script when setting a navgoal (like so:)
01362 
01363   For example: if you give this waypoint a targetname of "console", make an NPC go to it in a script like so:
01364 
01365   set ("navgoal", "console");
01366 
01367 radius - how far from the navgoal an ent can be before it thinks it reached it - default is "0" which means no radius check, just have to touch it
01368 */
01369 
01370 void SP_waypoint_navgoal( gentity_t *ent )
01371 {
01372         int radius = ( ent->radius ) ? (((int)ent->radius)|NAVGOAL_USE_RADIUS) : 12;
01373 
01374         VectorSet( ent->r.mins, -16, -16, -24 );
01375         VectorSet( ent->r.maxs, 16, 16, 32 );
01376         ent->s.origin[2] += 0.125;
01377         if ( !(ent->spawnflags&1) && G_CheckInSolid( ent, qfalse ) )
01378         {
01379                 Com_Printf(S_COLOR_RED"ERROR: Waypoint_navgoal %s at %s in solid!\n", ent->targetname, vtos(ent->r.currentOrigin));
01380                 assert(0);
01381         }
01382         TAG_Add( ent->targetname, NULL, ent->s.origin, ent->s.angles, radius, RTF_NAVGOAL );
01383 
01384         ent->classname = "navgoal";
01385         G_FreeEntity( ent );//can't do this, they need to be found later by some functions, though those could be fixed, maybe?
01386 }
01387 
01388 /*QUAKED waypoint_navgoal_8 (0.3 1 0.3) (-8 -8 -24) (8 8 32) SOLID_OK
01389 A waypoint for script navgoals, 8 x 8 size
01390 Not included in navigation data
01391 
01392 SOLID_OK - only use if placing inside solid is unavoidable in map, but may be clear in-game (ie: at the bottom of a tall, solid lift that starts at the top position)
01393 
01394 targetname - name you would use in script when setting a navgoal (like so:)
01395 
01396   For example: if you give this waypoint a targetname of "console", make an NPC go to it in a script like so:
01397 
01398   set ("navgoal", "console");
01399 
01400 You CANNOT set a radius on these navgoals, they are touch-reach ONLY
01401 */
01402 void SP_waypoint_navgoal_8( gentity_t *ent )
01403 {
01404         VectorSet( ent->r.mins, -8, -8, -24 );
01405         VectorSet( ent->r.maxs, 8, 8, 32 );
01406         ent->s.origin[2] += 0.125;
01407         if ( !(ent->spawnflags&1) && G_CheckInSolid( ent, qfalse ) )
01408         {
01409                 Com_Printf(S_COLOR_RED"ERROR: Waypoint_navgoal_8 %s at %s in solid!\n", ent->targetname, vtos(ent->r.currentOrigin));
01410                 assert(0);
01411         }
01412 
01413         TAG_Add( ent->targetname, NULL, ent->s.origin, ent->s.angles, 8, RTF_NAVGOAL );
01414 
01415         ent->classname = "navgoal";
01416         G_FreeEntity( ent );//can't do this, they need to be found later by some functions, though those could be fixed, maybe?
01417 }
01418 
01419 /*QUAKED waypoint_navgoal_4 (0.3 1 0.3) (-4 -4 -24) (4 4 32) SOLID_OK
01420 A waypoint for script navgoals, 4 x 4 size
01421 Not included in navigation data
01422 
01423 SOLID_OK - only use if placing inside solid is unavoidable in map, but may be clear in-game (ie: at the bottom of a tall, solid lift that starts at the top position)
01424 
01425 targetname - name you would use in script when setting a navgoal (like so:)
01426 
01427   For example: if you give this waypoint a targetname of "console", make an NPC go to it in a script like so:
01428 
01429   set ("navgoal", "console");
01430 
01431 You CANNOT set a radius on these navgoals, they are touch-reach ONLY
01432 */
01433 void SP_waypoint_navgoal_4( gentity_t *ent )
01434 {
01435         VectorSet( ent->r.mins, -4, -4, -24 );
01436         VectorSet( ent->r.maxs, 4, 4, 32 );
01437         ent->s.origin[2] += 0.125;
01438         if ( !(ent->spawnflags&1) && G_CheckInSolid( ent, qfalse ) )
01439         {
01440                 Com_Printf(S_COLOR_RED"ERROR: Waypoint_navgoal_4 %s at %s in solid!\n", ent->targetname, vtos(ent->r.currentOrigin));
01441                 assert(0);
01442         }
01443 
01444         TAG_Add( ent->targetname, NULL, ent->s.origin, ent->s.angles, 4, RTF_NAVGOAL );
01445 
01446         ent->classname = "navgoal";
01447         G_FreeEntity( ent );//can't do this, they need to be found later by some functions, though those could be fixed, maybe?
01448 }
01449 
01450 /*QUAKED waypoint_navgoal_2 (0.3 1 0.3) (-2 -2 -24) (2 2 32) SOLID_OK
01451 A waypoint for script navgoals, 2 x 2 size
01452 Not included in navigation data
01453 
01454 SOLID_OK - only use if placing inside solid is unavoidable in map, but may be clear in-game (ie: at the bottom of a tall, solid lift that starts at the top position)
01455 
01456 targetname - name you would use in script when setting a navgoal (like so:)
01457 
01458   For example: if you give this waypoint a targetname of "console", make an NPC go to it in a script like so:
01459 
01460   set ("navgoal", "console");
01461 
01462 You CANNOT set a radius on these navgoals, they are touch-reach ONLY
01463 */
01464 void SP_waypoint_navgoal_2( gentity_t *ent )
01465 {       
01466         VectorSet( ent->r.mins, -2, -2, -24 );
01467         VectorSet( ent->r.maxs, 2, 2, 32 );
01468         ent->s.origin[2] += 0.125;
01469         if ( !(ent->spawnflags&1) && G_CheckInSolid( ent, qfalse ) )
01470         {
01471                 Com_Printf(S_COLOR_RED"ERROR: Waypoint_navgoal_2 %s at %s in solid!\n", ent->targetname, vtos(ent->r.currentOrigin));
01472                 assert(0);
01473         }
01474 
01475         TAG_Add( ent->targetname, NULL, ent->s.origin, ent->s.angles, 2, RTF_NAVGOAL );
01476 
01477         ent->classname = "navgoal";
01478         G_FreeEntity( ent );//can't do this, they need to be found later by some functions, though those could be fixed, maybe?
01479 }
01480 
01481 /*QUAKED waypoint_navgoal_1 (0.3 1 0.3) (-1 -1 -24) (1 1 32) SOLID_OK
01482 A waypoint for script navgoals, 1 x 1 size
01483 Not included in navigation data
01484 
01485 SOLID_OK - only use if placing inside solid is unavoidable in map, but may be clear in-game (ie: at the bottom of a tall, solid lift that starts at the top position)
01486 
01487 targetname - name you would use in script when setting a navgoal (like so:)
01488 
01489   For example: if you give this waypoint a targetname of "console", make an NPC go to it in a script like so:
01490 
01491   set ("navgoal", "console");
01492 
01493 You CANNOT set a radius on these navgoals, they are touch-reach ONLY
01494 */
01495 void SP_waypoint_navgoal_1( gentity_t *ent )
01496 {
01497         VectorSet( ent->r.mins, -1, -1, -24 );
01498         VectorSet( ent->r.maxs, 1, 1, 32 );
01499         ent->s.origin[2] += 0.125;
01500         if ( !(ent->spawnflags&1) && G_CheckInSolid( ent, qfalse ) )
01501         {
01502                 Com_Printf(S_COLOR_RED"ERROR: Waypoint_navgoal_1 %s at %s in solid!\n", ent->targetname, vtos(ent->r.currentOrigin));
01503                 assert(0);
01504         }
01505 
01506         TAG_Add( ent->targetname, NULL, ent->s.origin, ent->s.angles, 1, RTF_NAVGOAL );
01507 
01508         ent->classname = "navgoal";
01509         G_FreeEntity( ent );//can't do this, they need to be found later by some functions, though those could be fixed, maybe?
01510 }
01511 
01512 /*
01513 -------------------------
01514 Svcmd_Nav_f
01515 -------------------------
01516 */
01517 
01518 void Svcmd_Nav_f( void )
01519 {
01520         char cmd[1024];
01521         trap_Argv( 1, cmd, 1024 );
01522 
01523         if ( Q_stricmp( cmd, "show" ) == 0 )
01524         {
01525                 trap_Argv(2, cmd, 1024);
01526 
01527                 if ( Q_stricmp( cmd, "all" ) == 0 )
01528                 {
01529                         NAVDEBUG_showNodes = !NAVDEBUG_showNodes;
01530                         
01531                         //NOTENOTE: This causes the two states to sync up if they aren't already
01532                         NAVDEBUG_showCollision = NAVDEBUG_showNavGoals = 
01533                         NAVDEBUG_showCombatPoints = NAVDEBUG_showEnemyPath = 
01534                         NAVDEBUG_showEdges = NAVDEBUG_showRadius = NAVDEBUG_showNodes;          
01535                 }
01536                 else if ( Q_stricmp( cmd, "nodes" ) == 0 )
01537                 {
01538                         NAVDEBUG_showNodes = !NAVDEBUG_showNodes;
01539                 }
01540                 else if ( Q_stricmp( cmd, "radius" ) == 0 )
01541                 {
01542                         NAVDEBUG_showRadius = !NAVDEBUG_showRadius;
01543                 }
01544                 else if ( Q_stricmp( cmd, "edges" ) == 0 )
01545                 {
01546                         NAVDEBUG_showEdges = !NAVDEBUG_showEdges;
01547                 }
01548                 else if ( Q_stricmp( cmd, "testpath" ) == 0 )
01549                 {
01550                         NAVDEBUG_showTestPath = !NAVDEBUG_showTestPath;
01551                 }
01552                 else if ( Q_stricmp( cmd, "enemypath" ) == 0 )
01553                 {
01554                         NAVDEBUG_showEnemyPath = !NAVDEBUG_showEnemyPath;
01555                 }
01556                 else if ( Q_stricmp( cmd, "combatpoints" ) == 0 )
01557                 {
01558                         NAVDEBUG_showCombatPoints = !NAVDEBUG_showCombatPoints;
01559                 }
01560                 else if ( Q_stricmp( cmd, "navgoals" ) == 0 )
01561                 {
01562                         NAVDEBUG_showNavGoals = !NAVDEBUG_showNavGoals;
01563                 }
01564                 else if ( Q_stricmp( cmd, "collision" ) == 0 )
01565                 {
01566                         NAVDEBUG_showCollision = !NAVDEBUG_showCollision;
01567                 }
01568         }
01569         else if ( Q_stricmp( cmd, "set" ) == 0 )
01570         {
01571                 trap_Argv( 2, cmd, 1024 );
01572 
01573                 if ( Q_stricmp( cmd, "testgoal" ) == 0 )
01574                 {
01575                         NAVDEBUG_curGoal = trap_Nav_GetNearestNode( &g_entities[0], g_entities[0].waypoint, NF_CLEAR_PATH, WAYPOINT_NONE );
01576                 }
01577         }
01578         else if ( Q_stricmp( cmd, "totals" ) == 0 )
01579         {
01580                 Com_Printf("Navigation Totals:\n");
01581                 Com_Printf("------------------\n");
01582                 Com_Printf("Total Nodes:         %d\n", trap_Nav_GetNumNodes() );
01583                 Com_Printf("Total Combat Points: %d\n", level.numCombatPoints );
01584         }
01585         else
01586         {
01587                 //Print the available commands
01588                 Com_Printf("nav - valid commands\n---\n" );
01589                 Com_Printf("show\n - nodes\n - edges\n - testpath\n - enemypath\n - combatpoints\n - navgoals\n---\n");
01590                 Com_Printf("set\n - testgoal\n---\n" );
01591         }
01592 }
01593 
01594 //
01595 //JWEIER ADDITIONS START
01596 
01597 qboolean        navCalculatePaths       = qfalse;
01598 
01599 qboolean        NAVDEBUG_showNodes                      = qfalse;
01600 qboolean        NAVDEBUG_showRadius                     = qfalse;
01601 qboolean        NAVDEBUG_showEdges                      = qfalse;
01602 qboolean        NAVDEBUG_showTestPath           = qfalse;
01603 qboolean        NAVDEBUG_showEnemyPath          = qfalse;
01604 qboolean        NAVDEBUG_showCombatPoints       = qfalse;
01605 qboolean        NAVDEBUG_showNavGoals           = qfalse;
01606 qboolean        NAVDEBUG_showCollision          = qfalse;
01607 int             NAVDEBUG_curGoal                        = 0;
01608 
01609 /*
01610 -------------------------
01611 NAV_CalculatePaths
01612 -------------------------
01613 */
01614 #ifndef FINAL_BUILD
01615 int fatalErrors = 0;
01616 char *fatalErrorPointer = NULL;
01617 char    fatalErrorString[4096];
01618 qboolean NAV_WaypointsTooFar( gentity_t *wp1, gentity_t *wp2 )
01619 {
01620         if ( Distance( wp1->r.currentOrigin, wp2->r.currentOrigin ) > 1024 )
01621         {
01622                 char    temp[1024];
01623                 int             len;
01624                 fatalErrors++;
01625                 if ( !wp1->targetname && !wp2->targetname )
01626                 {
01627                         Com_sprintf( temp, sizeof(temp), S_COLOR_RED"Waypoint conn %s->%s > 1024\n", vtos( wp1->r.currentOrigin ), vtos( wp2->r.currentOrigin ) );
01628                 }
01629                 else if ( !wp1->targetname )
01630                 {
01631                         Com_sprintf( temp, sizeof(temp), S_COLOR_RED"Waypoint conn %s->%s > 1024\n", vtos( wp1->r.currentOrigin ), wp2->targetname );
01632                 }
01633                 else if ( !wp2->targetname )
01634                 {
01635                         Com_sprintf( temp, sizeof(temp), S_COLOR_RED"Waypoint conn %s->%s > 1024\n", wp1->targetname, vtos( wp2->r.currentOrigin ) );
01636                 }
01637                 else
01638                 {//they both have valid targetnames
01639                         Com_sprintf( temp, sizeof(temp), S_COLOR_RED"Waypoint conn %s->%s > 1024\n", wp1->targetname, wp2->targetname );
01640                 }
01641                 len = strlen( temp );
01642                 if ( (fatalErrorPointer-fatalErrorString)+len >= sizeof( fatalErrorString ) )
01643                 {
01644                         Com_Error( ERR_DROP, "%s%s%dTOO MANY FATAL NAV ERRORS!!!\n", fatalErrorString, temp, fatalErrors );
01645                         return qtrue;
01646                 }
01647                 strcat( fatalErrorPointer, temp );
01648                 fatalErrorPointer += len;
01649                 return qtrue;
01650         }
01651         else
01652         {
01653                 return qfalse;
01654         }
01655 }
01656 #endif
01657 
01658 static int numStoredWaypoints = 0;
01659 //static waypointData_t *tempWaypointList=0;
01660 static waypointData_t tempWaypointList[MAX_STORED_WAYPOINTS]; //rwwFIXMEFIXME: Need.. dynamic.. memory
01661 
01662 
01663 void NAV_ClearStoredWaypoints(void)
01664 {
01665         numStoredWaypoints = 0;
01666 }
01667 
01668 
01669 void NAV_StoreWaypoint( gentity_t *ent )
01670 {
01671         /*
01672         if ( !tempWaypointList )
01673         {
01674                 //tempWaypointList = (waypointData_t *) gi.Malloc(sizeof(waypointData_t)*MAX_STORED_WAYPOINTS, TAG_TEMP_WORKSPACE, qtrue);
01675 
01676                 int size = sizeof(waypointData_t)*MAX_STORED_WAYPOINTS;
01677                 trap_TrueMalloc((void **)&tempWaypointList, size);
01678                 memset(tempWaypointList, 0, size);
01679         }
01680         */
01681 
01682         if ( numStoredWaypoints >= MAX_STORED_WAYPOINTS )
01683         {
01684                 //G_Error( "Too many waypoints!  (%d > %d)\n", numStoredWaypoints, MAX_STORED_WAYPOINTS );
01685                 //rwwFIXMEFIXME: commented this out so I can load some of the SP levels.
01686                 return;
01687         }
01688         if ( ent->targetname )
01689         {
01690                 Q_strncpyz( tempWaypointList[numStoredWaypoints].targetname, ent->targetname, MAX_QPATH );
01691         }
01692         if ( ent->target )
01693         {
01694                 Q_strncpyz( tempWaypointList[numStoredWaypoints].target, ent->target, MAX_QPATH );
01695         }
01696         if ( ent->target2 )
01697         {
01698                 Q_strncpyz( tempWaypointList[numStoredWaypoints].target2, ent->target2, MAX_QPATH );
01699         }
01700         if ( ent->target3 )
01701         {
01702                 Q_strncpyz( tempWaypointList[numStoredWaypoints].target3, ent->target3, MAX_QPATH );
01703         }
01704         if ( ent->target4 )
01705         {
01706                 Q_strncpyz( tempWaypointList[numStoredWaypoints].target4, ent->target4, MAX_QPATH );
01707         }
01708         tempWaypointList[numStoredWaypoints].nodeID = ent->health;
01709 
01710         numStoredWaypoints++;
01711 }
01712 
01713 int NAV_GetStoredWaypoint( char *targetname )
01714 {
01715         int i;
01716 
01717         if ( !tempWaypointList || !targetname || !targetname[0] )
01718         {
01719                 return -1;
01720         }
01721         for ( i = 0; i < numStoredWaypoints; i++ )
01722         {
01723                 if ( tempWaypointList[i].targetname[0] )
01724                 {
01725                         if ( !Q_stricmp( targetname, tempWaypointList[i].targetname ) )
01726                         {
01727                                 return i;
01728                         }
01729                 }
01730         }
01731         return -1;
01732 }
01733 
01734 void NAV_CalculatePaths( const char *filename, int checksum )
01735 {
01736         int target = -1;
01737         int i;
01738 
01739         if ( !tempWaypointList )
01740         {
01741                 return;
01742         }
01743 #ifndef FINAL_BUILD
01744         fatalErrors = 0;
01745         memset( fatalErrorString, 0, sizeof( fatalErrorString ) );
01746         fatalErrorPointer = &fatalErrorString[0];
01747 #endif
01748 #if _HARD_CONNECT
01749 
01750         //Find all connections and hard connect them
01751         for ( i = 0; i < numStoredWaypoints; i++ )
01752         {
01753                 //Find the first connection
01754                 target = NAV_GetStoredWaypoint( tempWaypointList[i].target );
01755 
01756                 if ( target != -1 )
01757                 {
01758 #ifndef FINAL_BUILD
01759 //                      if ( !NAV_WaypointsTooFar( ent, target ) )
01760 #endif
01761                         {
01762                                 trap_Nav_HardConnect( tempWaypointList[i].nodeID, tempWaypointList[target].nodeID );
01763                         }
01764                 }
01765 
01766                 //Find a possible second connection
01767                 target = NAV_GetStoredWaypoint( tempWaypointList[i].target2 );
01768 
01769                 if ( target != -1 )
01770                 {
01771 #ifndef FINAL_BUILD
01772 //                      if ( !NAV_WaypointsTooFar( ent, target ) )
01773 #endif
01774                         {
01775                                 trap_Nav_HardConnect( tempWaypointList[i].nodeID, tempWaypointList[target].nodeID );
01776                         }
01777                 }
01778 
01779                 //Find a possible third connection
01780                 target = NAV_GetStoredWaypoint( tempWaypointList[i].target3 );
01781 
01782                 if ( target != -1 )
01783                 {
01784 #ifndef FINAL_BUILD
01785 //                      if ( !NAV_WaypointsTooFar( ent, target ) )
01786 #endif
01787                         {
01788                                 trap_Nav_HardConnect( tempWaypointList[i].nodeID, tempWaypointList[target].nodeID );
01789                         }
01790                 }
01791 
01792                 //Find a possible fourth connection
01793                 target = NAV_GetStoredWaypoint( tempWaypointList[i].target4 );
01794 
01795                 if ( target != -1 )
01796                 {
01797 #ifndef FINAL_BUILD
01798 //                      if ( !NAV_WaypointsTooFar( ent, target ) )
01799 #endif
01800                         {
01801                                 trap_Nav_HardConnect( tempWaypointList[i].nodeID, tempWaypointList[target].nodeID );
01802                         }
01803                 }
01804         }
01805 
01806 #endif
01807 
01808         //Remove all waypoints now that they're done
01809         //gi.Free(tempWaypointList);
01810         /*
01811         trap_TrueFree((void **)&tempWaypointList);
01812         tempWaypointList=0;
01813         */
01814 
01815         //Now check all blocked edges, mark failed ones
01816         trap_Nav_CheckBlockedEdges();
01817 
01818         trap_Nav_SetPathsCalculated(qfalse);
01819         //navigator.pathsCalculated = qfalse;
01820 
01821         //Calculate the paths based on the supplied waypoints
01822         //trap_Nav_CalculatePaths();
01823 
01824         //Save the resulting information
01825         /*
01826         if ( trap_Nav_Save( filename, checksum ) == qfalse )
01827         {
01828                 Com_Printf("Unable to save navigations data for map \"%s\" (checksum:%d)\n", filename, checksum );
01829         }
01830         */
01831 #ifndef FINAL_BUILD
01832         if ( fatalErrors )
01833         {
01834                 //Com_Error( ERR_DROP, "%s%d FATAL NAV ERRORS\n", fatalErrorString, fatalErrors );
01835                 Com_Printf( "%s%d FATAL NAV ERRORS\n", fatalErrorString, fatalErrors );
01836         }
01837 #endif
01838 }
01839 
01840 /*
01841 -------------------------
01842 NAV_Shutdown
01843 -------------------------
01844 */
01845 
01846 void NAV_Shutdown( void )
01847 {
01848         trap_Nav_Free();
01849 }
01850 
01851 /*
01852 -------------------------
01853 NAV_ShowDebugInfo
01854 -------------------------
01855 */
01856 
01857 void NAV_ShowDebugInfo( void )
01858 {
01859         int i;
01860 
01861         if ( NAVDEBUG_showNodes )
01862         {
01863                 trap_Nav_ShowNodes();
01864         }
01865 
01866         if ( NAVDEBUG_showEdges )
01867         {
01868                 trap_Nav_ShowEdges();
01869         }
01870 
01871         if ( NAVDEBUG_showTestPath )
01872         {
01873                 //Get the nearest node to the player
01874                 int     nearestNode = trap_Nav_GetNearestNode( &g_entities[0], g_entities[0].waypoint, NF_ANY, WAYPOINT_NONE );
01875                 int     testNode = trap_Nav_GetBestNode( nearestNode, NAVDEBUG_curGoal, NODE_NONE );
01876                 vec3_t  dest, start;
01877                 
01878                 nearestNode = NAV_TestBestNode( &g_entities[0], nearestNode, testNode, qfalse );
01879 
01880                 //Show the connection
01881 
01882                 //Get the positions
01883                 trap_Nav_GetNodePosition( NAVDEBUG_curGoal, dest );
01884                 trap_Nav_GetNodePosition( nearestNode, start );
01885 
01886                 G_DrawNode( start, NODE_START );
01887                 G_DrawNode( dest, NODE_GOAL );
01888                 trap_Nav_ShowPath( nearestNode, NAVDEBUG_curGoal );
01889         }
01890 
01891         if ( NAVDEBUG_showCombatPoints )
01892         {
01893                 for ( i = 0; i < level.numCombatPoints; i++ )
01894                 {
01895                         G_DrawCombatPoint( level.combatPoints[i].origin, 0 );
01896                 }
01897         }
01898 
01899         if ( NAVDEBUG_showNavGoals )
01900         {
01901                 TAG_ShowTags( RTF_NAVGOAL );
01902         }
01903 }
01904 
01905 /*
01906 -------------------------
01907 NAV_FindPlayerWaypoint
01908 -------------------------
01909 */
01910 
01911 void NAV_FindPlayerWaypoint( int clNum )
01912 {
01913         g_entities[clNum].waypoint = trap_Nav_GetNearestNode( &g_entities[clNum], g_entities[clNum].lastWaypoint, NF_CLEAR_PATH, WAYPOINT_NONE );
01914 }
01915 
01916 //
01917 //JWEIER ADDITIONS END