1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
|
//========= Copyright Valve Corporation, All rights reserved. ============//
// tf_bot_destroy_enemy_sentry.cpp
// Destroy an enemy sentry gun
// Michael Booth, June 2010
#include "cbase.h"
#include "tf_player.h"
#include "tf_obj_sentrygun.h"
#include "tf_weaponbase_gun.h"
#include "bot/tf_bot.h"
#include "bot/behavior/tf_bot_destroy_enemy_sentry.h"
#include "bot/behavior/tf_bot_attack.h"
#include "bot/behavior/tf_bot_retreat_to_cover.h"
#include "bot/behavior/tf_bot_get_ammo.h"
#include "bot/behavior/demoman/tf_bot_stickybomb_sentrygun.h"
#include "nav_mesh.h"
extern ConVar tf_bot_path_lookahead_range;
extern ConVar tf_bot_sticky_base_range;
ConVar tf_bot_debug_destroy_enemy_sentry( "tf_bot_debug_destroy_enemy_sentry", "0", FCVAR_CHEAT );
ConVar tf_bot_max_grenade_launch_at_sentry_range( "tf_bot_max_grenade_launch_at_sentry_range", "1500", FCVAR_CHEAT );
ConVar tf_bot_max_sticky_launch_at_sentry_range( "tf_bot_max_sticky_launch_at_sentry_range", "1500", FCVAR_CHEAT );
//---------------------------------------------------------------------------------------------
// Search for angle to land grenade near target
bool FindGrenadeAim( CTFBot *me, CBaseEntity *target, float *aimYaw, float *aimPitch )
{
Vector toTarget = target->WorldSpaceCenter() - me->EyePosition();
if ( toTarget.IsLengthGreaterThan( tf_bot_max_grenade_launch_at_sentry_range.GetFloat() ) )
{
return false;
}
QAngle anglesToTarget;
VectorAngles( toTarget, anglesToTarget );
// start with current aim, in case we're already on target
const QAngle &eyeAngles = me->EyeAngles();
float yaw = eyeAngles.y;
float pitch = eyeAngles.x;
const int trials = 10;
for( int t=0; t<trials; ++t )
{
// estimate impact spot
const float pipebombInitVel = 900.0f;
Vector impactSpot = me->EstimateProjectileImpactPosition( pitch, yaw, pipebombInitVel );
// check if impactSpot landed near sentry
const float explosionRadius = 75.0f;
if ( ( target->WorldSpaceCenter() - impactSpot ).IsLengthLessThan( explosionRadius ) )
{
trace_t trace;
NextBotTraceFilterIgnoreActors filter( target, COLLISION_GROUP_NONE );
UTIL_TraceLine( target->WorldSpaceCenter(), impactSpot, MASK_SOLID_BRUSHONLY, &filter, &trace );
if ( !trace.DidHit() )
{
*aimYaw = yaw;
*aimPitch = pitch;
return true;
}
}
yaw = anglesToTarget.y + RandomFloat( -30.0f, 30.0f );
pitch = RandomFloat( -85.0f, 85.0f );
}
return false;
}
//---------------------------------------------------------------------------------------------
// Search for angle to land sticky near target
bool FindStickybombAim( CTFBot *me, CBaseEntity *target, float *aimYaw, float *aimPitch, float *aimCharge )
{
Vector toTarget = target->WorldSpaceCenter() - me->EyePosition();
if ( toTarget.IsLengthGreaterThan( tf_bot_max_sticky_launch_at_sentry_range.GetFloat() ) )
{
return false;
}
QAngle anglesToTarget;
VectorAngles( toTarget, anglesToTarget );
// start with current aim, in case we're already on target
const QAngle &eyeAngles = me->EyeAngles();
float yaw = eyeAngles.y;
float pitch = eyeAngles.x;
*aimCharge = 1.0f;
bool hasTarget = false;
const int trials = 100;
for( int t=0; t<trials; ++t )
{
float charge = 0.0f;
// if ( toTarget.IsLengthGreaterThan( tf_bot_sticky_base_range.GetBool() ) )
// {
// charge = RandomFloat( 0.1f, 1.0f );
//
// // skew towards zero - full charge shots are seldom required
// charge *= charge;
// }
// estimate impact spot
Vector impactSpot = me->EstimateStickybombProjectileImpactPosition( pitch, yaw, charge );
// check if impactSpot landed near target
const float explosionRadius = 75.0f;
if ( ( target->WorldSpaceCenter() - impactSpot ).IsLengthLessThan( explosionRadius ) )
{
trace_t trace;
NextBotTraceFilterIgnoreActors filter( target, COLLISION_GROUP_NONE );
UTIL_TraceLine( target->WorldSpaceCenter(), impactSpot, MASK_SOLID_BRUSHONLY, &filter, &trace );
if ( !trace.DidHit() )
{
// found target aim - keep one we find with least required
// charge, because we need to be fast in combat
if ( charge < (*aimCharge) )
{
hasTarget = true;
*aimCharge = charge;
*aimYaw = yaw;
*aimPitch = pitch;
if ( *aimCharge < 0.01 )
{
// as quick as possible - no need to search further
break;
}
}
}
}
yaw = anglesToTarget.y + RandomFloat( -30.0f, 30.0f );
pitch = RandomFloat( -85.0f, 85.0f );
}
return hasTarget;
}
//---------------------------------------------------------------------------------------------
// Return true if this Action has what it needs to perform right now
bool CTFBotDestroyEnemySentry::IsPossible( CTFBot *me )
{
if ( me->IsPlayerClass( TF_CLASS_HEAVYWEAPONS ) ||
me->IsPlayerClass( TF_CLASS_SNIPER ) ||
me->IsPlayerClass( TF_CLASS_MEDIC ) ||
me->IsPlayerClass( TF_CLASS_ENGINEER ) ||
me->IsPlayerClass( TF_CLASS_PYRO ) )
{
// these classes have no way to kill a sentry at long range
return false;
}
// don't go after a sentry if we're out of ammo
if ( me->GetAmmoCount( TF_AMMO_PRIMARY ) <= 0 || me->GetAmmoCount( TF_AMMO_SECONDARY ) <= 0 )
{
return false;
}
// if we're a spy, we have better ways of destroying sentries that shooting at it
if ( me->IsPlayerClass( TF_CLASS_SPY ) )
{
return false;
}
#ifdef TF_RAID_MODE
if ( TFGameRules()->IsRaidMode() )
{
if ( me->GetTeamNumber() == TF_TEAM_PVE_INVADERS )
{
return false;
}
}
#endif
if ( TFGameRules()->IsMannVsMachineMode() )
{
if ( me->GetTeamNumber() == TF_TEAM_PVE_INVADERS )
{
return false;
}
}
return true;
}
//---------------------------------------------------------------------------------------------
class CFindSafeAttackArea : public ISearchSurroundingAreasFunctor
{
public:
CFindSafeAttackArea( CTFBot *me )
{
m_me = me;
m_attackSpot = me->GetAbsOrigin();
m_foundAttackSpot = false;
CObjectSentrygun *sentry = me->GetEnemySentry();
if ( sentry )
{
sentry->UpdateLastKnownArea();
m_sentryArea = (CTFNavArea *)sentry->GetLastKnownArea();
}
else
{
m_sentryArea = NULL;
}
}
virtual bool operator() ( CNavArea *area, CNavArea *priorArea, float travelDistanceSoFar )
{
if ( !m_sentryArea )
{
return false;
}
if ( area->IsPotentiallyVisible( m_sentryArea ) )
{
// try the center first
m_attackSpot = area->GetCenter();
const int maxTries = 5;
for( int i=0; i<maxTries; ++i )
{
if ( m_me->IsLineOfFireClear( m_attackSpot + m_me->GetClassEyeHeight(), m_me->GetEnemySentry() ) )
{
if ( ( m_attackSpot - m_me->GetEnemySentry()->GetAbsOrigin() ).IsLengthGreaterThan( 1.1f * SENTRY_MAX_RANGE ) )
{
// found our attack spot
m_foundAttackSpot = true;
return false;
}
}
m_attackSpot = area->GetRandomPoint();
}
}
return true;
}
CTFBot *m_me;
CTFNavArea *m_sentryArea;
Vector m_attackSpot;
bool m_foundAttackSpot;
Vector m_splashFromSpot;
Vector m_splashToSpot;
bool m_foundSplashSpot;
};
//---------------------------------------------------------------------------------------------
void CTFBotDestroyEnemySentry::ComputeSafeAttackSpot( CTFBot *me )
{
m_hasSafeAttackSpot = false;
CObjectSentrygun *sentry = me->GetEnemySentry();
if ( sentry == NULL )
{
return;
}
sentry->UpdateLastKnownArea();
CTFNavArea *sentryArea = (CTFNavArea *)sentry->GetLastKnownArea();
if ( sentryArea == NULL )
{
return;
}
NavAreaCollector collector( true );
sentryArea->ForAllPotentiallyVisibleAreas( collector );
int i;
CUtlVector< CTFNavArea * > beyondSentryRangeVector;
for( i=0; i<collector.m_area.Count(); ++i )
{
CTFNavArea *area = (CTFNavArea *)collector.m_area[i];
Vector wayOut = ( area->GetCenter() - sentryArea->GetCenter() ) + area->GetCenter();
Vector farthestFromSentry;
area->GetClosestPointOnArea( wayOut, &farthestFromSentry );
if ( ( farthestFromSentry - sentry->GetAbsOrigin() ).IsLengthGreaterThan( SENTRY_MAX_RANGE ) )
{
// at least some of this area is out of sentry range
beyondSentryRangeVector.AddToTail( area );
if ( tf_bot_debug_destroy_enemy_sentry.GetBool() )
{
area->DrawFilled( 0, 255, 0, 255, 60.0f, true, 1.0f );
}
}
}
CUtlVector< CTFNavArea * > attackSentryVector;
for( i=0; i<beyondSentryRangeVector.Count(); ++i )
{
CTFNavArea *area = beyondSentryRangeVector[i];
Vector closestToSentry;
area->GetClosestPointOnArea( sentry->GetAbsOrigin(), &closestToSentry );
if ( ( closestToSentry - sentry->GetAbsOrigin() ).IsLengthLessThan( 1.5f * SENTRY_MAX_RANGE ) )
{
// good attack range
attackSentryVector.AddToTail( area );
if ( tf_bot_debug_destroy_enemy_sentry.GetBool() )
{
area->DrawFilled( 100, 255, 0, 255, 60.0f );
}
}
}
if ( beyondSentryRangeVector.Count() == 0 )
{
// no safe areas at all
m_hasSafeAttackSpot = false;
return;
}
CUtlVector< CTFNavArea * > *safeAreaVector;
if ( attackSentryVector.Count() == 0 )
{
// no good close-in attack areas, choose from farther away set
safeAreaVector = &beyondSentryRangeVector;
}
else
{
// for now, just pick a random spot
safeAreaVector = &attackSentryVector;
}
// TODO: find closest and least combat-hot area
CTFNavArea *safeArea = safeAreaVector->Element( RandomInt( 0, safeAreaVector->Count()-1 ) );
m_safeAttackSpot = safeArea->GetRandomPoint();
m_hasSafeAttackSpot = true;
if ( tf_bot_debug_destroy_enemy_sentry.GetBool() )
{
safeArea->DrawFilled( 255, 255, 0, 255, 60.0f );
NDebugOverlay::Cross3D( m_safeAttackSpot, 10.0f, 255, 0, 0, true, 60.0f );
}
}
//---------------------------------------------------------------------------------------------
class FindSafeSentryApproachAreaScan : public ISearchSurroundingAreasFunctor
{
public:
FindSafeSentryApproachAreaScan( CTFBot *me )
{
m_me = me;
m_isEscaping = false;
CTFNavArea *myArea = me->GetLastKnownArea();
if ( myArea && myArea->IsTFMarked() )
{
// I'm standing in a danger area - escape!
m_isEscaping = true;
}
}
virtual bool operator() ( CNavArea *baseArea, CNavArea *priorArea, float travelDistanceSoFar )
{
CTFNavArea *area = (CTFNavArea *)baseArea;
if ( m_isEscaping )
{
if ( !area->IsTFMarked() )
{
// found safe area - use it
m_approachAreaVector.AddToTail( area );
return false;
}
}
else
{
if ( area->IsTFMarked() && priorArea )
{
// we just stepped into sentry fire - keep the area one step prior
m_approachAreaVector.AddToTail( (CTFNavArea *)priorArea );
}
}
return true;
}
// return true if 'adjArea' should be included in the ongoing search
virtual bool ShouldSearch( CNavArea *baseAdjArea, CNavArea *baseCurrentArea, float travelDistanceSoFar )
{
CTFNavArea *area = (CTFNavArea *)baseCurrentArea;
if ( !m_isEscaping )
{
// don't search beyond sentry danger areas (but step into them)
if ( area->IsTFMarked() )
{
return false;
}
}
return m_me->GetLocomotionInterface()->IsAreaTraversable( baseAdjArea );
}
// Invoked after the search has completed
virtual void PostSearch( void )
{
if ( tf_bot_debug_destroy_enemy_sentry.GetBool() )
{
for( int i=0; i<m_approachAreaVector.Count(); ++i )
{
m_approachAreaVector[i]->DrawFilled( 0, 255, 0, 255, 60.0f );
}
}
}
CTFBot *m_me;
CUtlVector< CTFNavArea * > m_approachAreaVector;
bool m_isEscaping;
};
//---------------------------------------------------------------------------------------------
void CTFBotDestroyEnemySentry::ComputeCornerAttackSpot( CTFBot *me )
{
m_safeAttackSpot = vec3_origin;
m_hasSafeAttackSpot = false;
CObjectSentrygun *sentry = me->GetEnemySentry();
if ( !sentry )
{
return;
}
sentry->UpdateLastKnownArea();
CTFNavArea *sentryArea = (CTFNavArea *)sentry->GetLastKnownArea();
if ( !sentryArea )
{
return;
}
// mark all areas this sentry can potentially fire upon
// need to use completely visible so the partially visible areas are used as corner-fighting spots
NavAreaCollector sentryDanger;
sentryArea->ForAllCompletelyVisibleAreas( sentryDanger );
CTFNavArea::MakeNewTFMarker();
for( int i=0; i<sentryDanger.m_area.Count(); ++i )
{
CTFNavArea *area = (CTFNavArea *)sentryDanger.m_area[i];
Vector close;
area->GetClosestPointOnArea( sentry->GetAbsOrigin(), &close );
if ( ( sentry->GetAbsOrigin() - close ).IsLengthLessThan( SENTRY_MAX_RANGE ) )
{
area->TFMark();
if ( tf_bot_debug_destroy_enemy_sentry.GetBool() )
{
area->DrawFilled( 255, 0, 0, 255, 60.0f );
}
}
}
// find nearby area adjacent to area that is in enemy sentry fire field
FindSafeSentryApproachAreaScan scan( me );
SearchSurroundingAreas( me->GetLastKnownArea(), scan );
if ( scan.m_approachAreaVector.Count() > 0 )
{
CTFNavArea *safeArea = scan.m_approachAreaVector[ RandomInt( 0, scan.m_approachAreaVector.Count()-1 ) ];
// try to avoid picking a spot where sentry can attack us
const int retryCount = 25;
for( int r=0; r<retryCount; ++r )
{
m_safeAttackSpot = safeArea->GetRandomPoint();
if ( ( sentry->WorldSpaceCenter() - m_safeAttackSpot ).IsLengthGreaterThan( SENTRY_MAX_RANGE ) ||
!me->IsLineOfFireClear( sentry->WorldSpaceCenter(), m_safeAttackSpot ) )
{
break;
}
}
m_hasSafeAttackSpot = true;
if ( tf_bot_debug_destroy_enemy_sentry.GetBool() )
{
NDebugOverlay::Cross3D( m_safeAttackSpot, 5.0f, 255, 255, 0, true, 60.0f );
}
}
}
//---------------------------------------------------------------------------------------------
ActionResult< CTFBot > CTFBotDestroyEnemySentry::OnStart( CTFBot *me, Action< CTFBot > *priorAction )
{
m_path.SetMinLookAheadDistance( me->GetDesiredPathLookAheadRange() );
m_path.Invalidate();
m_repathTimer.Invalidate();
m_isAttackingSentry = false;
m_wasUber = false;
/*
// find a spot to attack the sentry out of its range
CFindSafeAttackArea find( me );
SearchSurroundingAreas( me->GetLastKnownArea(), find, 1.5f * SENTRY_MAX_RANGE );
m_hasSafeAttackSpot = find.m_foundAttackSpot;
m_safeAttackSpot = find.m_attackSpot;
*/
if ( me->IsPlayerClass( TF_CLASS_DEMOMAN ) )
{
ComputeCornerAttackSpot( me );
}
else
{
ComputeSafeAttackSpot( me );
}
/*
if ( !m_hasSafeAttackSpot )
{
return Done( "No safe attack spot found" );
}
*/
m_targetSentry = me->GetEnemySentry();
return Continue();
}
//---------------------------------------------------------------------------------------------
ActionResult< CTFBot > CTFBotDestroyEnemySentry::Update( CTFBot *me, float interval )
{
if ( me->GetEnemySentry() == NULL )
{
return Done( "Enemy sentry is destroyed" );
}
// if the sentry changes, re-evaluate
if ( me->GetEnemySentry() != m_targetSentry )
{
return ChangeTo( new CTFBotDestroyEnemySentry, "Changed sentry target" );
}
if ( me->m_Shared.IsInvulnerable() )
{
if ( !m_wasUber )
{
m_wasUber = true;
// we just became uber - are we close enough to rush the sentry?
const float maxRushDistance = 500.0f;
CTFBotPathCost cost( me, FASTEST_ROUTE );
float travelDistance = NavAreaTravelDistance( me->GetLastKnownArea(),
m_targetSentry->GetLastKnownArea(),
cost, maxRushDistance );
if ( travelDistance >= 0.0f )
{
return SuspendFor( new CTFBotUberAttackEnemySentry( m_targetSentry ), "Go get it!" );
}
}
}
else
{
m_wasUber = false;
}
if ( !me->HasAttribute( CTFBot::IGNORE_ENEMIES ) )
{
const CKnownEntity *threat = me->GetVisionInterface()->GetPrimaryKnownThreat();
if ( threat && threat->IsVisibleInFOVNow() )
{
float threatRange = me->GetRangeTo( threat->GetLastKnownPosition() );
float sentryRange = me->GetRangeTo( me->GetEnemySentry() );
if ( threatRange < 0.5f * sentryRange )
{
return Done( "Enemy near" );
}
}
}
bool isSentryFiringOnMe = false;
if ( me->GetEnemySentry()->GetTimeSinceLastFired() < 1.0f )
{
Vector sentryForward;
AngleVectors( me->GetEnemySentry()->GetTurretAngles(), &sentryForward );
Vector to = me->GetAbsOrigin() - me->GetEnemySentry()->GetAbsOrigin();
to.NormalizeInPlace();
if ( DotProduct( to, sentryForward ) > 0.8f )
{
isSentryFiringOnMe = true;
}
}
if ( me->IsPlayerClass( TF_CLASS_DEMOMAN ) )
{
// a demoman wants to get close to the sentry but just out of range or line of sight so
// he can pepper the area with stickies and destroy it
Vector attackSpot = m_hasSafeAttackSpot ? m_safeAttackSpot : m_targetSentry->GetAbsOrigin();
// move into position
if ( !m_path.IsValid() || m_repathTimer.IsElapsed() )
{
m_repathTimer.Start( 1.0f );
CTFBotPathCost cost( me, SAFEST_ROUTE );
m_path.Compute( me, attackSpot, cost );
}
float aimPitch, aimYaw, aimCharge;
if ( isSentryFiringOnMe )
{
// the sentry is firing on me - might as well shoot back!
me->EquipLongRangeWeapon();
me->PressFireButton();
}
else if ( FindStickybombAim( me, m_targetSentry, &aimYaw, &aimPitch, &aimCharge ) )
{
// found an opportunistic spot to sticky the sentry from
return ChangeTo( new CTFBotStickybombSentrygun( me->GetEnemySentry(), aimYaw, aimPitch, aimCharge ), "Destroying sentry with opportunistic sticky shot" );
}
// move towards sentry
if ( m_canMove )
{
m_path.Update( me );
}
if ( ( me->IsRangeLessThan( attackSpot, 50.0f ) &&
( me->GetAbsOrigin() - attackSpot ).AsVector2D().IsLengthLessThan( 25.0f ) ) ||
( me->IsLineOfFireClear( me->GetEnemySentry() ) && me->IsRangeLessThan( m_targetSentry, 1000.0f ) ) ) // opportunistic shot
{
// reached attack spot
return ChangeTo( new CTFBotStickybombSentrygun( me->GetEnemySentry() ), "Destroying sentry with stickies" );
}
if ( me->IsRangeLessThan( attackSpot, 200.0f ) )
{
#ifdef TF_CREEP_MODE
if ( m_creepTimer.IsElapsed() )
{
m_canMove = !m_canMove;
if ( m_canMove )
{
m_creepTimer.Start( 0.1f );
}
else
{
m_creepTimer.Start( RandomFloat( 0.2f, 0.5f ) );
}
}
#endif
}
else
{
m_canMove = true;
}
return Continue();
}
bool isInAttackPosition = ( m_hasSafeAttackSpot && me->IsRangeLessThan( m_safeAttackSpot, 20.0f ) );
if ( isInAttackPosition || me->IsLineOfFireClear( me->GetEnemySentry() ) )
{
// must look at sentry entity to make use of SelectTargetPoint()
me->GetBodyInterface()->AimHeadTowards( me->GetEnemySentry(), IBody::MANDATORY, 1.0f, NULL, "Aiming at enemy sentry" );
// because sentries are stationary, check if XY is on target to allow SelectTargetPoint() to adjust Z for grenades
Vector toSentry = me->GetEnemySentry()->WorldSpaceCenter() - me->EyePosition();
toSentry.NormalizeInPlace();
Vector forward;
me->EyeVectors( &forward );
if ( ( forward.x * toSentry.x + forward.y * toSentry.y ) > 0.95f )
{
if ( me->EquipLongRangeWeapon() == false )
{
return SuspendFor( new CTFBotRetreatToCover( 0.1f ), "No suitable range weapon available right now" );
}
me->PressFireButton();
m_isAttackingSentry = true;
}
else
{
m_isAttackingSentry = false;
}
if ( me->IsRangeGreaterThan( me->GetEnemySentry(), 1.1f * SENTRY_MAX_RANGE ) )
{
// safely out of range of the gun - hold here and fire at it
return Continue();
}
// we are in range of the gun - if it is pointed at us and firing, retreat to cover
if ( me->GetEnemySentry()->GetTimeSinceLastFired() < 1.0f )
{
Vector sentryForward;
AngleVectors( me->GetEnemySentry()->GetTurretAngles(), &sentryForward );
Vector to = me->GetAbsOrigin() - me->GetEnemySentry()->GetAbsOrigin();
to.NormalizeInPlace();
if ( DotProduct( to, sentryForward ) > 0.8f )
{
return SuspendFor( new CTFBotRetreatToCover( 0.1f ), "Taking cover from sentry fire" );
}
}
if ( isInAttackPosition )
{
// we're at our attack position, hold here
return Continue();
}
}
// move into position
if ( !m_path.IsValid() || m_repathTimer.IsElapsed() )
{
m_repathTimer.Start( 1.0f );
CTFBotPathCost cost( me, SAFEST_ROUTE );
Vector moveGoal = m_hasSafeAttackSpot ? m_safeAttackSpot : me->GetEnemySentry()->GetAbsOrigin();
if ( !m_path.Compute( me, moveGoal, cost ) )
{
return Done( "No path" );
}
}
// move along path to vantage point
m_path.Update( me );
return Continue();
}
//---------------------------------------------------------------------------------------------
ActionResult< CTFBot > CTFBotDestroyEnemySentry::OnResume( CTFBot *me, Action< CTFBot > *interruptingAction )
{
m_path.Invalidate();
m_repathTimer.Invalidate();
if ( me->IsPlayerClass( TF_CLASS_DEMOMAN ) )
{
ComputeCornerAttackSpot( me );
}
else
{
ComputeSafeAttackSpot( me );
}
return Continue();
}
//---------------------------------------------------------------------------------------------
QueryResultType CTFBotDestroyEnemySentry::ShouldHurry( const INextBot *me ) const
{
// while killing a sentry we're "hurrying" so we don't dodge
return m_isAttackingSentry ? ANSWER_YES : ANSWER_UNDEFINED;
}
//---------------------------------------------------------------------------------------------
QueryResultType CTFBotDestroyEnemySentry::ShouldRetreat( const INextBot *me ) const
{
// push in to kill the sentry
return ANSWER_NO;
}
//---------------------------------------------------------------------------------------------
QueryResultType CTFBotDestroyEnemySentry::ShouldAttack( const INextBot *me, const CKnownEntity *them ) const
{
// if we're in range to attack the sentry, we handle firing directly
return m_isAttackingSentry ? ANSWER_NO : ANSWER_UNDEFINED;
}
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
CTFBotUberAttackEnemySentry::CTFBotUberAttackEnemySentry( CObjectSentrygun *sentryTarget )
{
m_targetSentry = sentryTarget;
}
//---------------------------------------------------------------------------------------------
ActionResult< CTFBot > CTFBotUberAttackEnemySentry::OnStart( CTFBot *me, Action< CTFBot > *priorAction )
{
m_wasIgnoringEnemies = me->HasAttribute( CTFBot::IGNORE_ENEMIES );
me->SetAttribute( CTFBot::IGNORE_ENEMIES );
return Continue();
}
//---------------------------------------------------------------------------------------------
ActionResult< CTFBot > CTFBotUberAttackEnemySentry::Update( CTFBot *me, float interval )
{
if ( !me->m_Shared.InCond( TF_COND_INVULNERABLE ) )
{
return Done( "No longer uber" );
}
if ( m_targetSentry == NULL )
{
return Done( "Target sentry destroyed" );
}
float aimYaw, aimPitch;
if ( me->IsPlayerClass( TF_CLASS_DEMOMAN ) && FindGrenadeAim( me, m_targetSentry, &aimYaw, &aimPitch ) )
{
QAngle aimAngles;
aimAngles.x = aimPitch;
aimAngles.y = aimYaw;
aimAngles.z = 0.0f;
Vector aimForward;
AngleVectors( aimAngles, &aimForward );
// always recompute eye aim target so we can update our view
Vector eyeAimTarget = me->EyePosition() + 5000.0f * aimForward;
me->GetBodyInterface()->AimHeadTowards( eyeAimTarget, IBody::CRITICAL, 0.3f, NULL, "Aiming at opportunistic grenade shot" );
Vector eyeForward;
me->EyeVectors( &eyeForward );
if ( DotProduct( aimForward, eyeForward ) > 0.9f )
{
if ( me->EquipLongRangeWeapon() == false )
{
return SuspendFor( new CTFBotRetreatToCover( 0.1f ), "No suitable range weapon available right now" );
}
me->PressFireButton();
}
}
else if ( me->IsLineOfFireClear( m_targetSentry ) )
{
// must look at sentry entity to make use of SelectTargetPoint()
me->GetBodyInterface()->AimHeadTowards( m_targetSentry, IBody::MANDATORY, 1.0f, NULL, "Aiming at target sentry" );
// because sentries are stationary, check if XY is on target to allow SelectTargetPoint() to adjust Z for grenades
Vector toSentry = m_targetSentry->WorldSpaceCenter() - me->EyePosition();
toSentry.NormalizeInPlace();
Vector eyeForward;
me->EyeVectors( &eyeForward );
if ( ( eyeForward.x * toSentry.x + eyeForward.y * toSentry.y ) > 0.95f )
{
if ( me->EquipLongRangeWeapon() == false )
{
return SuspendFor( new CTFBotRetreatToCover( 0.1f ), "No suitable range weapon available right now" );
}
me->PressFireButton();
}
if ( me->IsRangeLessThan( m_targetSentry, 100.0f ) )
{
// we have a clear line of fire and are close enough
return Continue();
}
}
// move into position
if ( !m_path.IsValid() || m_repathTimer.IsElapsed() )
{
m_repathTimer.Start( 1.0f );
CTFBotPathCost cost( me, FASTEST_ROUTE );
m_path.Compute( me, m_targetSentry->WorldSpaceCenter(), cost );
}
m_path.Update( me );
return Continue();
}
//---------------------------------------------------------------------------------------------
void CTFBotUberAttackEnemySentry::OnEnd( CTFBot *me, Action< CTFBot > *nextAction )
{
if ( !m_wasIgnoringEnemies )
{
me->ClearAttribute( CTFBot::IGNORE_ENEMIES );
}
}
//---------------------------------------------------------------------------------------------
QueryResultType CTFBotUberAttackEnemySentry::ShouldHurry( const INextBot *me ) const
{
return ANSWER_YES;
}
//---------------------------------------------------------------------------------------------
QueryResultType CTFBotUberAttackEnemySentry::ShouldRetreat( const INextBot *me ) const
{
return ANSWER_NO;
}
//---------------------------------------------------------------------------------------------
QueryResultType CTFBotUberAttackEnemySentry::ShouldAttack( const INextBot *me, const CKnownEntity *them ) const
{
return ANSWER_YES;
}
|