//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBaseSDKGrenade::ItemPostFrame() { CSDKPlayer *pPlayer = GetPlayerOwner(); if ( !pPlayer ) return; CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex ); if ( !vm ) return; // If they let go of the fire button, they want to throw the grenade. if ( m_bPinPulled && !(pPlayer->m_nButtons & IN_ATTACK) ) { pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); // if (m_bSecondary) // DropGrenade(); // else ThrowGrenade(); DecrementAmmo( pPlayer ); m_bPinPulled = false; SendWeaponAnim( ACT_VM_THROW ); SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() ); m_bPinPulled = false; // m_bSecondary = false; } else if( m_bRedraw ) { // Has the throw animation finished playing if( m_flTimeWeaponIdle < gpGlobals->curtime ) { // if we're officially out of grenades, ditch this weapon if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) { #ifdef GAME_DLL pPlayer->Weapon_Drop( this, NULL, NULL ); UTIL_Remove(this); #endif pPlayer->SwitchToNextBestWeapon( NULL ); //Tony; now switch! cuz we rans outs! } else { m_bRedraw = false; m_flNextPrimaryAttack = gpGlobals->curtime + 1.2; m_flNextSecondaryAttack = gpGlobals->curtime + 1.2; SendWeaponAnim( GetDeployActivity() ); } return; //don't animate this grenade any more! } } else if( !m_bRedraw ) { BaseClass::ItemPostFrame(); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBaseSDKGrenade::ItemPostFrame() { CSDKPlayer *pPlayer = GetPlayerOwner(); if ( !pPlayer ) return; CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex ); if ( !vm ) return; // If they let go of the fire button, they want to throw the grenade. if ( m_bPinPulled && !(pPlayer->m_nButtons & IN_ATTACK) ) { pPlayer->DoAnimationEvent( PLAYERANIMEVENT_THROW_GRENADE ); StartGrenadeThrow(); DecrementAmmo( pPlayer ); m_bPinPulled = false; SendWeaponAnim( ACT_VM_THROW ); SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() ); } else if ((m_fThrowTime > 0) && (m_fThrowTime < gpGlobals->curtime)) { ThrowGrenade(); } else if( m_bRedraw ) { // Has the throw animation finished playing if( m_flTimeWeaponIdle < gpGlobals->curtime ) { #ifdef GAME_DLL // if we're officially out of grenades, ditch this weapon if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) { pPlayer->Weapon_Drop( this, NULL, NULL ); UTIL_Remove(this); } else { pPlayer->SwitchToNextBestWeapon( this ); } #endif return; //don't animate this grenade any more! } } else if( !m_bRedraw ) { BaseClass::ItemPostFrame(); } }
void CWeaponSDKBase::SendReloadEvents() { CSDKPlayer *pPlayer = dynamic_cast< CSDKPlayer* >( GetOwner() ); if ( !pPlayer ) return; // Send a message to any clients that have this entity to play the reload. CPASFilter filter( pPlayer->GetAbsOrigin() ); filter.RemoveRecipient( pPlayer ); UserMessageBegin( filter, "ReloadEffect" ); WRITE_SHORT( pPlayer->entindex() ); MessageEnd(); // Make the player play his reload animation. pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- bool CSDKGameMovement::CheckJumpButton( void ) { if (!m_pSDKPlayer->IsAlive()) { mv->m_nOldButtons |= IN_JUMP ; // don't jump again until released return false; } #if defined ( SDK_USE_PRONE ) if( m_pSDKPlayer->m_Shared.IsProne() || m_pSDKPlayer->m_Shared.IsGettingUpFromProne() || m_pSDKPlayer->m_Shared.IsGoingProne() ) { mv->m_nOldButtons |= IN_JUMP; return false; } #endif // See if we are waterjumping. If so, decrement count and return. float flWaterJumpTime = player->GetWaterJumpTime(); if ( flWaterJumpTime > 0 ) { flWaterJumpTime -= gpGlobals->frametime; if (flWaterJumpTime < 0) flWaterJumpTime = 0; player->SetWaterJumpTime( flWaterJumpTime ); return false; } // If we are in the water most of the way... if ( m_pSDKPlayer->GetWaterLevel() >= 2 ) { // swimming, not jumping SetGroundEntity( NULL ); if(m_pSDKPlayer->GetWaterType() == CONTENTS_WATER) // We move up a certain amount mv->m_vecVelocity[2] = 100; else if (m_pSDKPlayer->GetWaterType() == CONTENTS_SLIME) mv->m_vecVelocity[2] = 80; // play swiming sound if ( player->GetSwimSoundTime() <= 0 ) { // Don't play sound again for 1 second player->SetSwimSoundTime( 1000 ); PlaySwimSound(); } return false; } // No more effect if (m_pSDKPlayer->GetGroundEntity() == NULL) { mv->m_nOldButtons |= IN_JUMP; return false; // in air, so no effect } if ( mv->m_nOldButtons & IN_JUMP ) return false; // don't pogo stick // In the air now. SetGroundEntity( NULL ); m_pSDKPlayer->PlayStepSound( (Vector &)mv->GetAbsOrigin(), player->GetSurfaceData(), 1.0, true ); m_pSDKPlayer->DoAnimationEvent( PLAYERANIMEVENT_JUMP ); //Tony; liek the landing sound, leaving this here if as an example for playing a jump sound. // // make the jump sound // CPASFilter filter( m_pSDKPlayer->GetAbsOrigin() ); // filter.UsePredictionRules(); // m_pSDKPlayer->EmitSound( filter, m_pSDKPlayer->entindex(), "Player.Jump" ); float flGroundFactor = 1.0f; if ( player->GetSurfaceData() ) { flGroundFactor = player->GetSurfaceData()->game.jumpFactor; } Assert( sv_gravity.GetFloat() == 800.0f ); float flJumpHeight = 268.3281572999747f; //Warning("HERE team: %d", player->GetTeamNumber()); // Accelerate upward // If we are ducking... float startz = mv->m_vecVelocity[2]; if ( ( m_pSDKPlayer->m_Local.m_bDucking ) || ( m_pSDKPlayer->GetFlags() & FL_DUCKING ) ) { // d = 0.5 * g * t^2 - distance traveled with linear accel // t = sqrt(2.0 * 45 / g) - how long to fall 45 units // v = g * t - velocity at the end (just invert it to jump up that high) // v = g * sqrt(2.0 * 45 / g ) // v^2 = g * g * 2.0 * 45 / g // v = sqrt( g * 2.0 * 45 ) if(player->GetTeamNumber() == 2){ mv->m_vecVelocity[2] = flGroundFactor * flJumpHeight ; //mv->m_vecVelocity[1] *= 1.8; //mv->m_vecVelocity[0] *= 1.8; Vector vecForward; AngleVectors( mv->m_vecViewAngles, &vecForward ); vecForward.z = 0; VectorNormalize( vecForward ); VectorAdd( (vecForward*(fabs( mv->m_flForwardMove * 0.5f ))*2), mv->m_vecVelocity, mv->m_vecVelocity ); } else mv->m_vecVelocity[2] = flGroundFactor * flJumpHeight; // flJumpSpeed of 45 } else { if(player->GetTeamNumber() == 2) mv->m_vecVelocity[2] += flGroundFactor * flJumpHeight * 2; // 2 * gravity * height else mv->m_vecVelocity[2] += flGroundFactor * flJumpHeight; // 2 * gravity * height //mv->m_vecVelocity[2] += flGroundFactor * flJumpHeight; // flJumpSpeed of 45 } FinishGravity(); mv->m_outWishVel.z += mv->m_vecVelocity[2] - startz; mv->m_outStepHeight += 0.1f; // Flag that we jumped. mv->m_nOldButtons |= IN_JUMP; // don't jump again until released m_pSDKPlayer->m_Shared.SetJumping( true ); return true; }
//----------------------------------------------------------------------------- // Purpose: See if duck button is pressed and do the appropriate things //----------------------------------------------------------------------------- void CSDKGameMovement::Duck( void ) { int buttonsChanged = ( mv->m_nOldButtons ^ mv->m_nButtons ); // These buttons have changed this frame int buttonsPressed = buttonsChanged & mv->m_nButtons; // The changed ones still down are "pressed" int buttonsReleased = buttonsChanged & mv->m_nOldButtons; // The changed ones which were previously down are "released" if ( mv->m_nButtons & IN_DUCK ) { mv->m_nOldButtons |= IN_DUCK; } else { mv->m_nOldButtons &= ~IN_DUCK; } if ( !player->IsAlive() ) { #if defined ( SDK_USE_PRONE ) if( m_pSDKPlayer->m_Shared.IsProne() ) { FinishUnProne(); } #endif // SDK_USE_PRONE // Unduck if ( player->m_Local.m_bDucking || player->m_Local.m_bDucked ) { FinishUnDuck(); } return; } static int iState = 0; #if defined ( SDK_USE_PRONE ) // Prone / UnProne - we don't duck if this is happening if( m_pSDKPlayer->m_Shared.IsGettingUpFromProne() == true ) { float pronetime = m_pSDKPlayer->m_Shared.m_flUnProneTime - gpGlobals->curtime; if( pronetime < 0 ) { FinishUnProne(); if ( !m_pSDKPlayer->m_bUnProneToDuck && ( mv->m_nButtons & IN_DUCK ) ) { buttonsPressed |= IN_DUCK; mv->m_nOldButtons &= ~IN_DUCK; } } else { // Calc parametric time float fraction = SimpleSpline( pronetime / TIME_TO_PRONE ); SetProneEyeOffset( fraction ); } // Set these, so that as soon as we stop unproning, we don't pop to standing // the information that we let go of the duck key has been lost by now. if ( m_pSDKPlayer->m_bUnProneToDuck ) { player->m_Local.m_flDucktime = 1000; player->m_Local.m_bDucking = true; } //don't deal with ducking while we're proning return; } else if ( m_pSDKPlayer->m_Shared.IsGoingProne() == true ) { float pronetime = m_pSDKPlayer->m_Shared.m_flGoProneTime - gpGlobals->curtime; if( pronetime < 0 ) { FinishProne(); } else { // Calc parametric time float fraction = SimpleSpline( 1.0f - ( pronetime / TIME_TO_PRONE ) ); SetProneEyeOffset( fraction ); } //don't deal with ducking while we're proning return; } if ( gpGlobals->curtime > m_pSDKPlayer->m_Shared.m_flNextProneCheck ) { if ( buttonsPressed & IN_ALT1 && m_pSDKPlayer->m_Shared.CanChangePosition() ) { if( m_pSDKPlayer->m_Shared.IsProne() == false && m_pSDKPlayer->m_Shared.IsGettingUpFromProne() == false ) { m_pSDKPlayer->m_Shared.StartGoingProne(); //Tony; here is where you'd want to do an animation for first person to give the effect of going prone. if ( m_pSDKPlayer->m_Shared.IsDucking() ) m_pSDKPlayer->DoAnimationEvent( PLAYERANIMEVENT_CROUCH_TO_PRONE ); else m_pSDKPlayer->DoAnimationEvent( PLAYERANIMEVENT_STAND_TO_PRONE ); } else if ( CanUnprone() ) { m_pSDKPlayer->m_Shared.SetProne( false ); m_pSDKPlayer->m_Shared.StandUpFromProne(); // //Tony; here is where you'd want to do an animation for first person to give the effect of getting up from prone. // m_pSDKPlayer->m_bUnProneToDuck = ( mv->m_nButtons & IN_DUCK ) > 0; if ( m_pSDKPlayer->m_bUnProneToDuck ) m_pSDKPlayer->DoAnimationEvent( PLAYERANIMEVENT_PRONE_TO_CROUCH ); else m_pSDKPlayer->DoAnimationEvent( PLAYERANIMEVENT_PRONE_TO_STAND ); } m_pSDKPlayer->m_Shared.m_flNextProneCheck = gpGlobals->curtime + 1.0f; return; } } if ( m_pSDKPlayer->m_Shared.IsProne() && m_pSDKPlayer->m_Shared.CanChangePosition() && ( buttonsPressed & IN_DUCK ) && CanUnprone() ) { // If the player presses duck while prone, // unprone them to the duck position m_pSDKPlayer->m_Shared.SetProne( false ); m_pSDKPlayer->m_Shared.StandUpFromProne(); m_pSDKPlayer->m_bUnProneToDuck = true; // //Tony; here is where you'd want to do an animation for first person to give the effect of going to duck from prone. // m_pSDKPlayer->DoAnimationEvent( PLAYERANIMEVENT_PRONE_TO_CROUCH ); // simulate a duck that was pressed while we were prone player->AddFlag( FL_DUCKING ); player->m_Local.m_bDucked = true; player->m_Local.m_flDucktime = 1000; player->m_Local.m_bDucking = true; } // no ducking or unducking while deployed or prone if( m_pSDKPlayer->m_Shared.IsProne() || m_pSDKPlayer->m_Shared.IsGettingUpFromProne() || !m_pSDKPlayer->m_Shared.CanChangePosition() ) { return; } #endif // SDK_USE_PRONE HandleDuckingSpeedCrop(); if ( !( player->GetFlags() & FL_DUCKING ) && ( player->m_Local.m_bDucked ) ) { player->m_Local.m_bDucked = false; } // Holding duck, in process of ducking or fully ducked? if ( ( mv->m_nButtons & IN_DUCK ) || ( player->m_Local.m_bDucking ) || ( player->GetFlags() & FL_DUCKING ) ) { if ( mv->m_nButtons & IN_DUCK ) { bool alreadyDucked = ( player->GetFlags() & FL_DUCKING ) ? true : false; if ( (buttonsPressed & IN_DUCK ) && !( player->GetFlags() & FL_DUCKING ) ) { // Use 1 second so super long jump will work player->m_Local.m_flDucktime = 1000; player->m_Local.m_bDucking = true; } float duckmilliseconds = max( 0.0f, 1000.0f - (float)player->m_Local.m_flDucktime ); float duckseconds = duckmilliseconds / 1000.0f; //time = max( 0.0, ( 1.0 - (float)player->m_Local.m_flDucktime / 1000.0 ) ); if ( player->m_Local.m_bDucking ) { // Finish ducking immediately if duck time is over or not on ground if ( ( duckseconds > TIME_TO_DUCK ) || ( player->GetGroundEntity() == NULL ) || alreadyDucked) { FinishDuck(); } else { // Calc parametric time float flDuckFraction = SimpleSpline( duckseconds / TIME_TO_DUCK ); SetSDKDuckedEyeOffset( flDuckFraction ); } } } else { // Try to unduck unless automovement is not allowed // NOTE: When not onground, you can always unduck if ( player->m_Local.m_bAllowAutoMovement || player->GetGroundEntity() == NULL ) { if ( (buttonsReleased & IN_DUCK ) && ( player->GetFlags() & FL_DUCKING ) ) { // Use 1 second so super long jump will work player->m_Local.m_flDucktime = 1000; player->m_Local.m_bDucking = true; // or unducking } float duckmilliseconds = max( 0.0f, 1000.0f - (float)player->m_Local.m_flDucktime ); float duckseconds = duckmilliseconds / 1000.0f; if ( CanUnduck() ) { if ( player->m_Local.m_bDucking || player->m_Local.m_bDucked ) // or unducking { // Finish ducking immediately if duck time is over or not on ground if ( ( duckseconds > TIME_TO_UNDUCK ) || ( player->GetGroundEntity() == NULL ) ) { FinishUnDuck(); } else { // Calc parametric time float duckFraction = SimpleSpline( 1.0f - ( duckseconds / TIME_TO_UNDUCK ) ); SetSDKDuckedEyeOffset( duckFraction ); } } } else { // Still under something where we can't unduck, so make sure we reset this timer so // that we'll unduck once we exit the tunnel, etc. player->m_Local.m_flDucktime = 1000; } } } } }
void CWeaponSMG1::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) return; // Abort here to handle burst and auto fire modes if ( (UsesClipsForAmmo1() && m_iClip1 == 0) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) ) return; m_nShotsFired++; pPlayer->DoMuzzleFlash(); // To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems, // especially if the weapon we're firing has a really fast rate of fire. int iBulletsToFire = 0; float fireRate = GetFireRate(); while ( m_flNextPrimaryAttack <= gpGlobals->curtime ) { // MUST call sound before removing a round from the clip of a CHLMachineGun WeaponSound(SINGLE, m_flNextPrimaryAttack); m_flNextPrimaryAttack = gpGlobals->curtime + fireRate; iBulletsToFire++; } // Make sure we don't fire more than the amount in the clip, if this weapon uses clips if ( UsesClipsForAmmo1() ) { if ( iBulletsToFire > m_iClip1 ) iBulletsToFire = m_iClip1; m_iClip1 -= iBulletsToFire; } CSDKPlayer *pSDKPlayer = ToSDKPlayer( pPlayer ); // Fire the bullets FireBulletsInfo_t info; info.m_iShots = iBulletsToFire; info.m_vecSrc = pSDKPlayer->Weapon_ShootPosition( ); info.m_vecDirShooting = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES ); info.m_vecSpread = GetBulletSpread(); info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = m_iPrimaryAmmoType; info.m_iTracerFreq = 2; info.m_iDamage = GetSDKWpnData().m_iDamage; pPlayer->FireBullets( info ); //Factor in the view kick AddViewKick(); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } SendWeaponAnim( GetPrimaryAttackActivity() ); pPlayer->SetAnimation( PLAYER_ATTACK1 ); pSDKPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CBaseSDKGrenade::ItemPostFrame() { CSDKPlayer *pPlayer = GetPlayerOwner(); if ( !pPlayer ) return; CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex ); if ( !vm ) return; // If they let go of the fire button, they want to throw the grenade. if ( m_bPinPulled && !(pPlayer->m_nButtons & IN_ATTACK) ) { pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); // if (m_bSecondary) // DropGrenade(); // else ThrowGrenade(); if (!pPlayer->IsStyleSkillActive(SKILL_TROLL)) DecrementAmmo( pPlayer ); m_bPinPulled = false; SendWeaponAnim( ACT_VM_THROW ); SetWeaponIdleTime( GetCurrentTime() + SequenceDuration() ); m_bPinPulled = false; // m_bSecondary = false; } else if( m_bRedraw ) { // Has the throw animation finished playing if( m_flTimeWeaponIdle < GetCurrentTime() ) { // if we're officially out of grenades, ditch this weapon if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) { #ifdef GAME_DLL pPlayer->Weapon_Drop( this, NULL, NULL ); UTIL_Remove(this); #endif pPlayer->SwitchToNextBestWeapon( NULL ); //Tony; now switch! cuz we rans outs! } else if (pPlayer->IsStyleSkillActive(SKILL_TROLL)) { m_bRedraw = false; m_flNextPrimaryAttack = GetCurrentTime() + 1.2; m_flNextSecondaryAttack = GetCurrentTime() + 1.2; SendWeaponAnim( GetDeployActivity() ); } else { m_bRedraw = false; // Only switch to the next best weapon if the next best weapon is not brawl. CBaseCombatWeapon *pNewWeapon = g_pGameRules->GetNextBestWeapon(pPlayer, this); CWeaponSDKBase* pSDKNewWeapon = dynamic_cast<CWeaponSDKBase*>(pNewWeapon); bool bSwitch = true; if (!pSDKNewWeapon) bSwitch = false; // If I'm going to switch to brawl but I have more grenades, don't switch. else if (pSDKNewWeapon && pSDKNewWeapon->GetWeaponID() == SDK_WEAPON_BRAWL && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) > 0) bSwitch = false; if (bSwitch) pPlayer->SwitchToNextBestWeapon( this ); } return; //don't animate this grenade any more! } } else if( !m_bRedraw ) { BaseClass::ItemPostFrame(); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponHL2Pistol::PrimaryAttack( void ) { if ( ( gpGlobals->curtime - m_flLastAttackTime ) > 0.5f ) { m_nNumShotsFired = 0; } else { m_nNumShotsFired++; } m_flLastAttackTime = gpGlobals->curtime; m_flSoonestPrimaryAttack = gpGlobals->curtime + PISTOL_FASTEST_REFIRE_TIME; CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if( pOwner ) { // Each time the player fires the pistol, reset the view punch. This prevents // the aim from 'drifting off' when the player fires very quickly. This may // not be the ideal way to achieve this, but it's cheap and it works, which is // great for a feature we're evaluating. (sjb) pOwner->ViewPunchReset(); } // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) return; // Abort here to handle burst and auto fire modes if ( (UsesClipsForAmmo1() && m_iClip1 == 0) || ( !UsesClipsForAmmo1() && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) ) return; m_nShotsFired++; pPlayer->DoMuzzleFlash(); // To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems, // especially if the weapon we're firing has a really fast rate of fire. int iBulletsToFire = 0; float fireRate = GetFireRate(); while ( m_flNextPrimaryAttack <= gpGlobals->curtime ) { // MUST call sound before removing a round from the clip of a CHLMachineGun WeaponSound(SINGLE, m_flNextPrimaryAttack); m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate; iBulletsToFire++; } // Make sure we don't fire more than the amount in the clip, if this weapon uses clips if ( UsesClipsForAmmo1() ) { if ( iBulletsToFire > m_iClip1 ) iBulletsToFire = m_iClip1; m_iClip1 -= iBulletsToFire; } CSDKPlayer *pSDKPlayer = ToSDKPlayer( pPlayer ); // Fire the bullets FireBulletsInfo_t info; info.m_iShots = iBulletsToFire; info.m_vecSrc = pSDKPlayer->Weapon_ShootPosition( ); info.m_vecDirShooting = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES ); info.m_vecSpread = GetBulletSpread(); info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = m_iPrimaryAmmoType; info.m_iTracerFreq = 2; info.m_iDamage = GetSDKWpnData().m_iDamage; pPlayer->FireBullets( info ); //Factor in the view kick AddViewKick(); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } SendWeaponAnim( GetPrimaryAttackActivity() ); pPlayer->SetAnimation( PLAYER_ATTACK1 ); pSDKPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); // Abort here to handle burst and auto fire modes if ( (UsesClipsForAmmo1() && m_iClip1 == 0) || ( !UsesClipsForAmmo1() && !pOwner->GetAmmoCount(m_iPrimaryAmmoType) ) ) return; // Add an accuracy penalty which can move past our maximum penalty time if we're really spastic m_flAccuracyPenalty += PISTOL_ACCURACY_SHOT_PENALTY_TIME; }
bool CWeaponShotgun::Reload() { CSDKPlayer *pPlayer = GetPlayerOwner(); if (pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 || m_iClip1 == GetMaxClip1()) return true; // don't reload until recoil is done if (m_flNextPrimaryAttack > GetCurrentTime()) return true; CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex ); float flSpeedMultiplier = GetSDKWpnData().m_flReloadTimeMultiplier; // check to see if we're ready to reload if (m_iInSpecialReload == 0) { pPlayer->SetAnimation( PLAYER_RELOAD ); float flStartTime = 0.5f * flSpeedMultiplier; pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD ); SendWeaponAnim( ACT_SHOTGUN_RELOAD_START ); m_iInSpecialReload = 1; /* this is the only part of the reload sequence that can't be interrupted, seems unnecessary pPlayer->m_flNextAttack = GetCurrentTime() + flStartTime; m_flNextPrimaryAttack = GetCurrentTime() + flStartTime; m_flNextSecondaryAttack = GetCurrentTime() + flStartTime; */ SetWeaponIdleTime( GetCurrentTime() + flStartTime ); if (vm) vm->SetPlaybackRate( 1/flSpeedMultiplier ); pPlayer->Instructor_LessonLearned("reload"); return true; } else if (m_iInSpecialReload == 1) { if (m_flTimeWeaponIdle > GetCurrentTime()) return true; // was waiting for gun to move to side m_iInSpecialReload = 2; float flReloadTime = 0.45 * flSpeedMultiplier; SendWeaponAnim( ACT_VM_RELOAD ); SetWeaponIdleTime( GetCurrentTime() + flReloadTime ); pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD_LOOP ); if (vm) vm->SetPlaybackRate( 1/flSpeedMultiplier ); } else if ( m_iInSpecialReload == 2 ) // Sanity, make sure it's actually in the right state. { // Add them to the clip m_iClip1 += 1; #ifdef GAME_DLL // Send a message to any clients that have this entity to play the reload. CPASFilter filter( pPlayer->GetAbsOrigin() ); filter.RemoveRecipient( pPlayer ); UserMessageBegin( filter, "ReloadEffect" ); WRITE_SHORT( pPlayer->entindex() ); MessageEnd(); #endif if ( pPlayer ) { bool bConsume = true; if (pPlayer->IsStyleSkillActive(SKILL_MARKSMAN)) bConsume = false; if (bConsume) pPlayer->RemoveAmmo( 1, m_iPrimaryAmmoType ); } if ( pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 || m_iClip1 == GetMaxClip1() ) pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD_END ); m_iInSpecialReload = 1; } return true; }