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
14 changes: 14 additions & 0 deletions sp/src/game/client/c_basecombatweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ void C_BaseCombatWeapon::OnDataChanged( DataUpdateType_t updateType )
m_iOldState = m_iState;

m_bJustRestored = false;

#ifdef MAPBASE
if (updateType == DATA_UPDATE_CREATED)
{
Precache(); //cache weapon on client again, otherwise the client will always use default script name while server not
}

//update script in case if wanted
if (m_iOldNeedsUpdate != m_iNeedsUpdate)
{
Precache();
m_iOldNeedsUpdate = m_iNeedsUpdate; //assign new value to prevent updates on client when we don't want
}
#endif
}

//-----------------------------------------------------------------------------
Expand Down
58 changes: 57 additions & 1 deletion sp/src/game/client/hl2/hud_ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class CHudAmmo : public CHudNumericDisplay, public CHudElement
int m_iAmmo;
int m_iAmmo2;
CHudTexture *m_iconPrimaryAmmo;
#ifdef MAPBASE
int m_iOldNeedsUpdate; //needs update tracking
#endif
};

DECLARE_HUDELEMENT( CHudAmmo );
Expand All @@ -66,6 +69,9 @@ CHudAmmo::CHudAmmo( const char *pElementName ) : BaseClass(NULL, "HudAmmo"), CHu
hudlcd->SetGlobalStat( "(ammo_secondary)", "0" );
hudlcd->SetGlobalStat( "(weapon_print_name)", "" );
hudlcd->SetGlobalStat( "(weapon_name)", "" );
#ifdef MAPBASE
m_iOldNeedsUpdate = -1; // Initialize
#endif
}

//-----------------------------------------------------------------------------
Expand All @@ -75,6 +81,9 @@ void CHudAmmo::Init( void )
{
m_iAmmo = -1;
m_iAmmo2 = -1;
#ifdef MAPBASE
m_iOldNeedsUpdate = -1; // Initialize
#endif

m_iconPrimaryAmmo = NULL;

Expand Down Expand Up @@ -107,6 +116,9 @@ void CHudAmmo::Reset()
m_hCurrentVehicle = NULL;
m_iAmmo = 0;
m_iAmmo2 = 0;
#ifdef MAPBASE
m_iOldNeedsUpdate = -1; // Initialize
#endif

UpdateAmmoDisplays();
}
Expand Down Expand Up @@ -158,7 +170,12 @@ void CHudAmmo::UpdatePlayerAmmo( C_BasePlayer *player )
hudlcd->SetGlobalStat( "(ammo_primary)", VarArgs( "%d", ammo1 ) );
hudlcd->SetGlobalStat( "(ammo_secondary)", VarArgs( "%d", ammo2 ) );

#ifdef MAPBASE
int iNeedsUpdate = wpn ? wpn->m_iOldNeedsUpdate : -1;
if (wpn == m_hCurrentActiveWeapon && m_iOldNeedsUpdate == iNeedsUpdate)
#else
if (wpn == m_hCurrentActiveWeapon)
#endif
{
// same weapon, just update counts
SetAmmo(ammo1, true);
Expand All @@ -185,6 +202,10 @@ void CHudAmmo::UpdatePlayerAmmo( C_BasePlayer *player )
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("WeaponChanged");
m_hCurrentActiveWeapon = wpn;
}

#ifdef MAPBASE
m_iOldNeedsUpdate = iNeedsUpdate;
#endif
}

void CHudAmmo::UpdateVehicleAmmo( C_BasePlayer *player, IClientVehicle *pVehicle )
Expand Down Expand Up @@ -362,13 +383,20 @@ class CHudSecondaryAmmo : public CHudNumericDisplay, public CHudElement
CHudSecondaryAmmo( const char *pElementName ) : BaseClass( NULL, "HudAmmoSecondary" ), CHudElement( pElementName )
{
m_iAmmo = -1;
#ifdef MAPBASE
m_iOldNeedsUpdate = -1;
#endif

SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_WEAPONSELECTION | HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT );
}

