Skip to content

Commit

Permalink
Merge branch 'mapbase/feature/protagonist-system' of https://github.c…
Browse files Browse the repository at this point in the history
…om/Blixibon/source-sdk-2013 into ez2/feature/adapted-protagonist-system

# Conflicts:
#	sp/src/game/shared/hl2/basehlcombatweapon_shared.cpp
#	sp/src/game/shared/hl2/basehlcombatweapon_shared.h
  • Loading branch information
Blixibon committed Jan 31, 2025
2 parents a0dccd4 + ee75608 commit 8bb477d
Show file tree
Hide file tree
Showing 16 changed files with 1,181 additions and 3 deletions.
2 changes: 2 additions & 0 deletions sp/src/game/client/client_mapbase.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ $Project
$File "$SRCDIR\game\shared\mapbase\matchers.h"
$File "$SRCDIR\game\shared\mapbase\singleplayer_animstate.cpp"
$File "$SRCDIR\game\shared\mapbase\singleplayer_animstate.h"
$File "$SRCDIR\game\shared\mapbase\protagonist_system.cpp"
$File "$SRCDIR\game\shared\mapbase\protagonist_system.h"
$File "$SRCDIR\game\shared\mapbase\vscript_funcs_shared.cpp" [$MAPBASE_VSCRIPT]
$File "$SRCDIR\game\shared\mapbase\vscript_funcs_shared.h" [$MAPBASE_VSCRIPT]
$File "$SRCDIR\game\shared\mapbase\vscript_singletons.cpp" [$MAPBASE_VSCRIPT]
Expand Down
3 changes: 3 additions & 0 deletions sp/src/game/client/hl2/c_basehlplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ ConVar cl_npc_speedmod_outtime( "cl_npc_speedmod_outtime", "1.5", FCVAR_CLIENTDL
IMPLEMENT_CLIENTCLASS_DT(C_BaseHLPlayer, DT_HL2_Player, CHL2_Player)
RecvPropDataTable( RECVINFO_DT(m_HL2Local),0, &REFERENCE_RECV_TABLE(DT_HL2Local) ),
RecvPropBool( RECVINFO( m_fIsSprinting ) ),
#ifdef MAPBASE
RecvPropInt( RECVINFO( m_nProtagonistIndex ) ),
#endif
#ifdef SP_ANIM_STATE
RecvPropFloat( RECVINFO( m_flAnimRenderYaw ) ),
#endif
Expand Down
8 changes: 8 additions & 0 deletions sp/src/game/client/hl2/c_basehlplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class C_BaseHLPlayer : public C_BasePlayer

bool IsWeaponLowered( void ) { return m_HL2Local.m_bWeaponLowered; }

#ifdef MAPBASE
int GetProtagonistIndex() const { return m_nProtagonistIndex; }
#endif

#ifdef SP_ANIM_STATE
virtual const QAngle& GetRenderAngles( void );
#endif
Expand All @@ -86,6 +90,10 @@ class C_BaseHLPlayer : public C_BasePlayer
bool m_bPlayUseDenySound; // Signaled by PlayerUse, but can be unset by HL2 ladder code...
float m_flSpeedMod;
float m_flExitSpeedMod;

#ifdef MAPBASE
int m_nProtagonistIndex;
#endif

#ifdef SP_ANIM_STATE
// At the moment, we network the render angles since almost none of the player anim stuff is done on the client in SP.
Expand Down
167 changes: 167 additions & 0 deletions sp/src/game/server/hl2/hl2_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#ifdef MAPBASE
#include "triggers.h"
#include "mapbase/variant_tools.h"
#include "mapbase/protagonist_system.h"
#endif

#ifdef EZ2
Expand Down Expand Up @@ -685,6 +686,8 @@ BEGIN_DATADESC( CHL2_Player )
DEFINE_INPUTFUNC( FIELD_VOID, "DisableGeigerCounter", InputDisableGeigerCounter ),
DEFINE_INPUTFUNC( FIELD_VOID, "ShowSquadHUD", InputShowSquadHUD ),
DEFINE_INPUTFUNC( FIELD_VOID, "HideSquadHUD", InputHideSquadHUD ),

DEFINE_INPUTFUNC( FIELD_STRING, "SetProtagonist", InputSetProtagonist ),
#endif

DEFINE_SOUNDPATCH( m_sndLeeches ),
Expand All @@ -699,6 +702,10 @@ BEGIN_DATADESC( CHL2_Player )

DEFINE_FIELD( m_flTimeNextLadderHint, FIELD_TIME ),

#ifdef MAPBASE
DEFINE_KEYFIELD( m_iszProtagonistName, FIELD_STRING, "ProtagonistName" ),
#endif

//DEFINE_FIELD( m_hPlayerProxy, FIELD_EHANDLE ), //Shut up class check!

END_DATADESC()
Expand Down Expand Up @@ -726,6 +733,9 @@ BEGIN_ENT_SCRIPTDESC( CHL2_Player, CBasePlayer, "The HL2 player entity." )
DEFINE_SCRIPTFUNC( RemoveCustomSuitDevice, "Removes a custom suit device ID. (1-3)" )
DEFINE_SCRIPTFUNC( IsCustomSuitDeviceActive, "Checks if a custom suit device is active." )

DEFINE_SCRIPTFUNC( GetProtagonistName, "Gets the player's protagonist name." )
DEFINE_SCRIPTFUNC( SetProtagonist, "Sets the player's protagonist entry." )

#ifdef SP_ANIM_STATE
DEFINE_SCRIPTFUNC( AddAnimStateLayer, "Adds a custom sequence index as a misc. layer for the singleplayer anim state, wtih parameters for blending in/out, setting the playback rate, holding the animation at the end, and only playing when the player is still." )
#endif
Expand All @@ -741,6 +751,10 @@ CHL2_Player::CHL2_Player()

m_flArmorReductionTime = 0.0f;
m_iArmorReductionFrom = 0;

#ifdef MAPBASE
m_nProtagonistIndex = -1;
#endif
}

