00001 #include "b_local.h"
00002 #include "g_nav.h"
00003 #include "../icarus/Q3_Interface.h"
00004
00005
00006
00007
00008
00009
00010 extern qboolean NPC_SomeoneLookingAtMe(gentity_t *ent);
00011
00012
00013
00014
00015
00016
00017
00018 void NPC_LostEnemyDecideChase(void)
00019 {
00020 switch( NPCInfo->behaviorState )
00021 {
00022 case BS_HUNT_AND_KILL:
00023
00024 if ( NPC->enemy == NPCInfo->goalEntity && NPC->enemy->lastWaypoint != WAYPOINT_NONE )
00025 {
00026
00027 NPC_BSSearchStart( NPC->enemy->lastWaypoint, BS_SEARCH );
00028 }
00029
00030 break;
00031 default:
00032 break;
00033 }
00034 G_ClearEnemy( NPC );
00035 }
00036
00037
00038
00039
00040
00041
00042 void NPC_StandIdle( void )
00043 {
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 }
00086
00087 qboolean NPC_StandTrackAndShoot (gentity_t *NPC, qboolean canDuck)
00088 {
00089 qboolean attack_ok = qfalse;
00090 qboolean duck_ok = qfalse;
00091 qboolean faced = qfalse;
00092 float attack_scale = 1.0;
00093
00094
00095
00096
00097 if ( canDuck )
00098 {
00099 if ( NPC->health < 20 )
00100 {
00101
00102 if( random() )
00103 {
00104 duck_ok = qtrue;
00105 }
00106 }
00107 else if ( NPC->health < 40 )
00108 {
00109
00110
00111
00112
00113
00115
00116
00117
00118
00119 }
00120 }
00121
00122
00123
00124 if ( !duck_ok )
00125 {
00126 attack_ok = NPC_CheckCanAttack( attack_scale, qtrue );
00127 faced = qtrue;
00128 }
00129
00130 if ( canDuck && (duck_ok || (!attack_ok && client->ps.weaponTime <= 0)) && ucmd.upmove != -127 )
00131 {
00132 if( !duck_ok )
00133 {
00134 if ( NPC->enemy->client )
00135 {
00136 if ( NPC->enemy->enemy == NPC )
00137 {
00138 if ( NPC->enemy->client->buttons & BUTTON_ATTACK )
00139 {
00140 if ( NPC_CheckDefend( 1.0 ) )
00141 {
00142 duck_ok = qtrue;
00143 }
00144 }
00145 }
00146 }
00147 }
00148
00149 if ( duck_ok )
00150 {
00151 attack_ok = qfalse;
00152 ucmd.upmove = -127;
00153 NPCInfo->duckDebounceTime = level.time + 1000;
00154 }
00155 }
00156
00157 return faced;
00158 }
00159
00160
00161 void NPC_BSIdle( void )
00162 {
00163
00164
00165 if ( UpdateGoal() )
00166 {
00167 NPC_MoveToGoal( qtrue );
00168 }
00169
00170 if ( ( ucmd.forwardmove == 0 ) && ( ucmd.rightmove == 0 ) && ( ucmd.upmove == 0 ) )
00171 {
00172
00173 }
00174
00175 NPC_UpdateAngles( qtrue, qtrue );
00176 ucmd.buttons |= BUTTON_WALKING;
00177 }
00178
00179 void NPC_BSRun (void)
00180 {
00181
00182
00183 if ( UpdateGoal() )
00184 {
00185 NPC_MoveToGoal( qtrue );
00186 }
00187
00188 NPC_UpdateAngles( qtrue, qtrue );
00189 }
00190
00191 void NPC_BSStandGuard (void)
00192 {
00193
00194 if ( NPC->enemy == NULL )
00195 {
00196 if( random() < 0.5 )
00197 {
00198 if(NPC->client->enemyTeam)
00199 {
00200 gentity_t *newenemy = NPC_PickEnemy(NPC, NPC->client->enemyTeam, (NPC->cantHitEnemyCounter < 10), (NPC->client->enemyTeam == NPCTEAM_PLAYER), qtrue);
00201
00202 if(newenemy)
00203 {
00204 G_SetEnemy( NPC, newenemy );
00205 }
00206 }
00207 }
00208 }
00209
00210 if ( NPC->enemy != NULL )
00211 {
00212 if( NPCInfo->tempBehavior == BS_STAND_GUARD )
00213 {
00214 NPCInfo->tempBehavior = BS_DEFAULT;
00215 }
00216
00217 if( NPCInfo->behaviorState == BS_STAND_GUARD )
00218 {
00219 NPCInfo->behaviorState = BS_STAND_AND_SHOOT;
00220 }
00221 }
00222
00223 NPC_UpdateAngles( qtrue, qtrue );
00224 }
00225
00226
00227
00228
00229
00230
00231
00232 void NPC_BSHuntAndKill( void )
00233 {
00234 qboolean turned = qfalse;
00235 vec3_t vec;
00236 float enemyDist;
00237 visibility_t oEVis;
00238 int curAnim;
00239
00240 NPC_CheckEnemy( NPCInfo->tempBehavior != BS_HUNT_AND_KILL, qfalse, qtrue );
00241
00242 if ( NPC->enemy )
00243 {
00244 oEVis = enemyVisibility = NPC_CheckVisibility ( NPC->enemy, CHECK_FOV|CHECK_SHOOT );
00245 if(enemyVisibility > VIS_PVS)
00246 {
00247 if ( !NPC_EnemyTooFar( NPC->enemy, 0, qtrue ) )
00248 {
00249 NPC_CheckCanAttack( 1.0, qfalse );
00250 turned = qtrue;
00251 }
00252 }
00253
00254 curAnim = NPC->client->ps.legsAnim;
00255 if(curAnim != BOTH_ATTACK1 && curAnim != BOTH_ATTACK2 && curAnim != BOTH_ATTACK3 && curAnim != BOTH_MELEE1 && curAnim != BOTH_MELEE2 )
00256 {
00257
00258 VectorSubtract(NPC->enemy->r.currentOrigin, NPC->r.currentOrigin, vec);
00259 enemyDist = VectorLength(vec);
00260 if( enemyDist > 48 && ((enemyDist*1.5)*(enemyDist*1.5) >= NPC_MaxDistSquaredForWeapon() ||
00261 oEVis != VIS_SHOOT ||
00263 enemyDist > IdealDistance(NPC)*3 ) )
00264 {
00265 NPCInfo->goalEntity = NPC->enemy;
00266
00267 NPC_MoveToGoal( qtrue );
00268 }
00269 else if(enemyDist < IdealDistance(NPC))
00270 {
00271
00272 {
00273 NPCInfo->goalEntity = NPC->enemy;
00274 NPCInfo->goalRadius = 12;
00275 NPC_MoveToGoal( qtrue );
00276
00277 ucmd.forwardmove *= -1;
00278 ucmd.rightmove *= -1;
00279 VectorScale( NPC->client->ps.moveDir, -1, NPC->client->ps.moveDir );
00280
00281 ucmd.buttons |= BUTTON_WALKING;
00282 }
00283 }
00284 }
00285 }
00286 else
00287 {
00288 if( NPCInfo->tempBehavior == BS_HUNT_AND_KILL )
00289 {
00290 NPCInfo->tempBehavior = BS_DEFAULT;
00291 }
00292 else
00293 {
00294 NPCInfo->tempBehavior = BS_STAND_GUARD;
00295 NPC_BSStandGuard();
00296 }
00297 return;
00298 }
00299
00300 if(!turned)
00301 {
00302 NPC_UpdateAngles(qtrue, qtrue);
00303 }
00304 }
00305
00306 void NPC_BSStandAndShoot (void)
00307 {
00308
00309
00310
00311
00312
00313
00314
00315 if(NPC->client->playerTeam && NPC->client->enemyTeam)
00316 {
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 }
00363
00364 NPC_CheckEnemy(qtrue, qfalse, qtrue);
00365
00366 if(NPCInfo->duckDebounceTime > level.time && NPC->client->ps.weapon != WP_SABER )
00367 {
00368 ucmd.upmove = -127;
00369 if(NPC->enemy)
00370 {
00371 NPC_CheckCanAttack(1.0, qtrue);
00372 }
00373 return;
00374 }
00375
00376 if(NPC->enemy)
00377 {
00378 if(!NPC_StandTrackAndShoot( NPC, qtrue ))
00379 {
00380 NPCInfo->desiredYaw = NPC->client->ps.viewangles[YAW];
00381 NPCInfo->desiredPitch = NPC->client->ps.viewangles[PITCH];
00382 NPC_UpdateAngles(qtrue, qtrue);
00383 }
00384 }
00385 else
00386 {
00387 NPCInfo->desiredYaw = NPC->client->ps.viewangles[YAW];
00388 NPCInfo->desiredPitch = NPC->client->ps.viewangles[PITCH];
00389 NPC_UpdateAngles(qtrue, qtrue);
00390
00391 }
00392 }
00393
00394 void NPC_BSRunAndShoot (void)
00395 {
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414 NPC_CheckEnemy( qtrue, qfalse, qtrue );
00415
00416 if ( NPCInfo->duckDebounceTime > level.time )
00417 {
00418 ucmd.upmove = -127;
00419 if ( NPC->enemy )
00420 {
00421 NPC_CheckCanAttack( 1.0, qfalse );
00422 }
00423 return;
00424 }
00425
00426 if ( NPC->enemy )
00427 {
00428 int monitor = NPC->cantHitEnemyCounter;
00429 NPC_StandTrackAndShoot( NPC, qfalse );
00430
00431 if ( !(ucmd.buttons & BUTTON_ATTACK) && ucmd.upmove >= 0 && NPC->cantHitEnemyCounter > monitor )
00432 {
00433 vec3_t vec;
00434
00435 VectorSubtract( NPC->enemy->r.currentOrigin, NPC->r.currentOrigin, vec );
00436 vec[2] = 0;
00437 if ( VectorLength( vec ) > 128 || NPC->cantHitEnemyCounter >= 10 )
00438 {
00439
00440
00441
00442 if ( NPC->cantHitEnemyCounter > 60 )
00443 {
00444 NPC->cantHitEnemyCounter = 60;
00445 }
00446
00447 if ( NPC->cantHitEnemyCounter >= (NPCInfo->stats.aggression+1) * 10 )
00448 {
00449 NPC_LostEnemyDecideChase();
00450 }
00451
00452
00453 ucmd.angles[YAW] = 0;
00454 ucmd.angles[PITCH] = 0;
00455 NPCInfo->goalEntity = NPC->enemy;
00456 NPCInfo->goalRadius = 12;
00457
00458 NPC_MoveToGoal( qtrue );
00459 NPC_UpdateAngles(qtrue, qtrue);
00460 }
00461 else
00462 {
00463
00464
00465
00466
00467
00468
00469
00470 }
00471 }
00472 else
00473 {
00474 NPC->cantHitEnemyCounter = 0;
00475 }
00476 }
00477 else
00478 {
00479 if ( NPCInfo->tempBehavior == BS_HUNT_AND_KILL )
00480 {
00481 NPCInfo->tempBehavior = BS_DEFAULT;
00482 return;
00483 }
00484
00485
00486 }
00487 }
00488
00489
00490 void NPC_BSFace (void)
00491 {
00492
00493
00494 if( NPC_UpdateAngles ( qtrue, qtrue ) )
00495 {
00496 trap_ICARUS_TaskIDComplete( NPC, TID_BSTATE );
00497
00498 NPCInfo->desiredYaw = client->ps.viewangles[YAW];
00499 NPCInfo->desiredPitch = client->ps.viewangles[PITCH];
00500
00501 NPCInfo->aimTime = 0;
00502 }
00503 }
00504
00505 void NPC_BSPointShoot (qboolean shoot)
00506 {
00507 vec3_t muzzle, dir, angles, org;
00508
00509 if ( !NPC->enemy || !NPC->enemy->inuse || (NPC->enemy->NPC && NPC->enemy->health <= 0) )
00510 {
00511 trap_ICARUS_TaskIDComplete( NPC, TID_BSTATE );
00512 goto finished;
00513 return;
00514 }
00515
00516 CalcEntitySpot(NPC, SPOT_WEAPON, muzzle);
00517 CalcEntitySpot(NPC->enemy, SPOT_HEAD, org);
00518
00519 if ( NPC->enemy->client )
00520 {
00521 org[2] -= 12;
00522 }
00523
00524 VectorSubtract(org, muzzle, dir);
00525 vectoangles(dir, angles);
00526
00527 switch( NPC->client->ps.weapon )
00528 {
00529 case WP_NONE:
00530
00531 case WP_STUN_BATON:
00532 case WP_SABER:
00533
00534 break;
00535 default:
00536 NPCInfo->desiredPitch = NPCInfo->lockedDesiredPitch = AngleNormalize360(angles[PITCH]);
00537 break;
00538 }
00539
00540 NPCInfo->desiredYaw = NPCInfo->lockedDesiredYaw = AngleNormalize360(angles[YAW]);
00541
00542 if ( NPC_UpdateAngles ( qtrue, qtrue ) )
00543 {
00544
00545
00546 if ( shoot )
00547 {
00548 ucmd.buttons |= BUTTON_ATTACK;
00549 }
00550
00551
00552 if (1)
00553 {
00554 trap_ICARUS_TaskIDComplete( NPC, TID_BSTATE );
00555 goto finished;
00556 }
00557 }
00558
00559 if (0)
00560 {
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578 {
00579 float dist = VectorLength( dir );
00580 float yawMiss, yawMissAllow = NPC->enemy->r.maxs[0];
00581 float pitchMiss, pitchMissAllow = (NPC->enemy->r.maxs[2] - NPC->enemy->r.mins[2])/2;
00582
00583 if ( yawMissAllow < 8.0f )
00584 {
00585 yawMissAllow = 8.0f;
00586 }
00587
00588 if ( pitchMissAllow < 8.0f )
00589 {
00590 pitchMissAllow = 8.0f;
00591 }
00592
00593 yawMiss = tan(DEG2RAD(AngleDelta ( NPC->client->ps.viewangles[YAW], NPCInfo->desiredYaw ))) * dist;
00594 pitchMiss = tan(DEG2RAD(AngleDelta ( NPC->client->ps.viewangles[PITCH], NPCInfo->desiredPitch))) * dist;
00595
00596 if ( yawMissAllow >= yawMiss && pitchMissAllow > pitchMiss )
00597 {
00598 ucmd.buttons |= BUTTON_ATTACK;
00599 }
00600 }
00601 }
00602
00603 return;
00604
00605 finished:
00606 NPCInfo->desiredYaw = client->ps.viewangles[YAW];
00607 NPCInfo->desiredPitch = client->ps.viewangles[PITCH];
00608
00609 NPCInfo->aimTime = 0;
00610 }
00611
00612
00613
00614
00615
00616 void NPC_BSMove(void)
00617 {
00618 gentity_t *goal = NULL;
00619
00620 NPC_CheckEnemy(qtrue, qfalse, qtrue);
00621 if(NPC->enemy)
00622 {
00623 NPC_CheckCanAttack(1.0, qfalse);
00624 }
00625 else
00626 {
00627 NPC_UpdateAngles(qtrue, qtrue);
00628 }
00629
00630 goal = UpdateGoal();
00631 if(goal)
00632 {
00633
00634
00635 NPC_SlideMoveToGoal();
00636 }
00637 }
00638
00639
00640
00641
00642
00643
00644 void NPC_BSShoot(void)
00645 {
00646
00647
00648 enemyVisibility = VIS_SHOOT;
00649
00650 if ( client->ps.weaponstate != WEAPON_READY && client->ps.weaponstate != WEAPON_FIRING )
00651 {
00652 client->ps.weaponstate = WEAPON_READY;
00653 }
00654
00655 WeaponThink(qtrue);
00656 }
00657
00658
00659
00660
00661
00662
00663
00664 void NPC_BSPatrol( void )
00665 {
00666
00667
00668 if(level.time > NPCInfo->enemyCheckDebounceTime)
00669 {
00670 NPCInfo->enemyCheckDebounceTime = level.time + (NPCInfo->stats.vigilance * 1000);
00671 NPC_CheckEnemy(qtrue, qfalse, qtrue);
00672 if(NPC->enemy)
00673 {
00674 NPCInfo->behaviorState = BS_HUNT_AND_KILL;
00675
00676 return;
00677 }
00678 }
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692 NPCInfo->investigateSoundDebounceTime = 0;
00693
00694
00695 if ( UpdateGoal() )
00696 {
00697 NPC_MoveToGoal( qtrue );
00698 }
00699
00700 NPC_UpdateAngles( qtrue, qtrue );
00701
00702 ucmd.buttons |= BUTTON_WALKING;
00703 }
00704
00705
00706
00707
00708
00709 extern void NPC_CheckGetNewWeapon( void );
00710 extern void NPC_BSST_Attack( void );
00711
00712 void NPC_BSDefault( void )
00713 {
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724 qboolean move = qtrue;
00725
00726
00727
00728 if( NPCInfo->scriptFlags & SCF_FIRE_WEAPON )
00729 {
00730 WeaponThink( qtrue );
00731 }
00732
00733 if ( NPCInfo->scriptFlags & SCF_FORCED_MARCH )
00734 {
00735 if( NPC->client->ps.torsoAnim != TORSO_SURRENDER_START )
00736 {
00737 NPC_SetAnim( NPC, SETANIM_TORSO, TORSO_SURRENDER_START, SETANIM_FLAG_HOLD );
00738 }
00739 }
00740
00741 NPC_CheckEnemy( (NPCInfo->scriptFlags&SCF_LOOK_FOR_ENEMIES), qfalse, qtrue );
00742 if ( !NPC->enemy )
00743 {
00744 if ( !(NPCInfo->scriptFlags&SCF_IGNORE_ALERTS) )
00745 {
00746
00747 int alertEvent = NPC_CheckAlertEvents( qtrue, qtrue, -1, qtrue, AEL_DISCOVERED );
00748
00749
00750 if ( alertEvent >= 0 && level.alertEvents[alertEvent].ID != NPCInfo->lastAlertID )
00751 {
00752 if ( level.alertEvents[alertEvent].level >= AEL_DISCOVERED && (NPCInfo->scriptFlags&SCF_LOOK_FOR_ENEMIES) )
00753 {
00754 if ( level.alertEvents[alertEvent].owner && level.alertEvents[alertEvent].owner->client && level.alertEvents[alertEvent].owner->health >= 0 && level.alertEvents[alertEvent].owner->client->playerTeam == NPC->client->enemyTeam )
00755 {
00756 G_SetEnemy( NPC, level.alertEvents[alertEvent].owner );
00757 }
00758 }
00759 else
00760 {
00761 }
00762 }
00763
00764 }
00765 }
00766
00767 if ( NPC->enemy && !(NPCInfo->scriptFlags&SCF_FORCED_MARCH) )
00768 {
00769
00770 NPC_CheckGetNewWeapon();
00771 if ( NPC->client->leader
00772 && NPCInfo->goalEntity == NPC->client->leader
00773 && !trap_ICARUS_TaskIDPending( NPC, TID_MOVE_NAV ) )
00774 {
00775 NPC_ClearGoal();
00776 }
00777 NPC_BSST_Attack();
00778 return;
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881 }
00882
00883 if ( UpdateGoal() )
00884 {
00885 if ( !NPC->enemy
00886 && NPC->client->leader
00887 && NPCInfo->goalEntity == NPC->client->leader
00888 && !trap_ICARUS_TaskIDPending( NPC, TID_MOVE_NAV ) )
00889 {
00890 NPC_BSFollowLeader();
00891 }
00892 else
00893 {
00894
00895 if ( (NPCInfo->scriptFlags & SCF_FACE_MOVE_DIR) || NPCInfo->goalEntity != NPC->enemy )
00896 {
00897 NPCInfo->combatMove = qfalse;
00898 }
00899 else
00900 {
00901 vec3_t dir, angles;
00902
00903 NPCInfo->combatMove = qfalse;
00904
00905 VectorSubtract( NPCInfo->goalEntity->r.currentOrigin, NPC->r.currentOrigin, dir );
00906 vectoangles( dir, angles );
00907 NPCInfo->desiredYaw = angles[YAW];
00908 if ( NPCInfo->goalEntity == NPC->enemy )
00909 {
00910 NPCInfo->desiredPitch = angles[PITCH];
00911 }
00912 }
00913
00914
00915
00916
00917 if ( NPCInfo->scriptFlags & SCF_RUNNING )
00918 {
00919 ucmd.buttons &= ~BUTTON_WALKING;
00920 }
00921 else if ( NPCInfo->scriptFlags & SCF_WALKING )
00922 {
00923 ucmd.buttons |= BUTTON_WALKING;
00924 }
00925 else if ( NPCInfo->goalEntity == NPC->enemy )
00926 {
00927 ucmd.buttons &= ~BUTTON_WALKING;
00928 }
00929 else
00930 {
00931 ucmd.buttons |= BUTTON_WALKING;
00932 }
00933
00934 if ( NPCInfo->scriptFlags & SCF_FORCED_MARCH )
00935 {
00936
00937 if (!NPC_SomeoneLookingAtMe(NPC))
00938 {
00939 move = qfalse;
00940 }
00941 }
00942
00943 if ( move )
00944 {
00945
00946 NPC_MoveToGoal( qtrue );
00947 }
00948 }
00949 }
00950 else if ( !NPC->enemy && NPC->client->leader )
00951 {
00952 NPC_BSFollowLeader();
00953 }
00954
00955
00956 NPC_UpdateAngles( qtrue, qtrue );
00957 }