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

Function NPC_Think

code/game/NPC.cpp:2365–2533  ·  view source on GitHub ↗

AI_TIMERS

Source from the content-addressed store, hash-verified

2363extern int AITime;
2364#endif// AI_TIMERS
2365void NPC_Think ( gentity_t *self)//, int msec )
2366{
2367 vec3_t oldMoveDir;
2368
2369 self->nextthink = level.time + FRAMETIME/2;
2370
2371 SetNPCGlobals( self );
2372
2373 memset( &ucmd, 0, sizeof( ucmd ) );
2374
2375 VectorCopy( self->client->ps.moveDir, oldMoveDir );
2376 VectorClear( self->client->ps.moveDir );
2377 // see if NPC ai is frozen
2378 if ( debugNPCFreeze->integer || (NPC->svFlags&SVF_ICARUS_FREEZE) )
2379 {
2380 NPC_UpdateAngles( qtrue, qtrue );
2381 ClientThink(self->s.number, &ucmd);
2382 VectorCopy(self->s.origin, self->s.origin2 );
2383 return;
2384 }
2385
2386 if(!self || !self->NPC || !self->client)
2387 {
2388 return;
2389 }
2390
2391 // dead NPCs have a special think, don't run scripts (for now)
2392 //FIXME: this breaks deathscripts
2393 if ( self->health <= 0 )
2394 {
2395 DeadThink();
2396 if ( NPCInfo->nextBStateThink <= level.time )
2397 {
2398 if( self->m_iIcarusID != IIcarusInterface::ICARUS_INVALID && !stop_icarus )
2399 {
2400 IIcarusInterface::GetIcarus()->Update( self->m_iIcarusID );
2401 }
2402 }
2403 return;
2404 }
2405
2406 // TODO! Tauntaun's (and other creature vehicles?) think, we'll need to make an exception here to allow that.
2407
2408 if ( self->client
2409 && self->client->NPC_class == CLASS_VEHICLE
2410 && self->NPC_type
2411 && ( !self->m_pVehicle->m_pVehicleInfo->Inhabited( self->m_pVehicle ) ) )
2412 {//empty swoop logic
2413 if ( self->owner )
2414 {//still have attached owner, check and see if can forget him (so he can use me later)
2415 vec3_t dir2owner;
2416 VectorSubtract( self->owner->currentOrigin, self->currentOrigin, dir2owner );
2417
2418 gentity_t *oldOwner = self->owner;
2419 self->owner = NULL;//clear here for that SpotWouldTelefrag check...?
2420
2421 if ( VectorLengthSquared( dir2owner ) > 128*128
2422 || !(self->clipmask&oldOwner->clipmask)

Callers

nothing calls this directly

Calls 15

VectorCopyFunction · 0.85
VectorClearFunction · 0.85
VectorSubtractFunction · 0.85
VectorLengthSquaredFunction · 0.85
DotProductFunction · 0.85
Q_irandFunction · 0.85
GetTimeFunction · 0.85
VectorScaleFunction · 0.85
SetNPCGlobalsFunction · 0.70
NPC_UpdateAnglesFunction · 0.70
ClientThinkFunction · 0.70
DeadThinkFunction · 0.70

Tested by

no test coverage detected