//========================================================= // Tracking Hornet hit something //========================================================= void CNPC_Hornet::TrackTouch ( CBaseEntity *pOther ) { if ( !pOther->IsSolid() || pOther->IsSolidFlagSet(FSOLID_VOLUME_CONTENTS) ) { return; } if ( pOther == GetOwnerEntity() || pOther->GetModelIndex() == GetModelIndex() ) {// bumped into the guy that shot it. //SetSolid( SOLID_NOT ); return; } int nRelationship = IRelationType( pOther ); if ( (nRelationship == D_FR || nRelationship == D_NU || nRelationship == D_LI) ) { // hit something we don't want to hurt, so turn around. Vector vecVel = GetAbsVelocity(); VectorNormalize( vecVel ); vecVel.x *= -1; vecVel.y *= -1; SetAbsOrigin( GetAbsOrigin() + vecVel * 4 ); // bounce the hornet off a bit. SetAbsVelocity( vecVel * m_flFlySpeed ); return; } DieTouch( pOther ); }
//--------------------------------------------------------- //--------------------------------------------------------- void CBaseSpriteProjectile::Spawn( char *pszModel, const Vector &vecOrigin, const Vector &vecVelocity, edict_t *pOwner, MoveType_t iMovetype, MoveCollide_t nMoveCollide, int iDamage, int iDamageType, CBaseEntity *pIntendedTarget ) { Precache(); SetSolid( SOLID_BBOX ); SetModel( pszModel ); UTIL_SetSize( this, vec3_origin, vec3_origin ); m_iDmg = iDamage; m_iDmgType = iDamageType; SetMoveType( iMovetype, nMoveCollide ); UTIL_SetOrigin( this, vecOrigin ); SetAbsVelocity( vecVelocity ); SetOwnerEntity( Instance( pOwner ) ); m_hIntendedTarget.Set( pIntendedTarget ); // Call think for free the first time. It's up to derived classes to rethink. SetNextThink( gpGlobals->curtime ); }
//----------------------------------------------------------------------------- // 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 CShower::Spawn( void ) { Vector vecForward; AngleVectors( GetLocalAngles(), &vecForward ); Vector vecNewVelocity; vecNewVelocity = random->RandomFloat( 200, 300 ) * vecForward; vecNewVelocity.x += random->RandomFloat(-100.f,100.f); vecNewVelocity.y += random->RandomFloat(-100.f,100.f); if ( vecNewVelocity.z >= 0 ) vecNewVelocity.z += 200; else vecNewVelocity.z -= 200; SetAbsVelocity( vecNewVelocity ); SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE ); SetGravity( UTIL_ScaleForGravity( 400 ) ); // fall a bit more slowly than normal SetNextThink( gpGlobals->curtime + 0.1f ); SetSolid( SOLID_NONE ); UTIL_SetSize(this, vec3_origin, vec3_origin ); AddEffects( EF_NODRAW ); m_flSpeed = random->RandomFloat( 0.5, 1.5 ); SetLocalAngles( vec3_angle ); }
void CBaseGrenadeConcussion::FallThink(void) { if (!IsInWorld()) { Remove( ); return; } CSoundEnt::InsertSound ( SOUND_DANGER, GetAbsOrigin() + GetAbsVelocity() * 0.5, GetAbsVelocity().Length( ), 0.2 ); SetNextThink( gpGlobals->curtime + random->RandomFloat(0.05, 0.1) ); if (GetWaterLevel() != 0) { SetAbsVelocity( GetAbsVelocity() * 0.5 ); } Vector pos = GetAbsOrigin() + Vector(random->RandomFloat(-4, 4), random->RandomFloat(-4, 4), random->RandomFloat(-4, 4)); CPVSFilter filter( GetAbsOrigin() ); te->Sprite( filter, 0.0, &pos, m_nTrailSprite, random->RandomFloat(0.5, 0.8), 200 ); }
// This limits the player's speed in the start zone, depending on which gamemode the player is currently playing. // On surf/other, it only limits practice mode speed. On bhop/scroll, it limits the movement speed above a certain // threshhold, and clamps the player's velocity if they go above it. // This is to prevent prespeeding and is different per gamemode due to the different respective playstyles of surf and bhop. // MOM_TODO: Update this to extend to start zones of stages (if doing ILs) void CMomentumPlayer::LimitSpeedInStartZone() { ConVarRef gm("mom_gamemode"); CTriggerTimerStart *startTrigger = g_Timer->GetStartTrigger(); bool bhopGameMode = (gm.GetInt() == MOMGM_BHOP || gm.GetInt() == MOMGM_SCROLL); if (m_RunData.m_bIsInZone && m_RunData.m_iCurrentZone == 1) { if (GetGroundEntity() == nullptr && !m_bHasPracticeMode) // don't count ticks in air if we're in practice mode m_nTicksInAir++; else m_nTicksInAir = 0; // set bhop flag to true so we can't prespeed with practice mode if (m_bHasPracticeMode) m_bDidPlayerBhop = true; // depending on gamemode, limit speed outright when player exceeds punish vel if (bhopGameMode && ((!g_Timer->IsRunning() && m_nTicksInAir > MAX_AIRTIME_TICKS))) { Vector velocity = GetLocalVelocity(); float PunishVelSquared = startTrigger->GetPunishSpeed() * startTrigger->GetPunishSpeed(); if (velocity.Length2DSqr() > PunishVelSquared) // more efficent to check agaisnt the square of velocity { velocity = (velocity / velocity.Length()) * startTrigger->GetPunishSpeed(); SetAbsVelocity(Vector(velocity.x, velocity.y, velocity.z)); } } } SetNextThink(gpGlobals->curtime, "CURTIME_FOR_START"); }
//----------------------------------------------------------------------------- // 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(); }
//----------------------------------------------------------------------------- // Purpose: Drop/throw the weapon with the given velocity. //----------------------------------------------------------------------------- void CASW_Weapon::Drop( const Vector &vecVelocity ) { StopAnimation(); StopFollowingEntity( ); SetMoveType( MOVETYPE_FLYGRAVITY ); // clear follow stuff, setup for collision SetGravity(1.0); m_iState = WEAPON_NOT_CARRIED; RemoveEffects( EF_NODRAW ); FallInit(); SetGroundEntity( NULL ); SetTouch(NULL); IPhysicsObject *pObj = VPhysicsGetObject(); if ( pObj != NULL ) { AngularImpulse angImp( 200, 200, 200 ); pObj->AddVelocity( &vecVelocity, &angImp ); } else { SetAbsVelocity( vecVelocity ); } SetNextThink( gpGlobals->curtime + 1.0f ); SetOwnerEntity( NULL ); SetOwner( NULL ); SetModel( GetWorldModel() ); }
//----------------------------------------------------------------------------- // 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 ); } }
void CASW_Mine::MineTouch( CBaseEntity *pOther ) { Assert( pOther ); if (pOther->entindex() != 0 && asw_debug_mine.GetBool()) Msg("Touched by %s\n", pOther->GetClassname()); if (!m_bMineTriggered && m_bPrimed) { // if other is an alien, trigger the mine if (ValidMineTarget(pOther)) { // Ensure clear path to the target trace_t tr; UTIL_TraceLine( GetAbsOrigin(), pOther->WorldSpaceCenter(), MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction >= 1.0f || tr.m_pEnt == pOther ) { if (asw_debug_mine.GetBool()) Msg("Mine triggered!\n"); m_bMineTriggered = true; EmitSound("ASW_Mine.Flash"); SetNextThink( gpGlobals->curtime + ASW_MINE_EXPLODE_TIME ); } } } // Slow down Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity.x *= 0.8f; vecNewVelocity.y *= 0.8f; SetAbsVelocity( vecNewVelocity ); }
//----------------------------------------------------------------------------- // Purpose: // Input : // Output : //----------------------------------------------------------------------------- void CBaseHelicopter::ApplySidewaysDrag( const Vector &vecRight ) { Vector vecNewVelocity = GetAbsVelocity(); vecNewVelocity.x *= 1.0 - fabs( vecRight.x ) * 0.05; vecNewVelocity.y *= 1.0 - fabs( vecRight.y ) * 0.05; vecNewVelocity.z *= 1.0 - fabs( vecRight.z ) * 0.05; SetAbsVelocity( vecNewVelocity ); }
//------------------------------------------------------------------------------ // Purpose : Initialize a gibs position and velocity // Input : // Output : //------------------------------------------------------------------------------ void CGib::InitGib( CBaseEntity *pVictim, float fMinVelocity, float fMaxVelocity ) { // ------------------------------------------------------------------------ // If have a pVictim spawn the gib somewhere in the pVictim's bounding volume // ------------------------------------------------------------------------ if ( pVictim ) { // Find a random position within the bounding box (add 1 to Z to get it out of the ground) Vector vecOrigin; pVictim->CollisionProp()->RandomPointInBounds( vec3_origin, Vector( 1, 1, 1 ), &vecOrigin ); vecOrigin.z += 1.0f; SetAbsOrigin( vecOrigin ); // make the gib fly away from the attack vector Vector vecNewVelocity = g_vecAttackDir * -1; // mix in some noise vecNewVelocity.x += random->RandomFloat ( -0.25, 0.25 ); vecNewVelocity.y += random->RandomFloat ( -0.25, 0.25 ); vecNewVelocity.z += random->RandomFloat ( -0.25, 0.25 ); vecNewVelocity *= random->RandomFloat ( fMaxVelocity, fMinVelocity ); QAngle vecNewAngularVelocity = GetLocalAngularVelocity(); vecNewAngularVelocity.x = random->RandomFloat ( 100, 200 ); vecNewAngularVelocity.y = random->RandomFloat ( 100, 300 ); SetLocalAngularVelocity( vecNewAngularVelocity ); // copy owner's blood color SetBloodColor( pVictim->BloodColor() ); AdjustVelocityBasedOnHealth( pVictim->m_iHealth, vecNewVelocity ); // Attempt to be physical if we can if ( VPhysicsInitNormal( SOLID_BBOX, 0, false ) ) { IPhysicsObject *pObj = VPhysicsGetObject(); if ( pObj != NULL ) { AngularImpulse angImpulse = RandomAngularImpulse( -500, 500 ); pObj->AddVelocity( &vecNewVelocity, &angImpulse ); } } else { SetSolid( SOLID_BBOX ); SetCollisionBounds( vec3_origin, vec3_origin ); SetAbsVelocity( vecNewVelocity ); } SetCollisionGroup( COLLISION_GROUP_DEBRIS ); } LimitVelocity(); }
void CSatchelCharge::SatchelThink( void ) { // If attached resize so player can pick up off wall if (m_bIsAttached) { UTIL_SetSize(this, Vector( -2, -2, -6), Vector(2, 2, 6)); } // See if I can lose my owner (has dropper moved out of way?) // Want do this so owner can shoot the satchel charge if (GetOwnerEntity()) { trace_t tr; Vector vUpABit = GetAbsOrigin(); vUpABit.z += 5.0; CBaseEntity* saveOwner = GetOwnerEntity(); SetOwnerEntity( NULL ); UTIL_TraceEntity( this, GetAbsOrigin(), vUpABit, MASK_SOLID, &tr ); if ( tr.startsolid || tr.fraction != 1.0 ) { SetOwnerEntity( saveOwner ); } } // Bounce movement code gets this think stuck occasionally so check if I've // succeeded in moving, otherwise kill my motions. else if ((GetAbsOrigin() - m_vLastPosition).LengthSqr()<1) { SetAbsVelocity( vec3_origin ); QAngle angVel = GetLocalAngularVelocity(); angVel.y = 0; SetLocalAngularVelocity( angVel ); // Clear think function SetThink(NULL); return; } m_vLastPosition= GetAbsOrigin(); StudioFrameAdvance( ); SetNextThink( gpGlobals->curtime + 0.1f ); if (!IsInWorld()) { UTIL_Remove( this ); return; } // Is it attached to a wall? if (m_bIsAttached) { return; } }
//----------------------------------------------------------------------------- // Purpose: Throw the grenade. // Input : vecOrigin - Starting position // vecVelocity - Starting velocity // flExplodeTime - Time at which to detonate //----------------------------------------------------------------------------- void CThrownGrenade::Thrown( Vector vecOrigin, Vector vecVelocity, float flExplodeTime ) { // Throw SetLocalOrigin( vecOrigin ); SetAbsVelocity( vecVelocity ); // Explode in 3 seconds SetThink( &CThrownGrenade::Detonate ); SetNextThink( gpGlobals->curtime + flExplodeTime ); }
void CGERocket::AccelerateThink( void ) { float lifetime = gpGlobals->curtime - m_flSpawnTime; if ( lifetime > 0.75f ) { SetAbsVelocity(m_vForward * GE_ROCKET_MAXVEL * (lifetime < 0.75f ? lifetime : 0.75f) * phys_timescale.GetFloat()); SetThink( &CGERocket::FlyThink ); SetNextThink( gpGlobals->curtime + 0.1f ); } else { float timescale = phys_timescale.GetFloat(); float lifetime = (gpGlobals->curtime - m_flSpawnTime) * timescale; Vector flypath = m_vForward * GE_ROCKET_MAXVEL * min(lifetime, 0.75) * timescale; SetAbsVelocity( flypath ); SetNextThink( gpGlobals->curtime + m_fthinktime ); } }
void CSDKPlayer::State_PreThink_DEATH_ANIM() { // If the anim is done playing, go to the next state (waiting for a keypress to // either respawn the guy or put him into observer mode). if ( GetFlags() & FL_ONGROUND ) { float flForward = GetAbsVelocity().Length() - 20; if (flForward <= 0) { SetAbsVelocity( vec3_origin ); } else { Vector vAbsVel = GetAbsVelocity(); VectorNormalize( vAbsVel ); vAbsVel *= flForward; SetAbsVelocity( vAbsVel ); } } if ( gpGlobals->curtime >= (m_flDeathTime + SDK_PLAYER_DEATH_TIME ) ) // let the death cam stay going up to min spawn time. { m_lifeState = LIFE_DEAD; StopAnimation(); AddEffects( EF_NOINTERP ); if ( GetMoveType() != MOVETYPE_NONE && (GetFlags() & FL_ONGROUND) ) SetMoveType( MOVETYPE_NONE ); } //Tony; if we're now dead, and not changing classes, spawn if ( m_lifeState == LIFE_DEAD ) { #if defined ( SDK_USE_PLAYERCLASSES ) //Tony; if the class menu is open, don't respawn them, wait till they're done. if (IsClassMenuOpen()) return; #endif State_Transition( STATE_ACTIVE ); } }
void CASW_Simple_Alien::CorpseFade() { StopAnimation(); SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_NONE ); SetLocalAngularVelocity( vec3_angle ); m_flAnimTime = gpGlobals->curtime; AddEffects( EF_NOINTERP ); SUB_StartFadeOut(); }
bool CHL1NPCTalker::HandleInteraction(int interactionType, void *data, CBaseCombatCharacter* sourceEnt) { if (interactionType == g_interactionBarnacleVictimDangle) { // Force choosing of a new schedule ClearSchedule( "NPC talker being eaten by a barnacle" ); m_bInBarnacleMouth = true; return true; } else if ( interactionType == g_interactionBarnacleVictimReleased ) { SetState ( NPC_STATE_IDLE ); CPASAttenuationFilter filter( this ); CSoundParameters params; if ( GetParametersForSound( "Barney.Close", params, NULL ) ) { EmitSound_t ep( params ); ep.m_nPitch = GetExpresser()->GetVoicePitch(); EmitSound( filter, entindex(), ep ); } m_bInBarnacleMouth = false; SetAbsVelocity( vec3_origin ); SetMoveType( MOVETYPE_STEP ); return true; } else if ( interactionType == g_interactionBarnacleVictimGrab ) { if ( GetFlags() & FL_ONGROUND ) { SetGroundEntity( NULL ); } if ( GetState() == NPC_STATE_SCRIPT ) { if ( m_hCine ) { m_hCine->CancelScript(); } } SetState( NPC_STATE_PRONE ); ClearSchedule( "NPC talker grabbed by a barnacle" ); CTakeDamageInfo info; PainSound( info ); return true; } return false; }
void CGERocket::FlyThink( void ) { if ( gpGlobals->curtime > m_fFuseTime ) { Explode(); return; } SetAbsVelocity(m_vForward * GE_ROCKET_MAXVEL * 0.75f * phys_timescale.GetFloat()); SetNextThink( gpGlobals->curtime + 0.1 ); }
void CShockBeam::BallTouch( CBaseEntity* pOther ) { if( pOther->GetTakeDamageMode() != DAMAGE_NO ) { TraceResult tr = UTIL_GetGlobalTrace(); CBaseEntity* pOwner = GetOwner(); g_MultiDamage.Clear(); int bitsDamageTypes = DMG_ALWAYSGIB | DMG_SHOCK; if( CBaseMonster* pMonster = pOther->MyMonsterPointer() ) { bitsDamageTypes = 64; if( pMonster->m_flShockDuration > 1.0 ) { bitsDamageTypes = 8192; } pMonster->AddShockEffect( 63, 152, 208, 16, 0.5 ); } pOther->TraceAttack( CTakeDamageInfo( pOwner, bIsMultiplayer() ? gSkillData.GetPlrDmgShockRoachM() : gSkillData.GetPlrDmgShockRoachS(), bitsDamageTypes ), GetAbsVelocity().Normalize(), &tr ); g_MultiDamage.ApplyMultiDamage( this, pOwner ); SetAbsVelocity( g_vecZero ); } SetThink( &CShockBeam::ExplodeThink ); SetNextThink( gpGlobals->time + 0.01 ); if( pOther->GetTakeDamageMode() == DAMAGE_NO ) { TraceResult tr; UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + GetAbsVelocity() * 10, dont_ignore_monsters, edict(), &tr ); UTIL_DecalTrace( &tr, DECAL_OFSCORCH1 + UTIL_RandomLong( 0, 2 ) ); MESSAGE_BEGIN( MSG_PAS, SVC_TEMPENTITY, GetAbsOrigin() ); WRITE_BYTE( TE_SPARKS ); WRITE_COORD_VECTOR( GetAbsOrigin() ); MESSAGE_END(); } }
//----------------------------------------------------------------------------- // Purpose: // GetLocalTime() is the objects local current time // Input : destTime - new time that is being moved to // moveTime - amount of time to be advanced this frame // Output : float - the actual amount of time to move (usually moveTime) //----------------------------------------------------------------------------- float CBaseMoveBehavior::SetObjectPhysicsVelocity( float moveTime ) { // make sure we have a valid set up if ( !m_pCurrentKeyFrame || !m_pTargetKeyFrame ) return moveTime; // if we're not moving, we're not moving if ( !IsMoving() ) return moveTime; float destTime = moveTime + GetLocalTime(); // work out where we want to be, using destTime m_flTimeIntoFrame = destTime - m_flAnimStartTime; float newTime = (destTime - m_flAnimStartTime) / (m_flAnimEndTime - m_flAnimStartTime); Vector newPos; QAngle newAngles; IPositionInterpolator *pInterp = GetPositionInterpolator( m_iPositionInterpolator ); if( pInterp ) { // setup key frames pInterp->SetKeyPosition( -1, m_pPreKeyFrame->m_Origin ); Motion_SetKeyAngles( -1, m_pPreKeyFrame->m_qAngle ); pInterp->SetKeyPosition( 0, m_pCurrentKeyFrame->m_Origin ); Motion_SetKeyAngles( 0, m_pCurrentKeyFrame->m_qAngle ); pInterp->SetKeyPosition( 1, m_pTargetKeyFrame->m_Origin ); Motion_SetKeyAngles( 1, m_pTargetKeyFrame->m_qAngle ); pInterp->SetKeyPosition( 2, m_pPostKeyFrame->m_Origin ); Motion_SetKeyAngles( 2, m_pPostKeyFrame->m_qAngle ); // find new interpolated position & rotation pInterp->InterpolatePosition( newTime, newPos ); } else { newPos.Init(); } Quaternion qRot; Motion_InterpolateRotation( newTime, m_iRotationInterpolator, qRot ); QuaternionAngles( qRot, newAngles ); // find our velocity vector (newPos - currentPos) and scale velocity vector according to the movetime float oneOnMoveTime = 1 / moveTime; SetAbsVelocity( (newPos - GetLocalOrigin()) * oneOnMoveTime ); SetLocalAngularVelocity( (newAngles - GetLocalAngles()) * oneOnMoveTime ); return moveTime; }
// Purpose: Monitor the antlion's jump to play the proper landing sequence bool CASW_Alien_Jumper::CheckLanding( void ) { trace_t tr; Vector testPos; //Amount of time to predict forward const float timeStep = 0.1f; //Roughly looks one second into the future testPos = GetAbsOrigin() + ( GetAbsVelocity() * timeStep ); testPos[2] -= ( 0.5 * sv_gravity.GetFloat() * GetGravity() * timeStep * timeStep); if ( asw_debug_aliens.GetInt() == 2 ) { NDebugOverlay::Line( GetAbsOrigin(), testPos, 255, 0, 0, 0, 0.5f ); NDebugOverlay::Cross3D( m_vecSavedJump, -Vector(2,2,2), Vector(2,2,2), 0, 255, 0, true, 0.5f ); } // Look below AI_TraceHull( GetAbsOrigin(), testPos, NAI_Hull::Mins( GetHullType() ), NAI_Hull::Maxs( GetHullType() ), MASK_NPCSOLID, this, COLLISION_GROUP_NONE, &tr ); //See if we're about to contact, or have already contacted the ground if ( ( tr.fraction != 1.0f ) || ( GetFlags() & FL_ONGROUND ) ) { int sequence = SelectWeightedSequence( (Activity)ACT_ASW_ALIEN_LAND ); if ( GetSequence() != sequence ) { VacateStrategySlot(); SetIdealActivity( (Activity) ACT_ASW_ALIEN_LAND ); CreateDust( false ); EmitSound( "ASW_Drone.Land" ); // asw todo: make the alien attack here? //if ( GetEnemy() && GetEnemy()->IsPlayer() ) //{ //CBasePlayer *pPlayer = ToBasePlayer( GetEnemy() ); //if ( pPlayer && pPlayer->IsInAVehicle() == false ) //MeleeAttack( ANTLION_MELEE1_RANGE, sk_antlion_swipe_damage.GetFloat(), QAngle( 4.0f, 0.0f, 0.0f ), Vector( -250.0f, 1.0f, 1.0f ) ); //} SetAbsVelocity( GetAbsVelocity() * 0.33f ); return false; } return IsActivityFinished(); } return false; }
//----------------------------------------------------------------------------- // Purpose: Handles movement towards the last move target. // Input : flInterval - //----------------------------------------------------------------------------- bool CNPC_Controller::OverridePathMove( float flInterval ) { CBaseEntity *pMoveTarget = (GetTarget()) ? GetTarget() : GetEnemy(); Vector waypointDir = GetNavigator()->GetCurWaypointPos() - GetLocalOrigin(); float flWaypointDist = waypointDir.Length2D(); VectorNormalize(waypointDir); // cut corner? if (flWaypointDist < 128) { if (m_flGroundSpeed > 100) m_flGroundSpeed -= 40; } else { if (m_flGroundSpeed < 400) m_flGroundSpeed += 10; } m_velocity = m_velocity * 0.8 + m_flGroundSpeed * waypointDir * 0.5; SetAbsVelocity( m_velocity ); // ----------------------------------------------------------------- // Check route is blocked // ------------------------------------------------------------------ Vector checkPos = GetLocalOrigin() + (waypointDir * (m_flGroundSpeed * flInterval)); AIMoveTrace_t moveTrace; GetMoveProbe()->MoveLimit( NAV_FLY, GetLocalOrigin(), checkPos, MASK_NPCSOLID|CONTENTS_WATER, pMoveTarget, &moveTrace); if (IsMoveBlocked( moveTrace )) { TaskFail(FAIL_NO_ROUTE); GetNavigator()->ClearGoal(); return true; } // ---------------------------------------------- Vector lastPatrolDir = GetNavigator()->GetCurWaypointPos() - GetLocalOrigin(); if ( ProgressFlyPath( flInterval, pMoveTarget, MASK_NPCSOLID, false, 64 ) == AINPP_COMPLETE ) { { m_vLastPatrolDir = lastPatrolDir; VectorNormalize(m_vLastPatrolDir); } return true; } return false; }
// HACKHACK -- The gib velocity equations don't work void CGib::LimitVelocity( void ) { Vector vecNewVelocity = GetAbsVelocity(); float length = VectorNormalize( vecNewVelocity ); // ceiling at 1500. The gib velocity equation is not bounded properly. Rather than tune it // in 3 separate places again, I'll just limit it here. if ( length > 1500.0 ) { vecNewVelocity *= 1500; // This should really be sv_maxvelocity * 0.75 or something SetAbsVelocity( vecNewVelocity ); } }
//------------------------------------------------------------------------------ // Purpose : // Input : // Output : //------------------------------------------------------------------------------ void CGrenadePathfollower::Launch( float flLaunchSpeed, string_t sPathCornerName) { m_pPathTarget = gEntList.FindEntityByName( NULL, sPathCornerName ); if (m_pPathTarget) { m_flFlySpeed = flLaunchSpeed; Vector vTargetDir = (m_pPathTarget->GetAbsOrigin() - GetAbsOrigin()); VectorNormalize(vTargetDir); SetAbsVelocity( m_flFlySpeed * vTargetDir ); QAngle angles; VectorAngles( GetAbsVelocity(), angles ); SetLocalAngles( angles ); } else { Warning( "ERROR: Grenade_Pathfollower (%s) with no pathcorner!\n",GetDebugName()); return; } // Make this thing come to life RemoveSolidFlags( FSOLID_NOT_SOLID ); SetMoveType( MOVETYPE_FLYGRAVITY ); RemoveEffects( EF_NODRAW ); SetUse( &CGrenadePathfollower::DetonateUse ); SetTouch( &CGrenadePathfollower::GrenadeTouch ); SetThink( &CGrenadePathfollower::AimThink ); SetNextThink( gpGlobals->curtime + 0.1f ); // Make the trail m_hRocketTrail = RocketTrail::CreateRocketTrail(); if ( m_hRocketTrail ) { m_hRocketTrail->m_Opacity = 0.2f; m_hRocketTrail->m_SpawnRate = 100; m_hRocketTrail->m_ParticleLifetime = 0.5f; m_hRocketTrail->m_StartColor.Init( 0.65f, 0.65f , 0.65f ); m_hRocketTrail->m_EndColor.Init( 0.0, 0.0, 0.0 ); m_hRocketTrail->m_StartSize = 8; m_hRocketTrail->m_EndSize = 16; m_hRocketTrail->m_SpawnRadius = 4; m_hRocketTrail->m_MinSpeed = 2; m_hRocketTrail->m_MaxSpeed = 16; m_hRocketTrail->SetLifetime( 999 ); m_hRocketTrail->FollowEntity( this, "0" ); } }
//--------------------------------------------------------- //--------------------------------------------------------- void CRopeAnchor::FallThink() { SetMoveType( MOVETYPE_FLYGRAVITY ); Vector vecVelocity = GetAbsVelocity(); vecVelocity.x = random->RandomFloat( -30.0f, 30.0f ); vecVelocity.y = random->RandomFloat( -30.0f, 30.0f ); SetAbsVelocity( vecVelocity ); SetThink( &CRopeAnchor::RemoveThink ); SetNextThink( gpGlobals->curtime + 3.0 ); }
//----------------------------------------------------------------------------- // Purpose: Explode // Input : // Output : //----------------------------------------------------------------------------- void CPlayer_Missile::ExplodeThink() { SetAbsVelocity( m_vBounceVel ); color32 black = {0,0,0,255}; CHL2_Player* pPlayer = (CHL2_Player*)UTIL_PlayerByIndex( 1 ); Assert( pPlayer ); UTIL_ScreenFade( pPlayer, black, 2.0, 0.1, FFADE_OUT ); SetThink(RemoveThink); SetNextThink( gpGlobals->curtime + PMISSILE_DIE_TIME ); }
void CASW_Flamer_Projectile::PhysicsSimulate() { // Make sure not to simulate this guy twice per frame if (m_nSimulationTick == gpGlobals->tickcount) return; // slow down the projectile's velocity Vector dir = GetAbsVelocity(); VectorNormalize(dir); SetAbsVelocity(GetAbsVelocity() - (dir * gpGlobals->frametime * ASW_FLAMER_PROJECTILE_ACCN)); dir = GetAbsVelocity(); BaseClass::PhysicsSimulate(); }
//----------------------------------------------------------------------------- bool C_LowViolenceHostageDeathModel::SetupLowViolenceModel( C_CHostage *pHostage ) { const model_t *model = pHostage->GetModel(); const char *pModelName = modelinfo->GetModelName( model ); if ( InitializeAsClientEntity( pModelName, RENDER_GROUP_OPAQUE_ENTITY ) == false ) { Release(); return false; } // Play the low-violence death anim if ( LookupSequence( "death1" ) == -1 ) { Release(); return false; } m_flFadeOutStart = gpGlobals->curtime + 5.0f; SetNextClientThink( CLIENT_THINK_ALWAYS ); SetSequence( LookupSequence( "death1" ) ); ForceClientSideAnimationOn(); if ( pHostage && !pHostage->IsDormant() ) { SetNetworkOrigin( pHostage->GetAbsOrigin() ); SetAbsOrigin( pHostage->GetAbsOrigin() ); SetAbsVelocity( pHostage->GetAbsVelocity() ); // move my current model instance to the ragdoll's so decals are preserved. pHostage->SnatchModelInstance( this ); SetAbsAngles( pHostage->GetRenderAngles() ); SetNetworkAngles( pHostage->GetRenderAngles() ); CStudioHdr *pStudioHdr = GetModelPtr(); // update pose parameters float poseParameter[MAXSTUDIOPOSEPARAM]; GetPoseParameters( pStudioHdr, poseParameter ); for ( int i=0; i<NumInterestingPoseParameters; ++i ) { int poseParameterIndex = LookupPoseParameter( pStudioHdr, InterestingPoseParameters[i] ); SetPoseParameter( pStudioHdr, poseParameterIndex, poseParameter[poseParameterIndex] ); } } Interp_Reset( GetVarMapping() ); return true; }
void CShower::Touch( CBaseEntity *pOther ) { Vector vecNewVelocity = GetAbsVelocity(); if ( GetFlags() & FL_ONGROUND ) vecNewVelocity *= 0.1; else vecNewVelocity *= 0.6; if ( (vecNewVelocity.x*vecNewVelocity.x+vecNewVelocity.y*vecNewVelocity.y) < 10.0 ) m_flSpeed = 0; SetAbsVelocity( vecNewVelocity ); }