void CWeaponStickyLauncher::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) return; m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate(); WeaponSound(SINGLE); pPlayer->m_fEffects |= EF_MUZZLEFLASH; SendWeaponAnim( GetPrimaryAttackActivity() ); // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES ); m_iClip1 = m_iClip1 - 1; LaunchStickyBomb( pPlayer, vecSrc, vecAiming ); AddViewKick(); }
//=====================================================================================// // Purpose: Performs the screen shake and it checks to see if we hit an entity to // handle the proper damage // An entity here can be another player or a wood plank //=====================================================================================// void CTDPBludgeonWeaponBase::Hit( trace_t &tr, Activity nHitActivity ) { // Do we have a valid owner holding the weapon? CTDPPlayer *pPlayer = GetPlayerOwner(); if ( !pPlayer ) return; // Let's shake the screen a little AddViewKick(); // if tr.m_pEnt is not NULL it means we have hit a target if ( tr.m_pEnt != NULL ) { Vector vForward; pPlayer->EyeVectors( &vForward, NULL, NULL ); VectorNormalize( vForward ); // Process the damage and send it to the entity we just hit CTakeDamageInfo dmgInfo( GetOwner(), GetOwner(), GetDamageForActivity( nHitActivity ), DMG_CLUB ); CalculateMeleeDamageForce( &dmgInfo, vForward, tr.endpos ); tr.m_pEnt->DispatchTraceAttack( dmgInfo, vForward, &tr ); ApplyMultiDamage(); #if defined( GAME_DLL ) // Now hit all triggers along the ray that... TraceAttackToTriggers( dmgInfo, tr.startpos, tr.endpos, vForward ); #endif } // Apply an impact effect ImpactEffect( tr ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponCGuard::DelayedFire( void ) { if ( m_flChargeTime >= gpGlobals->curtime ) return; if ( m_bFired ) return; m_bFired = true; // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer == NULL ) return; // Abort here to handle burst and auto fire modes if ( (GetMaxClip1() != -1 && m_iClip1 == 0) || (GetMaxClip1() == -1 && !pPlayer->GetAmmoCount(m_iPrimaryAmmoType) ) ) return; // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(SINGLE); 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. if ( GetSequence() != SelectWeightedSequence( ACT_VM_PRIMARYATTACK ) ) { m_flNextPrimaryAttack = gpGlobals->curtime; } // Make sure we don't fire more than the amount in the clip, if this weapon uses clips if ( UsesClipsForAmmo1() ) { m_iClip1 = m_iClip1 - 1; } // Fire the bullets Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetRadialAutoVector( NEW_AUTOAIM_RADIUS, NEW_AUTOAIM_DIST ); //Factor in the view kick AddViewKick(); Vector impactPoint = vecSrc + ( vecAiming * MAX_TRACE_LENGTH ); trace_t tr; UTIL_TraceHull( vecSrc, impactPoint, Vector( -2, -2, -2 ), Vector( 2, 2, 2 ), MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr ); CreateConcussiveBlast( tr.endpos, tr.plane.normal, this, 1.0 ); }
void CWeaponSubMachineGun::PrimaryAttack() { BaseClass::PrimaryAttack(); // 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; AddViewKick(); }
//------------------------------------------------------------------------------ // Purpose: Implement impact function //------------------------------------------------------------------------------ void CBaseSDKBludgeonWeapon::Hit( trace_t &traceHit, Activity nHitActivity, bool bIsSecondary ) { CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); //Do view kick AddViewKick(); //Make sound for the AI CSoundEnt::InsertSound( SOUND_BULLET_IMPACT, traceHit.endpos, 400, 0.2f, pPlayer ); // This isn't great, but it's something for when the crowbar hits. pPlayer->RumbleEffect( RUMBLE_AR2, 0, RUMBLE_FLAG_RESTART ); CBaseEntity *pHitEntity = traceHit.m_pEnt; //Apply damage to a hit target if ( pHitEntity != NULL ) { Vector hitDirection; pPlayer->EyeVectors( &hitDirection, NULL, NULL ); VectorNormalize( hitDirection ); CTakeDamageInfo info( GetOwner(), GetOwner(), GetDamageForActivity( nHitActivity ), DMG_CLUB ); if( pPlayer && pHitEntity->IsNPC() ) { // If bonking an NPC, adjust damage. info.AdjustPlayerDamageInflictedForSkillLevel(); } CalculateMeleeDamageForce( &info, hitDirection, traceHit.endpos ); pHitEntity->DispatchTraceAttack( info, hitDirection, &traceHit ); ApplyMultiDamage(); // Now hit all triggers along the ray that... TraceAttackToTriggers( info, traceHit.startpos, traceHit.endpos, hitDirection ); if ( ToBaseCombatCharacter( pHitEntity ) ) { gamestats->Event_WeaponHit( pPlayer, !bIsSecondary, GetClassname(), info ); } } // Apply an impact effect ImpactEffect( traceHit ); }
void CWeaponShotgun::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) return; // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(SINGLE); pPlayer->DoMuzzleFlash(); SendWeaponAnim( ACT_VM_PRIMARYATTACK ); ToGEPlayer(pPlayer)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); // Don't fire again until our ROF expires m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate(); m_flSoonestPrimaryAttack = gpGlobals->curtime + GetClickFireRate(); m_iClip1 -= 1; // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); // FireBulletsInfo_t info( 5, vecSrc, vecAiming, pGEPlayer->GetAttackSpread(this), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); // info.m_pAttacker = pPlayer; // Knock the player's view around AddViewKick(); RecordShotFired(); // Fire the bullets, and force the first shot to be perfectly accuracy PrepareFireBullets(5, pPlayer, vecSrc, vecAiming, true); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CHLMachineGun::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(); // MUST call sound before removing a round from the clip of a CHLMachineGun while ( m_flNextPrimaryAttack <= gpGlobals->curtime ) { 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; } m_iPrimaryAttacks++; gamestats->Event_WeaponFired( pPlayer, true, GetClassname() ); // Fire the bullets FireBulletsInfo_t info; info.m_iShots = iBulletsToFire; info.m_vecSrc = pPlayer->Weapon_ShootPosition( ); info.m_vecDirShooting = pPlayer->GetAutoaimVector( AUTOAIM_SCALE_DEFAULT ); info.m_vecSpread = pPlayer->GetAttackSpread( this ); info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = m_iPrimaryAmmoType; info.m_iTracerFreq = 2; FireBullets( info ); //Factor in the view kick AddViewKick(); CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_MACHINEGUN, 0.2, pPlayer ); 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 ); // Register a muzzleflash for the AI pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 ); }
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 ); }
//========================================================= // Disparo //========================================================= void CWeaponGaussGun::Fire() { CBasePlayer *pOwner = ToBasePlayer(GetOwner()); // ¿El jugador no ha sido creado? if ( !pOwner ) return; m_bCharging = false; if ( m_hViewModel == NULL ) { CBaseViewModel *vm = pOwner->GetViewModel(); if ( vm ) m_hViewModel.Set(vm); } Vector startPos = pOwner->Weapon_ShootPosition(); Vector aimDir = pOwner->GetAutoaimVector(AUTOAIM_5DEGREES); Vector vecUp, vecRight; VectorVectors(aimDir, vecRight, vecUp); float x, y, z; //Gassian spread do { x = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5); y = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5); z = x*x+y*y; } while (z > 1); aimDir = aimDir + x * GetBulletSpread().x * vecRight + y * GetBulletSpread().y * vecUp; Vector endPos = startPos + (aimDir * MAX_TRACE_LENGTH); // Shoot a shot straight out trace_t tr; UTIL_TraceLine(startPos, endPos, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr); #ifndef CLIENT_DLL ClearMultiDamage(); CBaseEntity *pHit = tr.m_pEnt; CTakeDamageInfo dmgInfo(this, pOwner, sk_plr_dmg_gauss.GetFloat(), DMG_SHOCK | DMG_DISSOLVE); if ( pHit != NULL ) { CalculateBulletDamageForce(&dmgInfo, m_iPrimaryAmmoType, aimDir, tr.endpos); pHit->DispatchTraceAttack(dmgInfo, aimDir, &tr); } if ( tr.DidHitWorld() ) { float hitAngle = -DotProduct( tr.plane.normal, aimDir ); if ( hitAngle < 0.5f ) { Vector vReflection; vReflection = 2.0 * tr.plane.normal * hitAngle + aimDir; startPos = tr.endpos; endPos = startPos + (vReflection * MAX_TRACE_LENGTH); // Draw beam to reflection point DrawBeam(tr.startpos, tr.endpos, 15, true); CPVSFilter filter(tr.endpos); te->GaussExplosion(filter, 0.0f, tr.endpos, tr.plane.normal, 0); UTIL_ImpactTrace(&tr, GetAmmoDef()->DamageType(m_iPrimaryAmmoType), "ImpactGauss"); //Find new reflection end position UTIL_TraceLine(startPos, endPos, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr); if ( tr.m_pEnt != NULL ) { dmgInfo.SetDamageForce(GetAmmoDef()->DamageForce(m_iPrimaryAmmoType) * vReflection); dmgInfo.SetDamagePosition(tr.endpos); tr.m_pEnt->DispatchTraceAttack(dmgInfo, vReflection, &tr); } // Connect reflection point to end DrawBeam(tr.startpos, tr.endpos, 10); } else DrawBeam(tr.startpos, tr.endpos, 15, true); } else DrawBeam(tr.startpos, tr.endpos, 15, true); ApplyMultiDamage(); #endif UTIL_ImpactTrace(&tr, GetAmmoDef()->DamageType(m_iPrimaryAmmoType), "ImpactGauss"); CPVSFilter filter(tr.endpos); te->GaussExplosion(filter, 0.0f, tr.endpos, tr.plane.normal, 0); m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f; AddViewKick(); // Register a muzzleflash for the AI #ifndef CLIENT_DLL pOwner->SetMuzzleFlashTime(gpGlobals->curtime + 0.5); #endif }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponGauss::Fire( void ) { CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( pOwner == NULL ) return; m_bCharging = false; Vector startPos= pOwner->Weapon_ShootPosition(); Vector aimDir = pOwner->GetAutoaimVector( AUTOAIM_5DEGREES ); Vector vecUp, vecRight; VectorVectors( aimDir, vecRight, vecUp ); float x, y, z; //Gassian spread do { x = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5); y = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5); z = x*x+y*y; } while (z > 1); Vector endPos = startPos + ( aimDir * MAX_TRACE_LENGTH ); //Shoot a shot straight out trace_t tr; UTIL_TraceLine( startPos, endPos, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr ); #ifndef CLIENT_DLL ClearMultiDamage(); #endif CBaseEntity *pHit = tr.m_pEnt; #ifndef CLIENT_DLL CTakeDamageInfo dmgInfo( this, pOwner, sk_dmg_gauss.GetFloat(), DMG_SHOCK | DMG_BULLET ); #endif if ( pHit != NULL ) { #ifndef CLIENT_DLL CalculateBulletDamageForce( &dmgInfo, m_iPrimaryAmmoType, aimDir, tr.endpos, 7.0f * 5.0f ); pHit->DispatchTraceAttack( dmgInfo, aimDir, &tr ); #endif } if ( tr.DidHitWorld() ) { float hitAngle = -DotProduct( tr.plane.normal, aimDir ); if ( hitAngle < 0.5f ) { Vector vReflection; vReflection = 2.0 * tr.plane.normal * hitAngle + aimDir; startPos = tr.endpos; endPos = startPos + ( vReflection * MAX_TRACE_LENGTH ); //Draw beam to reflection point DrawBeam( tr.startpos, tr.endpos, 1.6, true ); CPVSFilter filter( tr.endpos ); te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 ); UTIL_ImpactTrace( &tr, GetAmmoDef()->DamageType(m_iPrimaryAmmoType), "ImpactGauss" ); //Find new reflection end position UTIL_TraceLine( startPos, endPos, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr ); if ( tr.m_pEnt != NULL ) { #ifndef CLIENT_DLL dmgInfo.SetDamageForce( GetAmmoDef()->DamageForce(m_iPrimaryAmmoType) * vReflection ); dmgInfo.SetDamagePosition( tr.endpos ); tr.m_pEnt->DispatchTraceAttack( dmgInfo, vReflection, &tr ); #endif } //Connect reflection point to end DrawBeam( tr.startpos, tr.endpos, 0.4 ); } else { DrawBeam( tr.startpos, tr.endpos, 1.6, true ); } } else { DrawBeam( tr.startpos, tr.endpos, 1.6, true ); } #ifndef CLIENT_DLL ApplyMultiDamage(); #endif UTIL_ImpactTrace( &tr, GetAmmoDef()->DamageType(m_iPrimaryAmmoType), "ImpactGauss" ); CPVSFilter filter( tr.endpos ); te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 ); m_flNextSecondaryAttack = gpGlobals->curtime + 1.0f; AddViewKick(); return; }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CHL2MPMachineGun::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++; // MUST call sound before removing a round from the clip of a CHLMachineGun // FIXME: only called once, will miss multiple sound events per frame if needed // FIXME: m_flNextPrimaryAttack is always in the past, it's not clear what'll happen with sounds WeaponSound(SINGLE, m_flNextPrimaryAttack); // Msg("%.3f\n", m_flNextPrimaryAttack.Get() ); 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 ) { 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; } CHL2MP_Player *pHL2MPPlayer = ToHL2MPPlayer( pPlayer ); // Fire the bullets FireBulletsInfo_t info; info.m_iShots = iBulletsToFire; info.m_vecSrc = pHL2MPPlayer->Weapon_ShootPosition( ); info.m_vecDirShooting = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES ); info.m_vecSpread = pHL2MPPlayer->GetAttackSpread( this ); info.m_flDistance = MAX_TRACE_LENGTH; info.m_iAmmoType = m_iPrimaryAmmoType; info.m_iTracerFreq = 2; 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 ); }
void CWeaponM249Para::PrimaryAttack(void) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer(GetOwner()); if (!pPlayer) { return; } if (m_iClip1 <= 0) { if (!m_bFireOnEmpty) { Reload(); } else { WeaponSound(EMPTY); m_flNextPrimaryAttack = 0.15; } return; } m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate(); m_flNextSecondaryAttack = gpGlobals->curtime + GetFireRate(); m_iPrimaryAttacks++; gamestats->Event_WeaponFired(pPlayer, true, GetClassname()); WeaponSound(SINGLE); pPlayer->DoMuzzleFlash(); SendWeaponAnim(ACT_VM_PRIMARYATTACK); pPlayer->SetAnimation(PLAYER_ATTACK1); if (GetWpnData().m_bUseMuzzleSmoke) { DispatchParticleEffect("weapon_muzzle_smoke", PATTACH_POINT_FOLLOW, pPlayer->GetViewModel(), "muzzle"); } m_iClip1--; Vector vecSrc = pPlayer->Weapon_ShootPosition(); Vector vecAiming = pPlayer->GetAutoaimVector(AUTOAIM_SCALE_DEFAULT); pPlayer->FireBullets(1, vecSrc, vecAiming, vec3_origin, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 0); pPlayer->SetMuzzleFlashTime(gpGlobals->curtime + 0.5); AddViewKick(); CSoundEnt::InsertSound(SOUND_COMBAT, GetAbsOrigin(), 600, 0.2, GetOwner()); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } }
//----------------------------------------------------------------------------- // Purpose: Launch a bounce/impact grenade //----------------------------------------------------------------------------- void CGEWeaponRocketLauncher::LaunchRocket( void ) { CBaseCombatCharacter *pOwner = GetOwner(); if ( !pOwner ) return; #ifndef CLIENT_DLL Vector vForward, vRight, vUp; AngleVectors( pOwner->EyeAngles(), &vForward, &vRight, &vUp ); // Manipulate the shoot position such that it is in front of our gun muzzle Vector vecSrc = pOwner->Weapon_ShootPosition(); if ( pOwner->IsPlayer() ) { VectorMA( vecSrc, 4.5f, vRight, vecSrc ); // 3.0, 5.0 VectorMA( vecSrc, 16.5f, vForward, vecSrc ); // 20, 19 VectorMA( vecSrc, -5.25f, vUp, vecSrc ); // -2, -6, -5, 5.25 } else { VectorMA( vecSrc, 20.0, vForward, vecSrc ); } CheckLaunchPosition( pOwner->EyePosition(), vecSrc ); if ( pOwner->MyNPCPointer() ) vForward = pOwner->MyNPCPointer()->GetActualShootTrajectory( vecSrc ); QAngle angAiming; VectorAngles( vForward, angAiming ); // Convert us into a bot player :-D if ( pOwner->IsNPC() ) { CNPC_GEBase *pNPC = (CNPC_GEBase*) pOwner; if ( pNPC->GetBotPlayer() ) pOwner = pNPC->GetBotPlayer(); } CGERocket *pRocket = (CGERocket*)CBaseEntity::Create( "npc_rocket", vecSrc, angAiming, NULL ); if ( pRocket ) { pRocket->SetThrower( pOwner ); pRocket->SetOwnerEntity( pOwner ); pRocket->SetSourceWeapon(this); pRocket->SetDamage( GetGEWpnData().m_iDamage ); pRocket->SetDamageRadius( GetGEWpnData().m_flDamageRadius ); if (pOwner->GetTeamNumber() == TEAM_JANUS) pRocket->SetCollisionGroup( COLLISION_GROUP_GRENADE_JANUS ); else if (pOwner->GetTeamNumber() == TEAM_MI6) pRocket->SetCollisionGroup( COLLISION_GROUP_GRENADE_MI6 ); // Tell the owner what we threw to implement anti-spamming if ( pOwner->IsPlayer() ) ToGEMPPlayer( pOwner )->AddThrownObject( pRocket ); } #endif // Remove the rocket from our ammo pool m_iClip1 -= 1; WeaponSound( SINGLE ); SwitchBodygroup(1, 1); //Add our view kick in AddViewKick(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWarsWeapon::PrimaryAttack( void ) { VPROF_BUDGET( "CWarsWeapon::PrimaryAttack", VPROF_BUDGETGROUP_UNITS ); CUnitBase *pOwner = GetOwner() ? GetOwner()->MyUnitPointer() : NULL; if( !pOwner ) return; #ifndef CLIENT_DLL if( m_bEnableBurst ) { // Auto reset burst shots next time we fire if( m_nBurstShotsRemaining <= 0 ) { m_nBurstShotsRemaining = GetRandomBurst(); } } #endif // CLIENT_DLL pOwner->DoMuzzleFlash(); SendWeaponAnim( GetPrimaryAttackActivity() ); Vector vecShootOrigin, vecShootDir; GetShootOriginAndDirection(vecShootOrigin, vecShootDir); int shots = 0; // Assume still firing if gpGlobals.curtime-nextprimaryattack falss within this range // In the other case reset nextprimaryattack, so we only fire one shot if( (gpGlobals->curtime - m_flNextPrimaryAttack) > m_fFireTimeOut ) m_flNextPrimaryAttack = gpGlobals->curtime; //WeaponSound(SINGLE, m_flNextPrimaryAttack); while( m_flNextPrimaryAttack <= gpGlobals->curtime ) { #ifdef CLIENT_DLL // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(SINGLE, m_flNextPrimaryAttack); #endif // CLIENT_DLL m_flNextPrimaryAttack = m_flNextPrimaryAttack + m_fFireRate; shots += 1; if( !m_fFireRate ) break; } // Fill in bullets info FireBulletsInfo_t info; info.m_vecSrc = vecShootOrigin; info.m_vecDirShooting = vecShootDir; info.m_iShots = shots; info.m_flDistance = m_fMaxBulletRange; info.m_iAmmoType = GetPrimaryAmmoType(); info.m_iTracerFreq = 2; info.m_vecSpread = m_vBulletSpread; info.m_flDamage = m_fOverrideAmmoDamage; pOwner->FireBullets( info ); #ifndef CLIENT_DLL if( m_bEnableBurst ) { m_nBurstShotsRemaining -= shots; // Dispatch burst finished event if we have no shots left // It's up to the AI to rest if( m_nBurstShotsRemaining <= 0 ) { pOwner->DispatchBurstFinished(); } } #endif // CLIENT_DLL // Add our view kick in AddViewKick(); }
//----------------------------------------------------------------------------- // 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; }