Skip to content

Commit 8b38259

Browse files
committed
2 parents 0b0812c + d7a8627 commit 8b38259

File tree

256 files changed

+37870
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+37870
-141
lines changed

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The Alien Swarm-based radial fog and rope code as well as the multiple skybox su
88
The dynamic RTT shadow angles code is from Saul Rennison on the VDC. (https://developer.valvesoftware.com/wiki/Dynamic_RTT_shadow_angles_in_Source_2007)
99
The vortigaunt LOS fix is from Half-Life 2: Community Edition (dky.tehkingd.u in particular). (https://gitlab.com/RaraCerberus/HL2CE)
1010
The parallax corrected cubemap code was originally created by Brian Charles. (https://developer.valvesoftware.com/wiki/Parallax_Corrected_Cubemaps)
11+
The custom VScript library was created by reductor for Mapbase. (https://github.com/mapbase-source/source-sdk-2013/pull/5)
1112
Various other code and contributions were based off of pull requests in the Source 2013 SDK (https://github.com/ValveSoftware/source-sdk-2013/pulls) and snippets on the Valve Developer Community (http://developer.valvesoftware.com/).
1213

1314
All of the work mentioned above was open source when it was borrowed.

sp/src/game/client/c_baseanimating.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ BEGIN_DATADESC( C_ClientRagdoll )
281281

282282
END_DATADESC()
283283

284+
BEGIN_ENT_SCRIPTDESC( C_BaseAnimating, C_BaseEntity, "Animating models client-side" )
285+
DEFINE_SCRIPTFUNC_NAMED( ScriptSetPoseParameter, "SetPoseParameter", "Set the specified pose parameter to the specified value" )
286+
DEFINE_SCRIPTFUNC( IsSequenceFinished, "Ask whether the main sequence is done playing" )
287+
END_SCRIPTDESC();
288+
284289
C_ClientRagdoll::C_ClientRagdoll( bool bRestoring )
285290
{
286291
m_iCurrentFriction = 0;
@@ -1403,6 +1408,15 @@ float C_BaseAnimating::ClampCycle( float flCycle, bool isLooping )
14031408
return flCycle;
14041409
}
14051410

1411+
void C_BaseAnimating::ScriptSetPoseParameter(const char* szName, float fValue)
1412+
{
1413+
CStudioHdr* pHdr = GetModelPtr();
1414+
if (pHdr == NULL)
1415+
return;
1416+
1417+
int iPoseParam = LookupPoseParameter(pHdr, szName);
1418+
SetPoseParameter(pHdr, iPoseParam, fValue);
1419+
}
14061420

14071421
void C_BaseAnimating::GetCachedBoneMatrix( int boneIndex, matrix3x4_t &out )
14081422
{

sp/src/game/client/c_baseanimating.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback
9595
DECLARE_CLIENTCLASS();
9696
DECLARE_PREDICTABLE();
9797
DECLARE_INTERPOLATION();
98+
DECLARE_ENT_SCRIPTDESC();
9899

99100
enum
100101
{
@@ -445,6 +446,7 @@ class C_BaseAnimating : public C_BaseEntity, private IModelLoadCallback
445446

446447
virtual bool IsViewModel() const;
447448

449+
void ScriptSetPoseParameter(const char* szName, float fValue);
448450
protected:
449451
// View models scale their attachment positions to account for FOV. To get the unmodified
450452
// attachment position (like if you're rendering something else during the view model's DrawModel call),

sp/src/game/client/c_baseentity.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "viewrender.h"
4545
#endif
4646

47+
#include "gamestringpool.h"
48+
4749
// memdbgon must be the last include file in a .cpp file!!!
4850
#include "tier0/memdbgon.h"
4951

@@ -423,6 +425,42 @@ BEGIN_RECV_TABLE_NOBASE( C_BaseEntity, DT_AnimTimeMustBeFirst )
423425
RecvPropInt( RECVINFO(m_flAnimTime), 0, RecvProxy_AnimTime ),
424426
END_RECV_TABLE()
425427

428+
BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities" )
429+
DEFINE_SCRIPTFUNC_NAMED( GetAbsOrigin, "GetOrigin", "" )
430+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetForward, "GetForwardVector", "Get the forward vector of the entity" )
431+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetLeft, "GetLeftVector", "Get the left vector of the entity" )
432+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetUp, "GetUpVector", "Get the up vector of the entity" )
433+
DEFINE_SCRIPTFUNC( GetTeamNumber, "Gets this entity's team" )
434+
435+
#ifdef MAPBASE_VSCRIPT
436+
DEFINE_SCRIPTFUNC( GetHealth, "" )
437+
DEFINE_SCRIPTFUNC( GetMaxHealth, "" )
438+
439+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetModelName, "GetModelName", "Returns the name of the model" )
440+
441+
DEFINE_SCRIPTFUNC_NAMED( ScriptEmitSound, "EmitSound", "Plays a sound from this entity." )
442+
DEFINE_SCRIPTFUNC_NAMED( VScriptPrecacheScriptSound, "PrecacheSoundScript", "Precache a sound for later playing." )
443+
DEFINE_SCRIPTFUNC_NAMED( ScriptSoundDuration, "GetSoundDuration", "Returns float duration of the sound. Takes soundname and optional actormodelname." )
444+
445+
DEFINE_SCRIPTFUNC( GetClassname, "" )
446+
DEFINE_SCRIPTFUNC_NAMED( GetEntityName, "GetName", "" )
447+
448+
DEFINE_SCRIPTFUNC_NAMED( WorldSpaceCenter, "GetCenter", "Get vector to center of object - absolute coords" )
449+
DEFINE_SCRIPTFUNC_NAMED( ScriptEyePosition, "EyePosition", "Get vector to eye position - absolute coords" )
450+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAngles, "GetAngles", "Get entity pitch, yaw, roll as a vector" )
451+
452+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetBoundingMins, "GetBoundingMins", "Get a vector containing min bounds, centered on object" )
453+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetBoundingMaxs, "GetBoundingMaxs", "Get a vector containing max bounds, centered on object" )
454+
455+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetMoveParent, "GetMoveParent", "If in hierarchy, retrieves the entity's parent" )
456+
DEFINE_SCRIPTFUNC_NAMED( ScriptGetRootMoveParent, "GetRootMoveParent", "If in hierarchy, walks up the hierarchy to find the root parent" )
457+
DEFINE_SCRIPTFUNC_NAMED( ScriptFirstMoveChild, "FirstMoveChild", "" )
458+
DEFINE_SCRIPTFUNC_NAMED( ScriptNextMovePeer, "NextMovePeer", "" )
459+
460+
DEFINE_SCRIPTFUNC( GetEffects, "Get effects" )
461+
DEFINE_SCRIPTFUNC( IsEffectActive, "Check if an effect is active" )
462+
#endif
463+
END_SCRIPTDESC();
426464