//
Expand Down Expand Up @@ -775,6 +789,9 @@ CSuitPowerDevice SuitDeviceCustom[] =
IMPLEMENT_SERVERCLASS_ST(CHL2_Player, DT_HL2_Player)
SendPropDataTable(SENDINFO_DT(m_HL2Local), &REFERENCE_SEND_TABLE(DT_HL2Local), SendProxy_SendLocalDataTable),
SendPropBool( SENDINFO(m_fIsSprinting) ),
#ifdef MAPBASE
SendPropInt( SENDINFO( m_nProtagonistIndex ), 8, SPROP_UNSIGNED ),
#endif
#ifdef SP_ANIM_STATE
SendPropFloat( SENDINFO(m_flAnimRenderYaw), 0, SPROP_NOSCALE ),
#endif
Expand Down Expand Up @@ -1418,6 +1435,11 @@ void CHL2_Player::Activate( void )
#endif

GetPlayerProxy();

#ifdef MAPBASE
if (m_iszProtagonistName != NULL_STRING)
SetProtagonist( STRING( m_iszProtagonistName ) );
#endif
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1658,6 +1680,8 @@ CStudioHdr *CHL2_Player::OnNewModel()

extern char g_szDefaultPlayerModel[MAX_PATH];
extern bool g_bDefaultPlayerDrawExternally;

extern char g_szDefaultProtagonist[MAX_PROTAGONIST_NAME];
#endif

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1690,6 +1714,9 @@ void CHL2_Player::Spawn(void)
}

SetDrawPlayerModelExternally( g_bDefaultPlayerDrawExternally );

if (m_iszProtagonistName == NULL_STRING && *g_szDefaultProtagonist)
m_iszProtagonistName = MAKE_STRING( g_szDefaultProtagonist );
#endif

//
Expand Down Expand Up @@ -4441,6 +4468,10 @@ bool CHL2_Player::Weapon_Switch( CBaseCombatWeapon *pWeapon, int viewmodelindex
StopZooming();
}

#ifdef MAPBASE
RefreshProtagonistWeaponData( pWeapon );
#endif

return BaseClass::Weapon_Switch( pWeapon, viewmodelindex );
}

Expand Down Expand Up @@ -5224,6 +5255,142 @@ bool CHL2_Player::IsCustomSuitDeviceActive( int iDeviceID )

return SuitPower_IsDeviceActive( SuitDeviceCustom[iDeviceID] );
}

//-----------------------------------------------------------------------------
// Purpose: Gets our protagonist name, if we have one
//-----------------------------------------------------------------------------
const char *CHL2_Player::GetProtagonistName() const
{
return STRING( m_iszProtagonistName );
}

