Skip to content
Closed
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
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
4 changes: 4 additions & 0 deletions 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
70 changes: 0 additions & 70 deletions src/game/server/basecombatcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2800,76 +2800,6 @@ bool CBaseCombatCharacter::Weapon_CanUse( CBaseCombatWeapon *pWeapon )
return true;
}

#ifdef MAPBASE

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
static Activity Weapon_BackupActivityFromList( CBaseCombatCharacter *pBCC, acttable_t *pTable, int actCount, Activity activity, bool weaponTranslationWasRequired, CBaseCombatWeapon *pWeapon )
{
int i = 0;
for ( ; i < actCount; i++, pTable++ )
{
if ( activity == pTable->baseAct )
{
// Don't pick backup activities we don't actually have an animation for.
if (!pBCC->GetModelPtr()->HaveSequenceForActivity(pTable->weaponAct))
break;

return (Activity)pTable->weaponAct;
}
}

// We didn't succeed in finding an activity. See if we can recurse
acttable_t *pBackupTable = CBaseCombatWeapon::GetDefaultBackupActivityList( pTable - i, actCount );
if (pBackupTable)
{
return Weapon_BackupActivityFromList( pBCC, pBackupTable, actCount, activity, weaponTranslationWasRequired, pWeapon );
}

return activity;
}

//-----------------------------------------------------------------------------
// Purpose: Uses an activity from a different weapon when the activity we were originally looking for does not exist on this character.
// This gives NPCs and players the ability to use weapons they are otherwise unable to use.
//-----------------------------------------------------------------------------
Activity CBaseCombatCharacter::Weapon_BackupActivity( Activity activity, bool weaponTranslationWasRequired, CBaseCombatWeapon *pSpecificWeapon )
{
CBaseCombatWeapon *pWeapon = pSpecificWeapon ? pSpecificWeapon : GetActiveWeapon();
if (!pWeapon)
return activity;

// Make sure the weapon allows this activity to have a backup.
if (!pWeapon->SupportsBackupActivity(activity))
return activity;

// UNDONE: Sometimes, a NPC is supposed to use the default activity. Return that if the weapon translation was "not required" and we have an original activity.
/*
if (!weaponTranslationWasRequired && GetModelPtr()->HaveSequenceForActivity(activity) && !IsPlayer())
{
return activity;
}
*/

acttable_t *pTable = pWeapon->GetBackupActivityList();
int actCount = pWeapon->GetBackupActivityListCount();
if (!pTable)
{
// Look for a default list
acttable_t *pTable = pWeapon->ActivityList( actCount );
pTable = CBaseCombatWeapon::GetDefaultBackupActivityList( pTable, actCount );
}

if (pTable && GetModelPtr())
{
return Weapon_BackupActivityFromList( this, pTable, actCount, activity, weaponTranslationWasRequired, pWeapon );
}

return activity;
}
#endif

//-----------------------------------------------------------------------------
// Purpose:
// Input :
Expand Down
27 changes: 0 additions & 27 deletions src/game/server/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8149,33 +8149,6 @@ void CBasePlayer::Weapon_Equip( CBaseCombatWeapon *pWeapon )
}
}

#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Activity CBasePlayer::Weapon_TranslateActivity( Activity baseAct, bool *pRequired )
{
Activity weaponTranslation = BaseClass::Weapon_TranslateActivity( baseAct, pRequired );

if ( GetActiveWeapon() && !GetActiveWeapon()->IsWeaponVisible() && baseAct != ACT_ARM )
{
// Our weapon is holstered. Use the base activity.
return baseAct;
}
if ( GetModelPtr() && (!GetModelPtr()->HaveSequenceForActivity(weaponTranslation) || baseAct == weaponTranslation) )
{
// This is used so players can fall back to backup activities in the same way NPCs in Mapbase can
Activity backupActivity = Weapon_BackupActivity(baseAct, pRequired ? *pRequired : false);
if ( baseAct != backupActivity && GetModelPtr()->HaveSequenceForActivity(backupActivity) )
return backupActivity;

return baseAct;
}

return weaponTranslation;
}
#endif


