Integrating vscript interface code (based on Alien Swarm)

This commit is contained in:
James Mitchell
2020-05-04 16:25:15 +10:00
parent af85131deb
commit d840c57b4a
53 changed files with 5128 additions and 134 deletions

View File

@@ -21,6 +21,9 @@
#include "shareddefs.h"
#include "engine/ivmodelinfo.h"
#include "vscript/ivscript.h"
#include "vscript_server.h"
class CDamageModifier;
class CDmgAccumulator;
@@ -311,11 +314,13 @@ a list of all CBaseEntitys is kept in gEntList
CBaseEntity *CreateEntityByName( const char *className, int iForceEdictIndex = -1 );
CBaseNetworkable *CreateNetworkableByName( const char *className );
CBaseEntity* ToEnt(HSCRIPT hScript);
// creates an entity and calls all the necessary spawn functions
extern void SpawnEntityByName( const char *className, CEntityMapData *mapData = NULL );
// calls the spawn functions for an entity
extern int DispatchSpawn( CBaseEntity *pEntity );
extern int DispatchSpawn( CBaseEntity *pEntity, bool bRunVScripts = true);
inline CBaseEntity *GetContainingEntity( edict_t *pent );
@@ -379,6 +384,8 @@ public:
DECLARE_SERVERCLASS();
// data description
DECLARE_DATADESC();
// script description
DECLARE_ENT_SCRIPTDESC();
// memory handling
void *operator new( size_t stAllocateBlock );
@@ -493,6 +500,8 @@ public:
virtual void SetOwnerEntity( CBaseEntity* pOwner );
void SetEffectEntity( CBaseEntity *pEffectEnt );
CBaseEntity *GetEffectEntity() const;
HSCRIPT GetScriptOwnerEntity();
virtual void SetScriptOwnerEntity(HSCRIPT pOwner);
// Only CBaseEntity implements these. CheckTransmit calls the virtual ShouldTransmit to see if the
// entity wants to be sent. If so, it calls SetTransmit, which will mark any dependents for transmission too.
@@ -563,9 +572,14 @@ public:
virtual bool KeyValue( const char *szKeyName, float flValue );
virtual bool KeyValue( const char *szKeyName, const Vector &vecValue );
virtual bool GetKeyValue( const char *szKeyName, char *szValue, int iMaxLen );
bool KeyValueFromString( const char *szKeyName, const char *szValue ) { return KeyValue( szKeyName, szValue ); }
bool KeyValueFromFloat( const char *szKeyName, float flValue ) { return KeyValue( szKeyName, flValue ); }
bool KeyValueFromInt( const char *szKeyName, int nValue ) { return KeyValue( szKeyName, nValue ); }
bool KeyValueFromVector( const char *szKeyName, const Vector &vecValue ) { return KeyValue( szKeyName, vecValue ); }
void ValidateEntityConnections();
void FireNamedOutput( const char *pszOutput, variant_t variant, CBaseEntity *pActivator, CBaseEntity *pCaller, float flDelay = 0.0f );
CBaseEntityOutput *FindNamedOutput( const char *pszOutput );
// Activate - called for each entity after each load game and level load
virtual void Activate( void );
@@ -588,6 +602,8 @@ public:
int GetParentAttachment();
string_t GetEntityName();
const char* GetEntityNameAsCStr(); // This method is temporary for VSCRIPT functionality until we figure out what to do with string_t (sjb)
const char* GetPreTemplateName(); // Not threadsafe. Get the name stripped of template unique decoration
bool NameMatches( const char *pszNameOrWildcard );
bool ClassMatches( const char *pszClassOrWildcard );
@@ -735,6 +751,14 @@ public:
COutputEvent m_OnKilled;
#endif
void InputRunScript(inputdata_t& inputdata);
void InputRunScriptFile(inputdata_t& inputdata);
void InputCallScriptFunction(inputdata_t& inputdata);
bool RunScriptFile(const char* pScriptFile, bool bUseRootScope = false);
bool RunScript(const char* pScriptText, const char* pDebugFilename = "CBaseEntity::RunScript");
// Returns the origin at which to play an inputted dispatcheffect
virtual void GetInputDispatchEffectPosition( const char *sInputString, Vector &pOrigin, QAngle &pAngles );
@@ -1715,7 +1739,7 @@ private:
// was pev->flags
CNetworkVarForDerived( int, m_fFlags );
string_t m_iName; // name used to identify this entity
CNetworkVar( string_t, m_iName ); // name used to identify this entity
// Damage modifiers
friend class CDamageModifier;
@@ -1920,6 +1944,59 @@ public:
{
return s_bAbsQueriesValid;
}
// VSCRIPT
HSCRIPT GetScriptInstance();
bool ValidateScriptScope();
virtual void RunVScripts();
bool CallScriptFunction(const char* pFunctionName, ScriptVariant_t* pFunctionReturn);
void ConnectOutputToScript(const char* pszOutput, const char* pszScriptFunc);
void DisconnectOutputFromScript(const char* pszOutput, const char* pszScriptFunc);
void ScriptThink();
const char* GetScriptId();
HSCRIPT GetScriptScope();
void RunPrecacheScripts(void);
void RunOnPostSpawnScripts(void);
HSCRIPT ScriptGetMoveParent(void);
HSCRIPT ScriptGetRootMoveParent();
HSCRIPT ScriptFirstMoveChild(void);
HSCRIPT ScriptNextMovePeer(void);
const Vector& ScriptEyePosition(void) { static Vector vec; vec = EyePosition(); return vec; }
void ScriptSetAngles(float fPitch, float fYaw, float fRoll) { QAngle angles(fPitch, fYaw, fRoll); Teleport(NULL, &angles, NULL); }
const Vector& ScriptGetAngles(void) { static Vector vec; QAngle qa = GetAbsAngles(); vec.x = qa.x; vec.y = qa.y; vec.z = qa.z; return vec; }
void ScriptSetSize(const Vector& mins, const Vector& maxs) { UTIL_SetSize(this, mins, maxs); }
void ScriptUtilRemove(void) { UTIL_Remove(this); }
void ScriptSetOwner(HSCRIPT hEntity) { SetOwnerEntity(ToEnt(hEntity)); }
void ScriptSetOrigin(const Vector& v) { Teleport(&v, NULL, NULL); }
void ScriptSetForward(const Vector& v) { QAngle angles; VectorAngles(v, angles); Teleport(NULL, &angles, NULL); }
const Vector& ScriptGetForward(void) { static Vector vecForward; GetVectors(&vecForward, NULL, NULL); return vecForward; }
const Vector& ScriptGetLeft(void) { static Vector vecLeft; GetVectors(NULL, &vecLeft, NULL); return vecLeft; }
const Vector& ScriptGetUp(void) { static Vector vecUp; GetVectors(NULL, NULL, &vecUp); return vecUp; }
const char* ScriptGetModelName(void) const;
HSCRIPT ScriptGetModelKeyValues(void);
void ScriptEmitSound(const char* soundname);
float ScriptSoundDuration(const char* soundname, const char* actormodel);
void VScriptPrecacheScriptSound(const char* soundname);
const Vector& ScriptGetLocalAngularVelocity( void );
void ScriptSetLocalAngularVelocity( float pitchVel, float yawVel, float rollVel );
const Vector& ScriptGetBoundingMins(void);
const Vector& ScriptGetBoundingMaxs(void);
string_t m_iszVScripts;
string_t m_iszScriptThinkFunction;
CScriptScope m_ScriptScope;
HSCRIPT m_hScriptInstance;
string_t m_iszScriptId;
CScriptKeyValues* m_pScriptModelKeyValues;
};
// Send tables exposed in this module.
@@ -2048,6 +2125,21 @@ inline string_t CBaseEntity::GetEntityName()
return m_iName;
}
inline const char *CBaseEntity::GetEntityNameAsCStr()
{
return STRING(m_iName.Get());
}
inline const char *CBaseEntity::GetPreTemplateName()
{
const char *pszDelimiter = V_strrchr( STRING(m_iName.Get()), '&' );
if ( !pszDelimiter )
return STRING( m_iName.Get() );
static char szStrippedName[128];
V_strncpy( szStrippedName, STRING( m_iName.Get() ), MIN( ARRAYSIZE(szStrippedName), pszDelimiter - STRING( m_iName.Get() ) + 1 ) );
return szStrippedName;
}
inline void CBaseEntity::SetName( string_t newName )
{
m_iName = newName;
@@ -2726,6 +2818,14 @@ inline void CBaseEntity::FireBullets( int cShots, const Vector &vecSrc,
FireBullets( info );
}
//-----------------------------------------------------------------------------
// VScript
//-----------------------------------------------------------------------------
inline const char* CBaseEntity::ScriptGetModelName(void) const
{
return STRING(m_ModelName);
}
// Ugly technique to override base member functions
// Normally it's illegal to cast a pointer to a member function of a derived class to a pointer to a
// member function of a base class. static_cast is a sleezy way around that problem.