427465
#ifndef NO_ENTITY_PREDICTION
428466
BEGIN_RECV_TABLE_NOBASE( C_BaseEntity, DT_PredictableId )
@@ -466,6 +504,8 @@ BEGIN_RECV_TABLE_NOBASE(C_BaseEntity, DT_BaseEntity)
466504
RecvPropInt( RECVINFO_NAME(m_hNetworkMoveParent, moveparent), 0, RecvProxy_IntToMoveParent ),
467505
RecvPropInt( RECVINFO( m_iParentAttachment ) ),
468506

507+
RecvPropString(RECVINFO(m_iName)),
508+
469509
RecvPropInt( "movetype", 0, SIZEOF_IGNORE, 0, RecvProxy_MoveType ),
470510
RecvPropInt( "movecollide", 0, SIZEOF_IGNORE, 0, RecvProxy_MoveCollide ),
471511
RecvPropDataTable( RECVINFO_DT( m_Collision ), 0, &REFERENCE_RECV_TABLE(DT_CollisionProperty) ),
@@ -1095,6 +1135,8 @@ bool C_BaseEntity::Init( int entnum, int iSerialNum )
10951135

10961136
m_nCreationTick = gpGlobals->tickcount;
10971137

1138+
m_hScriptInstance = NULL;
1139+
10981140
return true;
10991141
}
11001142

@@ -1165,6 +1207,7 @@ void C_BaseEntity::Term()
11651207
g_Predictables.RemoveFromPredictablesList( GetClientHandle() );
11661208
}
11671209

1210+
11681211
// If it's play simulated, remove from simulation list if the player still exists...
11691212
if ( IsPlayerSimulated() && C_BasePlayer::GetLocalPlayer() )
11701213
{
@@ -1201,6 +1244,12 @@ void C_BaseEntity::Term()
12011244
RemoveFromLeafSystem();
12021245

12031246
RemoveFromAimEntsList();
1247+
1248+
if ( m_hScriptInstance )
1249+
{
1250+
g_pScriptVM->RemoveInstance( m_hScriptInstance );
1251+
m_hScriptInstance = NULL;
1252+
}
12041253
}
12051254

12061255

@@ -6442,6 +6491,55 @@ int C_BaseEntity::GetCreationTick() const
64426491
return m_nCreationTick;
64436492
}
64446493

