mirror of
https://github.com/celisej567/source-sdk-2013.git
synced 2026-09-23 20:09:45 +03:00
Exposed matrix3x4_t and FireBulletsInfo_t to VScript, expanded available math functions
This commit is contained in:
@@ -1599,6 +1599,27 @@ typedef CTraceFilterSimpleList CBulletsTraceFilter;
|
||||
|
||||
void CBaseEntity::FireBullets( const FireBulletsInfo_t &info )
|
||||
{
|
||||
#if defined(MAPBASE_VSCRIPT) && defined(GAME_DLL)
|
||||
if (m_ScriptScope.IsInitialized())
|
||||
{
|
||||
CFireBulletsInfoAccessor pInfo( const_cast<FireBulletsInfo_t*>(&info) );
|
||||
HSCRIPT hInfo = g_pScriptVM->RegisterInstance( &pInfo );
|
||||
|
||||
g_pScriptVM->SetValue( "info", hInfo );
|
||||
|
||||
ScriptVariant_t functionReturn;
|
||||
if ( CallScriptFunction( "FireBullets", &functionReturn ) )
|
||||
{
|
||||
if (!functionReturn.m_bool)
|
||||
return;
|
||||
}
|
||||
|
||||
g_pScriptVM->RemoveInstance( hInfo );
|
||||
|
||||
g_pScriptVM->ClearValue( "info" );
|
||||
}
|
||||
#endif
|
||||
|
||||
static int tracerCount;
|
||||
trace_t tr;
|
||||
CAmmoDef* pAmmoDef = GetAmmoDef();
|
||||
|
||||
306
sp/src/game/shared/mapbase/vscript_funcs_math.cpp
Normal file
306
sp/src/game/shared/mapbase/vscript_funcs_math.cpp
Normal file
@@ -0,0 +1,306 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Shared VScript math functions.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "cbase.h"
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// matrix3x4_t
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
//
|
||||
// Exposes matrix3x4_t to VScript
|
||||
//
|
||||
class CScriptMatrix3x4
|
||||
{
|
||||
public:
|
||||
CScriptMatrix3x4()
|
||||
{
|
||||
matrix = new matrix3x4_t();
|
||||
m_bFree = true;
|
||||
}
|
||||
|
||||
~CScriptMatrix3x4()
|
||||
{
|
||||
if (m_bFree == true)
|
||||
delete matrix;
|
||||
}
|
||||
|
||||
CScriptMatrix3x4( matrix3x4_t &inmatrix ) { matrix = &inmatrix; }
|
||||
|
||||
matrix3x4_t *GetMatrix() { return matrix; }
|
||||
void SetMatrix( matrix3x4_t &inmatrix ) { matrix = &inmatrix; }
|
||||
|
||||
void Init( const Vector& xAxis, const Vector& yAxis, const Vector& zAxis, const Vector &vecOrigin )
|
||||
{
|
||||
matrix->Init( xAxis, yAxis, zAxis, vecOrigin );
|
||||
}
|
||||
|
||||
private:
|
||||
matrix3x4_t *matrix;
|
||||
bool m_bFree = false;
|
||||
};
|
||||
|
||||
BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptMatrix3x4, "matrix3x4_t", "A 3x4 matrix transform." )
|
||||
|
||||
DEFINE_SCRIPT_CONSTRUCTOR()
|
||||
DEFINE_SCRIPTFUNC( Init, "Creates a matrix where the X axis = forward, the Y axis = left, and the Z axis = up." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
|
||||
inline matrix3x4_t *ToMatrix3x4( HSCRIPT hMat ) { return HScriptToClass<CScriptMatrix3x4>( hMat )->GetMatrix(); }
|
||||
|
||||
HSCRIPT ScriptCreateMatrixInstance( matrix3x4_t &matrix )
|
||||
{
|
||||
CScriptMatrix3x4 *smatrix = new CScriptMatrix3x4( matrix );
|
||||
|
||||
return g_pScriptVM->RegisterInstance( smatrix );
|
||||
}
|
||||
|
||||
void ScriptFreeMatrixInstance( HSCRIPT hMat )
|
||||
{
|
||||
CScriptMatrix3x4 *smatrix = HScriptToClass<CScriptMatrix3x4>( hMat );
|
||||
if (smatrix)
|
||||
{
|
||||
g_pScriptVM->RemoveInstance( hMat );
|
||||
delete smatrix;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ScriptConcatTransforms( HSCRIPT hMat1, HSCRIPT hMat2, HSCRIPT hOut )
|
||||
{
|
||||
if (!hMat1 || !hMat2 || !hOut)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
matrix3x4_t *pMat2 = ToMatrix3x4( hMat2 );
|
||||
matrix3x4_t *pOut = ToMatrix3x4( hOut );
|
||||
|
||||
ConcatTransforms( *pMat1, *pMat2, *pOut );
|
||||
}
|
||||
|
||||
void ScriptMatrixCopy( HSCRIPT hMat1, HSCRIPT hOut )
|
||||
{
|
||||
if (!hMat1 || !hOut)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
matrix3x4_t *pOut = ToMatrix3x4( hOut );
|
||||
|
||||
MatrixCopy( *pMat1, *pOut );
|
||||
}
|
||||
|
||||
void ScriptMatrixInvert( HSCRIPT hMat1, HSCRIPT hOut )
|
||||
{
|
||||
if (!hMat1 || !hOut)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
matrix3x4_t *pOut = ToMatrix3x4( hOut );
|
||||
|
||||
MatrixInvert( *pMat1, *pOut );
|
||||
}
|
||||
|
||||
void ScriptMatricesAreEqual( HSCRIPT hMat1, HSCRIPT hMat2 )
|
||||
{
|
||||
if (!hMat1 || !hMat2)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
matrix3x4_t *pMat2 = ToMatrix3x4( hMat2 );
|
||||
|
||||
MatricesAreEqual( *pMat1, *pMat2 );
|
||||
}
|
||||
|
||||
const Vector& ScriptMatrixGetColumn( HSCRIPT hMat1, int column )
|
||||
{
|
||||
static Vector outvec;
|
||||
outvec.Zero();
|
||||
if (!hMat1)
|
||||
return outvec;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
MatrixGetColumn( *pMat1, column, outvec );
|
||||
return outvec;
|
||||
}
|
||||
|
||||
void ScriptMatrixSetColumn( const Vector& vecset, int column, HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
static Vector outvec;
|
||||
MatrixSetColumn( vecset, column, *pMat1 );
|
||||
}
|
||||
|
||||
void ScriptMatrixAngles( HSCRIPT hMat1, const QAngle& angset, const Vector& vecset )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
MatrixAngles( *pMat1, *const_cast<QAngle*>(&angset), *const_cast<Vector*>(&vecset) );
|
||||
}
|
||||
|
||||
void ScriptAngleMatrix( const QAngle& angset, const Vector& vecset, HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
AngleMatrix( angset, vecset, *pMat1 );
|
||||
}
|
||||
|
||||
void ScriptAngleIMatrix( const QAngle& angset, const Vector& vecset, HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
AngleIMatrix( angset, vecset, *pMat1 );
|
||||
}
|
||||
|
||||
void ScriptSetIdentityMatrix( HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
SetIdentityMatrix( *pMat1 );
|
||||
}
|
||||
|
||||
void ScriptSetScaleMatrix( float x, float y, float z, HSCRIPT hMat1 )
|
||||
{
|
||||
if (!hMat1)
|
||||
return;
|
||||
|
||||
matrix3x4_t *pMat1 = ToMatrix3x4( hMat1 );
|
||||
|
||||
SetScaleMatrix( x, y, z, *pMat1 );
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// Misc. Vector/QAngle functions
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
const Vector& ScriptAngleVectors( const QAngle &angles )
|
||||
{
|
||||
static Vector forward;
|
||||
AngleVectors( angles, &forward );
|
||||
return forward;
|
||||
}
|
||||
|
||||
const QAngle& ScriptVectorAngles( const Vector &forward )
|
||||
{
|
||||
static QAngle angles;
|
||||
VectorAngles( forward, angles );
|
||||
return angles;
|
||||
}
|
||||
|
||||
const Vector& ScriptCalcClosestPointOnAABB( const Vector &mins, const Vector &maxs, const Vector &point )
|
||||
{
|
||||
static Vector outvec;
|
||||
CalcClosestPointOnAABB( mins, maxs, point, outvec );
|
||||
return outvec;
|
||||
}
|
||||
|
||||
const Vector& ScriptCalcClosestPointOnLine( const Vector &point, const Vector &vLineA, const Vector &vLineB )
|
||||
{
|
||||
static Vector outvec;
|
||||
CalcClosestPointOnLine( point, vLineA, vLineB, outvec );
|
||||
return outvec;
|
||||
}
|
||||
|
||||
float ScriptCalcDistanceToLine( const Vector &point, const Vector &vLineA, const Vector &vLineB )
|
||||
{
|
||||
return CalcDistanceToLine( point, vLineA, vLineB );
|
||||
}
|
||||
|
||||
const Vector& ScriptCalcClosestPointOnLineSegment( const Vector &point, const Vector &vLineA, const Vector &vLineB )
|
||||
{
|
||||
static Vector outvec;
|
||||
CalcClosestPointOnLineSegment( point, vLineA, vLineB, outvec );
|
||||
return outvec;
|
||||
}
|
||||
|
||||
float ScriptCalcDistanceToLineSegment( const Vector &point, const Vector &vLineA, const Vector &vLineB )
|
||||
{
|
||||
return CalcDistanceToLineSegment( point, vLineA, vLineB );
|
||||
}
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
const Vector& ScriptPredictedPosition( HSCRIPT hTarget, float flTimeDelta )
|
||||
{
|
||||
static Vector predicted;
|
||||
UTIL_PredictedPosition( ToEnt(hTarget), flTimeDelta, &predicted );
|
||||
return predicted;
|
||||
}
|
||||
#endif
|
||||
|
||||
void RegisterMathScriptFunctions()
|
||||
{
|
||||
ScriptRegisterFunction( g_pScriptVM, RandomFloat, "Generate a random floating point number within a range, inclusive." );
|
||||
ScriptRegisterFunction( g_pScriptVM, RandomInt, "Generate a random integer within a range, inclusive." );
|
||||
|
||||
ScriptRegisterFunction( g_pScriptVM, Approach, "Returns a value which approaches the target value from the input value with the specified speed." );
|
||||
ScriptRegisterFunction( g_pScriptVM, ApproachAngle, "Returns an angle which approaches the target angle from the input angle with the specified speed." );
|
||||
ScriptRegisterFunction( g_pScriptVM, AngleDiff, "Returns the degrees difference between two yaw angles." );
|
||||
ScriptRegisterFunction( g_pScriptVM, AngleDistance, "Returns the distance between two angles." );
|
||||
ScriptRegisterFunction( g_pScriptVM, AngleNormalize, "Clamps an angle to be in between -360 and 360." );
|
||||
ScriptRegisterFunction( g_pScriptVM, AngleNormalizePositive, "Clamps an angle to be in between 0 and 360." );
|
||||
ScriptRegisterFunction( g_pScriptVM, AnglesAreEqual, "Checks if two angles are equal based on a given tolerance value." );
|
||||
|
||||
//
|
||||
// matrix3x4_t
|
||||
//
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptFreeMatrixInstance, "FreeMatrixInstance", "Frees an allocated matrix instance." );
|
||||
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptConcatTransforms, "ConcatTransforms", "Concatenates two transformation matrices into another matrix." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptMatrixCopy, "MatrixCopy", "Copies a matrix to another matrix." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptMatrixInvert, "MatrixInvert", "Inverts a matrix and copies the result to another matrix." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptMatricesAreEqual, "MatricesAreEqual", "Checks if two matrices are equal." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptMatrixGetColumn, "MatrixGetColumn", "Gets the column of a matrix." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptMatrixSetColumn, "MatrixSetColumn", "Sets the column of a matrix." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptMatrixAngles, "MatrixAngles", "Gets the angles and position of a matrix." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptAngleMatrix, "AngleMatrix", "Sets the angles and position of a matrix." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptAngleIMatrix, "AngleIMatrix", "Sets the inverted angles and position of a matrix." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptSetIdentityMatrix, "SetIdentityMatrix", "Turns a matrix into an identity matrix." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptSetScaleMatrix, "SetScaleMatrix", "Scales a matrix." );
|
||||
|
||||
//
|
||||
// Misc. Vector/QAngle functions
|
||||
//
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptAngleVectors, "AngleVectors", "Turns an angle into a direction vector." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptVectorAngles, "VectorAngles", "Turns a direction vector into an angle." );
|
||||
|
||||
ScriptRegisterFunction( g_pScriptVM, CalcSqrDistanceToAABB, "Returns the squared distance to a bounding box." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalcClosestPointOnAABB, "CalcClosestPointOnAABB", "Returns the closest point on a bounding box." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalcDistanceToLine, "CalcDistanceToLine", "Returns the distance to a line." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalcClosestPointOnLine, "CalcClosestPointOnLine", "Returns the closest point on a line." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalcDistanceToLineSegment, "CalcDistanceToLineSegment", "Returns the distance to a line segment." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalcClosestPointOnLineSegment, "CalcClosestPointOnLineSegment", "Returns the closest point on a line segment." );
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptPredictedPosition, "PredictedPosition", "Predicts what an entity's position will be in a given amount of time." );
|
||||
#endif
|
||||
}
|
||||
@@ -353,8 +353,6 @@ BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptConvarLookup, "CConvars", SCRIPT_SINGLETON "
|
||||
END_SCRIPTDESC();
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
extern ConVar sv_script_think_interval;
|
||||
|
||||
void AddThinkToEnt( HSCRIPT entity, const char *pszFuncName )
|
||||
{
|
||||
CBaseEntity *pEntity = ToEnt( entity );
|
||||
@@ -366,7 +364,7 @@ void AddThinkToEnt( HSCRIPT entity, const char *pszFuncName )
|
||||
else
|
||||
pEntity->m_iszScriptThinkFunction = AllocPooledString(pszFuncName);
|
||||
|
||||
pEntity->SetContextThink( &CBaseEntity::ScriptThink, gpGlobals->curtime + sv_script_think_interval.GetFloat(), "ScriptThink" );
|
||||
pEntity->SetContextThink( &CBaseEntity::ScriptThink, gpGlobals->curtime, "ScriptThink" );
|
||||
}
|
||||
|
||||
HSCRIPT EntIndexToHScript( int index )
|
||||
@@ -436,6 +434,7 @@ HSCRIPT SpawnEntityFromTable( const char *pszClassname, HSCRIPT hKV )
|
||||
ParseScriptTableKeyValues( pEntity, hKV );
|
||||
|
||||
DispatchSpawn( pEntity );
|
||||
pEntity->Activate();
|
||||
|
||||
return ToHScript( pEntity );
|
||||
}
|
||||
@@ -486,6 +485,7 @@ HSCRIPT SpawnEntityFromKeyValues( const char *pszClassname, HSCRIPT hKV )
|
||||
}
|
||||
|
||||
DispatchSpawn( pEntity );
|
||||
pEntity->Activate();
|
||||
|
||||
return ToHScript( pEntity );
|
||||
}
|
||||
@@ -634,8 +634,131 @@ static HSCRIPT ScriptTraceHullComplex( const Vector &vecStart, const Vector &vec
|
||||
return hScript;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
BEGIN_SCRIPTDESC_ROOT_NAMED( CFireBulletsInfoAccessor, "FireBulletsInfo_t", "Handle for accessing FireBulletsInfo_t info." )
|
||||
DEFINE_SCRIPTFUNC( GetShots, "Gets the number of shots which should be fired." )
|
||||
DEFINE_SCRIPTFUNC( SetShots, "Sets the number of shots which should be fired." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetSource, "Gets the source of the bullets." )
|
||||
DEFINE_SCRIPTFUNC( SetSource, "Sets the source of the bullets." )
|
||||
DEFINE_SCRIPTFUNC( GetDirShooting, "Gets the direction of the bullets." )
|
||||
DEFINE_SCRIPTFUNC( SetDirShooting, "Sets the direction of the bullets." )
|
||||
DEFINE_SCRIPTFUNC( GetSpread, "Gets the spread of the bullets." )
|
||||
DEFINE_SCRIPTFUNC( SetSpread, "Sets the spread of the bullets." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetDistance, "Gets the distance the bullets should travel." )
|
||||
DEFINE_SCRIPTFUNC( SetDistance, "Sets the distance the bullets should travel." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetAmmoType, "Gets the ammo type the bullets should use." )
|
||||
DEFINE_SCRIPTFUNC( SetAmmoType, "Sets the ammo type the bullets should use." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetTracerFreq, "Gets the tracer frequency." )
|
||||
DEFINE_SCRIPTFUNC( SetTracerFreq, "Sets the tracer frequency." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetDamage, "Gets the damage the bullets should deal. 0 = use ammo type" )
|
||||
DEFINE_SCRIPTFUNC( SetDamage, "Sets the damage the bullets should deal. 0 = use ammo type" )
|
||||
DEFINE_SCRIPTFUNC( GetPlayerDamage, "Gets the damage the bullets should deal when hitting the player. 0 = use regular damage" )
|
||||
DEFINE_SCRIPTFUNC( SetPlayerDamage, "Sets the damage the bullets should deal when hitting the player. 0 = use regular damage" )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetFlags, "Gets the flags the bullets should use." )
|
||||
DEFINE_SCRIPTFUNC( SetFlags, "Sets the flags the bullets should use." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetDamageForceScale, "Gets the scale of the damage force applied by the bullets." )
|
||||
DEFINE_SCRIPTFUNC( SetDamageForceScale, "Sets the scale of the damage force applied by the bullets." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetAttacker, "Gets the entity considered to be the one who fired the bullets." )
|
||||
DEFINE_SCRIPTFUNC( SetAttacker, "Sets the entity considered to be the one who fired the bullets." )
|
||||
DEFINE_SCRIPTFUNC( GetAdditionalIgnoreEnt, "Gets the optional entity which the bullets should ignore." )
|
||||
DEFINE_SCRIPTFUNC( SetAdditionalIgnoreEnt, "Sets the optional entity which the bullets should ignore." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetPrimaryAttack, "Gets whether the bullets came from a primary attack." )
|
||||
DEFINE_SCRIPTFUNC( SetPrimaryAttack, "Sets whether the bullets came from a primary attack." )
|
||||
|
||||
//DEFINE_SCRIPTFUNC( Destroy, "Deletes this instance. Important for preventing memory leaks." )
|
||||
END_SCRIPTDESC();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
HSCRIPT CFireBulletsInfoAccessor::GetAttacker()
|
||||
{
|
||||
return ToHScript( m_info->m_pAttacker );
|
||||
}
|
||||
|
||||
void CFireBulletsInfoAccessor::SetAttacker( HSCRIPT value )
|
||||
{
|
||||
m_info->m_pAttacker = ToEnt( value );
|
||||
}
|
||||
|
||||
HSCRIPT CFireBulletsInfoAccessor::GetAdditionalIgnoreEnt()
|
||||
{
|
||||
return ToHScript( m_info->m_pAdditionalIgnoreEnt );
|
||||
}
|
||||
|
||||
void CFireBulletsInfoAccessor::SetAdditionalIgnoreEnt( HSCRIPT value )
|
||||
{
|
||||
m_info->m_pAdditionalIgnoreEnt = ToEnt( value );
|
||||
}
|
||||
|
||||
static HSCRIPT CreateFireBulletsInfo( int cShots, const Vector &vecSrc, const Vector &vecDirShooting,
|
||||
const Vector &vecSpread, float iDamage, HSCRIPT pAttacker )
|
||||
{
|
||||
// The script is responsible for deleting this via DestroyFireBulletsInfo().
|
||||
FireBulletsInfo_t *info = new FireBulletsInfo_t();
|
||||
CFireBulletsInfoAccessor *bulletsInfo = new CFireBulletsInfoAccessor( info );
|
||||
|
||||
HSCRIPT hScript = g_pScriptVM->RegisterInstance( bulletsInfo );
|
||||
|
||||
bulletsInfo->SetShots( cShots );
|
||||
bulletsInfo->SetSource( vecSrc );
|
||||
bulletsInfo->SetDirShooting( vecDirShooting );
|
||||
bulletsInfo->SetSpread( vecSpread );
|
||||
bulletsInfo->SetDamage( iDamage );
|
||||
bulletsInfo->SetAttacker( pAttacker );
|
||||
|
||||
return hScript;
|
||||
}
|
||||
|
||||
static void DestroyFireBulletsInfo( HSCRIPT hBulletsInfo )
|
||||
{
|
||||
if (hBulletsInfo)
|
||||
{
|
||||
CFireBulletsInfoAccessor *pInfo = (CFireBulletsInfoAccessor*)g_pScriptVM->GetInstanceValue( hBulletsInfo, GetScriptDescForClass( CFireBulletsInfoAccessor ) );
|
||||
if (pInfo)
|
||||
{
|
||||
g_pScriptVM->RemoveInstance( hBulletsInfo );
|
||||
pInfo->Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For the function in baseentity.cpp
|
||||
FireBulletsInfo_t *GetFireBulletsInfoFromInfo( HSCRIPT hBulletsInfo )
|
||||
{
|
||||
if (hBulletsInfo)
|
||||
{
|
||||
CFireBulletsInfoAccessor *pInfo = (CFireBulletsInfoAccessor*)g_pScriptVM->GetInstanceValue( hBulletsInfo, GetScriptDescForClass( CFireBulletsInfoAccessor ) );
|
||||
if (pInfo)
|
||||
{
|
||||
return pInfo->GetInfo();
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
|
||||
bool ScriptMatcherMatch( const char *pszQuery, const char *szValue ) { return Matcher_Match( pszQuery, szValue ); }
|
||||
|
||||
//=============================================================================
|
||||
//=============================================================================
|
||||
|
||||
extern void RegisterMathScriptFunctions();
|
||||
|
||||
void RegisterSharedScriptFunctions()
|
||||
{
|
||||
//
|
||||
@@ -643,10 +766,6 @@ void RegisterSharedScriptFunctions()
|
||||
// some of the code normally available in games like L4D2 or Valve's original VScript DLL.
|
||||
// Instead, that code is recreated here, shared between server and client.
|
||||
//
|
||||
ScriptRegisterFunction( g_pScriptVM, RandomFloat, "Generate a random floating point number within a range, inclusive." );
|
||||
ScriptRegisterFunction( g_pScriptVM, RandomInt, "Generate a random integer within a range, inclusive." );
|
||||
|
||||
ScriptRegisterFunction( g_pScriptVM, AngleDiff, "Returns the number of degrees difference between two yaw angles." );
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::BoxDirection, "DebugDrawBoxDirection", "Draw a debug forward box" );
|
||||
@@ -678,6 +797,9 @@ void RegisterSharedScriptFunctions()
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCalculateMeleeDamageForce, "CalculateMeleeDamageForce", "Fill out a damage info handle with a damage force for a melee impact." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptGuessDamageForce, "GuessDamageForce", "Try and guess the physics force to use." );
|
||||
|
||||
ScriptRegisterFunction( g_pScriptVM, CreateFireBulletsInfo, "Creates FireBullets info." );
|
||||
ScriptRegisterFunction( g_pScriptVM, DestroyFireBulletsInfo, "Destroys FireBullets info." );
|
||||
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptTraceLineComplex, "TraceLineComplex", "Complex version of TraceLine which takes 2 points, an ent to ignore, a trace mask, and a collision group. Returns a handle which can access all trace info." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptTraceHullComplex, "TraceHullComplex", "Takes 2 points, min/max hull bounds, an ent to ignore, a trace mask, and a collision group to trace to a point using a hull. Returns a handle which can access all trace info." );
|
||||
|
||||
@@ -685,6 +807,8 @@ void RegisterSharedScriptFunctions()
|
||||
ScriptRegisterFunction( g_pScriptVM, Matcher_NamesMatch, "Compares a string to a query using Mapbase's matcher system using wildcards only." );
|
||||
ScriptRegisterFunction( g_pScriptVM, AppearsToBeANumber, "Checks if the given string appears to be a number." );
|
||||
|
||||
RegisterMathScriptFunctions();
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
VScriptRunScript( "vscript_client", true );
|
||||
#else
|
||||
|
||||
@@ -33,6 +33,62 @@ bool IsEntityCreationAllowedInScripts( void );
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
void RegisterSharedScriptFunctions();
|
||||
|
||||
//
|
||||
// Exposes FireBulletsInfo_t to VScript
|
||||
//
|
||||
class CFireBulletsInfoAccessor
|
||||
{
|
||||
public:
|
||||
CFireBulletsInfoAccessor( FireBulletsInfo_t *info ) { m_info = info; }
|
||||
|
||||
int GetShots() { return m_info->m_iShots; }
|
||||
void SetShots( int value ) { m_info->m_iShots = value; }
|
||||
|
||||
Vector GetSource() { return m_info->m_vecSrc; }
|
||||
void SetSource( Vector value ) { m_info->m_vecSrc = value; }
|
||||
Vector GetDirShooting() { return m_info->m_vecDirShooting; }
|
||||
void SetDirShooting( Vector value ) { m_info->m_vecDirShooting = value; }
|
||||
Vector GetSpread() { return m_info->m_vecSpread; }
|
||||
void SetSpread( Vector value ) { m_info->m_vecSpread = value; }
|
||||
|
||||
float GetDistance() { return m_info->m_flDistance; }
|
||||
void SetDistance( float value ) { m_info->m_flDistance = value; }
|
||||
|
||||
int GetAmmoType() { return m_info->m_iAmmoType; }
|
||||
void SetAmmoType( int value ) { m_info->m_iAmmoType = value; }
|
||||
|
||||
int GetTracerFreq() { return m_info->m_iTracerFreq; }
|
||||
void SetTracerFreq( int value ) { m_info->m_iTracerFreq = value; }
|
||||
|
||||
float GetDamage() { return m_info->m_flDamage; }
|
||||
void SetDamage( float value ) { m_info->m_flDamage = value; }
|
||||
int GetPlayerDamage() { return m_info->m_iPlayerDamage; }
|
||||
void SetPlayerDamage( float value ) { m_info->m_iPlayerDamage = value; }
|
||||
|
||||
int GetFlags() { return m_info->m_nFlags; }
|
||||
void SetFlags( float value ) { m_info->m_nFlags = value; }
|
||||
|
||||
float GetDamageForceScale() { return m_info->m_flDamageForceScale; }
|
||||
void SetDamageForceScale( float value ) { m_info->m_flDamageForceScale = value; }
|
||||
|
||||
HSCRIPT GetAttacker();
|
||||
void SetAttacker( HSCRIPT value );
|
||||
HSCRIPT GetAdditionalIgnoreEnt();
|
||||
void SetAdditionalIgnoreEnt( HSCRIPT value );
|
||||
|
||||
bool GetPrimaryAttack() { return m_info->m_bPrimaryAttack; }
|
||||
void SetPrimaryAttack( bool value ) { m_info->m_bPrimaryAttack = value; }
|
||||
|
||||
FireBulletsInfo_t *GetInfo() { return m_info; }
|
||||
|
||||
void Destroy() { delete m_info; delete this; }
|
||||
|
||||
private:
|
||||
FireBulletsInfo_t *m_info;
|
||||
};
|
||||
|
||||
HSCRIPT ScriptCreateMatrixInstance( matrix3x4_t &matrix );
|
||||
#endif
|
||||
|
||||
#endif // VSCRIPT_SHARED_H
|
||||
|
||||
Reference in New Issue
Block a user