MCPcopy Create free account
hub / github.com/JACoders/OpenJK / NPC_AvoidWallsAndCliffs

Function NPC_AvoidWallsAndCliffs

codeJK2/game/NPC.cpp:1024–1088  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1022}
1023
1024void NPC_AvoidWallsAndCliffs (void)
1025{
1026/*
1027 vec3_t forward, right, testPos, angles, mins;
1028 trace_t trace;
1029 float fwdDist, rtDist;
1030 //FIXME: set things like this forward dir once at the beginning
1031 //of a frame instead of over and over again
1032 if ( NPCInfo->aiFlags & NPCAI_NO_COLL_AVOID )
1033 {
1034 return;
1035 }
1036
1037 if ( ucmd.upmove > 0 || NPC->client->ps.groundEntityNum == ENTITYNUM_NONE )
1038 {//Going to jump or in the air
1039 return;
1040 }
1041
1042 if ( !ucmd.forwardmove && !ucmd.rightmove )
1043 {
1044 return;
1045 }
1046
1047 if ( fabs( AngleDelta( NPC->currentAngles[YAW], NPCInfo->desiredYaw ) ) < 5.0 )//!ucmd.angles[YAW] )
1048 {//Not turning much, don't do this
1049 //NOTE: Should this not happen only if you're not turning AT ALL?
1050 // You could be turning slowly but moving fast, so that would
1051 // still let you walk right off a cliff...
1052 //NOTE: Or maybe it is a good idea to ALWAYS do this, regardless
1053 // of whether ot not we're turning? But why would we be walking
1054 // straight into a wall or off a cliff unless we really wanted to?
1055 return;
1056 }
1057
1058 VectorCopy( NPC->mins, mins );
1059 mins[2] += STEPSIZE;
1060 angles[YAW] = NPC->client->ps.viewangles[YAW];//Add ucmd.angles[YAW]?
1061 AngleVectors( angles, forward, right, NULL );
1062 fwdDist = ((float)ucmd.forwardmove)/16.0f;
1063 rtDist = ((float)ucmd.rightmove)/16.0f;
1064 VectorMA( NPC->currentOrigin, fwdDist, forward, testPos );
1065 VectorMA( testPos, rtDist, right, testPos );
1066 gi.trace( &trace, NPC->currentOrigin, mins, NPC->maxs, testPos, NPC->s.number, NPC->clipmask );
1067 if ( trace.allsolid || trace.startsolid || trace.fraction < 1.0 )
1068 {//Going to bump into something, don't move, just turn
1069 ucmd.forwardmove = 0;
1070 ucmd.rightmove = 0;
1071 return;
1072 }
1073
1074 VectorCopy(trace.endpos, testPos);
1075 testPos[2] -= 128;
1076
1077 gi.trace( &trace, trace.endpos, mins, NPC->maxs, testPos, NPC->s.number, NPC->clipmask );
1078 if ( trace.allsolid || trace.startsolid || trace.fraction < 1.0 )
1079 {//Not going off a cliff
1080 return;
1081 }

Callers 1

NPC_ExecuteBStateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected