//----------------------------------------------------------------------------- // Purpose: Return true if this weapon can be selected via the weapon selection //----------------------------------------------------------------------------- bool C_TFWeaponBuilder::CanBeSelected( void ) { CTFPlayer *pOwner = ToTFPlayer( GetOwner() ); if ( !pOwner ) return false; if ( pOwner->CanBuild( m_iObjectType ) != CB_CAN_BUILD ) return false; return HasAmmo(); }
void CASW_Sentry_Top::CheckFiring() { if ( gpGlobals->curtime > m_fNextFireTime && HasAmmo() && ( m_bHasHysteresis || m_hEnemy.Get() ) ) { float flDist = fabs(m_fGoalYaw - m_fCurrentYaw); flDist = fsel( flDist - 180, 360 - flDist, flDist ); if ( (flDist < ASW_SENTRY_FIRE_ANGLE_THRESHOLD) || ( m_bHasHysteresis && !m_hEnemy ) ) { Fire(); } } }
// Returns the first weapon for a given slot. WEAPON *WeaponsResource :: GetFirstPos( int iSlot ) { WEAPON *pret = NULL; for( int i = 0; i < MAX_WEAPON_POSITIONS; i++ ) { if( rgSlots[iSlot][i] && HasAmmo( rgSlots[iSlot][i] )) { pret = rgSlots[iSlot][i]; break; } } return pret; }
bool RapidFireWeapon::Shoot(const Entity& playerEntity) { if (HasAmmo() && _cooldown - _timeSinceLastActivation <= 0) { _currentAmmo -= 1; //_builder->Light()->ChangeLightBlobRange(_weaponEntity, 0.1f*(_currentAmmo / (float)_maxAmmo)); _builder->Animation()->PlayAnimation(_weaponEntity, "scale", 0.1f*(_currentAmmo / (float)_maxAmmo) - _currentSize); System::GetAudio()->PlaySoundEffect(L"basicattack.wav", 0.15f); _timeSinceLastActivation = 0.0; _projectiles.push_back(new RapidFireProjectile(playerEntity, _builder, 1.0f)); return true; } return false; }
void CASW_Sentry_Top_Flamer::CheckFiring() { bool bShouldFire = false; if ( HasAmmo() && m_hEnemy.IsValid() && m_hEnemy.Get()) { float flDist = fabs(m_fGoalYaw - m_fCurrentYaw); if (flDist > 180) flDist = 360 - flDist; // use some hysteresis if (flDist < (IsFiring() ? ASW_SENTRY_FIRE_ANGLE_THRESHOLD * 1.1f : ASW_SENTRY_FIRE_ANGLE_THRESHOLD) ) { bShouldFire = true; } } if ( bShouldFire ) { m_flFireHysteresisTime = gpGlobals->curtime + 0.5f; } else { bShouldFire = gpGlobals->curtime < m_flFireHysteresisTime ; } // turn firing on or off as appropriate if ( IsFiring() != bShouldFire ) { if ( bShouldFire ) StartFiring(); else StopFiring(); } Assert( IsFiring() == bShouldFire ); if ( bShouldFire ) { Fire(); } }
/// @TODO: lead target void CASW_Sentry_Top_Cannon::Fire() { if ( !m_hEnemy.IsValid() || !m_hEnemy.Get() || !HasAmmo() ) return; BaseClass::Fire(); Vector diff = m_hEnemy->WorldSpaceCenter() - GetFiringPosition(); diff.NormalizeInPlace(); //FireBulletsInfo_t( int nShots, const Vector &vecSrc, const Vector &vecDir, const Vector &vecSpread, float flDistance, int nAmmoType, bool bPrimaryAttack = true ) Vector launchVector = diff * 1000.0f; CASW_Marine * RESTRICT pMarineDeployer = GetSentryBase()->m_hDeployer.Get(); Assert( pMarineDeployer ); float fGrenadeDamage = CASW_Weapon_Grenades::GetBoomDamage(pMarineDeployer) * 0.5f; float fGrenadeRadius = CASW_Weapon_Grenades::GetBoomRadius(pMarineDeployer) * 0.5f; CASW_Rifle_Grenade::Rifle_Grenade_Create( fGrenadeDamage, fGrenadeRadius, GetFiringPosition() + (diff * ( WorldAlignSize().Length() * 0.5f ) ), GetAbsAngles(), launchVector, AngularImpulse(0,0,0), pMarineDeployer, this ); if( pMarineDeployer ) pMarineDeployer->OnWeaponFired( this, 1 ); EmitSound("ASW_Sentry.CannonFire"); m_fNextFireTime = gpGlobals->curtime + ASW_SENTRY_CANNON_FIRE_RATE; // use ammo if ( GetSentryBase() ) { GetSentryBase()->OnFiredShots(); } }
void CEgon::Attack( void ) { // don't fire underwater if ( m_pPlayer->pev->waterlevel == 3 ) { if ( m_fireState != FIRE_OFF || m_pBeam ) { EndAttack(); } else { PlayEmptySound( ); } return; } UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle ); Vector vecAiming = gpGlobals->v_forward; Vector vecSrc = m_pPlayer->GetGunPosition( ); int flags; #if defined( CLIENT_WEAPONS ) flags = FEV_NOTHOST; #else flags = 0; #endif switch( m_fireState ) { case FIRE_OFF: { if ( !HasAmmo() ) { m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.25; PlayEmptySound( ); return; } m_flAmmoUseTime = gpGlobals->time;// start using ammo ASAP. PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usEgonFire, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, m_fireState, m_fireMode, 1, 0 ); m_shakeTime = 0; m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.1; pev->fuser1 = UTIL_WeaponTimeBase() + 2; pev->dmgtime = gpGlobals->time + GetPulseInterval(); m_fireState = FIRE_CHARGE; } break; case FIRE_CHARGE: { Fire( vecSrc, vecAiming ); m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME; if ( pev->fuser1 <= UTIL_WeaponTimeBase() ) { PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usEgonFire, 0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, m_fireState, m_fireMode, 0, 0 ); pev->fuser1 = 1000; } if ( !HasAmmo() ) { EndAttack(); m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0; } } break; } }
void CEgon::Attack( void ) { // don't fire underwater /**if ( m_pPlayer->pev->waterlevel == 3 ) { if ( m_fireState != FIRE_OFF || m_pBeam ) { EndAttack(); } else { PlayEmptySound( ); } return; }*/ // rather than not working, we're gonna explode in water. makes sense for a prototype supergun. if ( m_pPlayer->pev->waterlevel > 1 ) { // get the remaining ammo to calculate how much damage the explosion will do, and then "use up" the ammo. int remainingAmmo = m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]; m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] = 0; // do damage! #ifndef CLIENT_DLL ::RadiusDamage( m_pPlayer->pev->origin, m_pPlayer->pev, m_pPlayer->pev, 35 * remainingAmmo, ( 35 * remainingAmmo ) + 40, CLASS_NONE, DMG_ENERGYBEAM | DMG_BLAST | DMG_ALWAYSGIB ); #endif } UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle ); Vector vecAiming = gpGlobals->v_forward; Vector vecSrc = m_pPlayer->GetGunPosition( ); int flags; #if defined( CLIENT_WEAPONS ) flags = FEV_NOTHOST; #else flags = 0; #endif switch( m_fireState ) { case FIRE_OFF: { if ( !HasAmmo() ) { m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.25; PlayEmptySound( ); return; } m_flAmmoUseTime = gpGlobals->time;// start using ammo ASAP. PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usEgonFire, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, m_fireState, m_fireMode, 1, 0 ); m_shakeTime = 0; m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.1; pev->fuser1 = UTIL_WeaponTimeBase() + 2; pev->dmgtime = gpGlobals->time + GetPulseInterval(); m_fireState = FIRE_CHARGE; } break; case FIRE_CHARGE: { Fire( vecSrc, vecAiming ); m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME; if ( pev->fuser1 <= UTIL_WeaponTimeBase() ) { PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usEgonFire, 0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, m_fireState, m_fireMode, 0, 0 ); pev->fuser1 = 1000; } if ( !HasAmmo() ) { EndAttack(); m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0; } } break; } }
void CEgon::Attack( void ) { // don't fire underwater if (m_pPlayer->pev->waterlevel == 3) { if ( m_pBeam ) { EndAttack(); } else { PlayEmptySound( ); } return; } UTIL_MakeVectors( m_pPlayer->pev->viewangles + m_pPlayer->pev->punchangle ); Vector vecAiming = gpGlobals->v_forward; Vector vecSrc = m_pPlayer->GetGunPosition( ); switch( m_fireState ) { case FIRE_OFF: { if ( !HasAmmo() ) { m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->time + 0.25; PlayEmptySound( ); return; } m_flAmmoUseTime = gpGlobals->time;// start using ammo ASAP. SendWeaponAnim( g_fireAnims1[ RANDOM_LONG(0,ARRAYSIZE(g_fireAnims1)-1) ] ); m_shakeTime = 0; m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME; m_flTimeWeaponIdle = gpGlobals->time + 0.1; m_shootTime = gpGlobals->time + 2; if ( m_fireMode == FIRE_WIDE ) { EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_WEAPON, EGON_SOUND_STARTUP, 0.98, ATTN_NORM, 0, 125 ); } else { EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_WEAPON, EGON_SOUND_STARTUP, 0.9, ATTN_NORM, 0, 100 ); } pev->dmgtime = gpGlobals->time + GetPulseInterval(); m_fireState = FIRE_CHARGE; } break; case FIRE_CHARGE: { Fire( vecSrc, vecAiming ); m_pPlayer->m_iWeaponVolume = EGON_PRIMARY_VOLUME; if ( m_shootTime != 0 && gpGlobals->time > m_shootTime ) { if ( m_fireMode == FIRE_WIDE ) { EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_STATIC, EGON_SOUND_RUN, 0.98, ATTN_NORM, 0, 125 ); } else { EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_STATIC, EGON_SOUND_RUN, 0.9, ATTN_NORM, 0, 100 ); } m_shootTime = 0; } if ( !HasAmmo() ) { EndAttack(); m_fireState = FIRE_OFF; m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->time + 1.0; } } break; } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponEgon::PrimaryAttack( void ) { CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( !pPlayer ) { return; } // don't fire underwater if ( pPlayer->GetWaterLevel() == 3 ) { if ( m_fireState != FIRE_OFF || m_hBeam ) { EndAttack(); } else { WeaponSound( EMPTY ); } m_flNextPrimaryAttack = gpGlobals->curtime + 0.5; m_flNextSecondaryAttack = gpGlobals->curtime + 0.5; return; } Vector vecAiming = pPlayer->GetAutoaimVector( 0 ); Vector vecSrc = pPlayer->Weapon_ShootPosition( ); switch( m_fireState ) { case FIRE_OFF: { if ( !HasAmmo() ) { m_flNextPrimaryAttack = gpGlobals->curtime + 0.25; m_flNextSecondaryAttack = gpGlobals->curtime + 0.25; WeaponSound( EMPTY ); return; } m_flAmmoUseTime = gpGlobals->curtime;// start using ammo ASAP. EmitSound( "Weapon_Gluon.Start" ); SendWeaponAnim( ACT_VM_PRIMARYATTACK ); m_flShakeTime = 0; m_flStartFireTime = gpGlobals->curtime; SetWeaponIdleTime( gpGlobals->curtime + 0.1 ); m_flDmgTime = gpGlobals->curtime + EGON_PULSE_INTERVAL; m_fireState = FIRE_STARTUP; } break; case FIRE_STARTUP: { Fire( vecSrc, vecAiming ); if ( gpGlobals->curtime >= ( m_flStartFireTime + 2.0 ) ) { EmitSound( "Weapon_Gluon.Run" ); m_fireState = FIRE_CHARGE; } if ( !HasAmmo() ) { EndAttack(); m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; m_flNextSecondaryAttack = gpGlobals->curtime + 1.0; } } case FIRE_CHARGE: { Fire( vecSrc, vecAiming ); if ( !HasAmmo() ) { EndAttack(); m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; m_flNextSecondaryAttack = gpGlobals->curtime + 1.0; } } break; } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CASW_Weapon_Chainsaw::PrimaryAttack( void ) { // If my clip is empty (and I use clips) start reload //if ( UsesClipsForAmmo1() && !m_iClip1 ) //{ //Reload(); //return; //} CASW_Player *pPlayer = GetCommander(); CASW_Marine *pMarine = GetMarine(); if ( !pMarine || !pMarine->IsAlive()) { EndAttack(); return; } // don't fire underwater if ( pMarine->GetWaterLevel() == 3 ) { if ( m_fireState != FIRE_OFF || m_hBeam ) { EndAttack(); } else { WeaponSound( EMPTY ); } m_flNextPrimaryAttack = gpGlobals->curtime + GetWeaponInfo()->m_flFireRate; m_flNextSecondaryAttack = gpGlobals->curtime + GetWeaponInfo()->m_flFireRate; return; } #ifdef GAME_DLL // check for turning on lag compensation if (pPlayer && pMarine->IsInhabited()) { CASW_Lag_Compensation::RequestLagCompensation( pPlayer, pPlayer->GetCurrentUserCommand() ); } #endif Vector vecSrc = pMarine->Weapon_ShootPosition( ); Vector vecAiming = vec3_origin; if ( pPlayer && pMarine->IsInhabited() ) { vecAiming = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount()); // 45 degrees = 0.707106781187 } else { #ifndef CLIENT_DLL vecAiming = pMarine->GetActualShootTrajectory( vecSrc ); #endif } // make vecaiming go down at 45 degrees vecAiming.z = 0; VectorNormalize(vecAiming); vecAiming.z = -1.0f; VectorNormalize(vecAiming); switch( m_fireState ) { case FIRE_OFF: { //if ( !HasAmmo() ) //{ //m_flNextPrimaryAttack = gpGlobals->curtime + 0.25; //m_flNextSecondaryAttack = gpGlobals->curtime + 0.25; //WeaponSound( EMPTY ); //return; //} m_flAmmoUseTime = gpGlobals->curtime;// start using ammo ASAP. SendWeaponAnim( ACT_VM_PRIMARYATTACK ); m_flShakeTime = 0; m_flStartFireTime = gpGlobals->curtime; SetWeaponIdleTime( gpGlobals->curtime + 0.1 ); m_flDmgTime = gpGlobals->curtime + ASW_CHAINSAW_PULSE_INTERVAL; SetFiringState(FIRE_STARTUP); } break; case FIRE_STARTUP: { Fire( vecSrc, vecAiming ); #ifndef CLIENT_DLL pMarine->OnWeaponFired( this, 1 ); #endif if ( gpGlobals->curtime >= ( m_flStartFireTime + ASW_CHAINSAW_CHARGE_UP_TIME ) ) { //EmitSound( "ASW_Chainsaw.AttackLoop" ); SetFiringState(FIRE_CHARGE); } if ( !HasAmmo() ) { EndAttack(); m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; m_flNextSecondaryAttack = gpGlobals->curtime + 1.0; } } break; case FIRE_CHARGE: { Fire( vecSrc, vecAiming ); #ifndef CLIENT_DLL pMarine->OnWeaponFired( this, 1 ); #endif if ( !HasAmmo() ) { EndAttack(); m_flNextPrimaryAttack = gpGlobals->curtime + 1.0; m_flNextSecondaryAttack = gpGlobals->curtime + 1.0; } } break; } }