Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions src/game/client/c_ai_basenpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,34 @@
#include "c_basehlplayer.h"
#endif

#ifdef MAPBASE_MP
#include "takedamageinfo.h"
#ifdef HL2MP
#include "c_hl2mp_playerresource.h"
#endif
#endif

#include "death_pose.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

#define PING_MAX_TIME 2.0

#ifdef MAPBASE_MP
BEGIN_RECV_TABLE_NOBASE( C_AI_BaseNPC, DT_BaseNPCGameData )
RecvPropInt( RECVINFO( m_iHealth ) ),
RecvPropInt( RECVINFO( m_takedamage ) ),
RecvPropInt( RECVINFO( m_bloodColor ) ),
//RecvPropString( RECVINFO( m_szNetname ) ), // Transmitted by player resource now
RecvPropInt( RECVINFO( m_nDefaultPlayerRelationship ) ),
END_RECV_TABLE();
#endif

#ifdef CAI_BaseNPC
#undef CAI_BaseNPC
#endif

IMPLEMENT_CLIENTCLASS_DT( C_AI_BaseNPC, DT_AI_BaseNPC, CAI_BaseNPC )
RecvPropInt( RECVINFO( m_lifeState ) ),
RecvPropBool( RECVINFO( m_bPerformAvoidance ) ),
Expand All @@ -31,6 +52,9 @@ IMPLEMENT_CLIENTCLASS_DT( C_AI_BaseNPC, DT_AI_BaseNPC, CAI_BaseNPC )
RecvPropInt( RECVINFO( m_bSpeedModActive ) ),
RecvPropBool( RECVINFO( m_bImportanRagdoll ) ),
RecvPropFloat( RECVINFO( m_flTimePingEffect ) ),
#ifdef MAPBASE_MP
RecvPropDataTable( "npc_gamedata", 0, 0, &REFERENCE_RECV_TABLE( DT_BaseNPCGameData ) ),
#endif
END_RECV_TABLE()

extern ConVar cl_npc_speedmod_intime;
Expand All @@ -47,6 +71,9 @@ bool NPC_IsImportantNPC( C_BaseAnimating *pAnimating )

