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

Function NPC_CheckCanAttack

code/game/NPC_combat.cpp:2341–2542  ·  view source on GitHub ↗

NOTE: BE SURE TO CHECK PVS BEFORE THIS!

Source from the content-addressed store, hash-verified

2339
2340//NOTE: BE SURE TO CHECK PVS BEFORE THIS!
2341qboolean NPC_CheckCanAttack (float attack_scale, qboolean stationary)
2342{
2343 vec3_t delta, forward;
2344 vec3_t angleToEnemy;
2345 vec3_t hitspot, muzzle, diff, enemy_org;//, enemy_head;
2346 float distanceToEnemy;
2347 qboolean attack_ok = qfalse;
2348// qboolean duck_ok = qfalse;
2349 qboolean dead_on = qfalse;
2350 float aim_off;
2351 float max_aim_off = 128 - (16 * (float)NPCInfo->stats.aim);
2352 trace_t tr;
2353 gentity_t *traceEnt = NULL;
2354
2355 if(NPC->enemy->flags & FL_NOTARGET)
2356 {
2357 return qfalse;
2358 }
2359
2360 //FIXME: only check to see if should duck if that provides cover from the
2361 //enemy!!!
2362 if(!attack_scale)
2363 {
2364 attack_scale = 1.0;
2365 }
2366 //Yaw to enemy
2367 CalcEntitySpot( NPC->enemy, SPOT_HEAD, enemy_org );
2368 NPC_AimWiggle( enemy_org );
2369
2370 CalcEntitySpot( NPC, SPOT_WEAPON, muzzle );
2371
2372 VectorSubtract (enemy_org, muzzle, delta);
2373 vectoangles ( delta, angleToEnemy );
2374 distanceToEnemy = VectorNormalize(delta);
2375
2376 NPC->NPC->desiredYaw = angleToEnemy[YAW];
2377 NPC_UpdateFiringAngles(qfalse, qtrue);
2378
2379 if( NPC_EnemyTooFar(NPC->enemy, distanceToEnemy*distanceToEnemy, qtrue) )
2380 {//Too far away? Do not attack
2381 return qfalse;
2382 }
2383
2384 if(client->fireDelay > 0)
2385 {//already waiting for a shot to fire
2386 NPC->NPC->desiredPitch = angleToEnemy[PITCH];
2387 NPC_UpdateFiringAngles(qtrue, qfalse);
2388 return qfalse;
2389 }
2390
2391 if(NPCInfo->scriptFlags & SCF_DONT_FIRE)
2392 {
2393 return qfalse;
2394 }
2395
2396 NPCInfo->enemyLastVisibility = enemyVisibility;
2397 //See if they're in our FOV and we have a clear shot to them
2398 enemyVisibility = NPC_CheckVisibility ( NPC->enemy, CHECK_360|CHECK_FOV);////CHECK_PVS|

Callers 5

NPC_StandTrackAndShootFunction · 0.70
NPC_BSHuntAndKillFunction · 0.70
NPC_BSStandAndShootFunction · 0.70
NPC_BSRunAndShootFunction · 0.70
NPC_BSMoveFunction · 0.70

Calls 15

VectorSubtractFunction · 0.85
vectoanglesFunction · 0.85
VectorNormalizeFunction · 0.85
AngleVectorsFunction · 0.85
VectorCopyFunction · 0.85
VectorLengthSquaredFunction · 0.85
VectorLengthFunction · 0.85
Q_flrandFunction · 0.85
CalcEntitySpotFunction · 0.70
NPC_AimWiggleFunction · 0.70
NPC_UpdateFiringAnglesFunction · 0.70
NPC_EnemyTooFarFunction · 0.70

Tested by

no test coverage detected