//-----------------------------------------------------------------------------
// Purpose: Gets our protagonist index, if we have one
//-----------------------------------------------------------------------------
int CHL2_Player::GetProtagonistIndex() const
{
return m_nProtagonistIndex;
}

//-----------------------------------------------------------------------------
// Purpose: Sets our protagonist to the specified entry
//-----------------------------------------------------------------------------
void CHL2_Player::InputSetProtagonist( inputdata_t &inputdata )
{
SetProtagonist( inputdata.value.String() );
}

//-----------------------------------------------------------------------------
// Purpose: Sets our protagonist to the specified entry
//-----------------------------------------------------------------------------
void CHL2_Player::SetProtagonist( const char *pszProtagonist )
{
if (!pszProtagonist || !*pszProtagonist)
{
ResetProtagonist();
return;
}

int nIndex = g_ProtagonistSystem.FindProtagonistIndex( pszProtagonist );
if (nIndex == -1)
{
Warning( "\"%s\" is not a valid protagonist\n", pszProtagonist );
return;
}

if (m_nProtagonistIndex != -1)
{
// Flush any pre-existing data
ResetProtagonist();
}

m_nProtagonistIndex = nIndex;
m_iszProtagonistName = AllocPooledString( pszProtagonist );

RefreshProtagonistData();
}

//-----------------------------------------------------------------------------
// Purpose: Resets protagonist data
//-----------------------------------------------------------------------------
void CHL2_Player::ResetProtagonist()
{
SetModel( g_szDefaultPlayerModel );
m_nSkin = 0;
m_nBody = 0;

CBaseViewModel *vm = GetViewModel( 1 );
if (vm)
{
extern char g_szDefaultHandsModel[MAX_PATH];
vm->SetWeaponModel( g_szDefaultHandsModel, NULL );

vm->m_nSkin = 0;
vm->m_nBody = 0;
}

// RemoveContext will automatically remove contexts by name, regardless of how values are specified
const char *pszProtagContexts = g_ProtagonistSystem.GetProtagonist_ResponseContexts( this );
if (pszProtagContexts)
RemoveContext( pszProtagContexts );

m_iszProtagonistName = NULL_STRING;
m_nProtagonistIndex = -1;
}

//-----------------------------------------------------------------------------
// Purpose: Refreshes protagonist data
//-----------------------------------------------------------------------------
void CHL2_Player::RefreshProtagonistData()
{
if (m_nProtagonistIndex == -1)
return;

g_ProtagonistSystem.PrecacheProtagonist( this, m_nProtagonistIndex );

const char *pszProtagModel = g_ProtagonistSystem.GetProtagonist_PlayerModel( this );
if (pszProtagModel)
SetModel( pszProtagModel );

m_nSkin = g_ProtagonistSystem.GetProtagonist_PlayerModelSkin( this );
m_nBody = g_ProtagonistSystem.GetProtagonist_PlayerModelBody( this );

const char *pszProtagContexts = g_ProtagonistSystem.GetProtagonist_ResponseContexts( this );
if (pszProtagContexts)
AddContext( pszProtagContexts );

RefreshProtagonistWeaponData( GetActiveWeapon() );
}

//-----------------------------------------------------------------------------
// Purpose: Refreshes protagonist data
//-----------------------------------------------------------------------------
void CHL2_Player::RefreshProtagonistWeaponData( CBaseCombatWeapon *pWeapon )
{
if (m_nProtagonistIndex == -1)
return;

CBaseViewModel *vm = GetViewModel( 1 );
if (vm)
{
const char *pszHandModel = g_ProtagonistSystem.GetProtagonist_HandModel( this, pWeapon );
if (pszHandModel)
{
vm->SetWeaponModel( pszHandModel, NULL );

vm->m_nSkin = g_ProtagonistSystem.GetProtagonist_HandModelSkin( this, pWeapon );
vm->m_nBody = g_ProtagonistSystem.GetProtagonist_HandModelBody( this, pWeapon );
}
else
{
extern char g_szDefaultHandsModel[MAX_PATH];
vm->SetWeaponModel( g_szDefaultHandsModel, NULL );

vm->m_nSkin = 0;
vm->m_nBody = 0;
}
}
}
#endif

