-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBotManager.as
2767 lines (2235 loc) · 60.4 KB
/
BotManager.as
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
/*
* Bot manager plugin
* This is a sample script.
*/
#include "BotManagerInterface"
#include "BotWaypoint"
#include "CBotTasks"
#include "UtilFuncs"
#include "BotWeapons"
#include "CBotBits"
#include "BotVisibles"
#include "BotCommands"
BotManager::BotManager g_BotManager( @CreateRCBot );
const int PRIORITY_NONE = 0;
const int PRIORITY_WAYPOINT = 1;
const int PRIORITY_LISTEN = 2;
const int PRIORITY_LAST_SEE_ENEMY = 3;
const int PRIORITY_TASK = 4;
const int PRIORITY_HURT = 5;
const int PRIORITY_STUCK = 5;
const int PRIORITY_ATTACK = 6;
const int PRIORITY_LADDER = 7;
const int PRIORITY_OVERRIDE = 8;
// ------------------------------------
// BOT BASE - START
// ------------------------------------
final class RCBot : BotManager::BaseBot
{
//private float m_fNextThink = 0;
RCBotSchedule@ m_pCurrentSchedule;
float m_fNextShoutMedic;
float m_fNextShoutTakeCover;
float m_fNextShout;
bool init;
EHandle m_pEnemy;
// EHandle m_pNextEnemy;
BotEnemiesVisible m_pEnemiesVisible;
CBaseEntity@ m_pNearestTrain = null; // experimental - i.e. not yet implemented!
CBotVisibles@ m_pVisibles;
CBotUtilities@ utils;
CBotWeapons@ m_pWeapons;
EHandle m_pNearestTank;
EHandle m_pNearestClient;
float m_flStuckTime = 0;
Vector m_vLastSeeEnemy;
bool m_bLastSeeEnemyValid = false;
EHandle m_pLastEnemy = null;
float m_fLastSeeEnemyTime = 0;
int m_iPrevHealthArmor;
int m_iCurrentHealthArmor;
float m_flJumpTime = 0.0f;
int m_iLastWaypointFrom = 0;
int m_iLastWaypointTo = 0;
bool m_bLastPathFailed = false;
Vector m_vObjectiveOrigin;
bool m_bObjectiveOriginValid;
Vector m_vNoiseOrigin;
EHandle m_pListenPlayer;
Vector m_vListenOrigin;
float m_flHearNoiseTime = 0;
float m_fNextTakeCover = 0;
int m_iLastFailedWaypoint = -1;
EHandle m_pHeal;
EHandle m_pRevive;
EHandle m_pLastSeenBarney;
EHandle m_pLastSeenScientist;
EHandle m_pFollowingNPC;
float m_flJumpPlatformTime = 0;
CBaseEntity@ m_pExpectedPlatform = null;
Vector m_vLadderVector;
void setFollowingNPC ( CBaseEntity@ NPC )
{
m_pFollowingNPC = NPC;
}
CBaseEntity@ getNearestScientist ()
{
return m_pLastSeenScientist;
}
CBaseEntity@ getNearestBarney ()
{
return m_pLastSeenBarney;
}
bool IsScientistNearby ( )
{
return m_pLastSeenScientist.GetEntity() !is null;
}
bool IsBarneyNearby ( )
{
return m_pLastSeenBarney.GetEntity() !is null;
}
bool IsBarneyFollowing ( )
{
if ( IsNPCFollowing () )
{
CBaseEntity@ NPC = m_pFollowingNPC.GetEntity();
return NPC.GetClassname() == "monster_barney";
}
return false;
}
bool IsScientistFollowing ()
{
if ( IsNPCFollowing () )
{
CBaseEntity@ NPC = m_pFollowingNPC.GetEntity();
return NPC.GetClassname() == "monster_scientist";
}
return false;
}
bool IsNPCFollowing ()
{
if ( m_pFollowingNPC.GetEntity() !is null )
{
CBaseEntity@ NPC = m_pFollowingNPC.GetEntity();
if ( NPC.pev.deadflag == DEAD_NO )
{
CBaseMonster@ NPCm = cast<CBaseMonster@>(NPC);
//if ( NPCm.CanPlayerFollow() )
{
if ( NPCm.IsPlayerFollowing() )
{
return true;
}
}
}
}
// reset
m_pFollowingNPC = null;
return false;
}
void setNearestTank ( CBaseEntity@ pTank )
{
//BotMessage("setNearestTank");
if ( m_pNearestTank.GetEntity() is null )
m_pNearestTank = pTank;
else if ( m_pNearestTank.GetEntity() != pTank )
{
if ( distanceFrom(pTank) < distanceFrom(m_pNearestTank.GetEntity()) )
m_pNearestTank = pTank;
}
}
RCBot( CBasePlayer@ pPlayer )
{
super( pPlayer );
init = false;
@m_pVisibles = CBotVisibles(this);
@utils = CBotUtilities(this);
@m_pWeapons = CBotWeapons();
SpawnInit();
m_iPrevHealthArmor = 0;
m_iCurrentHealthArmor = 0;
m_bLastSeeEnemyValid = false;
m_pLastEnemy = null;
}
Vector getObjectiveOrigin ()
{
return m_vObjectiveOrigin;
}
bool isObjectiveOriginValid ()
{
return m_bObjectiveOriginValid;
}
void setObjectiveOrigin ( Vector vOrigin )
{
m_vObjectiveOrigin = vOrigin;
m_bObjectiveOriginValid = true;
}
void ClientSay ( CBaseEntity@ talker, array<string> args )
{
if ( args.length() > 1 )
{
bool OK = false;
bool bBotHeard = false;
Vector vTalker = talker.pev.origin;
if ( args[1] == "come")
{
RCBotSchedule@ sched = SCHED_CREATE_NEW();
RCBotTask@ task = SCHED_CREATE_PATH(vTalker,talker);
bBotHeard = true;
if ( task !is null )
{
sched.addTask(task);
sched.addTask(CBotMoveToOrigin(vTalker));
OK = true;
}
}
else if ( args[1] == "wait")
{
RCBotSchedule@ sched = SCHED_CREATE_NEW();
RCBotTask@ task = SCHED_CREATE_PATH(vTalker,talker);
float fTime = 90.0f;
bBotHeard = true;
// should work for eg....
// "Wait 2 min" or "wait here 2 min" or "wait here for 2 mins"
if ( args.length() > 2 )
{
uint arg = 2;
// search for a number
while ( arg < args.length() )
{
fTime = atof(args[arg++]);
if ( fTime > 0.0f ) // valid number
break;
}
if ( arg < args.length() )
{
if ( args[arg][0] == 'm' ) // mins
{
fTime *= 60.0f;
}
else if ( args[arg][0] == 'h' ) // hours
{
fTime *= 3600.0f;
}
}
}
// no time given
if ( fTime == 0.0f )
fTime = 90.0f;
if ( task !is null )
{
sched.addTask(task);
sched.addTask(CBotMoveToOrigin(vTalker));
sched.addTask(CBotTaskWait(fTime,vTalker));
OK = true;
}
}
else if ( args[1] == "use" )
{
RCBotSchedule@ sched = SCHED_CREATE_NEW();
CBaseEntity@ pTank = UTIL_FindNearestEntity ( "func_tank", talker.EyePosition(), 200.0f, false, false );
bBotHeard = true;
if ( pTank !is null )
{
if ( UTIL_CanUseTank(m_pPlayer,pTank) )
{
RCBotTask@ task = SCHED_CREATE_PATH(vTalker);
if ( task !is null )
{
sched.addTask(task);
sched.addTask(CBotMoveToOrigin(vTalker));
sched.addTask(CBotTaskUseTank(pTank));
OK = true;
}
}
}
}
else if ( args[1] == "press" )
{
RCBotSchedule@ sched = SCHED_CREATE_NEW();
float fTime = 0.0f;
fTime = atof( args[args.size()-1] );
CBaseEntity@ pButton = UTIL_FindNearestEntity ( "func_button", talker.EyePosition(), 128.0f, true, false );
if ( pButton is null )
@pButton = UTIL_FindNearestEntity ( "momentary_rot_button", talker.EyePosition(), 128.0f, true, false );
bBotHeard = true;
if ( pButton !is null )
{
RCBotTask@ task = SCHED_CREATE_PATH(vTalker);
if ( task !is null )
{
sched.addTask(task);
sched.addTask(CBotMoveToOrigin(vTalker));
if ( fTime > 0.0 )
sched.addTask(CUseButtonTimed(pButton,fTime));
else
sched.addTask(CUseButtonTask(pButton));
OK = true;
}
}
}
else if ( args[1] == "follow" )
{
bBotHeard = true;
if ( args.length() > 2 )
{
CBaseEntity@ pPlayerToFollow = null;
if ( args[2] == "me" )
{
@pPlayerToFollow = talker;
}
else
{
@pPlayerToFollow = UTIL_FindPlayer(args[2]);
}
if ( pPlayerToFollow !is null && pPlayerToFollow !is m_pPlayer )
{
RCBotSchedule@ sched = SCHED_CREATE_NEW();
RCBotTask@ task = SCHED_CREATE_PATH(vTalker,talker);
sched.addTask(task);
sched.addTask(CBotTaskFollow(pPlayerToFollow,false));
OK = true;
}
}
}
else if ( args[1] == "heal" )
{
bBotHeard = true;
if ( args.length() > 2 )
{
CBaseEntity@ pPlayerToHeal = null;
if ( args[2] == "me" )
{
@pPlayerToHeal = talker;
}
else
{
@pPlayerToHeal = UTIL_FindPlayer(args[2]);
}
if ( pPlayerToHeal !is null && pPlayerToHeal !is m_pPlayer )
{
RCBotSchedule@ sched = SCHED_CREATE_NEW();
RCBotTask@ task = SCHED_CREATE_PATH(vTalker,talker);
sched.addTask(task);
sched.addTask(CBotTaskHealPlayer(pPlayerToHeal));
OK = true;
}
}
}
else if ( args[1] == "revive" )
{
bBotHeard = true;
if ( args.length() > 2 )
{
CBaseEntity@ pPlayerToRevive = null;
if ( args[2] == "me" )
{
@pPlayerToRevive = talker;
}
else
{
@pPlayerToRevive = UTIL_FindPlayer(args[2]);
}
if ( pPlayerToRevive !is null && pPlayerToRevive !is m_pPlayer )
{
if ( pPlayerToRevive.pev.deadflag >= DEAD_RESPAWNABLE )
{
RCBotSchedule@ sched = SCHED_CREATE_NEW();
RCBotTask@ task = SCHED_CREATE_PATH(vTalker,talker);
sched.addTask(task);
sched.addTask(CBotTaskRevivePlayer(pPlayerToRevive));
OK = true;
}
}
}
}
else if ( args[1] == "pickup" )
{
bBotHeard = true;
if ( args.length() > 3 )
{
RCBotSchedule@ sched = SCHED_CREATE_NEW();
RCBotTask@ task = SCHED_CREATE_PATH(vTalker);
if ( task !is null )
{
sched.addTask(task);
if ( args[3] == "ammo" )
{
sched.addTask(CFindAmmoTask());
OK = true;
}
else if ( args[3] == "weapon" )
{
sched.addTask(CFindWeaponTask());
OK = true;
}
else if ( args[3] == "health")
{
sched.addTask(CFindHealthTask());
OK = true;
}
else if ( args[3] == "armor")
{
sched.addTask(CFindArmorTask());
OK = true;
}
}
}
}
if ( bBotHeard )
{
if ( OK )
Say("AFFIRMATIVE");
else
Say("NEGATIVE");
}
}
}
bool previousWaypointValid ()
{
return m_iPreviousWaypoint != -1;
}
Vector previousWaypointPosition ()
{
return g_Waypoints.getWaypointAtIndex(m_iPreviousWaypoint).m_vOrigin;
}
Vector getOrigin ()
{
return m_pPlayer.pev.origin;
}
string GetDebugMessage ()
{
string task = "null";
if ( m_pCurrentSchedule !is null )
task = m_pCurrentSchedule.getCurrentTask();
string message = "Debugging: " + m_pPlayer.pev.netname;
message += "\nTask: " + task;
message += "\nGoal: " + m_iGoalWaypoint;
if ( m_pUseBelief.GetBool() )
message += "[" + m_fBelief.getBeliefPercent(m_iGoalWaypoint) + " danger]";
if ( m_pNextWpt !is null )
{
message += "\nNext Wpt: " + m_pNextWpt.iIndex;
if ( m_pUseBelief.GetBool() )
message += "[" +m_fBelief.getBeliefPercent(m_pNextWpt.iIndex) + " danger]";
}
if ( m_iCurrentWaypoint != -1 )
{
CWaypoint@ pWpt = g_Waypoints.getWaypointAtIndex(m_iCurrentWaypoint);
message += "\nCurrent Wpt: " + m_iCurrentWaypoint;
message += " (distance = " + distanceFrom(pWpt.m_vOrigin) + ")";
Vector m_vOrigin = m_pPlayer.pev.origin;
CBasePlayer@ lp = ListenPlayer();
if ( lp !is null )
{
drawBeam(lp,m_vOrigin,pWpt.m_vOrigin,WptColor(200,200,200));
}
}
message += "\nEnemy: ";
if ( m_pEnemy.GetEntity() !is null )
{
CBaseEntity@ pEnemy = m_pEnemy.GetEntity();
message += pEnemy.GetClassname();
}
else
message += "none";
message += "\nEnemies Visible = " + m_pEnemiesVisible.EnemiesVisible();
message += "\nHealth: " + (HealthPercent()*100) + "%";
message += "\nArmor: " + (ArmorPercent()*100) + "%";
message += "\nSpeed: ";
if ( m_fDesiredMoveSpeed == 0 )
message += "100%";
else
message += "" + ((m_pPlayer.pev.velocity.Length()/m_fDesiredMoveSpeed)*100) + "%";
message += "\nNum Tasks: " + int(m_fNumTasks) + ", Failed: " + int(m_fNumTasksFailed);
return message;
}
bool isEntityVisible ( CBaseEntity@ pent )
{
int index = pent.entindex();
return m_pVisibles.isVisible(index)>0;
}
// anggara_nothing
void ClientCommand ( string command )
{
CBasePlayer@ pPlayer = m_pPlayer;
NetworkMessage m(MSG_ONE, NetworkMessages::SVC_STUFFTEXT, pPlayer.edict());
m.WriteString( command );
m.End();
//g_PlayerFuncs.ClientPrint( pPlayer, HUD_PRINTCENTER, command );
}
float HealthPercent ()
{
return (float(m_pPlayer.pev.health))/m_pPlayer.pev.max_health;
}
float ArmorPercent ()
{
return (float(m_pPlayer.pev.armorvalue))/m_pPlayer.pev.armortype;
}
float totalHealth ()
{
return (float(m_pPlayer.pev.health + m_pPlayer.pev.armorvalue))/(m_pPlayer.pev.max_health + m_pPlayer.pev.armortype);
}
bool BreakableIsEnemy ( CBaseEntity@ pBreakable )
{
// BotMessage("BreakableIsEnemy()");
// i. explosives required to blow breakable
// ii. OR is not a world brush (non breakable) and can be broken by shooting
if ( ((pBreakable.pev.flags & FL_WORLDBRUSH) != FL_WORLDBRUSH) && ((pBreakable.pev.spawnflags & 1)!=1) )
{
int iClass;
if ( pBreakable.pev.effects & EF_NODRAW == EF_NODRAW )
return false;
// this means explosives only
if ( pBreakable.pev.spawnflags & 512 == 512 )
{
if ( !m_pWeapons.HasExplosives(this) )
{
return false;
}
}
iClass = pBreakable.Classify();
switch ( iClass )
{
case -1:
case 1:
case 2:
case 3:
case 10:
case 11:
UTIL_DebugMsg(m_pPlayer,"pBreakable.Classify() false",DEBUG_THINK);
return false;
default:
break;
}
// forget it!!!
if ( pBreakable.pev.health > 9999 )
{
UTIL_DebugMsg(m_pPlayer,"pBreakable.pev.health > 9999",DEBUG_THINK);
return false;
}
if ( pBreakable.pev.target != "" )
{
UTIL_DebugMsg(m_pPlayer,"pBreakable.pev.target != ''",DEBUG_THINK);
return true;
}
// w00tguy
//if ( (iClass == -1) || (iClass == 1) || (iClass == 2) || (iClass == 3) || (iClass == 10) )
// return FALSE; // not an enemy
if ( m_pBlocking.GetEntity() !is null )
{
if ( m_pBlocking.GetEntity() is pBreakable )
{
UTIL_DebugMsg(m_pPlayer,"m_pBlocking.GetEntity() is pBreakable` ",DEBUG_THINK);
return true;
}
}
/*
Vector vSize = pBreakable.pev.size;
Vector vMySize = m_pPlayer.pev.size;
if ( (vSize.x >= vMySize.x) ||
(vSize.y >= vMySize.y) ||
(vSize.z >= (vMySize.z/2)) )
{
UTIL_DebugMsg(m_pPlayer,"BreakableIsEnemy() true",DEBUG_THINK);
return* true;
}*/
return true;
}
UTIL_DebugMsg(m_pPlayer,"BreakableIsEnemy() false",DEBUG_THINK);
return false;
}
bool IsEnemy ( CBaseEntity@ entity, bool bCheckWeapons = true )
{
string szClassname;
if ( m_pDontShoot.GetBool() )
return false;
szClassname = entity.GetClassname();
if ( bCheckWeapons )
{
CBotWeapon@ pBestWeapon = null;
@pBestWeapon = m_pWeapons.findBestWeapon(this,UTIL_EntityOrigin(entity),entity) ;
// return entity.pev.flags & FL_CLIENT == FL_CLIENT; (FOR TESTING)
// can't attack this enemy -- maybe cos I don't have an appropriate weapon
if ( pBestWeapon is null )
return false;
}
//BotMessage(szClassname);
if ( szClassname == "func_breakable" )
return BreakableIsEnemy(entity);
if ( szClassname == "func_guntarget" )
return entity.pev.velocity.Length() > 0;
if ( szClassname == "func_tank")
{
CBaseTank@ pTank = cast<CBaseTank@>( entity );
// to test
return pTank.IsBreakable() && pTank.IsPlayerAlly() == false;
}
if ( entity.pev.deadflag != DEAD_NO )
return false;
if ( entity.pev.health <= 0 )
return false;
if ( (entity.pev.effects & EF_NODRAW) == EF_NODRAW )
return false; // can't see
if ( szClassname == "hornet" )
return false;
if ( szClassname == "monster_tentacle" ) // tentacle things dont die
return false;
if ( szClassname == "monster_gargantua" )
return !entity.IsPlayerAlly();
if ( (entity.pev.flags & FL_MONSTER) == FL_MONSTER )
{
//http://www.svencoop.com/manual/classes.html
switch ( entity.Classify() )
{
case CLASS_FORCE_NONE :
case CLASS_NONE :
case CLASS_PLAYER :
case CLASS_ALIEN_PASSIVE :
case CLASS_PLAYER_BIOWEAPON :
return false; // ignore
case CLASS_PLAYER_ALLY :
case CLASS_HUMAN_PASSIVE :
return false; // ally
case CLASS_INSECT :
if ( szClassname == "monster_leech" )
{
if ( entity.pev.waterlevel > 0 && m_pPlayer.pev.waterlevel > 0 )
{
if ( distanceFrom(entity) < 64 )
{
// may be blocking the way, smack it!
return true;
}
}
}
return false;
case CLASS_ALIEN_BIOWEAPON :
case CLASS_MACHINE :
case CLASS_HUMAN_MILITARY :
case CLASS_ALIEN_MILITARY :
case CLASS_ALIEN_MONSTER :
case CLASS_ALIEN_PREY :
case CLASS_ALIEN_PREDATOR :
case CLASS_XRACE_PITDRONE :
case CLASS_XRACE_SHOCK :
case CLASS_BARNACLE :
if ( szClassname == "monster_turret" || szClassname == "monster_miniturret" )
{
// turret is invincible when closed
if ( entity.pev.sequence == 0 )
return false;
}
return true;
}
}
return false;
}
bool hasEnemy ()
{
return m_pEnemy.GetEntity() !is null;
}
CBaseEntity@ getEnemy ()
{
return m_pEnemy.GetEntity();
}
bool canGotoWaypoint ( CWaypoint@ currWpt, CWaypoint@ succWpt )
{
if ( succWpt.hasFlags(W_FL_CROUCHJUMP) )
{
// this waypoint requires the long jump modules
if ( m_pPlayer.m_fLongJump == false )
return false;
}
if ( m_bLastPathFailed )
{
if ( currWpt.iIndex == m_iLastWaypointFrom && succWpt.iIndex == m_iLastWaypointTo )
return false;
}
if ( succWpt.hasFlags(W_FL_UNREACHABLE) )
return false;
if ( succWpt.hasFlags(W_FL_GRAPPLE) )
{
if ( !HasWeapon("weapon_grapple") )
return false;
}
if ( succWpt.hasFlags(W_FL_CHECK_GROUND) )
{
TraceResult tr;
g_Utility.TraceLine( succWpt.m_vOrigin, succWpt.m_vOrigin - Vector(0,0,64.0f), ignore_monsters,dont_ignore_glass, null, tr );
// no ground?
if ( tr.flFraction >= 1.0f )
return false;
}
if ( succWpt.hasFlags(W_FL_OPENS_LATER) )
{
TraceResult tr;
g_Utility.TraceLine( currWpt.m_vOrigin, succWpt.m_vOrigin, ignore_monsters,dont_ignore_glass, null, tr );
if ( tr.flFraction < 1.0f )
{
if ( tr.pHit is null )
return false;
CBaseEntity@ ent = g_EntityFuncs.Instance(tr.pHit);
// mght be closed but is not locked
if ( ent.GetClassname() == "func_door" || ent.GetClassname() == "func_door_rotating" )
{
CBaseDoor@ door = cast<CBaseDoor@>( ent );
if ( !UTIL_DoorIsOpen(door,m_pPlayer) )
{
//BotMessage("UTIL_DoorIsOpen() == false");
return false;
}
}
else
return false;
}
else
{
CBaseEntity@ pent = null;
bool bFound = false;
Vector vSucc = succWpt.m_vOrigin;
while ( (@pent = g_EntityFuncs.FindEntityByClassname(pent, "trigger_push")) !is null )
//while ( (@pent = g_EntityFuncs.FindEntityInSphere(pent, succWpt.m_vOrigin , 128,"trigger_hurt", "classname" )) !is null )
{
if ( ((pent.pev.spawnflags & 8)!=8) && (pent.pev.solid == SOLID_TRIGGER) )
{
if ( UTIL_VectorInsideEntity(pent,vSucc) || ((UTIL_EntityOrigin(pent)-vSucc).Length() < 128) )
{
//BotMessage("TRIGGET PUSH DETECTED!!!");
bFound = true;
break;
}
//BotMessage("TRIGGET PUSH DETECTED!!! 1");
}
//BotMessage("TRIGGET PUSH DETECTED!!! 2");
}
if ( bFound )
return false;
}
}
if ( succWpt.hasFlags(W_FL_PAIN) )
{
CBaseEntity@ pent = null;
bool bFound = false;
Vector vSucc = succWpt.m_vOrigin;
while ( (@pent = g_EntityFuncs.FindEntityByClassname(pent, "trigger_hurt")) !is null )
//while ( (@pent = g_EntityFuncs.FindEntityInSphere(pent, succWpt.m_vOrigin , 128,"trigger_hurt", "classname" )) !is null )
{
if ( ((pent.pev.spawnflags & 8)!=8) && (pent.pev.solid == SOLID_TRIGGER) )
{
if ( UTIL_VectorInsideEntity(pent,vSucc) || ((UTIL_EntityOrigin(pent)-vSucc).Length() < 128) )
{
//BotMessage("TRIGGET HURT DETECTED!!!");
bFound = true;
break;
}
//BotMessage("TRIGGET HURT DETECTED!!! 1");
}
//BotMessage("TRIGGET HURT DETECTED!!! 2");
}
if ( bFound )
return false;
}
//if ( (iSucc != m_iGoalWaypoint) && !m_pBot.canGotoWaypoint(vOrigin,succWpt,currWpt) )
// continue;
if ( currWpt.hasFlags(W_FL_WATER) )
{
if ( g_EngineFuncs.PointContents(currWpt.m_vOrigin) != CONTENTS_WATER )
return false;
}
if ( currWpt.hasFlags(W_FL_TELEPORT) )
{
if ( !UTIL_DoesNearestTeleportGoTo(currWpt.m_vOrigin,succWpt.m_vOrigin) )
{
//BotMessage("WAYPINT DOESN'T GO TO THIS TELEPORT!!! SKIPPING!!!");
return false;
}
}
return true;
}
float distanceFrom ( Vector vOrigin )
{
return (vOrigin - m_pPlayer.pev.origin).Length();
}
float distanceFrom ( CBaseEntity@ pent )
{
return distanceFrom(UTIL_EntityOrigin(pent));
}
bool FVisible ( CBaseEntity@ pent )
{
return m_pVisibles.isVisible(pent.entindex()) > 0;
}
Vector origin ()
{
return m_pPlayer.pev.origin;
}
void addToSchedule ( RCBotTask@ task )
{
if ( m_pCurrentSchedule is null )
m_pCurrentSchedule = RCBotSchedule();
m_pCurrentSchedule.addTaskFront(task);
}
/**
* @return the number of times the route stack may be popped
*/
int touchedWpt ( CWaypoint@ wpt, CWaypoint@ pNextWpt, CWaypoint@ pThirdWpt )
{
UTIL_DebugMsg(m_pPlayer,"touchedWpt()",DEBUG_NAV);
if ( pThirdWpt !is null )
@m_pNextWpt = pThirdWpt;
else
@m_pNextWpt = null;
if ( pNextWpt !is null )
{
m_iLastWaypointFrom = wpt.iIndex;
m_iLastWaypointTo = pNextWpt.iIndex;
if ( pThirdWpt !is null )
{