//----------------------------------------------------------------------------- // Purpose: // Input : // Output : //----------------------------------------------------------------------------- void CWeapon_SLAM::StartTripmineAttach( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) { return; } Vector vecSrc, vecAiming; // Take the eye position and direction vecSrc = pPlayer->EyePosition(); QAngle angles = pPlayer->GetLocalAngles(); AngleVectors( angles, &vecAiming ); trace_t tr; UTIL_TraceLine( vecSrc, vecSrc + (vecAiming * 128), MASK_SOLID, pPlayer, COLLISION_GROUP_NONE, &tr ); if (tr.fraction < 1.0) { // ALERT( at_console, "hit %f\n", tr.flFraction ); CBaseEntity *pEntity = tr.m_pEnt; if (pEntity && !(pEntity->GetFlags() & FL_CONVEYOR)) { // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); //Tony: ??? ToHL2MPPlayer(pPlayer)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); // ----------------------------------------- // Play attach animation // ----------------------------------------- if (m_bDetonatorArmed) { SendWeaponAnim(ACT_SLAM_STICKWALL_ATTACH); } else { SendWeaponAnim(ACT_SLAM_TRIPMINE_ATTACH); } m_bNeedReload = true; m_bAttachTripmine = true; m_bNeedDetonatorDraw = m_bDetonatorArmed; } else { // ALERT( at_console, "no deploy\n" ); } } // needs a higher delay on all of these, a minimum time really - to elimiate refires. m_flNextPrimaryAttack = m_flNextSecondaryAttack = SLAM_REFIRE_DELAY + gpGlobals->curtime + SequenceDuration(); // SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() ); }
void CGauss::SecondaryAttack() { // don't fire underwater if ( m_pPlayer->pev->waterlevel == 3 ) { if ( m_fInAttack != 0 ) { EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/electro4.wav", 1.0, ATTN_NORM, 0, 80 + RANDOM_LONG(0,0x3f)); SendWeaponAnim( GAUSS_IDLE ); m_fInAttack = 0; } else { PlayEmptySound( ); } m_flNextSecondaryAttack = m_flNextPrimaryAttack = GetNextAttackDelay(0.5); return; } if ( m_fInAttack == 0 ) { if ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 ) { EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/357_cock1.wav", 0.8, ATTN_NORM); m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5; return; } m_fPrimaryFire = false; m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;// take one ammo just to start the spin m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase(); // spin up m_pPlayer->m_iWeaponVolume = GAUSS_PRIMARY_CHARGE_VOLUME; SendWeaponAnim( GAUSS_SPINUP ); m_fInAttack = 1; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5; m_pPlayer->m_flStartCharge = gpGlobals->time; m_pPlayer->m_flAmmoStartCharge = UTIL_WeaponTimeBase() + GetFullChargeTime(); PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_usGaussSpin, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, 110, 0, 0, 0 ); m_iSoundState = SND_CHANGE_PITCH; } else if (m_fInAttack == 1) { if (m_flTimeWeaponIdle < UTIL_WeaponTimeBase()) { SendWeaponAnim( GAUSS_SPIN ); m_fInAttack = 2; } } else { // during the charging process, eat one bit of ammo every once in a while if ( UTIL_WeaponTimeBase() >= m_pPlayer->m_flNextAmmoBurn && m_pPlayer->m_flNextAmmoBurn != 1000 ) { #ifdef CLIENT_DLL if ( bIsMultiplayer() ) #else if ( g_pGameRules->IsMultiplayer() ) #endif { m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--; m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase() + 0.1; } else { m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--; m_pPlayer->m_flNextAmmoBurn = UTIL_WeaponTimeBase() + 0.3; } } if ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 ) { // out of ammo! force the gun to fire StartFire(); m_fInAttack = 0; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.0; m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1; return; } if ( UTIL_WeaponTimeBase() >= m_pPlayer->m_flAmmoStartCharge ) { // don't eat any more ammo after gun is fully charged. m_pPlayer->m_flNextAmmoBurn = 1000; } int pitch = ( gpGlobals->time - m_pPlayer->m_flStartCharge ) * ( 150 / GetFullChargeTime() ) + 100; if ( pitch > 250 ) pitch = 250; // ALERT( at_console, "%d %d %d\n", m_fInAttack, m_iSoundState, pitch ); if ( m_iSoundState == 0 ) ALERT( at_console, "sound state %d\n", m_iSoundState ); PLAYBACK_EVENT_FULL( FEV_NOTHOST, m_pPlayer->edict(), m_usGaussSpin, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, pitch, 0, ( m_iSoundState == SND_CHANGE_PITCH ) ? 1 : 0, 0 ); m_iSoundState = SND_CHANGE_PITCH; // hack for going through level transitions m_pPlayer->m_iWeaponVolume = GAUSS_PRIMARY_CHARGE_VOLUME; // m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.1; if ( m_pPlayer->m_flStartCharge < gpGlobals->time - 10 ) { // Player charged up too long. Zap him. EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/electro4.wav", 1.0, ATTN_NORM, 0, 80 + RANDOM_LONG(0,0x3f)); EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_ITEM, "weapons/electro6.wav", 1.0, ATTN_NORM, 0, 75 + RANDOM_LONG(0,0x3f)); m_fInAttack = 0; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.0; m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0; #ifndef CLIENT_DLL m_pPlayer->TakeDamage( CWorld::GetInstance(), CWorld::GetInstance(), 50, DMG_SHOCK ); UTIL_ScreenFade( m_pPlayer, Vector(255,128,0), 2, 0.5, 128, FFADE_IN ); #endif SendWeaponAnim( GAUSS_IDLE ); // Player may have been killed and this weapon dropped, don't execute any more code after this! return; } } }
//----------------------------------------------------------------------------- // Purpose: // Input : // Output : //----------------------------------------------------------------------------- void CWeapon_SLAM::WeaponIdle( void ) { // Ready to switch animations? if ( HasWeaponIdleTimeElapsed() ) { // Don't allow throw to attach switch unless in idle m_flWallSwitchTime = gpGlobals->curtime + 50; if (m_bClearReload) { m_bNeedReload = false; m_bClearReload = false; } CBaseCombatCharacter *pOwner = GetOwner(); if (!pOwner) { return; } int iAnim = 0; if (m_bThrowSatchel) { SatchelThrow(); if (m_bDetonatorArmed && !m_bNeedDetonatorDraw) { iAnim = ACT_SLAM_THROW_THROW2; } else { iAnim = ACT_SLAM_THROW_THROW_ND2; } } else if (m_bAttachSatchel) { SatchelAttach(); if (m_bDetonatorArmed && !m_bNeedDetonatorDraw) { iAnim = ACT_SLAM_STICKWALL_ATTACH2; } else { iAnim = ACT_SLAM_STICKWALL_ND_ATTACH2; } } else if (m_bAttachTripmine) { TripmineAttach(); iAnim = ACT_SLAM_TRIPMINE_ATTACH2; } else if (m_bNeedReload) { // If owner had ammo draw the correct SLAM type if (pOwner->GetAmmoCount(m_iSecondaryAmmoType) > 0) { switch( m_tSlamState) { case SLAM_TRIPMINE_READY: { iAnim = ACT_SLAM_TRIPMINE_DRAW; } break; case SLAM_SATCHEL_ATTACH: { if (m_bNeedDetonatorHolster) { iAnim = ACT_SLAM_STICKWALL_DETONATOR_HOLSTER; m_bNeedDetonatorHolster = false; } else if (m_bDetonatorArmed) { iAnim = m_bNeedDetonatorDraw ? ACT_SLAM_DETONATOR_STICKWALL_DRAW : ACT_SLAM_STICKWALL_DRAW; m_bNeedDetonatorDraw = false; } else { iAnim = ACT_SLAM_STICKWALL_ND_DRAW; } } break; case SLAM_SATCHEL_THROW: { if (m_bNeedDetonatorHolster) { iAnim = ACT_SLAM_THROW_DETONATOR_HOLSTER; m_bNeedDetonatorHolster = false; } else if (m_bDetonatorArmed) { iAnim = m_bNeedDetonatorDraw ? ACT_SLAM_DETONATOR_THROW_DRAW : ACT_SLAM_THROW_DRAW; m_bNeedDetonatorDraw = false; } else { iAnim = ACT_SLAM_THROW_ND_DRAW; } } break; } m_bClearReload = true; } // If no ammo and armed, idle with only the detonator else if (m_bDetonatorArmed) { iAnim = m_bNeedDetonatorDraw ? ACT_SLAM_DETONATOR_DRAW : ACT_SLAM_DETONATOR_IDLE; m_bNeedDetonatorDraw = false; } else { pOwner->Weapon_Drop( this ); UTIL_Remove(this); } } else if (pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0) { pOwner->Weapon_Drop( this ); UTIL_Remove(this); } // If I don't need to reload just do the appropriate idle else { switch( m_tSlamState) { case SLAM_TRIPMINE_READY: { iAnim = ACT_SLAM_TRIPMINE_IDLE; } break; case SLAM_SATCHEL_THROW: { if (m_bNeedDetonatorHolster) { iAnim = ACT_SLAM_THROW_DETONATOR_HOLSTER; m_bNeedDetonatorHolster = false; } else { iAnim = m_bDetonatorArmed ? ACT_SLAM_THROW_IDLE : ACT_SLAM_THROW_ND_IDLE; m_flWallSwitchTime = 0; } } break; case SLAM_SATCHEL_ATTACH: { if (m_bNeedDetonatorHolster) { iAnim = ACT_SLAM_STICKWALL_DETONATOR_HOLSTER; m_bNeedDetonatorHolster = false; } else { iAnim = m_bDetonatorArmed ? ACT_SLAM_STICKWALL_IDLE : ACT_SLAM_STICKWALL_ND_IDLE; m_flWallSwitchTime = 0; } } break; } } SendWeaponAnim( iAnim ); } }
//----------------------------------------------------------------------------- // 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 ); SendWeaponAnim( GetPrimaryAttackActivity() ); pPlayer->SetAnimation( PLAYER_ATTACK1 ); // Register a muzzleflash for the AI pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 ); m_iShotsFired++; }
void CBaseHLBludgeonWeapon::MotionSwing( const Vector &pos, const Vector &dir, float velocity ) { trace_t traceHit; // Try a ray CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return; Vector v; Vector swingStart = pos; Vector forward = dir/dir.Length(); //dir*velocity; Vector swingEnd = swingStart + forward * (GetRange()*.75); UTIL_TraceLine( swingStart, swingEnd, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit ); Activity nHitActivity = ACT_VM_HITCENTER; // Like bullets, bludgeon traces have to trace against triggers. CTakeDamageInfo triggerInfo( GetOwner(), GetOwner(), GetDamageForActivity( nHitActivity ), DMG_CLUB ); triggerInfo.SetDamagePosition( traceHit.startpos ); triggerInfo.SetDamageForce( forward ); TraceAttackToTriggers( triggerInfo, traceHit.startpos, traceHit.endpos, forward ); if ( traceHit.fraction == 1.0 ) { float bludgeonHullRadius = 1.732f * BLUDGEON_HULL_DIM; // hull is +/- 16, so use cuberoot of 2 to determine how big the hull is from center to the corner point // Back off by hull "radius" swingEnd -= forward * bludgeonHullRadius; UTIL_TraceHull( swingStart, swingEnd, g_bludgeonMins, g_bludgeonMaxs, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit ); if ( traceHit.fraction < 1.0 && traceHit.m_pEnt ) { Vector vecToTarget = traceHit.m_pEnt->GetAbsOrigin() - swingStart; VectorNormalize( vecToTarget ); float dot = vecToTarget.Dot( forward ); // YWB: Make sure they are sort of facing the guy at least... if ( dot < 0.70721f ) { // Force amiss traceHit.fraction = 1.0f; } else { nHitActivity = ChooseIntersectionPointAndActivity( traceHit, g_bludgeonMins, g_bludgeonMaxs, pOwner ); } } } gamestats->Event_WeaponFired( pOwner, true, GetClassname() ); // ------------------------- // Miss // ------------------------- float motionFireRate = GetFireRate()*.75; if ( traceHit.fraction == 1.0f ) { nHitActivity = ACT_VM_MISSCENTER; // We want to test the first swing again Vector testEnd = swingStart + forward * GetRange(); // See if we happened to hit water if ( ImpactWater( swingStart, testEnd ) ) m_flNextPrimaryAttack = gpGlobals->curtime + motionFireRate; } else { Hit( traceHit, nHitActivity, false ? true : false ); SendWeaponAnim( ACT_VM_HITDYNAMIC ); //Setup our next attack times m_flNextPrimaryAttack = gpGlobals->curtime + motionFireRate; m_flNextSecondaryAttack = gpGlobals->curtime + motionFireRate; } }
void CASW_Weapon_Medkit::SelfHeal() { CASW_Marine *pMarine = GetMarine(); if (pMarine) // firing from a marine { if (pMarine->GetHealth() >= pMarine->GetMaxHealth()) // already on full health return; if (pMarine->GetHealth() <= 0) // aleady dead! return; if (pMarine->m_bSlowHeal) // already healing return; if (pMarine->GetFlags() & FL_FROZEN) // don't allow this if the marine is frozen return; // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(SINGLE); // sets the animation on the weapon model iteself SendWeaponAnim( GetPrimaryAttackActivity() ); // sets the animation on the marine holding this weapon //pMarine->SetAnimation( PLAYER_ATTACK1 ); #ifndef CLIENT_DLL bool bMedic = (pMarine->GetMarineProfile() && pMarine->GetMarineProfile()->CanUseFirstAid()); // put a slow heal onto the marine, play a particle effect if (!pMarine->m_bSlowHeal && pMarine->GetHealth() < pMarine->GetMaxHealth()) { pMarine->AddSlowHeal( GetHealAmount(), 1, pMarine, this ); // Fire event IGameEvent * event = gameeventmanager->CreateEvent( "player_heal" ); if ( event ) { CASW_Player *pPlayer = GetCommander(); event->SetInt( "userid", ( pPlayer ? pPlayer->GetUserID() : 0 ) ); event->SetInt( "entindex", pMarine->entindex() ); gameeventmanager->FireEvent( event ); } if ( ASWGameRules()->GetInfoHeal() ) { ASWGameRules()->GetInfoHeal()->OnMarineHealed( pMarine, pMarine, this ); } pMarine->OnWeaponFired( this, 1 ); } if (pMarine->IsInfested() && bMedic) { float fCure = GetInfestationCureAmount(); // cure infestation if (fCure < 100) pMarine->CureInfestation(pMarine, fCure); } #endif // decrement ammo m_iClip1 -= 1; #ifndef CLIENT_DLL DestroyIfEmpty( false ); #endif } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponGrapple::PrimaryAttack( void ) { // Can't have an active hook out if ( m_hHook != NULL ) return; #ifndef CLIENT_DLL CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( !pPlayer ) { return; } if ( m_iClip1 <= 0 ) { if ( !m_bFireOnEmpty ) { Reload(); } else { WeaponSound( EMPTY ); m_flNextPrimaryAttack = 0.15; } return; } m_iPrimaryAttacks++; gamestats->Event_WeaponFired( pPlayer, true, GetClassname() ); WeaponSound( SINGLE ); pPlayer->DoMuzzleFlash(); SendWeaponAnim( ACT_VM_PRIMARYATTACK ); pPlayer->SetAnimation( PLAYER_ATTACK1 ); m_flNextPrimaryAttack = gpGlobals->curtime + 0.75; m_flNextSecondaryAttack = gpGlobals->curtime + 0.75; //Disabled so we can shoot all the time that we want //m_iClip1--; Vector vecSrc = pPlayer->Weapon_ShootPosition(); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_SCALE_DEFAULT ); //We will not shoot bullets anymore //pPlayer->FireBullets( 1, vecSrc, vecAiming, vec3_origin, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 0 ); pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 ); 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 ); } trace_t tr; Vector vecShootOrigin, vecShootDir, vecDir, vecEnd; //Gets the direction where the player is aiming AngleVectors (pPlayer->EyeAngles(), &vecDir); //Gets the position of the player vecShootOrigin = pPlayer->Weapon_ShootPosition(); //Gets the position where the hook will hit vecEnd = vecShootOrigin + (vecDir * MAX_TRACE_LENGTH); //Traces a line between the two vectors UTIL_TraceLine( vecShootOrigin, vecEnd, MASK_SHOT, pPlayer, COLLISION_GROUP_NONE, &tr); //Draws the beam DrawBeam( vecShootOrigin, tr.endpos, 15.5 ); //Creates an energy impact effect if we don't hit the sky or other places if ( (tr.surface.flags & SURF_SKY) == false ) { CPVSFilter filter( tr.endpos ); te->GaussExplosion( filter, 0.0f, tr.endpos, tr.plane.normal, 0 ); m_nBulletType = GetAmmoDef()->Index("GaussEnergy"); UTIL_ImpactTrace( &tr, m_nBulletType ); //Makes a sprite at the end of the beam m_pLightGlow = CSprite::SpriteCreate( "sprites/physcannon_bluecore2b.vmt", GetAbsOrigin(), TRUE); //Sets FX render and color m_pLightGlow->SetTransparency( 9, 255, 255, 255, 200, kRenderFxNoDissipation ); //Sets the position m_pLightGlow->SetAbsOrigin(tr.endpos); //Bright m_pLightGlow->SetBrightness( 255 ); //Scale m_pLightGlow->SetScale( 0.65 ); } #endif FireHook(); SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration( ACT_VM_PRIMARYATTACK ) ); }
void CC4::PrimaryAttack(void) { if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0) return; BOOL onBombZone = m_pPlayer->m_signals.GetState() & SIGNAL_BOMB; BOOL onGround = m_pPlayer->pev->flags & FL_ONGROUND; if (!m_bStartedArming) { if (!onBombZone) { ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "#C4_Plant_At_Bomb_Spot"); m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1; return; } if (!onGround) { ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "#C4_Plant_Must_Be_On_Ground"); m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1; return; } m_bStartedArming = true; m_bBombPlacedAnimation = false; m_fArmedTime = gpGlobals->time + 3; SendWeaponAnim(C4_ARM, UseDecrement() != FALSE); g_engfuncs.pfnSetClientMaxspeed(ENT(m_pPlayer->pev), 1); m_pPlayer->SetAnimation(PLAYER_ATTACK1); m_pPlayer->SetProgressBarTime(3); m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.3; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + RANDOM_FLOAT(10, 15); } else { if (!onGround || !onBombZone) { if (onBombZone) ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "#C4_Plant_Must_Be_On_Ground"); else ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "#C4_Arming_Cancelled"); m_bStartedArming = false; m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.5; m_pPlayer->ResetMaxSpeed(); m_pPlayer->SetProgressBarTime(0); m_pPlayer->SetAnimation(PLAYER_HOLDBOMB); if (m_bBombPlacedAnimation == true) SendWeaponAnim(C4_DRAW, UseDecrement() != FALSE); else SendWeaponAnim(C4_IDLE1, UseDecrement() != FALSE); return; } if (gpGlobals->time > m_fArmedTime) { if (m_bStartedArming == true) { m_bStartedArming = false; m_fArmedTime = 0; Broadcast("BOMBPL"); m_pPlayer->m_bHasC4 = false; #ifndef CLIENT_WEAPONS if (pev->speed != 0 && g_pGameRules) g_pGameRules->m_iC4Timer = (int)pev->speed; #endif CGrenade *pGrenade = CGrenade::ShootSatchelCharge(m_pPlayer->pev, m_pPlayer->pev->origin, Vector(0, 0, 0)); MESSAGE_BEGIN(MSG_SPEC, SVC_DIRECTOR); WRITE_BYTE(9); WRITE_BYTE(DRC_CMD_EVENT); WRITE_SHORT(ENTINDEX(m_pPlayer->edict())); WRITE_SHORT(0); WRITE_LONG(11 | DRC_FLAG_FACEPLAYER); MESSAGE_END(); #ifndef CLIENT_WEAPONS MESSAGE_BEGIN(MSG_ALL, gmsgBombDrop); WRITE_COORD(pGrenade->pev->origin.x); WRITE_COORD(pGrenade->pev->origin.y); WRITE_COORD(pGrenade->pev->origin.z); WRITE_BYTE(1); MESSAGE_END(); #endif UTIL_ClientPrintAll(HUD_PRINTCENTER, "#Bomb_Planted"); #ifndef CLIENT_WEAPONS if (g_pGameRules->IsCareer() && !m_pPlayer->IsBot()) { } #endif UTIL_LogPrintf("\"%s<%i><%s><TERRORIST>\" triggered \"Planted_The_Bomb\"\n", STRING(m_pPlayer->pev->netname), GETPLAYERUSERID(m_pPlayer->edict()), GETPLAYERAUTHID(m_pPlayer->edict())); #ifndef CLIENT_WEAPONS g_pGameRules->m_bBombDropped = false; #endif EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/c4_plant.wav", VOL_NORM, ATTN_NORM); m_pPlayer->pev->body = 0; m_pPlayer->ResetMaxSpeed(); m_pPlayer->SetBombIcon(FALSE); m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--; if (!m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]) { RetireWeapon(); return; } } } else { if (gpGlobals->time >= m_fArmedTime - 0.75) { if (m_bBombPlacedAnimation == false) { m_bBombPlacedAnimation = true; SendWeaponAnim(C4_DROP, UseDecrement() != FALSE); m_pPlayer->SetAnimation(PLAYER_HOLDBOMB); } } } } m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.3; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + RANDOM_FLOAT(10, 15); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponAR2::DelayedAttack( void ) { m_bShotDelayed = false; CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( pOwner == NULL ) return; // Deplete the clip completely SendWeaponAnim( ACT_VM_SECONDARYATTACK ); m_flNextSecondaryAttack = pOwner->m_flNextAttack = gpGlobals->curtime + SequenceDuration(); // Register a muzzleflash for the AI pOwner->DoMuzzleFlash(); pOwner->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 ); WeaponSound( WPN_DOUBLE ); pOwner->RumbleEffect(RUMBLE_SHOTGUN_DOUBLE, 0, RUMBLE_FLAG_RESTART ); // Fire the bullets Vector vecSrc = pOwner->Weapon_ShootPosition( ); Vector vecAiming = pOwner->GetAutoaimVector( AUTOAIM_SCALE_DEFAULT ); Vector impactPoint = vecSrc + ( vecAiming * MAX_TRACE_LENGTH ); // Fire the bullets Vector vecVelocity = vecAiming * 1000.0f; // Fire the combine ball CreateCombineBall( vecSrc, vecVelocity, sk_weapon_ar2_alt_fire_radius.GetFloat(), sk_weapon_ar2_alt_fire_mass.GetFloat(), sk_weapon_ar2_alt_fire_duration.GetFloat(), pOwner ); // View effects color32 white = {255, 255, 255, 64}; UTIL_ScreenFade( pOwner, white, 0.1, 0, FFADE_IN ); //Disorient the player QAngle angles = pOwner->GetLocalAngles(); angles.x += random->RandomInt( -4, 4 ); angles.y += random->RandomInt( -4, 4 ); angles.z = 0; pOwner->SnapEyeAngles( angles ); pOwner->ViewPunch( QAngle( random->RandomInt( -8, -12 ), random->RandomInt( 1, 2 ), 0 ) ); // Decrease ammo pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType ); // Can shoot again immediately m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f; // Can blow up after a short delay (so have time to release mouse button) m_flNextSecondaryAttack = gpGlobals->curtime + 1.0f; }
//-------------------------------------------- // iDamageAmount - how much damage to give // iDamageType - DMG_ bits // flDmgDelay - delay between attack and the giving of damage, usually timed to animation // flAttackDelay - time until we can next attack //-------------------------------------------- CBaseEntity *CWeaponDODBase::MeleeAttack( int iDamageAmount, int iDamageType, float flDmgDelay, float flAttackDelay ) { if ( !CanAttack() ) return NULL; CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() ); #if !defined (CLIENT_DLL) // Move other players back to history positions based on local player's lag lagcompensation->StartLagCompensation( pPlayer, pPlayer->GetCurrentCommand() ); #endif Vector vForward, vRight, vUp; AngleVectors( pPlayer->EyeAngles(), &vForward, &vRight, &vUp ); Vector vecSrc = pPlayer->Weapon_ShootPosition(); Vector vecEnd = vecSrc + vForward * 48; CTraceFilterSimple filter( pPlayer, COLLISION_GROUP_NONE ); int iTraceMask = MASK_SOLID | CONTENTS_HITBOX | CONTENTS_DEBRIS; trace_t tr; UTIL_TraceLine( vecSrc, vecEnd, iTraceMask, &filter, &tr ); const float rayExtension = 40.0f; UTIL_ClipTraceToPlayers( vecSrc, vecEnd + vForward * rayExtension, iTraceMask, &filter, &tr ); // If the exact forward trace did not hit, try a larger swept box if ( tr.fraction >= 1.0 ) { Vector head_hull_mins( -16, -16, -18 ); Vector head_hull_maxs( 16, 16, 18 ); UTIL_TraceHull( vecSrc, vecEnd, head_hull_mins, head_hull_maxs, MASK_SOLID, &filter, &tr ); if ( tr.fraction < 1.0 ) { // Calculate the point of intersection of the line (or hull) and the object we hit // This is and approximation of the "best" intersection CBaseEntity *pHit = tr.m_pEnt; if ( !pHit || pHit->IsBSPModel() ) FindHullIntersection( vecSrc, tr, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX, pPlayer ); vecEnd = tr.endpos; // This is the point on the actual surface (the hull could have hit space) // Make sure it is in front of us Vector vecToEnd = vecEnd - vecSrc; VectorNormalize( vecToEnd ); // if zero length, always hit if ( vecToEnd.Length() > 0 ) { float dot = DotProduct( vForward, vecToEnd ); // sanity that our hit is within range if ( abs(dot) < 0.95 ) { // fake that we actually missed tr.fraction = 1.0; } } } } WeaponSound( MELEE_MISS ); bool bDidHit = ( tr.fraction < 1.0f ); if ( bDidHit ) //if the swing hit { // delay the decal a bit m_trHit = tr; // Store the ent in an EHANDLE, just in case it goes away by the time we get into our think function. m_pTraceHitEnt = tr.m_pEnt; m_iSmackDamage = iDamageAmount; m_iSmackDamageType = iDamageType; m_flSmackTime = gpGlobals->curtime + flDmgDelay; } SendWeaponAnim( GetMeleeActivity() ); // player animation pPlayer->DoAnimationEvent( PLAYERANIMEVENT_SECONDARY_ATTACK ); m_flNextPrimaryAttack = gpGlobals->curtime + flAttackDelay; m_flNextSecondaryAttack = gpGlobals->curtime + flAttackDelay; m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration(); #ifndef CLIENT_DLL IGameEvent * event = gameeventmanager->CreateEvent( "dod_stats_weapon_attack" ); if ( event ) { event->SetInt( "attacker", pPlayer->GetUserID() ); event->SetInt( "weapon", GetAltWeaponID() ); gameeventmanager->FireEvent( event ); } lagcompensation->FinishLagCompensation( pPlayer ); #endif //CLIENT_DLL return tr.m_pEnt; }
void CHandGrenade::WeaponIdle(void) { if (m_flTimeUpdate < UTIL_GlobalTimeBase() && m_iChargeLevel) { // we've finished the throw, restart. m_flStartThrow = 0; m_iChargeLevel = 0; if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]) SendWeaponAnim(HANDGRENADE_DRAW); else { RetireWeapon(); return; } m_flTimeWeaponIdle = UTIL_GlobalTimeBase() + RANDOM_LONG(10, 15); return; } if (m_flTimeWeaponIdle > UTIL_GlobalTimeBase()) return; if (m_flStartThrow) { Vector angThrow = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle; if (angThrow.x < 0) angThrow.x = -10 + angThrow.x * ((90 - 10) / 90.0); else angThrow.x = -10 + angThrow.x * ((90 + 10) / 90.0); float flVel = (90 - angThrow.x) * 4; if (flVel > 500) flVel = 500; UTIL_MakeVectors(angThrow); Vector vecSrc = m_pPlayer->pev->origin + m_pPlayer->pev->view_ofs + gpGlobals->v_forward * 16; Vector vecThrow = gpGlobals->v_forward * flVel + m_pPlayer->pev->velocity; // alway explode 3 seconds after the pin was pulled float time = m_flStartThrow - UTIL_GlobalTimeBase() + 3.0; if (time < 0) time = 0; CGrenade::ShootTimed(m_pPlayer->pev, vecSrc, vecThrow, time); if (flVel < 500) SendWeaponAnim(HANDGRENADE_THROW1); else if (flVel < 1000) SendWeaponAnim(HANDGRENADE_THROW2); else SendWeaponAnim(HANDGRENADE_THROW3); // player "shoot" animation m_pPlayer->SetAnimation(PLAYER_ATTACK1); m_flStartThrow = 0; m_iChargeLevel = 1; m_flNextPrimaryAttack = UTIL_GlobalTimeBase() + 0.5; m_flTimeWeaponIdle = UTIL_GlobalTimeBase() + 0.5; m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--; if (!m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]) { // just threw last grenade // set attack times in the future, and weapon idle in the future so we can see the whole throw // animation, weapon idle will automatically retire the weapon for us. m_flTimeWeaponIdle = m_flNextSecondaryAttack = m_flNextPrimaryAttack = UTIL_GlobalTimeBase() + 0.5;// ensure that the animation can finish playing } m_flTimeUpdate = m_flNextSecondaryAttack = m_flNextPrimaryAttack = UTIL_GlobalTimeBase() + 1.0; m_flTimeWeaponIdle = UTIL_GlobalTimeBase() + 3.0; return; } if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]) { int iAnim; float flRand = RANDOM_FLOAT(0, 1); if (flRand <= 0.75) { iAnim = HANDGRENADE_IDLE; m_flTimeWeaponIdle = UTIL_GlobalTimeBase() + RANDOM_LONG(10, 15);// how long till we do this again. } else { iAnim = HANDGRENADE_FIDGET; m_flTimeWeaponIdle = UTIL_GlobalTimeBase() + 75.0 / 30.0; } SendWeaponAnim(iAnim); } }
bool CWeaponDODBase::DefaultReload( int iClipSize1, int iClipSize2, int iActivity ) { CBaseCombatCharacter *pOwner = GetOwner(); if (!pOwner) return false; // If I don't have any spare ammo, I can't reload if ( pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) return false; bool bReload = false; // If you don't have clips, then don't try to reload them. if ( UsesClipsForAmmo1() ) { // need to reload primary clip? int primary = min(iClipSize1 - m_iClip1, pOwner->GetAmmoCount(m_iPrimaryAmmoType)); if ( primary != 0 ) { bReload = true; } } if ( UsesClipsForAmmo2() ) { // need to reload secondary clip? int secondary = min(iClipSize2 - m_iClip2, pOwner->GetAmmoCount(m_iSecondaryAmmoType)); if ( secondary != 0 ) { bReload = true; } } if ( !bReload ) return false; CDODPlayer *pPlayer = GetDODPlayerOwner(); if ( pPlayer ) { #ifdef CLIENT_DLL PlayWorldReloadSound( pPlayer ); #else pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD ); #endif } SendWeaponAnim( iActivity ); // Play the player's reload animation if ( pOwner->IsPlayer() ) { ( ( CBasePlayer * )pOwner)->SetAnimation( PLAYER_RELOAD ); } float flSequenceEndTime = gpGlobals->curtime + SequenceDuration(); pOwner->SetNextAttack( flSequenceEndTime ); m_flNextPrimaryAttack = m_flNextSecondaryAttack = flSequenceEndTime; m_bInReload = true; return true; }
/* <ccad8> ../cstrike/dlls/h_cycler.cpp:394 */ void CWeaponCycler::__MAKE_VHOOK(PrimaryAttack)() { SendWeaponAnim(pev->sequence); m_flNextPrimaryAttack = gpGlobals->time + 0.3f; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponFrag::ItemPostFrame( void ) { #ifdef MFS if (!HasPrimaryAmmo()) weight = 0; else if (GetPrimaryAmmoCount() == 1 ) weight = 0.5; else if (GetPrimaryAmmoCount() == 2) weight = 1; else if (GetPrimaryAmmoCount() == 3) weight = 1.5; else if (GetPrimaryAmmoCount() == 4) weight = 2; else if (GetPrimaryAmmoCount() == 5) weight = 2.5; else if (GetPrimaryAmmoCount() == 6) weight = 3; #endif if( m_fDrawbackFinished ) { CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if (pOwner) { switch( m_AttackPaused ) { case GRENADE_PAUSED_PRIMARY: if( !(pOwner->m_nButtons & IN_ATTACK) ) { SendWeaponAnim( ACT_VM_THROW ); m_fDrawbackFinished = false; } break; case GRENADE_PAUSED_SECONDARY: if( !(pOwner->m_nButtons & IN_ATTACK2) ) { //See if we're ducking if ( pOwner->m_nButtons & IN_DUCK ) { //Send the weapon animation SendWeaponAnim( ACT_VM_SECONDARYATTACK ); } else { //Send the weapon animation SendWeaponAnim( ACT_VM_HAULBACK ); } m_fDrawbackFinished = false; } break; default: break; } } } BaseClass::ItemPostFrame(); if ( m_bRedraw ) { if ( IsViewModelSequenceFinished() ) { Reload(); } } }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- 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 ); // Don't fire again until fire animation has completed m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); m_iClip1 -= 1; // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); ToHL2MPPlayer(pPlayer)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); #ifdef HL2SB #ifndef CLIENT_DLL pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 1.0 ); #endif #endif #ifndef HL2SB FireBulletsInfo_t info( 7, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); #else FireBulletsInfo_t info( sk_plr_num_shotgun_pellets.GetInt(), vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); #endif info.m_pAttacker = pPlayer; // Fire the bullets, and force the first shot to be perfectly accuracy pPlayer->FireBullets( info ); QAngle punch; punch.Init( SharedRandomFloat( "shotgunpax", -2, -1 ), SharedRandomFloat( "shotgunpay", -2, 2 ), 0 ); pPlayer->ViewPunch( punch ); #ifdef HL2SB #ifndef CLIENT_DLL CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_SHOTGUN, 0.2, GetOwner() ); #endif #endif if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } m_bNeedPump = true; #ifdef HL2SB #ifndef CLIENT_DLL gamestats->Event_WeaponFired( pPlayer, true, GetClassname() ); #endif #endif }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponOICW::GrenadeAttack(void) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer(GetOwner()); if (pPlayer == NULL) return; //Must have ammo if ((pPlayer->GetAmmoCount(m_iSecondaryAmmoType) <= 0) || (pPlayer->GetWaterLevel() == 3)) { SendWeaponAnim(ACT_VM_DRYFIRE); BaseClass::WeaponSound(EMPTY); m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f; return; } if (m_bInReload) m_bInReload = false; // MUST call sound before removing a round from the clip of a CMachineGun BaseClass::WeaponSound(WPN_DOUBLE); pPlayer->RumbleEffect(RUMBLE_357, 0, RUMBLE_FLAGS_NONE); Vector vecSrc = pPlayer->Weapon_ShootPosition(); Vector vecThrow; // Don't autoaim on grenade tosses AngleVectors(pPlayer->EyeAngles() + pPlayer->GetPunchAngle(), &vecThrow); VectorScale(vecThrow, 1000.0f, vecThrow); //Create the grenade QAngle angles; VectorAngles(vecThrow, angles); CGrenadeOCIW *pGrenade = (CGrenadeOCIW*)Create("grenade_ociw", vecSrc, angles, pPlayer); pGrenade->SetAbsVelocity(vecThrow); pGrenade->SetLocalAngularVelocity(RandomAngle(-400, 400)); pGrenade->SetMoveType(MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE); pGrenade->SetThrower(GetOwner()); pGrenade->SetDamage(sk_plr_dmg_oicw_grenade.GetFloat()); SendWeaponAnim(ACT_VM_SECONDARYATTACK); CSoundEnt::InsertSound(SOUND_COMBAT, GetAbsOrigin(), 1000, 0.2, GetOwner(), SOUNDENT_CHANNEL_WEAPON); // player "shoot" animation pPlayer->SetAnimation(PLAYER_ATTACK1); // Decrease ammo pPlayer->RemoveAmmo(1, m_iSecondaryAmmoType); // Can shoot again immediately m_flNextPrimaryAttack = gpGlobals->curtime + 0.5f; // Can blow up after a short delay (so have time to release mouse button) m_flNextSecondaryAttack = gpGlobals->curtime + 1.0f; // Register a muzzleflash for the AI. pPlayer->SetMuzzleFlashTime(gpGlobals->curtime + 0.5); m_iSecondaryAttacks++; gamestats->Event_WeaponFired(pPlayer, false, GetClassname()); }
void CWeaponPistol::SecondaryAttack(void) { // Check our secondary attack delay before anything if (m_flNextSecondaryAttack > gpGlobals->curtime) return; // 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 = 3; float fireRate = GetFireRate(); // MUST call sound before removing a round from the clip of a CHLMachineGun while (m_flNextPrimaryAttack <= gpGlobals->curtime) { WeaponSound(BURST, 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 > 3) iBulletsToFire = 3; 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(); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } SendWeaponAnim(GetSecondaryAttackActivity()); pPlayer->SetAnimation(PLAYER_ATTACK1); m_flNextSecondaryAttack = gpGlobals->curtime + 0.5; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponCrossbow::FireBolt( void ) { if ( m_iClip1 <= 0 ) { if ( !m_bFireOnEmpty ) { Reload(); } else { WeaponSound( EMPTY ); m_flNextPrimaryAttack = 0.15; } return; } CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( pOwner == NULL ) return; #ifndef CLIENT_DLL Vector vecAiming = pOwner->GetAutoaimVector( 0 ); Vector vecSrc = pOwner->Weapon_ShootPosition(); QAngle angAiming; VectorAngles( vecAiming, angAiming ); CCrossbowBolt *pBolt = CCrossbowBolt::BoltCreate( vecSrc, angAiming, GetHL2MPWpnData().m_iPlayerDamage, pOwner ); if ( pOwner->GetWaterLevel() == 3 ) { pBolt->SetAbsVelocity( vecAiming * BOLT_WATER_VELOCITY ); } else { pBolt->SetAbsVelocity( vecAiming * BOLT_AIR_VELOCITY ); } #endif m_iClip1--; pOwner->ViewPunch( QAngle( -2, 0, 0 ) ); WeaponSound( SINGLE ); WeaponSound( SPECIAL2 ); SendWeaponAnim( ACT_VM_PRIMARYATTACK ); if ( !m_iClip1 && pOwner->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 ) { // HEV suit - indicate out of ammo condition pOwner->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + 0.75; DoLoadEffect(); SetChargerState( CHARGER_STATE_DISCHARGE ); }
void CWeaponCombatCannon::CombatHealIncrement( void ) { CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); // Find and check the player's punch angle for // a block in sight CBlockBase *pBlock = FindTraceBlock(); if( !pBlock ) { ResetHealing(); return; } if ( pBlock->GetHealth() + lf_heal_increment_combat.GetFloat() >= pBlock->GetMaxHealth() ) { return; } else if ( pPlayer->GetTeamNumber() != pBlock->GetTeamNumber() ) { // You may not heal a block not belonging to your team return; } m_vecPlayerHealPosition = m_tr.endpos; // Check if the player has moved too far back from the freezing point float healDistance = fabs( ( pPlayer->GetAbsOrigin() - m_vecPlayerHealPosition ).Length() ); if ( healDistance > lf_heal_distance_combat.GetFloat() ) { ResetHealing(); return; } // First time heaing, so start the sound if ( m_flLastHeal <= 0.0f ) { // Play our repairing noise pBlock->EmitSound( "Luminousforts.Repair" ); m_pLastBlock = pBlock; } // Start healing the block if ( m_flLastHeal + lf_heal_delay_combat.GetFloat() <= gpGlobals->curtime ) { pBlock->SetHealth( pBlock->GetHealth() + lf_heal_increment_combat.GetFloat() ); SendWeaponAnim( ACT_VM_PRIMARYATTACK ); DoEffect( EFFECT_HOLDING ); float health = pBlock->GetHealth(); float maxHealth = pBlock->GetMaxHealth(); float percentage = ( health / maxHealth ) * 100; // Send a message with information on the amount frozen. CSingleUserRecipientFilter user( ToBasePlayer( GetOwner() ) ); // Send our stuff over the wire UserMessageBegin( user, "UpdateFreezeProgress" ); WRITE_BYTE( 1 ); // Letting the HUD know it's time to turn on WRITE_LONG( SFH_FREEZEPROGRESS_HEALING ); WRITE_FLOAT( percentage ); MessageEnd(); m_bHealing = true; m_flLastHeal = gpGlobals->curtime; } }
void CFlashBang::WeaponIdle( void ) { if ( m_flReleaseThrow == 0 && m_flStartThrow ) m_flReleaseThrow = gpGlobals->time; if ( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() ) return; if ( m_flStartThrow ) { Vector angThrow = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle; if ( angThrow.x < 0 ) angThrow.x = -10 + angThrow.x * ( ( 90 - 10 ) / 90.0 ); else angThrow.x = -10 + angThrow.x * ( ( 90 + 10 ) / 90.0 ); float flVel = ( 90 - angThrow.x ) * 6; if ( flVel > 750 ) { flVel = 750; } UTIL_MakeVectors( angThrow ); Vector vecSrc = m_pPlayer->GetGunPosition() + gpGlobals->v_forward * 16; Vector vecThrow = gpGlobals->v_forward * flVel + m_pPlayer->pev->velocity; CGrenade::FlashShoot( m_pPlayer->pev, vecSrc, vecThrow, 1.5, "models/weapons/flashbang/w_flashbang.mdl", 100 ); SendWeaponAnim( FLASHBANG_THROW, UseDecrement() ); m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); m_flStartThrow = 0; m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.75; m_pPlayer->m_rgAmmo[ m_iPrimaryAmmoType ]--; if ( !m_pPlayer->m_rgAmmo[ m_iPrimaryAmmoType ] ) { m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5; m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5; m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5; } return; } else if ( m_flReleaseThrow > 0 ) { // we've finished the throw, restart. m_flStartThrow = 0; if ( m_pPlayer->m_rgAmmo[ m_iPrimaryAmmoType ] ) { SendWeaponAnim( FLASHBANG_DEPLOY ); } else { RetireWeapon(); return; } m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); m_flReleaseThrow = -1; return; } if ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] ) { SendWeaponAnim( FLASHBANG_IDLE, UseDecrement() ); m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + RANDOM_FLOAT( 10.0, 15.0 ); } }
void CWeaponElite::ELITEFire( float flSpread ) { CCSPlayer *pPlayer = GetPlayerOwner(); if ( !pPlayer ) return; pPlayer->m_iShotsFired++; if (pPlayer->m_iShotsFired > 1) return; // Mark the time of this shot and determine the accuracy modifier based on the last shot fired... m_flAccuracy -= (0.275)*(0.325 - (gpGlobals->curtime - m_flLastFire)); if (m_flAccuracy > 0.88) m_flAccuracy = 0.88; else if (m_flAccuracy < 0.55) m_flAccuracy = 0.55; m_flLastFire = gpGlobals->curtime; if (m_iClip1 <= 0) { if (m_bFireOnEmpty) { PlayEmptySound(); m_flNextPrimaryAttack = gpGlobals->curtime + 0.2; } return; } m_iClip1--; m_bFireRight = !m_bFireRight; // flip side pPlayer->DoMuzzleFlash(); //SetPlayerShieldAnim(); // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); FX_FireBullets( pPlayer->entindex(), pPlayer->Weapon_ShootPosition(), pPlayer->EyeAngles() + 2.0f * pPlayer->GetPunchAngle(), GetWeaponID(), m_bFireRight?Primary_Mode:Secondary_Mode, CBaseEntity::GetPredictionRandomSeed() & 255, flSpread ); m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + GetCSWpnData().m_flCycleTime; if (!m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0); } SetWeaponIdleTime( gpGlobals->curtime + 2.5 ); if ( m_bFireRight ) //even number { if ( m_iClip1 > 1 ) SendWeaponAnim( ACT_VM_PRIMARYATTACK ); else SendWeaponAnim( ACT_VM_DRYFIRE_LEFT ); } else { if ( m_iClip1 > 0 ) SendWeaponAnim( ACT_VM_SECONDARYATTACK ); else SendWeaponAnim( ACT_VM_DRYFIRE ); } QAngle punchAngle = pPlayer->GetPunchAngle(); punchAngle.x -= 2; pPlayer->SetPunchAngle( punchAngle ); //ResetPlayerShieldAnim(); }
void CASW_Weapon::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 ) return; m_bIsFiring = true; // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(SINGLE); if (m_iClip1 <= AmmoClickPoint()) { LowAmmoSound(); } // tell the marine to tell its weapon to draw the muzzle flash pMarine->DoMuzzleFlash(); // sets the animation on the weapon model itself SendWeaponAnim( GetPrimaryAttackActivity() ); // sets the animation on the marine holding this weapon //pMarine->SetAnimation( PLAYER_ATTACK1 ); #ifdef GAME_DLL // check for turning on lag compensation if (pPlayer && pMarine->IsInhabited()) { CASW_Lag_Compensation::RequestLagCompensation( pPlayer, pPlayer->GetCurrentUserCommand() ); } #endif FireBulletsInfo_t info; info.m_vecSrc = pMarine->Weapon_ShootPosition( ); if ( pPlayer && pMarine->IsInhabited() ) { info.m_vecDirShooting = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount()); // 45 degrees = 0.707106781187 } else { #ifdef CLIENT_DLL Msg("Error, clientside firing of a weapon that's being controlled by an AI marine\n"); #else info.m_vecDirShooting = pMarine->GetActualShootTrajectory( info.m_vecSrc ); #endif } // 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. info.m_iShots = 0; float fireRate = GetFireRate(); while ( m_flNextPrimaryAttack <= gpGlobals->curtime ) { m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate; info.m_iShots++; if ( !fireRate ) break; } // Make sure we don't fire more than the amount in the clip if ( UsesClipsForAmmo1() ) { info.m_iShots = MIN( info.m_iShots, m_iClip1 ); m_iClip1 -= info.m_iShots; #ifdef GAME_DLL CASW_Marine *pMarine = GetMarine(); if (pMarine && m_iClip1 <= 0 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) { // check he doesn't have ammo in an ammo bay CASW_Weapon_Ammo_Bag* pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>(pMarine->GetASWWeapon(0)); if (!pAmmoBag) pAmmoBag = dynamic_cast<CASW_Weapon_Ammo_Bag*>(pMarine->GetASWWeapon(1)); if (!pAmmoBag || !pAmmoBag->CanGiveAmmoToWeapon(this)) pMarine->OnWeaponOutOfAmmo(true); } #endif } else { info.m_iShots = MIN( info.m_iShots, pMarine->GetAmmoCount( m_iPrimaryAmmoType ) ); pMarine->RemoveAmmo( info.m_iShots, m_iPrimaryAmmoType ); } info.m_flDistance = asw_weapon_max_shooting_distance.GetFloat(); info.m_iAmmoType = m_iPrimaryAmmoType; info.m_iTracerFreq = 1; // asw tracer test everytime info.m_flDamageForceScale = asw_weapon_force_scale.GetFloat(); info.m_vecSpread = pMarine->GetActiveWeapon()->GetBulletSpread(); info.m_flDamage = GetWeaponDamage(); #ifndef CLIENT_DLL if (asw_debug_marine_damage.GetBool()) Msg("Weapon dmg = %f\n", info.m_flDamage); info.m_flDamage *= pMarine->GetMarineResource()->OnFired_GetDamageScale(); if (asw_DebugAutoAim.GetBool()) { NDebugOverlay::Line(info.m_vecSrc, info.m_vecSrc + info.m_vecDirShooting * info.m_flDistance, 64, 0, 64, true, 1.0); } #endif pMarine->FireBullets( info ); // increment shooting stats #ifndef CLIENT_DLL if (pMarine && pMarine->GetMarineResource()) { pMarine->GetMarineResource()->UsedWeapon(this, info.m_iShots); pMarine->OnWeaponFired( this, info.m_iShots ); } #endif }
//------------------------------------------------------------------------------ // Purpose : Starts the swing of the weapon and determines the animation // Input : bIsSecondary - is this a secondary attack? //------------------------------------------------------------------------------ void CBaseHLBludgeonWeapon::Swing( int bIsSecondary ) { trace_t traceHit; // Try a ray CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return; pOwner->RumbleEffect( RUMBLE_CROWBAR_SWING, 0, RUMBLE_FLAG_RESTART ); Vector swingStart = pOwner->Weapon_ShootPosition( ); Vector forward; pOwner->EyeVectors(&forward); Vector swingEnd = swingStart + forward * GetRange(); UTIL_TraceLine( swingStart, swingEnd, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit ); Activity nHitActivity = ACT_VM_HITCENTER; // Like bullets, bludgeon traces have to trace against triggers. CTakeDamageInfo triggerInfo( GetOwner(), GetOwner(), GetDamageForActivity( nHitActivity ), DMG_CLUB ); triggerInfo.SetDamagePosition( traceHit.startpos ); triggerInfo.SetDamageForce( forward ); TraceAttackToTriggers( triggerInfo, traceHit.startpos, traceHit.endpos, forward ); if ( traceHit.fraction == 1.0 ) { float bludgeonHullRadius = 1.732f * BLUDGEON_HULL_DIM; // hull is +/- 16, so use cuberoot of 2 to determine how big the hull is from center to the corner point // Back off by hull "radius" swingEnd -= forward * bludgeonHullRadius; UTIL_TraceHull( swingStart, swingEnd, g_bludgeonMins, g_bludgeonMaxs, MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &traceHit ); if ( traceHit.fraction < 1.0 && traceHit.m_pEnt ) { Vector vecToTarget = traceHit.m_pEnt->GetAbsOrigin() - swingStart; VectorNormalize( vecToTarget ); float dot = vecToTarget.Dot( forward ); // YWB: Make sure they are sort of facing the guy at least... if ( dot < 0.70721f ) { // Force amiss traceHit.fraction = 1.0f; } else { nHitActivity = ChooseIntersectionPointAndActivity( traceHit, g_bludgeonMins, g_bludgeonMaxs, pOwner ); } } } if ( !bIsSecondary ) { m_iPrimaryAttacks++; } else { m_iSecondaryAttacks++; } gamestats->Event_WeaponFired( pOwner, !bIsSecondary, GetClassname() ); // ------------------------- // Miss // ------------------------- if ( traceHit.fraction == 1.0f ) { nHitActivity = bIsSecondary ? ACT_VM_MISSCENTER2 : ACT_VM_MISSCENTER; // We want to test the first swing again Vector testEnd = swingStart + forward * GetRange(); // See if we happened to hit water ImpactWater( swingStart, testEnd ); } else { Hit( traceHit, nHitActivity, bIsSecondary ? true : false ); } // Send the anim SendWeaponAnim( nHitActivity ); //Setup our next attack times m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate(); m_flNextSecondaryAttack = gpGlobals->curtime + SequenceDuration(); //Play swing sound WeaponSound( SINGLE ); }
void CASW_Weapon_Mines::PrimaryAttack( void ) { // Only the player fires this way so we can cast CASW_Player *pPlayer = GetCommander(); if (!pPlayer) return; CASW_Marine *pMarine = GetMarine(); #ifndef CLIENT_DLL bool bThisActive = (pMarine && pMarine->GetActiveWeapon() == this); #endif // mine weapon is lost when all mines are gone if ( UsesClipsForAmmo1() && !m_iClip1 ) { //Reload(); #ifndef CLIENT_DLL if (pMarine) { pMarine->Weapon_Detach(this); if (bThisActive) pMarine->SwitchToNextBestWeapon(NULL); } Kill(); #endif return; } if ( !pMarine || pMarine->GetWaterLevel() == 3 ) return; // MUST call sound before removing a round from the clip of a CMachineGun //WeaponSound(SINGLE); // tell the marine to tell its weapon to draw the muzzle flash //pMarine->DoMuzzleFlash(); // sets the animation on the weapon model iteself SendWeaponAnim( GetPrimaryAttackActivity() ); //pMarine->DoAnimationEvent(PLAYERANIMEVENT_HEAL); // sets the animation on the marine holding this weapon //pMarine->SetAnimation( PLAYER_ATTACK1 ); #ifndef CLIENT_DLL Vector vecSrc = pMarine->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount()); // 45 degrees = 0.707106781187 if ( !pMarine->IsInhabited() && vecSrc.DistTo( pMarine->m_vecOffhandItemSpot ) < 150.0f ) { vecSrc.x = pMarine->m_vecOffhandItemSpot.x; vecSrc.y = pMarine->m_vecOffhandItemSpot.y; vecSrc.z += 50.0f; } QAngle ang = pPlayer->EyeAngles(); ang.x = 0; ang.z = 0; CShotManipulator Manipulator( vecAiming ); AngularImpulse rotSpeed(0,0,720); // create a pellet at some random spread direction Vector newVel = Manipulator.ApplySpread(GetBulletSpread()); newVel *= ASW_MINE_VELOCITY; if ( !pMarine->IsInhabited() ) { newVel = vec3_origin; } CASW_Mine *pMine = CASW_Mine::ASW_Mine_Create( vecSrc, ang, newVel, rotSpeed, pMarine, this ); if ( pMine ) { float flDurationScale = 1.0f; int iExtraFires = 0; //CALL_ATTRIB_HOOK_FLOAT( flDurationScale, mod_duration ); //CALL_ATTRIB_HOOK_INT( iExtraFires, mod_firewall_length ); pMine->m_flDurationScale = flDurationScale; pMine->m_iExtraFires = iExtraFires; pMarine->OnWeaponFired( this, 1 ); } pMarine->GetMarineSpeech()->Chatter(CHATTER_MINE_DEPLOYED); #endif // decrement ammo m_iClip1 -= 1; #ifndef CLIENT_DLL DestroyIfEmpty( true ); #endif m_flSoonestPrimaryAttack = gpGlobals->curtime + ASW_FLARES_FASTEST_REFIRE_TIME; if (m_iClip1 > 0) // only force the fire wait time if we have ammo for another shot m_flNextPrimaryAttack = gpGlobals->curtime + GetFireRate(); else m_flNextPrimaryAttack = gpGlobals->curtime; }
float CWeaponPortalgun::FirePortal( bool bPortal2, Vector *pVector /*= 0*/, bool bTest /*= false*/ ) { bool bPlayer = false; Vector vEye; Vector vDirection; Vector vTracerOrigin; CBaseEntity *pOwner = GetOwner(); if ( pOwner && pOwner->IsPlayer() ) { bPlayer = true; } if( bPlayer ) { CPortal_Player *pPlayer = (CPortal_Player *)pOwner; if ( !bTest && pPlayer ) { pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY, 0 ); } Vector forward, right, up; AngleVectors( pPlayer->EyeAngles(), &forward, &right, &up ); pPlayer->EyeVectors( &vDirection, NULL, NULL ); vEye = pPlayer->EyePosition(); // Check if the players eye is behind the portal they're in and translate it VMatrix matThisToLinked; CProp_Portal *pPlayerPortal = pPlayer->m_hPortalEnvironment; if ( pPlayerPortal ) { Vector ptPortalCenter; Vector vPortalForward; ptPortalCenter = pPlayerPortal->GetAbsOrigin(); pPlayerPortal->GetVectors( &vPortalForward, NULL, NULL ); Vector vEyeToPortalCenter = ptPortalCenter - vEye; float fPortalDist = vPortalForward.Dot( vEyeToPortalCenter ); if( fPortalDist > 0.0f ) { // Eye is behind the portal matThisToLinked = pPlayerPortal->MatrixThisToLinked(); } else { pPlayerPortal = NULL; } } if ( pPlayerPortal ) { UTIL_Portal_VectorTransform( matThisToLinked, forward, forward ); UTIL_Portal_VectorTransform( matThisToLinked, right, right ); UTIL_Portal_VectorTransform( matThisToLinked, up, up ); UTIL_Portal_VectorTransform( matThisToLinked, vDirection, vDirection ); UTIL_Portal_PointTransform( matThisToLinked, vEye, vEye ); if ( pVector ) { UTIL_Portal_VectorTransform( matThisToLinked, *pVector, *pVector ); } } vTracerOrigin = vEye + forward * 30.0f + right * 4.0f + up * (-5.0f); } else { // This portalgun is not held by the player-- Fire using the muzzle attachment Vector vecShootOrigin; QAngle angShootDir; GetAttachment( LookupAttachment( "muzzle" ), vecShootOrigin, angShootDir ); vEye = vecShootOrigin; vTracerOrigin = vecShootOrigin; AngleVectors( angShootDir, &vDirection, NULL, NULL ); } if ( !bTest ) { SendWeaponAnim( ACT_VM_PRIMARYATTACK ); } if ( pVector ) { vDirection = *pVector; } Vector vTraceStart = vEye + (vDirection * m_fMinRange1); Vector vFinalPosition; QAngle qFinalAngles; PortalPlacedByType ePlacedBy = ( bPlayer ) ? ( PORTAL_PLACED_BY_PLAYER ) : ( PORTAL_PLACED_BY_PEDESTAL ); trace_t tr; float fPlacementSuccess = TraceFirePortal( bPortal2, vTraceStart, vDirection, tr, vFinalPosition, qFinalAngles, ePlacedBy, bTest ); if ( sv_portal_placement_never_fail.GetBool() ) { fPlacementSuccess = 1.0f; } if ( !bTest ) { CProp_Portal *pPortal = CProp_Portal::FindPortal( m_iPortalLinkageGroupID, bPortal2, true ); // If it was a failure, put the effect at exactly where the player shot instead of where the portal bumped to if ( fPlacementSuccess < 0.5f ) vFinalPosition = tr.endpos; pPortal->PlacePortal( vFinalPosition, qFinalAngles, fPlacementSuccess, true ); float fDelay = vTracerOrigin.DistTo( tr.endpos ) / ( ( bPlayer ) ? ( BLAST_SPEED ) : ( BLAST_SPEED_NON_PLAYER ) ); QAngle qFireAngles; VectorAngles( vDirection, qFireAngles ); DoEffectBlast( pPortal->m_bIsPortal2, ePlacedBy, vTracerOrigin, vFinalPosition, qFireAngles, fDelay ); pPortal->SetContextThink( &CProp_Portal::DelayedPlacementThink, gpGlobals->curtime + fDelay, s_pDelayedPlacementContext ); pPortal->m_vDelayedPosition = vFinalPosition; pPortal->m_hPlacedBy = this; } return fPlacementSuccess; }
void CFlakcannon::Holster( ) { m_fInReload = FALSE; SendWeaponAnim( (m_iClip)?FLAKCANNON_HOLSTER:FLAKCANNON_HOLSTER_EMPTY ); m_pPlayer->m_flNextAttack = gpGlobals->time + 0.7; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeapon357::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; } WeaponSound( SINGLE ); pPlayer->DoMuzzleFlash(); SendWeaponAnim( ACT_VM_PRIMARYATTACK ); pPlayer->SetAnimation( PLAYER_ATTACK1 ); ToHL2MPPlayer(pPlayer)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY ); m_flNextPrimaryAttack = gpGlobals->curtime + 0.75; m_flNextSecondaryAttack = gpGlobals->curtime + 0.75; m_iClip1--; Vector vecSrc = pPlayer->Weapon_ShootPosition(); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES ); FireBulletsInfo_t info( 1, vecSrc, vecAiming, vec3_origin, MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); info.m_pAttacker = pPlayer; // Fire the bullets, and force the first shot to be perfectly accuracy pPlayer->FireBullets( info ); //Disorient the player QAngle angles = pPlayer->GetLocalAngles(); angles.x += random->RandomInt( -1, 1 ); angles.y += random->RandomInt( -1, 1 ); angles.z = 0; #ifndef CLIENT_DLL pPlayer->SnapEyeAngles( angles ); #endif pPlayer->ViewPunch( QAngle( -8, random->RandomFloat( -2, 2 ), 0 ) ); if ( !m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 ) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 ); } }
void CBandsaw::Holster( ) { STOP_SOUND( ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/bandsaw_idle.wav" ); m_pPlayer->m_flNextAttack = gpGlobals->time + 0.6; SendWeaponAnim( BANDSAW_HOLSTER ); }
void CHandGrenade::WeaponIdle( void ) { if ( m_flReleaseThrow == 0 && m_flStartThrow ) m_flReleaseThrow = gpGlobals->time; if ( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() ) return; if ( m_flStartThrow ) { Vector angThrow = m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle; if ( angThrow.x < 0 ) angThrow.x = -10 + angThrow.x * ( ( 90 - 10 ) / 90.0 ); else angThrow.x = -10 + angThrow.x * ( ( 90 + 10 ) / 90.0 ); float flVel = ( 90 - angThrow.x ) * 6; if ( flVel > 800 ) flVel = 800; ALERT( at_console, "flVel: %f\n", flVel ); UTIL_MakeVectors( angThrow ); Vector vecSrc = m_pPlayer->pev->origin + m_pPlayer->pev->view_ofs + gpGlobals->v_forward * 16; Vector vecThrow = gpGlobals->v_forward * flVel + m_pPlayer->pev->velocity; // alway explode 3 seconds after the pin was pulled float time = m_flStartThrow - gpGlobals->time + 3.0; if (time < 0) time = 0; CGrenade::ShootTimed( m_pPlayer->pev, vecSrc, vecThrow, time ); if ( flVel < 500 ) { SendWeaponAnim( HANDGRENADE_THROW1 ); } else if ( flVel < 1000 ) { SendWeaponAnim( HANDGRENADE_THROW2 ); } else { SendWeaponAnim( HANDGRENADE_THROW3 ); } // player "shoot" animation m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); m_flReleaseThrow = 0; m_flStartThrow = 0; m_flNextPrimaryAttack = GetNextAttackDelay(0.5); m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5; m_pPlayer->m_rgAmmo[ m_iPrimaryAmmoType ]--; if ( !m_pPlayer->m_rgAmmo[ m_iPrimaryAmmoType ] ) { // just threw last grenade // set attack times in the future, and weapon idle in the future so we can see the whole throw // animation, weapon idle will automatically retire the weapon for us. m_flTimeWeaponIdle = m_flNextSecondaryAttack = m_flNextPrimaryAttack = GetNextAttackDelay(0.5);// ensure that the animation can finish playing } return; } else if ( m_flReleaseThrow > 0 ) { // we've finished the throw, restart. m_flStartThrow = 0; if ( m_pPlayer->m_rgAmmo[ m_iPrimaryAmmoType ] ) { SendWeaponAnim( HANDGRENADE_DRAW ); } else { RetireWeapon(); return; } m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); m_flReleaseThrow = -1; return; } if ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] ) { int iAnim; float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 ); if (flRand <= 0.75) { iAnim = HANDGRENADE_IDLE; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );// how long till we do this again. } else { iAnim = HANDGRENADE_FIDGET; m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 75.0 / 30.0; } SendWeaponAnim( iAnim ); } }
void CASW_Weapon_Flechette::PrimaryAttack() { // 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) // firing from a marine { m_bIsFiring = true; // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(SINGLE); if (m_iClip1 <= AmmoClickPoint()) { LowAmmoSound(); } // tell the marine to tell its weapon to draw the muzzle flash pMarine->DoMuzzleFlash(); // sets the animation on the weapon model iteself SendWeaponAnim( GetPrimaryAttackActivity() ); Vector vecDir; Vector vecSrc = pMarine->Weapon_ShootPosition( ); if ( pPlayer && pMarine->IsInhabited() ) { vecDir = pPlayer->GetAutoaimVectorForMarine(pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount()); // 45 degrees = 0.707106781187 } else { #ifdef CLIENT_DLL Msg("Error, clientside firing of a weapon that's being controlled by an AI marine\n"); #else vecDir = pMarine->GetActualShootTrajectory( vecSrc ); #endif } int iShots = 1; // Make sure we don't fire more than the amount in the clip if ( UsesClipsForAmmo1() ) { iShots = MIN( iShots, m_iClip1 ); m_iClip1 -= iShots; #ifdef GAME_DLL CASW_Marine *pMarine = GetMarine(); if (pMarine && m_iClip1 <= 0 && pMarine->GetAmmoCount(m_iPrimaryAmmoType) <= 0 ) { pMarine->OnWeaponOutOfAmmo(true); } #endif } else { iShots = MIN( iShots, pMarine->GetAmmoCount( m_iPrimaryAmmoType ) ); pMarine->RemoveAmmo( iShots, m_iPrimaryAmmoType ); } /*#ifndef CLIENT_DLL if (asw_debug_marine_damage.GetBool()) Msg("Weapon dmg = %d\n", info.m_flDamage); info.m_flDamage *= pMarine->GetMarineResource()->OnFired_GetDamageScale(); #endif*/ // increment shooting stats #ifndef CLIENT_DLL float fGrenadeDamage = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_FLECHETTE_DMG); QAngle vecRocketAngle; VectorAngles(vecDir, vecRocketAngle); vecRocketAngle[YAW] += random->RandomFloat(-10, 10); CASW_Rocket::Create(fGrenadeDamage, vecSrc, vecRocketAngle, GetMarine()); if (pMarine && pMarine->GetMarineResource()) { pMarine->GetMarineResource()->UsedWeapon(this, iShots); pMarine->OnWeaponFired( this, iShots ); } if (ASWGameRules()) ASWGameRules()->m_fLastFireTime = gpGlobals->curtime; #endif m_flNextPrimaryAttack = m_flNextPrimaryAttack + GetFireRate(); } }