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
|
/*
===========================================================================
Return to Castle Wolfenstein multiplayer GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (RTCW MP Source Code).
RTCW MP Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RTCW MP Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RTCW MP Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the RTCW MP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW MP Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
// g_bot.c
#include "g_local.h"
#include "../botlib/botai.h"
static int g_numBots;
static char g_botInfos[MAX_BOTS][MAX_INFO_STRING];
int g_numArenas;
static char g_arenaInfos[MAX_ARENAS][MAX_INFO_STRING];
#define BOT_BEGIN_DELAY_BASE 2000
#define BOT_BEGIN_DELAY_INCREMENT 1500
#define BOT_SPAWN_QUEUE_DEPTH 16
typedef struct {
int clientNum;
int spawnTime;
} botSpawnQueue_t;
static int botBeginDelay;
static botSpawnQueue_t botSpawnQueue[BOT_SPAWN_QUEUE_DEPTH];
vmCvar_t bot_minplayers;
extern gentity_t *podium1;
extern gentity_t *podium2;
extern gentity_t *podium3;
// TTimo gcc: defined but not used
#if 0
/*
===============
G_LoadArenas
===============
*/
static void G_LoadArenas( void ) {
#ifdef QUAKESTUFF
int len;
char *filename;
vmCvar_t arenasFile;
fileHandle_t f;
int n;
char buf[MAX_ARENAS_TEXT];
trap_Cvar_Register( &arenasFile, "g_arenasFile", "", CVAR_INIT | CVAR_ROM );
if ( *arenasFile.string ) {
filename = arenasFile.string;
} else {
filename = "scripts/arenas.txt";
}
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( !f ) {
trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) );
return;
}
if ( len >= MAX_ARENAS_TEXT ) {
trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_ARENAS_TEXT ) );
trap_FS_FCloseFile( f );
return;
}
trap_FS_Read( buf, len, f );
buf[len] = 0;
trap_FS_FCloseFile( f );
g_numArenas = COM_ParseInfos( buf, MAX_ARENAS, g_arenaInfos );
trap_Print( va( "%i arenas parsed\n", g_numArenas ) );
for ( n = 0; n < g_numArenas; n++ ) {
Info_SetValueForKey( g_arenaInfos[n], "num", va( "%i", n ) );
}
#endif
}
#endif
/*
===============
G_GetArenaInfoByNumber
===============
*/
const char *G_GetArenaInfoByMap( const char *map ) {
int n;
for ( n = 0; n < g_numArenas; n++ ) {
if ( Q_stricmp( Info_ValueForKey( g_arenaInfos[n], "map" ), map ) == 0 ) {
return g_arenaInfos[n];
}
}
return NULL;
}
/*
=================
PlayerIntroSound
=================
*/
static void PlayerIntroSound( const char *modelAndSkin ) {
char model[MAX_QPATH];
char *skin;
Q_strncpyz( model, modelAndSkin, sizeof( model ) );
skin = strrchr( model, '/' );
if ( skin ) {
*skin++ = '\0';
} else {
skin = model;
}
if ( Q_stricmp( skin, "default" ) == 0 ) {
skin = model;
}
trap_SendConsoleCommand( EXEC_APPEND, va( "play sound/player/announce/%s.wav\n", skin ) );
}
/*
===============
G_CountBotPlayersByName
Check connected and connecting (delay join) bots.
Returns number of bots with name on specified team or whole server if team is -1.
===============
*/
int G_CountBotPlayersByName( const char *name, int team ) {
int i, num;
gclient_t *cl;
num = 0;
for ( i=0 ; i< g_maxclients.integer ; i++ ) {
cl = level.clients + i;
if ( cl->pers.connected == CON_DISCONNECTED ) {
continue;
}
if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
continue;
}
if ( team >= 0 && cl->sess.sessionTeam != team ) {
continue;
}
if ( name && Q_stricmp( name, cl->pers.netname ) ) {
continue;
}
num++;
}
return num;
}
/*
===============
G_SelectRandomBotInfo
Get random least used bot info on team or whole server if team is -1.
===============
*/
int G_SelectRandomBotInfo( int team ) {
int selection[MAX_BOTS];
int n, num;
int count, bestCount;
char *value;
// don't add duplicate bots to the server if there are less bots than bot types
if ( team != -1 && G_CountBotPlayersByName( NULL, -1 ) < g_numBots ) {
team = -1;
}
num = 0;
bestCount = MAX_CLIENTS;
for ( n = 0; n < g_numBots ; n++ ) {
value = Info_ValueForKey( g_botInfos[n], "funname" );
if ( !value[0] ) {
value = Info_ValueForKey( g_botInfos[n], "name" );
}
//
count = G_CountBotPlayersByName( value, team );
if ( count < bestCount ) {
bestCount = count;
num = 0;
}
if ( count == bestCount ) {
selection[num++] = n;
if ( num == MAX_BOTS ) {
break;
}
}
}
if ( num > 0 ) {
num = random() * ( num - 1 );
return selection[num];
}
return -1;
}
/*
===============
G_AddRandomBot
===============
*/
void G_AddRandomBot( int team ) {
char *teamstr;
int skill;
skill = trap_Cvar_VariableIntegerValue( "g_spSkill" );
if ( team == TEAM_RED ) {
teamstr = "red";
} else if ( team == TEAM_BLUE ) {
teamstr = "blue";
} else {
teamstr = "free";
}
trap_SendConsoleCommand( EXEC_INSERT, va( "addbot random %i %s %i\n", skill, teamstr, 0 ) );
}
/*
===============
G_RemoveRandomBot
===============
*/
int G_RemoveRandomBot( int team ) {
int i;
gclient_t *cl;
for ( i = 0 ; i < g_maxclients.integer ; i++ ) {
cl = level.clients + i;
if ( cl->pers.connected != CON_CONNECTED ) {
continue;
}
if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
continue;
}
if ( team >= 0 && cl->sess.sessionTeam != team ) {
continue;
}
trap_SendConsoleCommand( EXEC_INSERT, va("clientkick %d\n", i) );
return qtrue;
}
return qfalse;
}
/*
===============
G_CountHumanPlayers
===============
*/
int G_CountHumanPlayers( int team ) {
int i, num;
gclient_t *cl;
num = 0;
for ( i = 0 ; i < g_maxclients.integer ; i++ ) {
cl = level.clients + i;
if ( cl->pers.connected != CON_CONNECTED ) {
continue;
}
if ( g_entities[i].r.svFlags & SVF_BOT ) {
continue;
}
if ( team >= 0 && cl->sess.sessionTeam != team ) {
continue;
}
num++;
}
return num;
}
/*
===============
G_CountBotPlayers
Check connected and connecting (delay join) bots.
===============
*/
int G_CountBotPlayers( int team ) {
int i, num;
gclient_t *cl;
num = 0;
for ( i = 0 ; i < g_maxclients.integer ; i++ ) {
cl = level.clients + i;
if ( cl->pers.connected == CON_DISCONNECTED ) {
continue;
}
if ( !(g_entities[i].r.svFlags & SVF_BOT) ) {
continue;
}
if ( team >= 0 && cl->sess.sessionTeam != team ) {
continue;
}
num++;
}
return num;
}
/*
===============
G_CheckMinimumPlayers
===============
*/
void G_CheckMinimumPlayers( void ) {
int minplayers;
int humanplayers, botplayers;
static int checkminimumplayers_time;
//only check once each 10 seconds
if ( checkminimumplayers_time > level.time - 10000 ) {
return;
}
checkminimumplayers_time = level.time;
trap_Cvar_Update( &bot_minplayers );
minplayers = bot_minplayers.integer;
if ( minplayers <= 0 ) {
return;
}
if ( g_gametype.integer >= GT_TEAM ) {
if ( minplayers >= g_maxclients.integer / 2 ) {
minplayers = ( g_maxclients.integer / 2 ) - 1;
}
humanplayers = G_CountHumanPlayers( TEAM_RED );
botplayers = G_CountBotPlayers( TEAM_RED );
//
if ( humanplayers + botplayers < minplayers ) {
G_AddRandomBot( TEAM_RED );
} else if ( humanplayers + botplayers > minplayers && botplayers ) {
G_RemoveRandomBot( TEAM_RED );
}
//
humanplayers = G_CountHumanPlayers( TEAM_BLUE );
botplayers = G_CountBotPlayers( TEAM_BLUE );
//
if ( humanplayers + botplayers < minplayers ) {
G_AddRandomBot( TEAM_BLUE );
} else if ( humanplayers + botplayers > minplayers && botplayers ) {
G_RemoveRandomBot( TEAM_BLUE );
}
} else if ( g_gametype.integer == GT_TOURNAMENT ) {
if ( minplayers >= g_maxclients.integer ) {
minplayers = g_maxclients.integer - 1;
}
humanplayers = G_CountHumanPlayers( -1 );
botplayers = G_CountBotPlayers( -1 );
//
if ( humanplayers + botplayers < minplayers ) {
G_AddRandomBot( TEAM_FREE );
} else if ( humanplayers + botplayers > minplayers && botplayers ) {
// try to remove spectators first
if ( !G_RemoveRandomBot( TEAM_SPECTATOR ) ) {
// just remove the bot that is playing
G_RemoveRandomBot( -1 );
}
}
} else if ( g_gametype.integer == GT_FFA ) {
if ( minplayers >= g_maxclients.integer ) {
minplayers = g_maxclients.integer - 1;
}
humanplayers = G_CountHumanPlayers( TEAM_FREE );
botplayers = G_CountBotPlayers( TEAM_FREE );
//
if ( humanplayers + botplayers < minplayers ) {
G_AddRandomBot( TEAM_FREE );
} else if ( humanplayers + botplayers > minplayers && botplayers ) {
G_RemoveRandomBot( TEAM_FREE );
}
}
}
/*
===============
G_CheckBotSpawn
===============
*/
void G_CheckBotSpawn( void ) {
int n;
char userinfo[MAX_INFO_STRING];
G_CheckMinimumPlayers();
for ( n = 0; n < BOT_SPAWN_QUEUE_DEPTH; n++ ) {
if ( !botSpawnQueue[n].spawnTime ) {
continue;
}
if ( botSpawnQueue[n].spawnTime > level.time ) {
continue;
}
ClientBegin( botSpawnQueue[n].clientNum );
botSpawnQueue[n].spawnTime = 0;
if ( g_gametype.integer == GT_SINGLE_PLAYER ) {
trap_GetUserinfo( botSpawnQueue[n].clientNum, userinfo, sizeof( userinfo ) );
PlayerIntroSound( Info_ValueForKey( userinfo, "model" ) );
}
}
}
/*
===============
AddBotToSpawnQueue
===============
*/
static void AddBotToSpawnQueue( int clientNum, int delay ) {
int n;
for ( n = 0; n < BOT_SPAWN_QUEUE_DEPTH; n++ ) {
if ( !botSpawnQueue[n].spawnTime ) {
botSpawnQueue[n].spawnTime = level.time + delay;
botSpawnQueue[n].clientNum = clientNum;
return;
}
}
G_Printf( S_COLOR_YELLOW "Unable to delay spawn\n" );
ClientBegin( clientNum );
}
/*
===============
G_QueueBotBegin
===============
*/
void G_QueueBotBegin( int clientNum ) {
AddBotToSpawnQueue( clientNum, botBeginDelay );
botBeginDelay += BOT_BEGIN_DELAY_INCREMENT;
}
/*
===============
G_BotConnect
===============
*/
qboolean G_BotConnect( int clientNum, qboolean restart ) {
bot_settings_t settings;
char userinfo[MAX_INFO_STRING];
trap_GetUserinfo( clientNum, userinfo, sizeof( userinfo ) );
Q_strncpyz( settings.characterfile, Info_ValueForKey( userinfo, "characterfile" ), sizeof( settings.characterfile ) );
settings.skill = atoi( Info_ValueForKey( userinfo, "skill" ) );
if ( !BotAISetupClient( clientNum, &settings ) ) {
trap_DropClient( clientNum, "BotAISetupClient failed" );
return qfalse;
}
if ( restart && g_gametype.integer == GT_SINGLE_PLAYER ) {
g_entities[clientNum].botDelayBegin = qtrue;
} else {
g_entities[clientNum].botDelayBegin = qfalse;
}
return qtrue;
}
/*
===============
G_AddBot
===============
*/
static void G_AddBot( const char *name, int skill, const char *team, int delay ) {
int clientNum;
int teamNum;
int botinfoNum;
char *botinfo;
char *key;
char *s;
char *botname;
char *model;
char userinfo[MAX_INFO_STRING];
// have the server allocate a client slot
clientNum = trap_BotAllocateClient();
if ( clientNum == -1 ) {
G_Printf( S_COLOR_RED "Unable to add bot. All player slots are in use.\n" );
G_Printf( S_COLOR_RED "Start server with more 'open' slots (or check setting of sv_maxclients cvar).\n" );
return;
}
// set default team
if( !team || !*team ) {
if( g_gametype.integer >= GT_TEAM ) {
if( PickTeam(clientNum) == TEAM_RED) {
team = "red";
}
else {
team = "blue";
}
}
else {
team = "free";
}
}
// get the botinfo from bots.txt
if ( Q_stricmp( name, "random" ) == 0 ) {
if ( Q_stricmp( team, "red" ) == 0 || Q_stricmp( team, "r" ) == 0 ) {
teamNum = TEAM_RED;
}
else if ( Q_stricmp( team, "blue" ) == 0 || Q_stricmp( team, "b" ) == 0 ) {
teamNum = TEAM_BLUE;
}
else if ( !Q_stricmp( team, "spectator" ) || !Q_stricmp( team, "s" ) ) {
teamNum = TEAM_SPECTATOR;
}
else {
teamNum = TEAM_FREE;
}
botinfoNum = G_SelectRandomBotInfo( teamNum );
if ( botinfoNum < 0 ) {
G_Printf( S_COLOR_RED "Error: Cannot add random bot, no bot info available.\n" );
trap_BotFreeClient( clientNum );
return;
}
botinfo = G_GetBotInfoByNumber( botinfoNum );
}
else {
botinfo = G_GetBotInfoByName( name );
}
if ( !botinfo ) {
G_Printf( S_COLOR_RED "Error: Bot '%s' not defined\n", name );
trap_BotFreeClient( clientNum );
return;
}
// create the bot's userinfo
userinfo[0] = '\0';
botname = Info_ValueForKey( botinfo, "funname" );
if ( !botname[0] ) {
botname = Info_ValueForKey( botinfo, "name" );
}
Info_SetValueForKey( userinfo, "name", botname );
Info_SetValueForKey( userinfo, "rate", "25000" );
Info_SetValueForKey( userinfo, "snaps", "20" );
Info_SetValueForKey( userinfo, "skill", va( "%i", skill ) );
Info_SetValueForKey( userinfo, "teampref", team );
if ( skill == 1 ) {
Info_SetValueForKey( userinfo, "handicap", "50" );
} else if ( skill == 2 ) {
Info_SetValueForKey( userinfo, "handicap", "70" );
} else if ( skill == 3 ) {
Info_SetValueForKey( userinfo, "handicap", "90" );
}
key = "model";
model = Info_ValueForKey( botinfo, key );
if ( !*model ) {
model = "visor/default";
}
Info_SetValueForKey( userinfo, key, model );
key = "gender";
s = Info_ValueForKey( botinfo, key );
if ( !*s ) {
s = "male";
}
Info_SetValueForKey( userinfo, "sex", s );
key = "color";
s = Info_ValueForKey( botinfo, key );
if ( !*s ) {
s = "4";
}
Info_SetValueForKey( userinfo, key, s );
s = Info_ValueForKey( botinfo, "aifile" );
if ( !*s ) {
trap_Print( S_COLOR_RED "Error: bot has no aifile specified\n" );
trap_BotFreeClient( clientNum );
return;
}
Info_SetValueForKey( userinfo, "characterfile", s );
// register the userinfo
trap_SetUserinfo( clientNum, userinfo );
// have it connect to the game as a normal client
if ( ClientConnect( clientNum, qtrue, qtrue ) ) {
return;
}
if ( delay == 0 ) {
ClientBegin( clientNum );
return;
}
AddBotToSpawnQueue( clientNum, delay );
}
/*
===============
Svcmd_AddBot_f
===============
*/
void Svcmd_AddBot_f( void ) {
int skill;
int delay;
char name[MAX_TOKEN_CHARS];
char string[MAX_TOKEN_CHARS];
char team[MAX_TOKEN_CHARS];
// are bots enabled?
if ( !trap_Cvar_VariableIntegerValue( "bot_enable" ) ) {
return;
}
// name
trap_Argv( 1, name, sizeof( name ) );
if ( !name[0] ) {
trap_Print( "Usage: Addbot <botname> [skill 1-4] [team] [msec delay]\n" );
return;
}
// skill
trap_Argv( 2, string, sizeof( string ) );
if ( !string[0] ) {
skill = 4;
} else {
skill = Com_Clamp( 1, 5, atoi( string ) );
}
// team
trap_Argv( 3, team, sizeof( team ) );
// delay
trap_Argv( 4, string, sizeof( string ) );
if ( !string[0] ) {
delay = 0;
} else {
delay = atoi( string );
}
G_AddBot( name, skill, team, delay );
// if this was issued during gameplay and we are playing locally,
// go ahead and load the bot's media immediately
if ( level.time - level.startTime > 1000 &&
trap_Cvar_VariableIntegerValue( "cl_running" ) ) {
trap_SendServerCommand( -1, "loaddeferred\n" ); // spelling fixed (SA)
}
}
// TTimo gcc: defined but not used
#if 0
/*
===============
G_SpawnBots
===============
*/
static void G_SpawnBots( char *botList, int baseDelay ) {
char *bot;
char *p;
int skill;
int delay;
char bots[MAX_INFO_VALUE];
podium1 = NULL;
podium2 = NULL;
podium3 = NULL;
skill = trap_Cvar_VariableIntegerValue( "g_spSkill" );
if ( skill < 1 || skill > 5 ) {
trap_Cvar_Set( "g_spSkill", "2" );
skill = 2;
}
Q_strncpyz( bots, botList, sizeof( bots ) );
p = &bots[0];
delay = baseDelay;
while ( *p ) {
//skip spaces
while ( *p && *p == ' ' ) {
p++;
}
if ( !*p ) {
break;
}
// mark start of bot name
bot = p;
// skip until space of null
while ( *p && *p != ' ' ) {
p++;
}
if ( *p ) {
*p++ = 0;
}
// we must add the bot this way, calling G_AddBot directly at this stage
// does "Bad Things"
trap_SendConsoleCommand( EXEC_INSERT, va( "addbot %s %i free %i\n", bot, skill, delay ) );
delay += BOT_BEGIN_DELAY_INCREMENT;
}
}
#endif
// TTimo gcc: defined but not used
#if 0
/*
===============
G_LoadBots
===============
*/
static void G_LoadBots( void ) {
#ifdef QUAKESTUFF
int len;
char *filename;
vmCvar_t botsFile;
fileHandle_t f;
char buf[MAX_BOTS_TEXT];
if ( !trap_Cvar_VariableIntegerValue( "bot_enable" ) ) {
return;
}
trap_Cvar_Register( &botsFile, "g_botsFile", "", CVAR_INIT | CVAR_ROM );
if ( *botsFile.string ) {
filename = botsFile.string;
} else {
filename = "scripts/bots.txt";
}
len = trap_FS_FOpenFile( filename, &f, FS_READ );
if ( !f ) {
trap_Print( va( S_COLOR_RED "file not found: %s\n", filename ) );
return;
}
if ( len >= MAX_BOTS_TEXT ) {
trap_Print( va( S_COLOR_RED "file too large: %s is %i, max allowed is %i", filename, len, MAX_BOTS_TEXT ) );
trap_FS_FCloseFile( f );
return;
}
trap_FS_Read( buf, len, f );
buf[len] = 0;
trap_FS_FCloseFile( f );
g_numBots = COM_ParseInfos( buf, MAX_BOTS, g_botInfos );
trap_Print( va( "%i bots parsed\n", g_numBots ) );
#endif
}
#endif
/*
===============
G_GetBotInfoByNumber
===============
*/
char *G_GetBotInfoByNumber( int num ) {
if ( num < 0 || num >= g_numBots ) {
trap_Print( va( S_COLOR_RED "Invalid bot number: %i\n", num ) );
return NULL;
}
return g_botInfos[num];
}
/*
===============
G_GetBotInfoByName
===============
*/
char *G_GetBotInfoByName( const char *name ) {
int n;
char *value;
for ( n = 0; n < g_numBots ; n++ ) {
value = Info_ValueForKey( g_botInfos[n], "name" );
if ( !Q_stricmp( value, name ) ) {
return g_botInfos[n];
}
}
return NULL;
}
/*
===============
G_InitBots
===============
*/
void G_InitBots( qboolean restart ) {
// Ridah, we don't need this anymore
return;
// done.
/*
int fragLimit;
int timeLimit;
const char *arenainfo;
char *strValue;
int basedelay;
char map[MAX_QPATH];
char serverinfo[MAX_INFO_STRING];
G_LoadBots();
G_LoadArenas();
trap_Cvar_Register( &bot_minplayers, "bot_minplayers", "0", CVAR_SERVERINFO );
if( g_gametype.integer == GT_SINGLE_PLAYER ) {
trap_GetServerinfo( serverinfo, sizeof(serverinfo) );
Q_strncpyz( map, Info_ValueForKey( serverinfo, "mapname" ), sizeof(map) );
arenainfo = G_GetArenaInfoByMap( map );
if ( !arenainfo ) {
return;
}
strValue = Info_ValueForKey( arenainfo, "fraglimit" );
fragLimit = atoi( strValue );
if ( fragLimit ) {
trap_Cvar_Set( "fraglimit", strValue );
}
else {
trap_Cvar_Set( "fraglimit", "0" );
}
strValue = Info_ValueForKey( arenainfo, "timelimit" );
timeLimit = atoi( strValue );
if ( timeLimit ) {
trap_Cvar_Set( "timelimit", strValue );
}
else {
trap_Cvar_Set( "timelimit", "0" );
}
if ( !fragLimit && !timeLimit ) {
trap_Cvar_Set( "fraglimit", "10" );
trap_Cvar_Set( "timelimit", "0" );
}
basedelay = BOT_BEGIN_DELAY_BASE;
strValue = Info_ValueForKey( arenainfo, "special" );
if( Q_stricmp( strValue, "training" ) == 0 ) {
basedelay += 10000;
}
if( !restart ) {
G_SpawnBots( Info_ValueForKey( arenainfo, "bots" ), basedelay );
}
}
*/
}
|