forked from pongo1231/rcbot2
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbot_tf2_mod.cpp
More file actions
1683 lines (1408 loc) · 50.9 KB
/
Copy pathbot_tf2_mod.cpp
File metadata and controls
1683 lines (1408 loc) · 50.9 KB
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
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
/*
* This file is part of RCBot.
*
* RCBot by Paul Murphy adapted from Botman's HPB Bot 2 template.
*
* RCBot is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* RCBot is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCBot; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*
*/
#include "engine_wrappers.h"
// #include "server_class.h"
#include "bot.h"
#include "bot_cvars.h"
#include "in_buttons.h"
#include "bot_configfile.h"
#include "bot_fortress.h"
#include "bot_getprop.h"
#include "bot_globals.h"
#include "bot_mods.h"
#include "bot_navigator.h"
#include "bot_perceptron.h"
#include "bot_sigscan.h"
#include "bot_tf2_points.h"
#include "bot_waypoint.h"
#include "bot_waypoint_locations.h"
#include "bot_weapons.h"
#include <algorithm>
#include <cstring>
#include "rcbot/logging.h"
//#if SOURCE_ENGINE == SE_SDK2013 || SOURCE_ENGINE == SE_BMS
#include "valve_minmax_off.h"
//#endif
eTFMapType CTeamFortress2Mod :: m_MapType = TF_MAP_CTF;
tf_tele_t CTeamFortress2Mod :: m_Teleporters[RCBOT_MAXPLAYERS];
int CTeamFortress2Mod :: m_iArea = 0;
float CTeamFortress2Mod::m_fSetupTime = 0.0f;
float CTeamFortress2Mod::m_fRoundTime = 0.0f;
MyEHandle CTeamFortress2Mod::m_pFlagCarrierRed = MyEHandle(nullptr);
MyEHandle CTeamFortress2Mod::m_pFlagCarrierBlue = MyEHandle(nullptr);
float CTeamFortress2Mod::m_fArenaPointOpenTime = 0.0f;
float CTeamFortress2Mod::m_fPointTime = 0.0f;
tf_sentry_t CTeamFortress2Mod::m_SentryGuns[RCBOT_MAXPLAYERS]; // used to let bots know if sentries have been sapped or not
tf_disp_t CTeamFortress2Mod::m_Dispensers[RCBOT_MAXPLAYERS]; // used to let bots know where friendly/enemy dispensers are
MyEHandle CTeamFortress2Mod::m_pResourceEntity = MyEHandle(nullptr);
MyEHandle CTeamFortress2Mod::m_pGameRules = MyEHandle(nullptr);
bool CTeamFortress2Mod::m_bAttackDefendMap = false;
int CTeamFortress2Mod::m_Cappers[MAX_CONTROL_POINTS];
int CTeamFortress2Mod::m_iCapDefenders[MAX_CONTROL_POINTS];
bool CTeamFortress2Mod::m_bHasRoundStarted = true;
bool CTeamFortress2Mod::m_bDontClearPoints = false;
int CTeamFortress2Mod::m_iFlagCarrierTeam = 0;
MyEHandle CTeamFortress2Mod::m_pBoss = MyEHandle(nullptr);
bool CTeamFortress2Mod::m_bBossSummoned = false;
MyEHandle CTeamFortress2Mod::pMediGuns[RCBOT_MAXPLAYERS];
CTFObjectiveResource CTeamFortress2Mod::m_ObjectiveResource = CTFObjectiveResource();
CTeamControlPointMaster *CTeamFortress2Mod::m_PointMaster = nullptr;
CTeamRoundTimer CTeamFortress2Mod::m_Timer;
MyEHandle CTeamFortress2Mod::m_PointMasterResource = MyEHandle(nullptr);
CTeamControlPointRound *CTeamFortress2Mod::m_pCurrentRound = nullptr;
bool CTeamFortress2Mod::bFlagStateDefault = true;
MyEHandle CTeamFortress2Mod::m_pPayLoadBombBlue = MyEHandle(nullptr);
MyEHandle CTeamFortress2Mod::m_pPayLoadBombRed = MyEHandle(nullptr);
bool CTeamFortress2Mod::m_bRoundOver = false;
int CTeamFortress2Mod::m_iWinningTeam = 0;
int CTeamFortress2Mod::m_iLastWinningTeam = 0;
Vector CTeamFortress2Mod::m_vFlagLocationBlue = Vector(0,0,0);
Vector CTeamFortress2Mod::m_vFlagLocationRed = Vector(0,0,0);
bool CTeamFortress2Mod::m_bFlagLocationValidBlue = false;
bool CTeamFortress2Mod::m_bFlagLocationValidRed = false;
bool CTeamFortress2Mod::m_bMVMFlagStartValid = false;
Vector CTeamFortress2Mod::m_vMVMFlagStart = Vector(0,0,0);
bool CTeamFortress2Mod::m_bMVMCapturePointValid = false;
Vector CTeamFortress2Mod::m_vMVMCapturePoint = Vector(0,0,0);
bool CTeamFortress2Mod::m_bMVMAlarmSounded = false;
float CTeamFortress2Mod::m_fMVMCapturePointRadius = 0.0f;
int CTeamFortress2Mod::m_iCapturePointWptID = -1;
int CTeamFortress2Mod::m_iFlagPointWptID = -1;
MyEHandle CTeamFortress2Mod::m_pNearestTankBoss = nullptr;
float CTeamFortress2Mod::m_fNearestTankDistance = 0.0f;
Vector CTeamFortress2Mod::m_vNearestTankLocation = Vector(0, 0, 0);
bool CTeamFortress2Mod::isSuddenDeath()
{
// Bot weapon Randomizer -- leonardo
if (!mp_stalemate_enable.IsValid() || !mp_stalemate_enable.GetBool() || isMapType(TF_MAP_ARENA) || isMapType(TF_MAP_SAXTON))
return false;
if (void *pGameRules = GetGameRules())
{
const int iRoundState = CClassInterface::TF2_getRoundState(pGameRules);
return iRoundState == RoundState_Stalemate;
}
return false;
}
bool CTeamFortress2Mod::isMedievalMode()
{
return CClassInterface::TF2_IsMedievalMode(GetGameRules());
}
bool CTeamFortress2Mod::checkWaypointForTeam(CWaypoint* pWpt, const int iTeam)
{
// Returns true if team can go to waypoint
return m_bRoundOver || ((!pWpt->hasFlag(CWaypointTypes::W_FL_NOBLU) || iTeam != TF2_TEAM_BLUE) && (!pWpt->hasFlag(CWaypointTypes::W_FL_NORED) || iTeam != TF2_TEAM_RED));
}
bool CTeamFortress2Mod :: isWaypointAreaValid (const int iWptArea, const int iWptFlags)
{
return CTeamFortress2Mod::m_ObjectiveResource.isWaypointAreaValid(iWptArea,iWptFlags);
}
///////////////////////////
bool CTeamFortress2Mod :: withinEndOfRound (const float fTime)
{
if ( m_Timer.m_flTimerEndTime )
return gpGlobals->curtime > *m_Timer.m_flTimerEndTime - fTime;
return false;
}
void CTeamFortress2Mod :: getTeamOnlyWaypointFlags (const int iTeam, int *iOn, int *iOff)
{
if ( iTeam == TF2_TEAM_BLUE )
{
*iOn = CWaypointTypes::W_FL_NORED;
*iOff = CWaypointTypes::W_FL_NOBLU;
}
else if ( iTeam == TF2_TEAM_RED )
{
*iOn = CWaypointTypes::W_FL_NOBLU;
*iOff = CWaypointTypes::W_FL_NORED;
}
}
void CTeamFortress2Mod ::modFrame ()
{
if( m_bPlayerHasSpawned )
{
if ( m_ObjectiveResource.m_ObjectiveResource == nullptr )
{
m_ObjectiveResource.m_ObjectiveResource = CClassInterface::FindEntityByNetClass(gpGlobals->maxClients+1, "CTFObjectiveResource");
if ( m_ObjectiveResource.m_ObjectiveResource.get() != nullptr)
m_ObjectiveResource.setup();
}
else
CTeamFortress2Mod::m_ObjectiveResource.think();
/*
if (m_pGameRules.get() == NULL)
{
//m_pGameRules = CClassInterface::FindEntityByClassnameNearest(Vector(0, 0, 0), "tf_gamerules_data", 99999.0f, NULL);
m_pGameRules = CClassInterface::FindEntityByNetClass(gpGlobals->maxClients + 1, "CTFGameRulesProxy");
if (m_pGameRules.get())
{
const char *classname = m_pGameRules.get()->GetClassName();
logger->Log(LogLevel::DEBUG, "Found gamerules %s", classname);
}
}*/
}
}
void CTeamFortress2Mod :: initMod ()
{
// unsigned i;
// Setup Weapons
CWeapons::loadWeapons(m_szWeaponListName == nullptr ? "TF2" : m_szWeaponListName, TF2Weaps.data());
//CWeapons::loadWeapons("TF2", TF2Weaps);
/*
i = 0;
while ( TF2Weaps[i].szWeaponName[0] != '\0' ) //for ( i = 0; i < TF2_WEAPON_MAX; i ++ )
CWeapons::addWeapon(new CWeapon(TF2Weaps[i++]));//.iSlot,TF2Weaps[i].szWeaponName,TF2Weaps[i].iId,TF2Weaps[i].m_iFlags,TF2Weaps[i].m_iAmmoIndex,TF2Weaps[i].minPrimDist,TF2Weaps[i].maxPrimDist,TF2Weaps[i].m_iPreference,TF2Weaps[i].m_fProjSpeed));
*/
CRCBotTF2UtilFile::loadConfig();
//memset(g_fBotUtilityPerturb,0,sizeof(float)*TF_CLASS_MAX*BOT_UTIL_MAX);
}
void CTeamFortress2Mod :: mapInit ()
{
CBotMod::mapInit();
m_vNearestTankLocation = Vector(0, 0, 0);
const string_t mapname = gpGlobals->mapname;
const char *szmapname = mapname.ToCStr();
m_iLastWinningTeam = 0;
m_iWinningTeam = 0;
m_pResourceEntity = nullptr;
m_ObjectiveResource.m_ObjectiveResource = nullptr;
m_ObjectiveResource.reset();
m_PointMaster = nullptr;
m_PointMasterResource = nullptr;
m_pCurrentRound = nullptr;
m_Timer = CTeamRoundTimer();
bFlagStateDefault = true;
m_bFlagLocationValidBlue = false;
m_bFlagLocationValidRed = false;
m_bMVMAlarmSounded = false;
m_bMVMFlagStartValid = false;
m_bMVMCapturePointValid = false;
m_fMVMCapturePointRadius = 0.0f;
m_iCapturePointWptID = -1;
m_iFlagPointWptID = -1;
if (std::strncmp(szmapname, "ctf_", 4) == 0 || std::strncmp(szmapname, "quake_turbine", 13) == 0 ||
std::strncmp(szmapname, "pass_", 5) == 0 || std::strncmp(szmapname, "pd_", 3) == 0 ||
std::strncmp(szmapname, "od_", 3) == 0 ||
std::strncmp(szmapname, "cr_", 3) == 0 ||
std::strncmp(szmapname, "workshop/cr_", 12) == 0 ||
std::strncmp(szmapname, "workshop/ctf_", 13) == 0 ||
std::strncmp(szmapname, "workshop/pass_", 14) == 0 ||
std::strncmp(szmapname, "workshop/pd_", 12) == 0 ||
std::strncmp(szmapname, "slendytubbies", 13) == 0)
// Quake Turbine is CTF. - RussiaTails
m_MapType = TF_MAP_CTF; // capture the flag + pass time + player destruction
else if (std::strncmp(szmapname, "cp_", 3) == 0 ||
std::strncmp(szmapname, "cqt_", 4) == 0 ||
std::strncmp(szmapname, "conquest_", 9) == 0 ||
std::strncmp(szmapname, "dom_", 4) == 0 ||
std::strncmp(szmapname, "2koth_", 6) == 0 ||
std::strncmp(szmapname, "falling_cp", 10) == 0 ||
std::strncmp(szmapname, "stt_", 4) == 0 ||
std::strncmp(szmapname, "koth_lifesnatcher", 17) == 0 ||
std::strncmp(szmapname, "vip_", 4) == 0 ||
std::strncmp(szmapname, "vipr_", 5) == 0 ||
std::strncmp(szmapname, "szf_", 4) == 0 ||
std::strncmp(szmapname, "rush_", 5) == 0 ||
std::strncmp(szmapname, "workshop/cp_", 12) == 0 ||
std::strncmp(szmapname, "workshop/vip_", 13) == 0 ||
std::strncmp(szmapname, "workshop/rush_", 14) == 0 ||
std::strncmp(szmapname, "zf_", 3) == 0)
// Conquest, 2koth and DOM works fine as CP_. Moved stt to cp to make bots attack a tank - RussiaTails
m_MapType = TF_MAP_CP; // control point
else if (std::strncmp(szmapname, "tc_", 3) == 0)
m_MapType = TF_MAP_TC; // territory control
else if (std::strncmp(szmapname, "pl_", 3) == 0 ||
std::strncmp(szmapname, "workshop/pl_", 12) == 0 ||
std::strncmp(szmapname, "kotc_", 5) == 0)
// Tug of War works fine as Payload - RussiaTails
m_MapType = TF_MAP_CART; // pipeline
else if (std::strncmp(szmapname, "plr_", 4) == 0 || std::strncmp(szmapname, "tow_", 4) == 0 ||
std::strncmp(szmapname, "workshop/plr_", 13) == 0 ||
std::strncmp(szmapname, "workshop/tow_", 13) == 0 ||
std::strncmp(szmapname, "arena_tinyrock", 14) == 0 || std::strncmp(szmapname, "tow_impasse", 11) == 0 ||
std::strncmp(szmapname, "arena_hailstone", 15) == 0) // to make bots push payloads on these maps. - RussiaTails
m_MapType = TF_MAP_CARTRACE; // pipeline racing
else if (std::strncmp(szmapname, "arena_", 6) == 0 ||
std::strncmp(szmapname, "workshop/arena_", 15) == 0 ||
std::strncmp(szmapname, "ft_", 3) == 0) // pongo1321
m_MapType = TF_MAP_ARENA; // arena mode
else if (std::strncmp(szmapname, "vsh_", 4) == 0 ||
std::strncmp(szmapname, "ff2_", 4) == 0 ||
std::strncmp(szmapname, "bvb_", 4) == 0 ||
std::strncmp(szmapname, "workshop/vsh_", 13) == 0 ||
std::strncmp(szmapname, "dr_", 3) == 0)
m_MapType = TF_MAP_SAXTON; // arena mode
else if (std::strncmp(szmapname, "pipeball_", 9) == 0)
m_MapType = TF_MAP_PIPEBALL; // arena mode
else if (std::strncmp(szmapname, "koth_", 5) == 0 ||
std::strncmp(szmapname, "workshop/koth_", 14) == 0 ||
std::strncmp(szmapname, "ctk_", 4) == 0)
// Control the Keep works almost the same as KOTH. - RussiaTails
m_MapType = TF_MAP_KOTH; // king of the hill
else if (std::strncmp(szmapname, "sd_", 3) == 0 ||
std::strncmp(szmapname, "workshop/sd_", 12) == 0 ||
std::strncmp(szmapname, "htf_", 4) == 0 ||
std::strncmp(szmapname, "workshop/htf_", 13) == 0 ||
std::strncmp(szmapname, "sdr_", 4) == 0)
// Object Destruction and Special Delivery Race (I dunno why it's named like this when it works as a usual sd_) works the same as SD_. - RussiaTails
m_MapType = TF_MAP_SD; // special delivery
else if (std::strncmp(szmapname, "tr_", 3) == 0)
m_MapType = TF_MAP_TR; // training mode
else if (std::strncmp(szmapname, "cppl_", 5) == 0 ||
std::strncmp(szmapname, "workshop/cppl_", 14) == 0 ||
std::strncmp(szmapname, "cw_", 3) == 0) // Hybrid - RussiaTails
m_MapType = TF_MAP_CPPL; // CP+PL maps
else if (std::strncmp(szmapname, "gg_", 3) == 0 || std::strncmp(szmapname, "dm_hydro", 8) == 0 ||
std::strncmp(szmapname, "dm_powerdown", 12) == 0 || std::strncmp(szmapname, "dm_forgecall", 12) == 0 ||
std::strncmp(szmapname, "dm_poolparty", 12) == 0 || std::strncmp(szmapname, "dm_badworks", 11) == 0 ||
std::strncmp(szmapname, "dm_razorpoint", 13) == 0 || std::strncmp(szmapname, "dm_deadlock", 11) == 0)
// GunGame (and non-team deathmatch) - RussiaTails
m_MapType = TF_MAP_GG; // GunGame maps
else if (std::strncmp(szmapname, "mvm_", 4) == 0 || std::strncmp(szmapname, "gd_", 3) == 0)
// gd is MvM Guardian, for now there are only two maps exist with this prefix. - RussiaTails
m_MapType = TF_MAP_MVM; // mann vs machine
else if (std::strncmp(szmapname, "rd_", 3) == 0 ||
std::strncmp(szmapname, "workshop/rd_", 12) == 0 ||
std::strncmp(szmapname, "rda_", 4) == 0)
m_MapType = TF_MAP_RD; // robot destruction
else if (std::strncmp(szmapname, "workshop/pdr_", 13) == 0 ||
std::strncmp(szmapname, "pdr_", 4) == 0)
m_MapType = TF_MAP_PDR; // player destruction + payload race - RussiaTails
else if (std::strncmp(szmapname, "zi_", 3) == 0 ||
std::strncmp(szmapname, "workshop/zi_", 12) == 0)
m_MapType = TF_MAP_ZI; // Zombie Infection //TODO: add support for those gamemodes [APG]RoboCop[CL]
else if (std::strncmp(szmapname, "workshop/boss_", 14) == 0 || std::strncmp(szmapname, "workshop/my_world_", 18) == 0 ||
std::strncmp(szmapname, "boss_", 5) == 0 || std::strncmp(szmapname, "my_world_", 9) == 0)
m_MapType = TF_MAP_BOSS; // test - RussiaTails
else
m_MapType = TF_MAP_DM; // deathmatch //TODO: to prevent bots from idling in their spawns by giving them basic tasks [APG]RoboCop[CL]
m_iArea = 0;
m_fSetupTime = 5.0f; // 5 seconds normal
m_fRoundTime = 0.0f;
m_pFlagCarrierRed = nullptr;
m_pFlagCarrierBlue = nullptr;
m_iFlagCarrierTeam = 0;
m_bDontClearPoints = false;
for ( unsigned i = 0; i < RCBOT_MAXPLAYERS; i ++ )
{
m_Teleporters[i].m_iWaypoint = -1;
m_Teleporters[i].m_fLastTeleported = 0.0f;
m_Teleporters[i].entrance = MyEHandle(nullptr);
m_Teleporters[i].exit = MyEHandle(nullptr);
m_Teleporters[i].sapper = MyEHandle(nullptr);
m_SentryGuns[i].sapper = MyEHandle(nullptr);
m_SentryGuns[i].sentry = MyEHandle(nullptr);
m_Dispensers[i].sapper = MyEHandle(nullptr);
m_Dispensers[i].disp = MyEHandle(nullptr);
pMediGuns[i] = nullptr;
}
m_bAttackDefendMap = false;
m_pBoss = nullptr;
m_bBossSummoned = false;
resetCappers();
resetDefenders();
//CPoints::loadMapScript();
}
int CTeamFortress2Mod :: getTeleporterWaypoint (const edict_t *pTele)
{
for (tf_tele_t& m_Teleporter : m_Teleporters)
{
if (m_Teleporter.exit.get() == pTele )
return m_Teleporter.m_iWaypoint;
}
return -1;
}
// Naris @ AlliedModders .net
bool CTeamFortress2Mod :: TF2_IsPlayerZoomed(edict_t *pPlayer)
{
const int pcond = CClassInterface :: getTF2Conditions(pPlayer);
return (pcond & TF2_PLAYER_ZOOMED) == TF2_PLAYER_ZOOMED;
}
bool CTeamFortress2Mod :: TF2_IsPlayerSlowed(edict_t *pPlayer)
{
const int pcond = CClassInterface :: getTF2Conditions(pPlayer);
return (pcond & TF2_PLAYER_SLOWED) == TF2_PLAYER_SLOWED;
}
bool CTeamFortress2Mod :: TF2_IsPlayerDisguised(edict_t *pPlayer)
{
const int pcond = CClassInterface :: getTF2Conditions(pPlayer);
return (pcond & TF2_PLAYER_DISGUISED) == TF2_PLAYER_DISGUISED;
}
bool CTeamFortress2Mod :: TF2_IsPlayerTaunting ( edict_t *pPlayer )
{
const int pcond = CClassInterface :: getTF2Conditions(pPlayer);
return (pcond & TF2_PLAYER_TAUNTING) == TF2_PLAYER_TAUNTING;
}
bool CTeamFortress2Mod :: TF2_IsPlayerCloaked(edict_t *pPlayer)
{
const int pcond = CClassInterface :: getTF2Conditions(pPlayer);
return (pcond & TF2_PLAYER_CLOAKED) == TF2_PLAYER_CLOAKED;
}
bool CTeamFortress2Mod :: TF2_IsPlayerKrits(edict_t *pPlayer)
{
const int pcond = CClassInterface :: getTF2Conditions(pPlayer);
return (pcond & TF2_PLAYER_KRITS) == TF2_PLAYER_KRITS;
//return false; //Unreachable? [APG]RoboCop[CL]
}
bool CTeamFortress2Mod :: TF2_IsPlayerInvuln(edict_t *pPlayer)
{
if ( CBotGlobals::isPlayer(pPlayer) )
{
const int pcond = CClassInterface :: getTF2Conditions(pPlayer);
return (pcond & TF2_PLAYER_INVULN) == TF2_PLAYER_INVULN;
}
return false;
}
bool CTeamFortress2Mod :: TF2_IsPlayerOnFire(edict_t *pPlayer)
{
const int pcond = CClassInterface :: getTF2Conditions(pPlayer);
return (pcond & TF2_PLAYER_ONFIRE) == TF2_PLAYER_ONFIRE;
}
//TODO: Experimental [APG]RoboCop[CL]
int CTeamFortress2Mod::numPlayersOnTeam(int iTeam, bool bAliveOnly)
{
return 0;
}
int CTeamFortress2Mod ::numClassOnTeam(const int iTeam, const int iClass)
{
int num = 0;
for ( int i = 1; i <= CBotGlobals::maxClients(); i ++ )
{
edict_t* pEdict = INDEXENT(i);
if ( !pEdict )
continue;
if ( CBotGlobals::entityIsValid(pEdict) )
{
if ( getTeam(pEdict) == iTeam )
{
if ( CClassInterface::getTF2Class(pEdict) == iClass )
num++;
}
}
}
return num;
}
edict_t *CTeamFortress2Mod :: findResourceEntity()
{
if ( !m_pResourceEntity ) // crash fix
m_pResourceEntity = CClassInterface::FindEntityByNetClass(gpGlobals->maxClients+1, "CTFPlayerResource");
return m_pResourceEntity;
}
TF_Class CTeamFortress2Mod :: getSpyDisguise ( edict_t *pPlayer )
{
static int iClass;
static int iTeam;
static int iIndex;
static int iHealth;
CClassInterface::getTF2SpyDisguised(pPlayer,&iClass,&iTeam,&iIndex,&iHealth);
return static_cast<TF_Class>(iClass);
}
float CTeamFortress2Mod :: TF2_GetClassSpeed(const int iClass)
{
switch (iClass)
{
case TF_CLASS_SCOUT: return 133.0f;
case TF_CLASS_SOLDIER: return 80.0f;
case TF_CLASS_DEMOMAN: return 93.0f;
case TF_CLASS_MEDIC: return 109.0f;
case TF_CLASS_PYRO: return 100.0f;
case TF_CLASS_SPY: return 109.0f;
case TF_CLASS_ENGINEER: return 100.0f;
case TF_CLASS_HWGUY: return 77.0f;
case TF_CLASS_SNIPER: return 100.0f;
}
return 0.0f;
}
float CTeamFortress2Mod :: TF2_GetPlayerSpeed(edict_t *pPlayer, const TF_Class iClass)
{
static float fSpeed;
fSpeed = CClassInterface::getMaxSpeed(pPlayer);// * CClassInterface::getSpeedFactor(pPlayer);
if ( fSpeed == 0.0f )
{
if (TF2_IsPlayerSlowed(pPlayer))
return 30.0f;
return TF2_GetClassSpeed(iClass) * 1.58f;
}
return fSpeed;
}
int CTeamFortress2Mod :: getTeam ( edict_t *pEntity )
{
return CClassInterface::getTeam (pEntity);
//return *((int*)(pEntity->GetIServerEntity()->GetBaseEntity())+110);
}
int CTeamFortress2Mod :: getSentryLevel ( edict_t *pSentry )
{
const string_t model = pSentry->GetIServerEntity()->GetModelName();
const char *szmodel = model.ToCStr();
return szmodel[24] - '1'+1;
//if ( pSentry && pSentry->
}
int CTeamFortress2Mod :: getDispenserLevel ( edict_t *pDispenser )
{
const string_t model = pDispenser->GetIServerEntity()->GetModelName();
const char *szmodel = model.ToCStr();
if ( std::strcmp(szmodel,"models/buildables/dispenser_light.mdl") == 0 )
return 1;
return szmodel[31] - '1'+1;
//if ( pSentry && pSentry->
}
int CTeamFortress2Mod :: getEnemyTeam (const int iTeam)
{
return iTeam == TF2_TEAM_BLUE?TF2_TEAM_RED:TF2_TEAM_BLUE;
}
/*
------------------int : m_nDisguiseTeam
------------------int : m_nDisguiseClass
------------------int : m_iDisguiseTargetIndex
------------------int : m_iDisguiseHealth
*/
bool CTeamFortress2Mod :: isDispenser (edict_t *pEntity, const int iTeam, const bool checkcarrying)
{
return (!iTeam || iTeam == getTeam(pEntity)) && std::strcmp(pEntity->GetClassName(),"obj_dispenser")==0 && (checkcarrying||!CClassInterface::isSentryGunBeingPlaced(pEntity));
}
bool CTeamFortress2Mod :: isFlag (edict_t *pEntity, const int iTeam)
{
return (!iTeam || getEnemyTeam(iTeam) == getTeam(pEntity)) && std::strcmp(pEntity->GetClassName(),"item_teamflag")==0;
}
/*bool CTeamFortress2Mod::isBall(edict_t* pEntity, const int iTeam)
{
return (!iTeam || getEnemyTeam(iTeam) == getTeam(pEntity)) && std::strcmp(pEntity->GetClassName(), "passtime_ball") == 0;
}*/
bool CTeamFortress2Mod::isBoss(edict_t* pEntity, float* fFactor)
{
const string_t mapname = gpGlobals->mapname;
const char* szmapname = mapname.ToCStr();
if (m_bBossSummoned)
{
if (m_pBoss.get() && CBotGlobals::entityIsAlive(m_pBoss.get()))
return m_pBoss.get() == pEntity;
if (std::strcmp(pEntity->GetClassName(), "merasmus") == 0 ||
std::strcmp(pEntity->GetClassName(), "headless_hatman") == 0 ||
std::strcmp(pEntity->GetClassName(), "eyeball_boss") == 0 ||
std::strcmp(pEntity->GetClassName(), "tf_merasmus_trick_or_treat_prop") == 0 ||
std::strcmp(pEntity->GetClassName(), "base_boss") == 0) // For Krampus and any other NPCs which uses base_boss entity - RussiaTails
{
m_pBoss = pEntity;
return true;
}
if (std::strcmp(pEntity->GetClassName(), "tf_merasmus_trick_or_treat_prop") == 0 && CBotGlobals::entityIsAlive(m_pBoss.get()))
return (std::strcmp(pEntity->GetClassName(), "merasmus") != 0);
}
else if (CTeamFortress2Mod::isMapType(TF_MAP_CARTRACE) || isMapType(TF_MAP_CART) || isMapType(TF_MAP_CTF) || isMapType(TF_MAP_KOTH) ||
isMapType(TF_MAP_CP) || isMapType(TF_MAP_PD) || isMapType(TF_MAP_ARENA) || isMapType(TF_MAP_SAXTON) || isMapType(TF_MAP_SD) || isMapType(TF_MAP_BOSS) || isMapType(TF_MAP_DM))
{
if (m_pBoss.get() == pEntity)
return true;
if (std::strcmp(pEntity->GetClassName(), "base_boss") == 0 || // For Krampus and any other NPCs which uses base_boss entity - RussiaTails
std::strcmp(pEntity->GetClassName(), "tf_robot_botler") == 0 || // Botler Robots from Embargo entity - RussiaTails
std::strcmp(pEntity->GetClassName(), "prop_soccer_ball") == 0)
{
m_pBoss = pEntity;
return true;
}
if (isTankBoss(pEntity))
{
/*if (fFactor != nullptr)
*fFactor = -200.0f;*/
m_pBoss = pEntity;
return true;
}
}
else if (CTeamFortress2Mod::isMapType(TF_MAP_PIPEBALL))
{
if (m_pBoss.get() == pEntity)
return true;
if (std::strcmp(pEntity->GetClassName(), "func_physbox") == 0 ||
std::strcmp(pEntity->GetClassName(), "base_boss") == 0)
{
m_pBoss = pEntity;
return true;
}
if (isTankBoss(pEntity))
{
if (fFactor != nullptr)
*fFactor = 200.0f;
m_pBoss = pEntity;
return true;
}
}
else if (CTeamFortress2Mod::isMapType(TF_MAP_MVM))
{
if (m_pBoss.get() == pEntity)
return true;
if (isTankBoss(pEntity)) /* && CClassInterface::getTeam(pEntity) != iTeam)*/
{
/*if (fFactor != nullptr)
*fFactor = -200.0f;*/
m_pBoss = pEntity;
return true;
}
}
return false;
}
void CTeamFortress2Mod :: updateTeleportTime (const edict_t* pOwner)
{
m_Teleporters[ENTINDEX(pOwner)-1].m_fLastTeleported = engine->Time();
}
float CTeamFortress2Mod :: getTeleportTime (const edict_t* pOwner)
{
return m_Teleporters[ENTINDEX(pOwner)-1].m_fLastTeleported;
}
bool CTeamFortress2Mod :: isSentry (edict_t *pEntity, const int iTeam, const bool checkcarrying)
{
return (!iTeam || iTeam == getTeam(pEntity)) && std::strcmp(pEntity->GetClassName(),"obj_sentrygun")==0 && (checkcarrying||!CClassInterface::isSentryGunBeingPlaced(pEntity));
}
bool CTeamFortress2Mod::isTankBoss(const edict_t* pEntity)
{
return std::strcmp(pEntity->GetClassName(), "tank_boss") == 0;
}
bool CTeamFortress2Mod :: isTeleporter (edict_t *pEntity, const int iTeam, const bool checkcarrying)
{
return (!iTeam || iTeam == getTeam(pEntity)) && std::strcmp(pEntity->GetClassName(),"obj_teleporter")==0 && (checkcarrying||!CClassInterface::isSentryGunBeingPlaced(pEntity));
}
bool CTeamFortress2Mod :: isTeleporterEntrance (edict_t *pEntity, const int iTeam, const bool checkcarrying)
{
return isTeleporter(pEntity,iTeam) && CClassInterface::isTeleporterMode(pEntity,TELE_ENTRANCE) && (checkcarrying||!CClassInterface::isSentryGunBeingPlaced(pEntity));
}
bool CTeamFortress2Mod :: isTeleporterExit (edict_t *pEntity, const int iTeam, const bool checkcarrying)
{
return isTeleporter(pEntity,iTeam) && CClassInterface::isTeleporterMode(pEntity,TELE_EXIT) && (checkcarrying||!CClassInterface::isSentryGunBeingPlaced(pEntity));
}
bool CTeamFortress2Mod :: isPipeBomb (edict_t *pEntity, const int iTeam)
{
return (!iTeam || iTeam == getTeam(pEntity)) && std::strcmp(pEntity->GetClassName(),"tf_projectile_pipe_remote")==0;
}
bool CTeamFortress2Mod :: isHurtfulPipeGrenade (edict_t *pEntity, edict_t *pPlayer, const bool bCheckOwner)
{
if ( std::strcmp(pEntity->GetClassName(),"tf_projectile_pipe")==0 )
{
if ( bCheckOwner && CClassInterface::getPipeBombOwner(pEntity) == pPlayer )
return true;
const int iPlayerTeam = getTeam(pPlayer);
const int iGrenTeam = getTeam(pEntity);
return iPlayerTeam != iGrenTeam;
}
return false;
}
bool CTeamFortress2Mod :: isRocket (edict_t *pEntity, const int iTeam)
{
return (!iTeam || iTeam == getTeam(pEntity)) && std::strcmp(pEntity->GetClassName(),"tf_projectile_rocket")==0;
}
edict_t *CTeamFortress2Mod:: getMediGun ( edict_t *pPlayer )
{
if ( CClassInterface::getTF2Class(pPlayer) == TF_CLASS_MEDIC )
return pMediGuns[ENTINDEX(pPlayer)-1];
return nullptr;
}
void CTeamFortress2Mod :: findMediGun ( edict_t *pPlayer )
{
static int i;
static edict_t *pEnt;
static Vector vOrigin;
vOrigin = CBotGlobals::entityOrigin(pPlayer);
for ( i = gpGlobals->maxClients+1; i < gpGlobals->maxEntities; i ++ )
{
pEnt = INDEXENT(i);
if ( pEnt && CBotGlobals::entityIsValid(pEnt) )
{
if ( std::strcmp(pEnt->GetClassName(),"tf_weapon_medigun") == 0 )
{
if ( CBotGlobals::entityOrigin(pEnt) == vOrigin )
{
pMediGuns[ENTINDEX(pPlayer)-1] = pEnt;
break;
}
}
}
}
}
// get the teleporter exit of an entrance
edict_t *CTeamFortress2Mod :: getTeleporterExit (const edict_t *pTele)
{
edict_t *pExit;
for (tf_tele_t& m_Teleporter : m_Teleporters)
{
if (m_Teleporter.entrance.get() == pTele )
{
if ( (pExit = m_Teleporter.exit.get()) != nullptr)
{
return pExit;
}
return nullptr;
}
}
return nullptr;
}
// check if the entity is a health kit
bool CTeamFortress2Mod :: isHealthKit (const edict_t* pEntity)
{
if (CTeamFortress2Mod::isMapType(TF_MAP_SAXTON) || isMapType(TF_MAP_ZI))
{
return false;
}
return std::strncmp(pEntity->GetClassName(),"item_healthkit",14)==0;
}
bool CTeamFortress2Mod :: isAreaOwnedByTeam (const int iArea, const int iTeam)
{
if ( CTeamFortress2Mod::m_ObjectiveResource.isInitialised() )
{
return iArea==0 || CTeamFortress2Mod::m_ObjectiveResource.GetOwningTeam(CTeamFortress2Mod::m_ObjectiveResource.m_WaypointAreaToIndexTranslation[iArea])==iTeam;
}
return false;
}
// cehc kif the team can pick up a flag in SD mode (special delivery)
bool CTeamFortress2Mod::canTeamPickupFlag_SD(const int iTeam, const bool bGetUnknown)
{
if ( isArenaPointOpen() )
{
if ( bGetUnknown )
return m_iFlagCarrierTeam==iTeam;
return m_iFlagCarrierTeam==0;
}
return false;
}
// For MVM only
bool CTeamFortress2Mod::getFlagLocation (const int iTeam, Vector *vec)
{
if ( getDroppedFlagLocation(iTeam,vec) )
{
return true;
}
if ( hasRoundStarted() && isFlagCarried(iTeam) )
{
*vec = CBotGlobals::entityOrigin(getFlagCarrier(iTeam));
return true;
}
return false;
}
// for special delivery mod and MVM
void CTeamFortress2Mod::flagReturned(const int iTeam)
{
m_iFlagCarrierTeam = 0;
bFlagStateDefault = true;
if ( iTeam == TF2_TEAM_BLUE )
{
m_bFlagLocationValidBlue = false;
}
else if ( iTeam == TF2_TEAM_RED )
{
m_bFlagLocationValidRed = false;
}
}
void CTeamFortress2Mod:: flagPickedUp (const int iTeam, edict_t *pPlayer)
{
bFlagStateDefault = false;
if ( iTeam == TF2_TEAM_BLUE )
{
m_pFlagCarrierBlue = pPlayer;
m_bFlagLocationValidBlue = false;
}
else if ( iTeam == TF2_TEAM_RED )
{
m_pFlagCarrierRed = pPlayer;
m_bFlagLocationValidRed = false;
}
m_iFlagCarrierTeam = iTeam;
CBotTF2FunctionEnemyAtIntel func(iTeam, CBotGlobals::entityOrigin(pPlayer), EVENT_FLAG_PICKUP);
CBots::botFunction(&func);
}
bool CTeamFortress2Mod :: isArenaPointOpen ()
{
return m_fArenaPointOpenTime < engine->Time();
}
void CTeamFortress2Mod :: resetSetupTime ()
{
m_fRoundTime = engine->Time() + m_Timer.getSetupTime();
m_fArenaPointOpenTime = engine->Time() + m_fPointTime;
}
bool CTeamFortress2Mod::hasRoundStarted()
{
return m_bHasRoundStarted || (!isMapType(TF_MAP_MVM) && engine->Time() > m_fRoundTime);
//return (engine->Time() > m_fRoundTime);
}
void CTeamFortress2Mod :: setPointOpenTime (const int time)
{
m_fArenaPointOpenTime = 0.0f;
m_fPointTime = static_cast<float>(time);
}
void CTeamFortress2Mod :: setSetupTime (const int time)
{
m_fRoundTime = 0.0f;
m_fSetupTime = static_cast<float>(time);
}
bool CTeamFortress2Mod :: isAmmo (const edict_t* pEntity)
{
static const char *szClassname;
szClassname = pEntity->GetClassName();
return std::strcmp(szClassname,"tf_ammo_pack") == 0 || std::strncmp(szClassname,"item_ammopack",13) == 0;
}
//TODO: Experimental [APG]RoboCop[CL]
int CTeamFortress2Mod::getArea()
{
return 0;
}
bool CTeamFortress2Mod::isPayloadBomb(edict_t* pEdict, int iTeam)
{
const string_t mapname = gpGlobals->mapname;
const char* szmapname = mapname.ToCStr();
const string_t model = pEdict->GetIServerEntity()->GetModelName();
if (std::strncmp(szmapname, "pl_embargo", 10) == 0 && engine->IndexOfEdict(pEdict) >= 400) // Make bots focus on payload only - RussiaTails
{
return std::strncmp(pEdict->GetClassName(), "mapobj_cart_dispenser", 21) == 0 && CClassInterface::getTeam(pEdict) == iTeam;
}
if (std::strncmp(szmapname, "pl_aquarius", 11) == 0 && engine->IndexOfEdict(pEdict) <= 100) // Make bots focus on payload only - RussiaTails
{
return std::strncmp(pEdict->GetClassName(), "mapobj_cart_dispenser", 21) == 0 && CClassInterface::getTeam(pEdict) == iTeam;
}
if (std::strncmp(szmapname, "plr_cutter", 10) == 0)
{
if ((engine->IndexOfEdict(pEdict) >= 400) && (CClassInterface::getTeam(pEdict) == TF2_TEAM_RED))
{
return std::strncmp(pEdict->GetClassName(), "mapobj_cart_dispenser", 21) == 0;
}
if ((engine->IndexOfEdict(pEdict) >= 400) && (CClassInterface::getTeam(pEdict) == TF2_TEAM_BLUE))
{
return std::strncmp(pEdict->GetClassName(), "mapobj_cart_dispenser", 21) == 0;
}
return false;
}
if (std::strncmp(szmapname, "plr_matterhorn", 14) == 0)
{
if (engine->IndexOfEdict(pEdict) >= 310)
{
return std::strncmp(pEdict->GetClassName(), "mapobj_cart_dispenser", 21) == 0 && CClassInterface::getTeam(pEdict) == iTeam;
}
return false;
}
if ((std::strncmp(szmapname, "tow_", 4) == 0 || std::strncmp(szmapname, "kotc_", 5) == 0) && std::strncmp(szmapname, "tow_impasse", 11) != 0)
{
return std::strncmp(pEdict->GetClassName(), "mapobj_cart_dispenser", 21) == 0;
}
if (std::strncmp(szmapname, "sd_offload", 10) == 0)
{
return (std::strncmp(pEdict->GetClassName(), "prop_dynamic", 12) == 0) && std::strcmp(model.ToCStr(), "models/props_doomsday/cap_point_small.mdl") == 0;
}
if (std::strncmp(szmapname, "ctf_system", sizeof("ctf_system") - 1) == 0)
{
return std::strncmp(pEdict->GetClassName(), "item_teamflag", sizeof("item_teamflag") - 1) == 0
&& CClassInterface::getTeam(pEdict) == iTeam;
}
if (CTeamFortress2Mod::isMapType(TF_MAP_CARTRACE) ||
CTeamFortress2Mod::isMapType(TF_MAP_CPPL) ||
CTeamFortress2Mod::isMapType(TF_MAP_PDR) ||
(CTeamFortress2Mod::isMapType(TF_MAP_CART) &&
!(std::strncmp(szmapname, "plr_cutter", 10) == 0 ||
std::strncmp(szmapname, "plr_matterhorn", 14) == 0 ||
std::strncmp(szmapname, "pl_embargo", 10) == 0 ||
std::strncmp(szmapname, "pl_aquarius", 11) == 0 ||
std::strncmp(szmapname, "sd_offload", 10) == 0 ||
std::strncmp(szmapname, "ctf_system", 10) == 0 ||
std::strncmp(szmapname, "tow_", 4) == 0)))
{
return std::strncmp(pEdict->GetClassName(), "mapobj_cart_dispenser", 21) == 0 && CClassInterface::getTeam(pEdict) == iTeam;
}
if (std::strncmp(szmapname, "tow_impasse", 11) == 0)
{
return std::strncmp(pEdict->GetClassName(), "mapobj_cart_dispenser", 21) == 0 && CClassInterface::getTeam(pEdict) == iTeam;
}
/*else if (std::strncmp(szmapname, "tow_impasse", 11) == 0)
{
if ((engine->IndexOfEdict(pEdict) > 250) && (CClassInterface::getTeam(pEdict) == TF2_TEAM_RED))
{
return std::strncmp(pEdict->GetClassName(), "trigger_capture_area", 21) == 0 && CBotGlobals::entityOrigin(pEdict);;
}