6494+
//-----------------------------------------------------------------------------
6495+
//
6496+
//-----------------------------------------------------------------------------
6497+
HSCRIPT C_BaseEntity::GetScriptInstance()
6498+
{
6499+
if (!m_hScriptInstance)
6500+
{
6501+
if (m_iszScriptId == NULL_STRING)
6502+
{
6503+
char* szName = (char*)stackalloc(1024);
6504+
g_pScriptVM->GenerateUniqueKey((m_iName != NULL_STRING) ? STRING(GetEntityName()) : GetClassname(), szName, 1024);
6505+
m_iszScriptId = AllocPooledString(szName);
6506+
}
6507+
6508+
m_hScriptInstance = g_pScriptVM->RegisterInstance(GetScriptDesc(), this);
6509+
g_pScriptVM->SetInstanceUniqeId(m_hScriptInstance, STRING(m_iszScriptId));
6510+
}
6511+
return m_hScriptInstance;
6512+
}
6513+
6514+
#ifdef MAPBASE_VSCRIPT
6515+
//-----------------------------------------------------------------------------
6516+
//-----------------------------------------------------------------------------
6517+
HSCRIPT C_BaseEntity::ScriptGetMoveParent( void )
6518+
{
6519+
return ToHScript( GetMoveParent() );
6520+
}
6521+
//-----------------------------------------------------------------------------
6522+
//-----------------------------------------------------------------------------
6523+
HSCRIPT C_BaseEntity::ScriptGetRootMoveParent()
6524+
{
6525+
return ToHScript( GetRootMoveParent() );
6526+
}
6527+
6528+
//-----------------------------------------------------------------------------
6529+
//-----------------------------------------------------------------------------
6530+
HSCRIPT C_BaseEntity::ScriptFirstMoveChild( void )
6531+
{
6532+
return ToHScript( FirstMoveChild() );
6533+
}
6534+
6535+
//-----------------------------------------------------------------------------
6536+
//-----------------------------------------------------------------------------
6537+
HSCRIPT C_BaseEntity::ScriptNextMovePeer( void )
6538+
{
6539+
return ToHScript( NextMovePeer() );
6540+
}
6541+
#endif
6542+
64456543
//------------------------------------------------------------------------------
64466544
void CC_CL_Find_Ent( const CCommand& args )
64476545
{

sp/src/game/client/c_baseentity.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include "toolframework/itoolentity.h"
3737
#include "tier0/threadtools.h"
3838

39+
#include "vscript/ivscript.h"
40+
#include "vscript_shared.h"
41+
3942
class C_Team;
4043
class IPhysicsObject;
4144
class IClientVehicle;
@@ -183,6 +186,8 @@ class C_BaseEntity : public IClientEntity
183186
DECLARE_DATADESC();
184187
DECLARE_CLIENTCLASS();
185188
DECLARE_PREDICTABLE();
189+
// script description
190+
DECLARE_ENT_SCRIPTDESC();
186191

187192
C_BaseEntity();
188193
virtual ~C_BaseEntity();
@@ -256,6 +261,11 @@ class C_BaseEntity : public IClientEntity
256261

257262
string_t m_iClassname;
258263

264+
HSCRIPT GetScriptInstance();
265+
266+
HSCRIPT m_hScriptInstance;
267+
string_t m_iszScriptId;
268+
259269
// IClientUnknown overrides.
260270
public:
261271

@@ -1119,6 +1129,30 @@ class C_BaseEntity : public IClientEntity
11191129
virtual int GetBody() { return 0; }
11201130
virtual int GetSkin() { return 0; }
11211131

1132+
const Vector& ScriptGetForward(void) { static Vector vecForward; GetVectors(&vecForward, NULL, NULL); return vecForward; }
1133+
const Vector& ScriptGetLeft(void) { static Vector vecLeft; GetVectors(NULL, &vecLeft, NULL); return vecLeft; }
1134+
const Vector& ScriptGetUp(void) { static Vector vecUp; GetVectors(NULL, NULL, &vecUp); return vecUp; }
1135+
1136+
#ifdef MAPBASE_VSCRIPT
1137+
const char* ScriptGetModelName( void ) const { return STRING(GetModelName()); }
1138+
1139+
void ScriptEmitSound(const char* soundname);
1140+
float ScriptSoundDuration(const char* soundname, const char* actormodel);
1141+
1142+
void VScriptPrecacheScriptSound(const char* soundname);
1143+
1144+
const Vector& ScriptEyePosition(void) { static Vector vec; vec = EyePosition(); return vec; }
1145+
const Vector& ScriptGetAngles(void) { static Vector vec; QAngle qa = GetAbsAngles(); vec.x = qa.x; vec.y = qa.y; vec.z = qa.z; return vec; }
1146+
1147+
const Vector& ScriptGetBoundingMins( void ) { return m_Collision.OBBMins(); }
1148+
const Vector& ScriptGetBoundingMaxs( void ) { return m_Collision.OBBMaxs(); }
1149+
1150+
HSCRIPT ScriptGetMoveParent( void );
1151+
HSCRIPT ScriptGetRootMoveParent();
1152+
HSCRIPT ScriptFirstMoveChild( void );
1153+
HSCRIPT ScriptNextMovePeer( void );
1154+
#endif
1155+
11221156
// Stubs on client
11231157
void NetworkStateManualMode( bool activate ) { }
11241158
void NetworkStateChanged() { }
@@ -1266,6 +1300,7 @@ class C_BaseEntity : public IClientEntity
12661300
void SetRenderMode( RenderMode_t nRenderMode, bool bForceUpdate = false );
12671301
RenderMode_t GetRenderMode() const;
12681302

1303+
const char* GetEntityName();
12691304
public:
12701305

12711306
// Determine what entity this corresponds to
@@ -1648,6 +1683,8 @@ class C_BaseEntity : public IClientEntity
16481683
// The owner!
16491684
EHANDLE m_hOwnerEntity;
16501685
EHANDLE m_hEffectEntity;
1686+
1687+
char m_iName[MAX_PATH];
16511688

16521689
// This is a random seed used by the networking code to allow client - side prediction code
16531690
// randon number generators to spit out the same random numbers on both sides for a particular
@@ -2203,6 +2240,12 @@ inline bool C_BaseEntity::ShouldRecordInTools() const
22032240
#endif
22042241
}
22052242

