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

Function NPC_GetMoveDirection

codeJK2/game/NPC_move.cpp:181–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179*/
180
181qboolean NPC_GetMoveDirection( vec3_t out, float *distance )
182{
183 vec3_t angles;
184
185 //Clear the struct
186 memset( &frameNavInfo, 0, sizeof( frameNavInfo ) );
187
188 //Get our movement, if any
189 if ( NPC_GetMoveInformation( frameNavInfo.direction, &frameNavInfo.distance ) == qfalse )
190 return qfalse;
191
192 //Setup the return value
193 *distance = frameNavInfo.distance;
194
195 //For starters
196 VectorCopy( frameNavInfo.direction, frameNavInfo.pathDirection );
197
198 //If on a ladder, move appropriately
199 if ( NPC->watertype & CONTENTS_LADDER )
200 {
201 NPC_LadderMove( frameNavInfo.direction );
202 return qtrue;
203 }
204
205 //Attempt a straight move to goal
206 if ( NPC_ClearPathToGoal( frameNavInfo.direction, NPCInfo->goalEntity ) == qfalse )
207 {
208 //See if we're just stuck
209 if ( NAV_MoveToGoal( NPC, frameNavInfo ) == WAYPOINT_NONE )
210 {
211 //Can't reach goal, just face
212 vectoangles( frameNavInfo.direction, angles );
213 NPCInfo->desiredYaw = AngleNormalize360( angles[YAW] );
214 VectorCopy( frameNavInfo.direction, out );
215 *distance = frameNavInfo.distance;
216 return qfalse;
217 }
218
219 frameNavInfo.flags |= NIF_MACRO_NAV;
220 }
221
222 //Avoid any collisions on the way
223 if ( NAV_AvoidCollision( NPC, NPCInfo->goalEntity, frameNavInfo ) == qfalse )
224 {
225 //FIXME: Emit a warning, this is a worst case scenario
226 //FIXME: if we have a clear path to our goal (exluding bodies), but then this
227 // check (against bodies only) fails, shouldn't we fall back
228 // to macro navigation? Like so:
229 if ( !(frameNavInfo.flags&NIF_MACRO_NAV) )
230 {//we had a clear path to goal and didn't try macro nav, but can't avoid collision so try macro nav here
231 //See if we're just stuck
232 if ( NAV_MoveToGoal( NPC, frameNavInfo ) == WAYPOINT_NONE )
233 {
234 //Can't reach goal, just face
235 vectoangles( frameNavInfo.direction, angles );
236 NPCInfo->desiredYaw = AngleNormalize360( angles[YAW] );
237 VectorCopy( frameNavInfo.direction, out );
238 *distance = frameNavInfo.distance;

Callers 6

Interrogator_HuntFunction · 0.70
Seeker_HuntFunction · 0.70
ImperialProbe_HuntFunction · 0.70
NPC_MoveToGoalFunction · 0.70
Remote_HuntFunction · 0.70
Sentry_HuntFunction · 0.70

Calls 8

VectorCopyFunction · 0.85
vectoanglesFunction · 0.85
AngleNormalize360Function · 0.85
NPC_GetMoveInformationFunction · 0.70
NPC_LadderMoveFunction · 0.70
NPC_ClearPathToGoalFunction · 0.70
NAV_MoveToGoalFunction · 0.70
NAV_AvoidCollisionFunction · 0.70

Tested by

no test coverage detected