//----------------------------------------------------------------------------- // Purpose: Override so shotgun can do multiple reloads in a row //----------------------------------------------------------------------------- void CWeapon870AE::ItemPostFrame( void ) { CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if (!pOwner) { return; } if (m_bInReload) { // If I'm primary firing and have one round stop reloading and fire if ((pOwner->m_nButtons & IN_ATTACK ) && (m_iClip1 >=1)) { m_bInReload = false; m_bDelayedFire1 = true; } else if (m_flNextPrimaryAttack <= gpGlobals->curtime) { if (pOwner->Inventory_CountAllObjectContentsOfID(GetPrimaryAmmoID()) <= 0) { FinishReload(); return; } // If clip not full reload again if (m_iClip1 < GetMaxClip1()) { Reload(); return; } // Clip full, stop reloading else { FinishReload(); return; } } } else { // Make shotgun shell invisible SetBodygroup(1,1); } if ( (m_bDelayedFire1 || pOwner->m_nButtons & IN_ATTACK) && m_flNextPrimaryAttack <= gpGlobals->curtime) { m_bDelayedFire1 = false; if ((m_iClip1 <= 0 && UsesClipsForAmmo1()) || (!UsesClipsForAmmo1() && !pOwner->Inventory_CountAllObjectContentsOfID(GetPrimaryAmmoID()) )) { if (!pOwner->Inventory_CountAllObjectContentsOfID(GetPrimaryAmmoID())) { DryFire(); } else { StartReload(); } } // Fire underwater? else if (pOwner->GetWaterLevel() == 3 && m_bFiresUnderwater == false) { WeaponSound(EMPTY); m_flNextPrimaryAttack = gpGlobals->curtime + 0.2; return; } else { // If the firing button was just pressed, reset the firing time CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer && pPlayer->m_afButtonPressed & IN_ATTACK ) { m_flNextPrimaryAttack = gpGlobals->curtime; } PrimaryAttack(); } } if ( pOwner->m_nButtons & IN_RELOAD && UsesClipsForAmmo1() && !m_bInReload ) { // reload when reload is pressed, or if no buttons are down and weapon is empty. StartReload(); } else { // no fire buttons down m_bFireOnEmpty = false; WeaponIdle( ); return; } }
void CWeaponGravityGun::ItemPostFrame( void ) { CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if (!pOwner) return; #ifdef ARGG // adnan // this is where we check if we're orbiting the object // if we're holding something and pressing use, // then set us in the orbiting state // - this will indicate to OverrideMouseInput that we should zero the input and update our delta angles // UPDATE: not anymore. now this just sets our state variables. CBaseEntity *pObject = m_hObject; if( pObject ) { if((pOwner->m_nButtons & IN_ATTACK) && (pOwner->m_nButtons & IN_USE) ) { m_gravCallback.m_bHasRotatedCarryAngles = true; // did we JUST hit use? // if so, grab the current angles to begin with as the rotated angles if( !(pOwner->m_afButtonLast & IN_USE) ) { m_gravCallback.m_vecRotatedCarryAngles = pObject->GetAbsAngles(); } m_bIsCurrentlyRotating = true; } else { m_gravCallback.m_bHasRotatedCarryAngles = false; m_bIsCurrentlyRotating = false; } } else { m_bIsCurrentlyRotating = false; m_gravCallback.m_bHasRotatedCarryAngles = false; } // end adnan #endif if ( pOwner->m_nButtons & IN_ATTACK ) { #if defined( ARGG ) if( (pOwner->m_nButtons & IN_USE) ) { pOwner->m_vecUseAngles = pOwner->pl.v_angle; } #endif if ( pOwner->m_afButtonPressed & IN_ATTACK2 ) { SecondaryAttack(); } else if ( pOwner->m_nButtons & IN_ATTACK2 ) { if ( m_active ) { EffectDestroy(); SoundDestroy(); } WeaponIdle( ); return; } PrimaryAttack(); } else { if ( m_active ) { EffectDestroy(); SoundDestroy(); } WeaponIdle( ); return; } if ( pOwner->m_afButtonPressed & IN_RELOAD ) { Reload(); } }
void CWeaponStunStick::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator ) { switch( pEvent->event ) { case EVENT_WEAPON_MELEE_HIT: { // Trace up or down based on where the enemy is... // But only if we're basically facing that direction Vector vecDirection; AngleVectors( GetAbsAngles(), &vecDirection ); CBaseEntity *pEnemy = pOperator->MyNPCPointer() ? pOperator->MyNPCPointer()->GetEnemy() : NULL; if ( pEnemy ) { Vector vecDelta; VectorSubtract( pEnemy->WorldSpaceCenter(), pOperator->Weapon_ShootPosition(), vecDelta ); VectorNormalize( vecDelta ); Vector2D vecDelta2D = vecDelta.AsVector2D(); Vector2DNormalize( vecDelta2D ); if ( DotProduct2D( vecDelta2D, vecDirection.AsVector2D() ) > 0.8f ) { vecDirection = vecDelta; } } Vector vecEnd; VectorMA( pOperator->Weapon_ShootPosition(), 32, vecDirection, vecEnd ); // Stretch the swing box down to catch low level physics objects CBaseEntity *pHurt = pOperator->CheckTraceHullAttack( pOperator->Weapon_ShootPosition(), vecEnd, Vector(-16,-16,-40), Vector(16,16,16), static_cast<int>(GetDamageForActivity( GetActivity() )), DMG_CLUB, 0.5f, false ); // did I hit someone? if ( pHurt ) { // play sound WeaponSound( MELEE_HIT ); CBasePlayer *pPlayer = ToBasePlayer( pHurt ); CNPC_MetroPolice *pCop = dynamic_cast<CNPC_MetroPolice *>(pOperator); bool bFlashed = false; if ( pCop != NULL && pPlayer != NULL ) { // See if we need to knock out this target if ( pCop->ShouldKnockOutTarget( pHurt ) ) { float yawKick = random->RandomFloat( -48, -24 ); //Kick the player angles pPlayer->ViewPunch( QAngle( -16, yawKick, 2 ) ); color32 white = {255,255,255,255}; UTIL_ScreenFade( pPlayer, white, 0.2f, 1.0f, FFADE_OUT|FFADE_PURGE|FFADE_STAYOUT ); bFlashed = true; pCop->KnockOutTarget( pHurt ); break; } else { // Notify that we've stunned a target pCop->StunnedTarget( pHurt ); } } // Punch angles if ( pPlayer != NULL && !(pPlayer->GetFlags() & FL_GODMODE) ) { float yawKick = random->RandomFloat( -48, -24 ); //Kick the player angles pPlayer->ViewPunch( QAngle( -16, yawKick, 2 ) ); Vector dir = pHurt->GetAbsOrigin() - GetAbsOrigin(); // If the player's on my head, don't knock him up if ( pPlayer->GetGroundEntity() == pOperator ) { dir = vecDirection; dir.z = 0; } VectorNormalize(dir); dir *= 500.0f; //If not on ground, then don't make them fly! if ( !(pPlayer->GetFlags() & FL_ONGROUND ) ) dir.z = 0.0f; //Push the target back pHurt->ApplyAbsVelocityImpulse( dir ); if ( !bFlashed ) { color32 red = {128,0,0,128}; UTIL_ScreenFade( pPlayer, red, 0.5f, 0.1f, FFADE_IN ); } // Force the player to drop anyting they were holding pPlayer->ForceDropOfCarriedPhysObjects(); } // do effect? } else { WeaponSound( MELEE_MISS ); } } break; default: BaseClass::Operator_HandleAnimEvent( pEvent, pOperator ); break; } }
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: Third-person function call to render world model //----------------------------------------------------------------------------- int CWeaponGravityGun::DrawModel( int flags ) { // Only render these on the transparent pass if ( flags & STUDIO_TRANSPARENCY ) { if ( !m_active ) return 0; C_BasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return 0; Vector points[3]; QAngle tmpAngle; C_BaseEntity *pObject = m_hObject; //if ( pObject == NULL ) // return 0; GetAttachment( 1, points[0], tmpAngle ); // a little noise 11t & 13t should be somewhat non-periodic looking //points[1].z += 4*sin( gpGlobals->curtime*11 ) + 5*cos( gpGlobals->curtime*13 ); if ( pObject == NULL ) { //points[2] = m_targetPosition; trace_t tr; TraceLine( &tr ); points[2] = tr.endpos; } else { pObject->EntityToWorldSpace( m_worldPosition, &points[2] ); } Vector forward, right, up; QAngle playerAngles = pOwner->EyeAngles(); AngleVectors( playerAngles, &forward, &right, &up ); if ( pObject == NULL ) { Vector vecDir = points[2] - points[0]; VectorNormalize( vecDir ); points[1] = points[0] + 0.5f * (vecDir * points[2].DistTo(points[0])); } else { Vector vecSrc = pOwner->Weapon_ShootPosition( ); points[1] = vecSrc + 0.5f * (forward * points[2].DistTo(points[0])); } IMaterial *pMat = materials->FindMaterial( "sprites/physbeam1", TEXTURE_GROUP_CLIENT_EFFECTS ); if ( pObject ) pMat = materials->FindMaterial( "sprites/physbeam", TEXTURE_GROUP_CLIENT_EFFECTS ); Vector color; color.Init(1,1,1); float scrollOffset = gpGlobals->curtime - (int)gpGlobals->curtime; CMatRenderContextPtr pRenderContext( materials ); pRenderContext->Bind( pMat ); DrawBeamQuadratic( points[0], points[1], points[2], pObject ? 13/3.0f : 13/5.0f, color, scrollOffset ); DrawBeamQuadratic( points[0], points[1], points[2], pObject ? 13/3.0f : 13/5.0f, color, -scrollOffset ); IMaterial *pMaterial = materials->FindMaterial( "sprites/physglow", TEXTURE_GROUP_CLIENT_EFFECTS ); color32 clr={0,64,255,255}; if ( pObject ) { clr.r = 186; clr.g = 253; clr.b = 247; clr.a = 255; } float scale = random->RandomFloat( 3, 5 ) * ( pObject ? 3 : 2 ); // Draw the sprite pRenderContext->Bind( pMaterial ); for ( int i = 0; i < 3; i++ ) { DrawSprite( points[2], scale, scale, clr ); } return 1; } // Only do this on the opaque pass return BaseClass::DrawModel( flags ); }
#include "cbase.h" #include "soundscape_system.h" #include "soundscape.h" #include "KeyValues.h" #include "filesystem.h" #include "game.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" #define SOUNDSCAPE_MANIFEST_FILE "scripts/soundscapes_manifest.txt" CON_COMMAND(soundscape_flush, "Flushes the server & client side soundscapes") { CBasePlayer *pPlayer = ToBasePlayer( UTIL_GetCommandClient() ); if ( engine->IsDedicatedServer() ) { // If it's a dedicated server, only the server console can run this. if ( pPlayer ) return; } else { // If it's a listen server, only the listen server host can run this. if ( !pPlayer || pPlayer != UTIL_GetListenServerHost() ) return; } g_SoundscapeSystem.FlushSoundscapes(); // don't bother forgetting about the entities g_SoundscapeSystem.Init();
//----------------------------------------------------------------------------- // Purpose: Override so shotgun can do mulitple reloads in a row //----------------------------------------------------------------------------- void CWeaponShotgun::ItemPostFrame( void ) { CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if (!pOwner) { return; } if ( m_bNeedPump && ( pOwner->m_nButtons & IN_RELOAD ) ) { m_bDelayedReload = true; } if (m_bInReload) { // If I'm primary firing and have one round stop reloading and fire if ((pOwner->m_nButtons & IN_ATTACK ) && (m_iClip1 >=1) && !m_bNeedPump ) { m_bInReload = false; m_bNeedPump = false; m_bDelayedFire1 = true; } // If I'm secondary firing and have two rounds stop reloading and fire else if ((pOwner->m_nButtons & IN_ATTACK2 ) && (m_iClip1 >=2) && !m_bNeedPump ) { m_bInReload = false; m_bNeedPump = false; m_bDelayedFire2 = true; } else if (m_flNextPrimaryAttack <= gpGlobals->curtime) { // If out of ammo end reload if (pOwner->GetAmmoCount(m_iPrimaryAmmoType) <=0) { FinishReload(); return; } // If clip not full reload again if (m_iClip1 < GetMaxClip1()) { Reload(); return; } // Clip full, stop reloading else { FinishReload(); return; } } } else { // Make shotgun shell invisible SetBodygroup(1,1); } if ((m_bNeedPump) && (m_flNextPrimaryAttack <= gpGlobals->curtime)) { Pump(); return; } // Shotgun uses same timing and ammo for secondary attack if ((m_bDelayedFire2 || pOwner->m_nButtons & IN_ATTACK2)&&(m_flNextPrimaryAttack <= gpGlobals->curtime)) { m_bDelayedFire2 = false; if ( (m_iClip1 <= 1 && UsesClipsForAmmo1())) { // If only one shell is left, do a single shot instead if ( m_iClip1 == 1 ) { PrimaryAttack(); } else if (!pOwner->GetAmmoCount(m_iPrimaryAmmoType)) { DryFire(); } else { StartReload(); } } // Fire underwater? else if (GetOwner()->GetWaterLevel() == 3 && m_bFiresUnderwater == false) { WeaponSound(EMPTY); m_flNextPrimaryAttack = gpGlobals->curtime + 0.2; return; } else { // If the firing button was just pressed, reset the firing time if ( pOwner->m_afButtonPressed & IN_ATTACK ) { m_flNextPrimaryAttack = gpGlobals->curtime; } SecondaryAttack(); } } else if ( (m_bDelayedFire1 || pOwner->m_nButtons & IN_ATTACK) && m_flNextPrimaryAttack <= gpGlobals->curtime) { m_bDelayedFire1 = false; if ( (m_iClip1 <= 0 && UsesClipsForAmmo1()) || ( !UsesClipsForAmmo1() && !pOwner->GetAmmoCount(m_iPrimaryAmmoType) ) ) { if (!pOwner->GetAmmoCount(m_iPrimaryAmmoType)) { DryFire(); } else { StartReload(); } } // Fire underwater? else if (pOwner->GetWaterLevel() == 3 && m_bFiresUnderwater == false) { WeaponSound(EMPTY); m_flNextPrimaryAttack = gpGlobals->curtime + 0.2; return; } else { // If the firing button was just pressed, reset the firing time CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer && pPlayer->m_afButtonPressed & IN_ATTACK ) { m_flNextPrimaryAttack = gpGlobals->curtime; } PrimaryAttack(); } } if ( pOwner->m_nButtons & IN_RELOAD && UsesClipsForAmmo1() && !m_bInReload ) { // reload when reload is pressed, or if no buttons are down and weapon is empty. StartReload(); } else { // no fire buttons down m_bFireOnEmpty = false; if ( !HasAnyAmmo() && m_flNextPrimaryAttack < gpGlobals->curtime ) { // weapon isn't useable, switch. if ( !(GetWeaponFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) && pOwner->SwitchToNextBestWeapon( this ) ) { m_flNextPrimaryAttack = gpGlobals->curtime + 0.3; return; } } else { // weapon is useable. Reload if empty and weapon has waited as long as it has to after firing if ( m_iClip1 <= 0 && !(GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime ) { if (StartReload()) { // if we've successfully started to reload, we're done return; } } } WeaponIdle( ); return; } }
//----------------------------------------------------------------------------- // 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; }
void CBliinkPlayer::FireBullet( Vector vecSrc, // shooting postion const QAngle &shootAngles, //shooting angle float vecSpread, // spread vector int iDamage, // base damage int iBulletType, // ammo type CBaseEntity *pevAttacker, // shooter bool bDoEffects, // create impact effect ? float x, // spread x factor float y // spread y factor ) { float fCurrentDamage = iDamage; // damage of the bullet at it's current trajectory float flCurrentDistance = 0.0; //distance that the bullet has traveled so far // Increasing damage based on the player's stats. fCurrentDamage *= GetBliinkPlayerStats().GetDamagePercent(); Vector vecDirShooting, vecRight, vecUp; AngleVectors( shootAngles, &vecDirShooting, &vecRight, &vecUp ); if ( !pevAttacker ) pevAttacker = this; // the default attacker is ourselves // add the spray Vector vecDir = vecDirShooting + x * vecSpread * vecRight + y * vecSpread * vecUp; VectorNormalize( vecDir ); float flMaxRange = 8000; Vector vecEnd = vecSrc + vecDir * flMaxRange; // max bullet range is 10000 units trace_t tr; // main enter bullet trace UTIL_TraceLine( vecSrc, vecEnd, MASK_SOLID|CONTENTS_DEBRIS|CONTENTS_HITBOX, this, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction == 1.0f ) return; // we didn't hit anything, stop tracing shoot if ( sv_showimpacts.GetBool() ) { #ifdef CLIENT_DLL // draw red client impact markers debugoverlay->AddBoxOverlay( tr.endpos, Vector(-2,-2,-2), Vector(2,2,2), QAngle( 0, 0, 0), 255,0,0,127, 4 ); if ( tr.m_pEnt && tr.m_pEnt->IsPlayer() ) { C_BasePlayer *player = ToBasePlayer( tr.m_pEnt ); player->DrawClientHitboxes( 4, true ); } #else // draw blue server impact markers NDebugOverlay::Box( tr.endpos, Vector(-2,-2,-2), Vector(2,2,2), 0,0,255,127, 4 ); if ( tr.m_pEnt && tr.m_pEnt->IsPlayer() ) { CBasePlayer *player = ToBasePlayer( tr.m_pEnt ); player->DrawServerHitboxes( 4, true ); } #endif } //calculate the damage based on the distance the bullet travelled. flCurrentDistance += tr.fraction * flMaxRange; // damage get weaker of distance fCurrentDamage *= pow ( 0.85f, (flCurrentDistance / 500)); int iDamageType = DMG_BULLET | DMG_NEVERGIB; #ifndef CLIENT_DLL CBliinkPlayer* pAttacker = static_cast<CBliinkPlayer*> ( pevAttacker ); int iActiveAmmo = GetAmmoDef()->Index( pAttacker->GetActiveWeapon()->GetWpnData().szAmmo1 ); int iAmmoSubtype = pAttacker->GetBliinkInventory().GetAmmoSubtype( iActiveAmmo ); switch( iAmmoSubtype ) { case ITEM_STYPE_AMMO_NORMAL: break; case ITEM_STYPE_AMMO_POISON: iDamageType &= DMG_POISON; break; case ITEM_STYPE_AMMO_FOGGED: iDamageType &= DMG_NERVEGAS; break; case ITEM_STYPE_AMMO_FIRE: iDamageType &= DMG_BURN; break; case ITEM_STYPE_AMMO_SLOW: iDamageType &= DMG_PARALYZE; break; } #endif if( bDoEffects ) { // See if the bullet ended up underwater + started out of the water if ( enginetrace->GetPointContents( tr.endpos ) & (CONTENTS_WATER|CONTENTS_SLIME) ) { trace_t waterTrace; UTIL_TraceLine( vecSrc, tr.endpos, (MASK_SHOT|CONTENTS_WATER|CONTENTS_SLIME), this, COLLISION_GROUP_NONE, &waterTrace ); if( waterTrace.allsolid != 1 ) { CEffectData data; data.m_vOrigin = waterTrace.endpos; data.m_vNormal = waterTrace.plane.normal; data.m_flScale = random->RandomFloat( 8, 12 ); if ( waterTrace.contents & CONTENTS_SLIME ) { data.m_fFlags |= FX_WATER_IN_SLIME; } DispatchEffect( "gunshotsplash", data ); } } else { //Do Regular hit effects // Don't decal nodraw surfaces if ( !( tr.surface.flags & (SURF_SKY|SURF_NODRAW|SURF_HINT|SURF_SKIP) ) ) { CBaseEntity *pEntity = tr.m_pEnt; UTIL_ImpactTrace( &tr, iDamageType ); } } } // bDoEffects // add damage to entity that we hit #ifdef GAME_DLL ClearMultiDamage(); CTakeDamageInfo info( pevAttacker, pevAttacker, fCurrentDamage, iDamageType ); CalculateBulletDamageForce( &info, iBulletType, vecDir, tr.endpos ); tr.m_pEnt->DispatchTraceAttack( info, vecDir, &tr ); TraceAttackToTriggers( info, tr.startpos, tr.endpos, vecDir ); ApplyMultiDamage(); #endif }
//----------------------------------------------------------------------------- // Purpose: Randomly adds extra effects //----------------------------------------------------------------------------- void C_WeaponStunStick::ClientThink( void ) { if ( InSwing() == false ) { if ( m_bSwungLastFrame ) { // Start fading m_flFadeTime = gpGlobals->curtime; m_bSwungLastFrame = false; } return; } // Remember if we were swinging last frame m_bSwungLastFrame = InSwing(); if ( IsEffectActive( EF_NODRAW ) ) return; if ( IsCarriedByLocalPlayer() && !::input->CAM_IsThirdPerson()) { // Update our effects if ( gpGlobals->frametime != 0.0f && ( random->RandomInt( 0, 3 ) == 0 ) ) { Vector vecOrigin; QAngle vecAngles; // Inner beams BeamInfo_t beamInfo; int attachment = random->RandomInt( 0, 15 ); UTIL_GetWeaponAttachment( this, attachment, vecOrigin, vecAngles ); ::FormatViewModelAttachment( vecOrigin, false ); CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); CBaseEntity *pBeamEnt = pOwner->GetViewModel(); beamInfo.m_vecStart = vec3_origin; beamInfo.m_pStartEnt= pBeamEnt; beamInfo.m_nStartAttachment = attachment; beamInfo.m_pEndEnt = NULL; beamInfo.m_nEndAttachment = -1; beamInfo.m_vecEnd = vecOrigin + RandomVector( -8, 8 ); beamInfo.m_pszModelName = STUNSTICK_BEAM_MATERIAL; beamInfo.m_flHaloScale = 0.0f; beamInfo.m_flLife = 0.05f; beamInfo.m_flWidth = random->RandomFloat( 1.0f, 2.0f ); beamInfo.m_flEndWidth = 0; beamInfo.m_flFadeLength = 0.0f; beamInfo.m_flAmplitude = random->RandomFloat( 16, 32 ); beamInfo.m_flBrightness = 255.0; beamInfo.m_flSpeed = 0.0; beamInfo.m_nStartFrame = 0.0; beamInfo.m_flFrameRate = 1.0f; beamInfo.m_flRed = 255.0f;; beamInfo.m_flGreen = 255.0f; beamInfo.m_flBlue = 255.0f; beamInfo.m_nSegments = 16; beamInfo.m_bRenderable = true; beamInfo.m_nFlags = 0; beams->CreateBeamEntPoint( beamInfo ); } } }
CBasePlayer *UTIL_PlayerByIndex( int entindex ) { return ToBasePlayer( ClientEntityList().GetEnt( entindex ) ); }
//----------------------------------------------------------------------------- // Purpose: // Output : float //----------------------------------------------------------------------------- float CWeaponDODBase::CalcViewmodelBob( void ) { static float bobtime; static float lastbobtime; static float lastspeed; float cycle; CBasePlayer *player = ToBasePlayer( GetOwner() ); //Assert( player ); //NOTENOTE: For now, let this cycle continue when in the air, because it snaps badly without it if ( ( !gpGlobals->frametime ) || ( player == NULL ) ) { //NOTENOTE: We don't use this return value in our case (need to restructure the calculation function setup!) return 0.0f;// just use old value } //Find the speed of the player float speed = player->GetLocalVelocity().Length2D(); float flmaxSpeedDelta = max( 0, (gpGlobals->curtime - lastbobtime) * 320.0f ); // don't allow too big speed changes speed = clamp( speed, lastspeed-flmaxSpeedDelta, lastspeed+flmaxSpeedDelta ); speed = clamp( speed, -320, 320 ); lastspeed = speed; //FIXME: This maximum speed value must come from the server. // MaxSpeed() is not sufficient for dealing with sprinting - jdw float bob_offset = RemapVal( speed, 0, 320, 0.0f, 1.0f ); bobtime += ( gpGlobals->curtime - lastbobtime ) * bob_offset; lastbobtime = gpGlobals->curtime; //Calculate the vertical bob cycle = bobtime - (int)(bobtime/cl_bobcycle.GetFloat())*cl_bobcycle.GetFloat(); cycle /= cl_bobcycle.GetFloat(); if ( cycle < cl_bobup.GetFloat() ) { cycle = M_PI * cycle / cl_bobup.GetFloat(); } else { cycle = M_PI + M_PI*(cycle-cl_bobup.GetFloat())/(1.0 - cl_bobup.GetFloat()); } g_verticalBob = speed*0.005f; g_verticalBob = g_verticalBob*0.3 + g_verticalBob*0.7*sin(cycle); g_verticalBob = clamp( g_verticalBob, -7.0f, 4.0f ); //Calculate the lateral bob cycle = bobtime - (int)(bobtime/cl_bobcycle.GetFloat()*2)*cl_bobcycle.GetFloat()*2; cycle /= cl_bobcycle.GetFloat()*2; if ( cycle < cl_bobup.GetFloat() ) { cycle = M_PI * cycle / cl_bobup.GetFloat(); } else { cycle = M_PI + M_PI*(cycle-cl_bobup.GetFloat())/(1.0 - cl_bobup.GetFloat()); } g_lateralBob = speed*0.005f; g_lateralBob = g_lateralBob*0.3 + g_lateralBob*0.7*sin(cycle); g_lateralBob = clamp( g_lateralBob, -7.0f, 4.0f ); //NOTENOTE: We don't use this return value in our case (need to restructure the calculation function setup!) return 0.0f; }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CWeaponImmolator::Update() { float flDuration = gpGlobals->curtime - m_flTimeLastUpdatedRadius; if( flDuration != 0.0 ) { m_flBurnRadius += RADIUS_GROW_RATE * flDuration; } // Clamp m_flBurnRadius = min( m_flBurnRadius, MAX_BURN_RADIUS ); CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); Vector vecSrc; Vector vecAiming; if( pOwner ) { vecSrc = pOwner->Weapon_ShootPosition( ); vecAiming = pOwner->GetAutoaimVector(AUTOAIM_2DEGREES); } else { CBaseCombatCharacter *pOwner = GetOwner(); vecSrc = pOwner->Weapon_ShootPosition( ); vecAiming = m_vecImmolatorTarget - vecSrc; VectorNormalize( vecAiming ); } trace_t tr; UTIL_TraceLine( vecSrc, vecSrc + vecAiming * MAX_TRACE_LENGTH, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr ); int brightness; brightness = 255 * (m_flBurnRadius/MAX_BURN_RADIUS); UTIL_Beam( vecSrc, tr.endpos, m_beamIndex, 0, //halo index 0, //frame start 2.0f, //framerate 0.1f, //life 20, // width 1, // endwidth 0, // fadelength, 1, // noise 0, // red 255, // green 0, // blue, brightness, // bright 100 // speed ); if( tr.DidHitWorld() ) { int beams; for( beams = 0 ; beams < 5 ; beams++ ) { Vector vecDest; // Random unit vector vecDest.x = random->RandomFloat( -1, 1 ); vecDest.y = random->RandomFloat( -1, 1 ); vecDest.z = random->RandomFloat( 0, 1 ); // Push out to radius dist. vecDest = tr.endpos + vecDest * m_flBurnRadius; UTIL_Beam( tr.endpos, vecDest, m_beamIndex, 0, //halo index 0, //frame start 2.0f, //framerate 0.15f, //life 20, // width 1.75, // endwidth 0.75, // fadelength, 15, // noise 0, // red 255, // green 0, // blue, 128, // bright 100 // speed ); } // Immolator starts to hurt a few seconds after the effect is seen if( m_flBurnRadius > 64.0 ) { ImmolationDamage( CTakeDamageInfo( this, this, 1, DMG_BURN ), tr.endpos, m_flBurnRadius, CLASS_NONE ); } } else { // The attack beam struck some kind of entity directly. } m_flTimeLastUpdatedRadius = gpGlobals->curtime; if( m_flBurnRadius >= MAX_BURN_RADIUS ) { StopImmolating(); } }
//----------------------------------------------------------------------------- // 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 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 CWeaponGravityGun::SecondaryAttack( void ) { m_flNextSecondaryAttack = gpGlobals->curtime + 0.1; if ( m_active ) { EffectDestroy(); SoundDestroy(); return; } CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); Assert( pOwner ); if ( pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0 ) return; m_viewModelIndex = pOwner->entindex(); // Make sure I've got a view model CBaseViewModel *vm = pOwner->GetViewModel(); if ( vm ) { m_viewModelIndex = vm->entindex(); } Vector forward; pOwner->EyeVectors( &forward ); Vector start = pOwner->Weapon_ShootPosition(); Vector end = start + forward * 4096; trace_t tr; UTIL_TraceLine( start, end, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction == 1.0 || (tr.surface.flags & SURF_SKY) ) return; CBaseEntity *pHit = tr.m_pEnt; if ( pHit->entindex() == 0 ) { pHit = NULL; } else { // if the object has no physics object, or isn't a physprop or brush entity, then don't glue if ( !pHit->VPhysicsGetObject() || pHit->GetMoveType() != MOVETYPE_VPHYSICS ) return; } QAngle angles; WeaponSound( SINGLE ); pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType ); VectorAngles( tr.plane.normal, angles ); Vector endPoint = tr.endpos + tr.plane.normal; CGravityPellet *pPellet = (CGravityPellet *)CBaseEntity::Create( "gravity_pellet", endPoint, angles, this ); if ( pHit ) { pPellet->SetParent( pHit ); } AddPellet( pPellet, pHit, tr.plane.normal ); // UNDONE: Probably should just do this client side CBaseEntity *pEnt = GetBeamEntity(); CBeam *pBeam = CBeam::BeamCreate( PHYSGUN_BEAM_SPRITE, 1.5 ); pBeam->PointEntInit( endPoint, pEnt ); pBeam->SetEndAttachment( 1 ); pBeam->SetBrightness( 255 ); pBeam->SetColor( 255, 0, 0 ); pBeam->RelinkBeam(); pBeam->LiveForTime( 0.1 ); }
//----------------------------------------------------------------------------- // Purpose: // Output : float //----------------------------------------------------------------------------- float CBaseHLCombatWeapon::CalcViewmodelBob( void ) { static float bobtime; static float lastbobtime; float cycle; CBasePlayer *player = ToBasePlayer( GetOwner() ); //Assert( player ); //NOTENOTE: For now, let this cycle continue when in the air, because it snaps badly without it if ( ( !gpGlobals->frametime ) || ( player == NULL ) ) { //NOTENOTE: We don't use this return value in our case (need to restructure the calculation function setup!) return 0.0f;// just use old value } //Find the speed of the player float speed = player->GetLocalVelocity().Length2D(); //FIXME: This maximum speed value must come from the server. // MaxSpeed() is not sufficient for dealing with sprinting - jdw speed = clamp( speed, -320, 320 ); float bob_offset = RemapVal( speed, 0, 320, 0.0f, 1.0f ); bobtime += ( gpGlobals->curtime - lastbobtime ) * bob_offset; lastbobtime = gpGlobals->curtime; //Calculate the vertical bob cycle = bobtime - (int)(bobtime/HL2_BOB_CYCLE_MAX)*HL2_BOB_CYCLE_MAX; cycle /= HL2_BOB_CYCLE_MAX; if ( cycle < HL2_BOB_UP ) { cycle = M_PI * cycle / HL2_BOB_UP; } else { cycle = M_PI + M_PI*(cycle-HL2_BOB_UP)/(1.0 - HL2_BOB_UP); } g_verticalBob = speed*0.005f; g_verticalBob = g_verticalBob*0.3 + g_verticalBob*0.7*sin(cycle); g_verticalBob = clamp( g_verticalBob, -7.0f, 4.0f ); //Calculate the lateral bob cycle = bobtime - (int)(bobtime/HL2_BOB_CYCLE_MAX*2)*HL2_BOB_CYCLE_MAX*2; cycle /= HL2_BOB_CYCLE_MAX*2; if ( cycle < HL2_BOB_UP ) { cycle = M_PI * cycle / HL2_BOB_UP; } else { cycle = M_PI + M_PI*(cycle-HL2_BOB_UP)/(1.0 - HL2_BOB_UP); } g_lateralBob = speed*0.005f; g_lateralBob = g_lateralBob*0.3 + g_lateralBob*0.7*sin(cycle); g_lateralBob = clamp( g_lateralBob, -7.0f, 4.0f ); //NOTENOTE: We don't use this return value in our case (need to restructure the calculation function setup!) return 0.0f; }
void CWeaponGravityGun::EffectUpdate( void ) { Vector start, angles, forward, right; trace_t tr; CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return; m_viewModelIndex = pOwner->entindex(); // Make sure I've got a view model CBaseViewModel *vm = pOwner->GetViewModel(); if ( vm ) { m_viewModelIndex = vm->entindex(); } pOwner->EyeVectors( &forward, &right, NULL ); start = pOwner->Weapon_ShootPosition(); Vector end = start + forward * 4096; UTIL_TraceLine( start, end, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr ); end = tr.endpos; float distance = tr.fraction * 4096; if ( tr.fraction != 1 ) { // too close to the player, drop the object if ( distance < 36 ) { DetachObject(); return; } } if ( m_hObject == NULL && tr.DidHitNonWorldEntity() ) { CBaseEntity *pEntity = tr.m_pEnt; // inform the object what was hit ClearMultiDamage(); pEntity->DispatchTraceAttack( CTakeDamageInfo( pOwner, pOwner, 0, DMG_PHYSGUN ), forward, &tr ); ApplyMultiDamage(); AttachObject( pEntity, start, tr.endpos, distance ); m_lastYaw = pOwner->EyeAngles().y; } // Add the incremental player yaw to the target transform matrix3x4_t curMatrix, incMatrix, nextMatrix; AngleMatrix( m_gravCallback.m_targetRotation, curMatrix ); AngleMatrix( QAngle(0,pOwner->EyeAngles().y - m_lastYaw,0), incMatrix ); ConcatTransforms( incMatrix, curMatrix, nextMatrix ); MatrixAngles( nextMatrix, m_gravCallback.m_targetRotation ); m_lastYaw = pOwner->EyeAngles().y; CBaseEntity *pObject = m_hObject; if ( pObject ) { if ( m_useDown ) { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = false; } } else { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = true; } } if ( m_useDown ) { pOwner->SetPhysicsFlag( PFLAG_DIROVERRIDE, true ); if ( pOwner->m_nButtons & IN_FORWARD ) { m_distance = UTIL_Approach( 1024, m_distance, gpGlobals->frametime * 100 ); } if ( pOwner->m_nButtons & IN_BACK ) { m_distance = UTIL_Approach( 40, m_distance, gpGlobals->frametime * 100 ); } } if ( pOwner->m_nButtons & IN_WEAPON1 ) { m_distance = UTIL_Approach( 1024, m_distance, m_distance * 0.1 ); } if ( pOwner->m_nButtons & IN_WEAPON2 ) { m_distance = UTIL_Approach( 40, m_distance, m_distance * 0.1 ); } // Send the object a physics damage message (0 damage). Some objects interpret this // as something else being in control of their physics temporarily. pObject->TakeDamage( CTakeDamageInfo( this, pOwner, 0, DMG_PHYSGUN ) ); Vector newPosition = start + forward * m_distance; // 24 is a little larger than 16 * sqrt(2) (extent of player bbox) // HACKHACK: We do this so we can "ignore" the player and the object we're manipulating // If we had a filter for tracelines, we could simply filter both ents and start from "start" Vector awayfromPlayer = start + forward * 24; UTIL_TraceLine( start, awayfromPlayer, MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction == 1 ) { UTIL_TraceLine( awayfromPlayer, newPosition, MASK_SOLID, pObject, COLLISION_GROUP_NONE, &tr ); Vector dir = tr.endpos - newPosition; float distance = VectorNormalize(dir); float maxDist = m_gravCallback.m_maxVel * gpGlobals->frametime; if ( distance > maxDist ) { newPosition += dir * maxDist; } else { newPosition = tr.endpos; } } else { newPosition = tr.endpos; } CreatePelletAttraction( phys_gunglueradius.GetFloat(), pObject ); // If I'm looking more than 20 degrees away from the glue point, then give up // This lets the player "gesture" for the glue to let go. Vector pelletDir = m_gravCallback.m_worldPosition - start; VectorNormalize(pelletDir); if ( DotProduct( pelletDir, forward ) < 0.939 ) // 0.939 ~= cos(20deg) { // lose attach for 2 seconds if you're too far away m_glueTime = gpGlobals->curtime + 1; } if ( m_pelletHeld >= 0 && gpGlobals->curtime > m_glueTime ) { CGravityPellet *pPelletAttract = m_activePellets[m_pelletAttract].pellet; g_pEffects->Sparks( pPelletAttract->GetAbsOrigin() ); } m_gravCallback.SetTargetPosition( newPosition ); Vector dir = (newPosition - pObject->GetLocalOrigin()); m_movementLength = dir.Length(); } else { m_gravCallback.SetTargetPosition( end ); } if ( m_pelletHeld >= 0 && gpGlobals->curtime > m_glueTime ) { Vector worldNormal, worldPos; GetPelletWorldCoords( m_pelletAttract, &worldPos, &worldNormal ); m_gravCallback.SetAutoAlign( m_activePellets[m_pelletHeld].localNormal, m_activePellets[m_pelletHeld].pellet->GetLocalOrigin(), worldNormal, worldPos ); } else { m_gravCallback.ClearAutoAlign(); } }
//----------------------------------------------------------------------------- // 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 }
// UNDONE: temporary scorching for PreAlpha - find a less sleazy permenant solution. void CBaseGrenade::Explode( trace_t *pTrace, int bitsDamageType ) { #if !defined( CLIENT_DLL ) SetModelName( NULL_STRING );//invisible AddSolidFlags( FSOLID_NOT_SOLID ); m_takedamage = DAMAGE_NO; // Pull out of the wall a bit if ( pTrace->fraction != 1.0 ) { SetAbsOrigin( pTrace->endpos + (pTrace->plane.normal * 0.6) ); } Vector vecAbsOrigin = GetAbsOrigin(); int contents = UTIL_PointContents ( vecAbsOrigin, MASK_ALL ); if ( pTrace->fraction != 1.0 ) { Vector vecNormal = pTrace->plane.normal; surfacedata_t *pdata = physprops->GetSurfaceData( pTrace->surface.surfaceProps ); CPASFilter filter( vecAbsOrigin ); te->Explosion( filter, -1.0, // don't apply cl_interp delay &vecAbsOrigin, !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion, m_DmgRadius * .03, 25, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage, &vecNormal, (char) pdata->game.material ); } else { CPASFilter filter( vecAbsOrigin ); te->Explosion( filter, -1.0, // don't apply cl_interp delay &vecAbsOrigin, !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion, m_DmgRadius * .03, 25, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage ); } #if !defined( CLIENT_DLL ) CSoundEnt::InsertSound ( SOUND_COMBAT, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 ); #endif // Use the thrower's position as the reported position Vector vecReported = m_hThrower ? m_hThrower->GetAbsOrigin() : vec3_origin; EmitSound( "BaseGrenade.Explode" ); CTakeDamageInfo info( this, m_hThrower, GetBlastForce(), GetAbsOrigin(), m_flDamage, bitsDamageType, 0, &vecReported ); RadiusDamage( info, GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL ); UTIL_DecalTrace( pTrace, "Scorch" ); SetThink( &CBaseGrenade::SUB_Remove ); SetTouch( NULL ); SetSolid( SOLID_NONE ); AddEffects( EF_NODRAW ); SetAbsVelocity( vec3_origin ); #if HL2_EPISODIC // Because the grenade is zipped out of the world instantly, the EXPLOSION sound that it makes for // the AI is also immediately destroyed. For this reason, we now make the grenade entity inert and // throw it away in 1/10th of a second instead of right away. Removing the grenade instantly causes // intermittent bugs with env_microphones who are listening for explosions. They will 'randomly' not // hear explosion sounds when the grenade is removed and the SoundEnt thinks (and removes the sound) // before the env_microphone thinks and hears the sound. SetNextThink( gpGlobals->curtime + 0.1 ); #else SetNextThink( gpGlobals->curtime ); #endif//HL2_EPISODIC #if defined( HL2_DLL ) CBasePlayer *pPlayer = ToBasePlayer( m_hThrower.Get() ); if ( pPlayer ) { gamestats->Event_WeaponHit( pPlayer, true, "weapon_frag", info ); } #endif #endif }
float CalculateObjectStress( IPhysicsObject *pObject, CBaseEntity *pInputOwnerEntity, vphysics_objectstress_t *pOutput ) { CUtlVector< CBaseEntity * > pObjectList; CUtlVector< Vector > objectForce; bool hasLargeObject = false; // add a slot for static objects pObjectList.AddToTail( NULL ); objectForce.AddToTail( vec3_origin ); // add a slot for friendly objects pObjectList.AddToTail( NULL ); objectForce.AddToTail( vec3_origin ); CBaseCombatCharacter *pBCC = pInputOwnerEntity->MyCombatCharacterPointer(); IPhysicsFrictionSnapshot *pSnapshot = pObject->CreateFrictionSnapshot(); float objMass = pObject->GetMass(); while ( pSnapshot->IsValid() ) { float force = pSnapshot->GetNormalForce(); if ( force > 0.0f ) { IPhysicsObject *pOther = pSnapshot->GetObject(1); CBaseEntity *pOtherEntity = static_cast<CBaseEntity *>(pOther->GetGameData()); if ( !pOtherEntity ) { // object was just deleted, but we still have a contact point this frame... // just assume it came from the world. pOtherEntity = GetWorldEntity(); } CBaseEntity *pOtherOwner = pOtherEntity; if ( pOtherEntity->GetOwnerEntity() ) { pOtherOwner = pOtherEntity->GetOwnerEntity(); } int outIndex = 0; if ( !pOther->IsMoveable() ) { outIndex = 0; } // NavIgnored objects are often being pushed by a friendly else if ( pBCC && (pBCC->IRelationType( pOtherOwner ) == D_LI || pOtherEntity->IsNavIgnored()) ) { outIndex = 1; } // player held objects do no stress else if ( pOther->GetGameFlags() & FVPHYSICS_PLAYER_HELD ) { outIndex = 1; } else { if ( pOther->GetMass() >= VPHYSICS_LARGE_OBJECT_MASS ) { if ( pInputOwnerEntity->GetGroundEntity() != pOtherEntity) { hasLargeObject = true; } } // moveable, non-friendly // aggregate contacts over each object to avoid greater stress in multiple contact cases // NOTE: Contacts should be in order, so this shouldn't ever search, but just in case outIndex = pObjectList.Count(); for ( int i = pObjectList.Count()-1; i >= 2; --i ) { if ( pObjectList[i] == pOtherOwner ) { outIndex = i; break; } } if ( outIndex == pObjectList.Count() ) { pObjectList.AddToTail( pOtherOwner ); objectForce.AddToTail( vec3_origin ); } } if ( outIndex != 0 && pInputOwnerEntity->GetMoveType() != MOVETYPE_VPHYSICS && !IsPhysicallyControlled(pOtherEntity, pOther) ) { // UNDONE: Test this! This is to remove any shadow/shadow stress. The game should handle this with blocked/damage force = 0.0f; } Vector normal; pSnapshot->GetSurfaceNormal( normal ); objectForce[outIndex] += normal * force; } pSnapshot->NextFrictionData(); } pObject->DestroyFrictionSnapshot( pSnapshot ); pSnapshot = NULL; // clear out all friendly force objectForce[1].Init(); float sum = 0; Vector negativeForce = vec3_origin; Vector positiveForce = vec3_origin; Assert( pObjectList.Count() == objectForce.Count() ); for ( int objectIndex = pObjectList.Count()-1; objectIndex >= 0; --objectIndex ) { sum += objectForce[objectIndex].Length(); for ( int i = 0; i < 3; i++ ) { if ( objectForce[objectIndex][i] < 0 ) { negativeForce[i] -= objectForce[objectIndex][i]; } else { positiveForce[i] += objectForce[objectIndex][i]; } } } // "external" stress is two way (something pushes on the object and something else pushes back) // so the set of minimum values per component are the projections of the two-way force // "internal" stress is one way (the object is pushing against something OR something pushing back) // the momentum must have come from inside the object (gravity, controller, etc) Vector internalForce = vec3_origin; Vector externalForce = vec3_origin; for ( int i = 0; i < 3; i++ ) { if ( negativeForce[i] < positiveForce[i] ) { internalForce[i] = positiveForce[i] - negativeForce[i]; externalForce[i] = negativeForce[i]; } else { internalForce[i] = negativeForce[i] - positiveForce[i]; externalForce[i] = positiveForce[i]; } } // sum is kg in / s Vector gravVector; physenv->GetGravity( &gravVector ); float gravity = gravVector.Length(); if ( pInputOwnerEntity->GetMoveType() != MOVETYPE_VPHYSICS && pObject->IsMoveable() ) { Vector lastVel; lastVel.Init(); if ( pObject->GetShadowController() ) { pObject->GetShadowController()->GetLastImpulse( &lastVel ); } else { if ( ( pObject->GetCallbackFlags() & CALLBACK_IS_PLAYER_CONTROLLER ) ) { CBasePlayer *pPlayer = ToBasePlayer( pInputOwnerEntity ); IPhysicsPlayerController *pController = pPlayer ? pPlayer->GetPhysicsController() : NULL; if ( pController ) { pController->GetLastImpulse( &lastVel ); } } } // Work in progress... // Peek into the controller for this object. Look at the input velocity and make sure it's all // accounted for in the computed stress. If not, redistribute external to internal as it's // probably being reflected in a way we can't measure here. float inputLen = lastVel.Length() * (1.0f / physenv->GetSimulationTimestep()) * objMass; if ( inputLen > 0.0f ) { float internalLen = internalForce.Length(); if ( internalLen < inputLen ) { float ratio = internalLen / inputLen; Vector delta = internalForce * (1.0f - ratio); internalForce += delta; float deltaLen = delta.Length(); sum -= deltaLen; float extLen = VectorNormalize(externalForce) - deltaLen; if ( extLen < 0 ) { extLen = 0; } externalForce *= extLen; } } } float invGravity = gravity; if ( invGravity <= 0 ) { invGravity = 1.0f; } else { invGravity = 1.0f / invGravity; } sum *= invGravity; internalForce *= invGravity; externalForce *= invGravity; if ( !pObject->IsMoveable() ) { // the above algorithm will see almost all force as internal if the object is not moveable // (it doesn't push on anything else, so nothing is reciprocated) // exceptions for friction of a single other object with multiple contact points on this object // But the game wants to see it all as external because obviously the object can't move, so it can't have // internal stress externalForce = internalForce; internalForce.Init(); if ( !pObject->IsStatic() ) { sum += objMass; } } else { // assume object is at rest if ( sum > objMass ) { sum = objMass + (sum-objMass) * 0.5; } } if ( pOutput ) { pOutput->exertedStress = internalForce.Length(); pOutput->receivedStress = externalForce.Length(); pOutput->hasNonStaticStress = pObjectList.Count() > 2 ? true : false; pOutput->hasLargeObjectContact = hasLargeObject; } // sum is now kg return sum; }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- 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(); // 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 if( IsIronsighted() ) { DoMachineGunKick( pPlayer, 0.5, 5.0, 0.5, 3.0 ); } else { DoMachineGunKick( pPlayer, 0.5, 10.0, 0.5, 3.0 ); } 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 ); }
void CBasePlayerAnimState::Update( float eyeYaw, float eyePitch ) { VPROF( "CBasePlayerAnimState::Update" ); // Clear animation overlays because we're about to completely reconstruct them. ClearAnimationLayers(); // Some mods don't want to update the player's animation state if they're dead and ragdolled. if ( !ShouldUpdateAnimState() ) { ClearAnimationState(); return; } CStudioHdr *pStudioHdr = GetOuter()->GetModelPtr(); // Store these. All the calculations are based on them. m_flEyeYaw = AngleNormalize( eyeYaw ); m_flEyePitch = AngleNormalize( eyePitch ); // Compute sequences for all the layers. ComputeSequences( pStudioHdr ); // Compute all the pose params. ComputePoseParam_BodyPitch( pStudioHdr ); // Look up/down. ComputePoseParam_BodyYaw(); // Torso rotation. ComputePoseParam_MoveYaw( pStudioHdr ); // What direction his legs are running in. ComputePlaybackRate(); #ifdef CLIENT_DLL if ( cl_showanimstate.GetInt() == m_pOuter->entindex() ) { DebugShowAnimStateFull( 5 ); } else if ( cl_showanimstate.GetInt() == -2 ) { C_BasePlayer *targetPlayer = C_BasePlayer::GetLocalPlayer(); if( targetPlayer && ( targetPlayer->GetObserverMode() == OBS_MODE_IN_EYE || targetPlayer->GetObserverMode() == OBS_MODE_CHASE ) ) { C_BaseEntity *target = targetPlayer->GetObserverTarget(); if( target && target->IsPlayer() ) { targetPlayer = ToBasePlayer( target ); } } if ( m_pOuter == targetPlayer ) { DebugShowAnimStateFull( 6 ); } } #else if ( sv_showanimstate.GetInt() == m_pOuter->entindex() ) { DebugShowAnimState( 20 ); } #endif }
//----------------------------------------------------------------------------- // Purpose: Handle grenade detonate in-air (even when no ammo is left) //----------------------------------------------------------------------------- void CWeaponOICW::ItemPostFrame(void) { CBasePlayer *pOwner = ToBasePlayer(GetOwner()); if (!pOwner) return; if ((pOwner->m_nButtons & IN_ATTACK) == false) { m_nShotsFired = 0; } //Zoom in if (pOwner->m_afButtonPressed & IN_ATTACK2) { if (m_iFireMode == 0) { Zoom(); } else if (m_iFireMode == 1) { if (m_flNextSecondaryAttack <= gpGlobals->curtime) { if (pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0) { if (m_flNextEmptySoundTime < gpGlobals->curtime) { WeaponSound(EMPTY); m_flNextSecondaryAttack = m_flNextEmptySoundTime = gpGlobals->curtime + 0.5; } } else if (pOwner->GetWaterLevel() == 3 && m_bAltFiresUnderwater == false) { // This weapon doesn't fire underwater WeaponSound(EMPTY); m_flNextPrimaryAttack = gpGlobals->curtime + 0.2; return; } else { GrenadeAttack(); } } } } //Throw a grenade. if (pOwner->m_afButtonPressed & IN_ATTACK3) { if (m_iFireMode == 0) { if (m_bZoomed) { Zoom(); } CFmtStr hint; hint.sprintf("#Valve_OICW_Grenades"); pOwner->ShowLevelMessage(hint.Access()); m_iFireMode = 1; WeaponSound(EMPTY); } else if (m_iFireMode == 1) { CFmtStr hint; hint.sprintf("#Valve_OICW_Scope"); pOwner->ShowLevelMessage(hint.Access()); m_iFireMode = 0; WeaponSound(EMPTY); } } //Allow a refire as fast as the player can click if (m_bZoomed && ((pOwner->m_nButtons & IN_ATTACK) == false) && (m_flSoonestPrimaryAttack < gpGlobals->curtime)) { m_flNextPrimaryAttack = gpGlobals->curtime - 0.1f; } //Don't kick the same when we're zoomed in if (m_bZoomed) { m_fFireDuration = 0.05f; } BaseClass::ItemPostFrame(); }
//----------------------------------------------------------------------------- // Purpose: First-person function call after viewmodel has been drawn //----------------------------------------------------------------------------- void CWeaponGravityGun::ViewModelDrawn( C_BaseViewModel *pBaseViewModel ) { if ( !m_active ) return; // Render our effects C_BasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return; Vector points[3]; QAngle tmpAngle; C_BaseEntity *pObject = m_hObject; //if ( pObject == NULL ) // return; pBaseViewModel->GetAttachment( 1, points[0], tmpAngle ); // a little noise 11t & 13t should be somewhat non-periodic looking //points[1].z += 4*sin( gpGlobals->curtime*11 ) + 5*cos( gpGlobals->curtime*13 ); if ( pObject == NULL ) { //points[2] = m_targetPosition; trace_t tr; TraceLine( &tr ); points[2] = tr.endpos; } else { pObject->EntityToWorldSpace(m_worldPosition, &points[2]); } Vector forward, right, up; QAngle playerAngles = pOwner->EyeAngles(); AngleVectors( playerAngles, &forward, &right, &up ); Vector vecSrc = pOwner->Weapon_ShootPosition( ); points[1] = vecSrc + 0.5f * (forward * points[2].DistTo(points[0])); IMaterial *pMat = materials->FindMaterial( "sprites/physbeam1", TEXTURE_GROUP_CLIENT_EFFECTS ); if ( pObject ) pMat = materials->FindMaterial( "sprites/physbeam", TEXTURE_GROUP_CLIENT_EFFECTS ); Vector color; color.Init(1,1,1); // Now draw it. CViewSetup beamView = *view->GetPlayerViewSetup(); Frustum dummyFrustum; render->Push3DView( beamView, 0, NULL, dummyFrustum ); float scrollOffset = gpGlobals->curtime - (int)gpGlobals->curtime; CMatRenderContextPtr pRenderContext( materials ); pRenderContext->Bind( pMat ); #if 1 // HACK HACK: Munge the depth range to prevent view model from poking into walls, etc. // Force clipped down range pRenderContext->DepthRange( 0.1f, 0.2f ); #endif DrawBeamQuadratic( points[0], points[1], points[2], pObject ? 13/3.0f : 13/5.0f, color, scrollOffset ); DrawBeamQuadratic( points[0], points[1], points[2], pObject ? 13/3.0f : 13/5.0f, color, -scrollOffset ); IMaterial *pMaterial = materials->FindMaterial( "sprites/physglow", TEXTURE_GROUP_CLIENT_EFFECTS ); color32 clr={0,64,255,255}; if ( pObject ) { clr.r = 186; clr.g = 253; clr.b = 247; clr.a = 255; } float scale = random->RandomFloat( 3, 5 ) * ( pObject ? 3 : 2 ); // Draw the sprite pRenderContext->Bind( pMaterial ); for ( int i = 0; i < 3; i++ ) { DrawSprite( points[2], scale, scale, clr ); } #if 1 pRenderContext->DepthRange( 0.0f, 1.0f ); #endif render->PopView( dummyFrustum ); // Pass this back up BaseClass::ViewModelDrawn( pBaseViewModel ); }
//----------------------------------------------------------------------------- // 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 CWeaponGravityGun::EffectUpdate( void ) { Vector start, forward, right; trace_t tr; CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return; pOwner->EyeVectors( &forward, &right, NULL ); start = pOwner->Weapon_ShootPosition(); TraceLine( &tr ); Vector end = tr.endpos; float distance = tr.fraction * 4096; if ( m_hObject == NULL && tr.DidHitNonWorldEntity() ) { CBaseEntity *pEntity = tr.m_pEnt; AttachObject( pEntity, GetPhysObjFromPhysicsBone( pEntity, tr.physicsbone ), tr.physicsbone, start, tr.endpos, distance ); } // Add the incremental player yaw to the target transform QAngle angles = m_gravCallback.TransformAnglesFromPlayerSpace( m_gravCallback.m_targetRotation, pOwner ); CBaseEntity *pObject = m_hObject; if ( pObject ) { if ( m_useDown ) { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = false; } } else { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = true; } } if ( m_useDown ) { #ifndef CLIENT_DLL pOwner->SetPhysicsFlag( PFLAG_DIROVERRIDE, true ); #endif if ( pOwner->m_nButtons & IN_FORWARD ) { m_distance = Approach( 1024, m_distance, gpGlobals->frametime * 100 ); } if ( pOwner->m_nButtons & IN_BACK ) { m_distance = Approach( 40, m_distance, gpGlobals->frametime * 100 ); } } if ( pOwner->m_nButtons & IN_WEAPON1 ) { m_distance = Approach( 1024, m_distance, m_distance * 0.1 ); } if ( pOwner->m_nButtons & IN_WEAPON2 ) { m_distance = Approach( 40, m_distance, m_distance * 0.1 ); } IPhysicsObject *pPhys = GetPhysObjFromPhysicsBone( pObject, m_physicsBone ); if ( pPhys ) { if ( pPhys->IsAsleep() ) { // on the odd chance that it's gone to sleep while under anti-gravity pPhys->Wake(); } Vector newPosition = start + forward * m_distance; Vector offset; pPhys->LocalToWorld( &offset, m_worldPosition ); Vector vecOrigin; pPhys->GetPosition( &vecOrigin, NULL ); m_gravCallback.SetTargetPosition( newPosition + (vecOrigin - offset), angles ); Vector dir = (newPosition - pObject->GetLocalOrigin()); m_movementLength = dir.Length(); } } else { m_targetPosition = end; //m_gravCallback.SetTargetPosition( end, m_gravCallback.m_targetRotation ); } }
bool CNPC_Combine_Cannon::FVisible( CBaseEntity *pEntity, int traceMask, CBaseEntity **ppBlocker ) { // NPC if ( pEntity->IsPlayer() == false ) return BaseClass::FVisible( pEntity, traceMask, ppBlocker ); if ( pEntity->GetFlags() & FL_NOTARGET ) return false; Vector vecVerticalOffset; Vector vecRight; Vector vecEye; trace_t tr; if( fabs( GetAbsOrigin().z - pEntity->WorldSpaceCenter().z ) <= 120.f ) { // If the player is around the same elevation, look straight at his eyes. // At the same elevation, the vertical peeking allowance makes it too easy // for a player to dispatch the sniper from cover. vecVerticalOffset = vec3_origin; } else { // Otherwise, look at a spot below his eyes. This allows the player to back away // from his cover a bit and have a peek at the sniper without being detected. vecVerticalOffset = CANNON_TARGET_VERTICAL_OFFSET; } AngleVectors( pEntity->GetLocalAngles(), NULL, &vecRight, NULL ); vecEye = vecRight * CANNON_EYE_DIST - vecVerticalOffset; UTIL_TraceLine( EyePosition(), pEntity->EyePosition() + vecEye, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); #if 0 NDebugOverlay::Line(EyePosition(), tr.endpos, 0,255,0, true, 0.1); #endif bool fCheckFailed = false; if ( tr.fraction != 1.0 && tr.m_pEnt != pEntity ) { fCheckFailed = true; } // Don't check the other eye if the first eye failed. if( !fCheckFailed ) { vecEye = -vecRight * CANNON_EYE_DIST - vecVerticalOffset; UTIL_TraceLine( EyePosition(), pEntity->EyePosition() + vecEye, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); #if 0 NDebugOverlay::Line(EyePosition(), tr.endpos, 0,255,0, true, 0.1); #endif if ( tr.fraction != 1.0 && tr.m_pEnt != pEntity ) { fCheckFailed = true; } } if( !fCheckFailed ) { // Can see the player. return true; } // Now, if the check failed, see if the player is ducking and has recently // fired a muzzleflash. If yes, see if you'd be able to see the player if // they were standing in their current position instead of ducking. Since // the sniper doesn't have a clear shot in this situation, he will harrass // near the player. CBasePlayer *pPlayer; pPlayer = ToBasePlayer( pEntity ); if( (pPlayer->GetFlags() & FL_DUCKING) && pPlayer->MuzzleFlashTime() > gpGlobals->curtime ) { vecEye = pPlayer->EyePosition() + Vector( 0, 0, 32 ); UTIL_TraceLine( EyePosition(), vecEye, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); if( tr.fraction != 1.0 ) { // Everything failed. if (ppBlocker) { *ppBlocker = tr.m_pEnt; } return false; } else { // Fake being able to see the player. return true; } } if (ppBlocker) { *ppBlocker = tr.m_pEnt; } return false; }
//----------------------------------------------------------------------------- // 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 ); ToSDKPlayer(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; info.m_iDamage = GetSDKWpnData().m_iDamage; // 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 ); } }
//----------------------------------------------------------------------------- // 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() ); }