當前位置: 首頁>>代碼示例>>C++>>正文


C++ BotCharacterFromHandle函數代碼示例

本文整理匯總了C++中BotCharacterFromHandle函數的典型用法代碼示例。如果您正苦於以下問題:C++ BotCharacterFromHandle函數的具體用法?C++ BotCharacterFromHandle怎麽用?C++ BotCharacterFromHandle使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了BotCharacterFromHandle函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: BotInterpolateCharacters

//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
int BotInterpolateCharacters( int handle1, int handle2, int desiredskill )
{
    bot_character_t *ch1, *ch2, *out;
    int             i, handle;
    float           scale;

    ch1 = BotCharacterFromHandle( handle1 );
    ch2 = BotCharacterFromHandle( handle2 );

    if ( !ch1 || !ch2 )
    {
        return 0;
    }

    //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;
    }

    out = ( bot_character_t * ) GetClearedMemory( sizeof( bot_character_t ) + MAX_CHARACTERISTICS * sizeof( bot_characteristic_t ) );
    out->skill = desiredskill;
    strcpy( out->filename, ch1->filename );
    botcharacters[ handle ] = out;

    scale = ( float )( desiredskill - 1 ) / ( ch2->skill - ch1->skill );

    for ( i = 0; i < MAX_CHARACTERISTICS; i++ )
    {
        //
        if ( ch1->c[ i ].type == CT_FLOAT && ch2->c[ i ].type == CT_FLOAT )
        {
            out->c[ i ].type = CT_FLOAT;
            out->c[ i ].value._float = ch1->c[ i ].value._float + ( ch2->c[ i ].value._float - ch1->c[ i ].value._float ) * scale;
        } //end if
        else if ( ch1->c[ i ].type == CT_INTEGER )
        {
            out->c[ i ].type = CT_INTEGER;
            out->c[ i ].value.integer = ch1->c[ i ].value.integer;
        } //end else if
        else if ( ch1->c[ i ].type == CT_STRING )
        {
            out->c[ i ].type = CT_STRING;
            out->c[ i ].value.string = ( char * ) GetMemory( strlen( ch1->c[ i ].value.string ) + 1 );
            strcpy( out->c[ i ].value.string, ch1->c[ i ].value.string );
        } //end else if
    } //end for

    return handle;
} //end of the function BotInterpolateCharacters
開發者ID:gfx0,項目名稱:Unvanquished,代碼行數:64,代碼來源:be_ai_char.c

示例2: Characteristic_String

//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
void Characteristic_String( int character, int index, char *buf, int size )
{
    bot_character_t *ch;

    ch = BotCharacterFromHandle( character );

    if ( !ch )
    {
        return;
    }

    //check if the index is in range
    if ( !CheckCharacteristicIndex( character, index ) )
    {
        return;
    }

    //an integer will be converted to a float
    if ( ch->c[ index ].type == CT_STRING )
    {
        strncpy( buf, ch->c[ index ].value.string, size - 1 );
        buf[ size - 1 ] = '\0';
        return;
    } //end if
    else
    {
        botimport.Print( PRT_ERROR, "characteristic %d is not a string\n", index );
        return;
    } //end else if

    return;
} //end of the function Characteristic_String
開發者ID:gfx0,項目名稱:Unvanquished,代碼行數:38,代碼來源:be_ai_char.c

示例3: Characteristic_BInteger

//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
int Characteristic_BInteger( int character, int index, int min, int max )
{
    int             value;
    bot_character_t *ch;

    ch = BotCharacterFromHandle( character );

    if ( !ch )
    {
        return 0;
    }

    if ( min > max )
    {
        botimport.Print( PRT_ERROR, "cannot bound characteristic %d between %d and %d\n", index, min, max );
        return 0;
    } //end if

    value = Characteristic_Integer( character, index );

    if ( value < min )
    {
        return min;
    }

    if ( value > max )
    {
        return max;
    }

    return value;
} //end of the function Characteristic_BInteger
開發者ID:gfx0,項目名稱:Unvanquished,代碼行數:38,代碼來源:be_ai_char.c

示例4: Characteristic_Integer

//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
int Characteristic_Integer( int character, int index )
{
    bot_character_t *ch;

    ch = BotCharacterFromHandle( character );

    if ( !ch )
    {
        return 0;
    }

    //check if the index is in range
    if ( !CheckCharacteristicIndex( character, index ) )
    {
        return 0;
    }

    //an integer will just be returned
    if ( ch->c[ index ].type == CT_INTEGER )
    {
        return ch->c[ index ].value.integer;
    } //end if
    //floats are casted to integers
    else if ( ch->c[ index ].type == CT_FLOAT )
    {
        return ( int ) ch->c[ index ].value._float;
    } //end else if
    else
    {
        botimport.Print( PRT_ERROR, "characteristic %d is not a integer\n", index );
        return 0;
    } //end else if

//  return 0;
} //end of the function Characteristic_Integer
開發者ID:gfx0,項目名稱:Unvanquished,代碼行數:41,代碼來源:be_ai_char.c

示例5: CheckCharacteristicIndex

