fix third person effects

fix some of the third person weapon effects (local player switching
between first and third person)
This commit is contained in:
tonysergi 2013-12-06 12:37:49 +09:00
parent 705d10cf52
commit 052c5c39b4
7 changed files with 92 additions and 62 deletions

View file

@ -1854,6 +1854,13 @@ void C_BasePlayer::ThirdPersonSwitch( bool bThirdperson )
}
}
}
//Notify weapon.
CBaseCombatWeapon *pWeapon = GetActiveWeapon();
if ( pWeapon )
{
pWeapon->ThirdPersonSwitch( bThirdperson );
}
}
}

View file

@ -512,6 +512,9 @@ public:
bool WantsToOverrideViewmodelAttachments( void ) { return false; }
#endif
//Tony; notifications of any third person switches.
virtual void ThirdPersonSwitch( bool bThirdPerson ) {};
#endif // End client-only methods
virtual bool CanLower( void ) { return false; }

View file

@ -792,29 +792,34 @@ void CWeaponCrossbow::DoLoadEffect( void )
if ( pOwner == NULL )
return;
CBaseViewModel *pViewModel = pOwner->GetViewModel();
if ( pViewModel == NULL )
return;
//Tony; change this up a bit; on the server, dispatch an effect but don't send it to the client who fires
//on the client, create an effect either in the view model, or on the world model if first person.
CEffectData data;
#ifdef CLIENT_DLL
data.m_hEntity = pViewModel->GetRefEHandle();
#else
data.m_nEntIndex = pViewModel->entindex();
#endif
data.m_nAttachmentIndex = 1;
data.m_vOrigin = pOwner->GetAbsOrigin();
DispatchEffect( "CrossbowLoad", data );
CPASFilter filter( data.m_vOrigin );
#ifdef GAME_DLL
filter.RemoveRecipient( pOwner );
data.m_nEntIndex = entindex();
#else
CBaseViewModel *pViewModel = pOwner->GetViewModel();
if ( ShouldDrawUsingViewModel() && pViewModel != NULL )
data.m_hEntity = pViewModel->GetRefEHandle();
else
data.m_hEntity = GetRefEHandle();
#endif
DispatchEffect( "CrossbowLoad", data, filter );
#ifndef CLIENT_DLL
CSprite *pBlast = CSprite::SpriteCreate( CROSSBOW_GLOW_SPRITE2, GetAbsOrigin(), false );
if ( pBlast )
{
pBlast->SetAttachment( pOwner->GetViewModel(), 1 );
pBlast->SetAttachment( this, 1 );
pBlast->SetTransparency( kRenderTransAdd, 255, 255, 255, 255, kRenderFxNone );
pBlast->SetBrightness( 128 );
pBlast->SetScale( 0.2f );

View file

@ -1224,7 +1224,9 @@ protected:
bool m_bOldOpen; // Used for parity checks
void NotifyShouldTransmit( ShouldTransmitState_t state );
private:
virtual void ThirdPersonSwitch( bool bThirdPerson );
protected:
#endif // CLIENT_DLL
int m_nChangeState; // For delayed state change of elements
@ -2601,56 +2603,26 @@ void CWeaponPhysCannon::DoEffectIdle( void )
StartEffects();
//if ( ShouldDrawUsingViewModel() )
// Turn on the glow sprites
for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ )
{
// Turn on the glow sprites
for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ )
{
m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 0.075f, 0.05f ) * SPRITE_SCALE );
m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 24, 32 ) );
}
// Turn on the glow sprites
for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ )
{
m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 3, 5 ) );
m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 200, 255 ) );
}
if ( m_EffectState != EFFECT_HOLDING )
{
// Turn beams off
m_Beams[0].SetVisible( false );
m_Beams[1].SetVisible( false );
m_Beams[2].SetVisible( false );
}
m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 0.075f, 0.05f ) * SPRITE_SCALE );
m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 24, 32 ) );
}
/*
else
// Turn on the glow sprites
for ( int i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ )
{
// Turn on the glow sprites
for ( int i = PHYSCANNON_GLOW1; i < (PHYSCANNON_GLOW1+NUM_GLOW_SPRITES); i++ )
{
m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 0.075f, 0.05f ) * SPRITE_SCALE );
m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 24, 32 ) );
}
// Turn on the glow sprites
for ( i = PHYSCANNON_ENDCAP1; i < (PHYSCANNON_ENDCAP1+NUM_ENDCAP_SPRITES); i++ )
{
m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 3, 5 ) );
m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 200, 255 ) );
}
if ( m_EffectState != EFFECT_HOLDING )
{
// Turn beams off
m_Beams[0].SetVisible( false );
m_Beams[1].SetVisible( false );
m_Beams[2].SetVisible( false );
}
m_Parameters[i].GetScale().SetAbsolute( random->RandomFloat( 3, 5 ) );
m_Parameters[i].GetAlpha().SetAbsolute( random->RandomInt( 200, 255 ) );
}
if ( m_EffectState != EFFECT_HOLDING )
{
// Turn beams off
m_Beams[0].SetVisible( false );
m_Beams[1].SetVisible( false );
m_Beams[2].SetVisible( false );
}
*/
#endif
}
@ -2957,6 +2929,15 @@ void CWeaponPhysCannon::StopEffects( bool stopSound )
#endif // !CLIENT_DLL
}
#ifdef CLIENT_DLL
void CWeaponPhysCannon::ThirdPersonSwitch( bool bThirdPerson )
{
//Tony; if we switch to first or third person or whatever, destroy and recreate the effects.
//Note: the sound only ever gets shut off on the server, so it's okay - as this is entirely client side.
DestroyEffects();
StartEffects();
}
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------

