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

Function NPC_CheckAttackHold

codeJK2/game/NPC.cpp:1101–1163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1099
1100float NPC_MaxDistSquaredForWeapon (void);
1101void NPC_CheckAttackHold(void)
1102{
1103 vec3_t vec;
1104
1105 // If they don't have an enemy they shouldn't hold their attack anim.
1106 if ( !NPC->enemy )
1107 {
1108 NPCInfo->attackHoldTime = 0;
1109 return;
1110 }
1111
1112/* if ( ( NPC->client->ps.weapon == WP_BORG_ASSIMILATOR ) || ( NPC->client->ps.weapon == WP_BORG_DRILL ) )
1113 {//FIXME: don't keep holding this if can't hit enemy?
1114
1115 // If they don't have shields ( been disabled) they shouldn't hold their attack anim.
1116 if ( !(NPC->NPC->aiFlags & NPCAI_SHIELDS) )
1117 {
1118 NPCInfo->attackHoldTime = 0;
1119 return;
1120 }
1121
1122 VectorSubtract(NPC->enemy->currentOrigin, NPC->currentOrigin, vec);
1123 if( VectorLengthSquared(vec) > NPC_MaxDistSquaredForWeapon() )
1124 {
1125 NPCInfo->attackHoldTime = 0;
1126 PM_SetTorsoAnimTimer(NPC, &NPC->client->ps.torsoAnimTimer, 0);
1127 }
1128 else if( NPCInfo->attackHoldTime && NPCInfo->attackHoldTime > level.time )
1129 {
1130 ucmd.buttons |= BUTTON_ATTACK;
1131 }
1132 else if ( ( NPCInfo->attackHold ) && ( ucmd.buttons & BUTTON_ATTACK ) )
1133 {
1134 NPCInfo->attackHoldTime = level.time + NPCInfo->attackHold;
1135 PM_SetTorsoAnimTimer(NPC, &NPC->client->ps.torsoAnimTimer, NPCInfo->attackHold);
1136 }
1137 else
1138 {
1139 NPCInfo->attackHoldTime = 0;
1140 PM_SetTorsoAnimTimer(NPC, &NPC->client->ps.torsoAnimTimer, 0);
1141 }
1142 }
1143 else*/
1144 {//everyone else...? FIXME: need to tie this into AI somehow?
1145 VectorSubtract(NPC->enemy->currentOrigin, NPC->currentOrigin, vec);
1146 if( VectorLengthSquared(vec) > NPC_MaxDistSquaredForWeapon() )
1147 {
1148 NPCInfo->attackHoldTime = 0;
1149 }
1150 else if( NPCInfo->attackHoldTime && NPCInfo->attackHoldTime > level.time )
1151 {
1152 ucmd.buttons |= BUTTON_ATTACK;
1153 }
1154 else if ( ( NPCInfo->attackHold ) && ( ucmd.buttons & BUTTON_ATTACK ) )
1155 {
1156 NPCInfo->attackHoldTime = level.time + NPCInfo->attackHold;
1157 }
1158 else

Callers 1

NPC_ExecuteBStateFunction · 0.70

Calls 3

VectorSubtractFunction · 0.85
VectorLengthSquaredFunction · 0.85

Tested by

no test coverage detected