2243+
inline const char *C_BaseEntity::GetEntityName()
2244+
{
2245+
return m_iName;
2246+
}
2247+
2248+
22062249
C_BaseEntity *CreateEntityByName( const char *className );
22072250

22082251
#endif // C_BASEENTITY_H

sp/src/game/client/c_baseflex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ bool C_BaseFlex::ClearSceneEvent( CSceneEventInfo *info, bool fastKill, bool can
14801480
// expression -
14811481
// duration -
14821482
//-----------------------------------------------------------------------------
1483-
void C_BaseFlex::AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseEntity *pTarget, bool bClientSide )
1483+
void C_BaseFlex::AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseEntity *pTarget, bool bClientSide, C_SceneEntity* pSceneEntity)
14841484
{
14851485
if ( !scene || !event )
14861486
{
@@ -1505,6 +1505,7 @@ void C_BaseFlex::AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, CBaseE
15051505
info.m_hTarget = pTarget;
15061506
info.m_bStarted = false;
15071507
info.m_bClientSide = bClientSide;
1508+
info.m_hSceneEntity = pSceneEntity;
15081509

15091510
if (StartSceneEvent( &info, scene, event, actor, pTarget ))
15101511
{

sp/src/game/client/c_baseflex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class C_BaseFlex : public C_BaseAnimatingOverlay, public IHasLocalToGlobalFlexSe
214214
virtual bool ClearSceneEvent( CSceneEventInfo *info, bool fastKill, bool canceled );
215215

216216
// Add the event to the queue for this actor
217-
void AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, C_BaseEntity *pTarget = NULL, bool bClientSide = false );
217+
void AddSceneEvent( CChoreoScene *scene, CChoreoEvent *event, C_BaseEntity *pTarget = NULL, bool bClientSide = false, C_SceneEntity* pSceneEntity = NULL);
218218

219219
// Remove the event from the queue for this actor
220220
void RemoveSceneEvent( CChoreoScene *scene, CChoreoEvent *event, bool fastKill );

sp/src/game/client/c_baseplayer.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,13 @@ C_BasePlayer::~C_BasePlayer()
480480
s_pLocalPlayer = NULL;
481481
}
482482

483+
#ifdef MAPBASE_VSCRIPT
484+
if ( IsLocalPlayer() && g_pScriptVM )
485+
{
486+
g_pScriptVM->SetValue( "player", SCRIPT_VARIANT_NULL );
487+
}
488+
#endif
489+
483490
delete m_pFlashlight;
484491
}
485492

@@ -974,6 +981,16 @@ void C_BasePlayer::OnRestore()
974981
input->ClearInputButton( IN_ATTACK | IN_ATTACK2 );
975982
// GetButtonBits() has to be called for the above to take effect
976983
input->GetButtonBits( 0 );
984+
985+
#ifdef MAPBASE_VSCRIPT
986+
// HACK: (03/25/09) Then the player goes across a transition it doesn't spawn and register
987+
// it's instance. We're hacking around this for now, but this will go away when we get around to
988+
// having entities cross transitions and keep their script state.
989+
if ( g_pScriptVM )
990+
{
991+
g_pScriptVM->SetValue( "player", GetScriptInstance() );
992+
}
993+
#endif
977994
}
978995

979996
// For ammo history icons to current value so they don't flash on level transtions

0 commit comments

Comments
 (0)