//===========================================================================
//
// Parameter:           -
// Returns:             -
// Changes Globals:     -
//===========================================================================
int CheckCharacteristicIndex( int character, int index )
{
    bot_character_t *ch;

    ch = BotCharacterFromHandle( character );

    if ( !ch )
    {
        return qfalse;
    }

    if ( index < 0 || index >= MAX_CHARACTERISTICS )
    {
        botimport.Print( PRT_ERROR, "characteristic %d does not exist\n", index );
        return qfalse;
    } //end if

    if ( !ch->c[ index ].type )
    {
        botimport.Print( PRT_ERROR, "characteristic %d is not initialized\n", index );
        return qfalse;
    } //end if

    return qtrue;
} //end of the function CheckCharacteristicIndex
開發者ID:gfx0,項目名稱:Unvanquished,代碼行數:31,代碼來源:be_ai_char.c

示例6: Characteristic_Float

//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
float Characteristic_Float(int character, int index)
{
	bot_character_t *ch;

	ch = BotCharacterFromHandle(character);
	if (!ch) return 0;
	//check if the index is in range
	if (!CheckCharacteristicIndex(character, index)) return 0;
	//an integer will be converted to a float
	if (ch->c[index].type == CT_INTEGER)
	{
		return (float) ch->c[index].value.integer;
	} //end if
	//floats are just returned
	else if (ch->c[index].type == CT_FLOAT)
	{
		return ch->c[index].value._float;
	} //end else if
	//cannot convert a string pointer to a float
	else
	{
		botimport.Print(PRT_ERROR, "characteristic %d is not a float\n", index);
		return 0;
	} //end else if
//	return 0;
} //end of the function Characteristic_Float
開發者ID:ensiform,項目名稱:q3pp,代碼行數:32,代碼來源:be_ai_char.cpp

示例7: BotInterpolateCharacters

//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
int BotInterpolateCharacters(int handle1, int handle2, float desiredskill)
{
	bot_character_t *ch1, *ch2, *out;
	int i, handle;
	float scale;

	ch1 = BotCharacterFromHandle(handle1);
	ch2 = BotCharacterFromHandle(handle2);
	if (!ch1 || !ch2)
		return 0;
	//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;
	out = &botcharacters[handle];
	out->skill = desiredskill;
	strcpy(out->filename, ch1->filename);

	scale = (float) (desiredskill - ch1->skill) / (ch2->skill - ch1->skill);
	for (i = 0; i < MAX_CHARACTERISTICS; i++)
	{
		//
		if (ch1->c[i].type == CT_FLOAT && ch2->c[i].type == CT_FLOAT)
		{
			out->c[i].type = CT_FLOAT;
			out->c[i].value._float = ch1->c[i].value._float +
								(ch2->c[i].value._float - ch1->c[i].value._float) * scale;
		} //end if
		else if (ch1->c[i].type == CT_INTEGER)
		{
			out->c[i].type = CT_INTEGER;
			out->c[i].value.integer = ch1->c[i].value.integer;
		} //end else if
		else if (ch1->c[i].type == CT_STRING)
		{
			out->c[i].type = CT_STRING;
			out->c[i].value.string = (char *) trap_Alloc(strlen(ch1->c[i].value.string)+1, NULL);
			strcpy(out->c[i].value.string, ch1->c[i].value.string);
		} //end else if
	} //end for
	return handle;
} //end of the function BotInterpolateCharacters
開發者ID:KuehnhammerTobias,項目名稱:ioid3-game,代碼行數:50,代碼來源:ai_char.c

示例8: Characteristic_BFloat

//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
float Characteristic_BFloat(int character, int index, float min, float max)
{
	float value;
	bot_character_t *ch;

	ch = BotCharacterFromHandle(character);
	if (!ch) return 0;
	if (min > max)
	{
		botimport.Print(PRT_ERROR, "cannot bound characteristic %d between %f and %f\n", index, min, max);
		return 0;
	} //end if
	value = Characteristic_Float(character, index);
	if (value < min) return min;
	if (value > max) return max;
	return value;
} //end of the function Characteristic_BFloat
開發者ID:ensiform,項目名稱:q3pp,代碼行數:23,代碼來源:be_ai_char.cpp

示例9: Characteristic_Integer

int
Characteristic_Integer(int character, int index)
{
	bot_character_t *ch;

	ch = BotCharacterFromHandle(character);
	if(!ch) return 0;
	/* check if the index is in range */
	if(!CheckCharacteristicIndex(character, index)) return 0;
	/* an integer will just be returned */
	if(ch->c[index].type == CT_INTEGER)
		return ch->c[index].value.integer;
	/* floats are casted to integers */
	else if(ch->c[index].type == CT_FLOAT)
		return (int)ch->c[index].value._float;

	else{
		botimport.Print(PRT_ERROR,
			"characteristic %d is not a integer\n",
			index);
		return 0;
	}
/*	return 0; */
}
開發者ID:icanhas,項目名稱:yantar,代碼行數:24,代碼來源:be_ai_char.c

示例10: Characteristic_Float

float
Characteristic_Float(int character, int index)
{
	bot_character_t *ch;

	ch = BotCharacterFromHandle(character);
	if(!ch) return 0;
	/* check if the index is in range */
	if(!CheckCharacteristicIndex(character, index)) return 0;
	/* an integer will be converted to a float */
	if(ch->c[index].type == CT_INTEGER)
		return (float)ch->c[index].value.integer;
	/* floats are just returned */
	else if(ch->c[index].type == CT_FLOAT)
		return ch->c[index].value._float;

	/* cannot convert a string pointer to a float */
	else{
		botimport.Print(PRT_ERROR, "characteristic %d is not a float\n",
			index);
		return 0;
	}
/*	return 0; */
}
開發者ID:icanhas,項目名稱:yantar,代碼行數:24,代碼來源:be_ai_char.c


注:本文中的BotCharacterFromHandle函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。