void Init( void )
{
#ifndef HL2MP
#ifdef MAPBASE
m_iOldNeedsUpdate = -1;
#endif

wchar_t *tempString = g_pVGuiLocalize->Find("#Valve_Hud_AMMO_ALT");
if (tempString)
{
Expand Down Expand Up @@ -414,6 +442,9 @@ class CHudSecondaryAmmo : public CHudNumericDisplay, public CHudElement
// hud reset, update ammo state
BaseClass::Reset();
m_iAmmo = 0;
#ifdef MAPBASE
m_iOldNeedsUpdate = -1;
#endif
m_hCurrentActiveWeapon = NULL;
SetAlpha( 0 );
UpdateAmmoState();
Expand Down Expand Up @@ -473,9 +504,14 @@ class CHudSecondaryAmmo : public CHudNumericDisplay, public CHudElement
SetAmmo(player->GetAmmoCount(wpn->GetSecondaryAmmoType()));
}

#ifdef MAPBASE
int iNeedsUpdate = wpn ? wpn->m_iOldNeedsUpdate : -1;
if (m_hCurrentActiveWeapon != wpn || m_iOldNeedsUpdate != iNeedsUpdate)
#else
if ( m_hCurrentActiveWeapon != wpn )
#endif
{
if ( wpn->UsesSecondaryAmmo() )
if (wpn && wpn->UsesSecondaryAmmo())
{
// we've changed to a weapon that uses secondary ammo
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("WeaponUsesSecondaryAmmo");
Expand All @@ -487,15 +523,35 @@ class CHudSecondaryAmmo : public CHudNumericDisplay, public CHudElement
}
m_hCurrentActiveWeapon = wpn;

#ifndef MAPBASE
// Get the icon we should be displaying
m_iconSecondaryAmmo = gWR.GetAmmoIconFromWeapon( m_hCurrentActiveWeapon->GetSecondaryAmmoType() );
#endif
}

#ifdef MAPBASE
// Always update the icon if weapon is valid
if (wpn && wpn->UsesSecondaryAmmo())
{
m_iconSecondaryAmmo = gWR.GetAmmoIconFromWeapon(wpn->GetSecondaryAmmoType());
}
else
{
m_iconSecondaryAmmo = nullptr;
}

// Update m_iOldNeedsUpdate
m_iOldNeedsUpdate = iNeedsUpdate;
#endif
}

private:
CHandle< C_BaseCombatWeapon > m_hCurrentActiveWeapon;
CHudTexture *m_iconSecondaryAmmo;
int m_iAmmo;
#ifdef MAPBASE
int m_iOldNeedsUpdate; //needs update tracking
#endif
};

DECLARE_HUDELEMENT( CHudSecondaryAmmo );
Expand Down
6 changes: 4 additions & 2 deletions sp/src/game/client/weapon_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,10 @@ void CBaseHudWeaponSelection::SwitchToLastWeapon( void )
void CBaseHudWeaponSelection::SetWeaponSelected( void )
{
Assert( GetSelectedWeapon() );
// Mark selection so that it's placed into next CUserCmd created
input->MakeWeaponSelection( GetSelectedWeapon() );

//Mark selection so that it's placed into next CUserCmd created if isn't active (or we'll get prediction glitch with custom scripts)
if(GetSelectedWeapon() != GetActiveWeapon())
input->MakeWeaponSelection( GetSelectedWeapon() );
}


Expand Down
4 changes: 2 additions & 2 deletions sp/src/game/server/ai_basenpc_squad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ int CAI_BaseNPC::NumWeaponsInSquad( const char *pszWeaponClassname )