//-----------------------------------------------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions sp/src/game/server/hl2/hl2_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,15 @@ class CHL2_Player : public CBasePlayer
void AddCustomSuitDevice( int iDeviceID );
void RemoveCustomSuitDevice( int iDeviceID );
bool IsCustomSuitDeviceActive( int iDeviceID );

// Protagonist system
const char *GetProtagonistName() const;
int GetProtagonistIndex() const;
void InputSetProtagonist( inputdata_t &inputdata );
void SetProtagonist( const char *pszProtagonist );
void ResetProtagonist();
void RefreshProtagonistData();
void RefreshProtagonistWeaponData( CBaseCombatWeapon *pWeapon );
#endif

CSoundPatch *m_sndLeeches;
Expand Down Expand Up @@ -513,6 +522,12 @@ class CHL2_Player : public CBasePlayer

friend class CHL2GameMovement;

#ifdef MAPBASE
// Protagonist used by protagonist_system.h
string_t m_iszProtagonistName;
CNetworkVar( int, m_nProtagonistIndex );
#endif

#ifdef SP_ANIM_STATE
CSinglePlayerAnimState* m_pPlayerAnimState;

Expand Down
5 changes: 5 additions & 0 deletions sp/src/game/server/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4494,6 +4494,11 @@ void CBasePlayer::SetSuitUpdate(const char *name, int fgroup, int iNoRepeatTime)
return;
}

#ifdef MAPBASE
if ( HasContext("silent_suit", "1") )
return;
#endif

// if name == NULL, then clear out the queue

if (!name)
Expand Down
2 changes: 2 additions & 0 deletions sp/src/game/server/server_mapbase.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ $Project
$File "$SRCDIR\game\shared\mapbase\matchers.h"
$File "$SRCDIR\game\shared\mapbase\singleplayer_animstate.cpp"
$File "$SRCDIR\game\shared\mapbase\singleplayer_animstate.h"
$File "$SRCDIR\game\shared\mapbase\protagonist_system.cpp"
$File "$SRCDIR\game\shared\mapbase\protagonist_system.h"
$File "$SRCDIR\game\shared\mapbase\vscript_funcs_shared.cpp" [$MAPBASE_VSCRIPT]
$File "$SRCDIR\game\shared\mapbase\vscript_funcs_shared.h" [$MAPBASE_VSCRIPT]
$File "$SRCDIR\game\shared\mapbase\vscript_singletons.cpp" [$MAPBASE_VSCRIPT]
Expand Down
8 changes: 8 additions & 0 deletions sp/src/game/shared/basecombatweapon_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ bool CBaseCombatWeapon::UsesHands() const
{
return GetWpnData().m_bUsesHands;
}

int CBaseCombatWeapon::GetHandRig() const
{
return GetWpnData().m_nHandRig;
}
#endif

#ifdef EZ2
Expand Down Expand Up @@ -3248,6 +3253,9 @@ BEGIN_ENT_SCRIPTDESC( CBaseCombatWeapon, CBaseAnimating, "The base class for all
DEFINE_SCRIPTFUNC( GetViewModel, "Get the weapon's view model." )
DEFINE_SCRIPTFUNC( GetDroppedModel, "Get the weapon's unique dropped model if it has one." )

DEFINE_SCRIPTFUNC( UsesHands, "" )
DEFINE_SCRIPTFUNC( GetHandRig, "" )

DEFINE_SCRIPTFUNC( GetWeight, "Get the weapon's weight." )
DEFINE_SCRIPTFUNC( GetPrintName, "" )

Expand Down
5 changes: 3 additions & 2 deletions sp/src/game/shared/basecombatweapon_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,13 @@ class CBaseCombatWeapon : public BASECOMBATWEAPON_DERIVED_FROM
virtual bool UsesClipsForAmmo2( void ) const;
bool IsMeleeWeapon() const;
#ifdef MAPBASE
float GetViewmodelFOVOverride() const;
virtual float GetViewmodelFOVOverride() const;
float GetBobScale() const;
float GetSwayScale() const;
float GetSwaySpeedScale() const;
virtual const char *GetDroppedModel( void ) const;
bool UsesHands( void ) const;
virtual bool UsesHands( void ) const;
virtual int GetHandRig( void ) const;
#endif
#ifdef EZ2
float GetDynamicScopeFOV( void ) const;
Expand Down
Loading

0 comments on commit 8bb477d

Please sign in to comment.