示例#1
0
/*
===============
Svcmd_BotList_f
===============
*/
void Svcmd_BotList_f( void ) {
	int i;
	char name[MAX_TOKEN_CHARS];
	char funname[MAX_TOKEN_CHARS];
	char model[MAX_TOKEN_CHARS];
	char personality[MAX_TOKEN_CHARS];

	trap_Printf("^1name             model            personality              funname\n");
	for (i = 0; i < g_numBots; i++) {
		strcpy(name, Info_ValueForKey( g_botInfos[i], "name" ));
		if ( !*name ) {
			strcpy(name, "Padawan");
		}
		strcpy(funname, Info_ValueForKey( g_botInfos[i], "funname" ));
		if ( !*funname ) {
			strcpy(funname, "");
		}
		strcpy(model, Info_ValueForKey( g_botInfos[i], "model" ));
		if ( !*model ) {
			strcpy(model, "kyle/default");
		}
		strcpy(personality, Info_ValueForKey( g_botInfos[i], "personality"));
		if (!*personality ) {
			strcpy(personality, "botfiles/kyle.jkb");
		}
		trap_Printf(va("%-16s %-16s %-20s %-20s\n", name, model, personality, funname));
	}
}
示例#2
0
文件: g_bot.c 项目: titityy/reaction
/*
===============
G_LoadArenasFromFile
===============
*/
static void G_LoadArenasFromFile(char *filename)
{
	int len;
	fileHandle_t f;
	char buf[MAX_ARENAS_TEXT];

	len = trap_FS_FOpenFile(filename, &f, FS_READ);
	if (!f) {
		trap_Printf(va(S_COLOR_RED "file not found: %s\n", filename));
		return;
	}
	if (len >= MAX_ARENAS_TEXT) {
		trap_Printf(va
			    (S_COLOR_RED "file too large: %s is %i, max allowed is %i\n", 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 += G_ParseInfos(buf, MAX_ARENAS - g_numArenas, &g_arenaInfos[g_numArenas]);
}
示例#3
0
/*
===============
Svcmd_BotList_f
===============
*/
void Svcmd_BotList_f( void ) {
	int i;
	char name[MAX_TOKEN_CHARS];
	char funname[MAX_TOKEN_CHARS];
	char model[MAX_TOKEN_CHARS];
	char aifile[MAX_TOKEN_CHARS];

	trap_Printf("^1name             model            aifile              funname\n");
	for (i = 0; i < g_numBots; i++) {
		strcpy(name, Info_ValueForKey( g_botInfos[i], "name" ));
		if ( !*name ) {
			strcpy(name, "UnnamedPlayer");
		}
		strcpy(funname, Info_ValueForKey( g_botInfos[i], "funname" ));
		if ( !*funname ) {
			strcpy(funname, "");
		}
		strcpy(model, Info_ValueForKey( g_botInfos[i], "model" ));
		if ( !*model ) {
			strcpy(model, "sarge/default");
		}
		strcpy(aifile, Info_ValueForKey( g_botInfos[i], "aifile"));
		if (!*aifile ) {
			strcpy(aifile, "bots/default_c.c");
		}
		trap_Printf(va("%-16s %-16s %-20s %-20s\n", name, model, aifile, funname));
	}
}
示例#4
0
文件: g_lua.c 项目: otty/cake3
/*
=================
G_LoadLuaScript
=================
*/
void G_LoadLuaScript(gentity_t * ent, const char *filename)
{
	int             len;
	fileHandle_t    f;
	char            buf[MAX_LUAFILE];
	
	G_Printf("...loading '%s'\n", filename);

	len = trap_FS_FOpenFile(filename, &f, FS_READ);
	if(!f)
	{
		trap_Printf(va(S_COLOR_RED "file not found: %s\n", filename));
		return;
	}

	if(len >= MAX_LUAFILE)
	{
		trap_Printf(va(S_COLOR_RED "file too large: %s is %i, max allowed is %i\n", filename, len, MAX_LUAFILE));
		trap_FS_FCloseFile(f);
		return;
	}

	trap_FS_Read(buf, len, f);
	buf[len] = 0;
	trap_FS_FCloseFile(f);

	if(luaL_loadbuffer(g_luaState, buf, strlen(buf), filename))
		G_Printf("G_RunLuaScript: cannot load lua file: %s\n", lua_tostring(g_luaState, -1));

	if(lua_pcall(g_luaState, 0, 0, 0))
		G_Printf("G_RunLuaScript: cannot pcall: %s\n", lua_tostring(g_luaState, -1));
}
示例#5
0
/*
===============
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 ( !bot_enable.integer ) {
		return;
	}

	// name
	trap_Argv( 1, name, sizeof( name ) );	/// read it just so we can check if it's a name (old method)
	if ( name[0] && !Q_stricmp( name, "?" ) ) {
		trap_Printf( "Usage: Addbot [skill 1-4] [team (RED/BLUE)] [msec delay]\n" );
		return;
	}
	// CHRUKER: b070 - Was 'wolfbot' but this must match in case
	Q_strncpyz( name, "Wolfbot", sizeof( name ) );	// RF, hard code the bots for wolf
	if ( !name[0] ) {
		trap_Printf( "Usage: Addbot [skill 1-4] [team (RED/BLUE)] [msec delay]\n" );
		return;
	}

	// skill
	trap_Argv( 1, string, sizeof( string ) );
	if ( !string[0] ) {
		trap_Cvar_Update( &bot_defaultskill );
		skill = bot_defaultskill.integer;
	}
	else {
		skill = atoi( string );
	}

	// team
	trap_Argv( 2, team, sizeof( team ) );

	// delay
	trap_Argv( 3, string, sizeof( string ) );
	if ( !string[0] ) {
		delay = 0;
	}
	else {
		delay = atoi( string );
	}

	G_AddBot( name, skill, team, NULL, 0, 0, -1, NULL, NULL, -1, NULL, qfalse);

	// 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" ) ) {
	}
}
示例#6
0
文件: g_bot.c 项目: otty/cake3
/*
===============
Svcmd_AddBot_f
===============
*/
void Svcmd_AddBot_f(void)
{
	float           skill;
	int             delay;
	char            name[MAX_TOKEN_CHARS];
	char            altname[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_Printf("Usage: Addbot <botname> [skill 1-5] [team] [msec delay] [altname]\n");
		return;
	}

	// skill
	trap_Argv(2, string, sizeof(string));
	if(!string[0])
	{
		skill = 4;
	}
	else
	{
		skill = atof(string);
	}

	// team
	trap_Argv(3, team, sizeof(team));

	// delay
	trap_Argv(4, string, sizeof(string));
	if(!string[0])
	{
		delay = 0;
	}
	else
	{
		delay = atoi(string);
	}

	// alternative name
	trap_Argv(5, altname, sizeof(altname));

	G_AddBot(name, skill, team, delay, altname);

	// 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, "loaddefered\n");	// FIXME: spelled wrong, but not changing for demo
	}
}
示例#7
0
/*
===============
G_GetBotInfoByNumber
===============
*/
char *G_GetBotInfoByNumber( int num ) {
	if( num < 0 || num >= g_numBots ) {
		trap_Printf( va( S_COLOR_RED "Invalid bot number: %i\n", num ) );
		return NULL;
	}
	return g_botInfos[num];
}
示例#8
0
/*
===============
G_LoadArenas
===============
*/
static void G_LoadArenas( void ) {
	int			numdirs;
	vmCvar_t	arenasFile;
	char		filename[128];
	char		dirlist[1024];
	char*		dirptr;
	int			i, n;
	int			dirlen;

	g_numArenas = 0;

	trap_Cvar_Register( &arenasFile, "g_arenasFile", "", CVAR_INIT|CVAR_ROM );
	if( *arenasFile.string ) {
		G_LoadArenasFromFile(arenasFile.string);
	}
	else {
		G_LoadArenasFromFile("scripts/arenas.txt");
	}

	// get all arenas from .arena files
	numdirs = trap_FS_GetFileList("scripts", ".arena", dirlist, 1024 );
	dirptr  = dirlist;
	for (i = 0; i < numdirs; i++, dirptr += dirlen+1) {
		dirlen = strlen(dirptr);
		strcpy(filename, "scripts/");
		strcat(filename, dirptr);
		G_LoadArenasFromFile(filename);
	}
	trap_Printf( va( "%i arenas parsed\n", g_numArenas ) );
	
	for( n = 0; n < g_numArenas; n++ ) {
		Info_SetValueForKey( g_arenaInfos[n], "num", va( "%i", n ) );
	}
}
示例#9
0
/*
===============
G_LoadBots
===============
*/
static void G_LoadBots( void ) {
	vmCvar_t	botsFile;
	int			numdirs;
	char		filename[128];
	char		dirlist[1024];
	char*		dirptr;
	int			i;
	int			dirlen;

	if ( !trap_Cvar_VariableIntegerValue( "bot_enable" ) ) {
		return;
	}

	g_numBots = 0;

	trap_Cvar_Register( &botsFile, "g_botsFile", "", CVAR_INIT|CVAR_ROM );
	if( *botsFile.string ) {
		G_LoadBotsFromFile(botsFile.string);
	}
	else {
		G_LoadBotsFromFile("scripts/bots.txt");
	}

	// get all bots from .bot files
	numdirs = trap_FS_GetFileList("scripts", ".bot", dirlist, 1024 );
	dirptr  = dirlist;
	for (i = 0; i < numdirs; i++, dirptr += dirlen+1) {
		dirlen = strlen(dirptr);
		strcpy(filename, "scripts/");
		strcat(filename, dirptr);
		G_LoadBotsFromFile(filename);
	}
	trap_Printf( va( "%i bots parsed\n", g_numBots ) );
}
示例#10
0
void QDECL LUA_LOG(const char *fmt, ...)
{
	va_list         argptr;
	char            buff[1024], string[1024];
	int             min, tens, sec;

	va_start(argptr, fmt);
	Com_sprintf(buff, sizeof(buff), fmt, argptr);
	va_end(argptr);

	if(g_dedicated.integer)
	{
		trap_Printf(buff);
	}

	if(level.logFile)
	{
		sec = level.time / 1000;
		min = sec / 60;
		sec -= min * 60;
		tens = sec / 10;
		sec -= tens * 10;

		Com_sprintf(string, sizeof(string), "%i:%i%i %s", min, tens, sec, buff);

		trap_FS_Write(string, strlen(string), level.logFile);
	}
}
示例#11
0
/*
===============
G_LoadBots
===============
*/
static void G_LoadBots(void)
{
	int          len;
	char         *filename;
	vmCvar_t     botsFile;
	fileHandle_t f;
	char         buf[MAX_BOTS_TEXT];

	if (!bot_enable.integer)
	{
		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_Printf(va(S_COLOR_RED "file not found: %s\n", filename));
		return;
	}
	if (len >= MAX_BOTS_TEXT)
	{
		trap_Printf(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_Printf(va("%i bots parsed\n", g_numBots));

	// load bot script
	Bot_ScriptLoad();
}
示例#12
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_Printf(va(S_COLOR_RED "file not found: %s\n", filename));
		return;
	}
	if (len >= MAX_ARENAS_TEXT)
	{
		trap_Printf(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_Printf(va("%i arenas parsed\n", g_numArenas));

	for (n = 0; n < g_numArenas; n++)
	{
		Info_SetValueForKey(g_arenaInfos[n], "num", va("%i", n));
	}
#endif
}
示例#13
0
void QDECL G_Printf( const char *fmt, ... ) {
	va_list		argptr;
	char		text[1024];

	va_start (argptr, fmt);
	Q_vsnprintf (text, sizeof(text), fmt, argptr);
	va_end (argptr);

	trap_Printf( text );
}
示例#14
0
文件: g_referee.c 项目: GenaSG/ET
void G_refPrintf( gentity_t* ent, const char *fmt, ... )
{
	va_list		argptr;
	char		text[1024];

	va_start (argptr, fmt);
	Q_vsnprintf (text, sizeof(text), fmt, argptr);
	va_end (argptr);

	if(ent == NULL) trap_Printf(text);
	else CP(va("cpm \"%s\n\"", text));
}
示例#15
0
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 );
}
示例#16
0
文件: g_bot.c 项目: GenaSG/ET
/*
TDF - Mad Doc
===============
Svcmd_RemoveBot_f
===============
*/
void Svcmd_RemoveBot_f( void ) {
	char			name[MAX_TOKEN_CHARS];

	// are bots enabled?
	if ( !bot_enable.integer ) {
		return;
	}

	// name
	trap_Argv( 1, name, sizeof( name ) );	/// read it just so we can check if it's a name (old method)
	if ( !name[0] ) {
		trap_Printf( "Usage: Removebot name\n" );
		return;
	}

	G_RemoveNamedBot(name);
}
示例#17
0
void G_refPrintf( gentity_t* ent, const char *fmt, ... )
{
	va_list		argptr;
	char		text[1024];

	va_start (argptr, fmt);
	Q_vsnprintf (text, sizeof(text), fmt, argptr);
	va_end (argptr);
	// CHRUKER: b046 - Added the linebreak to the string.
	if(ent == NULL){
		// yada - in server console color codes look stupid
		ConsolizeString(text,text);
		trap_Printf(va("%s\n",text));
	}else{
		// CHRUKER: b046 - Was using the cpm command, but this is really just for the console.
		CP(va("print \"%s\n\"", text));
	}
}
示例#18
0
void QDECL LOG(const char *fmt, ...)
{
	va_list         argptr;
	char            buff[1024], string[1024];
	int             min, tens, sec;

	va_start(argptr, fmt);
	Q_vsnprintf(buff, sizeof(buff), fmt, argptr);
	va_end(argptr);

	if(g_dedicated.integer)
	{
		trap_Printf(buff);
	}

	if(level.logFile)
	{
		/* xreal
		if ( g_logOptions.integer & LOGOPTS_REALTIME ) {
			Com_sprintf(string, sizeof(string), "%s %s", G_GetRealTime(), buff);
		} else {
		*/
			sec = level.time / 1000;
			min = sec / 60;
			sec -= min * 60;
			tens = sec / 10;
			sec -= tens * 10;

			Com_sprintf(string, sizeof(string), "%i:%i%i %s", min, tens, sec, buff);
		/* xreal
		}
		*/

		trap_FS_Write(string, strlen(string), level.logFile);
	}
}
/*
===============
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 );
}
示例#20
0
/*
===============
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 );
}
示例#21
0
文件: g_bot.c 项目: titityy/reaction
/*
===============
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;
	}
}
示例#22
0
/*
===============
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 );
}
示例#23
0
文件: g_bot.c 项目: GenaSG/ET
static void G_AddBot( const char *name, int skill, const char *team, const char *spawnPoint, int playerClass, int playerWeapon, int characerIndex, const char *respawn, const char *scriptName, int rank, int skills[], qboolean pow ) {
#define	MAX_BOTNAMES 1024
	int				clientNum;
	char			*botinfo;
	gentity_t		*bot;
	char			*key;
	char			*s;
	char			*botname;
//	char			*model;
	char			userinfo[MAX_INFO_STRING];

	// get the botinfo from bots.txt
	botinfo = G_GetBotInfoByName( "wolfbot" );
	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" );
	}
	Info_SetValueForKey( userinfo, "name", botname );
	Info_SetValueForKey( userinfo, "rate", "25000" );
	Info_SetValueForKey( userinfo, "snaps", "20" );
	Info_SetValueForKey( userinfo, "skill", va("%i", skill) );

	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( 0 );	// Arnout: 0 means no prefered clientslot
	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( PickTeam(clientNum) == TEAM_AXIS) {
			team = "red";
		} else {
			team = "blue";
		}
	}
	Info_SetValueForKey( userinfo, "characterfile", Info_ValueForKey( botinfo, "aifile" ) );
	//Info_SetValueForKey( userinfo, "skill", va( "%i", skill ) );
	Info_SetValueForKey( userinfo, "team", team );

	if( spawnPoint && spawnPoint[0] ) {
		Info_SetValueForKey( userinfo, "spawnPoint", spawnPoint );
	}

	if (scriptName && scriptName[0]) {
		Info_SetValueForKey( userinfo, "scriptName", scriptName );
	}

/*	if (playerClass > 0) {
		Info_SetValueForKey( userinfo, "pClass", va("%i", playerClass) );
	}

	if (playerWeapon) {
		Info_SetValueForKey( userinfo, "pWeapon", va("%i", playerWeapon) );
	}*/
	// END Mad Doc - TDF

	key = "wolfbot";
	if (!Q_stricmp( (char *)name, key )) {
		// read the botnames file, and pick a name that doesnt exist
		fileHandle_t f;
		int len, i, j, k;
		qboolean setname = qfalse;
		char botnames[8192], *pbotnames, *listbotnames[MAX_BOTNAMES], *token, *oldpbotnames;
		int	lengthbotnames[MAX_BOTNAMES];

		len = trap_FS_FOpenFile( "botfiles/botnames.txt", &f, FS_READ );

		if (len >= 0) {
			if (len > sizeof(botnames)) {
				G_Error( "botfiles/botnames.txt is too big (max = %i)", (int)sizeof(botnames) );
			}
			memset( botnames, 0, sizeof(botnames) );
			trap_FS_Read( botnames, len, f );
			pbotnames = botnames;
			// read them in
			i = 0;
			oldpbotnames = pbotnames;
			while ((token = COM_Parse( &pbotnames ))) {
				if (!token[0]) break;
				listbotnames[i] = strstr( oldpbotnames, token );
				lengthbotnames[i] = strlen(token);
				listbotnames[i][lengthbotnames[i]] = 0;
				oldpbotnames = pbotnames;
				if (++i == MAX_BOTNAMES) break;
			}
			//
			if (i > 2) {
				j = rand() % (i-1);	// start at a random spot inthe list
				for( k = j + 1; k != j; k++ ) {
					if( k == i ) {
						k = -1;	// gets increased on next loop
						continue;
					}
					if (ClientFromName( listbotnames[k] ) == -1) {
						// found an unused name
						Info_SetValueForKey( userinfo, "name", listbotnames[k]  );
						setname = qtrue;
						break;
					}
				}
			}
			//
			trap_FS_FCloseFile( f );
		}

		if (!setname) {
			Info_SetValueForKey( userinfo, "name", va("wolfbot_%i", clientNum+1)  );
		}
	} else {
		Info_SetValueForKey( userinfo, "name", name );
	}

	// if a character was specified, put the index of that character filename in the CS_CHARACTERS table in the userinfo
	if( characerIndex != -1 ) {
		Info_SetValueForKey( userinfo, "ch", va( "%i", characerIndex ) );
	}

	// if a rank was specified, use that
/*	if (rank != -1) {
		Info_SetValueForKey(userinfo, "rank", va("%i", rank));
	}*/

	// END Mad Doc - TDF
	
	bot = &g_entities[ clientNum ];
	bot->r.svFlags |= SVF_BOT;
	if( pow ) {
		bot->r.svFlags |= SVF_POW;
	}
	bot->inuse = qtrue;
	bot->aiName = bot->client->pers.netname;

	// register the userinfo
	trap_SetUserinfo( clientNum, userinfo );

	// have it connect to the game as a normal client
	if ((s = ClientConnect( clientNum, qtrue, qtrue ))) {
		G_Printf( S_COLOR_RED "Unable to add bot: %s\n", s );
		return;
	}

	SetTeam( bot, (char *)team, qtrue, -1, -1, qfalse );

/*	if( skills ) {
		int i;
		
		for( i = 0; i < SK_NUM_SKILLS; i++ ) {
			bot->client->sess.skill[i] = skills[i];
		}
	}*/
	return;
}