G
GrispernMix
bool variant_t::Convert( fieldtype_t newType )
{
if ( newType == fieldType )
{
return true;
}
//
// Converting to a null value is easy.
//
if ( newType == FIELD_VOID )
{
Set( FIELD_VOID, NULL );
return true;
}
//
// FIELD_INPUT accepts the variant type directly.
//
if ( newType == FIELD_INPUT )
{
return true;
}
switch ( fieldType )
{
case FIELD_INTEGER:
{
switch ( newType )
{
case FIELD_FLOAT:
{
SetFloat( (float) iVal );
return true;
}
case FIELD_BOOLEAN:
{
SetBool( iVal != 0 );
return true;
}
}
break;
}
case FIELD_FLOAT:
{
switch ( newType )
{
case FIELD_INTEGER:
{
SetInt( (int) flVal );
return true;
}
case FIELD_BOOLEAN:
{
SetBool( flVal != 0 );
return true;
}
}
break;
}
//
// Everyone must convert from FIELD_STRING if possible, since
// parameter overrides are always passed as strings.
//
case FIELD_STRING:
{
switch ( newType )
{
case FIELD_INTEGER:
{
if (iszVal != NULL_STRING)
{
SetInt(atoi(STRING(iszVal)));
}
else
{
SetInt(0);
}
return true;
}
case FIELD_FLOAT:
{
if (iszVal != NULL_STRING)
{
SetFloat(atof(STRING(iszVal)));
}
else
{
SetFloat(0);
}
return true;
}
case FIELD_BOOLEAN:
{
if (iszVal != NULL_STRING)
{
SetBool( atoi(STRING(iszVal)) != 0 );
}
else
{
SetBool(false);
}
return true;
}
case FIELD_VECTOR:
{
Vector tmpVec = vec3_origin;
if (sscanf(STRING(iszVal), "[%f %f %f]", &tmpVec[0], &tmpVec[1],
&tmpVec[2]) == 0)
{
// Try sucking out 3 floats with no []s
sscanf(STRING(iszVal), "%f %f %f", &tmpVec[0], &tmpVec[1],
&tmpVec[2]);
}
SetVector3D( tmpVec );
return true;
}
case FIELD_COLOR32:
{
int nRed = 0;
int nGreen = 0;
int nBlue = 0;
int nAlpha = 255;
problem-> sscanf(STRING(iszVal), "%d %d %d %d", &nRed, &nGreen, &nBlue,
&nAlpha);
SetColor32( nRed, nGreen, nBlue, nAlpha );
return true;
}
case FIELD_EHANDLE:
{
// convert the string to an entity by locating it by classname
CBaseEntity *ent = NULL;
if ( iszVal != NULL_STRING )
{
// FIXME: do we need to pass an activator in here?
ent = gEntList.FindEntityByName( NULL, iszVal, NULL );
}
SetEntity( ent );
return true;
}
}
break;
}
case FIELD_EHANDLE:
{
switch ( newType )
{
case FIELD_STRING:
{
// take the entities targetname as the string
string_t iszStr = NULL_STRING;
if ( eVal != NULL )
{
SetString( eVal->GetEntityName() );
}
return true;
}
}
break;
}
}
// invalid conversion
return false;
}
Can anyone tell me a good reason why i might be getting a sscanf
identifier not found error other than stdio.h missing
- it doesnt appear to be a syntax error
-
{
if ( newType == fieldType )
{
return true;
}
//
// Converting to a null value is easy.
//
if ( newType == FIELD_VOID )
{
Set( FIELD_VOID, NULL );
return true;
}
//
// FIELD_INPUT accepts the variant type directly.
//
if ( newType == FIELD_INPUT )
{
return true;
}
switch ( fieldType )
{
case FIELD_INTEGER:
{
switch ( newType )
{
case FIELD_FLOAT:
{
SetFloat( (float) iVal );
return true;
}
case FIELD_BOOLEAN:
{
SetBool( iVal != 0 );
return true;
}
}
break;
}
case FIELD_FLOAT:
{
switch ( newType )
{
case FIELD_INTEGER:
{
SetInt( (int) flVal );
return true;
}
case FIELD_BOOLEAN:
{
SetBool( flVal != 0 );
return true;
}
}
break;
}
//
// Everyone must convert from FIELD_STRING if possible, since
// parameter overrides are always passed as strings.
//
case FIELD_STRING:
{
switch ( newType )
{
case FIELD_INTEGER:
{
if (iszVal != NULL_STRING)
{
SetInt(atoi(STRING(iszVal)));
}
else
{
SetInt(0);
}
return true;
}
case FIELD_FLOAT:
{
if (iszVal != NULL_STRING)
{
SetFloat(atof(STRING(iszVal)));
}
else
{
SetFloat(0);
}
return true;
}
case FIELD_BOOLEAN:
{
if (iszVal != NULL_STRING)
{
SetBool( atoi(STRING(iszVal)) != 0 );
}
else
{
SetBool(false);
}
return true;
}
case FIELD_VECTOR:
{
Vector tmpVec = vec3_origin;
if (sscanf(STRING(iszVal), "[%f %f %f]", &tmpVec[0], &tmpVec[1],
&tmpVec[2]) == 0)
{
// Try sucking out 3 floats with no []s
sscanf(STRING(iszVal), "%f %f %f", &tmpVec[0], &tmpVec[1],
&tmpVec[2]);
}
SetVector3D( tmpVec );
return true;
}
case FIELD_COLOR32:
{
int nRed = 0;
int nGreen = 0;
int nBlue = 0;
int nAlpha = 255;
problem-> sscanf(STRING(iszVal), "%d %d %d %d", &nRed, &nGreen, &nBlue,
&nAlpha);
SetColor32( nRed, nGreen, nBlue, nAlpha );
return true;
}
case FIELD_EHANDLE:
{
// convert the string to an entity by locating it by classname
CBaseEntity *ent = NULL;
if ( iszVal != NULL_STRING )
{
// FIXME: do we need to pass an activator in here?
ent = gEntList.FindEntityByName( NULL, iszVal, NULL );
}
SetEntity( ent );
return true;
}
}
break;
}
case FIELD_EHANDLE:
{
switch ( newType )
{
case FIELD_STRING:
{
// take the entities targetname as the string
string_t iszStr = NULL_STRING;
if ( eVal != NULL )
{
SetString( eVal->GetEntityName() );
}
return true;
}
}
break;
}
}
// invalid conversion
return false;
}
Can anyone tell me a good reason why i might be getting a sscanf
identifier not found error other than stdio.h missing
- it doesnt appear to be a syntax error
-