//=========================================================
// HasNamedPlayerItem Does the player already have this item?
Expand Down
32 changes: 32 additions & 0 deletions src/game/server/soundent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "soundent.h"
#include "game.h"
#include "world.h"
#ifdef MAPBASE_MP
#include "ai_basenpc.h"
#endif

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down Expand Up @@ -459,6 +462,35 @@ void CSoundEnt::InsertSound ( int iType, const Vector &vecOrigin, int iVolume, f
if ( !g_pSoundEnt )
return;

#if defined(MAPBASE_MP) && defined(HL2MP)
// Mapbase adds AI sounds to HL2DM weapons, but this fills up the list very quickly and isn't needed when NPCs aren't actually being used
// Ignore weapon sounds when we're reasonably certain they wouldn't be useful
if ( soundChannelIndex == SOUNDENT_CHANNEL_WEAPON )
{
bool bHasNPCNearby = false;
CAI_BaseNPC **ppAIs = g_AI_Manager.AccessAIs();
for ( int i = 0; i < g_AI_Manager.NumAIs(); i++ )
{
CAI_BaseNPC *pNPC = ppAIs[i];

if ( !pNPC->IsAlive() || pNPC == pOwner )
continue;

// Is there any chance this NPC would hear me?
Vector vecDistSqr = vecOrigin - pNPC->EarPosition();
if (vecDistSqr.LengthSqr() > Square(iVolume))
continue;

bHasNPCNearby = true;
break;
}

// Just don't if there's no NPC nearby
if (!bHasNPCNearby)
return;
}
#endif

if( soundChannelIndex == SOUNDENT_CHANNEL_UNSPECIFIED )
{
// No sound channel specified. So just make a new sound.
Expand Down
21 changes: 21 additions & 0 deletions src/game/shared/ai_basenpc_shared.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//

#ifndef AI_BASENPC_SHARED_H
#define AI_BASENPC_SHARED_H

#ifdef CLIENT_DLL
#include "c_ai_basenpc.h"
#else
#include "ai_basenpc.h"
#endif

#ifdef CLIENT_DLL
#define CAI_BaseNPC C_AI_BaseNPC
#endif

#endif // AI_BASENPC_SHARED_H
69 changes: 69 additions & 0 deletions src/game/shared/basecombatcharacter_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,75 @@ void CBaseCombatCharacter::InputSetBloodColor( inputdata_t &inputdata )
}
#endif

#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
static Activity Weapon_BackupActivityFromList( CBaseCombatCharacter *pBCC, acttable_t *pTable, int actCount, Activity activity, bool weaponTranslationWasRequired, CBaseCombatWeapon *pWeapon )
{
int i = 0;
for ( ; i < actCount; i++, pTable++ )
{
if ( activity == pTable->baseAct )
{
// Don't pick backup activities we don't actually have an animation for.
if (!pBCC->GetModelPtr()->HaveSequenceForActivity(pTable->weaponAct))
break;

return (Activity)pTable->weaponAct;
}
}

// We didn't succeed in finding an activity. See if we can recurse
acttable_t *pBackupTable = CBaseCombatWeapon::GetDefaultBackupActivityList( pTable - i, actCount );
if (pBackupTable)
{
return Weapon_BackupActivityFromList( pBCC, pBackupTable, actCount, activity, weaponTranslationWasRequired, pWeapon );
}

return activity;
}

//-----------------------------------------------------------------------------
// Purpose: Uses an activity from a different weapon when the activity we were originally looking for does not exist on this character.
// This gives NPCs and players the ability to use weapons they are otherwise unable to use.
//-----------------------------------------------------------------------------
Activity CBaseCombatCharacter::Weapon_BackupActivity( Activity activity, bool weaponTranslationWasRequired, CBaseCombatWeapon *pSpecificWeapon )
{
CBaseCombatWeapon *pWeapon = pSpecificWeapon ? pSpecificWeapon : GetActiveWeapon();
if (!pWeapon)
return activity;

// Make sure the weapon allows this activity to have a backup.
if (!pWeapon->SupportsBackupActivity(activity))
return activity;

// UNDONE: Sometimes, a NPC is supposed to use the default activity. Return that if the weapon translation was "not required" and we have an original activity.
/*
if (!weaponTranslationWasRequired && GetModelPtr()->HaveSequenceForActivity(activity) && !IsPlayer())
{
return activity;
}
*/

acttable_t *pTable = pWeapon->GetBackupActivityList();
int actCount = pWeapon->GetBackupActivityListCount();
if (!pTable)
{
// Look for a default list
acttable_t *pDefaultTable = pWeapon->ActivityList( actCount );
pTable = CBaseCombatWeapon::GetDefaultBackupActivityList( pDefaultTable, actCount );
}

if (pTable && GetModelPtr())
{
return Weapon_BackupActivityFromList( this, pTable, actCount, activity, weaponTranslationWasRequired, pWeapon );
}

return activity;
}
#endif

//-----------------------------------------------------------------------------
/**
The main visibility check. Checks all the entity specific reasons that could
Expand Down
10 changes: 8 additions & 2 deletions src/game/shared/basecombatweapon_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ WeaponClass_t CBaseCombatWeapon::WeaponClassFromString(const char *str)
return WEPCLASS_INVALID;
}

#ifdef HL2_DLL
#if defined(HL2_DLL) || defined(HL2MP) // HL2MP is effectively used here as "present on client in MP"
extern acttable_t *GetSMG1Acttable();
extern int GetSMG1ActtableCount();

Expand Down Expand Up @@ -1206,7 +1206,7 @@ int CBaseCombatWeapon::GetBackupActivityListCount()
//-----------------------------------------------------------------------------
acttable_t *CBaseCombatWeapon::GetDefaultBackupActivityList( acttable_t *pTable, int &actCount )
{
#ifdef HL2_DLL
#if defined(HL2_DLL) || defined(HL2MP) // HL2MP is effectively used here as "present on client in MP"
// Ensure this isn't already a default backup activity list
if (pTable == GetSMG1Acttable() || pTable == GetPistolActtable())
return NULL;
Expand Down Expand Up @@ -1318,6 +1318,9 @@ void CBaseCombatWeapon::SetActivity( Activity act, float duration )
{
//Adrian: Oh man...
#if !defined( CLIENT_DLL ) && (defined( HL2MP ) || defined( PORTAL ))
#ifdef MAPBASE_MP
if ( GetOwner() && GetOwner()->IsPlayer() )
#endif
SetModel( GetWorldModel() );
#endif

Expand All @@ -1329,6 +1332,9 @@ void CBaseCombatWeapon::SetActivity( Activity act, float duration )

//Adrian: Oh man again...
#if !defined( CLIENT_DLL ) && (defined( HL2MP ) || defined( PORTAL ))
#ifdef MAPBASE_MP
if ( GetOwner() && GetOwner()->IsPlayer() )
#endif
SetModel( GetViewModel() );
#endif

Expand Down
35 changes: 35 additions & 0 deletions src/game/shared/baseplayer_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,41 @@ void CBasePlayer::SelectLastItem(void)
}


#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Activity CBasePlayer::Weapon_TranslateActivity( Activity baseAct, bool *pRequired )
{
Activity weaponTranslation = BaseClass::Weapon_TranslateActivity( baseAct, pRequired );

#ifdef CLIENT_DLL
// Since other players' weapons have invisible viewmodels
bool bWeaponNotVisible = (GetActiveWeapon() && GetActiveWeapon()->IsEffectActive( EF_NODRAW )) ? true : false;
#else
bool bWeaponNotVisible = (GetActiveWeapon() && !GetActiveWeapon()->IsWeaponVisible()) ? true : false;
#endif

if ( bWeaponNotVisible && baseAct != ACT_ARM )
{
// Our weapon is holstered. Use the base activity.
return baseAct;
}
if ( GetModelPtr() && (!GetModelPtr()->HaveSequenceForActivity(weaponTranslation) || baseAct == weaponTranslation) )
{
// This is used so players can fall back to backup activities in the same way NPCs in Mapbase can
Activity backupActivity = Weapon_BackupActivity(baseAct, pRequired ? *pRequired : false);
if ( baseAct != backupActivity && GetModelPtr()->HaveSequenceForActivity(backupActivity) )
return backupActivity;

return baseAct;
}

return weaponTranslation;
}
#endif


//-----------------------------------------------------------------------------
// Purpose: Abort any reloads we're in
//-----------------------------------------------------------------------------
Expand Down
Loading
Loading