-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot_start.cpp
2279 lines (2001 loc) · 63.2 KB
/
bot_start.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)
//
//
// bot_start.cpp
//
////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(WIN32)
#pragma warning(disable: 4005 91)
#endif
#include "defines.h"
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "bot.h"
#include "bot_func.h"
#include "bot_manager.h"
#include "bot_weapons.h"
// for new config system by Andrey Kotrekhov
#pragma warning(disable:4786)
#include "Config.h"
extern Section *conf;
extern int debug_engine;
// bot_start functions prototypes
inline bool isnt(const char *cc1, const char *cc2) { return (strcmp(cc1, cc2) != 0); }
void BotFinishWeaponSpawning(bot_t *pBot);
void BotFinishSkillsSpawning(bot_t *pBot);
int BotGenerateSkill(bot_t *pBot);
inline void BotSetBehaviour(bot_t *pBot);
inline void BotSetWeaponStatus(bot_t *pBot);
int SetMainWeapon(const char *bank, const char *slot);
inline int SetBackupWeapon(bot_t *pBot, const char *bank, const char *slot);
inline int SetGrenade(const char *bank, const char *slot);
inline int SetMine(const char *bank, const char *slot);
int NumberOfFASkills(bot_t *pBot);
void ProcessCustomConfig( bot_t *pBot, const char *line_buffer );
bool CanSpawnIt(bot_t *pBot, int iID);
void RearrangeWeapons(bot_t *pBot);
bool RearrangeWeapons(bot_t *pBot, int weapon);
void FA25SpawnBaseArmor(bot_t *pBot, const char *line_buffer);
void FA25SpawnAdditionalArmor(bot_t *pBot, const char *line_buffer);
void FA25SpawnItems(bot_t *pBot, const char *line_buffer);
void FA25SpawnSidearms(bot_t *pBot, const char *line_buffer);
void FA25SpawnShotguns(bot_t *pBot, const char *line_buffer);
void FA25SpawnSMGs(bot_t *pBot, const char *line_buffer);
void FA25SpawnRifles(bot_t *pBot, const char *line_buffer);
void FA25SpawnSnipes(bot_t *pBot, const char *line_buffer);
void FA25SpawnMGuns(bot_t *pBot, const char *line_buffer);
void FA25SpawnGLs(bot_t *pBot, const char *line_buffer);
bool BotSpawnSkills(bot_t *pBot, const char *line_buffer);
/*
* sets some important bot spawn/respawn variables and lead bot through VGUI menus
*/
void bot_t::BotStartGame()
{
if (mod_id == FIREARMS_DLL)
{
// handle MODT selection menu
if (start_action == MSG_FA_MOTD_WINDOW)
{
start_action = MSG_FA_IDLE; // switch back to idle
FakeClientCommand(pEdict, "vguimenuoption", "0", nullptr); // just press "okay"
return;
}
// handle team selection menu
if (start_action == MSG_FA_TEAM_SELECT)
{
start_action = MSG_FA_IDLE; // switch back to idle
// select the skin the bot wishes to use
if ((bot_skin < 1) || (bot_skin > 5))
bot_skin = -1;
if (bot_skin == -1)
{
bot_skin = RANDOM_LONG(1, 5);
}
if (bot_skin == 1)
FakeClientCommand(pEdict, "changeskin", "0", nullptr);
else if (bot_skin == 2)
FakeClientCommand(pEdict, "changeskin", "1", nullptr);
else if (bot_skin == 3)
FakeClientCommand(pEdict, "changeskin", "2", nullptr);
else if (bot_skin == 4)
FakeClientCommand(pEdict, "changeskin", "3", nullptr);
else if (bot_skin == 5)
FakeClientCommand(pEdict, "changeskin", "4", nullptr);
// was the team NOT specified so generate it
if ((bot_team != 1) && (bot_team != 2))
bot_team = -1;
if (bot_team == -1)
bot_team = RANDOM_LONG(1, 2);
// select the team the bot wishes to join
if (bot_team == 1)
{
// handle Firearms 2.9 and 3.0
if ((g_mod_version == FA_29) || (g_mod_version == FA_30))
FakeClientCommand(pEdict, "vguimenuoption", "1", nullptr); // join red team
else
FakeClientCommand(pEdict, "vguimenuoption", "2", nullptr);
}
else
{
if ((g_mod_version == FA_29) || (g_mod_version == FA_30))
FakeClientCommand(pEdict, "vguimenuoption", "2", nullptr); // join blue team
else
FakeClientCommand(pEdict, "vguimenuoption", "3", nullptr);
}
return;
}
// handle class selection menu
if (start_action == MSG_FA_CLASS_SELECT)
{
start_action = MSG_FA_IDLE; // switch back to idle
// force custom classes in FA25 and below
if (UTIL_IsOldVersion())
{
externals.SetCustomClasses(TRUE);
}
// do we use custom classes
if (externals.GetCustomClasses())
{
// SECTION - for new config system by Andrey Kotrekhov
// ADDED - debug also for Listen server and system debug by Frank McNeil
char temp[64];
if (conf != nullptr)
{
//process custom config kota@
const SI custom_section_i = conf->sectionList.find("custom_config");
#ifdef _DEBUG
//@@@@@@@
//PrintOutput(NULL, "*** BotStartGame() - find custom_config\n", msg_null);
#endif
if (custom_section_i != conf->sectionList.end())
{
Section *cust_sect_p = custom_section_i->second;
// to deal with compiler warning signed/unsigned mismatch
const int max_classes = cust_sect_p->sectionList.size();
// check for invalid class value ...
if ((bot_class < 1) || (bot_class > max_classes))
{
// and generate valid class
bot_class = RANDOM_LONG(1, max_classes);
}
// convert bot class to string number
sprintf(temp, "class%d", bot_class);
FakeClientCommand(pEdict, "usingpreconfig", nullptr, nullptr);
const SI class_sect_i = cust_sect_p->sectionList.find(temp);
if (class_sect_i != cust_sect_p->sectionList.end())
{
#ifdef _DEBUG
//@@@@@@@@@@@@
//char dmsg[256];
//sprintf(dmsg, "*** BotStartGame() - class %s found\n", temp);
//PrintOutput(NULL, dmsg, msg_null);
#endif
//class is found
Section *class_p = class_sect_i->second;
pcust_class = class_p;
// if is it FA25 and below then just enter the menu based spawning
if (UTIL_IsOldVersion())
{
#ifdef _DEBUG
//@@@@@@@@@@@@@
//PrintOutput(NULL, "BotStartGame() - FA25 menu based spawning entered\n", msg_null);
#endif
FakeClientCommand(pEdict, "vguimenuoption", "1", nullptr);
return;
}
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
#ifdef _DEBUG
//@@@@@@@@@@@@@@@@
char dmsg[256];
sprintf(dmsg, "*** %s ", item_i->second.c_str());
PrintOutput(NULL, dmsg, MType::msg_null);
#endif
ProcessCustomConfig(this, item_i->second.c_str());
}
#ifdef _DEBUG
//@@@@@
PrintOutput(NULL, "***\n", MType::msg_null);
#endif
}
}
}
// SECTION BY Andrey Kotrekhov END
}// END custom classes
// otherwise use hard coded classes
// default FA2.7 classes (fixed for FA2.7 credit system, because FA2.7 classes
// aren't compatible with FA2.7 credit system - it's a bug in FA2.7)
else
{
if ((bot_class < 1) || (bot_class > 8))
bot_class = -1;
if (bot_class == -1)
bot_class = RANDOM_LONG(1, 8);
// select the class the bot wishes to use
if (bot_class == 1)
{
//this will spawn assault
FakeClientCommand(pEdict, "usingpreconfig", nullptr, nullptr);
FakeClientCommand(pEdict, "loadpreconfig", "1", "2");
FakeClientCommand(pEdict, "loadpreconfig", "2", "2");
FakeClientCommand(pEdict, "loadpreconfig", "7", "3");
FakeClientCommand(pEdict, "loadpreconfig", "4", "3");
FakeClientCommand(pEdict, "loadpreconfig", "3", "2");
// if we are using skill system spawn this skill
if (internals.GetFASkillSystem() != 0.0)
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "1");
// also set this byte
bot_fa_skill |= MARKS1;
}
#ifndef NOFAMAS
main_weapon = fa_weapon_famas;
#endif
backup_weapon = fa_weapon_anaconda;
grenade_slot = fa_weapon_frag;
}
else if (bot_class == 2)
{
//this will spawn machinegunner
FakeClientCommand(pEdict, "usingpreconfig", nullptr, nullptr);
FakeClientCommand(pEdict, "loadpreconfig", "1", "2");
FakeClientCommand(pEdict, "loadpreconfig", "2", "2");
FakeClientCommand(pEdict, "loadpreconfig", "9", "2");
FakeClientCommand(pEdict, "loadpreconfig", "4", "2");
if (internals.GetFASkillSystem() != 0.0)
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "1");
bot_fa_skill |= MARKS1;
// spawn this skill only if allowed (ie more skills to start)
if ((internals.GetFASkillSystem() == 2.0) || (internals.GetFASkillSystem() == 3.0))
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "2");
bot_fa_skill |= MARKS2;
}
}
main_weapon = fa_weapon_m60;
backup_weapon = fa_weapon_coltgov;
}
else if (bot_class == 3)
{
//this will spawn grenadier
FakeClientCommand(pEdict, "usingpreconfig", nullptr, nullptr);
FakeClientCommand(pEdict, "loadpreconfig", "1", "2");
FakeClientCommand(pEdict, "loadpreconfig", "2", "2");
FakeClientCommand(pEdict, "loadpreconfig", "2", "3");
FakeClientCommand(pEdict, "loadpreconfig", "7", "6");
FakeClientCommand(pEdict, "loadpreconfig", "4", "5");
FakeClientCommand(pEdict, "loadpreconfig", "3", "2");
FakeClientCommand(pEdict, "loadpreconfig", "3", "6");
if (internals.GetFASkillSystem() != 0.0)
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "8");
bot_fa_skill |= ARTY1;
}
main_weapon = fa_weapon_m16;
backup_weapon = fa_weapon_ber92f;
grenade_slot = fa_weapon_frag;
}
else if (bot_class == 4)
{
//this will spawn specialist
FakeClientCommand(pEdict, "usingpreconfig", nullptr, nullptr);
FakeClientCommand(pEdict, "loadpreconfig", "1", "1");
FakeClientCommand(pEdict, "loadpreconfig", "2", "2");
FakeClientCommand(pEdict, "loadpreconfig", "2", "4");
FakeClientCommand(pEdict, "loadpreconfig", "2", "3");
FakeClientCommand(pEdict, "loadpreconfig", "6", "3");
FakeClientCommand(pEdict, "loadpreconfig", "4", "5");
FakeClientCommand(pEdict, "loadpreconfig", "3", "2");
FakeClientCommand(pEdict, "loadpreconfig", "3", "5");
FakeClientCommand(pEdict, "loadpreconfig", "3", "6");
if (internals.GetFASkillSystem() != 0.0)
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "1");
bot_fa_skill |= MARKS1;
if ((internals.GetFASkillSystem() == 2.0) || (internals.GetFASkillSystem() == 3.0))
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "2");
bot_fa_skill |= MARKS2;
}
}
main_weapon = fa_weapon_mp5a5;
backup_weapon = fa_weapon_ber92f;
grenade_slot = fa_weapon_frag;
claymore_slot = fa_weapon_claymore;
}
else if (bot_class == 5)
{
//this will spawn combat sniper
FakeClientCommand(pEdict, "usingpreconfig", nullptr, nullptr);
FakeClientCommand(pEdict, "loadpreconfig", "1", "1");
FakeClientCommand(pEdict, "loadpreconfig", "2", "3");
FakeClientCommand(pEdict, "loadpreconfig", "8", "2");
FakeClientCommand(pEdict, "loadpreconfig", "4", "3");
FakeClientCommand(pEdict, "loadpreconfig", "3", "5");
FakeClientCommand(pEdict, "loadpreconfig", "3", "6");
if (internals.GetFASkillSystem() != 0.0)
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "1");
bot_fa_skill |= MARKS1;
if ((internals.GetFASkillSystem() == 2.0) || (internals.GetFASkillSystem() == 3.0))
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "2");
bot_fa_skill |= MARKS2;
FakeClientCommand(pEdict, "loadpreconfig", "23", "10");
bot_fa_skill |= STEALTH;
}
}
main_weapon = fa_weapon_ssg3000;
backup_weapon = fa_weapon_anaconda;
claymore_slot = fa_weapon_claymore;
}
else if (bot_class == 6)
{
//this will spawn medic
FakeClientCommand(pEdict, "usingpreconfig", nullptr, nullptr);
FakeClientCommand(pEdict, "loadpreconfig", "1", "3");
FakeClientCommand(pEdict, "loadpreconfig", "2", "2");
FakeClientCommand(pEdict, "loadpreconfig", "2", "3");
FakeClientCommand(pEdict, "loadpreconfig", "2", "4");
FakeClientCommand(pEdict, "loadpreconfig", "5", "2");
FakeClientCommand(pEdict, "loadpreconfig", "4", "3");
FakeClientCommand(pEdict, "loadpreconfig", "3", "6");
if (internals.GetFASkillSystem() != 0.0)
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "6");
bot_fa_skill |= FAID;
if ((internals.GetFASkillSystem() == 2.0) || (internals.GetFASkillSystem() == 3.0))
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "7");
bot_fa_skill |= MEDIC;
FakeClientCommand(pEdict, "loadpreconfig", "23", "1");
bot_fa_skill |= MARKS1;
}
}
main_weapon = fa_weapon_benelli;
backup_weapon = fa_weapon_anaconda;
}
else if (bot_class == 7)
{
//this will spawn scout
FakeClientCommand(pEdict, "usingpreconfig", nullptr, nullptr);
FakeClientCommand(pEdict, "loadpreconfig", "1", "2");
FakeClientCommand(pEdict, "loadpreconfig", "2", "2");
FakeClientCommand(pEdict, "loadpreconfig", "2", "3");
FakeClientCommand(pEdict, "loadpreconfig", "7", "5");
FakeClientCommand(pEdict, "loadpreconfig", "4", "6");
FakeClientCommand(pEdict, "loadpreconfig", "3", "3");
FakeClientCommand(pEdict, "loadpreconfig", "3", "6");
if (internals.GetFASkillSystem() != 0.0)
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "8");
bot_fa_skill |= ARTY1;
}
main_weapon = fa_weapon_g36e;
backup_weapon = fa_weapon_desert;
grenade_slot = fa_weapon_concussion;
}
else
{
//this will spawn veteran
FakeClientCommand(pEdict, "usingpreconfig", nullptr, nullptr);
FakeClientCommand(pEdict, "loadpreconfig", "1", "3");
FakeClientCommand(pEdict, "loadpreconfig", "2", "2");
FakeClientCommand(pEdict, "loadpreconfig", "7", "4");
FakeClientCommand(pEdict, "loadpreconfig", "4", "2");
if (internals.GetFASkillSystem() != 0.0)
{
FakeClientCommand(pEdict, "loadpreconfig", "23", "1");
bot_fa_skill |= MARKS1;
}
main_weapon = fa_weapon_g3a3;
backup_weapon = fa_weapon_coltgov;
}
}// END hard coded classes
// init weapon & stuff settings
BotFinishWeaponSpawning(this);
// we need to check skills and spawn all posible skills based on game skill settings
BotFinishSkillsSpawning(this);
// finish spawning
FakeClientCommand(pEdict, "finishedpreconfig", nullptr, nullptr);
// bot has now joined the game (doesn't need to be started)
not_started = 0;
#ifdef _DEBUG
//@@@@@@@@@@@@@@@@
char dmsg[256];
sprintf(dmsg, "Bot reached end of class selection menu (mainW=%d backupW=%d)\n", main_weapon, backup_weapon);
PrintOutput(NULL, dmsg, MType::msg_null);
#endif
return;
}
// handle FA25 base armor menu (ie. light, medium etc.)
// we don't need to confirm this menu
if (start_action == MSG_FA25_BASE_ARMOR_SELECT)
{
start_action = MSG_FA_IDLE;
// use the custom class pointer only if exists
if (pcust_class != nullptr)
{
// init class pointer
Section *class_p = pcust_class;
// go through whole class
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnBaseArmor(this, item_i->second.c_str());
}
}
// otherwise we need to spawn some armor so why not to take the first one
else
FakeClientCommand(pEdict, "vguimenuoption", "1", nullptr);
return;
}
// handle FA25 additional armor menu (ie. helmet etc.)
if (start_action == MSG_FA25_ARMOR_SELECT)
{
start_action = MSG_FA_IDLE;
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnAdditionalArmor(this, item_i->second.c_str());
}
}
// we have to confirm this menu to continue to next section
FakeClientCommand(pEdict, "vguimenuoption", "1", nullptr);
return;
}
// handle FA25 items menu (ie. grenades etc.)
if (start_action == MSG_FA25_ITEMS_SELECT)
{
start_action = MSG_FA_IDLE;
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnItems(this, item_i->second.c_str());
}
}
FakeClientCommand(pEdict, "vguimenuoption", "1", nullptr);
return;
}
// handle FA25 sidearms menu
if (start_action == MSG_FA25_SIDEARMS_SELECT)
{
start_action = MSG_FA_IDLE;
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnSidearms(this, item_i->second.c_str());
}
}
FakeClientCommand(pEdict, "vguimenuoption", "9", nullptr);
return;
}
// handle FA25 shotguns menu
if (start_action == MSG_FA25_SHOTGUNS_SELECT)
{
start_action = MSG_FA_IDLE;
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnShotguns(this, item_i->second.c_str());
}
}
FakeClientCommand(pEdict, "vguimenuoption", "9", nullptr);
return;
}
// handle FA25 submachineguns menu
if (start_action == MSG_FA25_SMGS_SELECT)
{
start_action = MSG_FA_IDLE;
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnSMGs(this, item_i->second.c_str());
}
}
FakeClientCommand(pEdict, "vguimenuoption", "9", nullptr);
return;
}
// handle FA25 rifles menu
if (start_action == MSG_FA25_RIFLES_SELECT)
{
start_action = MSG_FA_IDLE;
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnRifles(this, item_i->second.c_str());
}
}
FakeClientCommand(pEdict, "vguimenuoption", "9", nullptr);
return;
}
// handle FA25 sniper rifles menu
if (start_action == MSG_FA25_SNIPES_SELECT)
{
start_action = MSG_FA_IDLE;
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnSnipes(this, item_i->second.c_str());
}
}
FakeClientCommand(pEdict, "vguimenuoption", "9", nullptr);
return;
}
// handle FA25 machineguns menu
if (start_action == MSG_FA25_MGUNS_SELECT)
{
start_action = MSG_FA_IDLE;
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnMGuns(this, item_i->second.c_str());
}
}
FakeClientCommand(pEdict, "vguimenuoption", "9", nullptr);
return;
}
// handle FA25 grenade launchers menu
if (start_action == MSG_FA25_GLS_SELECT)
{
start_action = MSG_FA_IDLE;
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
FA25SpawnGLs(this, item_i->second.c_str());
}
}
FakeClientCommand(pEdict, "vguimenuoption", "1", nullptr);
return;
}
// handle new skill select
if (start_action == MSG_FA_SKILL_SELECT)
{
bool skill_spawned = FALSE;
start_action = MSG_FA_IDLE;
// if the pointer to custom class exist use it
// otherwise the code logic will spawn one skill randomly
if (pcust_class != nullptr)
{
Section *class_p = pcust_class;
for (II item_i = class_p->item.begin(); item_i != class_p->item.end(); ++item_i)
{
skill_spawned = BotSpawnSkills(this, item_i->second.c_str());
}
}
// there were no or not enough skills in .cfg for this class
if (skill_spawned == FALSE)
{
// generate some skills randomly
char the_skill[4];
sprintf(the_skill, "%d", BotGenerateSkill(this) -1);
FakeClientCommand(pEdict, "setskill", the_skill, nullptr);
#ifdef _DEBUG
//@@@@@@@@@@@@@@@
char dmsg[126];
sprintf(dmsg, "***no skills in .cfg file -> generating skill no. %s\n", the_skill);
PrintOutput(NULL, dmsg, MType::msg_null);
#endif
}
return;
}
// in newer FA versions and use of custom classes this menu isn't called, because
// the bot enters the game at the end of class selection menu, just like a real player who
// used one of the predefined classes
if (start_action == MSG_FA_INTO_BATTLE)
{
start_action = MSG_FA_IDLE; // switch back to idle
// arrange weapons first ie. try to use main weapon slot all the time
RearrangeWeapons(this);
// init weapon based settings
BotFinishWeaponSpawning(this);
// with system 3.0 we automatically get all skills without any skill menu
// so we have to handle that here
if (internals.GetFASkillSystem() == 3.0)
{
// just set all the bytes to ensure correct behaviour
bot_fa_skill |= MARKS1;
bot_fa_skill |= MARKS2;
bot_fa_skill |= NOMEN;
bot_fa_skill |= BATTAG;
bot_fa_skill |= LEADER;
bot_fa_skill |= FAID;
bot_fa_skill |= MEDIC;
bot_fa_skill |= ARTY1;
bot_fa_skill |= ARTY2;
bot_fa_skill |= STEALTH;
}
FakeClientCommand(pEdict, "vguimenuoption", "1", nullptr);
// bot has now joined the game
not_started = 0;
#ifdef _DEBUG
char dmsg[256];
sprintf(dmsg, "***FA join the battle menu confirmed -> now the bot enters the game (mainW=%d backupW=%d)\n",
main_weapon, backup_weapon);
PrintOutput(NULL, dmsg, MType::msg_null);
#endif
return;
}
}
else
{
// otherwise, don't need to do anything to start game
not_started = 0;
}
}
/*
* inits weapon slots and calls other methods to finalize the spawn
*/
void BotFinishWeaponSpawning(bot_t *pBot)
{
#ifdef _DEBUG
ALERT(at_console, "BotFinishWeaponSpawning() called\n");
#endif
// have both weapons (main and backup) so use main
if ((pBot->main_weapon != NO_VAL) && (pBot->backup_weapon != NO_VAL))
{
pBot->UseWeapon(USE_MAIN);
pBot->main_no_ammo = FALSE;
pBot->backup_no_ammo = FALSE;
}
// have main weapon AND no backup weapon so use main
else if ((pBot->main_weapon != NO_VAL) && (pBot->backup_weapon == NO_VAL))
{
pBot->UseWeapon(USE_MAIN);
pBot->main_no_ammo = FALSE;
pBot->backup_no_ammo = TRUE;
}
// if no main weapon AND already have backup weapon so use it
else if ((pBot->main_weapon == NO_VAL) && (pBot->backup_weapon != NO_VAL))
{
pBot->UseWeapon(USE_BACKUP);
pBot->main_no_ammo = TRUE;
pBot->backup_no_ammo = FALSE;
}
// otherwise if both aren't available use knife
else if ((pBot->main_weapon == NO_VAL) && (pBot->backup_weapon == NO_VAL))
{
pBot->UseWeapon(USE_KNIFE);
pBot->main_no_ammo = TRUE;
pBot->backup_no_ammo = TRUE;
}
// is bot equipped with grenades use them
if (pBot->grenade_slot != NO_VAL)
pBot->grenade_action = ALTW_NOTUSED;
// otherwise prevent running BotThrowGrenade
else
pBot->grenade_action = ALTW_USED;
// set the behaviour now (bot already have weapon)
if (pBot->bot_behaviour == 0)
BotSetBehaviour(pBot);
// check if the bot has a weapon that supports silencer
if (pBot->weapon_status == 0)
BotSetWeaponStatus(pBot);
}
/*
* checks the game skill system and do sets & spawn all skills the bot needs to join the game
*/
void BotFinishSkillsSpawning(bot_t *pBot)
{
#ifdef _DEBUG
ALERT(at_console, "BotFinishSkillsSpawning() called\n");
#endif
// spawn one or more skills to finish spawning if bot do NOT have any
const int number_of_skills = NumberOfFASkills(pBot);
if ((pBot->bot_fa_skill == 0) || ((internals.GetFASkillSystem() == 1.0) && (number_of_skills < 1)) ||
((internals.GetFASkillSystem() == 2.0) && (number_of_skills < 4)) || (internals.GetFASkillSystem() == 3.0))
{
// is system without skills so do nothing
if (internals.GetFASkillSystem() == 0.0)
return;
if (internals.GetFASkillSystem() == 1.0)
{
char the_skill[4];
// convert skill value to char
sprintf(the_skill, "%d", BotGenerateSkill(pBot) - 1);
FakeClientCommand(pBot->pEdict, "loadpreconfig", "23", the_skill);
}
else if (internals.GetFASkillSystem() == 2.0)
{
char the_skill[4];
// with system 2.0 we can spawn 4 skills
// so check how many skills bot already have
const int still_need = 4 - number_of_skills;
// and spawn the rest we need
for (int i = 0; i < still_need; i++)
{
sprintf(the_skill, "%d", BotGenerateSkill(pBot));
FakeClientCommand(pBot->pEdict, "loadpreconfig", "23", the_skill);
}
}
else if (internals.GetFASkillSystem() == 3.0)
{
// with system 3.0 we get all skills
// so just set all these bytes for correct behaviour
pBot->bot_fa_skill |= MARKS1;
pBot->bot_fa_skill |= MARKS2;
pBot->bot_fa_skill |= NOMEN;
pBot->bot_fa_skill |= BATTAG;
pBot->bot_fa_skill |= LEADER;
pBot->bot_fa_skill |= FAID;
pBot->bot_fa_skill |= MEDIC;
pBot->bot_fa_skill |= ARTY1;
pBot->bot_fa_skill |= ARTY2;
pBot->bot_fa_skill |= STEALTH;
}
}
}
/*
* generates and returns new FA skill bot can choose
* checking which of skills bot already has
*/
int BotGenerateSkill(bot_t *pBot)
{
int new_skill;
bool spawn_different = TRUE;
#ifdef _DEBUG
ALERT(at_console, "BotGenerateSkill() called\n");
#endif
new_skill = RANDOM_LONG(1, 10);
// do generate different skill until one is valid (i.e. bot doesn't have it yet)
for(; ;)
{
if (((new_skill == 1) && !(pBot->bot_fa_skill & MARKS1)) ||
((new_skill == 2) && !(pBot->bot_fa_skill & MARKS2)) ||
((new_skill == 3) && !(pBot->bot_fa_skill & NOMEN)) ||
((new_skill == 4) && !(pBot->bot_fa_skill & BATTAG)) ||
((new_skill == 5) && !(pBot->bot_fa_skill & LEADER)) ||
((new_skill == 6) && !(pBot->bot_fa_skill & FAID)) ||
((new_skill == 7) && !(pBot->bot_fa_skill & MEDIC)) ||
((new_skill == 8) && !(pBot->bot_fa_skill & ARTY1)) ||
((new_skill == 9) && !(pBot->bot_fa_skill & ARTY2)) ||
((new_skill == 10) && !(pBot->bot_fa_skill & STEALTH)))
{
spawn_different = FALSE;
break;
}
new_skill = RANDOM_LONG(1, 10);
}
if (spawn_different == FALSE)
{
if (new_skill == 1)
pBot->bot_fa_skill |= MARKS1;
else if (new_skill == 2)
{
// does bot already have marksmanship1
if (pBot->bot_fa_skill & MARKS1)
pBot->bot_fa_skill |= MARKS2;
// otherwise take the marksmanship1 first
else
{
pBot->bot_fa_skill |= MARKS1;
// lower it to return correct value
new_skill--;
}
}
else if (new_skill == 3)
pBot->bot_fa_skill |= NOMEN;
else if (new_skill == 4)
pBot->bot_fa_skill |= BATTAG;
else if (new_skill == 5)
pBot->bot_fa_skill |= LEADER;
else if (new_skill == 6)
pBot->bot_fa_skill |= FAID;
else if (new_skill == 7)
{
if (pBot->bot_fa_skill & FAID)
pBot->bot_fa_skill |= MEDIC;
else
{
pBot->bot_fa_skill |= FAID;
new_skill--;
}
}
else if (new_skill == 8)
pBot->bot_fa_skill |= ARTY1;
else if (new_skill == 9)
{
if (pBot->bot_fa_skill & ARTY1)
pBot->bot_fa_skill |= ARTY2;
else
{
pBot->bot_fa_skill |= ARTY1;
new_skill--;
}
}
else if (new_skill == 10)
pBot->bot_fa_skill |= STEALTH;
#ifdef _DEBUG
ALERT(at_console, "***bot picked skill no. %d\n", new_skill);
#endif
return new_skill;
}
// log possible error
char ermsg[126];
sprintf(ermsg, "***BotGenerateSkill() FATAL ERROR (trying to spawn skill no. %d)\n", new_skill);
UTIL_DebugInFile(ermsg);
ALERT(at_console, ermsg);
return -1;
}
/*
* sets the best behaviour type based on current weapon
*/
inline void BotSetBehaviour(bot_t *pBot)
{
char behaviour_byte1[32], behaviour_byte2[32];
// set additional behaviour (for path system)
// based on version of Fireamrs
if (UTIL_IsSniperRifle(pBot->main_weapon))
pBot->bot_behaviour |= SNIPER;
else if (UTIL_IsMachinegun(pBot->main_weapon))
pBot->bot_behaviour |= MGUNNER;
else if (UTIL_IsSMG(pBot->main_weapon) || UTIL_IsShotgun(pBot->main_weapon))
pBot->bot_behaviour |= CQUARTER;
else
pBot->bot_behaviour |= COMMON;
// set main behaviour
// SNIPER RIFLES
if (pBot->bot_behaviour & SNIPER)
{
strcpy(behaviour_byte2, "sniper");
// in 25% of the time baheave normally
if (RANDOM_LONG(1, 100) > 75)
pBot->bot_behaviour |= STANDARD;
// otherwise behave defensively
else
pBot->bot_behaviour |= DEFENDER;
}