void C_CFPlayer::UpdateClientSideAnimation() { // Update the animation data. It does the local check here so this works when using // a third-person camera (and we don't have valid player angles). if ( this == C_CFPlayer::GetLocalCFPlayer() ) { if (m_hReviving != NULL || m_hReviver != NULL) { C_CFPlayer* pTarget = m_hReviving; if (!pTarget) pTarget = m_hReviver; // Snap the animation to face the model during fatalities. Vector vecToTarget = pTarget->GetAbsOrigin() - GetAbsOrigin(); QAngle angToTarget; VectorAngles(vecToTarget, angToTarget); m_PlayerAnimState->Update( angToTarget[YAW], angToTarget[PITCH] ); } else m_PlayerAnimState->Update( EyeAngles()[YAW], EyeAngles()[PITCH] ); } else m_PlayerAnimState->Update( m_angEyeAngles[YAW], m_angEyeAngles[PITCH] ); BaseClass::UpdateClientSideAnimation(); }
//----------------------------------------------------------------------------- // Purpose: Performs a takeoff. Called via an animation event at the moment // our feet leave the ground. // Input : pGoalEnt - The entity that we are going to fly toward. //----------------------------------------------------------------------------- void CNPC_Crow::Takeoff( const Vector &vGoal ) { if ( vGoal != vec3_origin ) { // // Lift us off ground so engine doesn't instantly reset FL_ONGROUND. // UTIL_SetOrigin( this, GetAbsOrigin() + Vector( 0 , 0 , 1 )); // // Fly straight at the goal entity at our maximum airspeed. // Vector vecMoveDir = vGoal - GetAbsOrigin(); VectorNormalize( vecMoveDir ); // FIXME: pitch over time SetFlyingState( FlyState_Flying ); QAngle angles; VectorAngles( vecMoveDir, angles ); SetAbsAngles( angles ); SetAbsVelocity( vecMoveDir * CROW_TAKEOFF_SPEED ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPropAPC::FireRocket( void ) { if ( m_flRocketTime > gpGlobals->curtime ) return; // If we're still firing the salvo, fire quickly m_iRocketSalvoLeft--; if ( m_iRocketSalvoLeft > 0 ) { m_flRocketTime = gpGlobals->curtime + ROCKET_DELAY_TIME; } else { // Reload the salvo m_iRocketSalvoLeft = ROCKET_SALVO_SIZE; m_flRocketTime = gpGlobals->curtime + random->RandomFloat( ROCKET_MIN_BURST_PAUSE_TIME, ROCKET_MAX_BURST_PAUSE_TIME ); } Vector vecRocketOrigin; GetRocketShootPosition( &vecRocketOrigin ); static float s_pSide[] = { 0.966, 0.866, 0.5, -0.5, -0.866, -0.966 }; Vector forward; GetVectors( &forward, NULL, NULL ); Vector vecDir; CrossProduct( Vector( 0, 0, 1 ), forward, vecDir ); vecDir.z = 1.0f; vecDir.x *= s_pSide[m_nRocketSide]; vecDir.y *= s_pSide[m_nRocketSide]; if ( ++m_nRocketSide >= 6 ) { m_nRocketSide = 0; } VectorNormalize( vecDir ); Vector vecVelocity; VectorMultiply( vecDir, ROCKET_SPEED, vecVelocity ); QAngle angles; VectorAngles( vecDir, angles ); CAPCMissile *pRocket = (CAPCMissile *)CAPCMissile::Create( vecRocketOrigin, angles, vecVelocity, this ); pRocket->IgniteDelay(); if ( m_hSpecificRocketTarget ) { pRocket->AimAtSpecificTarget( m_hSpecificRocketTarget ); m_hSpecificRocketTarget = NULL; } else if ( m_strMissileHint != NULL_STRING ) { pRocket->SetGuidanceHint( STRING( m_strMissileHint ) ); } EmitSound( "PropAPC.FireRocket" ); m_OnFiredMissile.FireOutput( this, this ); }
//----------------------------------------------------------------------------- // Purpose: Orient the projectile along its velocity //----------------------------------------------------------------------------- void CBaseProjectile::FlyThink( void ) { QAngle angles; VectorAngles( -(GetAbsVelocity()), angles ); SetAbsAngles( angles ); SetNextThink( gpGlobals->curtime + 0.1f ); }
//----------------------------------------------------------------------------- // Purpose: Try and turn towards the target point //----------------------------------------------------------------------------- void CGrenadeRocket::FollowThink( void ) { if ( m_hLockTarget == NULL ) return; // Weave slightly drunkenly to target Vector vecTarget = m_hLockTarget->GetAbsOrigin() - GetLocalOrigin(); VectorNormalize( vecTarget ); QAngle angles; VectorAngles( vecTarget, angles ); SetLocalAngles( angles ); Vector vecVelocity = GetAbsVelocity(); float flSpeed = vecVelocity.Length(); vecVelocity = vecVelocity * 0.2 + vecTarget * flSpeed * 1.2; // Clip to maxspeed if ( vecVelocity.Length() > ROCKET_VELOCITY ) { VectorNormalize( vecVelocity ); vecVelocity *= ROCKET_VELOCITY; } SetAbsVelocity( vecVelocity ); SetNextThink( gpGlobals->curtime + 0.1f ); }
void PerformCustomEffects( const Vector &vecOrigin, trace_t &tr, const Vector &shotDir, int iMaterial, int iScale, int nFlags ) { // Throw out the effect if any of these are true if ( tr.surface.flags & (SURF_SKY|SURF_NODRAW|SURF_HINT|SURF_SKIP) ) return; if ( cl_new_impact_effects.GetInt() ) { PerformNewCustomEffects( vecOrigin, tr, shotDir, iMaterial, iScale, nFlags ); return; } bool bNoFlecks = !r_drawflecks.GetBool(); if ( !bNoFlecks ) { bNoFlecks = ( ( nFlags & FLAGS_CUSTIOM_EFFECTS_NOFLECKS ) != 0 ); } // Cement and wood have dust and flecks if ( ( iMaterial == CHAR_TEX_CONCRETE ) || ( iMaterial == CHAR_TEX_TILE ) ) { FX_DebrisFlecks( vecOrigin, &tr, iMaterial, iScale, bNoFlecks ); } else if ( iMaterial == CHAR_TEX_WOOD ) { FX_DebrisFlecks( vecOrigin, &tr, iMaterial, iScale, bNoFlecks ); } else if ( ( iMaterial == CHAR_TEX_DIRT ) || ( iMaterial == CHAR_TEX_SAND ) ) { FX_DustImpact( vecOrigin, &tr, iScale ); } else if ( iMaterial == CHAR_TEX_ANTLION ) { FX_AntlionImpact( vecOrigin, &tr ); } else if ( ( iMaterial == CHAR_TEX_METAL ) || ( iMaterial == CHAR_TEX_VENT ) ) { Vector reflect; float dot = shotDir.Dot( tr.plane.normal ); reflect = shotDir + ( tr.plane.normal * ( dot*-2.0f ) ); reflect[0] += random->RandomFloat( -0.2f, 0.2f ); reflect[1] += random->RandomFloat( -0.2f, 0.2f ); reflect[2] += random->RandomFloat( -0.2f, 0.2f ); FX_MetalSpark( vecOrigin, reflect, tr.plane.normal, iScale ); } else if ( iMaterial == CHAR_TEX_COMPUTER ) { Vector offset = vecOrigin + ( tr.plane.normal * 1.0f ); g_pEffects->Sparks( offset ); } else if ( iMaterial == CHAR_TEX_WARPSHIELD ) { QAngle vecAngles; VectorAngles( -shotDir, vecAngles ); DispatchParticleEffect( "warp_shield_impact", vecOrigin, vecAngles ); } }
//----------------------------------------------------------------------------- // Purpose: // Input : *pOther - //----------------------------------------------------------------------------- void CRocket_Turret_Projectile::MissileTouch( CBaseEntity *pOther ) { Assert( pOther ); Vector vVel = GetAbsVelocity(); // Touched a launcher, and is heading towards that launcher if ( FClassnameIs( pOther, "npc_rocket_turret" ) ) { Dissolve( NULL, gpGlobals->curtime + 0.1f, false, ENTITY_DISSOLVE_NORMAL ); Vector vBounceVel = Vector( -vVel.x, -vVel.y, 200 ); SetAbsVelocity ( vBounceVel * 0.1f ); QAngle vBounceAngles; VectorAngles( vBounceVel, vBounceAngles ); SetAbsAngles ( vBounceAngles ); SetLocalAngularVelocity ( QAngle ( 180, 90, 45 ) ); UTIL_Remove ( m_hRocketTrail ); SetSolid ( SOLID_NONE ); if( m_hRocketTrail ) { m_hRocketTrail->SetLifetime(0.1f); m_hRocketTrail = NULL; } return; } // Don't touch triggers (but DO hit weapons) if ( pOther->IsSolidFlagSet(FSOLID_TRIGGER|FSOLID_VOLUME_CONTENTS) && pOther->GetCollisionGroup() != COLLISION_GROUP_WEAPON ) return; Explode(); }
//Pose la mine sur son support une fois l'animation terminée void CWeaponMine::FinishAttach( void ){ CHL2MP_Player *pOwner = ToHL2MPPlayer( GetOwner() ); if (!pOwner) return; Vector vecSrc, vecAiming; vecSrc = pOwner->EyePosition(); QAngle angles = pOwner->GetLocalAngles(); AngleVectors( angles, &vecAiming ); trace_t tr; UTIL_TraceLine( vecSrc, vecSrc + (vecAiming * 60), MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr ); if (tr.fraction < 1.0) { if (tr.m_pEnt) { //On attache pas la mine sur une entité vivante CBaseEntity *pEntity = tr.m_pEnt; CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pEntity ); if (pBCC){ m_bAttachMine = false; m_bNeedReload = true; return; } #ifndef CLIENT_DLL //On vérifie qu'il n 'y a pas déjà une mine sur le support visé CBaseEntity* pResult = gEntList.FindEntityByClassname(NULL,"npc_mine"); while (pResult) { if((pResult->GetAbsOrigin() - tr.endpos).Length() < MINE_DISTANCE){ m_bAttachMine = false; m_bNeedReload = true; return; } pResult = gEntList.FindEntityByClassname(pResult,"npc_mine"); } if (pEntity && !(pEntity->GetFlags() & FL_CONVEYOR)) { QAngle angles; VectorAngles(tr.plane.normal, angles); angles.x += 90; CBaseEntity *pEnt = CBaseEntity::Create( "npc_mine", tr.endpos + tr.plane.normal * 3, angles, NULL ); CNPCMine *pMine = (CNPCMine *)pEnt; pMine->m_hOwner = GetOwner(); ChooseMineColor(pMine); pMine->AttachToEntity( pEntity ); pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType ); } #endif } } m_bAttachMine = false; m_bNeedReload = true; }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void BloodImpactCallback( const CEffectData & data ) { bool bFoundBlood = false; // Find which sort of blood we are for ( int i = 0; i < ARRAYSIZE( bloodCallbacks ); i++ ) { if ( bloodCallbacks[i].nColor == data.m_nColor ) { QAngle vecAngles; VectorAngles( -data.m_vNormal, vecAngles ); DispatchParticleEffect( bloodCallbacks[i].lpszParticleSystemName, data.m_vOrigin, vecAngles ); bFoundBlood = true; break; } } if ( bFoundBlood == false ) { Vector vecPosition; vecPosition = data.m_vOrigin; // Fetch the blood color. colorentry_t color; GetBloodColor( data.m_nColor, color ); FX_BloodBulletImpact( vecPosition, data.m_vNormal, data.m_flScale, color.r, color.g, color.b ); } }
void CObjectTeleporter::ShowDirectionArrow( bool bShow ) { if ( bShow != m_bShowDirectionArrow ) { if ( m_iDirectionBodygroup >= 0 ) { SetBodygroup( m_iDirectionBodygroup, bShow ? 1 : 0 ); } m_bShowDirectionArrow = bShow; if ( bShow ) { CObjectTeleporter *pMatch = GetMatchingTeleporter(); Assert( pMatch ); Vector vecToOwner = pMatch->GetAbsOrigin() - GetAbsOrigin(); QAngle angleToExit; VectorAngles( vecToOwner, Vector(0,0,1), angleToExit ); angleToExit -= GetAbsAngles(); // pose param is flipped and backwards, adjust. m_flYawToExit = anglemod( -angleToExit.y + 180 ); } } }
//----------------------------------------------------------------------------- // Purpose: Draws magic lines... //----------------------------------------------------------------------------- void CPointAngularVelocitySensor::DrawDebugLines( void ) { if ( m_hTargetEntity ) { Vector vForward, vRight, vUp; AngleVectors( m_hTargetEntity->GetAbsAngles(), &vForward, &vRight, &vUp ); NDebugOverlay::Line( GetAbsOrigin(), GetAbsOrigin() + vForward * 64, 255, 0, 0, false, 0 ); NDebugOverlay::Line( GetAbsOrigin(), GetAbsOrigin() + vRight * 64, 0, 255, 0, false, 0 ); NDebugOverlay::Line( GetAbsOrigin(), GetAbsOrigin() + vUp * 64, 0, 0, 255, false, 0 ); } if ( m_bUseHelper == true ) { QAngle Angles; Vector vAxisForward, vAxisRight, vAxisUp; Vector vLine = m_vecAxis - GetAbsOrigin(); VectorNormalize( vLine ); VectorAngles( vLine, Angles ); AngleVectors( Angles, &vAxisForward, &vAxisRight, &vAxisUp ); NDebugOverlay::Line( GetAbsOrigin(), GetAbsOrigin() + vAxisForward * 64, 255, 0, 0, false, 0 ); NDebugOverlay::Line( GetAbsOrigin(), GetAbsOrigin() + vAxisRight * 64, 0, 255, 0, false, 0 ); NDebugOverlay::Line( GetAbsOrigin(), GetAbsOrigin() + vAxisUp * 64, 0, 0, 255, false, 0 ); } }
void CASW_Rocket::FindHomingPosition( Vector *pTarget ) { CBaseEntity *pHomingTarget = m_hHomingTarget.Get(); if ( !pHomingTarget ) { SetTarget( pHomingTarget = FindPotentialTarget() ); m_bFlyingWild = false; } if ( pHomingTarget ) { *pTarget = pHomingTarget->WorldSpaceCenter(); return; } else { // just fly straight if there's nothing to home in on Vector vecDir = GetAbsVelocity(); vecDir.z = 0; *pTarget = GetAbsOrigin() + vecDir * 200.0f; VectorAngles( vecDir, m_vWobbleAngles ); m_bFlyingWild = true; } }
//------------------------------------------------------------------------------ // Purpose : Drop a window pane entity // Input : // Output : //------------------------------------------------------------------------------ void CBreakableSurface::DropPane(int nWidth, int nHeight) { // Check parameter range if (nWidth < 0 || nWidth >= m_nNumWide) return; if (nHeight < 0 || nHeight >= m_nNumHigh) return; if (!IsBroken(nWidth,nHeight)) { BreakPane(nWidth,nHeight); QAngle vAngles; VectorAngles(-1*m_vNormal,vAngles); Vector vWidthDir,vHeightDir; AngleVectors(vAngles,NULL,&vWidthDir,&vHeightDir); Vector vBreakPos = m_vCorner + (nWidth*vWidthDir*m_flPanelWidth) + (nHeight*vHeightDir*m_flPanelHeight); CreateShards(vBreakPos, vAngles, vec3_origin, vec3_origin, WINDOW_PANEL_SIZE, WINDOW_PANEL_SIZE, WINDOW_SMALL_SHARD_SIZE); DamageSound(); CWindowPane *pPane = CWindowPane::CreateWindowPane(vBreakPos, vAngles); if (pPane) { pPane->SetLocalAngularVelocity( RandomAngle(-120,120) ); } } }
void CLaser::PostRender() const { BaseClass::PostRender(); if (!GameServer()->GetRenderer()->IsRenderingTransparent()) return; if (!m_bShouldRender) return; if (!m_hOwner) return; CRenderingContext r(DigitanksGame()->GetDigitanksRenderer(), true); r.SetBlend(BLEND_ADDITIVE); Vector vecForward, vecRight, vecUp; float flLength = LaserLength(); CDigitank* pOwner = dynamic_cast<CDigitank*>(GetOwner()); Vector vecMuzzle = m_hOwner->GetGlobalOrigin(); Vector vecTarget = vecMuzzle + AngleVector(GetGlobalAngles()) * flLength; if (pOwner) { Vector vecDirection = (pOwner->GetLastAim() - pOwner->GetGlobalOrigin()).Normalized(); vecTarget = vecMuzzle + vecDirection * flLength; AngleVectors(VectorAngles(vecDirection), &vecForward, &vecRight, &vecUp); vecMuzzle = pOwner->GetGlobalOrigin() + vecDirection * 3 + Vector(0, 0, 3); } float flBeamWidth = 1.5; Vector avecRayColors[] = { Vector(1, 0, 0), Vector(0, 1, 0), Vector(0, 0, 1), }; float flRayRamp = RemapValClamped((float)(GameServer()->GetGameTime() - GetSpawnTime()), 0.5f, 1.5f, 0.0f, 1); float flAlphaRamp = RemapValClamped((float)(GameServer()->GetGameTime() - GetSpawnTime()), 1, 2, 1.0f, 0); size_t iBeams = 21; for (size_t i = 0; i < iBeams; i++) { float flUp = RemapVal((float)i, 0, (float)iBeams, -flLength, flLength); Vector vecRay = LerpValue<Vector>(Vector(1, 1, 1), avecRayColors[i%3], flRayRamp); Color clrRay = vecRay; clrRay.SetAlpha((int)(200*flAlphaRamp)); r.SetColor(clrRay); CRopeRenderer rope(DigitanksGame()->GetDigitanksRenderer(), s_hBeam, vecMuzzle, flBeamWidth); rope.SetTextureOffset(((float)i/20) - GameServer()->GetGameTime() - GetSpawnTime()); rope.Finish(vecTarget + vecUp*flUp); } }
// // Sticky gib puts blood on the wall and stays put. // void CGib::StickyGibTouch ( CBaseEntity *pOther ) { Vector vecSpot; trace_t tr; SetThink ( &CGib::SUB_Remove ); SetNextThink( gpGlobals->curtime + 10 ); if ( !FClassnameIs( pOther, "worldspawn" ) ) { SetNextThink( gpGlobals->curtime ); return; } UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + GetAbsVelocity() * 32, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr); UTIL_BloodDecalTrace( &tr, m_bloodColor ); Vector vecForward = tr.plane.normal * -1; QAngle angles; VectorAngles( vecForward, angles ); SetLocalAngles( angles ); SetAbsVelocity( vec3_origin ); SetLocalAngularVelocity( vec3_angle ); SetMoveType( MOVETYPE_NONE ); }
//========================================================= // NoFriendlyFire - checks for possibility of friendly fire // // Builds a large box in front of the grunt and checks to see // if any squad members are in that box. //========================================================= bool CHL1BaseNPC::NoFriendlyFire( void ) { if ( !m_pSquad ) { return true; } CPlane backPlane; CPlane leftPlane; CPlane rightPlane; Vector vecLeftSide; Vector vecRightSide; Vector v_left; Vector vForward, vRight, vUp; QAngle vAngleToEnemy; if ( GetEnemy() != NULL ) { //!!!BUGBUG - to fix this, the planes must be aligned to where the monster will be firing its gun, not the direction it is facing!!! VectorAngles( ( GetEnemy()->WorldSpaceCenter() - GetAbsOrigin() ), vAngleToEnemy ); AngleVectors ( vAngleToEnemy, &vForward, &vRight, &vUp ); } else { // if there's no enemy, pretend there's a friendly in the way, so the grunt won't shoot. return false; } vecLeftSide = GetAbsOrigin() - ( vRight * ( WorldAlignSize().x * 1.5 ) ); vecRightSide = GetAbsOrigin() + ( vRight * ( WorldAlignSize().x * 1.5 ) ); v_left = vRight * -1; leftPlane.InitializePlane ( vRight, vecLeftSide ); rightPlane.InitializePlane ( v_left, vecRightSide ); backPlane.InitializePlane ( vForward, GetAbsOrigin() ); AISquadIter_t iter; for ( CAI_BaseNPC *pSquadMember = m_pSquad->GetFirstMember( &iter ); pSquadMember; pSquadMember = m_pSquad->GetNextMember( &iter ) ) { if ( pSquadMember == NULL ) continue; if ( pSquadMember == this ) continue; if ( backPlane.PointInFront ( pSquadMember->GetAbsOrigin() ) && leftPlane.PointInFront ( pSquadMember->GetAbsOrigin() ) && rightPlane.PointInFront ( pSquadMember->GetAbsOrigin()) ) { // this guy is in the check volume! Don't shoot! return false; } } return true; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponSMG1::SecondaryAttack( 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 ); CGrenadeAR2 *pGrenade = (CGrenadeAR2*)Create( "grenade_ar2", 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_smg1_grenade.GetFloat() ); SendWeaponAnim( ACT_VM_SECONDARYATTACK ); // 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 ); }
void CNPC_Infected::MeleeAttack( float distance, float damage, QAngle &viewPunch, Vector &shove ) { Vector vecForceDir; // Always hurt bullseyes for now if ( ( GetEnemy() != NULL ) && ( GetEnemy()->Classify() == CLASS_BULLSEYE ) ) { vecForceDir = (GetEnemy()->GetAbsOrigin() - GetAbsOrigin()); CTakeDamageInfo info( this, this, damage, DMG_SLASH ); CalculateMeleeDamageForce( &info, vecForceDir, GetEnemy()->GetAbsOrigin() ); GetEnemy()->TakeDamage( info ); return; } CBaseEntity *pHurt = CheckTraceHullAttack( distance, -Vector(16,16,32), Vector(16,16,32), damage, DMG_SLASH, 5.0f ); if ( pHurt ) { vecForceDir = ( pHurt->WorldSpaceCenter() - WorldSpaceCenter() ); //FIXME: Until the interaction is setup, kill combine soldiers in one hit -- jdw if ( FClassnameIs( pHurt, "npc_combine_s" ) ) { CTakeDamageInfo dmgInfo( this, this, pHurt->m_iHealth+25, DMG_SLASH ); CalculateMeleeDamageForce( &dmgInfo, vecForceDir, pHurt->GetAbsOrigin() ); pHurt->TakeDamage( dmgInfo ); return; } CBasePlayer *pPlayer = ToBasePlayer( pHurt ); if ( pPlayer != NULL ) { //Kick the player angles if ( !(pPlayer->GetFlags() & FL_GODMODE ) && pPlayer->GetMoveType() != MOVETYPE_NOCLIP ) { pPlayer->ViewPunch( viewPunch ); Vector dir = pHurt->GetAbsOrigin() - GetAbsOrigin(); VectorNormalize(dir); QAngle angles; VectorAngles( dir, angles ); Vector forward, right; AngleVectors( angles, &forward, &right, NULL ); //Push the target back pHurt->ApplyAbsVelocityImpulse( - right * shove[1] - forward * shove[0] ); } } // Play a random attack hit sound EmitSound( "Zombie.Punch" ); } else { EmitSound( "Zombie.AttackMiss" ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponCGuard::UpdateLasers( void ) { //Only update the lasers whilst charging if ( ( m_flChargeTime < gpGlobals->curtime ) || ( m_bFired ) ) return; Vector start, end, v_forward, v_right, v_up; CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if ( pPlayer == NULL ) return; pPlayer->GetVectors( &v_forward, &v_right, &v_up ); //Get the position of the laser start = pPlayer->Weapon_ShootPosition( ); start += ( v_forward * 8.0f ) + ( v_right * 3.0f ) + ( v_up * -2.0f ); end = start + ( v_forward * MAX_TRACE_LENGTH ); float angleOffset = ( 1.0f - ( m_flChargeTime - gpGlobals->curtime ) ) / 1.0f; Vector offset[4]; offset[0] = Vector( 0.0f, 0.5f, -0.5f ); offset[1] = Vector( 0.0f, 0.5f, 0.5f ); offset[2] = Vector( 0.0f, -0.5f, -0.5f ); offset[3] = Vector( 0.0f, -0.5f, 0.5f ); QAngle v_ang; Vector v_dir; angleOffset *= 2.0f; if ( angleOffset > 1.0f ) angleOffset = 1.0f; for ( int i = 0; i < 4; i++ ) { Vector ofs = start + ( v_forward * offset[i][0] ) + ( v_right * offset[i][1] ) + ( v_up * offset[i][2] ); float hScale = ( offset[i][1] <= 0.0f ) ? 1.0f : -1.0f; float vScale = ( offset[i][2] <= 0.0f ) ? 1.0f : -1.0f; VectorAngles( v_forward, v_ang ); v_ang[PITCH] = UTIL_AngleMod( v_ang[PITCH] + ( (1.0f-angleOffset) * 15.0f * vScale ) ); v_ang[YAW] = UTIL_AngleMod( v_ang[YAW] + ( (1.0f-angleOffset) * 15.0f * hScale ) ); AngleVectors( v_ang, &v_dir ); trace_t tr; UTIL_TraceLine( ofs, ofs + ( v_dir * MAX_TRACE_LENGTH ), MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); UTIL_Beam( ofs, tr.endpos, m_beamIndex, 0, 0, 2.0f, 0.1f, 2, 0, 1, 0, 255, 255, 255, 32, 100 ); UTIL_Beam( ofs, tr.endpos, m_haloIndex, 0, 0, 2.0f, 0.1f, 4, 0, 1, 16, 255, 255, 255, 8, 100 ); } }
//------------------------------------------------------------------------------ // Purpose : Create leak effect if material requests it // Input : // Output : //------------------------------------------------------------------------------ void LeakEffect( trace_t &tr ) { Vector diffuseColor, baseColor; Vector vTraceDir = (tr.endpos - tr.startpos); VectorNormalize(vTraceDir); Vector vTraceStart = tr.endpos - 0.1*vTraceDir; Vector vTraceEnd = tr.endpos + 0.1*vTraceDir; IMaterial* pTraceMaterial = engine->TraceLineMaterialAndLighting( vTraceStart, vTraceEnd, diffuseColor, baseColor ); if (!pTraceMaterial) return; bool found; IMaterialVar *pLeakVar = pTraceMaterial->FindVar( "$leakamount", &found, false ); if( !found ) return; C_Splash* pLeak = new C_Splash(); if (!pLeak) return; ClientEntityList().AddNonNetworkableEntity( pLeak->GetIClientUnknown() ); IMaterialVar* pLeakColorVar = pTraceMaterial->FindVar( "$leakcolor", &found ); if (found) { Vector color; pLeakColorVar->GetVecValue(color.Base(),3); pLeak->m_vStartColor = pLeak->m_vEndColor = color; } IMaterialVar* pLeakNoiseVar = pTraceMaterial->FindVar( "$leaknoise", &found ); if (found) { pLeak->m_flNoise = pLeakNoiseVar->GetFloatValue(); } IMaterialVar* pLeakForceVar = pTraceMaterial->FindVar( "$leakforce", &found ); if (found) { float flForce = pLeakForceVar->GetFloatValue(); pLeak->m_flSpeed = flForce; pLeak->m_flSpeedRange = pLeak->m_flNoise * flForce; } pLeak->m_flSpawnRate = pLeakVar->GetFloatValue();; pLeak->m_flParticleLifetime = 10; pLeak->m_flWidthMin = 1; pLeak->m_flWidthMax = 5; pLeak->SetLocalOrigin( tr.endpos ); QAngle angles; VectorAngles( tr.plane.normal, angles ); pLeak->SetLocalAngles( angles ); pLeak->Start(&g_ParticleMgr, NULL); pLeak->m_flStopEmitTime = gpGlobals->curtime+5.0; pLeak->SetNextClientThink(gpGlobals->curtime+20.0); }
//----------------------------------------------------------------------------- // Purpose: // Input : *pTask - //----------------------------------------------------------------------------- void CNPC_WpnScanner::RunTask( const Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_WPNSCANNER_ATTACK: { CBaseEntity *pEnemy = GetEnemy(); if ( !pEnemy ) { TaskFail( FAIL_NO_ENEMY ); return; } if ( m_flNextAttack > gpGlobals->curtime ) return; m_flNextAttack = gpGlobals->curtime + 0.2; Vector vecFirePos; QAngle vecAngles; GetAttachment( m_iMuzzleAttachment, vecFirePos, vecAngles ); Vector vecTarget = GetEnemy()->BodyTarget( vecFirePos ); Vector vecToTarget = (vecTarget - vecFirePos); VectorNormalize( vecToTarget ); VectorAngles( vecToTarget, vecAngles ); Vector vecRight; Vector vecUp; AngleVectors( vecAngles, &vecToTarget, &vecRight, &vecUp ); // Add some inaccuracy float x, y, z; do { x = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5); y = random->RandomFloat(-0.5,0.5) + random->RandomFloat(-0.5,0.5); z = x*x+y*y; } while (z > 1); vecToTarget = vecToTarget + x * VECTOR_CONE_20DEGREES * vecRight + y * VECTOR_CONE_20DEGREES * vecUp; vecToTarget *= sk_wpnscanner_proj_speed.GetFloat(); baseprojectilecreate_t newProj; newProj.vecOrigin = vecFirePos; newProj.vecVelocity = vecToTarget; newProj.pOwner = this; newProj.iszModel = m_iszProjectileModel; newProj.flDamage = sk_wpnscanner_proj_dmg.GetFloat(); newProj.iDamageType = DMG_ENERGYBEAM; newProj.flDamageScale = 1.0; CBaseProjectile::Create( newProj ); break; } default: { BaseClass::RunTask(pTask); } } }
QAngle M::CalcAngle( Vector src, Vector dst ) { QAngle angles; Vector delta = src - dst; VectorAngles(delta, angles); delta.Normalize(); return angles; }
//----------------------------------------------------------------------------- // Purpose: // Input : &info - // &vecDir - // *ptr - //----------------------------------------------------------------------------- void CAntlionGrub::TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr ) { QAngle vecAngles; VectorAngles( -vecDir, vecAngles ); DispatchParticleEffect( "GrubBlood", ptr->endpos, vecAngles ); BaseClass::TraceAttack( info, vecDir, ptr ); }
// Tout ce qui suit est un immonde copié collé d'au dessus, serait trop chiant de faire autrement void CreateFlechette( const Vector &vecOrigin, const Vector &vecDirection, int nSkin ) { model_t *pModel = (model_t *)engine->LoadModel( "models/Weapons/flechette.mdl" ); QAngle vAngles; VectorAngles( vecDirection, vAngles ); C_LocalTempEntity *pTemp = tempents->SpawnTempModel( pModel, vecOrigin - vecDirection * 8, vAngles, Vector(0, 0, 0 ), 30.0f, FTENT_NONE ); pTemp->m_nSkin = nSkin; }
void CSDKPlayerAnimState::EstimateYaw( void ) { // Get the frame time. float flDeltaTime = gpGlobals->frametime * m_pSDKPlayer->GetSlowMoMultiplier(); if ( flDeltaTime == 0.0f ) return; // Get the player's velocity and angles. Vector vecEstVelocity; GetOuterAbsVelocity( vecEstVelocity ); QAngle angles = GetBasePlayer()->GetLocalAngles(); // If we are not moving, sync up the feet and eyes slowly. if (m_pSDKPlayer->m_Shared.IsProne()) { // Don't touch it } else if ( vecEstVelocity.x == 0.0f && vecEstVelocity.y == 0.0f ) { float flYawDelta = angles[YAW] - m_PoseParameterData.m_flEstimateYaw; flYawDelta = AngleNormalize( flYawDelta ); if ( flDeltaTime < 0.25f ) { flYawDelta *= ( flDeltaTime * 4.0f ); } else { flYawDelta *= flDeltaTime; } m_PoseParameterData.m_flEstimateYaw += flYawDelta; m_PoseParameterData.m_flEstimateYaw = AngleNormalize( m_PoseParameterData.m_flEstimateYaw ); } else if (m_pSDKPlayer->m_Shared.IsAimedIn() || m_pSDKPlayer->m_Shared.IsDiving() || m_pSDKPlayer->m_Shared.IsRolling() || m_pSDKPlayer->m_Shared.IsSliding()) { m_PoseParameterData.m_flEstimateYaw = ( atan2( vecEstVelocity.y, vecEstVelocity.x ) * 180.0f / M_PI ); m_PoseParameterData.m_flEstimateYaw = clamp( m_PoseParameterData.m_flEstimateYaw, -180.0f, 180.0f ); } else { QAngle angDir; VectorAngles(vecEstVelocity, angDir); if (fabs(AngleNormalize(angDir[YAW] - m_flEyeYaw)) <= 90) m_bFacingForward = true; else if (fabs(AngleNormalize(angDir[YAW] - m_flEyeYaw)) >= 91) m_bFacingForward = false; float flYawDelta = AngleNormalize(m_flGoalFeetYaw - m_flCurrentFeetYaw); if (m_bFacingForward) m_PoseParameterData.m_flEstimateYaw = flYawDelta; else m_PoseParameterData.m_flEstimateYaw = 180-flYawDelta; } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CGrappleHook::FlyThink(void) { QAngle angNewAngles; VectorAngles(GetAbsVelocity(), angNewAngles); SetAbsAngles(angNewAngles); SetNextThink(gpGlobals->curtime + 0.1f); }
void CVehicleMortar::UpdateElevation( const Vector &vecTargetVel ) { QAngle angles; VectorAngles( vecTargetVel, angles ); m_flMortarPitch = anglemod( -angles[PITCH] ); SetBoneController( 0, m_flMortarYaw ); SetBoneController( 1, m_flMortarPitch ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CUnitBase::SetAim( Vector &vAimDir ) { QAngle angDir = QAngle(); VectorAngles(vAimDir, angDir); // Just set pitch to enemy direction and yaw to our move directin m_fEyePitch = angDir.x; m_fEyeYaw = angDir.y; //GetAbsAngles().y; }
int CBaseTurret::MoveTurret(void) { bool bDidMove = false; int iPose; matrix3x4_t localToWorld; GetAttachment( LookupAttachment( "eyes" ), localToWorld ); Vector vecGoalDir; AngleVectors( m_vecGoalAngles, &vecGoalDir ); Vector vecGoalLocalDir; VectorIRotate( vecGoalDir, localToWorld, vecGoalLocalDir ); QAngle vecGoalLocalAngles; VectorAngles( vecGoalLocalDir, vecGoalLocalAngles ); float flDiff; QAngle vecNewAngles; // update pitch flDiff = AngleNormalize( UTIL_ApproachAngle( vecGoalLocalAngles.x, 0.0, 0.1 * m_iBaseTurnRate ) ); iPose = LookupPoseParameter( TURRET_BC_PITCH ); SetPoseParameter( iPose, GetPoseParameter( iPose ) + flDiff / 1.5 ); if (fabs(flDiff) > 0.1) { bDidMove = true; } // update yaw, with acceleration #if 0 float flDist = AngleNormalize( vecGoalLocalAngles.y ); float flNewDist; float flNewTurnRate; ChangeDistance( 0.1, flDist, 0.0, m_fTurnRate, m_iBaseTurnRate, m_iBaseTurnRate * 4, flNewDist, flNewTurnRate ); m_fTurnRate = flNewTurnRate; flDiff = flDist - flNewDist; #else flDiff = AngleNormalize( UTIL_ApproachAngle( vecGoalLocalAngles.y, 0.0, 0.1 * m_iBaseTurnRate ) ); #endif iPose = LookupPoseParameter( TURRET_BC_YAW ); SetPoseParameter( iPose, GetPoseParameter( iPose ) + flDiff / 1.5 ); if (fabs(flDiff) > 0.1) { bDidMove = true; } if (bDidMove) { // DevMsg( "(%.2f, %.2f)\n", AngleNormalize( vecGoalLocalAngles.x ), AngleNormalize( vecGoalLocalAngles.y ) ); } return bDidMove; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CAntlionGrub::Squash( CBaseEntity *pOther, bool bDealDamage, bool bSpawnBlood ) { // If we're already squashed, then don't bother doing it again! if ( GetEffects() & EF_NODRAW ) return; SpawnSquashedGrub(); AddEffects( EF_NODRAW ); AddSolidFlags( FSOLID_NOT_SOLID ); // Stop being attached to us if ( m_hGlowSprite ) { FadeGlow(); m_hGlowSprite->SetParent( NULL ); } EmitSound( "NPC_Antlion_Grub.Die" ); EmitSound( "NPC_Antlion_Grub.Squish" ); // if vort stepped on me, maybe he wants to say something if ( pOther && FClassnameIs( pOther, "npc_vortigaunt" ) ) { Assert(dynamic_cast<CNPC_Vortigaunt *>(pOther)); static_cast<CNPC_Vortigaunt *>(pOther)->OnSquishedGrub(this); } SetTouch( NULL ); //if ( bSpawnBlood ) { // Temp squash effect Vector vecForward, vecUp; AngleVectors( GetAbsAngles(), &vecForward, NULL, &vecUp ); // Start effects at either end of the grub Vector vecSplortPos = GetAbsOrigin() + vecForward * 14.0f; DispatchParticleEffect( "GrubSquashBlood", vecSplortPos, GetAbsAngles() ); vecSplortPos = GetAbsOrigin() - vecForward * 16.0f; Vector vecDir = -vecForward; QAngle vecAngles; VectorAngles( vecDir, vecAngles ); DispatchParticleEffect( "GrubSquashBlood", vecSplortPos, vecAngles ); MakeSquashDecals( GetAbsOrigin() + vecForward * 32.0f ); MakeSquashDecals( GetAbsOrigin() - vecForward * 32.0f ); } // Deal deadly damage to ourself if ( bDealDamage ) { CTakeDamageInfo info( pOther, pOther, Vector( 0, 0, -1 ), GetAbsOrigin(), GetHealth()+1, DMG_CRUSH ); TakeDamage( info ); } }