//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponShieldGrenade::ThrowGrenade( void ) { CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>( GetOwner() ); if ( !pPlayer ) return; BaseClass::WeaponSound(WPN_DOUBLE); // Calculate launch velocity (3 seconds for max distance) float flThrowTime = min( (gpGlobals->curtime - m_flStartedThrowAt), 3.0 ); float flSpeed = 800 + (200 * flThrowTime); // If the player's crouched, roll the grenade if ( pPlayer->GetFlags() & FL_DUCKING ) { // Launch the grenade Vector vecForward; QAngle vecAngles = pPlayer->EyeAngles(); // Throw it up just a tad vecAngles.x = -1; AngleVectors( vecAngles, &vecForward, NULL, NULL); Vector vecOrigin; VectorLerp( pPlayer->EyePosition(), pPlayer->GetAbsOrigin(), 0.25f, vecOrigin ); vecOrigin += (vecForward * 16); vecForward = vecForward * flSpeed; QAngle vecGrenAngles; vecGrenAngles.Init( 0, vecAngles.y, 0 ); #if !defined( CLIENT_DLL ) CreateShieldGrenade( vecOrigin, vecGrenAngles, vecForward, vec3_angle, pPlayer, SHIELD_GRENADE_LIFETIME ); #endif } else { // Launch the grenade Vector vecForward; QAngle vecAngles = pPlayer->EyeAngles(); AngleVectors( vecAngles, &vecForward, NULL, NULL); Vector vecOrigin = pPlayer->EyePosition(); vecOrigin += (vecForward * 16); vecForward = vecForward * flSpeed; QAngle vecGrenAngles; vecGrenAngles.Init( 0, vecAngles.y, 0 ); #if !defined( CLIENT_DLL ) CreateShieldGrenade( vecOrigin, vecGrenAngles, vecForward, vec3_angle, pPlayer, SHIELD_GRENADE_LIFETIME ); #endif } pPlayer->RemoveAmmo( 1, m_iPrimaryAmmoType ); }
static cell_t smn_TRTraceRay(IPluginContext *pContext, const cell_t *params) { cell_t *startaddr, *endaddr; pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[2], &endaddr); g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); switch (params[4]) { case RayType_EndPoint: { g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); break; } case RayType_Infinite: { g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); AngleVectors(g_DirAngles, &g_EndVec); /* Make it unitary and get the ending point */ g_EndVec.NormalizeInPlace(); g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; break; } } g_Ray.Init(g_StartVec, g_EndVec); enginetrace->TraceRay(g_Ray, params[3], &g_HitAllFilter, &g_Trace); g_Trace.UpdateEntRef(); return 1; }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CWeaponDoubleShotgun::PrimaryAttack( void ) { // Only the player fires this way so we can cast CBasePlayer *pPlayer = ToBasePlayer( GetOwner() ); if (!pPlayer) { return; } if (m_iClip1 >= 2) { // MUST call sound before removing a round from the clip of a CMachineGun WeaponSound(WPN_DOUBLE); pPlayer->DoMuzzleFlash(); SendWeaponAnim( ACT_VM_SECONDARYATTACK ); // Don't fire again until fire animation has completed m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration(); m_iClip1 -= 2; // player "shoot" animation pPlayer->SetAnimation( PLAYER_ATTACK1 ); Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); FireBulletsInfo_t info( 40, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); 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 ); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } //m_bNeedPump = true; } else { if (m_bInReload) { Reload(); } else { StartReload(); } } }
void StudioModel::GetMovement( float prevcycle[5], Vector &vecPos, QAngle &vecAngles ) { vecPos.Init(); vecAngles.Init(); CStudioHdr *pStudioHdr = GetStudioHdr(); if ( !pStudioHdr ) return; // assume that changes < -0.5 are loops.... if (m_cycle - prevcycle[0] < -0.5) { prevcycle[0] = prevcycle[0] - 1.0; } Studio_SeqMovement( pStudioHdr, m_sequence, prevcycle[0], m_cycle, m_poseparameter, vecPos, vecAngles ); prevcycle[0] = m_cycle; int i; for (i = 0; i < 4; i++) { Vector vecTmp; QAngle angTmp; if (m_Layer[i].m_cycle - prevcycle[i+1] < -0.5) { prevcycle[i+1] = prevcycle[i+1] - 1.0; } if (m_Layer[i].m_weight > 0.0) { vecTmp.Init(); angTmp.Init(); if (Studio_SeqMovement( pStudioHdr, m_Layer[i].m_sequence, prevcycle[i+1], m_Layer[i].m_cycle, m_poseparameter, vecTmp, angTmp )) { vecPos = vecPos * ( 1.0 - m_Layer[i].m_weight ) + vecTmp * m_Layer[i].m_weight; } } prevcycle[i+1] = m_Layer[i].m_cycle; } return; }
bool RegReadQAngle( HKEY hKey, const char *szSubKey, QAngle& value ) { Vector tmp; if (RegReadVector( hKey, szSubKey, tmp )) { value.Init( tmp.x, tmp.y, tmp.z ); return true; } return false; }
bool C_BaseCombatWeapon::GetShootPosition( Vector &vOrigin, QAngle &vAngles ) { // Get the entity because the weapon doesn't have the right angles. C_BaseCombatCharacter *pEnt = ToBaseCombatCharacter( GetOwner() ); if ( pEnt ) { if ( pEnt == C_BasePlayer::GetLocalPlayer() ) { vAngles = pEnt->EyeAngles(); } else { vAngles = pEnt->GetRenderAngles(); } } else { vAngles.Init(); } C_BasePlayer *player = ToBasePlayer( pEnt ); bool bUseViewModel = false; if ( C_BasePlayer::IsLocalPlayer( pEnt ) ) { ACTIVE_SPLITSCREEN_PLAYER_GUARD_ENT( pEnt ); bUseViewModel = !player->ShouldDrawLocalPlayer(); } QAngle vDummy; if ( IsActiveByLocalPlayer() && bUseViewModel ) { C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } } else { // Thirdperson int iAttachment = LookupAttachment( "muzzle" ); if ( GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } vOrigin = GetRenderOrigin(); return false; }
static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *params) { cell_t *startaddr, *endaddr; IPluginFunction *pFunc; cell_t data; pFunc = pContext->GetFunctionById(params[5]); if (!pFunc) { return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); } if (params[0] >= 6) { data = params[6]; } else { data = 0; } g_SMTraceFilter.SetFunctionPtr(pFunc, data); pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[2], &endaddr); g_StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); switch (params[4]) { case RayType_EndPoint: { g_EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); break; } case RayType_Infinite: { g_DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); AngleVectors(g_DirAngles, &g_EndVec); /* Make it unitary and get the ending point */ g_EndVec.NormalizeInPlace(); g_EndVec = g_StartVec + g_EndVec * MAX_TRACE_LENGTH; break; } } g_Ray.Init(g_StartVec, g_EndVec); enginetrace->TraceRay(g_Ray, params[3], &g_SMTraceFilter, &g_Trace); g_Trace.UpdateEntRef(); return 1; }
//----------------------------------------------------------------------------- // 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 ); Vector vecSrc = pPlayer->Weapon_ShootPosition( ); Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES ); FireBulletsInfo_t info( 7, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); info.m_pAttacker = pPlayer; // Fire the bullets, and force the first shot to be perfectly accuracy pPlayer->FireBullets( info ); #ifdef SecobMod__Enable_Fixed_Multiplayer_AI #ifndef CLIENT_DLL // DM: Hellow? NPCs... look here! I'm shooting! pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 1.0 ); CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), SOUNDENT_VOLUME_SHOTGUN, 0.2 ); #endif #endif //SecobMod__Enable_Fixed_Multiplayer_AI QAngle punch; punch.Init( SharedRandomFloat( "shotgunpax", -2, -1 ), SharedRandomFloat( "shotgunpay", -2, 2 ), 0 ); pPlayer->ViewPunch( punch ); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } m_bNeedPump = true; }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CWeaponStriderBuster::OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason ) { m_PickupTime = gpGlobals->curtime; m_CarryAngles.Init( 45, 0, 0 ); if ( ( reason == PICKED_UP_BY_CANNON ) && ( !HasSpawnFlags( SF_DONT_WEAPON_MANAGE ) ) ) { WeaponManager_RemoveManaged( this ); } else if ( reason == PUNTED_BY_CANNON ) { Launch( pPhysGunUser ); } BaseClass::OnPhysGunPickup( pPhysGunUser, reason ); }
void StudioModel::GetMovement( int iSequence, float prevCycle, float nextCycle, Vector &vecPos, QAngle &vecAngles ) { CStudioHdr *pStudioHdr = GetStudioHdr(); if ( !pStudioHdr ) { vecPos.Init(); vecAngles.Init(); return; } // FIXME: this doesn't consider layers Studio_SeqMovement( pStudioHdr, iSequence, prevCycle, nextCycle, m_poseparameter, vecPos, vecAngles ); return; }
void CTETFParticleEffect::Init( void ) { m_vecOrigin.Init(); m_vecStart.Init(); m_vecAngles.Init(); m_iParticleSystemIndex = 0; m_nEntIndex = -1; m_iAttachType = PATTACH_ABSORIGIN; m_iAttachmentPointIndex = 0; m_bResetParticles = false; }
virtual bool LookupOrigin( char const *name, Vector& origin, QAngle& angles ) { int idx = FindNamedEntity( name ); if ( idx == -1 ) { origin.Init(); angles.Init(); return false; } CMapEntityData *e = &m_Entities[ idx ]; Assert( e ); origin = e->origin; angles = e->angles; return true; }
bool C_BaseCombatWeapon::GetShootPosition( Vector &vOrigin, QAngle &vAngles ) { // Get the entity because the weapon doesn't have the right angles. C_BaseCombatCharacter *pEnt = ToBaseCombatCharacter( GetOwner() ); if ( pEnt ) { if ( pEnt == C_BasePlayer::GetLocalPlayer() ) { vAngles = pEnt->EyeAngles(); } else { vAngles = pEnt->GetRenderAngles(); } } else { vAngles.Init(); } QAngle vDummy; if ( IsActiveByLocalPlayer() && !input->CAM_IsThirdPerson() ) { C_BasePlayer *player = ToBasePlayer( pEnt ); C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } } else { // Thirdperson int iAttachment = LookupAttachment( "muzzle" ); if ( GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } vOrigin = GetRenderOrigin(); return false; }
static cell_t smn_TRTraceRayEx(IPluginContext *pContext, const cell_t *params) { cell_t *startaddr, *endaddr; pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[2], &endaddr); Vector StartVec, EndVec; Ray_t ray; StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); switch (params[4]) { case RayType_EndPoint: { EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); break; } case RayType_Infinite: { QAngle DirAngles; DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); AngleVectors(DirAngles, &EndVec); /* Make it unitary and get the ending point */ EndVec.NormalizeInPlace(); EndVec = StartVec + EndVec * MAX_TRACE_LENGTH; break; } } sm_trace_t *tr = new sm_trace_t; ray.Init(StartVec, EndVec); enginetrace->TraceRay(ray, params[3], &g_HitAllFilter, tr); tr->UpdateEntRef(); HandleError herr; Handle_t hndl; if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) { delete tr; return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); } return hndl; }
//----------------------------------------------------------------------------- // Primary gun //----------------------------------------------------------------------------- void CPropAPC::AimPrimaryWeapon( const Vector &vecWorldTarget ) { EntityMatrix parentMatrix; parentMatrix.InitFromEntity( this, m_nMachineGunBaseAttachment ); Vector target = parentMatrix.WorldToLocal( vecWorldTarget ); float quadTarget = target.LengthSqr(); float quadTargetXY = target.x*target.x + target.y*target.y; // Target is too close! Can't aim at it if ( quadTarget > m_vecBarrelPos.LengthSqr() ) { // We're trying to aim the offset barrel at an arbitrary point. // To calculate this, I think of the target as being on a sphere with // it's center at the origin of the gun. // The rotation we need is the opposite of the rotation that moves the target // along the surface of that sphere to intersect with the gun's shooting direction // To calculate that rotation, we simply calculate the intersection of the ray // coming out of the barrel with the target sphere (that's the new target position) // and use atan2() to get angles // angles from target pos to center float targetToCenterYaw = atan2( target.y, target.x ); float centerToGunYaw = atan2( m_vecBarrelPos.y, sqrt( quadTarget - (m_vecBarrelPos.y*m_vecBarrelPos.y) ) ); float targetToCenterPitch = atan2( target.z, sqrt( quadTargetXY ) ); float centerToGunPitch = atan2( -m_vecBarrelPos.z, sqrt( quadTarget - (m_vecBarrelPos.z*m_vecBarrelPos.z) ) ); QAngle angles; angles.Init( -RAD2DEG(targetToCenterPitch+centerToGunPitch), RAD2DEG( targetToCenterYaw + centerToGunYaw ), 0 ); SetPoseParameter( "vehicle_weapon_yaw", angles.y ); SetPoseParameter( "vehicle_weapon_pitch", angles.x ); StudioFrameAdvance(); float curPitch = GetPoseParameter( "vehicle_weapon_pitch" ); float curYaw = GetPoseParameter( "vehicle_weapon_yaw" ); m_bInFiringCone = (fabs(curPitch - angles.x) < 1e-3) && (fabs(curYaw - angles.y) < 1e-3); } else { m_bInFiringCone = false; } }
bool CGlobalLight::KeyValue( const char *szKeyName, const char *szValue ) { if ( FStrEq( szKeyName, "color" ) ) { float tmp[4]; UTIL_StringToFloatArray( tmp, 4, szValue ); m_LightColor.SetR( tmp[0] ); m_LightColor.SetG( tmp[1] ); m_LightColor.SetB( tmp[2] ); m_LightColor.SetA( tmp[3] ); } else if ( FStrEq( szKeyName, "angles" ) ) { QAngle angles; UTIL_StringToVector( angles.Base(), szValue ); if (angles == vec3_angle) { angles.Init( 80, 30, 0 ); } Vector vForward; AngleVectors( angles, &vForward ); m_shadowDirection = vForward; return true; } else if ( FStrEq( szKeyName, "texturename" ) ) { #if defined( _X360 ) if ( Q_strcmp( szValue, "effects/flashlight001" ) == 0 ) { // Use this as the default for Xbox Q_strcpy( m_TextureName.GetForModify(), "effects/flashlight_border" ); } else { Q_strcpy( m_TextureName.GetForModify(), szValue ); } #else Q_strcpy( m_TextureName.GetForModify(), szValue ); #endif } return BaseClass::KeyValue( szKeyName, szValue ); }
void AimLegit::RecoilControlSystem() { int firedShots = g_LocalPlayer->m_iShotsFired(); if (usercmd->buttons & IN_ATTACK) { QAngle aimPunchAngle = g_LocalPlayer->m_aimPunchAngle(); std::random_device r3nd0m; std::mt19937 r3nd0mGen(r3nd0m()); std::uniform_real<float> r3nd0mXAngle(1.7f, 1.9f); std::uniform_real<float> r3nd0mYAngle(1.7f, 1.9f); aimPunchAngle.pitch *= r3nd0mXAngle(r3nd0mGen); aimPunchAngle.yaw *= r3nd0mYAngle(r3nd0mGen); aimPunchAngle.roll = 0.0f; Math::NormalizeAngles(aimPunchAngle); if (firedShots > 2) { QAngle viewangles = usercmd->viewangles; QAngle viewangles_mod = aimPunchAngle; viewangles_mod -= oldPunch; viewangles_mod.roll = 0.0f; Math::NormalizeAngles(viewangles_mod); viewangles -= viewangles_mod; viewangles.roll = 0.0f; Math::NormalizeAngles(viewangles); usercmd->viewangles = viewangles; } oldPunch = aimPunchAngle; } else oldPunch.Init(); }
bool C_CFPlayer::GetIntervalMovement( float flIntervalUsed, bool &bMoveSeqFinished, Vector &newPosition, QAngle &newAngles ) { CStudioHdr *pstudiohdr = GetModelPtr( ); if (! pstudiohdr || !pstudiohdr->SequencesAvailable()) return false; float flComputedCycleRate = GetSequenceCycleRate( pstudiohdr, GetSequence() ); float flNextCycle = GetCycle() + flIntervalUsed * flComputedCycleRate * m_flPlaybackRate; if ((!SequenceLoops()) && flNextCycle > 1.0) { flIntervalUsed = GetCycle() / (flComputedCycleRate * m_flPlaybackRate); flNextCycle = 1.0; bMoveSeqFinished = true; } else { bMoveSeqFinished = false; } Vector deltaPos; QAngle deltaAngles; float poseParameters[MAXSTUDIOPOSEPARAM]; GetPoseParameters(pstudiohdr, poseParameters); if (Studio_SeqMovement( pstudiohdr, GetSequence(), GetCycle(), flNextCycle, poseParameters, deltaPos, deltaAngles )) { VectorYawRotate( deltaPos, GetLocalAngles().y, deltaPos ); newPosition = GetLocalOrigin() + deltaPos; newAngles.Init(); newAngles.y = GetLocalAngles().y + deltaAngles.y; return true; } else { newPosition = GetLocalOrigin(); newAngles = GetLocalAngles(); return false; } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CASW_Broadcast_Camera::FollowTarget( ) { //if (m_hPlayer == NULL) //return; if ( m_hTarget == NULL ) { Disable(); return; } if ( !HasSpawnFlags(SF_CAMERA_PLAYER_INFINITE_WAIT) && (!m_hTarget || m_flReturnTime < gpGlobals->curtime) ) { Disable(); return; } UpdateAllPlayers(); QAngle vecGoal; if ( m_iAttachmentIndex ) { Vector vecOrigin; m_hTarget->GetBaseAnimating()->GetAttachment( m_iAttachmentIndex, vecOrigin ); VectorAngles( vecOrigin - GetAbsOrigin(), vecGoal ); } else { if ( m_hTarget ) { VectorAngles( m_hTarget->GetAbsOrigin() - GetAbsOrigin(), vecGoal ); } else { // Use the viewcontroller's angles vecGoal = GetAbsAngles(); } } // Should we just snap to the goal angles? if ( m_bSnapToGoal ) { SetAbsAngles( vecGoal ); m_bSnapToGoal = false; } else { // UNDONE: Can't we just use UTIL_AngleDiff here? QAngle angles = GetLocalAngles(); if (angles.y > 360) angles.y -= 360; if (angles.y < 0) angles.y += 360; SetLocalAngles( angles ); float dx = vecGoal.x - GetLocalAngles().x; float dy = vecGoal.y - GetLocalAngles().y; if (dx < -180) dx += 360; if (dx > 180) dx = dx - 360; if (dy < -180) dy += 360; if (dy > 180) dy = dy - 360; QAngle vecAngVel; vecAngVel.Init( dx * 40 * gpGlobals->frametime, dy * 40 * gpGlobals->frametime, GetLocalAngularVelocity().z ); SetLocalAngularVelocity(vecAngVel); } if (!HasSpawnFlags(SF_CAMERA_PLAYER_TAKECONTROL)) { SetAbsVelocity( GetAbsVelocity() * 0.8 ); if (GetAbsVelocity().Length( ) < 10.0) { SetAbsVelocity( vec3_origin ); } } SetNextThink( gpGlobals->curtime ); Move(); }
static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *params) { IPluginFunction *pFunc; cell_t *startaddr, *endaddr; cell_t data; pFunc = pContext->GetFunctionById(params[5]); if (!pFunc) { return pContext->ThrowNativeError("Invalid function id (%X)", params[5]); } pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[2], &endaddr); Vector StartVec, EndVec; CSMTraceFilter smfilter; Ray_t ray; if (params[0] >= 6) { data = params[6]; } else { data = 0; } smfilter.SetFunctionPtr(pFunc, data); StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); switch (params[4]) { case RayType_EndPoint: { EndVec.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); break; } case RayType_Infinite: { QAngle DirAngles; DirAngles.Init(sp_ctof(endaddr[0]), sp_ctof(endaddr[1]), sp_ctof(endaddr[2])); AngleVectors(DirAngles, &EndVec); /* Make it unitary and get the ending point */ EndVec.NormalizeInPlace(); EndVec = StartVec + EndVec * MAX_TRACE_LENGTH; break; } } sm_trace_t *tr = new sm_trace_t; ray.Init(StartVec, EndVec); enginetrace->TraceRay(ray, params[3], &smfilter, tr); tr->UpdateEntRef(); HandleError herr; Handle_t hndl; if (!(hndl=handlesys->CreateHandle(g_TraceHandle, tr, pContext->GetIdentity(), myself->GetIdentity(), &herr))) { delete tr; return pContext->ThrowNativeError("Unable to create a new trace handle (error %d)", herr); } return hndl; }
//----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CWeaponFreeze::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 ); FireBulletsInfo_t info( 7, vecSrc, vecAiming, GetBulletSpread(), MAX_TRACE_LENGTH, m_iPrimaryAmmoType ); 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 ); if (!m_iClip1 && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0) { // HEV suit - indicate out of ammo condition pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0); } trace_t tr; // do the traceline UTIL_TraceLine( vecSrc, vecAiming, MASK_ALL, pPlayer,COLLISION_GROUP_NPC, &tr ); // do if statements to check what we hit ... add if player is human, etc, etc if ( tr.m_pEnt ) { // This will ignite the player tr.m_pEnt->SetAbsVelocity(0); tr.m_pEnt->Freeze(); tr.m_pEnt->SetGravity(2000000); } }
static void PlaceDetail( DetailModel_t const& model, const Vector& pt, const Vector& normal ) { // But only place it on the surface if it meets the angle constraints... float cosAngle = normal.z; // Never emit if the angle's too steep if (cosAngle < model.m_MaxCosAngle) return; // If it's between min + max, flip a coin... if (cosAngle < model.m_MinCosAngle) { float probability = (cosAngle - model.m_MaxCosAngle) / (model.m_MinCosAngle - model.m_MaxCosAngle); float t = rand() / (float)RAND_MAX; if (t > probability) return; } // Compute the orientation of the detail QAngle angles; if (model.m_Flags & MODELFLAG_UPRIGHT) { // If it's upright, we just select a random yaw angles.Init( 0, 360.0f * rand() / (float)RAND_MAX, 0.0f ); } else { // It's not upright, so it must conform to the ground. Choose // a random orientation based on the surface normal Vector zaxis; VectorCopy( normal, zaxis ); // Choose any two arbitrary axes which are perpendicular to the normal Vector xaxis( 1, 0, 0 ); if (fabs(xaxis.Dot(zaxis)) - 1.0 > -1e-3) xaxis.Init( 0, 1, 0 ); Vector yaxis; CrossProduct( zaxis, xaxis, yaxis ); CrossProduct( yaxis, zaxis, xaxis ); VMatrix matrix; matrix.SetBasisVectors( xaxis, yaxis, zaxis ); float rotAngle = 360.0f * rand() / (float)RAND_MAX; VMatrix rot = SetupMatrixAxisRot( Vector( 0, 0, 1 ), rotAngle ); matrix = matrix * rot; MatrixToAngles( matrix, angles ); } // FIXME: We may also want a purely random rotation too // Insert an element into the object dictionary if it aint there... switch ( model.m_Type ) { case DETAIL_PROP_TYPE_MODEL: AddDetailToLump( model.m_ModelName.String(), pt, angles, model.m_Orientation ); break; case DETAIL_PROP_TYPE_SPRITE: { float flScale = 1.0f; if ( model.m_flRandomScaleStdDev != 0.0f ) { flScale = fabs( RandomGaussianFloat( 1.0f, model.m_flRandomScaleStdDev ) ); } AddDetailSpriteToLump( pt, angles, model.m_Orientation, model.m_Pos, model.m_Tex, flScale ); } break; } }