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

Function NPC_Think

codeJK2/game/NPC.cpp:1993–2128  ·  view source on GitHub ↗

AI_TIMERS

Source from the content-addressed store, hash-verified

1991extern int AITime;
1992#endif// AI_TIMERS
1993void NPC_Think ( gentity_t *self)//, int msec )
1994{
1995 vec3_t oldMoveDir;
1996
1997 self->nextthink = level.time + FRAMETIME;
1998
1999 SetNPCGlobals( self );
2000
2001 memset( &ucmd, 0, sizeof( ucmd ) );
2002
2003 VectorCopy( self->client->ps.moveDir, oldMoveDir );
2004 VectorClear( self->client->ps.moveDir );
2005 // see if NPC ai is frozen
2006 if ( debugNPCFreeze->value || (NPC->svFlags&SVF_ICARUS_FREEZE) )
2007 {
2008 NPC_UpdateAngles( qtrue, qtrue );
2009 ClientThink(self->s.number, &ucmd);
2010 VectorCopy(self->s.origin, self->s.origin2 );
2011 return;
2012 }
2013
2014 if(!self || !self->NPC || !self->client)
2015 {
2016 return;
2017 }
2018
2019 // dead NPCs have a special think, don't run scripts (for now)
2020 //FIXME: this breaks deathscripts
2021 if ( self->health <= 0 )
2022 {
2023 DeadThink();
2024 if ( NPCInfo->nextBStateThink <= level.time )
2025 {
2026 if( self->taskManager && !stop_icarus )
2027 {
2028 self->taskManager->Update( );
2029 }
2030 }
2031 return;
2032 }
2033
2034 self->nextthink = level.time + FRAMETIME/2;
2035
2036 if ( player->client->ps.viewEntity == self->s.number )
2037 {//being controlled by player
2038 if ( self->client )
2039 {//make the noises
2040 if ( TIMER_Done( self, "patrolNoise" ) && !Q_irand( 0, 20 ) )
2041 {
2042 switch( self->client->NPC_class )
2043 {
2044 case CLASS_R2D2: // droid
2045 G_SoundOnEnt(self, CHAN_AUTO, va("sound/chars/r2d2/misc/r2d2talk0%d.wav",Q_irand(1, 3)) );
2046 break;
2047 case CLASS_R5D2: // droid
2048 G_SoundOnEnt(self, CHAN_AUTO, va("sound/chars/r5d2/misc/r5talk%d.wav",Q_irand(1, 4)) );
2049 break;
2050 case CLASS_PROBE: // droid

Callers

nothing calls this directly

Calls 15

VectorCopyFunction · 0.85
VectorClearFunction · 0.85
Q_irandFunction · 0.85
GetTimeFunction · 0.85
SetNPCGlobalsFunction · 0.70
NPC_UpdateAnglesFunction · 0.70
ClientThinkFunction · 0.70
DeadThinkFunction · 0.70
TIMER_DoneFunction · 0.70
G_SoundOnEntFunction · 0.70
TIMER_SetFunction · 0.70
NPC_ExecuteBStateFunction · 0.70

Tested by

no test coverage detected