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
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
|
//========= Copyright Valve Corporation, All rights reserved. ============//
// tf_bot.h
// Team Fortress NextBot
// Michael Booth, February 2009
#ifndef TF_BOT_H
#define TF_BOT_H
#include "Player/NextBotPlayer.h"
#include "../nav_mesh/tf_nav_mesh.h"
#include "tf_bot_vision.h"
#include "tf_bot_body.h"
#include "tf_bot_locomotion.h"
#include "tf_player.h"
#include "tf_bot_squad.h"
#include "bot/map_entities/tf_bot_proxy.h"
#include "tf_gamerules.h"
#include "entity_capture_flag.h"
#include "func_capture_zone.h"
#include "nav_entities.h"
#include "utlstack.h"
#define TF_BOT_TYPE 1337
class CTriggerAreaCapture;
class CTFBotActionPoint;
class CObjectSentrygun;
class CTFBotGenerator;
extern void BotGenerateAndWearItem( CTFPlayer *pBot, const char *itemName );
//----------------------------------------------------------------------------
// These must remain in sync with the bot_generator's spawnflags in tf.fgd:
#define TFBOT_IGNORE_ENEMY_SCOUTS 0x0001
#define TFBOT_IGNORE_ENEMY_SOLDIERS 0x0002
#define TFBOT_IGNORE_ENEMY_PYROS 0x0004
#define TFBOT_IGNORE_ENEMY_DEMOMEN 0x0008
#define TFBOT_IGNORE_ENEMY_HEAVIES 0x0010
#define TFBOT_IGNORE_ENEMY_MEDICS 0x0020
#define TFBOT_IGNORE_ENEMY_ENGINEERS 0x0040
#define TFBOT_IGNORE_ENEMY_SNIPERS 0x0080
#define TFBOT_IGNORE_ENEMY_SPIES 0x0100
#define TFBOT_IGNORE_ENEMY_SENTRY_GUNS 0x0200
#define TFBOT_IGNORE_SCENARIO_GOALS 0x0400
#define TFBOT_ALL_BEHAVIOR_FLAGS 0xFFFF
#define TFBOT_MVM_MAX_PATH_LENGTH 0.0f // 7000.0f // in MvM, all pathfinds are limited to this (0 == no limit)
//----------------------------------------------------------------------------
class CTFBot: public NextBotPlayer< CTFPlayer >, public CGameEventListener
{
public:
DECLARE_CLASS( CTFBot, NextBotPlayer< CTFPlayer > );
CTFBot();
virtual ~CTFBot();
virtual void Spawn();
virtual void FireGameEvent( IGameEvent *event );
virtual void Event_Killed( const CTakeDamageInfo &info );
virtual void PhysicsSimulate( void );
virtual void Touch( CBaseEntity *pOther );
virtual void AvoidPlayers( CUserCmd *pCmd ); // some game types allow players to pass through each other, this method pushes them apart
virtual void UpdateOnRemove( void );
virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo ) OVERRIDE;
virtual void ChangeTeam( int iTeamNum, bool bAutoTeam, bool bSilent, bool bAutoBalance = false ) OVERRIDE;
virtual bool ShouldGib( const CTakeDamageInfo &info ) OVERRIDE;
virtual int DrawDebugTextOverlays(void);
virtual bool IsAllowedToPickUpFlag( void ) const;
virtual void InitClass( void ); // set health/etc
void ModifyMaxHealth( int nNewMaxHealth, bool bSetCurrentHealth = true, bool bAllowModelScaling = true );
virtual int GetBotType( void ) const; // return a unique int representing the type of bot instance this is
virtual CTFNavArea *GetLastKnownArea( void ) const { return static_cast< CTFNavArea * >( BaseClass::GetLastKnownArea() ); } // return the last nav area the player occupied - NULL if unknown
// NextBotPlayer
static CBasePlayer *AllocatePlayerEntity( edict_t *pEdict, const char *playerName );
virtual void PressFireButton( float duration = -1.0f ) OVERRIDE;
virtual void PressAltFireButton( float duration = -1.0f ) OVERRIDE;
virtual void PressSpecialFireButton( float duration = -1.0f ) OVERRIDE;
// INextBot
virtual CTFBotLocomotion *GetLocomotionInterface( void ) const { return m_locomotor; }
virtual CTFBotBody *GetBodyInterface( void ) const { return m_body; }
virtual CTFBotVision *GetVisionInterface( void ) const { return m_vision; }
DECLARE_INTENTION_INTERFACE( CTFBot );
virtual bool IsDormantWhenDead( void ) const; // should this player-bot continue to update itself when dead (respawn logic, etc)
virtual void OnWeaponFired( CBaseCombatCharacter *whoFired, CBaseCombatWeapon *weapon ); // when someone fires their weapon
virtual bool IsDebugFilterMatch( const char *name ) const; // return true if we match the given debug symbol
virtual int GetAllowedTauntPartnerTeam() const OVERRIDE { return GetTeamNumber(); }
// CTFBot specific
CTeamControlPoint *GetMyControlPoint( void ) const; // return point we want to capture, or need to defend
void ClearMyControlPoint( void );
bool WasPointJustLost( void ) const; // return true if we just lost territory recently
bool AreAllPointsUncontestedSoFar( void ) const; // return true if no enemy has contested any point yet
bool IsPointBeingCaptured( CTeamControlPoint *point ) const; // return true if the given point is being captured
bool IsAnyPointBeingCaptured( void ) const; // return true if any point is being captured
bool IsNearPoint( CTeamControlPoint *point ) const; // return true if we are within a short travel distance of the current point
float GetTimeLeftToCapture( void ) const; // return time left to capture the point before we lose the game
CCaptureFlag *GetFlagToFetch( void ) const; // return flag we want to fetch
CCaptureZone *GetFlagCaptureZone( void ) const; // return capture zone for our flag(s)
struct SniperSpotInfo
{
CTFNavArea *m_vantageArea;
Vector m_vantageSpot;
CTFNavArea *m_theaterArea;
Vector m_theaterSpot;
float m_range;
float m_advantage; // the difference in how long it takes us to reach our vantage spot vs them to reach the theater spot
};
void AccumulateSniperSpots( void ); // find good sniping spots and store them
const CUtlVector< SniperSpotInfo > *GetSniperSpots( void ) const; // return vector of good sniping positions
bool HasSniperSpots( void ) const;
void ClearSniperSpots( void );
// search outwards from startSearchArea and collect all reachable objects from the given list that pass the given filter
void SelectReachableObjects( const CUtlVector< CHandle< CBaseEntity > > &candidateObjectVector, CUtlVector< CHandle< CBaseEntity > > *selectedObjectVector, const INextBotFilter &filter, CNavArea *startSearchArea, float maxRange = 2000.0f ) const;
CBaseEntity *FindClosestReachableObject( const char *objectName, CNavArea *from, float maxRange = 2000.0f ) const;
CTFNavArea *GetSpawnArea( void ) const; // get area where we spawned in
bool IsAmmoLow( void ) const;
bool IsAmmoFull( void ) const;
void UpdateLookingAroundForEnemies( void ); // update our view to keep an eye on enemies, and where enemies come from
#define LOOK_FOR_FRIENDS false
#define LOOK_FOR_ENEMIES true
void UpdateLookingAroundForIncomingPlayers( bool lookForEnemies ); // update our view to watch where friends or enemies will be coming from
void StartLookingAroundForEnemies( void ); // enable updating view for enemy searching
void StopLookingAroundForEnemies( void ); // disable updating view for enemy searching
void SetAttentionFocus( CBaseEntity *focusOn ); // restrict bot's attention to only this entity (or radius around this entity) to the exclusion of everything else
void ClearAttentionFocus( void ); // remove attention focus restrictions
bool IsAttentionFocused( void ) const;
bool IsAttentionFocusedOn( CBaseEntity *who ) const;
void DelayedThreatNotice( CHandle< CBaseEntity > who, float noticeDelay ); // notice the given threat after the given number of seconds have elapsed
void UpdateDelayedThreatNotices( void );
CTFNavArea *FindVantagePoint( float maxTravelDistance = 2000.0f ) const; // return a nearby area where we can see a member of the enemy team
const char *GetNextSpawnClassname( void ) const;
float GetThreatDanger( CBaseCombatCharacter *who ) const; // return perceived danger of threat (0=none, 1=immediate deadly danger)
float GetMaxAttackRange( void ) const; // return the max range at which we can effectively attack
float GetDesiredAttackRange( void ) const; // return the ideal range at which we can effectively attack
bool EquipRequiredWeapon( void ); // if we're required to equip a specific weapon, do it.
void EquipBestWeaponForThreat( const CKnownEntity *threat ); // equip the best weapon we have to attack the given threat
bool EquipLongRangeWeapon( void ); // equip a weapon that can damage far-away targets
void PushRequiredWeapon( CTFWeaponBase *weapon ); // force us to equip and use this weapon until popped off the required stack
void PopRequiredWeapon( void ); // pop top required weapon off of stack and discard
#define MY_CURRENT_GUN NULL // can be passed as weapon to following queries
bool IsCombatWeapon( CTFWeaponBase *weapon ) const; // return true if given weapon can be used to attack
bool IsHitScanWeapon( CTFWeaponBase *weapon ) const; // return true if given weapon is a "hitscan" weapon (scattered tracelines with instant damage)
bool IsContinuousFireWeapon( CTFWeaponBase *weapon ) const; // return true if given weapon "sprays" bullets/fire/etc continuously (ie: not individual rockets/etc)
bool IsExplosiveProjectileWeapon( CTFWeaponBase *weapon ) const;// return true if given weapon launches explosive projectiles with splash damage
bool IsBarrageAndReloadWeapon( CTFWeaponBase *weapon ) const; // return true if given weapon has small clip and long reload cost (ie: rocket launcher, etc)
bool IsQuietWeapon( CTFWeaponBase *weapon ) const; // return true if given weapon doesn't make much sound when used (ie: spy knife, etc)
bool IsEnvironmentNoisy( void ) const; // return true if there are/have been loud noises (ie: non-quiet weapons) nearby very recently
enum WeaponRestrictionType
{
ANY_WEAPON = 0,
MELEE_ONLY = 0x0001,
PRIMARY_ONLY = 0x0002,
SECONDARY_ONLY = 0x0004,
};
void ClearWeaponRestrictions( void );
void SetWeaponRestriction( int restrictionFlags );
bool HasWeaponRestriction( int restrictionFlags ) const;
bool IsWeaponRestricted( CTFWeaponBase *weapon ) const;
bool ShouldFireCompressionBlast( void );
bool IsLineOfFireClear( const Vector &where ) const; // return true if a weapon has no obstructions along the line from our eye to the given position
bool IsLineOfFireClear( CBaseEntity *who ) const; // return true if a weapon has no obstructions along the line from our eye to the given entity
bool IsLineOfFireClear( const Vector &from, const Vector &to ) const; // return true if a weapon has no obstructions along the line between the given points
bool IsLineOfFireClear( const Vector &from, CBaseEntity *who ) const; // return true if a weapon has no obstructions along the line between the given point and entity
bool IsEntityBetweenTargetAndSelf( CBaseEntity *other, CBaseEntity *target ); // return true if "other" is positioned inbetween us and "target"
class SuspectedSpyInfo_t
{
public:
bool IsCurrentlySuspected();
void Suspect(); // The verb form of the word, not the noun.
bool TestForRealizing();
CHandle< CTFPlayer > m_suspectedSpy;
private:
CUtlVector< int > m_touchTimes;
};
bool IsKnownSpy( CTFPlayer *player ) const; // return true if we are sure this player actually is an enemy spy
SuspectedSpyInfo_t* IsSuspectedSpy( CTFPlayer *player ); // return true if we suspect this player might be an enemy spy
void SuspectSpy( CTFPlayer *player ); // note that this player might be a spy
void RealizeSpy( CTFPlayer *player ); // note that this player *IS* a spy
void ForgetSpy( CTFPlayer *player ); // remove player from spy suspect system
void StopSuspectingSpy( CTFPlayer *pPlayer );
CTFPlayer *GetClosestHumanLookingAtMe( int team = TEAM_ANY ) const; // return the nearest human player on the given team who is looking directly at me
enum AttributeType
{
REMOVE_ON_DEATH = 1<<0, // kick bot from server when killed
AGGRESSIVE = 1<<1, // in MvM mode, push for the cap point
IS_NPC = 1<<2, // a non-player support character
SUPPRESS_FIRE = 1<<3,
DISABLE_DODGE = 1<<4,
BECOME_SPECTATOR_ON_DEATH = 1<<5, // move bot to spectator team when killed
QUOTA_MANANGED = 1<<6, // managed by the bot quota in CTFBotManager
RETAIN_BUILDINGS = 1<<7, // don't destroy this bot's buildings when it disconnects
SPAWN_WITH_FULL_CHARGE = 1<<8, // all weapons start with full charge (ie: uber)
ALWAYS_CRIT = 1<<9, // always fire critical hits
IGNORE_ENEMIES = 1<<10,
HOLD_FIRE_UNTIL_FULL_RELOAD = 1<<11, // don't fire our barrage weapon until it is full reloaded (rocket launcher, etc)
PRIORITIZE_DEFENSE = 1<<12, // bot prioritizes defending when possible
ALWAYS_FIRE_WEAPON = 1<<13, // constantly fire our weapon
TELEPORT_TO_HINT = 1<<14, // bot will teleport to hint target instead of walking out from the spawn point
MINIBOSS = 1<<15, // is miniboss?
USE_BOSS_HEALTH_BAR = 1<<16, // should I use boss health bar?
IGNORE_FLAG = 1<<17, // don't pick up flag/bomb
AUTO_JUMP = 1<<18, // auto jump
AIR_CHARGE_ONLY = 1<<19, // demo knight only charge in the air
PREFER_VACCINATOR_BULLETS = 1<<20, // When using the vaccinator, prefer to use the bullets shield
PREFER_VACCINATOR_BLAST = 1<<21, // When using the vaccinator, prefer to use the blast shield
PREFER_VACCINATOR_FIRE = 1<<22, // When using the vaccinator, prefer to use the fire shield
BULLET_IMMUNE = 1<<23, // Has a shield that makes the bot immune to bullets
BLAST_IMMUNE = 1<<24, // "" blast
FIRE_IMMUNE = 1<<25, // "" fire
PARACHUTE = 1<<26, // demo/soldier parachute when falling
PROJECTILE_SHIELD = 1<<27, // medic projectile shield
};
void SetAttribute( int attributeFlag );
void ClearAttribute( int attributeFlag );
void ClearAllAttributes();
bool HasAttribute( int attributeFlag ) const;
enum DifficultyType
{
UNDEFINED = -1,
EASY = 0,
NORMAL = 1,
HARD = 2,
EXPERT = 3,
NUM_DIFFICULTY_LEVELS
};
DifficultyType GetDifficulty( void ) const;
void SetDifficulty( DifficultyType difficulty );
bool IsDifficulty( DifficultyType skill ) const;
void SetHomeArea( CTFNavArea *area );
CTFNavArea *GetHomeArea( void ) const;
CObjectSentrygun *GetEnemySentry( void ) const; // if we've been attacked/killed by an enemy sentry, this will return it, otherwise NULL
void RememberEnemySentry( CObjectSentrygun *sentry, const Vector &injurySpot );
const Vector &GetSpotWhereEnemySentryLastInjuredMe( void ) const;
void SetActionPoint( CTFBotActionPoint *point );
CTFBotActionPoint *GetActionPoint( void ) const;
bool HasProxy( void ) const;
void SetProxy( CTFBotProxy *proxy ); // attach this bot to a bot_proxy entity for map I/O communications
CTFBotProxy *GetProxy( void ) const;
bool HasSpawner( void ) const;
void SetSpawner( CTFBotGenerator *spawner );
CTFBotGenerator *GetSpawner( void ) const;
void JoinSquad( CTFBotSquad *squad ); // become a member of the given squad
void LeaveSquad( void ); // leave our current squad
void DeleteSquad( void );
bool IsInASquad( void ) const;
bool IsSquadmate( CTFPlayer *who ) const; // return true if given bot is in my squad
CTFBotSquad *GetSquad( void ) const; // return squad we are in, or NULL
float GetSquadFormationError( void ) const; // return normalized error term where 0 = in formation position and 1 = completely out of position
void SetSquadFormationError( float error );
bool HasBrokenFormation( void ) const; // return true if this bot is far out of formation, or has no path back
void SetBrokenFormation( bool state );
float TransientlyConsistentRandomValue( float period = 10.0f, int seedValue = 0 ) const; // compute a pseudo random value (0-1) that stays consistent for the given period of time, but changes unpredictably each period
void SetBehaviorFlag( unsigned int flags );
void ClearBehaviorFlag( unsigned int flags );
bool IsBehaviorFlagSet( unsigned int flags ) const;
bool FindSplashTarget( CBaseEntity *target, float maxSplashRadius, Vector *splashTarget ) const;
void GiveRandomItem( loadout_positions_t loadoutPosition );
enum MissionType
{
NO_MISSION = 0,
MISSION_SEEK_AND_DESTROY, // focus on finding and killing enemy players
MISSION_DESTROY_SENTRIES, // focus on finding and destroying enemy sentry guns (and buildings)
MISSION_SNIPER, // maintain teams of snipers harassing the enemy
MISSION_SPY, // maintain teams of spies harassing the enemy
MISSION_ENGINEER, // maintain engineer nests for harassing the enemy
MISSION_REPROGRAMMED, // MvM: robot has been hacked and will do bad things to their team
};
#define MISSION_DOESNT_RESET_BEHAVIOR_SYSTEM false
void SetMission( MissionType mission, bool resetBehaviorSystem = true );
void SetPrevMission( MissionType mission );
MissionType GetMission( void ) const;
MissionType GetPrevMission( void ) const;
bool HasMission( MissionType mission ) const;
bool IsOnAnyMission( void ) const;
void SetMissionTarget( CBaseEntity *target );
CBaseEntity *GetMissionTarget( void ) const;
void SetMissionString( CUtlString string );
CUtlString *GetMissionString( void );
void SetTeleportWhere( const CUtlStringList& teleportWhereName );
const CUtlStringList& GetTeleportWhere();
void ClearTeleportWhere();
void SetScaleOverride( float fScale );
void SetMaxVisionRangeOverride( float range );
float GetMaxVisionRangeOverride( void ) const;
void DisguiseAsMemberOfEnemyTeam( void ); // set Spy disguise to be a class that someone on the enemy team is actually using
CBaseObject *GetNearestKnownSappableTarget( void );
void ClearTags( void );
void AddTag( const char *tag );
void RemoveTag( const char *tag );
bool HasTag( const char *tag );
Action< CTFBot > *OpportunisticallyUseWeaponAbilities( void );
CTFPlayer *SelectRandomReachableEnemy( void ); // mostly for MvM - pick a random enemy player that is not in their spawn room
float GetDesiredPathLookAheadRange( void ) const; // different sized bots used different lookahead distances
void StartIdleSound( void );
void StopIdleSound( void );
bool ShouldQuickBuild() const { return m_bForceQuickBuild; }
void SetShouldQuickBuild( bool bShouldQuickBuild ) { m_bForceQuickBuild = bShouldQuickBuild; }
void SetAutoJump( float flAutoJumpMin, float flAutoJumpMax ) { m_flAutoJumpMin = flAutoJumpMin; m_flAutoJumpMax = flAutoJumpMax; }
bool ShouldAutoJump();
void SetFlagTarget( CCaptureFlag* pFlag );
CCaptureFlag* GetFlagTarget() const { return m_hFollowingFlagTarget; }
bool HasFlagTaget() const { return m_hFollowingFlagTarget != NULL; }
struct EventChangeAttributes_t
{
EventChangeAttributes_t()
{
Reset();
}
EventChangeAttributes_t( const EventChangeAttributes_t& copy )
{
Reset();
m_eventName = copy.m_eventName;
m_skill = copy.m_skill;
m_weaponRestriction = copy.m_weaponRestriction;
m_mission = copy.m_mission;
m_prevMission = copy.m_prevMission;
m_attributeFlags = copy.m_attributeFlags;
m_maxVisionRange = copy.m_maxVisionRange;
for ( int i=0; i<copy.m_items.Count(); ++i )
{
m_items.CopyAndAddToTail( copy.m_items[i] );
}
m_itemsAttributes = copy.m_itemsAttributes;
m_characterAttributes = copy.m_characterAttributes;
for ( int i=0; i<copy.m_tags.Count(); ++i )
{
m_tags.CopyAndAddToTail( copy.m_tags[i] );
}
}
void Reset()
{
m_eventName = "default";
m_skill = CTFBot::EASY;
m_weaponRestriction = CTFBot::ANY_WEAPON;
m_mission = CTFBot::NO_MISSION;
m_prevMission = m_mission;
m_attributeFlags = 0;
m_maxVisionRange = -1.f;
m_items.RemoveAll();
m_itemsAttributes.RemoveAll();
m_characterAttributes.RemoveAll();
m_tags.RemoveAll();
}
CUtlString m_eventName;
DifficultyType m_skill;
WeaponRestrictionType m_weaponRestriction;
MissionType m_mission;
MissionType m_prevMission;
int m_attributeFlags;
float m_maxVisionRange;
CUtlStringList m_items;
struct item_attributes_t
{
CUtlString m_itemName;
CCopyableUtlVector< static_attrib_t > m_attributes;
};
CUtlVector< item_attributes_t > m_itemsAttributes;
CUtlVector< static_attrib_t > m_characterAttributes;
CUtlStringList m_tags;
};
void ClearEventChangeAttributes() { m_eventChangeAttributes.RemoveAll(); }
void AddEventChangeAttributes( const EventChangeAttributes_t* newEvent );
const EventChangeAttributes_t* GetEventChangeAttributes( const char* pszEventName ) const;
void OnEventChangeAttributes( const CTFBot::EventChangeAttributes_t* pEvent );
void AddItem( const char* pszItemName );
int GetUberHealthThreshold();
float GetUberDeployDelayDuration();
private:
CTFBotLocomotion *m_locomotor;
CTFBotBody *m_body;
CTFBotVision *m_vision;
CountdownTimer m_lookAtEnemyInvasionAreasTimer;
CTFNavArea *m_spawnArea; // where we spawned
CountdownTimer m_justLostPointTimer;
int m_weaponRestrictionFlags;
int m_attributeFlags;
DifficultyType m_difficulty;
CTFNavArea *m_homeArea;
CHandle< CTFBotActionPoint > m_actionPoint;
CHandle< CTFBotProxy > m_proxy;
CHandle< CTFBotGenerator > m_spawner;
CTFBotSquad *m_squad;
bool m_didReselectClass;
CHandle< CObjectSentrygun > m_enemySentry;
Vector m_spotWhereEnemySentryLastInjuredMe; // the last position where I was injured by an enemy sentry
CUtlVector< SuspectedSpyInfo_t* > m_suspectedSpyVector;
CUtlVector< CHandle< CTFPlayer > > m_knownSpyVector;
CUtlVector< SniperSpotInfo > m_sniperSpotVector; // collection of good sniping spots for the current objective
CUtlVector< CTFNavArea * > m_sniperVantageAreaVector;
CUtlVector< CTFNavArea * > m_sniperTheaterAreaVector;
CBaseEntity *m_snipingGoalEntity; // the entity we are guarding (control point, payload cart)
Vector m_lastSnipingGoalEntityPosition;
void SetupSniperSpotAccumulation( void ); // do internal setup when control point changes
CountdownTimer m_retrySniperSpotSetupTimer;
bool m_isLookingAroundForEnemies;
unsigned int m_behaviorFlags; // spawnflags from the bot_generator that spawned us
CUtlVector< CFmtStr > m_tags;
CHandle< CBaseEntity > m_attentionFocusEntity;
CTeamControlPoint *SelectPointToCapture( CUtlVector< CTeamControlPoint * > *captureVector ) const;
CTeamControlPoint *SelectPointToDefend( CUtlVector< CTeamControlPoint * > *defendVector ) const;
mutable CHandle< CTeamControlPoint > m_myControlPoint;
mutable CountdownTimer m_evaluateControlPointTimer;
float m_fModelScaleOverride;
MissionType m_mission;
MissionType m_prevMission;
CHandle< CBaseEntity > m_missionTarget;
CUtlString m_missionString;
CUtlStack< CHandle<CTFWeaponBase> > m_requiredWeaponStack; // if non-empty, bot must equip the weapon on top of the stack
CountdownTimer m_noisyTimer;
struct DelayedNoticeInfo
{
CHandle< CBaseEntity > m_who;
float m_when;
};
CUtlVector< DelayedNoticeInfo > m_delayedNoticeVector;
float m_maxVisionRangeOverride;
CountdownTimer m_opportunisticTimer;
CSoundPatch *m_pIdleSound;
float m_squadFormationError;
bool m_hasBrokenFormation;
CUtlStringList m_teleportWhereName; // spawn name an engineer mission teleporter will override
bool m_bForceQuickBuild;
float m_flAutoJumpMin;
float m_flAutoJumpMax;
CountdownTimer m_autoJumpTimer;
CHandle< CCaptureFlag > m_hFollowingFlagTarget;
CUtlVector< const EventChangeAttributes_t* > m_eventChangeAttributes;
};
inline void CTFBot::SetTeleportWhere( const CUtlStringList& teleportWhereName )
{
// deep copy strings
for ( int i=0; i<teleportWhereName.Count(); ++i )
{
m_teleportWhereName.CopyAndAddToTail( teleportWhereName[i] );
}
}
inline const CUtlStringList& CTFBot::GetTeleportWhere()
{
return m_teleportWhereName;
}
inline void CTFBot::ClearTeleportWhere()
{
m_teleportWhereName.RemoveAll();
}
inline void CTFBot::SetMissionString( CUtlString string )
{
m_missionString = string;
}
inline CUtlString *CTFBot::GetMissionString( void )
{
return &m_missionString;
}
inline void CTFBot::SetMissionTarget( CBaseEntity *target )
{
m_missionTarget = target;
}
inline CBaseEntity *CTFBot::GetMissionTarget( void ) const
{
return m_missionTarget;
}
inline float CTFBot::GetSquadFormationError( void ) const
{
return m_squadFormationError;
}
inline void CTFBot::SetSquadFormationError( float error )
{
m_squadFormationError = error;
}
inline bool CTFBot::HasBrokenFormation( void ) const
{
return m_hasBrokenFormation;
}
inline void CTFBot::SetBrokenFormation( bool state )
{
m_hasBrokenFormation = state;
}
inline void CTFBot::SetMaxVisionRangeOverride( float range )
{
m_maxVisionRangeOverride = range;
}
inline float CTFBot::GetMaxVisionRangeOverride( void ) const
{
return m_maxVisionRangeOverride;
}
inline void CTFBot::SetBehaviorFlag( unsigned int flags )
{
m_behaviorFlags |= flags;
}
inline void CTFBot::ClearBehaviorFlag( unsigned int flags )
{
m_behaviorFlags &= ~flags;
}
inline bool CTFBot::IsBehaviorFlagSet( unsigned int flags ) const
{
return ( m_behaviorFlags & flags ) ? true : false;
}
inline void CTFBot::StartLookingAroundForEnemies( void )
{
m_isLookingAroundForEnemies = true;
}
inline void CTFBot::StopLookingAroundForEnemies( void )
{
m_isLookingAroundForEnemies = false;
}
inline int CTFBot::GetBotType( void ) const
{
return TF_BOT_TYPE;
}
inline void CTFBot::RememberEnemySentry( CObjectSentrygun *sentry, const Vector &injurySpot )
{
m_enemySentry = sentry;
m_spotWhereEnemySentryLastInjuredMe = injurySpot;
}
inline CObjectSentrygun *CTFBot::GetEnemySentry( void ) const
{
return m_enemySentry;
}
inline const Vector &CTFBot::GetSpotWhereEnemySentryLastInjuredMe( void ) const
{
return m_spotWhereEnemySentryLastInjuredMe;
}
inline CTFBot::DifficultyType CTFBot::GetDifficulty( void ) const
{
return m_difficulty;
}
inline void CTFBot::SetDifficulty( CTFBot::DifficultyType difficulty )
{
m_difficulty = difficulty;
m_nBotSkill = m_difficulty;
}
inline bool CTFBot::IsDifficulty( DifficultyType skill ) const
{
return skill == m_difficulty;
}
inline bool CTFBot::HasProxy( void ) const
{
return m_proxy == NULL ? false : true;
}
inline void CTFBot::SetProxy( CTFBotProxy *proxy )
{
m_proxy = proxy;
}
inline CTFBotProxy *CTFBot::GetProxy( void ) const
{
return m_proxy;
}
inline bool CTFBot::HasSpawner( void ) const
{
return m_spawner == NULL ? false : true;
}
inline void CTFBot::SetSpawner( CTFBotGenerator *spawner )
{
m_spawner = spawner;
}
inline CTFBotGenerator *CTFBot::GetSpawner( void ) const
{
return m_spawner;
}
inline void CTFBot::SetActionPoint( CTFBotActionPoint *point )
{
m_actionPoint = point;
}
inline CTFBotActionPoint *CTFBot::GetActionPoint( void ) const
{
return m_actionPoint;
}
inline bool CTFBot::IsInASquad( void ) const
{
return m_squad == NULL ? false : true;
}
inline CTFBotSquad *CTFBot::GetSquad( void ) const
{
return m_squad;
}
inline void CTFBot::SetHomeArea( CTFNavArea *area )
{
m_homeArea = area;
}
inline CTFNavArea *CTFBot::GetHomeArea( void ) const
{
return m_homeArea;
}
inline void CTFBot::ClearWeaponRestrictions( void )
{
m_weaponRestrictionFlags = 0;
}
inline void CTFBot::SetWeaponRestriction( int restrictionFlags )
{
m_weaponRestrictionFlags |= restrictionFlags;
}
inline bool CTFBot::HasWeaponRestriction( int restrictionFlags ) const
{
return m_weaponRestrictionFlags & restrictionFlags ? true : false;
}
inline void CTFBot::SetAttribute( int attributeFlag )
{
m_attributeFlags |= attributeFlag;
}
inline void CTFBot::ClearAttribute( int attributeFlag )
{
m_attributeFlags &= ~attributeFlag;
}
inline void CTFBot::ClearAllAttributes()
{
m_attributeFlags = 0;
}
inline bool CTFBot::HasAttribute( int attributeFlag ) const
{
return m_attributeFlags & attributeFlag ? true : false;
}
inline CTFNavArea *CTFBot::GetSpawnArea( void ) const
{
return m_spawnArea;
}
inline bool CTFBot::WasPointJustLost( void ) const
{
return m_justLostPointTimer.HasStarted() && !m_justLostPointTimer.IsElapsed();
}
inline const CUtlVector< CTFBot::SniperSpotInfo > *CTFBot::GetSniperSpots( void ) const
{
return &m_sniperSpotVector;
}
inline bool CTFBot::HasSniperSpots( void ) const
{
return m_sniperSpotVector.Count() > 0 ? true : false;
}
inline CTFBot::MissionType CTFBot::GetMission( void ) const
{
return m_mission;
}
inline void CTFBot::SetPrevMission( MissionType mission )
{
m_prevMission = mission;
}
inline CTFBot::MissionType CTFBot::GetPrevMission( void ) const
{
return m_prevMission;
}
inline bool CTFBot::HasMission( MissionType mission ) const
{
return m_mission == mission ? true : false;
}
inline bool CTFBot::IsOnAnyMission( void ) const
{
return m_mission == NO_MISSION ? false : true;
}
inline void CTFBot::SetScaleOverride( float fScale )
{
m_fModelScaleOverride = fScale;
SetModelScale( m_fModelScaleOverride > 0.0f ? m_fModelScaleOverride : 1.0f );
}
inline bool CTFBot::IsEnvironmentNoisy( void ) const
{
return !m_noisyTimer.IsElapsed();
}
//---------------------------------------------------------------------------------------------
inline CTFBot *ToTFBot( CBaseEntity *pEntity )
{
if ( !pEntity || !pEntity->IsPlayer() || !ToTFPlayer( pEntity )->IsBotOfType( TF_BOT_TYPE ) )
return NULL;
Assert( "***IMPORTANT!!! DONT IGNORE ME!!!***" && dynamic_cast< CTFBot * >( pEntity ) != 0 );
return static_cast< CTFBot * >( pEntity );
}
//---------------------------------------------------------------------------------------------
inline const CTFBot *ToTFBot( const CBaseEntity *pEntity )
{
if ( !pEntity || !pEntity->IsPlayer() || !ToTFPlayer( const_cast< CBaseEntity * >( pEntity ) )->IsBotOfType( TF_BOT_TYPE ) )
return NULL;
Assert( "***IMPORTANT!!! DONT IGNORE ME!!!***" && dynamic_cast< const CTFBot * >( pEntity ) != 0 );
return static_cast< const CTFBot * >( pEntity );
}
//--------------------------------------------------------------------------------------------------------------
/**
* Functor used with NavAreaBuildPath()
*/
class CTFBotPathCost : public IPathCost
{
public:
CTFBotPathCost( CTFBot *me, RouteType routeType )
{
m_me = me;
m_routeType = routeType;
m_stepHeight = me->GetLocomotionInterface()->GetStepHeight();
m_maxJumpHeight = me->GetLocomotionInterface()->GetMaxJumpHeight();
m_maxDropHeight = me->GetLocomotionInterface()->GetDeathDropHeight();
}
virtual float operator()( CNavArea *baseArea, CNavArea *fromArea, const CNavLadder *ladder, const CFuncElevator *elevator, float length ) const
{
VPROF_BUDGET( "CTFBotPathCost::operator()", "NextBot" );
CTFNavArea *area = (CTFNavArea *)baseArea;
if ( fromArea == NULL )
{
// first area in path, no cost
return 0.0f;
}
else
{
if ( !m_me->GetLocomotionInterface()->IsAreaTraversable( area ) )
{
return -1.0f;
}
// in training, avoid capturing the point until the human trainee does so
if ( TFGameRules()->IsInTraining() &&
area->HasAttributeTF( TF_NAV_CONTROL_POINT ) &&
!m_me->IsAnyPointBeingCaptured() &&
!m_me->IsPlayerClass( TF_CLASS_ENGINEER ) ) // allow engineers to path so they can test travel distance for sentry placement
{
return -1.0f;
}
// don't path through enemy spawn rooms
if ( ( m_me->GetTeamNumber() == TF_TEAM_RED && area->HasAttributeTF( TF_NAV_SPAWN_ROOM_BLUE ) ) ||
( m_me->GetTeamNumber() == TF_TEAM_BLUE && area->HasAttributeTF( TF_NAV_SPAWN_ROOM_RED ) ) )
{
if ( !TFGameRules()->RoundHasBeenWon() )
{
return -1.0f;
}
}
// compute distance traveled along path so far
float dist;
if ( ladder )
{
dist = ladder->m_length;
}
else if ( length > 0.0 )
{
dist = length;
}
else
{
dist = ( area->GetCenter() - fromArea->GetCenter() ).Length();
}
// check height change
float deltaZ = fromArea->ComputeAdjacentConnectionHeightChange( area );
if ( deltaZ >= m_stepHeight )
{
if ( deltaZ >= m_maxJumpHeight )
{
// too high to reach
return -1.0f;
}
// jumping is slower than flat ground
const float jumpPenalty = 2.0f;
dist *= jumpPenalty;
}
else if ( deltaZ < -m_maxDropHeight )
{
// too far to drop
return -1.0f;
}
// add a random penalty unique to this character so they choose different routes to the same place
float preference = 1.0f;
if ( m_routeType == DEFAULT_ROUTE && !m_me->IsMiniBoss() )
{
// this term causes the same bot to choose different routes over time,
// but keep the same route for a period in case of repaths
int timeMod = (int)( gpGlobals->curtime / 10.0f ) + 1;
preference = 1.0f + 50.0f * ( 1.0f + FastCos( (float)( m_me->GetEntity()->entindex() * area->GetID() * timeMod ) ) );
}
if ( m_routeType == SAFEST_ROUTE )
{
// avoid combat areas
if ( area->IsInCombat() )
{
const float combatDangerCost = 4.0f;
dist *= combatDangerCost * area->GetCombatIntensity();
}
// if this area exposes us to enemy sentry fire, avoid it
const float sentryDangerCost = 5.0f;
if ( ( m_me->GetTeamNumber() == TF_TEAM_RED && area->HasAttributeTF( TF_NAV_BLUE_SENTRY_DANGER ) ) ||
( m_me->GetTeamNumber() == TF_TEAM_BLUE && area->HasAttributeTF( TF_NAV_RED_SENTRY_DANGER ) ) )
{
dist *= sentryDangerCost;
}
}
if ( m_me->IsPlayerClass( TF_CLASS_SPY ) )
{
int enemyTeam = GetEnemyTeam( m_me->GetTeamNumber() );
// Since spies can get right up to enemy buildings, avoid them.
for ( int oit = 0; oit < IBaseObjectAutoList::AutoList().Count(); ++oit )
{
CBaseObject *enemyObj = static_cast< CBaseObject* >( IBaseObjectAutoList::AutoList()[ oit ] );
if ( ( enemyObj->ObjectType() == OBJ_SENTRYGUN ) &&
( enemyObj->GetTeamNumber() == enemyTeam ) )
{
enemyObj->UpdateLastKnownArea();
if ( enemyObj->GetLastKnownArea() == area )
{
// There is an enemy building in this area - avoid it as a spy.
const float enemyBuildingCost = 10.0f;
dist *= enemyBuildingCost;
}
}
}
// Spies avoid teammates, since they draw attention and gunfire.
const float teammateCost = 10.0f;
dist += dist * teammateCost * area->GetPlayerCount( m_me->GetTeamNumber() );
// We shouldn't be getting NaNs here. It will be handled when we return, but ideally
// it should be fixed here and not just worked around in NavAreaBuildPath.
DebuggerBreakOnNaN_StagingOnly( dist );
}
float cost = ( dist * preference );
if ( area->HasAttributes( NAV_MESH_FUNC_COST ) )
{
cost *= area->ComputeFuncNavCost( m_me );
DebuggerBreakOnNaN_StagingOnly( cost );
}
return cost + fromArea->GetCostSoFar();
}
}
CTFBot *m_me;
RouteType m_routeType;
float m_stepHeight;
float m_maxJumpHeight;
float m_maxDropHeight;
};
//---------------------------------------------------------------------------------------------
class CClosestTFPlayer
{
public:
CClosestTFPlayer( const Vector &where, int team = TEAM_ANY )
{
m_where = where;
m_closeRangeSq = FLT_MAX;
m_closePlayer = NULL;
m_team = team;
}
CClosestTFPlayer( CBaseEntity *entity, int team = TEAM_ANY )
{
m_where = entity->WorldSpaceCenter();
m_closeRangeSq = FLT_MAX;
m_closePlayer = NULL;
m_team = team;
}
bool operator() ( CBasePlayer *player )
{
if ( !player->IsAlive() )
return true;
if ( player->GetTeamNumber() != TF_TEAM_RED && player->GetTeamNumber() != TF_TEAM_BLUE )
return true;
if ( m_team != TEAM_ANY && player->GetTeamNumber() != m_team )
return true;
CTFBot *bot = ToTFBot( player );
if ( bot && bot->HasAttribute( CTFBot::IS_NPC ) )
return true;
float rangeSq = ( m_where - player->GetAbsOrigin() ).LengthSqr();
if ( rangeSq < m_closeRangeSq )
{
m_closeRangeSq = rangeSq;
m_closePlayer = player;
}
return true;
}
Vector m_where;
float m_closeRangeSq;
CBasePlayer *m_closePlayer;
int m_team;
};
#endif // TF_BOT_H
|