const char *CASW_Weapon::GetASWShootSound( int iIndex, int &iPitch ) { if ( iIndex == SINGLE || iIndex == SINGLE_NPC ) { iIndex = IsCarriedByLocalPlayer() ? SINGLE : SINGLE_NPC; } if ( iIndex == WPN_DOUBLE || iIndex == DOUBLE_NPC ) { iIndex = IsCarriedByLocalPlayer() ? WPN_DOUBLE : DOUBLE_NPC; } if ( iIndex == RELOAD || iIndex == RELOAD_NPC ) { iIndex = IsCarriedByLocalPlayer() ? RELOAD : RELOAD_NPC; // play the weapon sound according to marine skill int iSkill = MarineSkills()->GetSkillBasedValueByMarine(GetMarine(), ASW_MARINE_SKILL_RELOADING, ASW_MARINE_SUBSKILL_RELOADING_SOUND); switch (iSkill) { case 5: return GetWpnData().aShootSounds[ FAST_RELOAD ]; break; case 4: iPitch = 120; return GetWpnData().aShootSounds[ iIndex ]; break; case 3: iPitch = 115; return GetWpnData().aShootSounds[ iIndex ]; break; case 2: iPitch = 110; return GetWpnData().aShootSounds[ iIndex ]; break; case 1: iPitch = 105; return GetWpnData().aShootSounds[ iIndex ]; break; default: return GetWpnData().aShootSounds[ iIndex ]; break; }; } return GetShootSound( iIndex ); }
//----------------------------------------------------------------------------- // Purpose: // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool C_BaseCombatWeapon::ShouldDraw( void ) { if ( m_iWorldModelIndex == 0 ) { return false; } // carried by player? if ( IsCarriedByLocalPlayer() ) { // Only ever show the active weapon if ( !IsActiveByLocalPlayer() ) return false; // Don't show it if it's the view model and we're in firstperson if (input->CAM_IsThirdPerson() == false) return false; return true; } // If it's a player, then only show active weapons if ( GetOwner() && GetOwner()->IsPlayer() ) { // Show it if it's active... return (m_iState == WEAPON_IS_ACTIVE); } // FIXME: We may want to only show active weapons on NPCs // These are carried by AIs; always show them return true; }
//----------------------------------------------------------------------------- // Purpose: Sets up the attachment point lookup for the model //----------------------------------------------------------------------------- void C_WeaponStunStick::SetupAttachmentPoints( void ) { // Setup points for both types of views if ( IsCarriedByLocalPlayer() && !::input->CAM_IsThirdPerson()) { const char *szBeamAttachNamesTop[NUM_BEAM_ATTACHMENTS] = { "spark1a","spark2a","spark3a","spark4a", "spark5a","spark6a","spark7a","spark8a", "spark9a", }; const char *szBeamAttachNamesBottom[NUM_BEAM_ATTACHMENTS] = { "spark1b","spark2b","spark3b","spark4b", "spark5b","spark6b","spark7b","spark8b", "spark9b", }; // Lookup and store all connections for ( int i = 0; i < NUM_BEAM_ATTACHMENTS; i++ ) { m_BeamAttachments[i].IDs[0] = LookupAttachment( szBeamAttachNamesTop[i] ); m_BeamAttachments[i].IDs[1] = LookupAttachment( szBeamAttachNamesBottom[i] ); } // Setup the center beam point m_BeamCenterAttachment = LookupAttachment( BEAM_ATTACH_CORE_NAME ); } else { // Setup the center beam point m_BeamCenterAttachment = 1; } }
//----------------------------------------------------------------------------- // Purpose: Returns true if this weapon is the local client's currently wielded weapon //----------------------------------------------------------------------------- bool C_BaseCombatWeapon::IsActiveByLocalPlayer( void ) { if ( IsCarriedByLocalPlayer() ) { return (m_iState == WEAPON_IS_ACTIVE); } return false; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_BaseCombatWeapon::SetDormant( bool bDormant ) { // If I'm going from active to dormant and I'm carried by another player, holster me. if ( !IsDormant() && bDormant && GetOwner() && !IsCarriedByLocalPlayer() ) { Holster( NULL ); } BaseClass::SetDormant( bDormant ); }
//----------------------------------------------------------------------------- // Should this object cast shadows? //----------------------------------------------------------------------------- ShadowType_t C_BaseCombatWeapon::ShadowCastType() { if (!IsBeingCarried()) return SHADOWS_RENDER_TO_TEXTURE; if (IsCarriedByLocalPlayer()) return SHADOWS_NONE; return (m_iState != WEAPON_IS_CARRIED_BY_PLAYER) ? SHADOWS_RENDER_TO_TEXTURE : SHADOWS_NONE; }
//----------------------------------------------------------------------------- // Purpose: Draw our special effects //----------------------------------------------------------------------------- void C_WeaponStunStick::DrawEffects( void ) { if ( IsCarriedByLocalPlayer() ) { DrawFirstPersonEffects(); } else { DrawThirdPersonEffects(); } }
//----------------------------------------------------------------------------- // Should this object cast shadows? //----------------------------------------------------------------------------- ShadowType_t C_BaseCombatWeapon::ShadowCastType() { if ( IsEffectActive( /*EF_NODRAW |*/ EF_NOSHADOW ) ) return SHADOWS_NONE; if (!IsBeingCarried()) return SHADOWS_RENDER_TO_TEXTURE; if (IsCarriedByLocalPlayer() && !C_BasePlayer::ShouldDrawLocalPlayer()) return SHADOWS_NONE; return SHADOWS_RENDER_TO_TEXTURE; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFFlameThrower::SetDormant( bool bDormant ) { // If I'm going from active to dormant and I'm carried by another player, stop our firing sound. if ( !IsCarriedByLocalPlayer() ) { if ( !IsDormant() && bDormant ) { StopFlame(); StopPilotLight(); } } // Deliberately skip base combat weapon to avoid being holstered C_BaseEntity::SetDormant( bDormant ); }
//----------------------------------------------------------------------------- // Purpose: Tells us we're always a translucent entity //----------------------------------------------------------------------------- bool C_WeaponStunStick::InSwing( void ) { int activity = GetActivity(); // FIXME: This is needed until the actual animation works if ( IsCarriedByLocalPlayer() == false || ::input->CAM_IsThirdPerson()) return true; // These are the swing activities this weapon can play if ( activity == GetPrimaryAttackActivity() || activity == GetSecondaryAttackActivity() || activity == ACT_VM_MISSCENTER || activity == ACT_VM_MISSCENTER2 ) return true; return false; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CTFMinigun::SetDormant( bool bDormant ) { // If I'm going from active to dormant and I'm carried by another player, stop our firing sound. if ( !IsCarriedByLocalPlayer() ) { // Am I firing? Stop the firing sound. if ( !IsDormant() && bDormant && m_iWeaponState >= AC_STATE_FIRING ) { WeaponSoundUpdate(); } // If firing and going dormant - stop the brass effect. if ( !IsDormant() && bDormant && m_iWeaponState != AC_STATE_IDLE ) { StopMuzzleEffect(); StopBrassEffect(); } } // Deliberately skip base combat weapon //C_BaseEntity::SetDormant( bDormant ); BaseClass::SetDormant(bDormant); }
//----------------------------------------------------------------------------- // Purpose: Returns true if this client is carrying this weapon and is // using the view models //----------------------------------------------------------------------------- bool C_BaseCombatWeapon::ShouldDrawUsingViewModel( void ) { return IsCarriedByLocalPlayer() && !C_BasePlayer::ShouldDrawLocalPlayer(); }
//----------------------------------------------------------------------------- // Purpose: Randomly adds extra effects //----------------------------------------------------------------------------- void C_WeaponStunStick::ClientThink( void ) { if ( InSwing() == false ) { if ( m_bSwungLastFrame ) { // Start fading m_flFadeTime = gpGlobals->curtime; m_bSwungLastFrame = false; } return; } // Remember if we were swinging last frame m_bSwungLastFrame = InSwing(); if ( IsEffectActive( EF_NODRAW ) ) return; if ( IsCarriedByLocalPlayer() && !::input->CAM_IsThirdPerson()) { // Update our effects if ( gpGlobals->frametime != 0.0f && ( random->RandomInt( 0, 3 ) == 0 ) ) { Vector vecOrigin; QAngle vecAngles; // Inner beams BeamInfo_t beamInfo; int attachment = random->RandomInt( 0, 15 ); UTIL_GetWeaponAttachment( this, attachment, vecOrigin, vecAngles ); ::FormatViewModelAttachment( vecOrigin, false ); CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); CBaseEntity *pBeamEnt = pOwner->GetViewModel(); beamInfo.m_vecStart = vec3_origin; beamInfo.m_pStartEnt= pBeamEnt; beamInfo.m_nStartAttachment = attachment; beamInfo.m_pEndEnt = NULL; beamInfo.m_nEndAttachment = -1; beamInfo.m_vecEnd = vecOrigin + RandomVector( -8, 8 ); beamInfo.m_pszModelName = STUNSTICK_BEAM_MATERIAL; beamInfo.m_flHaloScale = 0.0f; beamInfo.m_flLife = 0.05f; beamInfo.m_flWidth = random->RandomFloat( 1.0f, 2.0f ); beamInfo.m_flEndWidth = 0; beamInfo.m_flFadeLength = 0.0f; beamInfo.m_flAmplitude = random->RandomFloat( 16, 32 ); beamInfo.m_flBrightness = 255.0; beamInfo.m_flSpeed = 0.0; beamInfo.m_nStartFrame = 0.0; beamInfo.m_flFrameRate = 1.0f; beamInfo.m_flRed = 255.0f;; beamInfo.m_flGreen = 255.0f; beamInfo.m_flBlue = 255.0f; beamInfo.m_nSegments = 16; beamInfo.m_bRenderable = true; beamInfo.m_nFlags = 0; beams->CreateBeamEntPoint( beamInfo ); } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_WeaponMortar::OnDataChanged( DataUpdateType_t updateType ) { BaseClass::OnDataChanged(updateType); // If the mortar's being carried by some other player, don't make a ground line if ( !IsCarriedByLocalPlayer() ) return; // Draw power chart if the mortar is deployed if ( !m_bCarried && !m_bMortarReloading ) { vgui::Panel *pParent = GetClientModeNormal()->GetViewport(); int parentWidth, parentHeight; pParent->GetSize(parentWidth, parentHeight); int iWidth = 256; int iHeight = 40; int iX = (parentWidth - iWidth) / 2; int iY = (parentHeight - 200); // Only show the power bar if the mortar's the active weapon if ( IsActiveByLocalPlayer() ) { m_pPowerBar->SetBounds( iX, iY, iWidth, iHeight ); m_pPowerBar->SetParent(pParent); } else { m_pPowerBar->SetParent( (vgui::Panel *)NULL ); } if ( !m_bRotating && m_flPrevMortarServerYaw != m_vecMortarAngles.y ) { m_flMortarYaw = m_vecMortarAngles.y; } // Create the Ground lines if ( !m_pGroundLine ) { m_pGroundLine = new CGroundLine(); m_pGroundLine->Init( "player/support/mortarline" ); } if ( !m_pDarkLine ) { m_pDarkLine = new CGroundLine(); m_pDarkLine->Init( "player/support/mortarline" ); } } else { m_pPowerBar->SetParent( (vgui::Panel *)NULL ); if ( m_pGroundLine ) { delete m_pGroundLine; m_pGroundLine = NULL; } if ( m_pDarkLine ) { delete m_pDarkLine; m_pDarkLine = NULL; } } }