-
Notifications
You must be signed in to change notification settings - Fork 18
/
game.cpp
803 lines (677 loc) · 25.6 KB
/
game.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
/**
* 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.
*
**/
#include <string.h>
#include <extdll.h>
#include <dllapi.h>
#include <meta_api.h>
#include <entity_state.h>
#include "bot.h"
#include "game.h"
#include "NodeMachine.h"
#include "ChatEngine.h"
#include "IniParser.h"
#include "bot_func.h"
extern cNodeMachine NodeMachine;
extern cChatEngine ChatEngine;
extern cGame Game;
extern cBot bots[MAX_BOTS];
// GAME: Init
void cGame::Init() {
// Default Bot Skill
iDefaultBotSkill = -1; // random
iOverrideBotSkill = GAME_YES;
// Randomized skill boundries
iRandomMinSkill = 0;
iRandomMaxSkill = 10;
// Internet simulation
iMinPlayRounds = 5;
iMaxPlayRounds = 25;
// New round stuff
bNewRound = false;
// Broadcasting
iVersionBroadcasting = BROADCAST_ROUND;
iKillsBroadcasting = BROADCAST_KILLS_FULL;
iDeathsBroadcasting = BROADCAST_DEATHS_FULL;
bSpeechBroadcasting = false; // @ default we do NOT broadcast this shit every round to the listen server
// Installed into correct directory
bInstalledCorrectly = true;
// Round time
fRoundTime = gpGlobals->time;
// Dropped C4 location
vDroppedC4 = Vector(9999, 9999, 9999);
// May we walk with knife (when bots want to), default = yes (3600 seconds)
fWalkWithKnife = 3600;
// Chat related
iMaxSentences = 1; // max sentences produced by chatengine per second (1=default)
iProducedSentences = 0; // currently produced sentences
// DEBUG RELATED
bDoNotShoot = false; // ... guess
bDebug = -2; // ... prints debug messages (-2 is off, -1 == for everyone > -1 specific bot index)
messageVerbosity = 0; // normal verbosity
bEngineDebug = false; // ... prints engine debug messages (for figuring out engine interceptions)
bPistols = false; // pistols only mode
// Speech sentences (from POD and a *few* own made)
strcpy(cSpeechSentences[0], "hello user,communication is acquired");
strcpy(cSpeechSentences[1], "your presence is acknowledged");
strcpy(cSpeechSentences[2], "high man, your in command now");
strcpy(cSpeechSentences[3], "blast your hostile for good");
strcpy(cSpeechSentences[4], "high man, kill some idiot here");
strcpy(cSpeechSentences[5], "is there a doctor in the area");
strcpy(cSpeechSentences[6], "warning, experimental materials detected");
strcpy(cSpeechSentences[7], "high amigo, shoot some but");
strcpy(cSpeechSentences[8], "attention, hours of work software, detected");
strcpy(cSpeechSentences[9], "time for some bad ass explosion");
strcpy(cSpeechSentences[10], "bad ass son of a breach device activated");
strcpy(cSpeechSentences[11], "high, do not question this great service");
strcpy(cSpeechSentences[12], "engine is operative, hello and goodbye");
strcpy(cSpeechSentences[13], "high amigo, your administration has been great last day");
strcpy(cSpeechSentences[14], "attention, expect experimental armed hostile presence");
strcpy(cSpeechSentences[15], "warning,medical attention required");
InitNewRound();
} // Init()
void cGame::InitNewRound() {
// Map goal flags
bBombPlanted = false;
vPlantedC4 = Vector(9999, 9999, 9999);
bHostageRescueMap = false;
// update map goal flags timer
fUpdateGoalTimer = gpGlobals->time;
resetRoundTime();
DetermineMapGoal();
// initialize bots for new round
for (int i = 0; i < MAX_BOTS; i++) {
cBot &bot = bots[i];
if (bot.bIsUsed) {
bot.NewRound();
}
}
iProducedSentences = RANDOM_LONG(0, Game.iMaxSentences);
ChatEngine.fThinkTimer = gpGlobals->time + RANDOM_FLOAT(0.0, 0.5);
}
/**
* If the c4 is dropped (not planted), then return true.
* @return
*/
bool cGame::isC4Dropped() {
return vDroppedC4 != Vector(9999, 9999, 9999);
}
/**
* Is the C4 - when planted - discovered?
* @return
*/
bool cGame::isPlantedC4Discovered() {
return vPlantedC4 != Vector(9999, 9999, 9999);
}
// Returns random sentence for speech
char *cGame::RandomSentence() {
return cSpeechSentences[RANDOM_LONG(0, 15)];
}
void cGame::DetermineMapGoal() {
rblog("DetermineMapGoal called\n");
edict_t *pEnt = NULL;
int hostagesFound = 0;
while ((pEnt = UTIL_FindEntityByClassname(pEnt, "hostage_entity")) != NULL) {
hostagesFound++;
}
char msg[255];
memset(msg, 0, sizeof(msg));
sprintf(msg, "DetermineMapGoal: There are %d hostages found to rescue\n", hostagesFound);
rblog(msg);
Game.bHostageRescueMap = hostagesFound > 0;
int rescueZonesFound = 0;
// GOAL #3 - Hostage rescue zone
while ((pEnt = UTIL_FindEntityByClassname(pEnt, "func_hostage_rescue")) != NULL) {
rescueZonesFound++;
}
// rescue zone can also be an entity of info_hostage_rescue
while ((pEnt = UTIL_FindEntityByClassname(pEnt, "info_hostage_rescue")) != NULL) {
rescueZonesFound++;
}
memset(msg, 0, sizeof(msg));
sprintf(msg, "DetermineMapGoal: There are %d rescue zones found\n", rescueZonesFound);
rblog(msg);
Game.bHostageRescueZoneFound = rescueZonesFound > 0;
int bombSpots = 0;
// GOAL #4 - Bombspot zone
// Bomb spot
while ((pEnt = UTIL_FindEntityByClassname(pEnt, "func_bomb_target")) != NULL) {
bombSpots++;
}
while ((pEnt = UTIL_FindEntityByClassname(pEnt, "info_bomb_target")) != NULL) {
bombSpots++;
}
memset(msg, 0, sizeof(msg));
sprintf(msg, "DetermineMapGoal: There are %d bomb spots in this level\n", bombSpots);
Game.bBombPlantMap = bombSpots > 0;
rblog(msg);
}
void cGame::resetRoundTime() {
// start counting down, but include freezetime to match up with the count-down
SetRoundTime(gpGlobals->time + CVAR_GET_FLOAT("mp_freezetime"));
}
// GAME: Set round time
void cGame::SetRoundTime(float fTime) {
fRoundTime = fTime;
}
// GAME: Get round time
// NOTE: This is the time when a round has just started!
float cGame::getRoundStartedTime() {
return fRoundTime;
}
float cGame::getRoundTimeElapsed() {
if (getRoundStartedTime() > -1) {
return gpGlobals->time - getRoundStartedTime();
} else {
return -1;
}
}
// GAME: Set new round flag
void cGame::SetNewRound(bool bState) {
bNewRound = bState;
}
// GAME: Get new round status
bool cGame::NewRound() {
return bNewRound;
}
// GAME: Set min and max playing rounds
void cGame::SetPlayingRounds(int iMin, int iMax) {
if (iMin > -1)
iMinPlayRounds = iMin;
if (iMax > -1)
iMaxPlayRounds = iMax;
// Boundries
if (iMinPlayRounds < 1)
iMinPlayRounds = 1;
if (iMaxPlayRounds < 2)
iMaxPlayRounds = 2;
// Make sure MAX never is lower then MIN
if (iMinPlayRounds > iMaxPlayRounds)
iMinPlayRounds = iMaxPlayRounds - 1;
} // SetPlayingRounds()
// GAME: GET Max playing rounds
int cGame::GetMaxPlayRounds() {
return iMaxPlayRounds;
}
// GAME: GET Min playing rounds
int cGame::GetMinPlayRounds() {
return iMinPlayRounds;
}
// GAME: Load bot.cfg
void cGame::LoadCFG() {
// loads bot.cfg?
} // LoadCFG()
// GAME: Load names file
// NOTE: This function is just a copy/paste stuff from Botmans template, nothing more, nothing less
// TODO: Rewrite this, can be done much cleaner.
void cGame::LoadNames() {
FILE *bot_name_fp;
int str_index;
char name_buffer[80];
int length, index;
char filename[256];
UTIL_BuildFileNameRB("rb_names.txt", filename);
bot_name_fp = fopen(filename, "r");
if (bot_name_fp != NULL) {
while ((iAmountNames < MAX_BOT_NAMES) &&
(fgets(name_buffer, 80, bot_name_fp) != NULL)) {
length = strlen(name_buffer);
if (name_buffer[length - 1] == '\n') {
name_buffer[length - 1] = 0; // remove '\n'
length--;
}
str_index = 0;
while (str_index < length) {
if ((name_buffer[str_index] < ' ')
|| (name_buffer[str_index] > '~')
|| (name_buffer[str_index] == '"'))
for (index = str_index; index < length; index++)
name_buffer[index] = name_buffer[index + 1];
str_index++;
}
if (name_buffer[0] != 0) {
strncpy(cBotNames[iAmountNames], name_buffer, BOT_NAME_LEN);
iAmountNames++;
}
}
fclose(bot_name_fp);
}
} // LoadNames()
// Any names available?
bool cGame::NamesAvailable() {
if (iAmountNames > 0)
return true;
return false;
} // NamesAvailable()
// Picks a random name
// rewritten on april 10th 2004
void cGame::SelectName(char *name) {
int iNameIndex, iIndex;
bool bUsed;
edict_t *pPlayer;
iNameIndex = 0; // zero based (RANDOM_LONG (0, iAmountNames-1))
bool iNameUsed[MAX_BOT_NAMES];
for (int i = 0; i < MAX_BOT_NAMES; i++) {
iNameUsed[i] = false;
}
// check make sure this name isn't used
bUsed = true;
while (bUsed) {
iNameIndex = RANDOM_LONG(0, iAmountNames - 1); // pick random one
int iLimit = iNameIndex; // remember this.
// make sure it is not checked yet
while (iNameUsed[iNameIndex]) {
// check again
if (iNameUsed[iNameIndex] == false)
break;
// add up
iNameIndex++;
// make sure that it does not check out of range
if (iNameIndex == iAmountNames)
iNameIndex = 0; // go to 0 (will be set to 0 next 'name')
// when we are back to where we came from, get the fuck outta here
if (iNameIndex == iLimit) {
strcpy(name, "RealBot");
return;
}
}
// so far we did not find evidence that this name has been used already
bUsed = false;
// check if this name is used
for (iIndex = 1; iIndex <= gpGlobals->maxClients; iIndex++) {
pPlayer = INDEXENT(iIndex);
if (pPlayer && !pPlayer->free) {
if (strcmp(cBotNames[iNameIndex], STRING(pPlayer->v.netname))
== 0) {
// atten tion, this namehas been used.
bUsed = true;
break;
}
}
}
if (bUsed)
iNameUsed[iNameIndex] = true; // set on true
}
// copy name into the name_buffer
strcpy(name, cBotNames[iNameIndex]);
} // SelectName()
// GAME: Load BUYTABLE.INI file
void cGame::LoadBuyTable() {
INI_PARSE_BUYTABLE();
}
// GAME: Update global vars (called by StartFrame)
void cGame::UpdateGameStatus() {
// Used variables
edict_t *pEnt;
pEnt = NULL;
// ------------------
// Update: Dropped C4
// ------------------
// Its not dropped unless stated otherwise.
vDroppedC4 = Vector(9999, 9999, 9999);
// Find the dropped bomb
while ((pEnt = UTIL_FindEntityByClassname(pEnt, "weaponbox")) != NULL) {
// when DROPPED C4
if ((FStrEq(STRING(pEnt->v.model), "models/w_backpack.mdl"))) {
vDroppedC4 = pEnt->v.origin; // this is the origin.
break;
}
}
// ------------------
// Update: Is the bomb planted?
// ------------------
// Same as dropped c4, its NOT, unless stated otherwise.
pEnt = NULL;
bool bPlanted = bBombPlanted;
while ((pEnt = UTIL_FindEntityByClassname(pEnt, "grenade")) != NULL) {
if (UTIL_GetGrenadeType(pEnt) == 4) {
bPlanted = true; // Found planted bomb!
break;
}
}
// Discovered the bomb is planted and it was a different value than before (not planted).
// all counter-terrorists should know this, and they should head for the bomb
if (bPlanted && // found a planted bomb
bPlanted != bBombPlanted // and previously we didn't know that
) {
int i;
for (i = 1; i <= gpGlobals->maxClients; i++) {
edict_t *pPlayer = INDEXENT(i);
cBot *bot = UTIL_GetBotPointer(pPlayer);
// valid bot
if (bot) {
if (bot->isCounterTerrorist()) {
bot->forgetPath();
bot->rprint("Setting goal for bombspot");
tGoal *bombSpotGoal = NodeMachine.getRandomGoalByType(GOAL_BOMBSPOT);
if (bombSpotGoal) {
bot->setGoalNode(bombSpotGoal); // picks a random bomb spot
}
} // ct
} // bot
} // through all clients
// Now update bBombPlanted
bBombPlanted = bPlanted;
} // planted, and not planted before
// Every 3 seconds update the goals
if (gpGlobals->time > (fUpdateGoalTimer + 3)) {
// rblog("cGame::UpdateGameStatus - updateGoals\n");
NodeMachine.updateGoals();
fUpdateGoalTimer = gpGlobals->time;
}
} // UpdateGameStatus()
/**
* Add bot -> ARG1(team), ARG2(skill), ARG3(model), ARG4(name)
* pPlayer == player who wanted to create bot (if not null)
* @param pPlayer
* @param teamArg
* @param skillArg
* @param modelArg
* @param nameArg
* @return
*/
int cGame::createBot(edict_t *pPlayer, const char *teamArg, const char *skillArg, const char *modelArg, const char *nameArg) {
// NAME
char botName[BOT_NAME_LEN + 1];
memset(botName, 0, sizeof(botName));
// if name given, use that
if ((nameArg != NULL) && (*nameArg != 0)) {
strncpy(botName, nameArg, BOT_NAME_LEN - 1);
botName[BOT_NAME_LEN] = 0; // make sure botName is null terminated
} else { // else pick random one or fallback to default "RealBot"
if (NamesAvailable()) {
SelectName(botName);
} else {
strcpy(botName, "RealBot");
}
}
// length of name
int lengthOfBotName = strlen(botName);
// remove any illegal characters from name...
int i, j;
for (i = 0; i < lengthOfBotName; i++) {
if ((botName[i] <= ' ') || (botName[i] > '~') || (botName[i] == '"')) {
// move chars to the left (and null)
for (j = i; j < lengthOfBotName; j++) {
botName[j] = botName[j + 1];
}
lengthOfBotName--;
}
}
int botSkill = -2; // -2, not valid
// Skill argument provided
if ((skillArg != NULL) && (*skillArg != 0)) {
botSkill = atoi(skillArg); // set to given skill
}
// when not valid (-2), it has default skill
if ((botSkill < -1) || (botSkill > 10)) {
botSkill = iDefaultBotSkill;
}
// When skill is -1, random, we set it by boundries given
if (botSkill == -1) {
botSkill = RANDOM_LONG(iRandomMinSkill, iRandomMaxSkill);
}
// CREATE fake client!
edict_t *pBotEdict = (*g_engfuncs.pfnCreateFakeClient)(botName);
if (FNullEnt(pBotEdict)) {
REALBOT_PRINT(NULL, "cGame::CreateBot", "Cannot create bot, server is full");
return GAME_MSG_FAIL_SERVERFULL; // failed
}
char ptr[128]; // allocate space for message from ClientConnect
char *infobuffer;
int clientIndex;
// find empty bot index
int freeBotIndex;
freeBotIndex = 0;
while ((bots[freeBotIndex].bIsUsed) && (freeBotIndex < MAX_BOTS))
freeBotIndex++;
if (freeBotIndex == MAX_BOTS) { // failure
return GAME_MSG_FAILURE;
}
// create the player entity by calling MOD's player function
// (from LINK_ENTITY_TO_CLASS for player object)
// FIX: Free data for bot, so we can fill in new
if (pBotEdict->pvPrivateData != NULL)
FREE_PRIVATE(pBotEdict);
pBotEdict->pvPrivateData = NULL;
pBotEdict->v.frags = 0;
// END OF FIX: --- score resetted
CALL_GAME_ENTITY(PLID, "player", VARS(pBotEdict));
infobuffer = (*g_engfuncs.pfnGetInfoKeyBuffer)(pBotEdict);
clientIndex = ENTINDEX(pBotEdict);
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "model", "");
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "rate", "3500.000000");
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "cl_updaterate", "20");
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "tracker", "0");
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "cl_dlmax", "128");
if (RANDOM_LONG(0, 100) < 50) {
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "lefthand", "1");
} else {
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "lefthand", "0");
}
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "friends", "0");
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "dm", "0");
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "ah", "1");
(*g_engfuncs.pfnSetClientKeyValue)(clientIndex, infobuffer, "_vgui_menus", "0");
MDLL_ClientConnect(pBotEdict, botName, "127.0.0.1", ptr);
// Pieter van Dijk - use instead of DispatchSpawn() - Hip Hip Hurray!
MDLL_ClientPutInServer(pBotEdict);
pBotEdict->v.flags |= FL_THIRDPARTYBOT;
// initialize all the variables for this bot...
// Retrieve Pointer
cBot *pBot = &bots[freeBotIndex];
// TODO: Stefan 05/09/2019 - init function? (re-use, so much duplication here)
// Set variables
pBot->iBotIndex = freeBotIndex;
pBot->bIsUsed = true;
pBot->respawn_state = RESPAWN_IDLE;
pBot->fCreateTime = gpGlobals->time;
pBot->fKickTime = 0.0;
pBot->name[0] = 0; // name not set by server yet
pBot->bot_money = 0;
// clear
char c_skin[BOT_SKIN_LEN + 1];
memset(c_skin, 0, sizeof(c_skin));
strcpy(pBot->skin, c_skin);
pBot->pEdict = pBotEdict;
pBot->hasJoinedTeam = false; // hasn't joined game yet
// CS Message IDLE..
pBot->start_action = MSG_CS_IDLE;
pBot->SpawnInit();
pBot->bInitialize = false; // don't need to initialize yet
pBotEdict->v.idealpitch = pBotEdict->v.v_angle.x;
pBotEdict->v.ideal_yaw = pBotEdict->v.v_angle.y;
pBotEdict->v.pitch_speed = BOT_PITCH_SPEED;
pBotEdict->v.yaw_speed = BOT_YAW_SPEED;
pBot->bot_skill = botSkill;
// Personality related
pBot->ipHostage = 0;
pBot->ipBombspot = 0;
pBot->ipRandom = 0;
pBot->ipTurnSpeed = 20;
pBot->ipReplyToRadio = 0;
pBot->ipCreateRadio = 0;
pBot->ipHelpTeammate = 0;
pBot->ipWalkWithKnife = 0;
pBot->ipDroppedBomb = 0;
pBot->ipCampRate = 0;
pBot->ipChatRate = 0;
pBot->ipFearRate = 0;
pBot->ipHearRate = 0;
pBot->played_rounds = 0;
// Buy-personality related
pBot->ipFavoPriWeapon = -1;
pBot->ipFavoSecWeapon = -1;
pBot->ipBuyFlashBang = 0;
pBot->ipBuyGrenade = 0;
pBot->ipBuySmokeGren = 0;
pBot->ipBuyDefuseKit = 0;
pBot->ipSaveForWeapon = 0;
pBot->ipBuyArmour = 0;
// here we set team
if ((teamArg != NULL) && (teamArg[0] != 0)) {
pBot->iTeam = atoi(teamArg);
// and class
if ((modelArg != NULL) && (modelArg[0] != 0)) {
pBot->bot_class = atoi(modelArg);
}
}
// Parsing name into bot identity
INI_PARSE_BOTS(botName, pBot);
pBot->clearHostages();
pBot->clearHostageToRescueTarget();
// return success
return GAME_MSG_SUCCESS;
} // CreateBot()
// Debug message (without BOT)
void REALBOT_PRINT(const char *Function, const char *msg) {
REALBOT_PRINT(NULL, Function, msg);
}
// Debug message
void REALBOT_PRINT(cBot *pBot, const char *Function, const char *msg) {
char cMessage[512];
char team[9];
char name[MAX_NAME_LENGTH];
char mapName[32];
int botIndex = -1;
memset(team, 0, sizeof(team)); // clear
memset(name, 0, sizeof(name)); // clear
memset(mapName, 0, sizeof(mapName)); // clear
strcpy(team, "NONE");
strcpy(name, "FUNCTION");
if (gpGlobals->mapname) {
strcpy(mapName, STRING(gpGlobals->mapname));
} else {
strcpy(mapName, "NA");
}
if (pBot) {
botIndex = pBot->iBotIndex;
memset(name, 0, sizeof(name)); // clear
strcpy(name, pBot->name); // copy name
if (pBot->isCounterTerrorist()) {
strcpy(team, "COUNTER");
} else if (pBot->isTerrorist()) {
strcpy(team, "TERROR");
}
}
float roundElapsedTimeInSeconds = Game.getRoundTimeElapsed();
if (roundElapsedTimeInSeconds < 0) roundElapsedTimeInSeconds = 1; // sensible default to prevent division by 0
// Counter-Strike uses a timer that counts down, so we need to reverse it as well
float roundTimeInMinutes = CVAR_GET_FLOAT("mp_roundtime");
if (roundTimeInMinutes < 0) roundTimeInMinutes = 4; // sensible default
float roundTimeInSeconds = roundTimeInMinutes * 60;
float roundTimeRemaining = roundTimeInSeconds - roundElapsedTimeInSeconds;
int minutesLeft = roundTimeRemaining / 60;
int secondsLeft = (int)roundTimeRemaining % 60;
sprintf(cMessage, "[rb] [%s] [%0d:%02d] - [%s|%d] [%s] [%s] : %s\n", mapName, minutesLeft, secondsLeft, name, botIndex, team, Function, msg);
// print in console only when on debug print
if (Game.bDebug > -2) {
if (Game.bDebug == -1) {
rblog(cMessage);
} else if (Game.bDebug == botIndex && botIndex > -1) {
rblog(cMessage);
}
}
} // REALBOT_PRINT()
// $Log: game.cpp,v $
// Revision 1.18 2004/09/07 15:44:34 eric
// - bumped build nr to 3060
// - minor changes in add2 (to add nodes for Bsp2Rbn utilities)
// - if compiled with USE_EVY_ADD, then the add2() function is used when adding
// nodes based on human players instead of add()
// - else, it now compiles mostly without warnings :-)
//
// Revision 1.17 2004/07/30 15:02:30 eric
// - jumped to version 3057
// - improved readibility (wapen_tabel -> weapons_table) :-P
// - all Josh Borke modifications to the buying stuff:
// * using a switch() instead of several if
// * better buying code for shield and primary weapons
// * new command 'debug pistols 0/1'
//
// Revision 1.16 2004/07/02 16:43:35 stefan
// - upped to build 3051
// - changed log() into rblog()
// - removed BOT.CFG code that interpets old RB V1.0 commands
// - neater respons of the RealBot console
// - more help from RealBot console (ie, type realbot server broadcast ... with no arguments it will tell you what you can do with this, etc)
// - removed message "bot personality loaded from file"
// - in overal; some cleaning done, no extra features added
//
// Revision 1.15 2004/07/01 18:09:46 stefan
// - fixed skill 10 bots not causing memory bugger on re-adding (respawning)
// - added extra check for respawning bots so auto-add function cannot crash
// - fixed 2 nitpicks pointed out on the forums
//
// Revision 1.14 2004/06/23 08:24:14 stefan
// - upped to build 3049
// - added swat behaviour (team leader assignment, radio response change and leaders command team-mates) - THIS IS EXPERIMENTAL AND DOES NOT ALWAYS WORK AS I WANT IT TO.
// - changed some conditions in nodemachine
// - sorry evy, still not added your new goals ;) will do next time, i promise
//
// Revision 1.13 2004/06/18 12:20:07 stefan
// - fixed another bug in chatting, CS 1.5 won't crash now
// - added some limit to bots searching for goals
//
// Revision 1.12 2004/06/17 21:23:23 stefan
// - fixes several connection problems with nodes. Going down from steep + crates (de_dust) PLUS going up/down from very steep slopes on as_oilrig.. 0wnage and thx to PMB and Evy
// - fixed chat bug in CS 1.6, its still CS 1.5 & CS 1.6 compatible though
//
// Revision 1.11 2004/06/13 20:08:21 stefan
// - 'bad score for goals' added
// - bmp dump info (Thanks Evy)
// - added 'realbot server players', so you can keep a server full at NR players at all times
// - slightly adjusted goal selection code
// - wander code disabled
// - lots of debug info introduced, do not use this source for REAL USAGE!
//
// Revision 1.10 2004/05/29 19:05:47 stefan
// - upped to BUILD 3044
// - removed several debug messages on screen
// - changed default 'chatrate (max sentences)' to 3
// - removed copyright notice, which is not valid due GPL license
//
// i know, nothing special :)
//
// Revision 1.9 2004/04/26 16:36:48 stefan
// changed:
// #elseif into #else to keep MSVC satisfied
//
// added:
// comment lines in game.cpp so you know what vars are what.
//
// Revision 1.8 2004/04/18 19:33:57 stefan
// - Restructured code a bit
//
// Revision 1.7 2004/04/18 17:39:19 stefan
// - Upped to build 2043
// - REALBOT_PRINT() works properly now
// - Log() works properly now
// - Clearing in dll.cpp of reallog.txt at dll init
// - Logging works now, add REALBOT_PRINT() at every point you want to log something.
//