-
Notifications
You must be signed in to change notification settings - Fork 19
/
IniParser.cpp
1238 lines (1030 loc) · 38.9 KB
/
IniParser.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
/**
* RealBot : Artificial Intelligence
* Version : Work In Progress
* Author : Stefan Hendriks
* Url : http://realbot.bots-united.com
**
* DISCLAIMER
*
* History, Information & Credits:
* RealBot is based partially upon the HPB-Bot Template #3 by Botman
* Thanks to Ditlew (NNBot), Pierre Marie Baty (RACCBOT), Tub (RB AI PR1/2/3)
* Greg Slocum & Shivan (RB V1.0), Botman (HPB-Bot) and Aspirin (JOEBOT). And
* everybody else who helped me with this project.
* Storage of Visibility Table using BITS by Cheesemonster.
*
* Some portions of code are from other bots, special thanks (and credits) go
* to (in no specific order):
*
* Pierre Marie Baty
* Count-Floyd
*
* !! BOTS-UNITED FOREVER !!
*
* This project is open-source, it is protected under the GPL license;
* By using this source-code you agree that you will ALWAYS release the
* source-code with your project.
*
**/
/**
* INI PARSER
* COPYRIGHTED BY STEFAN HENDRIKS (C) 2003-2004
**/
#include <string.h>
#include <extdll.h>
#include <dllapi.h>
#include <meta_api.h>
#include <entity_state.h>
#include "bot.h"
#include "game.h"
#include "bot_weapons.h"
#include "bot_func.h"
#include "IniParser.h"
#include "NodeMachine.h"
#include "ChatEngine.h"
#include <ctype.h>
extern int mod_id;
extern edict_t *pHostEdict;
extern cNodeMachine NodeMachine;
extern int m_spriteTexture;
extern cGame Game;
extern cChatEngine ChatEngine;
// Reads out INPUT , will check for a [ at [0] and then checks till ], it will fill section[]
// with the chars in between. So : [MAP] -> section = 'MAP'. Use function INI_SectionType(..)
// to get the correct ID for that.
void INI_Section(char input[80], char section[30]) {
int pos = 0;
int end_pos = -1;
// clear out entire string
for (int i = 0; i < 30; i++)
section[i] = '\0';
// check if the first character is a '['
if (input[0] == '[') {
pos = 1; // Begin at character 1
while (pos < 79) {
if (input[pos] == ']') {
end_pos = pos - 1;
break;
}
pos++;
}
if (end_pos > 1 && end_pos < 29) {
for (int wc = 0; wc < end_pos; wc++)
section[wc] = input[wc + 1];
section[end_pos] = '\0'; // terminate string
}
}
}
// Reads out INPUT and will check for an '=' Everything at the left of the
// '=' IS a word and will be put in 'word[]'. Use function INI_WordType(char word[25]) to get
// the correct ID tag.
void INI_Word(char input[80], char word[25]) {
int pos = 0;
int word_pos = -1;
// clear out entire string
for (int i = 0; i < 25; i++)
word[i] = '\0';
while (pos < 79) {
if (input[pos] == '=') {
word_pos = pos;
break;
}
pos++;
}
if (word_pos > -1 && word_pos < 23) {
for (int wc = 0; wc < word_pos; wc++)
word[wc] = input[wc];
word[word_pos] = '\0'; // terminate string
}
}
// Reads out word[], does a string compare and returns type id
int INI_WordType(char word[25], int section) {
if (strlen(word) > 0) {
if (strcmp(word, "Word") == 0)
return WORD_WORD;
if (strcmp(word, "Sentence") == 0)
return WORD_SENTENCE;
if (strcmp(word, "X") == 0)
return WORD_AREAX;
if (strcmp(word, "Y") == 0)
return WORD_AREAY;
if (strcmp(word, "Z") == 0)
return WORD_AREAZ;
// ------ personality stuff ------
if (strcmp(word, "PrimaryWeapon") == 0)
return WORD_PRIWEAPON;
if (strcmp(word, "SecondaryWeapon") == 0)
return WORD_SECWEAPON;
if (strcmp(word, "SaveForWeapon") == 0)
return WORD_SAVEFORWEAP;
if (strcmp(word, "Grenade") == 0)
return WORD_GRENADE;
if (strcmp(word, "FlashBang") == 0)
return WORD_FLASHBANG;
if (strcmp(word, "SmokeGrenade") == 0)
return WORD_SMOKEGREN;
if (strcmp(word, "DefuseKit") == 0)
return WORD_DEFUSEKIT;
if (strcmp(word, "Armour") == 0)
return WORD_ARMOUR;
// ---- skill
if (strcmp(word, "XOffset") == 0)
return WORD_XOFFSET;
if (strcmp(word, "YOffset") == 0)
return WORD_YOFFSET;
if (strcmp(word, "ZOffset") == 0)
return WORD_ZOFFSET;
if (strcmp(word, "BotSkill") == 0)
return WORD_BOTSKILL;
if (strcmp(word, "MaxReactionTime") == 0)
return WORD_MAXREACTTIME;
if (strcmp(word, "MinReactionTime") == 0)
return WORD_MINREACTTIME;
if (strcmp(word, "Turnspeed") == 0)
return WORD_TURNSPEED;
// ---- Game
if (strcmp(word, "Hostage") == 0)
return WORD_HOSTAGERATE;
if (strcmp(word, "BompSpot") == 0)
return WORD_BOMBSPOTRATE;
if (strcmp(word, "Random") == 0)
return WORD_RANDOMRATE;
if (strcmp(word, "DroppedBomb") == 0)
return WORD_DROPPEDBOMB;
// ---- Radio
if (strcmp(word, "Reply") == 0)
return WORD_REPLYRADIO;
if (strcmp(word, "Create") == 0)
return WORD_CREATERADIO;
// ---- Team
if (strcmp(word, "HelpTeammate") == 0)
return WORD_HELPTEAM;
// ---- person
if (strcmp(word, "WalkWithKnife") == 0)
return WORD_WALKKNIFE;
if (strcmp(word, "FearRate") == 0)
return WORD_FEARRATE;
if (strcmp(word, "HearRate") == 0)
return WORD_HEARRATE;
if (strcmp(word, "ChatRate") == 0)
return WORD_CHATRATE;
if (strcmp(word, "CampRate") == 0)
return WORD_CAMPRATE;
// ------ buy table stuff -------
if (strcmp(word, "Price") == 0)
return WORD_PRICE;
if (strcmp(word, "Priority") == 0)
return WORD_PRIORITY;
if (strcmp(word, "Ammo1Index") == 0)
return WORD_INDEX1;
if (strcmp(word, "Ammo2Index") == 0)
return WORD_INDEX2;
if (strcmp(word, "Ammo1Max") == 0)
return WORD_MAXAMMO1;
if (strcmp(word, "Ammo2Max") == 0)
return WORD_MAXAMMO2;
}
return WORD_NONE;
}
// Reads out an entire sentence and returns it
void INI_Sentence(FILE * f, char result[80]) {
char ch;
int pos = 0;
// clear out entire string
for (int i = 0; i < 80; i++)
result[i] = '\0';
while ((feof(f) == 0) && ((ch = fgetc(f)) != '\n')) {
result[pos] = ch;
pos++;
// do not allow strings greater then 80 characters. This check prevents a crash for
// users who do exceed the limit.
if (pos > 79)
break;
// remove dedicated server garbage
//putchar (ch);
}
}
// Reads out section[], does a string compare and returns type id
int INI_SectionType(char section[30], int last) {
if (strcmp(section, "BLOCK") == 0)
return INI_BLOCK;
if (strcmp(section, "DEATH") == 0)
return INI_DEATHS;
if (strcmp(section, "WELCOME") == 0)
return INI_WELCOME;
if (strcmp(section, "AREA") == 0)
return INI_AREA;
if (strcmp(section, "WEAPON") == 0)
return INI_WEAPON;
if (strcmp(section, "SKILL") == 0)
return INI_SKILL;
if (strcmp(section, "GAME") == 0)
return INI_GAME;
if (strcmp(section, "RADIO") == 0)
return INI_RADIO;
if (strcmp(section, "TEAM") == 0)
return INI_TEAM;
if (strcmp(section, "PERSON") == 0)
return INI_PERSON;
// When nothing found; we assume its just a new ID tag for some unit or structure
// Therefor we return the last known SECTION ID so we can assign the proper WORD ID's
return last;
}
// Reads out section[], does a string compare and returns type id
// BUYTABLE.INI SPECIFIC!
int INI_SectionType_BUYTABLE(char section[30], int last) {
if (strcmp(section, "P228") == 0)
return CS_WEAPON_P228;
if (strcmp(section, "HEGRENADE") == 0)
return CS_WEAPON_HEGRENADE;
if (strcmp(section, "AK47") == 0)
return CS_WEAPON_AK47;
if (strcmp(section, "DEAGLE") == 0)
return CS_WEAPON_DEAGLE;
if (strcmp(section, "MAC10") == 0)
return CS_WEAPON_MAC10;
if (strcmp(section, "AUG") == 0)
return CS_WEAPON_AUG;
if (strcmp(section, "SG552") == 0)
return CS_WEAPON_SG552;
if (strcmp(section, "ELITE") == 0)
return CS_WEAPON_ELITE;
if (strcmp(section, "FIVESEVEN") == 0)
return CS_WEAPON_FIVESEVEN;
if (strcmp(section, "UMP45") == 0)
return CS_WEAPON_UMP45;
if (strcmp(section, "SG550") == 0)
return CS_WEAPON_SG550;
if (strcmp(section, "USP") == 0)
return CS_WEAPON_USP;
if (strcmp(section, "GLOCK18") == 0)
return CS_WEAPON_GLOCK18;
if (strcmp(section, "AWP") == 0)
return CS_WEAPON_AWP;
if (strcmp(section, "MP5") == 0)
return CS_WEAPON_MP5NAVY;
if (strcmp(section, "M249") == 0)
return CS_WEAPON_M249;
if (strcmp(section, "M3") == 0)
return CS_WEAPON_M3;
if (strcmp(section, "M4A1") == 0)
return CS_WEAPON_M4A1;
if (strcmp(section, "TMP") == 0)
return CS_WEAPON_TMP;
if (strcmp(section, "G3SG1") == 0)
return CS_WEAPON_G3SG1;
if (strcmp(section, "SCOUT") == 0)
return CS_WEAPON_SCOUT;
if (strcmp(section, "FLASHBANG") == 0)
return CS_WEAPON_FLASHBANG;
if (strcmp(section, "C4") == 0)
return CS_WEAPON_C4;
if (strcmp(section, "SMOKEGRENADE") == 0)
return CS_WEAPON_SMOKEGRENADE;
if (strcmp(section, "XM1014") == 0)
return CS_WEAPON_XM1014;
if (strcmp(section, "KNIFE") == 0)
return CS_WEAPON_KNIFE;
if (strcmp(section, "P90") == 0)
return CS_WEAPON_P90;
// Counter-Strike 1.6
if (strcmp(section, "FAMAS") == 0)
return CS_WEAPON_FAMAS;
if (strcmp(section, "GALIL") == 0)
return CS_WEAPON_GALIL;
// Unconfirmed
if (strcmp(section, "SHIELD") == 0)
return CS_WEAPON_SHIELD;
// When nothing found; we assume its just a new ID tag for some unit or structure
// Therefor we return the last known SECTION ID so we can assign the proper WORD ID's
return last;
}
// Reads out 'result' and will return the value after the '='. Returns integer.
// For CHAR returns see "INI_WordValueCHAR(char result[80]);
int INI_WordValueINT(char result[80]) {
int pos = 0;
int is_pos = -1;
while (pos < 79) {
if (result[pos] == '=') {
is_pos = pos;
break;
}
pos++;
}
if (is_pos > -1) {
// Whenever the IS (=) position is known, we make a number out of 'IS_POS' till the next empty
// space.
int end_pos = -1;
while (pos < 79) {
if (result[pos] == '\0') {
end_pos = pos;
break;
}
pos++;
}
// End position found!
if (end_pos > -1) {
// We know the END position. We will use that piece of string to read out a number.
char number[10];
// clear out entire string
for (int i = 0; i < 10; i++)
number[i] = '\0';
// Copy the part to 'number', Make sure we won't get outside the array of the character.
int cp = is_pos + 1;
int c = 0;
while (cp < end_pos) {
number[c] = result[cp];
c++;
cp++;
if (c > 9)
break;
}
/*
char aa[80];
sprintf(aa, "Original %s, atoi %d\n", number, atoi(number));
DebugOut(aa);
*/
return atoi(number);
}
// nothing here, so we return NULL at the end
}
return 0; // No value, return 0 (was NULL)
}
// Reads out 'result' and will return the value after the '='. Returns integer.
// For CHAR returns see "INI_WordValueCHAR(char result[80]);
float INI_WordValueFLOAT(char result[80]) {
int pos = 0;
int is_pos = -1;
while (pos < 79) {
if (result[pos] == '=') {
is_pos = pos;
break;
}
pos++;
}
if (is_pos > -1) {
// Whenever the IS (=) position is known, we make a number out of 'IS_POS' till the next empty
// space.
int end_pos = -1;
while (pos < 79) {
if (result[pos] == '\0') {
end_pos = pos;
break;
}
pos++;
}
// End position found!
if (end_pos > -1) {
// We know the END position. We will use that piece of string to read out a number.
char number[10];
// clear out entire string
for (int i = 0; i < 10; i++)
number[i] = '\0';
// Copy the part to 'number', Make sure we won't get outside the array of the character.
int cp = is_pos + 1;
int c = 0;
while (cp < end_pos) {
number[c] = result[cp];
c++;
cp++;
if (c > 9)
break;
}
return atof(number);
}
// nothing here, so we return NULL at the end
}
return 0.0; // No value, return 0.0 was NULL
}
// Reads out 'result' and will return the value after the '='. Returns nothing but will put
// the result in 'value[25]'. Max argument may be 25 characters!
void INI_WordValueCHAR(char result[80], char value[80]) {
int pos = 0;
int is_pos = -1;
// clear out entire string
for (int i = 0; i < 25; i++)
value[i] = '\0';
while (pos < 79) {
if (result[pos] == '=') {
is_pos = pos;
break;
}
pos++;
}
if (is_pos > -1) {
// Whenever the IS (=) position is known, we make a number out of 'IS_POS' till the next empty
// space.
int end_pos = -1;
while (pos < 79) {
if (result[pos] == '\0') {
end_pos = pos;
break;
}
pos++;
}
// End position found!
if (end_pos > -1) {
// We know the END position. We will use that piece of string to read out a number.
// Copy the part to 'value', Make sure we won't get outside the array of the character.
int cp = is_pos + 1;
int c = 0;
while (cp < end_pos) {
value[c] = result[cp];
c++;
cp++;
if (c > 79)
break;
}
}
}
}
// parses the chat file (loads in blocks)
void INI_PARSE_CHATFILE() {
char dirname[256];
char filename[256];
FILE *stream;
int section = INI_NONE;
int wordtype = WORD_NONE;
// Set Directory name + file
strcpy(dirname, "data/cstrike/chat.ini");
// writes whole path into "filename", Linux compatible
UTIL_BuildFileNameRB(dirname, filename);
// make sure the engine knows...
REALBOT_PRINT(NULL, "INI_PARSE_CHATFILE", "Loading CHAT.INI\n");
int iBlockId = -1;
int iBlockWord = -1;
int iBlockSentence = -1;
// load it
if ((stream = fopen(filename, "r+t")) != NULL) {
char linefeed[80];
char lineword[25];
char linesection[30];
// infinite loop baby
while (!feof(stream)) {
INI_Sentence(stream, linefeed);
// Linefeed contains a string of 1 sentence. Whenever the first character is a commentary
// character (which is "//", ";" or "#"), or an empty line, then skip it
if (linefeed[0] == ';' ||
linefeed[0] == '#' ||
(linefeed[0] == '/' && linefeed[1] == '/') ||
linefeed[0] == '\n' || linefeed[0] == '\0')
continue; // Skip
wordtype = WORD_NONE;
// Every line is checked for a new section.
INI_Section(linefeed, linesection);
if (linesection[0] != '\0' && strlen(linesection) > 1) {
section = INI_SectionType(linesection, section);
if (section == INI_BLOCK) {
iBlockId++;
if (iBlockId > 97)
iBlockId = 97;
section = INI_NONE;
iBlockWord = -1;
iBlockSentence = -1;
}
if (section == INI_DEATHS) {
iBlockId = 99; // 99 = death
iBlockWord = -1;
iBlockSentence = -1;
section = INI_NONE;
}
if (section == INI_WELCOME) {
iBlockId = 98; // 98 = welcome
iBlockWord = -1;
iBlockSentence = -1;
section = INI_NONE;
}
continue; // next line
}
if (iBlockId > -1) {
INI_Word(linefeed, lineword);
wordtype = INI_WordType(lineword, section);
// We load in words
if (wordtype == WORD_WORD) {
iBlockWord++;
if (iBlockWord > 9)
iBlockWord = 9;
// write the word in the block
char chWord[25];
memset(chWord, 0, sizeof(chWord));
INI_WordValueCHAR(linefeed, chWord);
// lower case
//chWord = _strlwr( _strdup( chWord ) );
#ifdef _WIN32
_strupr(chWord);
// #elseif did not work for MSVC
#else
//for linux by ok:
// transform removed by evyncke since it works only on strings and not char array
//further changed back by evyncke as these are normal string not CString
//Hence, hardcoding the strupr inline...
char *pString;
pString = chWord;
while (*pString) {
*pString = toupper(*pString);
pString++;
}
#endif
strcpy(ChatEngine.ReplyBlock[iBlockId].word[iBlockWord],
chWord);
}
if (wordtype == WORD_SENTENCE) {
iBlockSentence++;
if (iBlockSentence > 49)
iBlockSentence = 49;
// write the word in the block
char chSentence[80];
memset(chSentence, 0, sizeof(chSentence));
INI_WordValueCHAR(linefeed, chSentence);
strcpy(ChatEngine.ReplyBlock[iBlockId].
sentence[iBlockSentence], chSentence);
// here we say it is used
ChatEngine.ReplyBlock[iBlockId].bUsed = true;
}
}
} // while
fclose(stream);
}
}
// Parse IAD file:
// Important Area Definition file
void INI_PARSE_IAD() {
char dirname[256];
char filename[256];
FILE *stream;
int section = INI_NONE;
int wordtype = WORD_NONE;
// Set Directory name
strcpy(dirname, "data/cstrike/ini/");
strcat(dirname, STRING(gpGlobals->mapname));
strcat(dirname, ".ini"); // nodes file
// writes whole path into "filename", Linux compatible
UTIL_BuildFileNameRB(dirname, filename);
SERVER_PRINT(filename);
SERVER_PRINT("\n");
float AreaX, AreaY, AreaZ;
AreaX = AreaY = AreaZ = 9999;
if ((stream = fopen(filename, "r+t")) != NULL) {
char linefeed[80];
char lineword[25];
char linesection[30];
while (!feof(stream)) {
INI_Sentence(stream, linefeed);
// Linefeed contains a string of 1 sentence. Whenever the first character is a commentary
// character (which is "//", ";" or "#"), or an empty line, then skip it
if (linefeed[0] == ';' ||
linefeed[0] == '#' ||
(linefeed[0] == '/' && linefeed[1] == '/') ||
linefeed[0] == '\n' || linefeed[0] == '\0')
continue; // Skip
wordtype = WORD_NONE;
// Every line is checked for a new section.
INI_Section(linefeed, linesection);
if (linesection[0] != '\0' && strlen(linesection) > 1) {
section = INI_SectionType(linesection, section);
continue; // next line
}
// Check word only when in a section
if (section != INI_NONE) {
INI_Word(linefeed, lineword);
wordtype = INI_WordType(lineword, section);
if (section == INI_AREA) {
if (wordtype == WORD_AREAX)
AreaX = INI_WordValueINT(linefeed);
if (wordtype == WORD_AREAY)
AreaY = INI_WordValueINT(linefeed);
if (wordtype == WORD_AREAZ)
AreaZ = INI_WordValueINT(linefeed);
if (AreaX != 9999 && AreaY != 9999 && AreaZ != 9999) {
// add this to goal
rblog("IAD: Adding an important area/goal\n");
NodeMachine.addGoal(NULL, GOAL_IMPORTANT, Vector(AreaX, AreaY, AreaZ));
AreaX = AreaY = AreaZ = 9999;
}
}
}
} // while
fclose(stream);
}
}
// Parse personality file
void INI_PARSE_BOTS(char cBotName[33], cBot * pBot) {
/*
Revisited: 02/07/05 - Stefan
Last bug/issue report:
- seems to overwrite personality file ? (loading does not work?)
RESULT: There is no bug.
- removed any messages sent by this function.
*/
FILE *stream;
int section = INI_NONE;
int wordtype = WORD_NONE;
char dirname[256];
char filename[256];
// Set Directory name
if (mod_id == CSTRIKE_DLL)
strcpy(dirname, "data/cstrike/bots/");
//strcat(dirname, STRING(gpGlobals->mapname));
strcat(dirname, cBotName);
strcat(dirname, ".ini");
// writes whole path into "filename", Linux compatible
UTIL_BuildFileNameRB(dirname, filename);
// we open the file here!
if ((stream = fopen(filename, "r+t")) != NULL) {
char linefeed[80];
char lineword[25];
char linesection[30];
// infinite loop baby
while (!feof(stream)) {
INI_Sentence(stream, linefeed);
// Linefeed contains a string of 1 sentence. Whenever the first character is a commentary
// character (which is "//", ";" or "#"), or an empty line, then skip it
if (linefeed[0] == ';' ||
linefeed[0] == '#' ||
(linefeed[0] == '/' && linefeed[1] == '/') ||
linefeed[0] == '\n' || linefeed[0] == '\0')
continue; // Skip
wordtype = WORD_NONE;
// Every line is checked for a new section.
INI_Section(linefeed, linesection);
if (linesection[0] != '\0' && strlen(linesection) > 1) {
section = INI_SectionType(linesection, section);
continue; // next line
}
// Check word only when in a section
if (section != INI_NONE) {
INI_Word(linefeed, lineword);
wordtype = INI_WordType(lineword, section);
// WEAPON
if (section == INI_WEAPON) {
// 30/07/04 Josh
// Code optimization using a case instead of series of IF THEN
switch (wordtype) {
case WORD_PRIWEAPON:
pBot->ipFavoPriWeapon = INI_WordValueINT(linefeed);
break;
case WORD_SECWEAPON:
pBot->ipFavoSecWeapon = INI_WordValueINT(linefeed);
break;
case WORD_GRENADE:
pBot->ipBuyGrenade = INI_WordValueINT(linefeed);
break;
case WORD_SAVEFORWEAP:
pBot->ipSaveForWeapon = INI_WordValueINT(linefeed);
break;
case WORD_FLASHBANG:
pBot->ipBuyFlashBang = INI_WordValueINT(linefeed);
break;
case WORD_SMOKEGREN:
pBot->ipBuySmokeGren = INI_WordValueINT(linefeed);
break;
case WORD_DEFUSEKIT:
pBot->ipBuyDefuseKit = INI_WordValueINT(linefeed);
break;
case WORD_ARMOUR:
pBot->ipBuyArmour = INI_WordValueINT(linefeed);
break;
}
}
// SKILL
if (section == INI_SKILL) {
switch (wordtype) {
case WORD_MINREACTTIME:
pBot->fpMinReactTime = INI_WordValueFLOAT(linefeed);
break;
case WORD_MAXREACTTIME:
pBot->fpMaxReactTime = INI_WordValueFLOAT(linefeed);
break;
case WORD_XOFFSET:
pBot->fpXOffset = INI_WordValueFLOAT(linefeed);
break;
case WORD_YOFFSET:
pBot->fpYOffset = INI_WordValueFLOAT(linefeed);
break;
case WORD_ZOFFSET:
pBot->fpZOffset = INI_WordValueFLOAT(linefeed);
break;
}
// default we override bot skill with personality skill
if (Game.iOverrideBotSkill == GAME_YES)
if (wordtype == WORD_BOTSKILL)
pBot->bot_skill = INI_WordValueINT(linefeed);
}
// GAME
if (section == INI_GAME) {
if (wordtype == WORD_HOSTAGERATE)
pBot->ipHostage = INI_WordValueINT(linefeed);
if (wordtype == WORD_BOMBSPOTRATE)
pBot->ipBombspot = INI_WordValueINT(linefeed);
if (wordtype == WORD_RANDOMRATE)
pBot->ipRandom = INI_WordValueINT(linefeed);
if (wordtype == WORD_DROPPEDBOMB)
pBot->ipDroppedBomb = INI_WordValueINT(linefeed);
}
// RADIO
if (section == INI_RADIO) {
if (wordtype == WORD_REPLYRADIO)
pBot->ipReplyToRadio = INI_WordValueINT(linefeed);
if (wordtype == WORD_CREATERADIO)
pBot->ipCreateRadio = INI_WordValueINT(linefeed);
}
// TEAM
if (section == INI_TEAM) {
if (wordtype == WORD_HELPTEAM)
pBot->ipHelpTeammate = INI_WordValueINT(linefeed);
}
// PERSON
if (section == INI_PERSON) {
if (wordtype == WORD_TURNSPEED)
pBot->ipTurnSpeed = INI_WordValueINT(linefeed);
if (wordtype == WORD_WALKKNIFE)
pBot->ipWalkWithKnife = INI_WordValueINT(linefeed);
if (wordtype == WORD_FEARRATE)
pBot->ipFearRate = INI_WordValueINT(linefeed);
if (wordtype == WORD_HEARRATE)
pBot->ipHearRate = INI_WordValueINT(linefeed);
if (wordtype == WORD_CHATRATE)
pBot->ipChatRate = INI_WordValueINT(linefeed);
if (wordtype == WORD_CAMPRATE)
pBot->ipCampRate = INI_WordValueINT(linefeed);
}
}
}
fclose(stream);
}
// When we end up here, there is NO file?
else {
// Create new variables and save them into file.
// Buy preferences
pBot->ipFavoPriWeapon = -1;
pBot->ipFavoSecWeapon = -1;
pBot->ipBuyFlashBang = RANDOM_LONG(20, 80);
pBot->ipBuyGrenade = RANDOM_LONG(20, 80);
pBot->ipBuySmokeGren = RANDOM_LONG(20, 80);
pBot->ipBuyDefuseKit = RANDOM_LONG(20, 80);
pBot->ipDroppedBomb = RANDOM_LONG(20, 80);
pBot->ipSaveForWeapon = RANDOM_LONG(0, 30);
pBot->ipBuyArmour = RANDOM_LONG(30, 100);
pBot->ipFearRate = RANDOM_LONG(20, 60);
// Skill, everything but botskill can change.
// Determine reaction time based upon botskill here
float fMinReact = 0.0, fMaxReact;
if (pBot->bot_skill == 0)
fMinReact = 0.0;
else
//30.8.04 redefined by frashman
// fMinReact = RANDOM_FLOAT (0.05, (pBot->bot_skill / 10));
fMinReact =
RANDOM_FLOAT((pBot->bot_skill / 20) + 0.05,
(pBot->bot_skill / 5) + 0.05);
fMaxReact = fMinReact + RANDOM_FLOAT(0.05, 0.2);
// SET them
pBot->fpMinReactTime = fMinReact;
pBot->fpMaxReactTime = fMaxReact;
// Set Offsets (note, they are extra upon current aiming code)
// 30.8.04 redefined by frashman
// float fOffset = RANDOM_FLOAT ((pBot->bot_skill / 5), (pBot->bot_skill / 2));
float fOffset = RANDOM_FLOAT((pBot->bot_skill / 5) + 0.05,
(pBot->bot_skill / 2) + 0.05);
// SET
pBot->fpXOffset = pBot->fpYOffset = pBot->fpZOffset = fOffset;
// Team
pBot->ipHelpTeammate = RANDOM_LONG(10, 70);
// Game
pBot->ipHostage = RANDOM_LONG(25, 70);
pBot->ipBombspot = RANDOM_LONG(25, 70);
pBot->ipRandom = RANDOM_LONG(25, 70);
// Radio
pBot->ipReplyToRadio = RANDOM_LONG(10, 60);
pBot->ipCreateRadio = RANDOM_LONG(10, 60);
pBot->ipHearRate = RANDOM_LONG(10, 60);
// Person
pBot->ipTurnSpeed = RANDOM_LONG(20, 40);
pBot->ipCampRate = RANDOM_LONG(0, 60);
pBot->ipChatRate = RANDOM_LONG(0, 30);
pBot->ipWalkWithKnife = RANDOM_LONG(0, 60);
// SAVE TO DISK:
char dirname[256];
char filename[256];
// Set Directory name
if (mod_id == CSTRIKE_DLL)
strcpy(dirname, "data/cstrike/bots/");
strcat(dirname, cBotName);
strcat(dirname, ".ini");
// writes whole path into "filename", Linux compatible
UTIL_BuildFileNameRB(dirname, filename);
FILE *rbl;
// Only save if lock type is < 1