if( !GetSquad() )
{
if( GetActiveWeapon() && GetActiveWeapon()->m_iClassname == iszWeaponClassname )
if(GetActiveWeapon() && FClassnameIs(GetActiveWeapon(), iszWeaponClassname.ToCStr()))
{
// I'm alone in my squad, but I do have this weapon.
return 1;
Expand All @@ -281,7 +281,7 @@ int CAI_BaseNPC::NumWeaponsInSquad( const char *pszWeaponClassname )
CAI_BaseNPC *pSquadmate = m_pSquad->GetFirstMember( &iter );
while ( pSquadmate )
{
if( pSquadmate->GetActiveWeapon() && pSquadmate->GetActiveWeapon()->m_iClassname == iszWeaponClassname )
if(pSquadmate->GetActiveWeapon() && FClassnameIs(pSquadmate->GetActiveWeapon(), iszWeaponClassname.ToCStr()))
{
count++;
}
Expand Down
9 changes: 7 additions & 2 deletions sp/src/game/server/basecombatweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,13 @@ CBaseEntity* CBaseCombatWeapon::Respawn( void )
// will decide when to make the weapon visible and touchable.
CBaseEntity *pNewWeapon = CBaseEntity::Create( GetClassname(), g_pGameRules->VecWeaponRespawnSpot( this ), GetLocalAngles(), GetOwnerEntity() );

if ( pNewWeapon )
if (pNewWeapon)
{
#ifdef MAPBASE
pNewWeapon->KeyValue("weaponscriptname", GetClassname()); // pass along the script name
pNewWeapon->Precache(); // precache it here to avoid prediction errors
pNewWeapon->SetModel(GetWorldModel()); // fix bbox for world model
#endif // MAPBASE
pNewWeapon->AddEffects( EF_NODRAW );// invisible for now
pNewWeapon->SetTouch( NULL );// no touch
pNewWeapon->SetThink( &CBaseCombatWeapon::AttemptToMaterialize );
Expand All @@ -215,7 +220,7 @@ CBaseEntity* CBaseCombatWeapon::Respawn( void )
}
else
{
Warning("Respawn failed to create %s!\n", GetClassname() );
Warning("Respawn failed to create %s!\n", GetClassname());
}

return pNewWeapon;
Expand Down
9 changes: 5 additions & 4 deletions sp/src/game/server/baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,10 @@ class CBaseEntity : public IServerEntity
const char* GetPreTemplateName(); // Not threadsafe. Get the name stripped of template unique decoration

bool NameMatches( const char *pszNameOrWildcard );
bool ClassMatches( const char *pszClassOrWildcard );
bool NameMatches( string_t nameStr );
bool ClassMatches( string_t nameStr );

virtual bool ClassMatches( string_t nameStr );
virtual bool ClassMatches( const char *pszClassOrWildcard );

private:
bool NameMatchesComplex( const char *pszNameOrWildcard );
Expand Down Expand Up @@ -820,8 +821,8 @@ class CBaseEntity : public IServerEntity
bool ReadKeyField( const char *varName, variant_t *var );

// classname access
void SetClassname( const char *className );
const char* GetClassname();
void SetClassname( const char *className );
virtual const char* GetClassname();

// Debug Overlays
void EntityText( int text_offset, const char *text, float flDuration, int r = 255, int g = 255, int b = 255, int a = 255 );
Expand Down
8 changes: 4 additions & 4 deletions sp/src/game/server/gameweaponmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void WeaponManager_AmmoMod( CBaseCombatWeapon *pWeapon )
{
for ( int i = 0; i < g_Managers.Count(); i++ )
{
if ( g_Managers[i]->m_iszWeaponName == pWeapon->m_iClassname )
if (FClassnameIs(pWeapon, g_Managers[i]->m_iszWeaponName.ToCStr()))
{
int iNewClip = (int)(pWeapon->m_iClip1 * g_Managers[i]->m_flAmmoMod);
int iNewRandomClip = iNewClip + RandomInt( -2, 2 );
Expand All @@ -111,7 +111,7 @@ void WeaponManager_AddManaged( CBaseEntity *pWeapon )
{
for ( int i = 0; i < g_Managers.Count(); i++ )
{
if ( g_Managers[i]->m_iszWeaponName == pWeapon->m_iClassname )
if (FClassnameIs(pWeapon, g_Managers[i]->m_iszWeaponName.ToCStr()))
{
Assert( g_Managers[i]->m_ManagedNonWeapons.Find( pWeapon ) == g_Managers[i]->m_ManagedNonWeapons.InvalidIndex() );
g_Managers[i]->m_ManagedNonWeapons.AddToTail( pWeapon );
Expand All @@ -124,7 +124,7 @@ void WeaponManager_RemoveManaged( CBaseEntity *pWeapon )
{
for ( int i = 0; i < g_Managers.Count(); i++ )
{
if ( g_Managers[i]->m_iszWeaponName == pWeapon->m_iClassname )
if (FClassnameIs(pWeapon, g_Managers[i]->m_iszWeaponName.ToCStr()))
{
int j = g_Managers[i]->m_ManagedNonWeapons.Find( pWeapon );
if ( j != g_Managers[i]->m_ManagedNonWeapons.InvalidIndex() )
Expand Down Expand Up @@ -213,7 +213,7 @@ void CGameWeaponManager::Think()
CBaseEntity *pEntity = m_ManagedNonWeapons[i];
if ( pEntity )
{
Assert( pEntity->m_iClassname == m_iszWeaponName );
Assert(FClassnameIs(pEntity, m_iszWeaponName.ToCStr()));
if ( !pEntity->IsEffectActive( EF_NODRAW ) )
{
candidates.AddToTail( pEntity );
Expand Down
6 changes: 3 additions & 3 deletions sp/src/game/server/hl2/npc_alyx_episodic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,7 @@ void CNPC_Alyx::Weapon_Drop( CBaseCombatWeapon *pWeapon, const Vector *pvecTarge
{
BaseClass::Weapon_Drop( pWeapon, pvecTarget, pVelocity );

if( pWeapon && pWeapon->ClassMatches( CLASSNAME_ALYXGUN ) )
if(pWeapon && pWeapon->ClassMatches(CLASSNAME_ALYXGUN.ToCStr()))
{
pWeapon->SUB_Remove();
}
Expand Down Expand Up @@ -3256,7 +3256,7 @@ void CNPC_Alyx::OnChangeActiveWeapon( CBaseCombatWeapon *pOldWeapon, CBaseCombat
void CNPC_Alyx::OnGivenWeapon( CBaseCombatWeapon *pNewWeapon )
{
// HACK: This causes Alyx to pull her gun from a holstered position
if ( pNewWeapon->ClassMatches( CLASSNAME_ALYXGUN ) )
if (pNewWeapon->ClassMatches(CLASSNAME_ALYXGUN.ToCStr()))
{
// Put it away so we can pull it out properly
GetActiveWeapon()->Holster();
Expand All @@ -3279,7 +3279,7 @@ void CNPC_Alyx::Weapon_Equip( CBaseCombatWeapon *pWeapon )
//-----------------------------------------------------------------------------
bool CNPC_Alyx::Weapon_CanUse( CBaseCombatWeapon *pWeapon )
{
if( !pWeapon->ClassMatches( CLASSNAME_SHOTGUN ) )
if(!pWeapon->ClassMatches(CLASSNAME_SHOTGUN.ToCStr()))
return false;

return BaseClass::Weapon_CanUse( pWeapon );
Expand Down
13 changes: 11 additions & 2 deletions sp/src/game/server/hl2/npc_citizen17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,18 +924,27 @@ void CNPC_Citizen::FixupMattWeapon()
if ( pWeapon && pWeapon->ClassMatches( "weapon_crowbar" ) && NameMatches( "matt" ) )
#endif
{
#ifdef MAPBASE
variant_t tmpVar;

tmpVar.SetString(MAKE_STRING("weapon_mattpipe"));
pWeapon->AcceptInput("ChangeScript", this, this, tmpVar, 0);

//weapon doesn't save the prevent pick up flag when dropped, set the flag when needed (death in this case)
tmpVar.SetString(MAKE_STRING("OnDeath matt_weapon:AddOutput:spawnflags 2:0.00:1"));
AcceptInput("AddOutput", this, this, tmpVar, 0);
#else
Weapon_Drop( pWeapon );
UTIL_Remove( pWeapon );
pWeapon = (CBaseCombatWeapon *)CREATE_UNSAVED_ENTITY( CMattsPipe, "weapon_crowbar" );
pWeapon->SetName( AllocPooledString( "matt_weapon" ) );
DispatchSpawn( pWeapon );
#endif

#ifdef DEBUG
extern bool g_bReceivedChainedActivate;
g_bReceivedChainedActivate = false;
#endif
pWeapon->Activate();
Weapon_Equip( pWeapon );
}
}

Expand Down
10 changes: 5 additions & 5 deletions sp/src/game/server/hl2/npc_combine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3824,7 +3824,7 @@ void CNPC_Combine::OnEndMoveAndShoot()
WeaponProficiency_t CNPC_Combine::CalcWeaponProficiency( CBaseCombatWeapon *pWeapon )
{
#ifdef MAPBASE
if( pWeapon->ClassMatches( gm_isz_class_AR2 ) )
if( pWeapon->ClassMatches( gm_isz_class_AR2.ToCStr() ) )
#else
if( FClassnameIs( pWeapon, "weapon_ar2" ) )
#endif
Expand All @@ -3839,7 +3839,7 @@ WeaponProficiency_t CNPC_Combine::CalcWeaponProficiency( CBaseCombatWeapon *pWea
}
}
#ifdef MAPBASE
else if( pWeapon->ClassMatches( gm_isz_class_Shotgun ) )
else if( pWeapon->ClassMatches( gm_isz_class_Shotgun.ToCStr() ) )
#else
else if( FClassnameIs( pWeapon, "weapon_shotgun" ) )
#endif
Expand All @@ -3854,15 +3854,15 @@ WeaponProficiency_t CNPC_Combine::CalcWeaponProficiency( CBaseCombatWeapon *pWea
return WEAPON_PROFICIENCY_PERFECT;
}
#ifdef MAPBASE
else if( pWeapon->ClassMatches( gm_isz_class_SMG1 ) )
else if( pWeapon->ClassMatches( gm_isz_class_SMG1.ToCStr() ) )
#else
else if( FClassnameIs( pWeapon, "weapon_smg1" ) )
#endif
{
return WEAPON_PROFICIENCY_GOOD;
}
#ifdef MAPBASE
else if ( pWeapon->ClassMatches( gm_isz_class_Pistol ) )
else if ( pWeapon->ClassMatches( gm_isz_class_Pistol.ToCStr() ) )
{
// Mods which need a lower soldier pistol accuracy can either change this value or use proficiency override in Hammer.
return WEAPON_PROFICIENCY_VERY_GOOD;
Expand All @@ -3876,7 +3876,7 @@ WeaponProficiency_t CNPC_Combine::CalcWeaponProficiency( CBaseCombatWeapon *pWea
//-----------------------------------------------------------------------------
bool CNPC_Combine::HasShotgun()
{
if( GetActiveWeapon() && GetActiveWeapon()->m_iClassname == s_iszShotgunClassname )
if (GetActiveWeapon() && FClassnameIs(GetActiveWeapon(), s_iszShotgunClassname.ToCStr()))
{
return true;
}
Expand Down
Loading