Beispiel #1
0
int BotSetupGoalAI( bool singleplayer ) {
	if ( GGameType & GAME_ET ) {
		g_singleplayer = singleplayer;
	} else {
		//check if teamplay is on
		g_gametype = LibVarValue( "g_gametype", "0" );
	}
	//item configuration file
	const char* filename = LibVarString( "itemconfig", "items.c" );
	if ( GGameType & GAME_ET ) {
		PS_SetBaseFolder( BOTFILESBASEFOLDER );
	}
	//load the item configuration
	itemconfig = LoadItemConfig( filename );
	if ( GGameType & GAME_ET ) {
		PS_SetBaseFolder( "" );
	}
	if ( !itemconfig ) {
		BotImport_Print( PRT_FATAL, "couldn't load item config\n" );
		return GGameType & GAME_Quake3 ? Q3BLERR_CANNOTLOADITEMCONFIG : WOLFBLERR_CANNOTLOADITEMCONFIG;
	}

	if ( GGameType & GAME_Quake3 ) {
		droppedweight = LibVar( "droppedweight", "1000" );
	}
	//everything went ok
	return BLERR_NOERROR;
}
Beispiel #2
0
int BotLoadItemWeights( int goalstate, const char* filename ) {
	bot_goalstate_t* gs = BotGoalStateFromHandle( goalstate );
	if ( !gs ) {
		return GGameType & GAME_Quake3 ? Q3BLERR_CANNOTLOADITEMWEIGHTS : WOLFBLERR_CANNOTLOADITEMWEIGHTS;
	}
	//load the weight configuration
	if ( GGameType & GAME_ET ) {
		PS_SetBaseFolder( BOTFILESBASEFOLDER );
	}
	gs->itemweightconfig = ReadWeightConfig( filename );
	if ( GGameType & GAME_ET ) {
		PS_SetBaseFolder( "" );
	}
	if ( !gs->itemweightconfig ) {
		BotImport_Print( PRT_FATAL, "couldn't load weights\n" );
		return GGameType & GAME_Quake3 ? Q3BLERR_CANNOTLOADITEMWEIGHTS : WOLFBLERR_CANNOTLOADITEMWEIGHTS;
	}
	//if there's no item configuration
	if ( !itemconfig ) {
		return GGameType & GAME_Quake3 ? Q3BLERR_CANNOTLOADITEMWEIGHTS : WOLFBLERR_CANNOTLOADITEMWEIGHTS;
	}
	//create the item weight index
	gs->itemweightindex = ItemWeightIndex( gs->itemweightconfig, itemconfig );
	//everything went ok
	return BLERR_NOERROR;
}
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
int BotSetupWeaponAI( void ) {
	char *file;

	PS_SetBaseFolder( "botfiles" );
	file = LibVarString( "weaponconfig", "weapons.c" );
	weaponconfig = LoadWeaponConfig( file );
	PS_SetBaseFolder( "" );
	if ( !weaponconfig ) {
		botimport.Print( PRT_FATAL, "couldn't load the weapon config\n" );
		return BLERR_CANNOTLOADWEAPONCONFIG;
	} //end if

#ifdef DEBUG_AI_WEAP
	DumpWeaponConfig( weaponconfig );
#endif //DEBUG_AI_WEAP
	   //
	return BLERR_NOERROR;
} //end of the function BotSetupWeaponAI
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
int BotLoadWeaponWeights( int weaponstate, char *filename ) {
	bot_weaponstate_t *ws;

	ws = BotWeaponStateFromHandle( weaponstate );
	if ( !ws ) {
		return BLERR_CANNOTLOADWEAPONWEIGHTS;
	}
	BotFreeWeaponWeights( weaponstate );
	//
	PS_SetBaseFolder( "botfiles" );
	ws->weaponweightconfig = ReadWeightConfig( filename );
	PS_SetBaseFolder( "" );
	if ( !ws->weaponweightconfig ) {
		botimport.Print( PRT_FATAL, "couldn't load weapon config %s\n", filename );
		return BLERR_CANNOTLOADWEAPONWEIGHTS;
	} //end if
	if ( !weaponconfig ) {
		return BLERR_CANNOTLOADWEAPONCONFIG;
	}
	ws->weaponweightindex = WeaponWeightIndex( ws->weaponweightconfig, weaponconfig );
	return BLERR_NOERROR;
} //end of the function BotLoadWeaponWeights
Beispiel #5
0
//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
bot_character_t *BotLoadCharacterFromFile( char *charfile, int skill )
{
    int             indent, index, foundcharacter;
    bot_character_t *ch;
    source_t        *source;
    token_t         token;

    foundcharacter = qfalse;
    //a bot character is parsed in two phases
    PS_SetBaseFolder( "botfiles" );
    source = LoadSourceFile( charfile );
    PS_SetBaseFolder( "" );

    if ( !source )
    {
        botimport.Print( PRT_ERROR, "counldn't load %s\n", charfile );
        return NULL;
    } //end if

    ch = ( bot_character_t * ) GetClearedMemory( sizeof( bot_character_t ) + MAX_CHARACTERISTICS * sizeof( bot_characteristic_t ) );
    strcpy( ch->filename, charfile );

    while ( PC_ReadToken( source, &token ) )
    {
        if ( !strcmp( token.string, "skill" ) )
        {
            if ( !PC_ExpectTokenType( source, TT_NUMBER, 0, &token ) )
            {
                FreeSource( source );
                BotFreeCharacterStrings( ch );
                FreeMemory( ch );
                return NULL;
            } //end if

            if ( !PC_ExpectTokenString( source, "{" ) )
            {
                FreeSource( source );
                BotFreeCharacterStrings( ch );
                FreeMemory( ch );
                return NULL;
            } //end if

            //if it's the correct skill
            if ( skill < 0 || token.intvalue == skill )
            {
                foundcharacter = qtrue;
                ch->skill = token.intvalue;

                while ( PC_ExpectAnyToken( source, &token ) )
                {
                    if ( !strcmp( token.string, "}" ) )
                    {
                        break;
                    }

                    if ( token.type != TT_NUMBER || !( token.subtype & TT_INTEGER ) )
                    {
                        SourceError( source, "expected integer index, found %s\n", token.string );
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    index = token.intvalue;

                    if ( index < 0 || index > MAX_CHARACTERISTICS )
                    {
                        SourceError( source, "characteristic index out of range [0, %d]\n", MAX_CHARACTERISTICS );
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    if ( ch->c[ index ].type )
                    {
                        SourceError( source, "characteristic %d already initialized\n", index );
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    if ( !PC_ExpectAnyToken( source, &token ) )
                    {
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    if ( token.type == TT_NUMBER )
                    {
                        if ( token.subtype & TT_FLOAT )
                        {
                            ch->c[ index ].value._float = token.floatvalue;
                            ch->c[ index ].type = CT_FLOAT;
                        } //end if
                        else
                        {
                            ch->c[ index ].value.integer = token.intvalue;
                            ch->c[ index ].type = CT_INTEGER;
                        } //end else
                    } //end if
                    else if ( token.type == TT_STRING )
                    {
                        StripDoubleQuotes( token.string );
                        ch->c[ index ].value.string = GetMemory( strlen( token.string ) + 1 );
                        strcpy( ch->c[ index ].value.string, token.string );
                        ch->c[ index ].type = CT_STRING;
                    } //end else if
                    else
                    {
                        SourceError( source, "expected integer, float or string, found %s\n", token.string );
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end else
                } //end if

                break;
            } //end if
            else
            {
                indent = 1;

                while ( indent )
                {
                    if ( !PC_ExpectAnyToken( source, &token ) )
                    {
                        FreeSource( source );
                        BotFreeCharacterStrings( ch );
                        FreeMemory( ch );
                        return NULL;
                    } //end if

                    if ( !strcmp( token.string, "{" ) )
                    {
                        indent++;
                    }
                    else if ( !strcmp( token.string, "}" ) )
                    {
                        indent--;
                    }
                } //end while
            } //end else
        } //end if
        else
        {
            SourceError( source, "unknown definition %s\n", token.string );
            FreeSource( source );
            BotFreeCharacterStrings( ch );
            FreeMemory( ch );
            return NULL;
        } //end else
    } //end while

    FreeSource( source );

    //
    if ( !foundcharacter )
    {
        BotFreeCharacterStrings( ch );
        FreeMemory( ch );
        return NULL;
    } //end if

    return ch;
} //end of the function BotLoadCharacterFromFile