-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathengine.cpp
1562 lines (1431 loc) · 53.2 KB
/
engine.cpp
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
///////////////////////////////////////////////////////////////////////////////////////////////
//
// -- GNU -- open source
// Please read and agree to the mb_gnu_license.txt file
// (the file is located in the marine_bot source folder)
// before editing or distributing this source code.
// This source code is free for use under the rules of the GNU General Public License.
// For more information goto:: http://www.gnu.org/licenses/
//
// credits to - valve, botman.
//
// Marine Bot - code by Frank McNeil, Kota@, Mav, Shrike.
//
// (http://marinebot.xf.cz)
//
//
// engine.cpp
//
////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(WIN32)
#pragma warning(disable: 4005 91 4477)
#endif
#include "defines.h"
#include "extdll.h"
#include "util.h"
#include "bot.h"
#include "bot_client.h"
#include "bot_func.h"
#include "bot_manager.h"
#include "engine.h"
extern enginefuncs_t g_engfuncs;
int debug_engine = 0;
char debug_fname[256]; // allow debugging into any location within HL folder
void (*botMsgFunction)(void *, int) = nullptr;
void (*botMsgEndFunction)(void *, int) = nullptr;
int botMsgIndex;
// messages created in RegUserMsg which will be "caught"
int message_VGUI = 0;
int message_ShowMenu = 0;
int message_WeaponList = 0;
int message_CurWeapon = 0;
int message_AmmoX = 0;
int message_WeapPickup = 0;
int message_AmmoPickup = 0;
int message_ItemPickup = 0;
int message_Health = 0;
int message_Bandages = 0;
int message_StatusIcon = 0; // code for FireArms 2.7+
int message_Parachute = 0; // code for FA 2.65 and versions below
int message_BrokenLeg = 0; // code for FA 2.65 and versions below
int message_Battery = 0; // Armor
int message_Damage = 0;
int message_DeathMsg = 0;
int message_TextMsg = 0;
int message_FOV = 0; // code for FireArms 2.7+
int message_Stamina = 0; // code for FireArms 2.7+
int message_Reins = 0; // code for FireArms 2.7+
int message_Concuss = 0; // code for FA 2.8 and versions above
int message_ScreenFade = 0;
static FILE *fp;
#ifndef NEWSDKAM
// if you're getting errors here then go to defines.h and change the NEWSDKAM setting
int pfnPrecacheModel(char* s)
#else
int pfnPrecacheModel(const char* s)
#endif
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnPrecacheModel: %s\n",s); fclose(fp); }
return (*g_engfuncs.pfnPrecacheModel)(s);
}
#ifndef NEWSDKAM
int pfnPrecacheSound(char* s)
#else
int pfnPrecacheSound(const char* s)
#endif
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnPrecacheSound: %s\n",s); fclose(fp); }
return (*g_engfuncs.pfnPrecacheSound)(s);
}
void pfnSetModel(edict_t *e, const char *m)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnSetModel: edict=%x %s\n",e,m); fclose(fp); }
(*g_engfuncs.pfnSetModel)(e, m);
}
int pfnModelIndex(const char *m)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnModelIndex: %s\n",m); fclose(fp); }
return (*g_engfuncs.pfnModelIndex)(m);
}
int pfnModelFrames(int modelIndex)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnModelFrames: %d\n",modelIndex); fclose(fp); }
return (*g_engfuncs.pfnModelFrames)(modelIndex);
}
void pfnSetSize(edict_t *e, const float *rgflMin, const float *rgflMax)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnSetSize: %x rgflMin: %f rgflMax: %f\n",e,*rgflMin,*rgflMax); fclose(fp); }
(*g_engfuncs.pfnSetSize)(e, rgflMin, rgflMax);
}
#ifndef NEWSDKAM
void pfnChangeLevel(char* s1, char* s2)
#else
void pfnChangeLevel(const char* s1, const char* s2)
#endif
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnChangeLevel: s1: %s s2: %s\n",s1,s2); fclose(fp); }
// kick any bot off of the server after time/frag limit...
for (int index = 0; index < MAX_CLIENTS; index++)
{
if (bots[index].is_used) // is this slot used?
{
char cmd[40];
sprintf(cmd, "kick \"%s\"\n", bots[index].name);
bots[index].respawn_state = RESPAWN_NEED_TO_RESPAWN;
SERVER_COMMAND(cmd); // kick the bot using (kick "name")
}
}
(*g_engfuncs.pfnChangeLevel)(s1, s2);
}
void pfnGetSpawnParms(edict_t *ent)
{
#ifdef _DEBUG
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnGetSpawnParms: edict=%p\n",ent); fclose(fp); }
#endif
(*g_engfuncs.pfnGetSpawnParms)(ent);
}
void pfnSaveSpawnParms(edict_t *ent)
{
#ifdef _DEBUG
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnSaveSpawnParms: edict=%p\n",ent); fclose(fp); }
#endif
(*g_engfuncs.pfnSaveSpawnParms)(ent);
}
float pfnVecToYaw(const float *rgflVector)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnVecToYaw: rgflVector: %f\n",*rgflVector); fclose(fp); }
return (*g_engfuncs.pfnVecToYaw)(rgflVector);
}
void pfnVecToAngles(const float *rgflVectorIn, float *rgflVectorOut)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnVecToAngles: rgflVectorIn: %f rgflVectorOut: %f\n",*rgflVectorIn,*rgflVectorOut); fclose(fp); }
(*g_engfuncs.pfnVecToAngles)(rgflVectorIn, rgflVectorOut);
}
void pfnMoveToOrigin(edict_t *ent, const float *pflGoal, float dist, int iMoveType)
{
#ifdef _DEBUG
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnMoveToOrigin: edict=%p pflGoal: %f dist: %f iMoveType: %d\n",ent,*pflGoal,dist,iMoveType); fclose(fp); }
#endif
(*g_engfuncs.pfnMoveToOrigin)(ent, pflGoal, dist, iMoveType);
}
void pfnChangeYaw(edict_t* ent)
{
#ifdef _DEBUG
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnChangeYaw: edict=%p\n",ent); fclose(fp); }
#endif
(*g_engfuncs.pfnChangeYaw)(ent);
}
void pfnChangePitch(edict_t* ent)
{
#ifdef _DEBUG
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnChangePitch: edict=%p\n",ent); fclose(fp); }
#endif
(*g_engfuncs.pfnChangePitch)(ent);
}
edict_t* pfnFindEntityByString(edict_t *pEdictStartSearchAfter, const char *pszField, const char *pszValue)
{
if (debug_engine)
{
fp=fopen(debug_fname,"a");
if (pEdictStartSearchAfter && pEdictStartSearchAfter->v.classname)
fprintf(fp,"pfnFindEntityByString: (ent name: %s) field=%s value=%s\n",
STRING(pEdictStartSearchAfter->v.classname), pszField, pszValue);
else if (strcmp(pszValue, "info_firearms_detect") == 0)
; // do nothing ie. don't print it into the debugging file
else
fprintf(fp,"pfnFindEntityByString: field=%s value=%s\n", pszField, pszValue);
fclose(fp);
}
return (*g_engfuncs.pfnFindEntityByString)(pEdictStartSearchAfter, pszField, pszValue);
}
int pfnGetEntityIllum(edict_t* pEnt)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnGetEntityIllum:\n"); fclose(fp); }
return (*g_engfuncs.pfnGetEntityIllum)(pEnt);
}
edict_t* pfnFindEntityInSphere(edict_t *pEdictStartSearchAfter, const float *org, float rad)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnFindEntityInSphere:\n"); fclose(fp); }
return (*g_engfuncs.pfnFindEntityInSphere)(pEdictStartSearchAfter, org, rad);
}
edict_t* pfnFindClientInPVS(edict_t *pEdict)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnFindClientInPVS:\n"); fclose(fp); }
return (*g_engfuncs.pfnFindClientInPVS)(pEdict);
}
edict_t* pfnEntitiesInPVS(edict_t *pplayer)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnEntitiesInPVS:\n"); fclose(fp); }
return (*g_engfuncs.pfnEntitiesInPVS)(pplayer);
}
void pfnMakeVectors(const float *rgflVector)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnMakeVectors: rgflVector=%f\n", *rgflVector); fclose(fp); }
(*g_engfuncs.pfnMakeVectors)(rgflVector);
}
void pfnAngleVectors(const float *rgflVector, float *forward, float *right, float *up)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnAngleVectors:\n"); fclose(fp); }
(*g_engfuncs.pfnAngleVectors)(rgflVector, forward, right, up);
}
edict_t* pfnCreateEntity()
{
edict_t *pent = (*g_engfuncs.pfnCreateEntity)();
#ifdef _DEBUG
if (debug_engine)
{
fp=fopen(debug_fname,"a");
if (pent->v.classname != NULL)
fprintf(fp,"pfnCreateEntity: %p (classname: %s)\n",pent, STRING(pent->v.classname));
else
fprintf(fp,"pfnCreateEntity: %p\n",pent);
fclose(fp);
}
#endif
return pent;
}
void pfnRemoveEntity(edict_t* e)
{
#ifdef _DEBUG
if (debug_engine)
{
fp=fopen(debug_fname,"a");
if (e->v.classname != NULL)
fprintf(fp,"pfnRemoveEntity: %p (classname: %s)\n",e, STRING(e->v.classname));
else
fprintf(fp,"pfnRemoveEntity: %p\n",e);
if (e->v.model != 0)
fprintf(fp," model=%s\n", STRING(e->v.model));
fclose(fp);
}
#endif
(*g_engfuncs.pfnRemoveEntity)(e);
}
edict_t* pfnCreateNamedEntity(int className)
{
edict_t *pent = (*g_engfuncs.pfnCreateNamedEntity)(className);
#ifdef _DEBUG
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnCreateNamedEntity: edict=%p name=%s\n",pent,STRING(className)); fclose(fp); }
#endif
return pent;
}
void pfnMakeStatic(edict_t *ent)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnMakeStatic:\n"); fclose(fp); }
(*g_engfuncs.pfnMakeStatic)(ent);
}
int pfnEntIsOnFloor(edict_t *e)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnEntIsOnFloor:\n"); fclose(fp); }
return (*g_engfuncs.pfnEntIsOnFloor)(e);
}
int pfnDropToFloor(edict_t* e)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnDropToFloor:\n"); fclose(fp); }
return (*g_engfuncs.pfnDropToFloor)(e);
}
int pfnWalkMove(edict_t *ent, float yaw, float dist, int iMode)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnWalkMove:\n"); fclose(fp); }
return (*g_engfuncs.pfnWalkMove)(ent, yaw, dist, iMode);
}
void pfnSetOrigin(edict_t *e, const float *rgflOrigin)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnSetOrigin: client=%x origin=%.1f\n", e, rgflOrigin); fclose(fp); }
(*g_engfuncs.pfnSetOrigin)(e, rgflOrigin);
}
void pfnEmitSound(edict_t *entity, int channel, const char *sample, /*int*/float volume, float attenuation, int fFlags, int pitch)
{
int index;
edict_t *pEdict;
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnEmitSound: edict=%p sound=%s channel=%d volume=%.2f attenuation=%.2f fFlags=%d, pitch=%d (gametime=%.3f)\n",entity,sample,channel,volume,attenuation,fFlags,pitch,gpGlobals->time); fclose(fp); }
// did the bot heard a grenade that has been just thrown
if (strstr(sample, "fuze.wav") != nullptr)
{
// muted message holds a pointer to the invoker
if (volume == 0.0)
{
for (index=0; index < MAX_CLIENTS; index++)
{
if (bots[index].is_used) // is this slot used?
{
pEdict = bots[index].pEdict;
// is it this bot who threw the grenade
if (entity == pEdict)
{
bots[index].BotSpeak(SAY_GRENADE_OUT);
break;
}
}
}
}
}
// is someone bleeding?
else if (strstr(sample, "bleed.wav") != nullptr)
{
for (index=0; index < MAX_CLIENTS; index++)
{
// is this slot used ie. is this entity a bot?
if (bots[index].is_used)
{
pEdict = bots[index].pEdict;
// is it this bot who bleeds
if (entity == pEdict)
{
// the bot doesn't bleed any more
if (volume == 0.0)
bots[index].RemoveTask(TASK_BLEEDING);
// the bot bleeds
if (volume > 0.0)
{
bots[index].SetTask(TASK_BLEEDING);
}
break;
}
// we can/should ignore non-bleeding for the rest of this code
if (volume == 0.0)
break;
// don't listen other clients if passive healing
// they will have to call for medic if they need help
if (externals.GetPassiveHealing())
{
break;
}
// if the bot has NOT the needed skills to help skip him
if (!(bots[index].bot_fa_skill & (FAID | MEDIC)))
continue;
// if this medic is NOT free go for next bot
if (UTIL_IsAnyMedic(&bots[index], entity, TRUE) == FALSE)
continue;
}
// then this entity must be a human player
else
{
// is it this player who bleeds
if (entity == clients[index].pEntity)
{
if (volume == 0.0)
clients[index].SetBleeding(FALSE);
if (volume > 0.0)
clients[index].SetBleeding(TRUE);
break;
}
}
}
}
// is someone merging magazines?
else if (strstr(sample, "mergemags.wav") != nullptr)
{
// can it really be heard?
if (volume > 0.0)
{
for (index = 0; index < MAX_CLIENTS; index++)
{
if (bots[index].is_used)
{
pEdict = bots[index].pEdict;
// is it this bot who does merge magazines?
if (entity == pEdict)
{
// then pause him for some time to finish it
// the proccess takes roughly 3 seconds, but we'll set longer pause time
bots[index].SetPauseTime(RANDOM_FLOAT(3.7, 5.0));
// set correct weapon action
bots[index].weapon_action = W_INMERGEMAGS;
// and clear both bits to prevent doing this over and over again
bots[index].RemoveWeaponStatus(WS_MERGEMAGS1);
bots[index].RemoveWeaponStatus(WS_MERGEMAGS2);
#ifdef DEBUG
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ // NEW CODE 094 (remove it)
char dm[256];
sprintf(dm, "(engine.cpp) %s heard his own MERGING MAGAZINES sound!\n", bots[index].name);
//ALERT(at_console, dm);
UTIL_DebugInFile(dm);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // DEBUG
break;
}
}
}
}
}
// skip all muted sounds for the rest of sound messages
if (volume == 0.0)
{
}
// is someone yelling for a medic?
else if (strstr(sample, "voice_medic") != nullptr)
{
for (index=0; index < MAX_CLIENTS; index++)
{
if (bots[index].is_used) // is this slot used?
{
// if the bot isn't medic then skip him
if (!(bots[index].bot_fa_skill & (FAID | MEDIC)))
continue;
// if this medic is NOT free go for next bot
if (UTIL_IsAnyMedic(&bots[index], entity, FALSE) == FALSE)
continue;
}
}
}
// is any medic close AND this bot is bleeding?
else if ((strstr(sample, "voice_medhere.wav") != nullptr) || (strstr(sample, "voice_treatyou.wav") != nullptr))
{
for (index=0; index < MAX_CLIENTS; index++)
{
if (bots[index].is_used) // is this slot used?
{
// does this bot bleed and the bot doesn't bandage himself,
// pause for a while to allow the medic to get close
if (bots[index].IsTask(TASK_BLEEDING) && (bots[index].bandage_time < gpGlobals->time) &&
UTIL_HeardIt(&bots[index], entity, 600))
{
bots[index].SetPauseTime(RANDOM_FLOAT(2.5, 5.0));
}
// NEW CODE 094 (prev code)
/*/
float distance = (bots[index].pEdict->v.origin - entity->v.origin).Length();
// don't react if this bot is too far from the medic
if (distance > (550 - ((bots[index].bot_skill + 1) * 50)))
continue;
int player_team = UTIL_GetTeam(entity);
int bot_team = UTIL_GetTeam(bots[index].pEdict);
// don't react on enemy medics
if (bot_team != player_team)
continue;
// does this bot bleed and the bot doesn't bandage himself,
// pause for a while to allow the medic to get close
if (bots[index].IsTask(TASK_BLEEDING) && (bots[index].bandage_time <= gpGlobals->time))
{
bots[index].SetPauseTime(RANDOM_FLOAT(2.5, 5.0));
}
/**/
}
}
}
// is there a downed soldier yelling for help?
else if (strstr(sample, "gr_pain") != nullptr)
{
for (index=0; index < MAX_CLIENTS; index++)
{
// exist this bot and is it time for him to react on this event
if (bots[index].is_used) //&&
//(bots[index].f_look_for_ground_items <= gpGlobals->time))
{
if (!(bots[index].bot_fa_skill & (FAID | MEDIC)))
continue;
// once we find suitable bot break the loop
if (UTIL_CanMedEvac(&bots[index], entity))
break;
}
}
}
// does someone call for cover?
else if (strstr(sample, "voice_coverme.wav") != nullptr)
{
for (index=0; index < MAX_CLIENTS; index++)
{
if (bots[index].is_used) // is this slot used?
{
pEdict = bots[index].pEdict;
// skip "yourself"
if (pEdict == entity)
continue;
// is this bot already "used" so ignore the call
if (bots[index].pBotUser != nullptr)
continue;
// can this bot hear the call
if (UTIL_HeardIt(&bots[index], entity, 400))
{
int counter = 0;
// check how many "followers" has this "user"
for (int i = 0; i < 31; i++)
{
if (bots[i].pBotUser == entity)
counter++;
}
// follow this "user" only if doesn't have too many "followers"
if (counter < 2)
{
bots[index].pBotUser = entity;
// set use time to know that this bot has been just "used"
bots[index].f_bot_use_time = gpGlobals->time;
UTIL_Radio(pEdict, "yes");
bots[index].speak_time = gpGlobals->time;
}
// say no, this "user" already has enough "followers"
else
{
UTIL_Radio(pEdict, "no");
bots[index].speak_time = gpGlobals->time;
}
}
}
}
}
}
(*g_engfuncs.pfnEmitSound)(entity, channel, sample, volume, attenuation, fFlags, pitch);
}
void pfnEmitAmbientSound(edict_t *entity, float *pos, const char *samp, float vol, float attenuation, int fFlags, int pitch)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnEmitAmbientSound:\n"); fclose(fp); }
(*g_engfuncs.pfnEmitAmbientSound)(entity, pos, samp, vol, attenuation, fFlags, pitch);
}
void pfnTraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnTraceLine:\n"); fclose(fp); }
(*g_engfuncs.pfnTraceLine)(v1, v2, fNoMonsters, pentToSkip, ptr);
}
void pfnTraceToss(edict_t* pent, edict_t* pentToIgnore, TraceResult *ptr)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnTraceToss:\n"); fclose(fp); }
(*g_engfuncs.pfnTraceToss)(pent, pentToIgnore, ptr);
}
int pfnTraceMonsterHull(edict_t *pEdict, const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnTraceMonsterHull:\n"); fclose(fp); }
return (*g_engfuncs.pfnTraceMonsterHull)(pEdict, v1, v2, fNoMonsters, pentToSkip, ptr);
}
void pfnTraceHull(const float *v1, const float *v2, int fNoMonsters, int hullNumber, edict_t *pentToSkip, TraceResult *ptr)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnTraceHull: v1=%f v2=%f fnoMonsters=%d, hullNumber=%d pentToSkip=%x traceresult=%f\n", *v1, *v2, fNoMonsters, hullNumber, pentToSkip, ptr->flFraction); fclose(fp); }
(*g_engfuncs.pfnTraceHull)(v1, v2, fNoMonsters, hullNumber, pentToSkip, ptr);
}
void pfnTraceModel(const float *v1, const float *v2, int hullNumber, edict_t *pent, TraceResult *ptr)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnTraceModel:\n"); fclose(fp); }
(*g_engfuncs.pfnTraceModel)(v1, v2, hullNumber, pent, ptr);
}
const char *pfnTraceTexture(edict_t *pTextureEntity, const float *v1, const float *v2 )
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnTraceTexture:\n"); fclose(fp); }
return (*g_engfuncs.pfnTraceTexture)(pTextureEntity, v1, v2);
}
void pfnTraceSphere(const float *v1, const float *v2, int fNoMonsters, float radius, edict_t *pentToSkip, TraceResult *ptr)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnTraceSphere:\n"); fclose(fp); }
(*g_engfuncs.pfnTraceSphere)(v1, v2, fNoMonsters, radius, pentToSkip, ptr);
}
void pfnGetAimVector(edict_t* ent, float speed, float *rgflReturn)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnGetAimVector:\n"); fclose(fp); }
(*g_engfuncs.pfnGetAimVector)(ent, speed, rgflReturn);
}
#ifndef NEWSDKAM
void pfnServerCommand(char* str)
#else
void pfnServerCommand(const char* str)
#endif
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnServerCommand: %s\n",str); fclose(fp); }
(*g_engfuncs.pfnServerCommand)(str);
}
void pfnServerExecute()
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnServerExecute:\n"); fclose(fp); }
(*g_engfuncs.pfnServerExecute)();
}
#ifndef NEWSDKAM
void pfnClientCommand(edict_t* pEdict, char* szFmt, ...)
#else
void pfnClientCommand(edict_t* pEdict, const char* szFmt, ...)
#endif
{
if (debug_engine)
{
// print this also to console
ALERT(at_console, "pfnClientCommand=%s\n",szFmt);
fp=fopen(debug_fname,"a");
fprintf(fp,"pfnClientCommand=%s (time=%.3f)\n",szFmt,gpGlobals->time);
fclose(fp);
}
// new code to test if this finally fix the problem with bot using the say and teamsay cmds
static char tempFmt[1024];
va_list argp;
va_start(argp, szFmt);
vsprintf(tempFmt, szFmt, argp);
va_end(argp);
if (!(pEdict->v.flags & FL_FAKECLIENT))
(*g_engfuncs.pfnClientCommand)(pEdict, tempFmt);
return;
}
void pfnParticleEffect(const float *org, const float *dir, float color, float count)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnParticleEffect:\n"); fclose(fp); }
(*g_engfuncs.pfnParticleEffect)(org, dir, color, count);
}
#ifndef NEWSDKAM
void pfnLightStyle(int style, char* val)
#else
void pfnLightStyle(int style, const char* val)
#endif
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnLightStyle:\n"); fclose(fp); }
(*g_engfuncs.pfnLightStyle)(style, val);
}
int pfnDecalIndex(const char *name)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnDecalIndex:\n"); fclose(fp); }
return (*g_engfuncs.pfnDecalIndex)(name);
}
int pfnPointContents(const float *rgflVector)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnPointContents:\n"); fclose(fp); }
return (*g_engfuncs.pfnPointContents)(rgflVector);
}
void pfnMessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnMessageBegin: edict=%p dest=%d type=%d (gametime=%.3f)\n", ed, msg_dest, msg_type, gpGlobals->time); fclose(fp); }
if (ed)
{
const int index = UTIL_GetBotIndex(ed);
// is this message for a bot?
if (index != -1)
{
botMsgFunction = nullptr; // no msg function until known otherwise
botMsgEndFunction = nullptr; // no msg end function until known otherwise
botMsgIndex = index; // index of bot receiving message
if (mod_id == FIREARMS_DLL)
{
if (msg_type == message_VGUI)
botMsgFunction = BotClient_FA_VGUI;
else if (msg_type == message_WeaponList)
botMsgFunction = BotClient_FA_WeaponList;
else if (msg_type == message_CurWeapon)
botMsgFunction = BotClient_FA_CurrentWeapon;
else if (msg_type == message_AmmoX)
botMsgFunction = BotClient_FA_AmmoX;
else if (msg_type == message_AmmoPickup)
botMsgFunction = BotClient_FA_AmmoPickup;
else if (msg_type == message_WeapPickup)
botMsgFunction = BotClient_FA_WeaponPickup;
else if (msg_type == message_ItemPickup)
botMsgFunction = BotClient_FA_ItemPickup;
else if (msg_type == message_Health)
botMsgFunction = BotClient_FA_Health;
else if (msg_type == message_Bandages)
botMsgFunction = BotClient_FA_Bandages;
else if (msg_type == message_StatusIcon)
botMsgFunction = BotClient_FA_StatusIcon;
else if (msg_type == message_Parachute) // code for FA 2.65 and versions below
{
botMsgFunction = BotClient_FA_Parachute;
// ugly technique to handle this message
if (botMsgFunction)
(*botMsgFunction)(static_cast<void*>(nullptr), botMsgIndex);
}
else if (msg_type == message_BrokenLeg) // code for FA 2.65 and versions below
botMsgFunction = BotClient_FA_BrokenLeg;
else if (msg_type == message_Battery)
botMsgFunction = BotClient_FA_Battery;
else if (msg_type == message_Damage)
botMsgFunction = BotClient_FA_Damage;
else if (msg_type == message_TextMsg)
botMsgFunction = BotClient_FA_TextMsg;
else if (msg_type == message_FOV)
botMsgFunction = BotClient_FA_FOV;
else if (msg_type == message_Stamina)
botMsgFunction = BotClient_FA_Stamina;
else if (msg_type == message_Reins)
botMsgFunction = BotClient_FA_Reins;
else if (msg_type == message_Concuss)
botMsgFunction = BotClient_FA_Concuss;
else if (msg_type == message_ScreenFade)
botMsgFunction = BotClient_FA_ScreenFade;
else if (msg_type == 23)
{
botMsgFunction = BotClient_FA_HUDMsg;
}
}
}
}
else if (msg_dest == MSG_ALL)
{
botMsgFunction = nullptr; // no msg function until known otherwise
botMsgIndex = -1; // index of bot receiving message (none)
if (mod_id == FIREARMS_DLL)
{
if (msg_type == message_DeathMsg)
botMsgFunction = BotClient_FA_DeathMsg;
else if (msg_type == message_TextMsg)
botMsgFunction = BotClient_FA_TextMsg_ForAll;
}
}
}
(*g_engfuncs.pfnMessageBegin)(msg_dest, msg_type, pOrigin, ed);
}
void pfnMessageEnd()
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnMessageEnd:\n"); fclose(fp); }
if (botMsgEndFunction)
(*botMsgEndFunction)(nullptr, botMsgIndex); // NULL indicated msg end
// clear out the bot message function pointers...
botMsgFunction = nullptr;
botMsgEndFunction = nullptr;
}
(*g_engfuncs.pfnMessageEnd)();
}
void pfnWriteByte(int iValue)
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnWriteByte: %d\n",iValue); fclose(fp); }
// if this message is for a bot, call the client message function...
if (botMsgFunction)
(*botMsgFunction)(static_cast<void*>(&iValue), botMsgIndex);
}
(*g_engfuncs.pfnWriteByte)(iValue);
}
void pfnWriteChar(int iValue)
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnWriteChar: %d\n",iValue); fclose(fp); }
// if this message is for a bot, call the client message function...
if (botMsgFunction)
(*botMsgFunction)(static_cast<void*>(&iValue), botMsgIndex);
}
(*g_engfuncs.pfnWriteChar)(iValue);
}
void pfnWriteShort(int iValue)
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnWriteShort: %d\n",iValue); fclose(fp); }
// if this message is for a bot, call the client message function...
if (botMsgFunction)
(*botMsgFunction)(static_cast<void*>(&iValue), botMsgIndex);
}
(*g_engfuncs.pfnWriteShort)(iValue);
}
void pfnWriteLong(int iValue)
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnWriteLong: %d\n",iValue); fclose(fp); }
// if this message is for a bot, call the client message function...
if (botMsgFunction)
(*botMsgFunction)(static_cast<void*>(&iValue), botMsgIndex);
}
(*g_engfuncs.pfnWriteLong)(iValue);
}
void pfnWriteAngle(float flValue)
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnWriteAngle: %f\n",flValue); fclose(fp); }
// if this message is for a bot, call the client message function...
if (botMsgFunction)
(*botMsgFunction)(static_cast<void*>(&flValue), botMsgIndex);
}
(*g_engfuncs.pfnWriteAngle)(flValue);
}
void pfnWriteCoord(float flValue)
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnWriteCoord: %f\n",flValue); fclose(fp); }
// if this message is for a bot, call the client message function...
if (botMsgFunction)
(*botMsgFunction)(static_cast<void*>(&flValue), botMsgIndex);
}
(*g_engfuncs.pfnWriteCoord)(flValue);
}
void pfnWriteString(const char *sz)
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnWriteString: %s\n",sz); fclose(fp); }
// if this message is for a bot, call the client message function...
if (botMsgFunction)
(*botMsgFunction)((void *)sz, botMsgIndex);
}
(*g_engfuncs.pfnWriteString)(sz);
}
void pfnWriteEntity(int iValue)
{
if (gpGlobals->deathmatch)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnWriteEntity: %d\n",iValue); fclose(fp); }
// if this message is for a bot, call the client message function...
if (botMsgFunction)
(*botMsgFunction)(static_cast<void*>(&iValue), botMsgIndex);
}
(*g_engfuncs.pfnWriteEntity)(iValue);
}
void pfnCVarRegister(cvar_t *pCvar)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnCVarRegister:\n"); fclose(fp); }
(*g_engfuncs.pfnCVarRegister)(pCvar);
}
float pfnCVarGetFloat(const char *szVarName)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnCVarGetFloat: %s\n",szVarName); fclose(fp); }
return (*g_engfuncs.pfnCVarGetFloat)(szVarName);
}
const char* pfnCVarGetString(const char *szVarName)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnCVarGetString:\n"); fclose(fp); }
return (*g_engfuncs.pfnCVarGetString)(szVarName);
}
void pfnCVarSetFloat(const char *szVarName, float flValue)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnCVarSetFloat:\n"); fclose(fp); }
(*g_engfuncs.pfnCVarSetFloat)(szVarName, flValue);
}
void pfnCVarSetString(const char *szVarName, const char *szValue)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnCVarSetString: varName=%s value=%s\n", szVarName, szValue); fclose(fp); }
(*g_engfuncs.pfnCVarSetString)(szVarName, szValue);
}
#if !defined ( NEWSDKAM ) && !defined ( NEWSDKVALVE ) && !defined ( NEWSDKMM ) && !defined ( __linux__ )
// original HL SDK v2.3
// if you're getting errors here then go to 'defines.h' and set the correct flag
// matching your HL SDK version
void* pfnPvAllocEntPrivateData(edict_t *pEdict, long cb)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnPvAllocEntPrivateData:\n"); fclose(fp); }
return (*g_engfuncs.pfnPvAllocEntPrivateData)(pEdict, cb);
}
#else
// all other newer HL SDKs and original HL SDK v2.3 on Linux
void* pfnPvAllocEntPrivateData(edict_t* pEdict, int32 cb)
{
if (debug_engine) { fp = fopen(debug_fname, "a"); fprintf(fp, "pfnPvAllocEntPrivateData:\n"); fclose(fp); }
return (*g_engfuncs.pfnPvAllocEntPrivateData)(pEdict, cb);
}
#endif
void* pfnPvEntPrivateData(edict_t *pEdict)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnPvEntPrivateData:\n"); fclose(fp); }
return (*g_engfuncs.pfnPvEntPrivateData)(pEdict);
}
void pfnFreeEntPrivateData(edict_t *pEdict)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnFreeEntPrivateData:\n"); fclose(fp); }
(*g_engfuncs.pfnFreeEntPrivateData)(pEdict);
}
const char* pfnSzFromIndex(int iString)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnSzFromIndex:\n"); fclose(fp); }
return (*g_engfuncs.pfnSzFromIndex)(iString);
}
int pfnAllocString(const char *szValue)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnAllocString:\n"); fclose(fp); }
return (*g_engfuncs.pfnAllocString)(szValue);
}
entvars_t* pfnGetVarsOfEnt(edict_t *pEdict)
{
if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnGetVarsOfEnt:\n"); fclose(fp); }
return (*g_engfuncs.pfnGetVarsOfEnt)(pEdict);
}
edict_t* pfnPEntityOfEntOffset(int iEntOffset)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnPEntityOfEntOffset:\n"); fclose(fp); }
return (*g_engfuncs.pfnPEntityOfEntOffset)(iEntOffset);
}
int pfnEntOffsetOfPEntity(const edict_t *pEdict)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnEntOffsetOfPEntity: %x\n",pEdict); fclose(fp); }
return (*g_engfuncs.pfnEntOffsetOfPEntity)(pEdict);
}
int pfnIndexOfEdict(const edict_t *pEdict)
{
//if (debug_engine) { fp=fopen(debug_fname,"a"); fprintf(fp,"pfnIndexOfEdict: %x\n",pEdict); fclose(fp); }
return (*g_engfuncs.pfnIndexOfEdict)(pEdict);
}
edict_t* pfnPEntityOfEntIndex(int iEntIndex)
{
//#ifdef _DEBUG
//edict_t* pent = (*g_engfuncs.pfnPEntityOfEntIndex)(iEntIndex);
/*/ // gets called really often
if (debug_engine)
{
fp=fopen(debug_fname,"a");
if (pent != NULL)
{
if (pent->v.classname != NULL)
{
if (pent->v.netname != NULL)
fprintf(fp,"pfnPEntityOfEntIndex: %x (classname: %s) (netname: %s)\n",
pent, STRING(pent->v.classname), STRING(pent->v.netname));
else
fprintf(fp,"pfnPEntityOfEntIndex: %x (classname: %s)\n",pent, STRING(pent->v.classname));
}
else
fprintf(fp,"pfnPEntityOfEntIndex: %x\n",pent);
}