View file

@ -1882,6 +1882,19 @@ void CWeaponRPG::GetWeaponAttachment( int attachmentId, Vector &outVector, Vecto
}
}
//Tony; added so when the rpg switches to third person, the beam etc is re-created.
void CWeaponRPG::ThirdPersonSwitch( bool bThirdPerson )
{
if ( m_pBeam != NULL )
{
//Tell it to die right away and let the beam code free it.
m_pBeam->brightness = 0.0f;
m_pBeam->flags &= ~FBEAM_FOREVER;
m_pBeam->die = gpGlobals->curtime - 0.1;
m_pBeam = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose: Setup our laser beam
//-----------------------------------------------------------------------------
@ -2230,7 +2243,7 @@ int CLaserDot::DrawModel( int flags )
if ( pOwner != NULL && pOwner->IsDormant() == false )
{
// Always draw the dot in front of our faces when in first-person
if ( pOwner->IsLocalPlayer() )
if ( pOwner->IsLocalPlayer() && C_BasePlayer::LocalPlayerInFirstPersonView() ) //Tony; !!!
{
// Take our view position and orientation
vecAttachment = CurrentViewOrigin();

View file

@ -238,6 +238,9 @@ public:
CMaterialReference m_hBeamMaterial; // Used for the laser beam
Beam_t *m_pBeam; // Laser beam temp entity
//Tony; third person check thing, to destroy/reinitialize the beam ( swapping first -> third or back, etc )
virtual void ThirdPersonSwitch( bool bThirdPerson );
#endif //CLIENT_DLL
CBaseEntity *GetMissile( void ) { return m_hMissile; }

View file

@ -68,7 +68,7 @@ public:
virtual void OnDataChanged( DataUpdateType_t updateType );
virtual RenderGroup_t GetRenderGroup( void );
virtual void ViewModelDrawn( C_BaseViewModel *pBaseViewModel );
virtual bool IsTransparent( void );
#endif
virtual void Precache();
@ -123,6 +123,9 @@ private:
float m_flFadeTime;
//Tony; third person check thing, this has to be done for the local player if third person switches, so we can re-calc attachment points.
virtual void ThirdPersonSwitch( bool bThirdPerson );
#endif
CNetworkVar( bool, m_bActive );
@ -447,6 +450,10 @@ void CWeaponStunStick::SetStunState( bool state )
bool CWeaponStunStick::Deploy( void )
{
SetStunState( true );
#ifdef CLIENT_DLL
//Tony; we need to just do this
SetupAttachmentPoints();
#endif
return BaseClass::Deploy();
}
@ -842,6 +849,10 @@ void C_WeaponStunStick::DrawFirstPersonEffects( void )
}
}
void C_WeaponStunStick::ThirdPersonSwitch( bool bThirdPerson )
{
SetupAttachmentPoints();
}
//-----------------------------------------------------------------------------
// Purpose: Draw our special effects
//-----------------------------------------------------------------------------
@ -872,6 +883,13 @@ void C_WeaponStunStick::ViewModelDrawn( C_BaseViewModel *pBaseViewModel )
BaseClass::ViewModelDrawn( pBaseViewModel );
}
//-----------------------------------------------------------------------------
// Purpose: We are always considered transparent
//-----------------------------------------------------------------------------
bool C_WeaponStunStick::IsTransparent( void )
{
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Draw a cheap glow quad at our impact point (with sparks)
//-----------------------------------------------------------------------------