📄 scriptvariable.cpp
字号:
}
EXPORT_FROM_DLL ScriptVariable *ScriptVariableList::GetVariable
(
int num
)
{
return list.ObjectAt( num );
}
EXPORT_FROM_DLL ScriptVariable *ScriptVariableList::SetVariable
(
const char *name,
float value
)
{
ScriptVariable *var;
var = GetVariable( name );
if ( !var )
{
var = new ScriptVariable;
var->setName( name );
list.AddObject( var );
}
var->setFloatValue( value );
return var;
}
EXPORT_FROM_DLL ScriptVariable *ScriptVariableList::SetVariable
(
const char *name,
int value
)
{
ScriptVariable *var;
var = GetVariable( name );
if ( !var )
{
var = new ScriptVariable;
var->setName( name );
list.AddObject( var );
}
var->setIntValue( value );
return var;
}
EXPORT_FROM_DLL ScriptVariable *ScriptVariableList::SetVariable
(
const char *name,
const char *text
)
{
ScriptVariable *var;
var = GetVariable( name );
if ( !var )
{
var = new ScriptVariable;
var->setName( name );
list.AddObject( var );
}
var->setStringValue( text );
return var;
}
EXPORT_FROM_DLL ScriptVariable *ScriptVariableList::SetVariable
(
const char *name,
Entity *ent
)
{
ScriptVariable *var;
var = GetVariable( name );
if ( !var )
{
var = new ScriptVariable;
var->setName( name );
list.AddObject( var );
}
if ( !ent )
{
// use the world
var->setStringValue( "*0" );
}
else
{
var->setStringValue( va( "*%d", ent->entnum ) );
}
return var;
}
EXPORT_FROM_DLL ScriptVariable *ScriptVariableList::SetVariable
(
const char *name,
Vector &vec
)
{
ScriptVariable *var;
var = GetVariable( name );
if ( !var )
{
var = new ScriptVariable;
var->setName( name );
list.AddObject( var );
}
var->setStringValue( va( "(%f %f %f)", vec.x, vec.y, vec.z) );
return var;
}
//****************************************************************************************
//
// Variable commands
//
//****************************************************************************************
void ScriptVariable::Var_Append
(
Event *ev
)
{
str newstring;
newstring = string + ev->GetString( 1 );
setStringValue( newstring.c_str() );
}
void ScriptVariable::Var_AppendInt
(
Event *ev
)
{
str newstring;
newstring = string + va( "%d", ev->GetInteger( 1 ) );
setStringValue( newstring.c_str() );
}
void ScriptVariable::Var_AppendFloat
(
Event *ev
)
{
str newstring;
newstring = string + va( "%f", ev->GetFloat( 1 ) );
setStringValue( newstring.c_str() );
}
void ScriptVariable::Var_String
(
Event *ev
)
{
setStringValue( ev->GetString( 1 ) );
}
void ScriptVariable::Var_ConInput
(
Event *ev
)
{
str varname;
ScriptVariable *var;
varname = str( "console." ) + ev->GetString( 1 );
var = Director.GetExistingVariable( varname.c_str() );
if ( !var )
{
warning( "Var_ConInput", "Variable %s does not exist yet.\n", varname.c_str() );
return;
}
setStringValue( var->stringValue() );
}
void ScriptVariable::Var_RandomFloat
(
Event *ev
)
{
setFloatValue( G_Random( ev->GetFloat( 1 ) ) );
}
void ScriptVariable::Var_RandomInteger
(
Event *ev
)
{
setIntValue( G_Random( ev->GetInteger( 1 ) ) );
}
void ScriptVariable::Var_Equals
(
Event *ev
)
{
setFloatValue( ev->GetFloat( 1 ) );
}
void ScriptVariable::Var_PlusEquals
(
Event *ev
)
{
setFloatValue( floatValue() + ev->GetFloat( 1 ) );
}
void ScriptVariable::Var_MinusEquals
(
Event *ev
)
{
setFloatValue( floatValue() - ev->GetFloat( 1 ) );
}
void ScriptVariable::Var_TimesEquals
(
Event *ev
)
{
setFloatValue( floatValue() * ev->GetFloat( 1 ) );
}
void ScriptVariable::Var_DivideEquals
(
Event *ev
)
{
setFloatValue( floatValue() / ev->GetFloat( 1 ) );
}
void ScriptVariable::Var_Div
(
Event *ev
)
{
setIntValue( floatValue() / ev->GetInteger( 1 ) );
}
void ScriptVariable::Var_Mod
(
Event *ev
)
{
setIntValue( intValue() % ev->GetInteger( 1 ) );
}
void ScriptVariable::Var_IfEqual
(
Event *ev
)
{
if ( floatValue() == ev->GetFloat( 1 ) )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_IfNotEqual
(
Event *ev
)
{
if ( floatValue() != ev->GetFloat( 1 ) )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_IfGreater
(
Event *ev
)
{
if ( floatValue() > ev->GetFloat( 1 ) )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_IfGreaterEqual
(
Event *ev
)
{
if ( floatValue() >= ev->GetFloat( 1 ) )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_IfLess
(
Event *ev
)
{
if ( floatValue() < ev->GetFloat( 1 ) )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_IfLessEqual
(
Event *ev
)
{
if ( floatValue() <= ev->GetFloat( 1 ) )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_IfStrEqual
(
Event *ev
)
{
if ( stricmp( stringValue(), ev->GetString( 1 ) ) == 0 )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_IfStrNotEqual
(
Event *ev
)
{
if ( stricmp( stringValue(), ev->GetString( 1 ) ) != 0 )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_IfThreadActive
(
Event *ev
)
{
ScriptThread *thread;
thread = Director.GetThread( intValue() );
if ( thread )
{
VarProcessCommand( ev, 1 );
}
}
void ScriptVariable::Var_IfThreadNotActive
(
Event *ev
)
{
ScriptThread *thread;
thread = Director.GetThread( intValue() );
if ( !thread )
{
VarProcessCommand( ev, 1 );
}
}
void ScriptVariable::Var_GetCvar
(
Event *ev
)
{
cvar_t *var;
var = gi.cvar( ev->GetString( 1 ), "", 0 );
setStringValue( var->string );
}
void ScriptVariable::Var_Vector
(
Event *ev
)
{
setVectorValue( ev->GetVector( 1 ) );
}
void ScriptVariable::Var_Vector_Add
(
Event *ev
)
{
Vector tempvec;
tempvec = vectorValue();
tempvec += ev->GetVector( 1 );
setVectorValue( tempvec );
}
void ScriptVariable::Var_Vector_Subtract
(
Event *ev
)
{
Vector tempvec;
tempvec = vectorValue();
tempvec -= ev->GetVector( 1 );
setVectorValue( tempvec );
}
void ScriptVariable::Var_Vector_Scale
(
Event *ev
)
{
Vector tempvec;
tempvec = vectorValue();
tempvec = tempvec * ev->GetFloat( 1 );
setVectorValue( tempvec );
}
void ScriptVariable::Var_Vector_Normalize
(
Event *ev
)
{
setVectorValue( vectorValue().normalize() );
}
void ScriptVariable::Var_Vector_GetX
(
Event *ev
)
{
setFloatValue( ev->GetVector( 1 ).x );
}
void ScriptVariable::Var_Vector_GetY
(
Event *ev
)
{
setFloatValue( ev->GetVector( 1 ).y );
}
void ScriptVariable::Var_Vector_GetZ
(
Event *ev
)
{
setFloatValue( ev->GetVector( 1 ).z );
}
void ScriptVariable::Var_Vector_SetX
(
Event *ev
)
{
Vector tempvec;
tempvec = vectorValue();
tempvec.x = ev->GetFloat( 1 );
setVectorValue( tempvec );
}
void ScriptVariable::Var_Vector_SetY
(
Event *ev
)
{
Vector tempvec;
tempvec = vectorValue();
tempvec.y = ev->GetFloat( 1 );
setVectorValue( tempvec );
}
void ScriptVariable::Var_Vector_SetZ
(
Event *ev
)
{
Vector tempvec;
tempvec = vectorValue();
tempvec.z = ev->GetFloat( 1 );
setVectorValue( tempvec );
}
void ScriptVariable::Var_Vector_IfEqual
(
Event *ev
)
{
if ( vectorValue() == ev->GetVector( 1 ) )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_Vector_IfNotEqual
(
Event *ev
)
{
if ( vectorValue() != ev->GetVector( 1 ) )
{
VarProcessCommand( ev, 2 );
}
}
void ScriptVariable::Var_Vector_DotProduct
(
Event *ev
)
{
Vector vec1, vec2;
vec1 = ev->GetVector( 1 );
vec2 = ev->GetVector( 2 );
setFloatValue( vec1 * vec2 );
}
void ScriptVariable::Var_Vector_Length
(
Event *ev
)
{
setFloatValue( ev->GetVector( 1 ).length() );
}
void ScriptVariable::Var_Vector_CrossProduct
(
Event *ev
)
{
Vector vec1, vec2, cross;
vec1 = ev->GetVector( 1 );
vec2 = ev->GetVector( 2 );
cross.CrossProduct( vec1, vec2 );
setVectorValue( cross );
}
void ScriptVariable::Var_Angles_ToForward
(
Event *ev
)
{
Vector forward;
ev->GetVector( 1 ).AngleVectors( &forward, NULL, NULL );
setVectorValue( forward );
}
void ScriptVariable::Var_Angles_ToRight
(
Event *ev
)
{
Vector right;
ev->GetVector( 1 ).AngleVectors( NULL, &right, NULL );
setVectorValue( right );
}
void ScriptVariable::Var_Angles_ToUp
(
Event *ev
)
{
Vector up;
ev->GetVector( 1 ).AngleVectors( NULL, NULL, &up );
setVectorValue( up );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -