Beispiel #1
0
//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
int BotLoadCharacter( char *charfile, int skill )
{
    int skill1, skill4, handle;

    //make sure the skill is in the valid range
    if ( skill < 1 )
    {
        skill = 1;
    }
    else if ( skill > 5 )
    {
        skill = 5;
    }

    //skill 1, 4 and 5 should be available in the character files
    if ( skill == 1 || skill == 4 || skill == 5 )
    {
        return BotLoadCharacterSkill( charfile, skill );
    } //end if

    //check if there's a cached skill 2 or 3
    handle = BotFindCachedCharacter( charfile, skill );

    if ( handle )
    {
        //botimport.Print(PRT_MESSAGE, "loaded cached skill %d from %s\n", skill, charfile);
        return handle;
    } //end if

    //load skill 1 and 4
    skill1 = BotLoadCharacterSkill( charfile, 1 );

    if ( !skill1 )
    {
        return 0;
    }

    skill4 = BotLoadCharacterSkill( charfile, 4 );

    if ( !skill4 )
    {
        return skill1;
    }

    //interpolate between 1 and 4 to create skill 2 or 3
    handle = BotInterpolateCharacters( skill1, skill4, skill );

    if ( !handle )
    {
        return 0;
    }

    //write the character to the log file
    BotDumpCharacter( botcharacters[ handle ] );
    //
    return handle;
} //end of the function BotLoadCharacter
Beispiel #2
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
int BotLoadCharacter(char *charfile, float skill)
{
	int firstskill, secondskill, handle;

	//make sure the skill is in the valid range
	if (skill < 1.0) skill = 1.0;
	else if (skill > 5.0) skill = 5.0;
	//skill 1, 4 and 5 should be available in the character files
	if (skill == 1.0 || skill == 4.0 || skill == 5.0)
	{
		return BotLoadCharacterSkill(charfile, skill);
	} //end if
	//check if there's a cached skill
	handle = BotFindCachedCharacter(charfile, skill);
	if (handle)
	{
		BotAI_Print(PRT_DEVELOPER, "loaded cached skill %f from %s\n", skill, charfile);
		return handle;
	} //end if
	if (skill < 4.0)
	{
		//load skill 1 and 4
		firstskill = BotLoadCharacterSkill(charfile, 1);
		if (!firstskill) return 0;
		secondskill = BotLoadCharacterSkill(charfile, 4);
		if (!secondskill) return firstskill;
	} //end if
	else
	{
		//load skill 4 and 5
		firstskill = BotLoadCharacterSkill(charfile, 4);
		if (!firstskill) return 0;
		secondskill = BotLoadCharacterSkill(charfile, 5);
		if (!secondskill) return firstskill;
	} //end else
	//interpolate between the two skills
	handle = BotInterpolateCharacters(firstskill, secondskill, skill);
	if (!handle) return 0;
#if 0 // ZTM: FIXME: add new bot logfile for game to write to?
	//write the character to the log file
	BotDumpCharacter(&botcharacters[handle]);
#endif
	//
	return handle;
} //end of the function BotLoadCharacter
Beispiel #3
0
int
BotLoadCharacter(char *charfile, float skill)
{
	int firstskill, secondskill, handle;

	/* make sure the skill is in the valid range */
	if(skill < 1.0) skill = 1.0;
	else if(skill > 5.0) skill = 5.0;
	/* skill 1, 4 and 5 should be available in the character files */
	if(skill == 1.0 || skill == 4.0 || skill == 5.0)
		return BotLoadCharacterSkill(charfile, skill);
	/* check if there's a cached skill */
	handle = BotFindCachedCharacter(charfile, skill);
	if(handle){
		botimport.Print(PRT_MESSAGE, "loaded cached skill %f from %s\n",
			skill,
			charfile);
		return handle;
	}
	if(skill < 4.0){
		/* load skill 1 and 4 */
		firstskill = BotLoadCharacterSkill(charfile, 1);
		if(!firstskill) return 0;
		secondskill = BotLoadCharacterSkill(charfile, 4);
		if(!secondskill) return firstskill;
	}else{
		/* load skill 4 and 5 */
		firstskill = BotLoadCharacterSkill(charfile, 4);
		if(!firstskill) return 0;
		secondskill = BotLoadCharacterSkill(charfile, 5);
		if(!secondskill) return firstskill;
	}
	/* interpolate between the two skills */
	handle = BotInterpolateCharacters(firstskill, secondskill, skill);
	if(!handle) return 0;
	/* write the character to the log file */
	BotDumpCharacter(botcharacters[handle]);
	return handle;
}
Beispiel #4
0
//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
int BotLoadCachedCharacter( char *charfile, int skill, int reload )
{
    int             handle, cachedhandle;
    bot_character_t *ch = NULL;

#ifdef DEBUG
    int             starttime;

    starttime = Sys_MilliSeconds();
#endif //DEBUG

    //find a free spot for a character
    for ( handle = 1; handle <= MAX_CLIENTS; handle++ )
    {
        if ( !botcharacters[ handle ] )
        {
            break;
        }
    } //end for

    if ( handle > MAX_CLIENTS )
    {
        return 0;
    }

    //try to load a cached character with the given skill
    if ( !reload )
    {
        cachedhandle = BotFindCachedCharacter( charfile, skill );

        if ( cachedhandle )
        {
            //botimport.Print(PRT_MESSAGE, "loaded cached skill %d from %s\n", skill, charfile);
            return cachedhandle;
        } //end if
    } //end else

    //try to load the character with the given skill
    ch = BotLoadCharacterFromFile( charfile, skill );

    if ( ch )
    {
        botcharacters[ handle ] = ch;
        //
        //botimport.Print(PRT_MESSAGE, "loaded skill %d from %s\n", skill, charfile);
#ifdef DEBUG

        if ( bot_developer )
        {
            botimport.Print( PRT_MESSAGE, "skill %d loaded in %d msec from %s\n", skill, Sys_MilliSeconds() - starttime, charfile );
        } //end if

#endif //DEBUG
        return handle;
    } //end if

    //
    botimport.Print( PRT_WARNING, "couldn't find skill %d in %s\n", skill, charfile );

    //
    if ( !reload )
    {
        //try to load a cached default character with the given skill
        cachedhandle = BotFindCachedCharacter( "bots/default_c.c", skill );

        if ( cachedhandle )
        {
            botimport.Print( PRT_MESSAGE, "loaded cached default skill %d from %s\n", skill, charfile );
            return cachedhandle;
        } //end if
    } //end if

    //try to load the default character with the given skill
    ch = BotLoadCharacterFromFile( DEFAULT_CHARACTER, skill );

    if ( ch )
    {
        botcharacters[ handle ] = ch;
        //botimport.Print(PRT_MESSAGE, "loaded default skill %d from %s\n", skill, charfile);
        return handle;
    } //end if

    //
    if ( !reload )
    {
        //try to load a cached character with any skill
        cachedhandle = BotFindCachedCharacter( charfile, -1 );

        if ( cachedhandle )
        {
            //botimport.Print(PRT_MESSAGE, "loaded cached skill %d from %s\n", botcharacters[cachedhandle]->skill, charfile);
            return cachedhandle;
        } //end if
    } //end if

    //try to load a character with any skill
    ch = BotLoadCharacterFromFile( charfile, -1 );

    if ( ch )
    {
        botcharacters[ handle ] = ch;
        //botimport.Print(PRT_MESSAGE, "loaded skill %d from %s\n", ch->skill, charfile);
        return handle;
    } //end if

    //
    if ( !reload )
    {
        //try to load a cached character with any skill
        cachedhandle = BotFindCachedCharacter( DEFAULT_CHARACTER, -1 );

        if ( cachedhandle )
        {
            botimport.Print( PRT_MESSAGE, "loaded cached default skill %d from %s\n", botcharacters[ cachedhandle ]->skill,
                             charfile );
            return cachedhandle;
        } //end if
    } //end if

    //try to load a character with any skill
    ch = BotLoadCharacterFromFile( DEFAULT_CHARACTER, -1 );

    if ( ch )
    {
        botcharacters[ handle ] = ch;
        botimport.Print( PRT_MESSAGE, "loaded default skill %d from %s\n", ch->skill, charfile );
        return handle;
    } //end if

    //
    botimport.Print( PRT_WARNING, "couldn't load any skill from %s\n", charfile );
    //couldn't load any character
    return 0;
} //end of the function BotLoadCachedCharacter
Beispiel #5
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
int BotLoadCachedCharacter(char *charfile, float skill, int reload)
{
	int handle, cachedhandle, intskill;
#ifdef DEBUG
	int starttime;

	starttime = trap_Milliseconds();
#endif //DEBUG

	//find a free spot for a character
	for (handle = 1; handle < MAX_BOT_CHARACTERS; handle++)
	{
		if (!botcharacters[handle].skill) break;
	} //end for
	if (handle >= MAX_BOT_CHARACTERS) return 0;
	//try to load a cached character with the given skill
	if (!reload)
	{
		cachedhandle = BotFindCachedCharacter(charfile, skill);
		if (cachedhandle)
		{
			BotAI_Print(PRT_DEVELOPER, "loaded cached skill %f from %s\n", skill, charfile);
			return cachedhandle;
		} //end if
	} //end else
	//
	intskill = (int) (skill + 0.5);
	//try to load the character with the given skill
	if (BotLoadCharacterFromFile(charfile, intskill, &botcharacters[handle]))
	{
		//
		BotAI_Print(PRT_DEVELOPER, "loaded skill %d from %s\n", intskill, charfile);
#ifdef DEBUG
		BotAI_Print(PRT_DEVELOPER, "skill %d loaded in %d msec from %s\n", intskill, trap_Milliseconds() - starttime, charfile);
#endif //DEBUG
		return handle;
	} //end if
	//
	BotAI_Print(PRT_WARNING, "couldn't find skill %d in %s\n", intskill, charfile);
	//
	if (!reload)
	{
		//try to load a cached default character with the given skill
		cachedhandle = BotFindCachedCharacter(DEFAULT_CHARACTER, skill);
		if (cachedhandle)
		{
			BotAI_Print(PRT_MESSAGE, "loaded cached default skill %d from %s\n", intskill, charfile);
			return cachedhandle;
		} //end if
	} //end if
	//try to load the default character with the given skill
	if (BotLoadCharacterFromFile(DEFAULT_CHARACTER, intskill, &botcharacters[handle]))
	{
		BotAI_Print(PRT_MESSAGE, "loaded default skill %d from %s\n", intskill, charfile);
		return handle;
	} //end if
	//
	if (!reload)
	{
		//try to load a cached character with any skill
		cachedhandle = BotFindCachedCharacter(charfile, -1);
		if (cachedhandle)
		{
			BotAI_Print(PRT_DEVELOPER, "loaded cached skill %f from %s\n", botcharacters[cachedhandle].skill, charfile);
			return cachedhandle;
		} //end if
	} //end if
	//try to load a character with any skill
	if (BotLoadCharacterFromFile(charfile, -1, &botcharacters[handle]))
	{
		BotAI_Print(PRT_DEVELOPER, "loaded skill %f from %s\n", botcharacters[handle].skill, charfile);
		return handle;
	} //end if
	//
	if (!reload)
	{
		//try to load a cached character with any skill
		cachedhandle = BotFindCachedCharacter(DEFAULT_CHARACTER, -1);
		if (cachedhandle)
		{
			BotAI_Print(PRT_MESSAGE, "loaded cached default skill %f from %s\n", botcharacters[cachedhandle].skill, charfile);
			return cachedhandle;
		} //end if
	} //end if
	//try to load a character with any skill
	if (BotLoadCharacterFromFile(DEFAULT_CHARACTER, -1, &botcharacters[handle]))
	{
		BotAI_Print(PRT_MESSAGE, "loaded default skill %f from %s\n", botcharacters[handle].skill, charfile);
		return handle;
	} //end if
	//
	BotAI_Print(PRT_WARNING, "couldn't load any skill from %s\n", charfile);
	//couldn't load any character
	return 0;
} //end of the function BotLoadCachedCharacter
Beispiel #6
0
int
BotLoadCachedCharacter(char *charfile, float skill, int reload)
{
	int handle, cachedhandle, intskill;
	bot_character_t *ch = NULL;
#ifdef DEBUG
	int starttime;

	starttime = Sys_MilliSeconds();
#endif	/* DEBUG */

	/* find a free spot for a character */
	for(handle = 1; handle <= MAX_CLIENTS; handle++)
		if(!botcharacters[handle]) break;
	if(handle > MAX_CLIENTS) return 0;
	/* try to load a cached character with the given skill */
	if(!reload){
		cachedhandle = BotFindCachedCharacter(charfile, skill);
		if(cachedhandle){
			botimport.Print(PRT_MESSAGE,
				"loaded cached skill %f from %s\n", skill,
				charfile);
			return cachedhandle;
		}
	}
	intskill = (int)(skill + 0.5);
	/* try to load the character with the given skill */
	ch = BotLoadCharacterFromFile(charfile, intskill);
	if(ch){
		botcharacters[handle] = ch;
		botimport.Print(PRT_MESSAGE, "loaded skill %d from %s\n",
			intskill,
			charfile);
#ifdef DEBUG
		if(botDeveloper)
			botimport.Print(PRT_MESSAGE,
				"skill %d loaded in %d msec from %s\n", intskill,
				Sys_MilliSeconds() - starttime, charfile);
#endif	/* DEBUG */
		return handle;
	}
	botimport.Print(PRT_WARNING, "couldn't find skill %d in %s\n", intskill,
		charfile);
	if(!reload){
		/* try to load a cached default character with the given skill */
		cachedhandle = BotFindCachedCharacter(DEFAULT_CHARACTER, skill);
		if(cachedhandle){
			botimport.Print(
				PRT_MESSAGE,
				"loaded cached default skill %d from %s\n",
				intskill, charfile);
			return cachedhandle;
		}
	}
	/* try to load the default character with the given skill */
	ch = BotLoadCharacterFromFile(DEFAULT_CHARACTER, intskill);
	if(ch){
		botcharacters[handle] = ch;
		botimport.Print(PRT_MESSAGE, "loaded default skill %d from %s\n",
			intskill,
			charfile);
		return handle;
	}
	if(!reload){
		/* try to load a cached character with any skill */
		cachedhandle = BotFindCachedCharacter(charfile, -1);
		if(cachedhandle){
			botimport.Print(PRT_MESSAGE,
				"loaded cached skill %f from %s\n",
				botcharacters[cachedhandle]->skill,
				charfile);
			return cachedhandle;
		}
	}
	/* try to load a character with any skill */
	ch = BotLoadCharacterFromFile(charfile, -1);
	if(ch){
		botcharacters[handle] = ch;
		botimport.Print(PRT_MESSAGE, "loaded skill %f from %s\n",
			ch->skill,
			charfile);
		return handle;
	}
	if(!reload){
		/* try to load a cached character with any skill */
		cachedhandle = BotFindCachedCharacter(DEFAULT_CHARACTER, -1);
		if(cachedhandle){
			botimport.Print(
				PRT_MESSAGE,
				"loaded cached default skill %f from %s\n",
				botcharacters[cachedhandle]->skill, charfile);
			return cachedhandle;
		}
	}
	/* try to load a character with any skill */
	ch = BotLoadCharacterFromFile(DEFAULT_CHARACTER, -1);
	if(ch){
		botcharacters[handle] = ch;
		botimport.Print(PRT_MESSAGE, "loaded default skill %f from %s\n",
			ch->skill,
			charfile);
		return handle;
	}
	botimport.Print(PRT_WARNING, "couldn't load any skill from %s\n",
		charfile);
	/* couldn't load any character */
	return 0;
}