/* =============== G_CheckBotSpawn =============== */ void G_CheckBotSpawn(void) { int n; char userinfo[MAX_INFO_VALUE]; 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")); } } }
/* =============== G_CheckBotSpawn =============== */ void G_CheckBotSpawn( void ) { int n; // MJN - added check here if ( g_mAllowBotLimit.integer ){ M_CheckMinimumBotPlayers(); } else{ 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, qfalse ); botSpawnQueue[n].spawnTime = 0; /* if( g_gametype.integer == GT_SINGLE_PLAYER ) { trap_GetUserinfo( botSpawnQueue[n].clientNum, userinfo, sizeof(userinfo) ); PlayerIntroSound( Info_ValueForKey (userinfo, "model") ); } */ } }
/** * @brief Swaps active players on teams */ void G_swapTeams(void) { int i; gclient_t *cl; for (i = TEAM_AXIS; i <= TEAM_ALLIES; i++) { G_teamReset(i, qtrue); } for (i = 0; i < level.numConnectedClients; i++) { cl = level.clients + level.sortedClients[i]; if (cl->sess.sessionTeam == TEAM_AXIS) { cl->sess.sessionTeam = TEAM_ALLIES; } else if (cl->sess.sessionTeam == TEAM_ALLIES) { cl->sess.sessionTeam = TEAM_AXIS; } else { continue; } G_UpdateCharacter(cl); ClientUserinfoChanged(level.sortedClients[i]); ClientBegin(level.sortedClients[i]); } AP("cp \"^1Teams have been swapped!\n\""); }
/** * @brief Shuffle active players onto teams */ void G_shuffleTeams(void) { int i; team_t cTeam; //, cMedian = level.numNonSpectatorClients / 2; int cnt = 0; int sortClients[MAX_CLIENTS]; gclient_t *cl; G_teamReset(TEAM_AXIS, qtrue); G_teamReset(TEAM_ALLIES, qtrue); for (i = 0; i < level.numConnectedClients; i++) { cl = level.clients + level.sortedClients[i]; if (cl->sess.sessionTeam != TEAM_AXIS && cl->sess.sessionTeam != TEAM_ALLIES) { continue; } sortClients[cnt++] = level.sortedClients[i]; } qsort(sortClients, cnt, sizeof(int), G_SortPlayersByXP); for (i = 0; i < cnt; i++) { cl = level.clients + sortClients[i]; // cTeam = (i % 2) + TEAM_AXIS; cTeam = (((i + 1) % 4) - ((i + 1) % 2)) / 2 + TEAM_AXIS; if (cl->sess.sessionTeam != cTeam) { G_LeaveTank(g_entities + sortClients[i], qfalse); G_RemoveClientFromFireteams(sortClients[i], qtrue, qfalse); if (g_landminetimeout.integer) { G_ExplodeMines(g_entities + sortClients[i]); } G_FadeItems(g_entities + sortClients[i], MOD_SATCHEL); } cl->sess.sessionTeam = cTeam; G_UpdateCharacter(cl); ClientUserinfoChanged(sortClients[i]); ClientBegin(sortClients[i]); } AP("cp \"^1Teams have been shuffled!\n\""); }
/* =============== 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 ); }
int baseq3_qagame_vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { #else int vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { #endif // IOS switch ( command ) { case GAME_INIT: G_InitGame( arg0, arg1, arg2 ); return 0; case GAME_SHUTDOWN: G_ShutdownGame( arg0 ); return 0; case GAME_CLIENT_CONNECT: return (int)ClientConnect( arg0, arg1, arg2 ); case GAME_CLIENT_THINK: ClientThink( arg0 ); return 0; case GAME_CLIENT_USERINFO_CHANGED: ClientUserinfoChanged( arg0 ); return 0; case GAME_CLIENT_DISCONNECT: ClientDisconnect( arg0 ); return 0; case GAME_CLIENT_BEGIN: ClientBegin( arg0 ); return 0; case GAME_CLIENT_COMMAND: ClientCommand( arg0 ); return 0; case GAME_RUN_FRAME: G_RunFrame( arg0 ); return 0; case GAME_CONSOLE_COMMAND: return ConsoleCommand(); case BOTAI_START_FRAME: return BotAIStartFrame( arg0 ); } return -1; } void QDECL G_Printf( const char *fmt, ... ) { va_list argptr; char text[1024]; va_start (argptr, fmt); vsprintf (text, fmt, argptr); va_end (argptr); trap_Printf( text ); }
//----(SA) modified this for head separation gentity_t *AICast_AddCastToGame( gentity_t *ent, char *castname, char *model, char *head, char *sex, char *color, char *handicap ) { int clientNum; gentity_t *bot; char userinfo[MAX_INFO_STRING]; usercmd_t cmd; // create the bot's userinfo userinfo[0] = '\0'; Info_SetValueForKey( userinfo, "name", castname ); Info_SetValueForKey( userinfo, "rate", "25000" ); Info_SetValueForKey( userinfo, "snaps", "20" ); Info_SetValueForKey( userinfo, "handicap", handicap ); Info_SetValueForKey( userinfo, "model", model ); Info_SetValueForKey( userinfo, "head", head ); Info_SetValueForKey( userinfo, "color", color ); // have the server allocate a client slot clientNum = trap_BotAllocateClient(); if ( clientNum == -1 ) { G_Printf( S_COLOR_RED "BotAllocateClient failed\n" ); return NULL; } bot = &g_entities[ clientNum ]; bot->r.svFlags |= SVF_BOT; bot->r.svFlags |= SVF_CASTAI; // flag it for special Cast AI behaviour // register the userinfo trap_SetUserinfo( bot->s.number, userinfo ); // have it connect to the game as a normal client //----(SA) ClientConnect requires a third 'isbot' parameter. setting to qfalse and noting ClientConnect( bot->s.number, qtrue, qfalse ); //----(SA) end // copy the origin/angles across VectorCopy( ent->s.origin, bot->s.origin ); VectorCopy( ent->s.angles, bot->s.angles ); memset( &cmd, 0, sizeof( cmd ) ); ClientBegin( bot->s.number ); // set up the ai AICast_SetupClient( bot->s.number ); return bot; }
/* =============== G_CheckBotSpawn =============== */ void G_CheckBotSpawn( void ) { int n; 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; } }
/* ================== SpectatorClientEndFrame ================== */ void SpectatorClientEndFrame( gentity_t *ent ) { gclient_t *cl; // if we are doing a chase cam or a remote view, grab the latest info if ( ent->client->sess.spectatorState == SPECTATOR_FOLLOW ) { int clientNum, flags; clientNum = ent->client->sess.spectatorClient; // team follow1 and team follow2 go to whatever clients are playing if ( clientNum == -1 ) { clientNum = level.follow1; } else if ( clientNum == -2 ) { clientNum = level.follow2; } if ( clientNum >= 0 ) { cl = &level.clients[ clientNum ]; if ( cl->pers.connected == CON_CONNECTED && cl->sess.sessionTeam != TEAM_SPECTATOR ) { flags = (cl->ps.eFlags & ~(EF_VOTED | EF_TEAMVOTED)) | (ent->client->ps.eFlags & (EF_VOTED | EF_TEAMVOTED)); ent->client->ps = cl->ps; ent->client->ps.pm_flags |= PMF_FOLLOW; ent->client->ps.eFlags = flags; return; } else { // drop them to free spectators unless they are dedicated camera followers if ( ent->client->sess.spectatorClient >= 0 ) { ent->client->sess.spectatorState = SPECTATOR_FREE; ClientBegin( ent->client - level.clients, qtrue ); } } } } if ( ent->client->sess.spectatorState == SPECTATOR_SCOREBOARD ) { ent->client->ps.pm_flags |= PMF_SCOREBOARD; } else { ent->client->ps.pm_flags &= ~PMF_SCOREBOARD; } }
/* =============== G_CheckBotSpawn =============== */ void G_CheckBotSpawn( void ) { int n; 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, qfalse ); botSpawnQueue[n].spawnTime = 0; /* if( level.gametype == GT_SINGLE_PLAYER ) { trap->GetUserinfo( botSpawnQueue[n].clientNum, userinfo, sizeof(userinfo) ); PlayerIntroSound( Info_ValueForKey (userinfo, "model") ); } */ } }
/* ================ vmMain This is the only way control passes into the module. This must be the very first function compiled into the .q3vm file ================ */ Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11 ) { switch ( command ) { case GAME_INIT: G_InitGame( arg0, arg1, arg2 ); return 0; case GAME_SHUTDOWN: G_ShutdownGame( arg0 ); return 0; case GAME_CLIENT_CONNECT: return (intptr_t)ClientConnect( arg0, arg1, arg2 ); case GAME_CLIENT_THINK: ClientThink( arg0 ); return 0; case GAME_CLIENT_USERINFO_CHANGED: ClientUserinfoChanged( arg0 ); return 0; case GAME_CLIENT_DISCONNECT: ClientDisconnect( arg0 ); return 0; case GAME_CLIENT_BEGIN: ClientBegin( arg0 ); return 0; case GAME_CLIENT_COMMAND: ClientCommand( arg0 ); return 0; case GAME_RUN_FRAME: G_RunFrame( arg0 ); return 0; case GAME_CONSOLE_COMMAND: return ConsoleCommand(); case BOTAI_START_FRAME: return BotAIStartFrame( arg0 ); } return -1; }
bool G_BotAdd( const char *name, team_t team, int skill, const char *behavior, bool filler ) { int clientNum; char userinfo[MAX_INFO_STRING]; const char* s = 0; gentity_t *bot; bool autoname = false; bool okay; if ( !navMeshLoaded ) { Log::Warn( "No Navigation Mesh file is available for this map" ); return false; } // find what clientNum to use for bot clientNum = trap_BotAllocateClient(); if ( clientNum < 0 ) { Log::Warn( "no more slots for bot" ); return false; } bot = &g_entities[ clientNum ]; bot->r.svFlags |= SVF_BOT; bot->inuse = true; if ( !Q_stricmp( name, BOT_NAME_FROM_LIST ) ) { name = G_BotSelectName( team ); autoname = name != nullptr; } //default bot data okay = G_BotSetDefaults( clientNum, team, skill, behavior ); // register user information userinfo[0] = '\0'; Info_SetValueForKey( userinfo, "name", name ? name : "", false ); // allow defaulting Info_SetValueForKey( userinfo, "rate", "25000", false ); Info_SetValueForKey( userinfo, "snaps", "20", false ); if ( autoname ) { Info_SetValueForKey( userinfo, "autoname", name, false ); } //so we can connect if server is password protected if ( g_needpass.integer == 1 ) { Info_SetValueForKey( userinfo, "password", g_password.string, false ); } trap_SetUserinfo( clientNum, userinfo ); // have it connect to the game as a normal client if ( ( s = ClientBotConnect( clientNum, true, team ) ) ) { // won't let us join Log::Warn( s ); okay = false; } if ( !okay ) { G_BotDel( clientNum ); return false; } if ( autoname ) { G_BotNameUsed( team, name, true ); } ClientBegin( clientNum ); bot->pain = BotPain; // ClientBegin resets the pain function level.clients[clientNum].pers.isFillerBot = filler; G_ChangeTeam( bot, team ); return true; }
/* ================== SpectatorClientEndFrame ================== */ void SpectatorClientEndFrame(gentity_t *ent) { // OSP - specs periodically get score updates for useful demo playback info // if we are doing a chase cam or a remote view, grab the latest info if ((ent->client->sess.spectatorState == SPECTATOR_FOLLOW) || (ent->client->ps.pm_flags & PMF_LIMBO)) { int clientNum; gclient_t *cl; if (ent->client->sess.sessionTeam == TEAM_AXIS || ent->client->sess.sessionTeam == TEAM_ALLIES) { reinforce(ent); return; } // Limbos aren't following while in MV if (ent->client->ps.pm_flags & PMF_LIMBO) { return; } clientNum = ent->client->sess.spectatorClient; // team follow1 and team follow2 go to whatever clients are playing if (clientNum == -1) { clientNum = level.follow1; } else if (clientNum == -2) { clientNum = level.follow2; } if (clientNum >= 0) { cl = &level.clients[clientNum]; if (cl->pers.connected == CON_CONNECTED && cl->sess.sessionTeam != TEAM_SPECTATOR) { int flags = (cl->ps.eFlags & ~(EF_VOTED)) | (ent->client->ps.eFlags & (EF_VOTED)); int ping = ent->client->ps.ping; if (ent->client->sess.sessionTeam != TEAM_SPECTATOR && (ent->client->ps.pm_flags & PMF_LIMBO)) { int savedScore = ent->client->ps.persistant[PERS_SCORE]; int savedClass = ent->client->ps.stats[STAT_PLAYER_CLASS]; ent->client->ps = cl->ps; ent->client->ps.pm_flags |= PMF_FOLLOW; ent->client->ps.pm_flags |= PMF_LIMBO; ent->client->ps.persistant[PERS_SCORE] = savedScore; // put score back ent->client->ps.stats[STAT_PLAYER_CLASS] = savedClass; // NERVE - SMF - put player class back } else { ent->client->ps = cl->ps; ent->client->ps.pm_flags |= PMF_FOLLOW; } // DHM - Nerve :: carry flags over ent->client->ps.eFlags = flags; ent->client->ps.ping = ping; return; } // drop them to free spectators unless they are dedicated camera followers if (ent->client->sess.spectatorClient >= 0) { ent->client->sess.spectatorState = SPECTATOR_FREE; ClientBegin(ent->client - level.clients); } } } }
/* =============== G_AddBot =============== */ static void G_AddBot( const char *name, float skill, const char *team, int delay ) { int clientNum; 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; } // get the botinfo from bots.txt 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("%.2f", skill) ); 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 ); if ( !team || !*team ) { if ( g_gametype.integer == GT_TEAM || g_gametype.integer == GT_CTF ) { if ( PickTeam( clientNum ) == TEAM_RED ) { team = "red"; } else { team = "blue"; } } else { team = "red"; } } Info_SetValueForKey( userinfo, "team", team ); // 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 ); }
/* =============== G_AddBot =============== */ static void G_AddBot(const char *name, float skill, const char *team, int delay, char *altname) { int clientNum; char *botinfo; gentity_t *bot; char *s; char *botname; char *model; char *headmodel; char userinfo[MAX_INFO_STRING]; weapon_t tpWeapon = WP_M4; holdable_t tpItem = HI_LASER; // get the botinfo from bots.txt botinfo = G_GetBotInfoByName(name); if (!botinfo) { G_Printf(S_COLOR_RED "Error: Bot '%s' not defined\n", name); return; } // create the bot's userinfo userinfo[0] = '\0'; botname = Info_ValueForKey(botinfo, "funname"); if (!botname[0]) { botname = Info_ValueForKey(botinfo, "name"); } // check for an alternative name if (altname && altname[0]) { botname = altname; } Info_SetValueForKey(userinfo, "name", botname); Info_SetValueForKey(userinfo, "rate", "25000"); Info_SetValueForKey(userinfo, "snaps", "20"); Info_SetValueForKey(userinfo, "skill", va("%1.2f", skill)); if (skill >= 1 && skill < 2) { Info_SetValueForKey(userinfo, "handicap", "50"); } else if (skill >= 2 && skill < 3) { Info_SetValueForKey(userinfo, "handicap", "70"); } else if (skill >= 3 && skill < 4) { Info_SetValueForKey(userinfo, "handicap", "90"); } model = Info_ValueForKey(botinfo, "model"); if (!*model) { // Elder: changed to our default model = "reactionmale/default"; } Info_SetValueForKey(userinfo, "model", model); Info_SetValueForKey(userinfo, "team_model", model); headmodel = Info_ValueForKey(botinfo, "headmodel"); if (!*headmodel) { headmodel = model; } Info_SetValueForKey(userinfo, "headmodel", headmodel); Info_SetValueForKey(userinfo, "team_headmodel", headmodel); s = Info_ValueForKey(botinfo, "gender"); if (!*s) { s = "male"; } Info_SetValueForKey(userinfo, "sex", s); s = Info_ValueForKey(botinfo, "color1"); if (!*s) { s = "4"; } Info_SetValueForKey(userinfo, "color1", s); s = Info_ValueForKey(botinfo, "color2"); if (!*s) { s = "5"; } Info_SetValueForKey(userinfo, "color2", s); s = Info_ValueForKey(botinfo, "aifile"); if (!*s) { trap_Printf(S_COLOR_RED "Error: bot has no aifile specified\n"); return; } // 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; } // initialize the bot settings if (!team || !*team) { if (g_gametype.integer >= GT_TEAM) { if (PickTeam(clientNum) == TEAM_RED) { team = "red"; } else { team = "blue"; } } else { team = "red"; } } Info_SetValueForKey(userinfo, "characterfile", Info_ValueForKey(botinfo, "aifile")); Info_SetValueForKey(userinfo, "skill", va("%5.2f", skill)); Info_SetValueForKey(userinfo, "team", team); if (g_gametype.integer == GT_TEAMPLAY) { //Makro - load custom weapon/item from bot file tpWeapon = CharToWeapon(Info_ValueForKey(botinfo, "weapon"), WP_M4); tpItem = CharToItem(Info_ValueForKey(botinfo, "item"), HI_LASER); } Info_SetValueForKey(userinfo, "tpw", va("%i", tpWeapon - WP_NONE)); Info_SetValueForKey(userinfo, "tpi", va("%i", tpItem - HI_NONE)); bot = &g_entities[clientNum]; bot->r.svFlags |= SVF_BOT; bot->inuse = qtrue; // 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); //Makro - load custom weapon/item from bot file if (g_gametype.integer == GT_TEAMPLAY) { bot->client->teamplayWeapon = tpWeapon; bot->client->teamplayItem = tpItem; } return; } AddBotToSpawnQueue(clientNum, delay); //Makro - load custom weapon/item from bot file if (g_gametype.integer == GT_TEAMPLAY) { bot->client->teamplayWeapon = tpWeapon; bot->client->teamplayItem = tpItem; } }
/* =============== G_AddBot =============== */ static void G_AddBot( const char *name, float skill, const char *team, int delay, char *altname) { int clientNum; char *botinfo; gentity_t *bot; char *key; char *s; char *botname; char *model; char *headmodel; char *logo; char userinfo[MAX_INFO_STRING]; // get the botinfo from bots.txt botinfo = G_GetBotInfoByName( name ); if ( !botinfo ) { G_Printf( S_COLOR_RED "Error: Bot '%s' not defined\n", name ); return; } // create the bot's userinfo userinfo[0] = '\0'; botname = Info_ValueForKey( botinfo, "funname" ); if( !botname[0] ) { botname = Info_ValueForKey( botinfo, "name" ); } // check for an alternative name if (altname && altname[0]) { botname = altname; } Info_SetValueForKey( userinfo, "name", botname ); Info_SetValueForKey( userinfo, "rate", "25000" ); Info_SetValueForKey( userinfo, "snaps", "20" ); Info_SetValueForKey( userinfo, "skill", va("%1.2f", skill) ); if ( skill >= 1 && skill < 2 ) { Info_SetValueForKey( userinfo, "handicap", "50" ); } else if ( skill >= 2 && skill < 3 ) { Info_SetValueForKey( userinfo, "handicap", "70" ); } else if ( skill >= 3 && skill < 4 ) { Info_SetValueForKey( userinfo, "handicap", "90" ); } key = "spraylogo"; logo = Info_ValueForKey( botinfo, key); if ( !*logo ) { logo = "15_padlogo"; } Info_SetValueForKey( userinfo, key, logo ); key = "model"; model = Info_ValueForKey( botinfo, key ); if ( !*model ) { model = "padman/default"; } else if ( g_gametype.integer < GT_TEAM ) { // If a team is given, but we're not in a team-gametype // this is caused by the ui, so we're forcing a skin. // This is rather nasty.. // TODO: Check whether the resulting model exists if ( *team ) { char *color = NULL; if ( !Q_stricmp( team, "red" ) || !Q_stricmp( team, "r" ) || !Q_stricmp( team, "0" ) ) { color = "red"; } else if ( !Q_stricmp( team, "blue" ) || !Q_stricmp( team, "b" ) || !Q_stricmp( team, "1" ) ) { color = "blue"; } // user decided to add a skin and specify a team // use skin color (way easier to implement) // FIXME: Explicitly search for color after ('/' or) '_' if ( strstr( model, "_red" ) || strstr( model, "_blue" ) ) { color = NULL; } if ( color ) { if ( strrchr( model, '/' ) ) { // model is a skin already, append colorname to skin // fatpad/fatty _red model = va( "%s_%s", model, color ); } else { // model is a "basemodel", append skin // fatpad /red model = va( "%s/%s", model, color ); } } } } Info_SetValueForKey( userinfo, key, model ); key = "team_model"; Info_SetValueForKey( userinfo, key, model ); key = "headmodel"; headmodel = Info_ValueForKey( botinfo, key ); if ( !*headmodel ) { headmodel = model; } Info_SetValueForKey( userinfo, key, headmodel ); key = "team_headmodel"; Info_SetValueForKey( userinfo, key, headmodel ); key = "gender"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "male"; } Info_SetValueForKey( userinfo, "sex", s ); key = "color1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "4"; } Info_SetValueForKey( userinfo, key, s ); key = "color2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "5"; } Info_SetValueForKey( userinfo, key, s ); s = Info_ValueForKey(botinfo, "aifile"); if (!*s ) { trap_Printf( S_COLOR_RED "Error: bot has no aifile specified\n" ); return; } // 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; } // initialize the bot settings if( !team || !*team ) { if( g_gametype.integer >= GT_TEAM ) { if( PickTeam(clientNum) == TEAM_RED) { team = "red"; } else { team = "blue"; } } else { team = "red"; } } Info_SetValueForKey( userinfo, "characterfile", Info_ValueForKey( botinfo, "aifile" ) ); Info_SetValueForKey( userinfo, "skill", va( "%5.2f", skill ) ); Info_SetValueForKey( userinfo, "team", team ); bot = &g_entities[ clientNum ]; bot->r.svFlags |= SVF_BOT; bot->inuse = qtrue; // 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 ); }
/* =============== G_AddBot =============== */ static void G_AddBot( const char *name, float skill, const char *team, int delay, char *altname) { int clientNum; char *botinfo; gentity_t *bot; char *key; char *s; char *botname; char *model; // char *headmodel; char userinfo[MAX_INFO_STRING]; int preTeam = 0; // get the botinfo from bots.txt botinfo = G_GetBotInfoByName( name ); if ( !botinfo ) { G_Printf( S_COLOR_RED "Error: Bot '%s' not defined\n", name ); return; } // create the bot's userinfo userinfo[0] = '\0'; botname = Info_ValueForKey( botinfo, "funname" ); if( !botname[0] ) { botname = Info_ValueForKey( botinfo, "name" ); } // check for an alternative name if (altname && altname[0]) { botname = altname; } Info_SetValueForKey( userinfo, "name", botname ); Info_SetValueForKey( userinfo, "rate", "25000" ); Info_SetValueForKey( userinfo, "snaps", "20" ); Info_SetValueForKey( userinfo, "skill", va("%1.2f", skill) ); if ( skill >= 1 && skill < 2 ) { Info_SetValueForKey( userinfo, "handicap", "50" ); } else if ( skill >= 2 && skill < 3 ) { Info_SetValueForKey( userinfo, "handicap", "70" ); } else if ( skill >= 3 && skill < 4 ) { Info_SetValueForKey( userinfo, "handicap", "90" ); } key = "model"; model = Info_ValueForKey( botinfo, key ); if ( !*model ) { model = "kyle/default"; } Info_SetValueForKey( userinfo, key, model ); /* key = "headmodel"; headmodel = Info_ValueForKey( botinfo, key ); if ( !*headmodel ) { headmodel = model; } Info_SetValueForKey( userinfo, key, headmodel ); key = "team_headmodel"; Info_SetValueForKey( userinfo, key, headmodel ); */ key = "gender"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "male"; } Info_SetValueForKey( userinfo, "sex", s ); key = "color1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "4"; } Info_SetValueForKey( userinfo, key, s ); key = "color2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "4"; } Info_SetValueForKey( userinfo, key, s ); key = "saber1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "single_1"; } Info_SetValueForKey( userinfo, key, s ); key = "saber2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "none"; } Info_SetValueForKey( userinfo, key, s ); s = Info_ValueForKey(botinfo, "personality"); if (!*s ) { Info_SetValueForKey( userinfo, "personality", "botfiles/default.jkb" ); } else { Info_SetValueForKey( userinfo, "personality", s ); } // 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.\n" ); trap_SendServerCommand( -1, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "UNABLE_TO_ADD_BOT"))); return; } // initialize the bot settings if( !team || !*team ) { if( g_gametype.integer >= GT_TEAM ) { if( PickTeam(clientNum) == TEAM_RED) { team = "red"; } else { team = "blue"; } } else { team = "red"; } } // Info_SetValueForKey( userinfo, "characterfile", Info_ValueForKey( botinfo, "aifile" ) ); Info_SetValueForKey( userinfo, "skill", va( "%5.2f", skill ) ); Info_SetValueForKey( userinfo, "team", team ); bot = &g_entities[ clientNum ]; bot->r.svFlags |= SVF_BOT; bot->inuse = qtrue; // register the userinfo trap_SetUserinfo( clientNum, userinfo ); if (g_gametype.integer >= GT_TEAM) { if (team && Q_stricmp(team, "red") == 0) { bot->client->sess.sessionTeam = TEAM_RED; } else if (team && Q_stricmp(team, "blue") == 0) { bot->client->sess.sessionTeam = TEAM_BLUE; } else { bot->client->sess.sessionTeam = PickTeam( -1 ); } } if (g_gametype.integer == GT_SIEGE) { bot->client->sess.siegeDesiredTeam = bot->client->sess.sessionTeam; bot->client->sess.sessionTeam = TEAM_SPECTATOR; } preTeam = bot->client->sess.sessionTeam; // have it connect to the game as a normal client if ( ClientConnect( clientNum, qtrue, qtrue ) ) { return; } if (bot->client->sess.sessionTeam != preTeam) { trap_GetUserinfo(clientNum, userinfo, MAX_INFO_STRING); if (bot->client->sess.sessionTeam == TEAM_SPECTATOR) { bot->client->sess.sessionTeam = preTeam; } if (bot->client->sess.sessionTeam == TEAM_RED) { team = "Red"; } else { if (g_gametype.integer == GT_SIEGE) { if (bot->client->sess.sessionTeam == TEAM_BLUE) { team = "Blue"; } else { team = "s"; } } else { team = "Blue"; } } Info_SetValueForKey( userinfo, "team", team ); trap_SetUserinfo( clientNum, userinfo ); bot->client->ps.persistant[ PERS_TEAM ] = bot->client->sess.sessionTeam; G_ReadSessionData( bot->client ); ClientUserinfoChanged( clientNum ); } if (g_gametype.integer == GT_DUEL || g_gametype.integer == GT_POWERDUEL) { int loners = 0; int doubles = 0; bot->client->sess.duelTeam = 0; G_PowerDuelCount(&loners, &doubles, qtrue); if (!doubles || loners > (doubles/2)) { bot->client->sess.duelTeam = DUELTEAM_DOUBLE; } else { bot->client->sess.duelTeam = DUELTEAM_LONE; } bot->client->sess.sessionTeam = TEAM_SPECTATOR; SetTeam(bot, "s"); } else { if( delay == 0 ) { ClientBegin( clientNum, qfalse ); return; } AddBotToSpawnQueue( clientNum, delay ); } }
/* ================== SpectatorClientEndFrame ================== */ void SpectatorClientEndFrame(gentity_t * ent) { gclient_t *cl; int savedPing, savedFlags, i; int savedPers[MAX_PERSISTANT]; // if we are doing a chase cam or a remote view, grab the latest info if (ent->client->sess.spectatorState == SPECTATOR_FOLLOW) { int clientNum, flags; clientNum = ent->client->sess.spectatorClient; // team follow1 and team follow2 go to whatever clients are playing if (clientNum == -1) { clientNum = level.follow1; } else if (clientNum == -2) { clientNum = level.follow2; } if (clientNum >= 0) { cl = &level.clients[clientNum]; if (cl->pers.connected == CON_CONNECTED && cl->sess.sessionTeam != TEAM_SPECTATOR) { flags = (cl->ps.eFlags & ~(EF_VOTED | EF_TEAMVOTED)) | (ent->client->ps. eFlags & (EF_VOTED | EF_TEAMVOTED)); // JBravo: saving score and ping to fix the scoreboard savedPing = ent->client->ps.ping; //Slicer saving pm_flags & pers savedFlags = ent->client->ps.pm_flags; for (i = 0; i < MAX_PERSISTANT; i++) savedPers[i] = ent->client->ps.persistant[i]; //This will make the spectator get the client's stuff ent->client->ps = cl->ps; //Reposting score and ping.. if (g_gametype.integer >= GT_TEAM) { for (i = 0; i < MAX_PERSISTANT; i++) ent->client->ps.persistant[i] = savedPers[i]; ent->client->ps.ping = savedPing; //Slicer reposting pmflags ent->client->ps.pm_flags = savedFlags; } ent->client->ps.pm_flags |= PMF_FOLLOW; ent->client->ps.eFlags = flags; return; } else { // drop them to free spectators unless they are dedicated camera followers if (ent->client->sess.spectatorClient >= 0) { ent->client->sess.spectatorState = SPECTATOR_FREE; // JBravo: saving spectatorState ent->client->specMode = SPECTATOR_FREE; ClientBegin(ent->client - level.clients); } } } } if (ent->client->sess.spectatorState == SPECTATOR_SCOREBOARD) { ent->client->ps.pm_flags |= PMF_SCOREBOARD; } else { ent->client->ps.pm_flags &= ~PMF_SCOREBOARD; } }
/* =============== G_AddBot =============== */ static void G_AddBot( const char *name, float skill, const char *team, int delay, char *altname) { gentity_t *bot = NULL; int clientNum, preTeam = TEAM_FREE; char userinfo[MAX_INFO_STRING] = {0}, *botinfo = NULL, *key = NULL, *s = NULL, *botname = NULL, *model = NULL; // have the server allocate a client slot clientNum = trap->BotAllocateClient(); if ( clientNum == -1 ) { // trap->Print( S_COLOR_RED "Unable to add bot. All player slots are in use.\n" ); // trap->Print( S_COLOR_RED "Start server with more 'open' slots.\n" ); trap->SendServerCommand( -1, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "UNABLE_TO_ADD_BOT"))); return; } // get the botinfo from bots.txt botinfo = G_GetBotInfoByName( name ); if ( !botinfo ) { trap->BotFreeClient( clientNum ); trap->Print( S_COLOR_RED "Error: Bot '%s' not defined\n", name ); return; } // create the bot's userinfo userinfo[0] = '\0'; botname = Info_ValueForKey( botinfo, "funname" ); if( !botname[0] ) botname = Info_ValueForKey( botinfo, "name" ); // check for an alternative name if ( altname && altname[0] ) botname = altname; Info_SetValueForKey( userinfo, "name", botname ); Info_SetValueForKey( userinfo, "rate", "25000" ); Info_SetValueForKey( userinfo, "snaps", "20" ); Info_SetValueForKey( userinfo, "ip", "localhost" ); Info_SetValueForKey( userinfo, "skill", va("%.2f", skill) ); if ( skill >= 1 && skill < 2 ) Info_SetValueForKey( userinfo, "handicap", "50" ); else if ( skill >= 2 && skill < 3 ) Info_SetValueForKey( userinfo, "handicap", "70" ); else if ( skill >= 3 && skill < 4 ) Info_SetValueForKey( userinfo, "handicap", "90" ); else Info_SetValueForKey( userinfo, "handicap", "100" ); key = "model"; model = Info_ValueForKey( botinfo, key ); if ( !*model ) model = DEFAULT_MODEL"/default"; Info_SetValueForKey( userinfo, key, model ); key = "sex"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = Info_ValueForKey( botinfo, "gender" ); if ( !*s ) s = "male"; Info_SetValueForKey( userinfo, key, s ); key = "color1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = "4"; Info_SetValueForKey( userinfo, key, s ); key = "color2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = "4"; Info_SetValueForKey( userinfo, key, s ); key = "saber1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = DEFAULT_SABER; Info_SetValueForKey( userinfo, key, s ); key = "saber2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = "none"; Info_SetValueForKey( userinfo, key, s ); key = "forcepowers"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = DEFAULT_FORCEPOWERS; Info_SetValueForKey( userinfo, key, s ); key = "cg_predictItems"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = "1"; Info_SetValueForKey( userinfo, key, s ); key = "char_color_red"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = "255"; Info_SetValueForKey( userinfo, key, s ); key = "char_color_green"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = "255"; Info_SetValueForKey( userinfo, key, s ); key = "char_color_blue"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = "255"; Info_SetValueForKey( userinfo, key, s ); key = "teamtask"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = "0"; Info_SetValueForKey( userinfo, key, s ); key = "personality"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) s = "botfiles/default.jkb"; Info_SetValueForKey( userinfo, key, s ); // initialize the bot settings if ( !team || !*team ) { if ( level.gametype >= GT_TEAM ) { if ( PickTeam( clientNum ) == TEAM_RED) team = "red"; else team = "blue"; } else team = "red"; } Info_SetValueForKey( userinfo, "team", team ); bot = &g_entities[ clientNum ]; // bot->r.svFlags |= SVF_BOT; // bot->inuse = qtrue; // register the userinfo trap->SetUserinfo( clientNum, userinfo ); if ( level.gametype >= GT_TEAM ) { if ( team && !Q_stricmp( team, "red" ) ) bot->client->sess.sessionTeam = TEAM_RED; else if ( team && !Q_stricmp( team, "blue" ) ) bot->client->sess.sessionTeam = TEAM_BLUE; else bot->client->sess.sessionTeam = PickTeam( -1 ); } if ( level.gametype == GT_SIEGE ) { bot->client->sess.siegeDesiredTeam = bot->client->sess.sessionTeam; bot->client->sess.sessionTeam = TEAM_SPECTATOR; } preTeam = bot->client->sess.sessionTeam; // have it connect to the game as a normal client if ( ClientConnect( clientNum, qtrue, qtrue ) ) return; if ( bot->client->sess.sessionTeam != preTeam ) { trap->GetUserinfo( clientNum, userinfo, sizeof( userinfo ) ); if ( bot->client->sess.sessionTeam == TEAM_SPECTATOR ) bot->client->sess.sessionTeam = preTeam; if ( bot->client->sess.sessionTeam == TEAM_RED ) team = "Red"; else { if ( level.gametype == GT_SIEGE ) team = (bot->client->sess.sessionTeam == TEAM_BLUE) ? "Blue" : "s"; else team = "Blue"; } Info_SetValueForKey( userinfo, "team", team ); trap->SetUserinfo( clientNum, userinfo ); bot->client->ps.persistant[ PERS_TEAM ] = bot->client->sess.sessionTeam; G_ReadSessionData( bot->client ); if ( !ClientUserinfoChanged( clientNum ) ) return; } if (level.gametype == GT_DUEL || level.gametype == GT_POWERDUEL) { int loners = 0; int doubles = 0; bot->client->sess.duelTeam = 0; G_PowerDuelCount(&loners, &doubles, qtrue); if (!doubles || loners > (doubles/2)) { bot->client->sess.duelTeam = DUELTEAM_DOUBLE; } else { bot->client->sess.duelTeam = DUELTEAM_LONE; } bot->client->sess.sessionTeam = TEAM_SPECTATOR; SetTeam(bot, "s"); } else { if( delay == 0 ) { ClientBegin( clientNum, qfalse ); return; } AddBotToSpawnQueue( clientNum, delay ); } }
/* ================== SpectatorClientEndFrame ================== */ void SpectatorClientEndFrame( gentity_t *ent ) { gclient_t *cl; int do_respawn = 0; // JPW NERVE int savedScore; // DHM - Nerve int savedRespawns; // DHM - Nerve int savedClass; // NERVE - SMF int flags; int testtime; // if we are doing a chase cam or a remote view, grab the latest info if ( ( ent->client->sess.spectatorState == SPECTATOR_FOLLOW ) || ( ent->client->ps.pm_flags & PMF_LIMBO ) ) { // JPW NERVE for limbo int clientNum; if ( ent->client->sess.sessionTeam == TEAM_RED ) { testtime = level.time % g_redlimbotime.integer; if ( testtime < ent->client->pers.lastReinforceTime ) { do_respawn = 1; } ent->client->pers.lastReinforceTime = testtime; } else if ( ent->client->sess.sessionTeam == TEAM_BLUE ) { testtime = level.time % g_bluelimbotime.integer; if ( testtime < ent->client->pers.lastReinforceTime ) { do_respawn = 1; } ent->client->pers.lastReinforceTime = testtime; } if ( ( g_maxlives.integer > 0 || g_alliedmaxlives.integer > 0 || g_axismaxlives.integer > 0 ) && ent->client->ps.persistant[PERS_RESPAWNS_LEFT] == 0 ) { do_respawn = 0; } if ( do_respawn ) { reinforce( ent ); return; } clientNum = ent->client->sess.spectatorClient; // team follow1 and team follow2 go to whatever clients are playing if ( clientNum == -1 ) { clientNum = level.follow1; } else if ( clientNum == -2 ) { clientNum = level.follow2; } if ( clientNum >= 0 ) { cl = &level.clients[ clientNum ]; if ( cl->pers.connected == CON_CONNECTED && cl->sess.sessionTeam != TEAM_SPECTATOR ) { // DHM - Nerve :: carry flags over flags = ( cl->ps.eFlags & ~( EF_VOTED ) ) | ( ent->client->ps.eFlags & ( EF_VOTED ) ); // JPW NERVE -- limbo latch if ( ent->client->sess.sessionTeam != TEAM_SPECTATOR && ent->client->ps.pm_flags & PMF_LIMBO ) { // abuse do_respawn var savedScore = ent->client->ps.persistant[PERS_SCORE]; do_respawn = ent->client->ps.pm_time; savedRespawns = ent->client->ps.persistant[PERS_RESPAWNS_LEFT]; savedClass = ent->client->ps.stats[STAT_PLAYER_CLASS]; ent->client->ps = cl->ps; ent->client->ps.pm_flags |= PMF_FOLLOW; ent->client->ps.pm_flags |= PMF_LIMBO; ent->client->ps.persistant[PERS_RESPAWNS_LEFT] = savedRespawns; ent->client->ps.pm_time = do_respawn; // put pm_time back ent->client->ps.persistant[PERS_SCORE] = savedScore; // put score back ent->client->ps.stats[STAT_PLAYER_CLASS] = savedClass; // NERVE - SMF - put player class back } else { ent->client->ps = cl->ps; ent->client->ps.pm_flags |= PMF_FOLLOW; } // jpw // DHM - Nerve :: carry flags over ent->client->ps.eFlags = flags; return; } else { // drop them to free spectators unless they are dedicated camera followers if ( ent->client->sess.spectatorClient >= 0 ) { ent->client->sess.spectatorState = SPECTATOR_FREE; ClientBegin( ent->client - level.clients ); } } } } if ( ent->client->sess.spectatorState == SPECTATOR_SCOREBOARD ) { ent->client->ps.pm_flags |= PMF_SCOREBOARD; } else { ent->client->ps.pm_flags &= ~PMF_SCOREBOARD; } }
/* =============== G_AddBot =============== */ static void G_AddBot( const char *name, float skill, const char *team, int delay, char *altname) { int value; int connectionNum; int clientNum; int t; char *botinfo; char *key; char *s; char *botname; char *model; char *headmodel; char userinfo[MAX_INFO_STRING]; qboolean modelSet; // have the server allocate a client slot value = trap_BotAllocateClient(); if ( value == -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; } // get connection and client numbers connectionNum = value & 0xFFFF; clientNum = value >> 16; // 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, "blue") == 0) t = TEAM_BLUE; else if (Q_stricmp(team, "red") == 0) t = TEAM_RED; else t = TEAM_FREE; // get info of a randomly selected bot botinfo = G_GetBotInfoByNumber( G_SelectRandomBotForAdd( t ) ); } else { // get info of the bot 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" ); } // check for an alternative name if (altname && altname[0]) { botname = altname; } Info_SetValueForKey( userinfo, "name", botname ); Info_SetValueForKey( userinfo, "rate", "25000" ); Info_SetValueForKey( userinfo, "snaps", "20" ); Info_SetValueForKey( userinfo, "skill", va("%.2f", skill) ); Info_SetValueForKey( userinfo, "teampref", team ); if ( skill >= 1 && skill < 2 ) { Info_SetValueForKey( userinfo, "handicap", "50" ); } else if ( skill >= 2 && skill < 3 ) { Info_SetValueForKey( userinfo, "handicap", "70" ); } else if ( skill >= 3 && skill < 4 ) { Info_SetValueForKey( userinfo, "handicap", "90" ); } key = "model"; model = Info_ValueForKey( botinfo, key ); modelSet = ( *model ); if ( !modelSet ) { model = DEFAULT_MODEL; } Info_SetValueForKey( userinfo, key, model ); key = "team_model"; Info_SetValueForKey( userinfo, key, model ); key = "headmodel"; headmodel = Info_ValueForKey( botinfo, key ); if ( !*headmodel ) { if (!modelSet) { headmodel = DEFAULT_HEAD; } else { headmodel = model; } } Info_SetValueForKey( userinfo, key, headmodel ); key = "team_headmodel"; Info_SetValueForKey( userinfo, key, headmodel ); key = "color1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = va("%d", DEFAULT_CLIENT_COLOR1); } Info_SetValueForKey( userinfo, key, s ); key = "color2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = va("%d", DEFAULT_CLIENT_COLOR2); } 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, connectionNum, 0 ) ) { return; } if( delay == 0 ) { ClientBegin( clientNum ); return; } AddBotToSpawnQueue( clientNum, delay ); }
void SetTeam( gentity_t *ent, char *s ) { int clientNum, specClient=0; team_t team, oldTeam; gclient_t *client = ent->client; spectatorState_t specState = SPECTATOR_NOT; // see what change is requested clientNum = ARRAY_INDEX( level.clients, client ); if ( !Q_stricmp( s, "scoreboard" ) || !Q_stricmp( s, "score" ) ) { team = TEAM_SPECTATOR; specState = SPECTATOR_SCOREBOARD; } else if ( !Q_stricmp( s, "follow1" ) ) { team = TEAM_SPECTATOR; specState = SPECTATOR_FOLLOW; specClient = -1; } else if ( !Q_stricmp( s, "follow2" ) ) { team = TEAM_SPECTATOR; specState = SPECTATOR_FOLLOW; specClient = -2; } else if ( !Q_stricmp( s, "spectator" ) || !Q_stricmp( s, "s" ) ) { team = TEAM_SPECTATOR; specState = SPECTATOR_FREE; } // if running a team game, assign player to one of the teams else if ( level.gametype >= GT_TEAMBLOOD ) { specState = SPECTATOR_NOT; if ( !Q_stricmp( s, "red" ) || !Q_stricmp( s, "r" ) ) team = TEAM_RED; else if ( !Q_stricmp( s, "blue" ) || !Q_stricmp( s, "b" ) ) team = TEAM_BLUE; else team = PickTeam( clientNum ); // pick the team with the least number of players if ( g_teamForceBalance->integer ) { int counts[TEAM_NUM_TEAMS]; counts[TEAM_BLUE] = TeamCount( clientNum, TEAM_BLUE ); counts[TEAM_RED] = TeamCount( clientNum, TEAM_RED ); // We allow a spread of two if ( team == TEAM_RED && counts[TEAM_RED] - counts[TEAM_BLUE] > 1 ) { trap->SV_GameSendServerCommand( clientNum, "cp \"Red team has too many players.\n\"" ); return; // ignore the request } if ( team == TEAM_BLUE && counts[TEAM_BLUE] - counts[TEAM_RED] > 1 ) { trap->SV_GameSendServerCommand( clientNum, "cp \"Blue team has too many players.\n\"" ); return; // ignore the request } // It's ok, the team we are switching to has less or same number of players } } else team = TEAM_FREE; // force them to spectators if there aren't any spots free // override decision if limiting the players if ( (level.gametype == GT_DUEL) && level.numNonSpectatorClients >= 2 ) team = TEAM_SPECTATOR; else if ( g_maxGameClients->integer > 0 && level.numNonSpectatorClients >= g_maxGameClients->integer ) team = TEAM_SPECTATOR; // decide if we will allow the change oldTeam = client->sess.sessionTeam; if ( team == oldTeam && team != TEAM_SPECTATOR ) return; // if the player was dead leave the body if ( client->ps.stats[STAT_HEALTH] <= 0 ) { CopyToBodyQue( ent ); } // he starts at 'base' client->pers.teamState.state = TEAM_BEGIN; if ( oldTeam != TEAM_SPECTATOR ) { // Kill him (makes sure he loses flags, etc) ent->flags &= ~FL_GODMODE; ent->client->ps.stats[STAT_HEALTH] = ent->health = 0; player_die( ent, ent, ent, 100000, MOD_SUICIDE ); } // they go to the end of the line for tournaments if ( team == TEAM_SPECTATOR && oldTeam != team ) AddTournamentQueue( client ); // exploit fix: with 3 (any odd amount?) players connected, one could /callvote map x followed by /team s to force the vote G_ClearVote( ent ); client->sess.sessionTeam = team; client->sess.spectatorState = specState; client->sess.spectatorClient = specClient; BroadcastTeamChange( client, oldTeam ); ClientUserinfoChanged( clientNum ); ClientBegin( clientNum ); }
/* =========== ClientBegin called when a client has finished connecting, and is ready to be placed into the level. This will happen every level load, and on transition between teams, but doesn't happen on respawns ============ */ void ClientBegin( int clientNum, qboolean allowTeamReset ) { gentity_t *ent; gclient_t *client; gentity_t *tent; int flags, i; char userinfo[MAX_INFO_VALUE], *modelname; ent = g_entities + clientNum; if ((ent->r.svFlags & SVF_BOT) && g_gametype.integer >= GT_TEAM) { if (allowTeamReset) { const char *team = "Red"; int preSess; //SetTeam(ent, ""); ent->client->sess.sessionTeam = PickTeam(-1); trap_GetUserinfo(clientNum, userinfo, MAX_INFO_STRING); if (ent->client->sess.sessionTeam == TEAM_SPECTATOR) { ent->client->sess.sessionTeam = TEAM_RED; } if (ent->client->sess.sessionTeam == TEAM_RED) { team = "Red"; } else { team = "Blue"; } Info_SetValueForKey( userinfo, "team", team ); trap_SetUserinfo( clientNum, userinfo ); ent->client->ps.persistant[ PERS_TEAM ] = ent->client->sess.sessionTeam; preSess = ent->client->sess.sessionTeam; G_ReadSessionData( ent->client ); ent->client->sess.sessionTeam = preSess; G_WriteClientSessionData(ent->client); ClientUserinfoChanged( clientNum ); ClientBegin(clientNum, qfalse); return; } } client = level.clients + clientNum; if ( ent->r.linked ) { trap_UnlinkEntity( ent ); } G_InitGentity( ent ); ent->touch = 0; ent->pain = 0; ent->client = client; client->pers.connected = CON_CONNECTED; client->pers.enterTime = level.time; client->pers.teamState.state = TEAM_BEGIN; // save eflags around this, because changing teams will // cause this to happen with a valid entity, and we // want to make sure the teleport bit is set right // so the viewpoint doesn't interpolate through the // world to the new position flags = client->ps.eFlags; i = 0; while (i < NUM_FORCE_POWERS) { if (ent->client->ps.fd.forcePowersActive & (1 << i)) { WP_ForcePowerStop(ent, i); } i++; } i = TRACK_CHANNEL_1; while (i < NUM_TRACK_CHANNELS) { if (ent->client->ps.fd.killSoundEntIndex[i-50] && ent->client->ps.fd.killSoundEntIndex[i-50] < MAX_GENTITIES && ent->client->ps.fd.killSoundEntIndex[i-50] > 0) { G_MuteSound(ent->client->ps.fd.killSoundEntIndex[i-50], CHAN_VOICE); } i++; } i = 0; memset( &client->ps, 0, sizeof( client->ps ) ); client->ps.eFlags = flags; client->ps.hasDetPackPlanted = qfalse; //first-time force power initialization WP_InitForcePowers( ent ); //init saber ent WP_SaberInitBladeData( ent ); // First time model setup for that player. trap_GetUserinfo( clientNum, userinfo, sizeof(userinfo) ); modelname = Info_ValueForKey (userinfo, "model"); SetupGameGhoul2Model(client, modelname); if (ent->client->ghoul2) { ent->bolt_Head = trap_G2API_AddBolt(ent->client->ghoul2, 0, "cranium"); ent->bolt_Waist = trap_G2API_AddBolt(ent->client->ghoul2, 0, "thoracic"); ent->bolt_LArm = trap_G2API_AddBolt(ent->client->ghoul2, 0, "lradius"); ent->bolt_RArm = trap_G2API_AddBolt(ent->client->ghoul2, 0, "rradius"); ent->bolt_LLeg = trap_G2API_AddBolt(ent->client->ghoul2, 0, "ltibia"); ent->bolt_RLeg = trap_G2API_AddBolt(ent->client->ghoul2, 0, "rtibia"); ent->bolt_Motion = trap_G2API_AddBolt(ent->client->ghoul2, 0, "Motion"); } // locate ent at a spawn point ClientSpawn( ent ); if ( client->sess.sessionTeam != TEAM_SPECTATOR ) { // send event tent = G_TempEntity( ent->client->ps.origin, EV_PLAYER_TELEPORT_IN ); tent->s.clientNum = ent->s.clientNum; if ( g_gametype.integer != GT_TOURNAMENT ) { trap_SendServerCommand( -1, va("print \"%s" S_COLOR_WHITE " %s\n\"", client->pers.netname, G_GetStripEdString("SVINGAME", "PLENTER")) ); } } G_LogPrintf( "ClientBegin: %i\n", clientNum ); // count current clients and rank for scoreboard CalculateRanks(); G_ClearClientLog(clientNum); }
/* ================= SetTeam ================= */ void SetTeam( gentity_t *ent, char *s ) { int team, oldTeam; gclient_t *client; int clientNum; spectatorState_t specState; int specClient; int teamLeader; // // see what change is requested // client = ent->client; clientNum = client - level.clients; specClient = 0; specState = SPECTATOR_NOT; if ( !Q_stricmp( s, "scoreboard" ) || !Q_stricmp( s, "score" ) ) { team = TEAM_SPECTATOR; specState = SPECTATOR_SCOREBOARD; } else if ( !Q_stricmp( s, "follow1" ) ) { team = TEAM_SPECTATOR; specState = SPECTATOR_FOLLOW; specClient = -1; } else if ( !Q_stricmp( s, "follow2" ) ) { team = TEAM_SPECTATOR; specState = SPECTATOR_FOLLOW; specClient = -2; } else if ( !Q_stricmp( s, "spectator" ) || !Q_stricmp( s, "s" ) ) { team = TEAM_SPECTATOR; specState = SPECTATOR_FREE; } else if ( g_gametype.integer >= GT_TEAM ) { // if running a team game, assign player to one of the teams specState = SPECTATOR_NOT; if ( !Q_stricmp( s, "red" ) || !Q_stricmp( s, "r" ) ) { team = TEAM_RED; } else if ( !Q_stricmp( s, "blue" ) || !Q_stricmp( s, "b" ) ) { team = TEAM_BLUE; } else { // pick the team with the least number of players team = PickTeam( clientNum ); } if ( g_teamForceBalance.integer ) { int counts[TEAM_NUM_TEAMS]; counts[TEAM_BLUE] = TeamCount( clientNum, TEAM_BLUE ); counts[TEAM_RED] = TeamCount( clientNum, TEAM_RED ); // We allow a spread of two if ( team == TEAM_RED && counts[TEAM_RED] - counts[TEAM_BLUE] > 1 ) { trap_SendServerCommand( clientNum, "cp \"Red team has too many players.\n\"" ); return; // ignore the request } if ( team == TEAM_BLUE && counts[TEAM_BLUE] - counts[TEAM_RED] > 1 ) { trap_SendServerCommand( clientNum, "cp \"Blue team has too many players.\n\"" ); return; // ignore the request } // It's ok, the team we are switching to has less or same number of players } } else { // force them to spectators if there aren't any spots free team = TEAM_FREE; } // override decision if limiting the players if ( (g_gametype.integer == GT_TOURNAMENT) && level.numNonSpectatorClients >= 2 ) { team = TEAM_SPECTATOR; } else if ( g_maxGameClients.integer > 0 && level.numNonSpectatorClients >= g_maxGameClients.integer ) { team = TEAM_SPECTATOR; } // // decide if we will allow the change // oldTeam = client->sess.sessionTeam; if ( team == oldTeam && team != TEAM_SPECTATOR ) { return; } // // execute the team change // // if the player was dead leave the body if ( client->ps.stats[STAT_HEALTH] <= 0 ) { CopyToBodyQue(ent); } // he starts at 'base' client->pers.teamState.state = TEAM_BEGIN; if ( oldTeam != TEAM_SPECTATOR ) { // Kill him (makes sure he loses flags, etc) ent->flags &= ~FL_GODMODE; ent->client->ps.stats[STAT_HEALTH] = ent->health = 0; player_die (ent, ent, ent, 100000, MOD_SUICIDE); } // they go to the end of the line for tournements if(team == TEAM_SPECTATOR && oldTeam != team) AddTournamentQueue(client); client->sess.sessionTeam = team; client->sess.spectatorState = specState; client->sess.spectatorClient = specClient; client->sess.teamLeader = qfalse; if ( team == TEAM_RED || team == TEAM_BLUE ) { teamLeader = TeamLeader( team ); // if there is no team leader or the team leader is a bot and this client is not a bot if ( teamLeader == -1 || ( !(g_entities[clientNum].r.svFlags & SVF_BOT) && (g_entities[teamLeader].r.svFlags & SVF_BOT) ) ) { SetLeader( team, clientNum ); } } // make sure there is a team leader on the team the player came from if ( oldTeam == TEAM_RED || oldTeam == TEAM_BLUE ) { CheckTeamLeader( oldTeam ); } BroadcastTeamChange( client, oldTeam ); // get and distribute relevent paramters ClientUserinfoChanged( clientNum ); ClientBegin( clientNum ); }
// Module RPC entry point static void VMMain(int index, RPC::Reader& inputs, RPC::Writer& outputs) { switch (index) { case GAME_INIT: { int levelTime = inputs.ReadInt(); int randomSeed = inputs.ReadInt(); qboolean restart = inputs.ReadInt(); G_InitGame(levelTime, randomSeed, restart); break; } case GAME_SHUTDOWN: G_ShutdownGame(inputs.ReadInt()); break; case GAME_CLIENT_CONNECT: { int clientNum = inputs.ReadInt(); qboolean firstTime = inputs.ReadInt(); qboolean isBot = inputs.ReadInt(); const char* denied = isBot ? ClientBotConnect(clientNum, firstTime, TEAM_NONE) : ClientConnect(clientNum, firstTime); outputs.WriteInt(denied ? qtrue : qfalse); if (denied) outputs.WriteString(denied); break; } case GAME_CLIENT_THINK: ClientThink(inputs.ReadInt()); break; case GAME_CLIENT_USERINFO_CHANGED: ClientUserinfoChanged(inputs.ReadInt(), qfalse); break; case GAME_CLIENT_DISCONNECT: ClientDisconnect(inputs.ReadInt()); break; case GAME_CLIENT_BEGIN: ClientBegin(inputs.ReadInt()); break; case GAME_CLIENT_COMMAND: ClientCommand(inputs.ReadInt()); break; case GAME_RUN_FRAME: G_RunFrame(inputs.ReadInt()); break; case GAME_CONSOLE_COMMAND: outputs.WriteInt(ConsoleCommand()); break; case GAME_SNAPSHOT_CALLBACK: G_Error("GAME_SNAPSHOT_CALLBACK not implemented"); break; case BOTAI_START_FRAME: G_Error("BOTAI_START_FRAME not implemented"); break; case GAME_MESSAGERECEIVED: G_Error("GAME_MESSAGERECEIVED not implemented"); break; default: G_Error("VMMain(): unknown game command %i", index); } }
void VM::VMHandleSyscall(uint32_t id, Util::Reader reader) { int major = id >> 16; int minor = id & 0xffff; if (major == VM::QVM) { switch (minor) { case GAME_STATIC_INIT: IPC::HandleMsg<GameStaticInitMsg>(VM::rootChannel, std::move(reader), [] (int milliseconds) { VM::InitializeProxies(milliseconds); FS::Initialize(); VM::VMInit(); }); break; case GAME_INIT: IPC::HandleMsg<GameInitMsg>(VM::rootChannel, std::move(reader), [](int levelTime, int randomSeed, bool cheats, bool inClient) { g_cheats.integer = cheats; G_InitGame(levelTime, randomSeed, inClient); }); break; case GAME_SHUTDOWN: IPC::HandleMsg<GameShutdownMsg>(VM::rootChannel, std::move(reader), [](bool restart) { G_ShutdownGame(restart); }); break; case GAME_CLIENT_CONNECT: IPC::HandleMsg<GameClientConnectMsg>(VM::rootChannel, std::move(reader), [](int clientNum, bool firstTime, int isBot, bool& denied, std::string& reason) { const char* deniedStr = isBot ? ClientBotConnect(clientNum, firstTime, TEAM_NONE) : ClientConnect(clientNum, firstTime); denied = deniedStr != nullptr; if (denied) reason = deniedStr; }); break; case GAME_CLIENT_THINK: IPC::HandleMsg<GameClientThinkMsg>(VM::rootChannel, std::move(reader), [](int clientNum) { ClientThink(clientNum); }); break; case GAME_CLIENT_USERINFO_CHANGED: IPC::HandleMsg<GameClientUserinfoChangedMsg>(VM::rootChannel, std::move(reader), [](int clientNum) { ClientUserinfoChanged(clientNum, false); }); break; case GAME_CLIENT_DISCONNECT: IPC::HandleMsg<GameClientDisconnectMsg>(VM::rootChannel, std::move(reader), [](int clientNum) { ClientDisconnect(clientNum); }); break; case GAME_CLIENT_BEGIN: IPC::HandleMsg<GameClientBeginMsg>(VM::rootChannel, std::move(reader), [](int clientNum) { ClientBegin(clientNum); }); break; case GAME_CLIENT_COMMAND: IPC::HandleMsg<GameClientCommandMsg>(VM::rootChannel, std::move(reader), [](int clientNum, std::string command) { Cmd::PushArgs(command); ClientCommand(clientNum); Cmd::PopArgs(); }); break; case GAME_RUN_FRAME: IPC::HandleMsg<GameRunFrameMsg>(VM::rootChannel, std::move(reader), [](int levelTime) { G_RunFrame(levelTime); }); break; case GAME_SNAPSHOT_CALLBACK: G_Error("GAME_SNAPSHOT_CALLBACK not implemented"); break; case BOTAI_START_FRAME: G_Error("BOTAI_START_FRAME not implemented"); break; case GAME_MESSAGERECEIVED: G_Error("GAME_MESSAGERECEIVED not implemented"); break; default: G_Error("VMMain(): unknown game command %i", minor); } } else if (major < VM::LAST_COMMON_SYSCALL) { VM::HandleCommonSyscall(major, minor, std::move(reader), VM::rootChannel); } else { G_Error("unhandled VM major syscall number %i", major); } }
/* =============== G_AddBot =============== */ static void G_AddBot( const char *name, float skill, const char *team, int delay, char *altname) { int clientNum; int teamNum; int botinfoNum; char *botinfo; char *key; char *s; char *botname; char *model; char *headmodel; 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" ); } // check for an alternative name if (altname && altname[0]) { botname = altname; } Info_SetValueForKey( userinfo, "name", botname ); Info_SetValueForKey( userinfo, "rate", "25000" ); Info_SetValueForKey( userinfo, "snaps", "20" ); Info_SetValueForKey( userinfo, "skill", va("%.2f", skill) ); Info_SetValueForKey( userinfo, "teampref", team ); key = "model"; model = Info_ValueForKey( botinfo, key ); if ( !*model ) { model = "visor/default"; } Info_SetValueForKey( userinfo, key, model ); key = "team_model"; Info_SetValueForKey( userinfo, key, model ); key = "headmodel"; headmodel = Info_ValueForKey( botinfo, key ); if ( !*headmodel ) { headmodel = model; } Info_SetValueForKey( userinfo, key, headmodel ); key = "team_headmodel"; Info_SetValueForKey( userinfo, key, headmodel ); key = "gender"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "male"; } Info_SetValueForKey( userinfo, "sex", s ); key = "color1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "4"; } Info_SetValueForKey( userinfo, key, s ); key = "color2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "5"; } 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 ); // don't send tinfo to bots, they don't parse it Info_SetValueForKey( userinfo, "teamoverlay", "0" ); // 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 ); }
/* =============== G_AddBot =============== */ static void G_AddBot( const char *name, float skill, const char *team, const char *pclass, int delay, char *altname) { int clientNum; char *botinfo; gentity_t *bot; char *key; char *s; char *botname; char *model; char userinfo[MAX_INFO_STRING]; int preTeam = 0; // get the botinfo from bots.txt botinfo = G_GetBotInfoByName( name ); if ( !botinfo ) { G_Printf( S_COLOR_RED "Error: Bot '%s' not defined\n", name ); return; } // create the bot's userinfo userinfo[0] = '\0'; botname = Info_ValueForKey( botinfo, "funname" ); if( !botname[0] ) { botname = Info_ValueForKey( botinfo, "name" ); } // check for an alternative name if (altname && altname[0]) { botname = altname; } Info_SetValueForKey( userinfo, "name", botname ); Info_SetValueForKey( userinfo, "rate", "25000" ); Info_SetValueForKey( userinfo, "snaps", "20" ); Info_SetValueForKey( userinfo, "skill", va("%1.2f", skill) ); /* if ( skill >= 1 && skill < 2 ) { Info_SetValueForKey( userinfo, "handicap", "50" ); } else if ( skill >= 2 && skill < 3 ) { Info_SetValueForKey( userinfo, "handicap", "70" ); } else if ( skill >= 3 && skill < 4 ) { Info_SetValueForKey( userinfo, "handicap", "90" ); } */ key = "model"; model = Info_ValueForKey( botinfo, key ); if ( !*model ) { model = "munro/main/default"; //RPG-X MODEL SYSTEM } 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_Printf( S_COLOR_RED "Error: bot has no aifile specified\n" ); return; } // 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; } // initialize the bot settings if( !team || !*team ) { if( g_gametype.integer >= GT_TEAM ) { if( PickTeam(clientNum) == TEAM_RED) { team = "red"; } else { team = "blue"; } } else { team = "red"; } } Info_SetValueForKey( userinfo, "characterfile", Info_ValueForKey( botinfo, "aifile" ) ); Info_SetValueForKey( userinfo, "skill", va( "%5.2f", skill ) ); Info_SetValueForKey( userinfo, "team", team ); bot = &g_entities[ clientNum ]; bot->r.svFlags |= SVF_BOT; bot->inuse = qtrue; // register the userinfo trap_SetUserinfo( clientNum, userinfo ); if (g_gametype.integer >= GT_TEAM) { if (team && Q_stricmp(team, "red") == 0) { bot->client->sess.sessionTeam = TEAM_RED; } else if (team && Q_stricmp(team, "blue") == 0) { bot->client->sess.sessionTeam = TEAM_BLUE; } else { bot->client->sess.sessionTeam = PickTeam( -1 ); } } preTeam = bot->client->sess.sessionTeam; // have it connect to the game as a normal client if ( ClientConnect( clientNum, qtrue, qtrue ) ) { return; } if (bot->client->sess.sessionTeam != preTeam) { trap_GetUserinfo(clientNum, userinfo, MAX_INFO_STRING); if (bot->client->sess.sessionTeam == TEAM_SPECTATOR) { bot->client->sess.sessionTeam = preTeam; } if (bot->client->sess.sessionTeam == TEAM_RED) { team = "Red"; } else { team = "Blue"; } Info_SetValueForKey( userinfo, "team", team ); trap_SetUserinfo( clientNum, userinfo ); bot->client->ps.persistant[ PERS_TEAM ] = bot->client->sess.sessionTeam; G_ReadSessionData( bot->client ); ClientUserinfoChanged( clientNum ); } if( delay == 0 ) { ClientBegin( clientNum, qfalse, qfalse, qfalse ); return; } AddBotToSpawnQueue( clientNum, delay ); }
/* =============== G_AddBot =============== */ static void G_AddBot( const char *name, float skill, const char *team, int delay, char *altname) { int clientNum; char *botinfo; gentity_t *bot; char *key; char *s; char *botname; char *model; char *headmodel; char userinfo[MAX_INFO_STRING]; // get the botinfo from bots.txt botinfo = G_GetBotInfoByName( name ); if ( !botinfo ) { G_Printf( S_COLOR_RED "Error: Bot '%s' not defined\n", name ); return; } // create the bot's userinfo userinfo[0] = '\0'; botname = Info_ValueForKey( botinfo, "funname" ); if( !botname[0] ) { botname = Info_ValueForKey( botinfo, "name" ); } // check for an alternative name if (altname && altname[0]) { botname = altname; } Info_SetValueForKey( userinfo, "name", botname ); Info_SetValueForKey( userinfo, "rate", "25000" ); Info_SetValueForKey( userinfo, "snaps", "20" ); Info_SetValueForKey( userinfo, "skill", va("%1.2f", skill) ); if ( skill >= 1 && skill < 2 ) { Info_SetValueForKey( userinfo, "handicap", "50" ); } else if ( skill >= 2 && skill < 3 ) { Info_SetValueForKey( userinfo, "handicap", "70" ); } else if ( skill >= 3 && skill < 4 ) { Info_SetValueForKey( userinfo, "handicap", "90" ); } key = "model"; model = Info_ValueForKey( botinfo, key ); if ( !*model ) { model = "sarge/default"; } Info_SetValueForKey( userinfo, key, model ); key = "team_model"; Info_SetValueForKey( userinfo, key, model ); key = "headmodel"; headmodel = Info_ValueForKey( botinfo, key ); if ( !*headmodel ) { headmodel = model; } Info_SetValueForKey( userinfo, key, headmodel ); key = "team_headmodel"; Info_SetValueForKey( userinfo, key, headmodel ); key = "gender"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "male"; } Info_SetValueForKey( userinfo, "sex", s ); key = "color1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "4"; } Info_SetValueForKey( userinfo, key, s ); key = "color2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "5"; } Info_SetValueForKey( userinfo, key, s ); s = Info_ValueForKey(botinfo, "aifile"); if (!*s ) { trap_Printf( S_COLOR_RED "Error: bot has no aifile specified\n" ); return; } // 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; } // initialize the bot settings if( !team || !*team ) { if( g_gametype.integer >= GT_TEAM && g_ffa_gt!=1) { if( PickTeam(clientNum) == TEAM_RED) { team = "red"; } else { team = "blue"; } } else { team = "red"; } } Info_SetValueForKey( userinfo, "characterfile", Info_ValueForKey( botinfo, "aifile" ) ); Info_SetValueForKey( userinfo, "skill", va( "%5.2f", skill ) ); Info_SetValueForKey( userinfo, "team", team ); bot = &g_entities[ clientNum ]; bot->r.svFlags |= SVF_BOT; bot->inuse = qtrue; // 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 ); }
//[TABBot] //added bot type varible static void G_AddBot( const char *name, float skill, const char *team, int delay, char *altname, int bottype) { //static void G_AddBot( const char *name, float skill, const char *team, int delay, char *altname) { //[/TABBot] int clientNum; char *botinfo; gentity_t *bot; char *key; char *s; char *botname; char *model; // char *headmodel; char userinfo[MAX_INFO_STRING]; int preTeam = 0; //[DuelGuns][EnhancedImpliment] /* char *firearm; // ** change gun model qboolean bot_dualguns = qfalse; int gunoption=0; */ //[/DuelGuns][EnhancedImpliment] // get the botinfo from bots.txt botinfo = G_GetBotInfoByName( name ); if ( !botinfo ) { G_Printf( S_COLOR_RED "Error: Bot '%s' not defined\n", name ); return; } // create the bot's userinfo userinfo[0] = '\0'; botname = Info_ValueForKey( botinfo, "funname" ); if( !botname[0] ) { botname = Info_ValueForKey( botinfo, "name" ); } // check for an alternative name if (altname && altname[0]) { botname = altname; } Info_SetValueForKey( userinfo, "name", botname ); Info_SetValueForKey( userinfo, "rate", "25000" ); Info_SetValueForKey( userinfo, "snaps", "20" ); Info_SetValueForKey( userinfo, "skill", va("%1.2f", skill) ); if ( skill >= 1 && skill < 2 ) { Info_SetValueForKey( userinfo, "handicap", "50" ); } else if ( skill >= 2 && skill < 3 ) { Info_SetValueForKey( userinfo, "handicap", "70" ); } else if ( skill >= 3 && skill < 4 ) { Info_SetValueForKey( userinfo, "handicap", "90" ); } key = "model"; model = Info_ValueForKey( botinfo, key ); if ( !*model ) { model = "kyle/default"; } Info_SetValueForKey( userinfo, key, model ); /* key = "headmodel"; headmodel = Info_ValueForKey( botinfo, key ); if ( !*headmodel ) { headmodel = model; } Info_SetValueForKey( userinfo, key, headmodel ); key = "team_headmodel"; Info_SetValueForKey( userinfo, key, headmodel ); */ key = "gender"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "male"; } Info_SetValueForKey( userinfo, "sex", s ); key = "color1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "4"; } Info_SetValueForKey( userinfo, key, s ); key = "color2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "4"; } Info_SetValueForKey( userinfo, key, s ); key = "saber1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "single_1"; } Info_SetValueForKey( userinfo, key, s ); key = "saber2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "none"; } Info_SetValueForKey( userinfo, key, s ); s = Info_ValueForKey(botinfo, "personality"); if (!*s ) { Info_SetValueForKey( userinfo, "personality", "botfiles/default.jkb" ); } else { Info_SetValueForKey( userinfo, "personality", s ); } //[DuelGuns][EnhancedImpliment] /* // if(1)//f_dualguns.integer) // { key = "dualgun"; s = Info_ValueForKey(botinfo, key); if (*s) { gunoption = atoi(s); } if(gunoption>0) bot_dualguns = qtrue; // } firearm = Info_ValueForKey( botinfo, "firearm"); if (!*firearm) { Info_SetValueForKey( userinfo, "firearm", botname ); } else { Info_SetValueForKey( userinfo, "firearm", firearm); } */ //[/DuelGuns][EnhancedImpliment] //[RGBSabers] key = "rgb_saber1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "255,0,0"; } Info_SetValueForKey( userinfo, key, s ); key = "rgb_saber2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "0,255,255"; } Info_SetValueForKey( userinfo, key, s ); key = "rgb_script1"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "none"; } Info_SetValueForKey( userinfo, key, s ); key = "rgb_script2"; s = Info_ValueForKey( botinfo, key ); if ( !*s ) { s = "none"; } Info_SetValueForKey( userinfo, key, s ); //[/RGBSabers] //[ClientPlugInDetect] //set it so that the bots are assumed to have the OJP client plugin //this should be CURRENT_OJPENHANCED_CLIENTVERSION Info_SetValueForKey( userinfo, "ojp_clientplugin", CURRENT_OJPENHANCED_CLIENTVERSION ); //[/ClientPlugInDetect] // 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.\n" ); trap_SendServerCommand( -1, va("print \"%s\n\"", G_GetStringEdString("MP_SVGAME", "UNABLE_TO_ADD_BOT"))); return; } //[DuelGuns][EnhancedImpliment] /* if(bot_dualguns) { g_entities[clientNum].client->ps.dualguns = 1; } */ //[/DuelGuns][EnhancedImpliment] // initialize the bot settings if( !team || !*team ) { if( g_gametype.integer >= GT_TEAM ) { //[AdminSys] if( PickTeam(clientNum, qtrue) == TEAM_RED) { //if( PickTeam(clientNum) == TEAM_RED) { //[/AdminSys] team = "red"; } else { team = "blue"; } } else { team = "red"; } } // Info_SetValueForKey( userinfo, "characterfile", Info_ValueForKey( botinfo, "aifile" ) ); Info_SetValueForKey( userinfo, "skill", va( "%5.2f", skill ) ); Info_SetValueForKey( userinfo, "team", team ); //[TABBot] Info_SetValueForKey( userinfo, "bottype", va( "%i", bottype) ); //[/TABBot] bot = &g_entities[ clientNum ]; bot->r.svFlags |= SVF_BOT; bot->inuse = qtrue; // register the userinfo trap_SetUserinfo( clientNum, userinfo ); //[NewGameTypes][EnhancedImpliment] //if (g_gametype.integer >= GT_TEAM && g_gametype.integer != GT_RPG) if (g_gametype.integer >= GT_TEAM) //[/NewGameTypes][EnhancedImpliment] { if (team && Q_stricmp(team, "red") == 0) { bot->client->sess.sessionTeam = TEAM_RED; } else if (team && Q_stricmp(team, "blue") == 0) { bot->client->sess.sessionTeam = TEAM_BLUE; } else { //[AdminSys] bot->client->sess.sessionTeam = PickTeam( -1, qtrue ); //bot->client->sess.sessionTeam = PickTeam( -1 ); //[/AdminSys] } } if (g_gametype.integer == GT_SIEGE) { bot->client->sess.siegeDesiredTeam = bot->client->sess.sessionTeam; bot->client->sess.sessionTeam = TEAM_SPECTATOR; } preTeam = bot->client->sess.sessionTeam; // have it connect to the game as a normal client if ( ClientConnect( clientNum, qtrue, qtrue ) ) { return; } if (bot->client->sess.sessionTeam != preTeam) { trap_GetUserinfo(clientNum, userinfo, MAX_INFO_STRING); if (bot->client->sess.sessionTeam == TEAM_SPECTATOR) { bot->client->sess.sessionTeam = preTeam; } if (bot->client->sess.sessionTeam == TEAM_RED) { team = "Red"; } else { if (g_gametype.integer == GT_SIEGE) { if (bot->client->sess.sessionTeam == TEAM_BLUE) { team = "Blue"; } else { team = "s"; } } else { team = "Blue"; } } Info_SetValueForKey( userinfo, "team", team ); trap_SetUserinfo( clientNum, userinfo ); bot->client->ps.persistant[ PERS_TEAM ] = bot->client->sess.sessionTeam; G_ReadSessionData( bot->client ); ClientUserinfoChanged( clientNum ); } if (g_gametype.integer == GT_DUEL || g_gametype.integer == GT_POWERDUEL) { int loners = 0; int doubles = 0; bot->client->sess.duelTeam = 0; G_PowerDuelCount(&loners, &doubles, qtrue); if (!doubles || loners > (doubles/2)) { bot->client->sess.duelTeam = DUELTEAM_DOUBLE; } else { bot->client->sess.duelTeam = DUELTEAM_LONE; } bot->client->sess.sessionTeam = TEAM_SPECTATOR; SetTeam(bot, "s"); } else { if( delay == 0 ) { ClientBegin( clientNum, qfalse ); //UNIQUEFIX - what's the purpose of this? //ClientUserinfoChanged( clientNum ); return; } AddBotToSpawnQueue( clientNum, delay ); //UNIQUEFIX - what's the purpose of this? //ClientUserinfoChanged( clientNum ); } }