C_AI_BaseNPC::C_AI_BaseNPC()
{
#ifdef MAPBASE_MP
SetBloodColor( DONT_BLEED );
#endif
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -183,3 +210,105 @@ bool C_AI_BaseNPC::GetRagdollInitBoneArrays( matrix3x4_t *pDeltaBones0, matrix3x
return bRet;
}

#ifdef MAPBASE_MP
//-----------------------------------------------------------------------------
// Purpose:
// Output : char const
//-----------------------------------------------------------------------------
const char *C_AI_BaseNPC::GetPlayerName( void ) const
{
#ifdef HL2MP
if (g_HL2MP_PR)
{
return g_HL2MP_PR->GetNPCName( entindex() );
}
#endif

return BaseClass::GetPlayerName();
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_AI_BaseNPC::DispatchTraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator )
{
m_fNoDamageDecal = false;

if ( info.GetAttacker() && info.GetAttacker()->IsPlayer() )
{
if ( IsPlayerAlly( ToBasePlayer( info.GetAttacker() ) ) )
{
m_fNoDamageDecal = true;
return;
}
}

BaseClass::DispatchTraceAttack( info, vecDir, ptr, pAccumulator );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_AI_BaseNPC::DecalTrace( trace_t *pTrace, char const *decalName )
{
if ( m_fNoDamageDecal )
{
// Don't do impact decals when we shouldn't
// (adapts an existing hack from singleplayer HL2, see serverside counterpart)
m_fNoDamageDecal = false;
return;
}
BaseClass::DecalTrace( pTrace, decalName );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_AI_BaseNPC::ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName )
{
if ( m_fNoDamageDecal )
{
// Don't do impact decals when we shouldn't
// (adapts an existing hack from singleplayer HL2, see serverside counterpart)
m_fNoDamageDecal = false;
return;
}
BaseClass::ImpactTrace( pTrace, iDamageType, pCustomImpactName );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool C_AI_BaseNPC::IsPlayerAlly( C_BasePlayer *pPlayer )
{
if ( pPlayer == NULL )
{
pPlayer = C_BasePlayer::GetLocalPlayer();
}

if ( pPlayer->GetTeamNumber() == TEAM_UNASSIGNED )
{
// AI relationship code isn't available here, so we currently transmit a var from the server to determine if we're, at least generically, an ally
return (m_nDefaultPlayerRelationship == GR_TEAMMATE);
}
else if (GetTeamNumber() == pPlayer->GetTeamNumber())
{
// Same team probably means allies
return true;
}

return false;
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool C_AI_BaseNPC::IsNeutralTo( C_BasePlayer *pPlayer )
{
if ( IsPlayerAlly( pPlayer ) )
return false;

return (m_nDefaultPlayerRelationship == GR_NOTTEAMMATE);
}
#endif

27 changes: 27 additions & 0 deletions src/game/client/c_ai_basenpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@


#include "c_basecombatcharacter.h"
#ifdef MAPBASE_MP
#include "ai_debug_shared.h"
#endif

// NOTE: Moved all controller code into c_basestudiomodel
class C_AI_BaseNPC : public C_BaseCombatCharacter
Expand Down Expand Up @@ -41,6 +44,17 @@ class C_AI_BaseNPC : public C_BaseCombatCharacter
void OnDataChanged( DataUpdateType_t type );
bool ImportantRagdoll( void ) { return m_bImportanRagdoll; }

#ifdef MAPBASE_MP
virtual int GetHealth() const { return m_iHealth; }

virtual const char *GetPlayerName( void ) const;
virtual void DispatchTraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator = NULL );
void DecalTrace( trace_t *pTrace, char const *decalName );
void ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName );
virtual bool IsPlayerAlly( C_BasePlayer *pPlayer = NULL );
virtual bool IsNeutralTo( C_BasePlayer *pPlayer = NULL );
#endif

private:
C_AI_BaseNPC( const C_AI_BaseNPC & ); // not defined, not accessible
float m_flTimePingEffect;
Expand All @@ -55,6 +69,19 @@ class C_AI_BaseNPC : public C_BaseCombatCharacter
bool m_bFadeCorpse;
bool m_bSpeedModActive;
bool m_bImportanRagdoll;

#ifdef MAPBASE_MP
// User-friendly name used for death notices, etc.
// Now transmitted by player resource
//char m_szNetname[32];

// Used to determine whether to draw blood, target ID, etc. on the client
// Uses first 3 gamerules relationship return codes (GR_TEAMMATE, GR_NOTTEAMMATE, and GR_ENEMY)
int m_nDefaultPlayerRelationship;

// Based on the existing decal hack from singleplayer HL2
bool m_fNoDamageDecal;
#endif
};


Expand Down
16 changes: 14 additions & 2 deletions src/game/client/c_baseanimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4322,7 +4322,13 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int

case CL_EVENT_FOOTSTEP_LEFT:
{
#ifndef HL2MP
#if !defined(HL2MP) || defined(MAPBASE_MP)
#ifdef MAPBASE_MP
// NPCs should still use footstep sounds in MP
if (!IsNPC())
break;
#endif

char pSoundName[256];
if ( !options || !options[0] )
{
Expand All @@ -4348,7 +4354,13 @@ void C_BaseAnimating::FireEvent( const Vector& origin, const QAngle& angles, int

case CL_EVENT_FOOTSTEP_RIGHT:
{
#ifndef HL2MP
#if !defined(HL2MP) || defined(MAPBASE_MP)
#ifdef MAPBASE_MP
// NPCs should still use footstep sounds in MP
if (!IsNPC())
break;
#endif

char pSoundName[256];
if ( !options || !options[0] )
{
Expand Down
19 changes: 19 additions & 0 deletions src/game/client/c_basecombatcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ void C_BaseCombatCharacter::DoMuzzleFlash()
}
}

#ifdef MAPBASE
// UNDONE: Should these operate on a list of weapon/items
Activity C_BaseCombatCharacter::Weapon_TranslateActivity( Activity baseAct, bool *pRequired )
{
Activity translated = baseAct;

if ( m_hActiveWeapon )
{
translated = m_hActiveWeapon->ActivityOverride( baseAct, pRequired );
}
else if (pRequired)
{
*pRequired = false;
}

return translated;
}
#endif

#ifdef GLOWS_ENABLE
//-----------------------------------------------------------------------------
// Purpose:
Expand Down
5 changes: 5 additions & 0 deletions src/game/client/c_basecombatcharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class C_BaseCombatCharacter : public C_BaseFlex
HSCRIPT ScriptGetWeapon( int i );
#endif

#ifdef MAPBASE
virtual Activity Weapon_TranslateActivity( Activity baseAct, bool *pRequired );
virtual Activity Weapon_BackupActivity( Activity activity, bool weaponTranslationWasRequired = false, C_BaseCombatWeapon *pSpecificWeapon = NULL );
#endif

public:

float m_flNextAttack;
Expand Down
5 changes: 5 additions & 0 deletions src/game/client/c_baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,11 @@ class C_BaseEntity : public IClientEntity
// are relative to the attachment on this entity.
void SetParent( C_BaseEntity *pParentEntity, int iParentAttachment=0 );

#ifdef MAPBASE_MP
// Some entities should predict +USE interaction
virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) {}
#endif

bool PhysicsRunThink( thinkmethods_t thinkMethod = THINK_FIRE_ALL_FUNCTIONS );
bool PhysicsRunSpecificThink( int nContextIndex, BASEPTR thinkFunc );

Expand Down
9 changes: 8 additions & 1 deletion src/game/client/c_baseplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ void C_BasePlayer::FireGameEvent( IGameEvent *event )
//-----------------------------------------------------------------------------
// returns the player name
//-----------------------------------------------------------------------------
const char * C_BasePlayer::GetPlayerName()
const char * C_BasePlayer::GetPlayerName() const
{
return g_PR ? g_PR->GetPlayerName( entindex() ) : "";
}
Expand Down Expand Up @@ -2448,6 +2448,13 @@ void C_BasePlayer::PostThink( void )
{
SetCollisionBounds( VEC_HULL_MIN, VEC_HULL_MAX );
}

#ifdef MAPBASE_MP
if ( m_hUseEntity != NULL )
{
m_hUseEntity->Use( this, this, USE_SET, 2 );
}
#endif

if ( !CommentaryModeShouldSwallowInput( this ) )
{
Expand Down
6 changes: 5 additions & 1 deletion src/game/client/c_baseplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class C_BasePlayer : public C_BaseCombatCharacter, public CGameEventListener
virtual Vector Weapon_ShootPosition();
virtual void Weapon_DropPrimary( void ) {}

#ifdef MAPBASE
virtual Activity Weapon_TranslateActivity( Activity baseAct, bool *pRequired = NULL );
#endif

virtual Vector GetAutoaimVector( float flScale );
void SetSuitUpdate(const char *name, int fgroup, int iNoRepeat);

Expand Down Expand Up @@ -310,7 +314,7 @@ class C_BasePlayer : public C_BaseCombatCharacter, public CGameEventListener
virtual void OverrideView( CViewSetup *pSetup );

// returns the player name
const char * GetPlayerName();
const char * GetPlayerName() const;
virtual const Vector GetPlayerMins( void ) const; // uses local player
virtual const Vector GetPlayerMaxs( void ) const; // uses local player

Expand Down
2 changes: 2 additions & 0 deletions src/game/client/client_hl2mp.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ $Project "Client (HL2MP)"
$File "hl2mp\c_te_hl2mp_shotgun_shot.cpp"
$File "hl2mp\clientmode_hl2mpnormal.cpp"
$File "hl2mp\clientmode_hl2mpnormal.h"
$File "hl2mp\c_hl2mp_playerresource.cpp"
$File "hl2mp\c_hl2mp_playerresource.h"
$File "$SRCDIR\game\shared\hl2mp\hl2mp_gamerules.cpp"
$File "$SRCDIR\game\shared\hl2mp\hl2mp_gamerules.h"
$File "$SRCDIR\game\shared\hl2mp\hl2mp_player_shared.cpp"
Expand Down
26 changes: 25 additions & 1 deletion src/game/client/hl2/c_basehlplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,30 @@ void C_BaseHLPlayer::BuildTransformations( CStudioHdr *hdr, Vector *pos, Quatern


#ifdef SP_ANIM_STATE
// Set the activity based on an event or current state
void C_BaseHLPlayer::SetAnimation( PLAYER_ANIM playerAnim )
{
#ifdef MAPBASE_MP
if (!m_pPlayerAnimState)
{
BaseClass::SetAnimation( playerAnim );
return;
}

m_pPlayerAnimState->SetPlayerAnimation( playerAnim );
#endif
}

void C_BaseHLPlayer::AddAnimStateLayer( int iSequence, float flBlendIn, float flBlendOut, float flPlaybackRate, bool bHoldAtEnd, bool bOnlyWhenStill )
{
#ifdef MAPBASE_MP
if (!m_pPlayerAnimState)
return;

m_pPlayerAnimState->AddMiscSequence( iSequence, flBlendIn, flBlendOut, flPlaybackRate, bHoldAtEnd, bOnlyWhenStill );
#endif
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Expand All @@ -737,7 +761,7 @@ const Vector &C_BaseHLPlayer::GetRenderOrigin()
const QAngle& C_BaseHLPlayer::GetRenderAngles( void )
{
#ifdef MAPBASE_MP
if ( m_pPlayerAnimState )
if ( m_pPlayerAnimState && !IsRagdoll() )
{
return m_pPlayerAnimState->GetRenderAngles();
}
Expand Down
3 changes: 3 additions & 0 deletions src/game/client/hl2/c_basehlplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class C_BaseHLPlayer : public C_BasePlayer
#endif

#ifdef SP_ANIM_STATE
void SetAnimation( PLAYER_ANIM playerAnim );
void AddAnimStateLayer( int iSequence, float flBlendIn, float flBlendOut, float flPlaybackRate, bool bHoldAtEnd, bool bOnlyWhenStill );

virtual const Vector& GetRenderOrigin();
virtual const QAngle& GetRenderAngles( void );
virtual CStudioHdr *OnNewModel();
Expand Down
Loading
Loading