//----------------------------------------------------------------------------- // Purpose: Attaches the flame to an entity and moves with it // Input : pTarget - target entity to attach to //----------------------------------------------------------------------------- void CEntityDissolve::AttachToEntity( CBaseEntity *pTarget ) { // So our dissolver follows the entity around on the server. SetParent( pTarget ); SetLocalOrigin( vec3_origin ); SetLocalAngles( vec3_angle ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPlayer_Missile::InputActivate( inputdata_t &inputdata ) { // Make sure not already active if (m_bActive) { return; } BaseClass::InputActivate( inputdata ); Vector origin = GetLocalOrigin(); origin.z += 50; SetLocalOrigin( origin ); RemoveSolidFlags( FSOLID_NOT_SOLID ); Relink(); // Using player angles to determine turning. Initailze to 0,0,0 CHL2_Player* pPlayer = (CHL2_Player*)UTIL_PlayerByIndex( 1 ); Assert( pPlayer ); pPlayer->SetLocalAngles( vec3_angle ); // Note: Set GetLocalAngles(), not pl.v_angle pPlayer->SnapEyeAngles( vec3_angle ); // Force reset pPlayer->SetFOV( 100 ); engine->SetView( pPlayer->edict(), edict() ); m_flStatic = 0; SetThink(Launch); SetNextThink( gpGlobals->curtime + m_flLaunchDelay ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_BaseObject::Simulate( void ) { if ( IsPlacing() && !MustBeBuiltOnAttachmentPoint() ) { int iValidPlacement = ( IsPlacementPosValid() && ServerValidPlacement() ) ? 1 : 0; if ( m_iLastPlacementPosValid != iValidPlacement ) { m_iLastPlacementPosValid = iValidPlacement; OnPlacementStateChanged( m_iLastPlacementPosValid > 0 ); } // We figure out our own placement pos, but we still leave it to the server to // do collision with other entities and nobuild triggers, so that sets the // placement animation SetLocalOrigin( m_vecBuildOrigin ); InvalidateBoneCache(); // Clear out our origin and rotation interpolation history // so we don't pop when we teleport in the actual position from the server CInterpolatedVar< Vector > &interpolator = GetOriginInterpolator(); interpolator.ClearHistory(); CInterpolatedVar<QAngle> &rotInterpolator = GetRotationInterpolator(); rotInterpolator.ClearHistory(); } BaseClass::Simulate(); }
AIMoveResult_t CAI_Motor::MoveClimbExecute( const Vector &climbDest, float yaw) { const float climbSpeed = 100.0; Vector moveDir = climbDest - GetLocalOrigin(); float flDist = VectorNormalize( moveDir ); SetSmoothedVelocity( moveDir * climbSpeed ); if ( flDist < climbSpeed * GetMoveInterval() ) { if (flDist <= 1e-2) flDist = 0; const float climbTime = flDist / climbSpeed; SetMoveInterval( GetMoveInterval() - climbTime ); SetLocalOrigin( climbDest ); return AIMR_CHANGE_TYPE; } else { SetMoveInterval( 0 ); } // -------------------------------------------- // Turn to face the climb // -------------------------------------------- SetIdealYawAndUpdate( yaw ); return AIMR_OK; }
//==================================================================== // Solicita al Director un lugar para la creación //==================================================================== void CAP_PlayerInfected::RequestDirectorSpawn() { Vector vecSpawnPosition; // Le preguntamos al Administrador sobre un lugar para aparecer DirectorManager->Update(); bool result = DirectorManager->GetSpawnLocation( &vecSpawnPosition, DIRECTOR_CHILD ); // El Director te quiere aquí if ( result && DirectorManager->PostSpawn(this) ) { // Establecemos la ubicación SetLocalOrigin( vecSpawnPosition + Vector(0, 0, 5) ); SetAbsVelocity( vec3_origin ); m_Local.m_vecPunchAngle = vec3_angle; m_Local.m_vecPunchAngleVel = vec3_angle; // Ahora somos visibles RemoveEffects( EF_NODRAW ); RemoveFlag( FL_FREEZING ); SetCollisionGroup( COLLISION_GROUP_PLAYER ); m_takedamage = DAMAGE_YES; // No volvemos a pensar SetNextThink( TICK_NEVER_THINK, "RequestDirectorSpawn" ); return; } // Volvemos a intentarlo en .3s SetNextThink( gpGlobals->curtime + .3, "RequestDirectorSpawn" ); }
void CGEBloodScreenVM::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles ) { #if defined( CLIENT_DLL ) SetLocalOrigin( eyePosition ); SetLocalAngles( eyeAngles ); #endif }
void CBaseViewModel::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles ) { // UNDONE: Calc this on the server? Disabled for now as it seems unnecessary to have this info on the server #if defined( CLIENT_DLL ) QAngle vmangoriginal = eyeAngles; QAngle vmangles = eyeAngles; Vector vmorigin = eyePosition; Vector vecRight; Vector vecUp; Vector vecForward; AngleVectors( vmangoriginal, &vecForward, &vecRight, &vecUp ); //Vector vecOffset = Vector( viewmodel_offset_x.GetFloat(), viewmodel_offset_y.GetFloat(), viewmodel_offset_z.GetFloat() ); vmorigin += (vecForward * viewmodel_offset_y.GetFloat()) + (vecUp * viewmodel_offset_z.GetFloat()) + (vecRight * viewmodel_offset_x.GetFloat()); // TrackIR if ( IsHeadTrackingEnabled() ) { vmorigin = owner->EyePosition(); VectorAngles( owner->GetAutoaimVector( AUTOAIM_5DEGREES ), vmangoriginal ); vmangles = vmangoriginal; } // TrackIR CBaseCombatWeapon *pWeapon = m_hWeapon.Get(); //Allow weapon lagging if ( pWeapon != NULL ) { #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) #endif { // add weapon-specific bob pWeapon->AddViewmodelBob( this, vmorigin, vmangles ); } } // Add model-specific bob even if no weapon associated (for head bob for off hand models) AddViewModelBob( owner, vmorigin, vmangles ); // Add lag CalcViewModelLag( vmorigin, vmangles, vmangoriginal ); #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) { // Let the viewmodel shake at about 10% of the amplitude of the player's view ACTIVE_SPLITSCREEN_PLAYER_GUARD_ENT( GetOwner() ); GetViewEffects()->ApplyShake( vmorigin, vmangles, 0.1 ); } #endif CalcIronsights( vmorigin, vmangles ); SetLocalOrigin( vmorigin ); SetLocalAngles( vmangles ); #endif }
//----------------------------------------------------------------------------- // 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 CWeaponTFCBase::Spawn() { BaseClass::Spawn(); // Set this here to allow players to shoot dropped weapons SetCollisionGroup( COLLISION_GROUP_WEAPON ); // Move it up a little bit, otherwise it'll be at the guy's feet, and its sound origin // will be in the ground so its EmitSound calls won't do anything. SetLocalOrigin( Vector( 0, 0, 5 ) ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- int C_ObjectSentrygun::DrawModel( int flags ) { float flRealOriginZ = GetLocalOrigin().z; // If we're turtling, slide the model into the ground if ( m_bTurtled ) { // How far down are we? float flTime = min( gpGlobals->curtime - m_flStartedTurtlingAt, SENTRY_TURTLE_TIME ); float flPercent = 1 - (SENTRY_TURTLE_TIME - flTime) / SENTRY_TURTLE_TIME; Vector vNewOrigin = GetLocalOrigin(); vNewOrigin.z -= (EntitySpaceSize().z * flPercent); SetLocalOrigin( vNewOrigin ); InvalidateBoneCache(); } else if ( !m_bTurtled ) { if ( m_flStartedUnTurtlingAt ) { float flTime = min( gpGlobals->curtime - m_flStartedUnTurtlingAt, SENTRY_TURTLE_TIME ); float flPercent = (SENTRY_TURTLE_TIME - flTime) / SENTRY_TURTLE_TIME; Vector vNewOrigin = GetLocalOrigin(); vNewOrigin.z -= (EntitySpaceSize().z * flPercent); SetLocalOrigin( vNewOrigin ); InvalidateBoneCache(); // Fully unturtled? if ( flTime >= SENTRY_TURTLE_TIME ) { m_flStartedUnTurtlingAt = 0; } } } int drawn = BaseClass::DrawModel( flags ); SetLocalOriginDim( Z_INDEX, flRealOriginZ ); return drawn; }
void CASW_Parasite::InfestColonist(CASW_Colonist* pColonist) { if (m_bDefanged || !pColonist) // no infesting if we've been defanged return; if (!IsOnFire()) // don't actually infest if we're on fire, since we'll die very shortly pColonist->BecomeInfested(this); // attach int attachment = pColonist->LookupAttachment( "chest" ); if ( attachment ) { //SetAbsAngles( GetOwnerEntity()->GetAbsAngles() ); SetSolid( SOLID_NONE ); SetMoveType( MOVETYPE_NONE ); QAngle current(0,0,0); Vector diff = pColonist->GetAbsOrigin() - GetAbsOrigin(); float angle = UTIL_VecToYaw(diff); angle -= pColonist->GetAbsAngles()[YAW]; // get the diff between our angle from the marine and the marine's facing; current = GetAbsAngles(); SetParent( pColonist, attachment ); Vector vecPosition; float fRaise = random->RandomFloat(0,20); SetLocalOrigin( Vector( -fRaise * 0.2f, 0, fRaise ) ); SetLocalAngles( QAngle( 0, angle + asw_infest_angle.GetFloat(), 0 ) ); // play our infesting anim if ( asw_parasite_inside.GetBool() ) { SetActivity(ACT_RANGE_ATTACK2); } else { int iInfestAttack = LookupSequence("Infest_attack"); if (GetSequence() != iInfestAttack) { ResetSequence(iInfestAttack); } } // don't do anymore thinking - need to think still to animate? AddFlag( FL_NOTARGET ); SetThink( &CASW_Parasite::InfestThink ); SetTouch( NULL ); m_bInfesting = true; } else { FinishedInfesting(); } }
void CWorld::Spawn( void ) { SetLocalOrigin( vec3_origin ); SetLocalAngles( vec3_angle ); // NOTE: SHOULD NEVER BE ANYTHING OTHER THAN 1!!! SetModelIndex( 1 ); // world model SetModelName( MAKE_STRING( modelinfo->GetModelName( GetModel() ) ) ); AddFlag( FL_WORLDBRUSH ); g_EventQueue.Init(); Precache( ); }
void C_Ball::ClientThink() { if (m_pHoldingPlayer) { Vector handPos; QAngle handAng; m_pHoldingPlayer->GetAttachment("ball_right_hand", handPos, handAng); SetLocalOrigin(handPos); SetLocalAngles(handAng); } SetNextClientThink(CLIENT_THINK_ALWAYS); }
void CWorld::Spawn( void ) { SetLocalOrigin( vec3_origin ); SetLocalAngles( vec3_angle ); // NOTE: SHOULD NEVER BE ANYTHING OTHER THAN 1!!! SetModelIndex( 1 ); // world model SetModelName( AllocPooledString( modelinfo->GetModelName( GetModel() ) ) ); AddFlag( FL_WORLDBRUSH ); g_EventQueue.Init(); Precache( ); GlobalEntity_Add( "is_console", STRING(gpGlobals->mapname), ( IsConsole() ) ? GLOBAL_ON : GLOBAL_OFF ); GlobalEntity_Add( "is_pc", STRING(gpGlobals->mapname), ( !IsConsole() ) ? GLOBAL_ON : GLOBAL_OFF ); }
//Handle all necessary movement stuffs void CDHLProjectile::MoveProjectileToPosition( Vector& vecPos ) { #ifdef CLIENT_DLL SetLocalOrigin( vecPos ); //This is VERY important - C_BaseEntity::PostDataUpdate calls MoveToLastReceivedPosition which forces the origin and angles to their "network" values //Result is that if we don't set them here there will be painful hitching in real world situations (with lag). SetNetworkOrigin( vecPos ); if ( m_pTrail ) m_pTrail->SetAbsOrigin( vecPos ); //m_pTrail->m_vecPosition = vecPos; #else m_vecCurPosition = vecPos; #endif }
void CSPCharacter::StandOnNearestPlanet() { CPlanet* pPlanet = GetNearestPlanet(FINDPLANET_ANY); if (!pPlanet) return; CScalableVector vecPlanetOrigin = pPlanet->GetGlobalOrigin(); CScalableVector vecCharacterOrigin = GetGlobalOrigin(); CScalableVector vecCharacterDirection = (vecCharacterOrigin - vecPlanetOrigin).Normalized(); SetMoveParent(pPlanet); TVector vecPoint, vecNormal; pPlanet->CollideLocal(vecCharacterDirection * (pPlanet->GetRadius()*2.0f), TVector(), vecPoint, vecNormal); SetLocalOrigin(vecPoint); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPlayer_Missile::ControlDeactivate( void ) { BaseClass::ControlDeactivate(); CHL2_Player* pPlayer = (CHL2_Player*)UTIL_PlayerByIndex( 1 ); Assert( pPlayer ); engine->SetView( pPlayer->edict(), pPlayer->edict() ); pPlayer->m_Local.m_iHideHUD &= ~HIDEHUD_WEAPONS; SetAbsVelocity( vec3_origin ); SetLocalAngles( m_vSpawnAng ); SetLocalOrigin( m_vSpawnPos ); m_fEffects |= EF_NODRAW; Relink(); }
void CBaseViewModel::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles ) { // UNDONE: Calc this on the server? Disabled for now as it seems unnecessary to have this info on the server #if defined( CLIENT_DLL ) QAngle vmangoriginal = eyeAngles; QAngle vmangles = eyeAngles; Vector vmorigin = eyePosition; //We are using the weapon model's animation to make view bobbing CBaseCombatWeapon *pWeapon = m_hWeapon.Get(); //Allow weapon lagging if ( pWeapon != NULL ) { #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) #endif { // add weapon-specific bob // pWeapon->AddViewmodelBob( this, vmorigin, vmangles ); } } // Add model-specific bob even if no weapon associated (for head bob for off hand models) // AddViewModelBob( owner, vmorigin, vmangles ); // Add lag // CalcViewModelLag( vmorigin, vmangles, vmangoriginal ); #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) { // Let the viewmodel shake at about 10% of the amplitude of the player's view vieweffects->ApplyShake( vmorigin, vmangles, 0.1 ); } #endif CalcIronsights( vmorigin, vmangles ); CalcLeg( vmorigin, vmangles ); // CalcLimitAim( vmorigin, vmangles ); SetLocalOrigin( vmorigin ); SetLocalAngles( vmangles ); #endif }
void CBaseViewModel::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles ) { // UNDONE: Calc this on the server? Disabled for now as it seems unnecessary to have this info on the server #if defined( CLIENT_DLL ) QAngle vmangoriginal = eyeAngles; QAngle vmangles = eyeAngles; Vector vmorigin = eyePosition; CBaseCombatWeapon *pWeapon = m_hWeapon.Get(); //Allow weapon lagging //if ( pWeapon != NULL ) if( pWeapon != NULL && !pWeapon->IsIronsighted() ) // { #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) #endif { // add weapon-specific bob pWeapon->AddViewmodelBob( this, vmorigin, vmangles ); } } // Add model-specific bob even if no weapon associated (for head bob for off hand models) AddViewModelBob( owner, vmorigin, vmangles ); //So this is the function that does the model movement when you move around. // Add lag CalcViewModelLag( vmorigin, vmangles, vmangoriginal ); #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) { // Let the viewmodel shake at about 10% of the amplitude of the player's view vieweffects->ApplyShake( vmorigin, vmangles, 0.1 ); } #endif CalcIronsights( vmorigin, vmangles ); //BG2 -Added for Iron Sights Testing. Credits to Jorg for the code. -HairyPotter SetLocalOrigin( Vector( vmorigin.x, vmorigin.y, vmorigin.z ) ); SetLocalAngles( vmangles ); #endif }
/* ============ hhPhysics_StaticWeapon::Evaluate ============ */ bool hhPhysics_StaticWeapon::Evaluate( int timeStepMSec, int endTimeMSec ) { if( !selfOwner ) { return false; } idMat3 localAxis; idVec3 localOrigin( 0.0f, 0.0f, selfOwner->EyeHeight() ); idAngles pitchAngles( selfOwner->GetUntransformedViewAngles().pitch, 0.0f, 0.0f ); if( selfOwner->InVehicle() ) { localAxis = pitchAngles.ToMat3(); } else { localAxis = ( pitchAngles + selfOwner->GunTurningOffset() ).ToMat3(); localOrigin += selfOwner->GunAcceleratingOffset(); if ( castSelf ) { castSelf->MuzzleRise( localOrigin, localAxis ); } } SetLocalAxis( localAxis ); SetLocalOrigin( localOrigin ); return idPhysics_Static::Evaluate( timeStepMSec, endTimeMSec ); }
void CHL1BaseGrenade::Explode( trace_t *pTrace, int bitsDamageType ) { float flRndSound;// sound randomizer SetModelName( NULL_STRING );//invisible AddSolidFlags( FSOLID_NOT_SOLID ); m_takedamage = DAMAGE_NO; // Pull out of the wall a bit if ( pTrace->fraction != 1.0 ) { SetLocalOrigin( pTrace->endpos + (pTrace->plane.normal * 0.6) ); } UTIL_Relink( this ); Vector vecAbsOrigin = GetAbsOrigin(); int contents = UTIL_PointContents ( vecAbsOrigin ); if ( pTrace->fraction != 1.0 ) { Vector vecNormal = pTrace->plane.normal; surfacedata_t *pdata = physprops->GetSurfaceData( pTrace->surface.surfaceProps ); CPASFilter filter( vecAbsOrigin ); te->Explosion( filter, 0.0, &vecAbsOrigin, !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion, m_DmgRadius * .03, 25, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage, &vecNormal, (char) pdata->gameMaterial ); } else { CPASFilter filter( vecAbsOrigin ); te->Explosion( filter, 0.0, &vecAbsOrigin, !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion, m_DmgRadius * .03, 25, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage ); } CSoundEnt::InsertSound ( SOUND_COMBAT, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 ); // Use the owner's position as the reported position Vector vecReported = GetOwner() ? GetOwner()->GetAbsOrigin() : vec3_origin; CTakeDamageInfo info( this, GetOwner(), GetBlastForce(), GetAbsOrigin(), m_flDamage, bitsDamageType, 0, &vecReported ); RadiusDamage( info, GetAbsOrigin(), m_DmgRadius, CLASS_NONE ); UTIL_DecalTrace( pTrace, "Scorch" ); flRndSound = random->RandomFloat( 0 , 1 ); EmitSound( "BaseGrenade.Explode" ); SetTouch( NULL ); m_fEffects |= EF_NODRAW; SetAbsVelocity( vec3_origin ); SetThink( Smoke ); SetNextThink( gpGlobals->curtime + 0.3); if ( GetWaterLevel() == 0 ) { int sparkCount = random->RandomInt( 0,3 ); QAngle angles; VectorAngles( pTrace->plane.normal, angles ); for ( int i = 0; i < sparkCount; i++ ) Create( "spark_shower", GetAbsOrigin(), angles, NULL ); } }
void CASW_Sentry_Top::SetSentryBase(CASW_Sentry_Base* pSentryBase) { m_hSentryBase = pSentryBase; SetParent(pSentryBase); SetLocalOrigin(vec3_origin); }
//----------------------------------------------------------------------------- // Purpose: // Input : *pSpriteName - // &origin - //----------------------------------------------------------------------------- void CSprite::SpriteInit( const char *pSpriteName, const Vector &origin ) { SetModelName( MAKE_STRING(pSpriteName) ); SetLocalOrigin( origin ); Spawn(); }
//----------------------------------------------------------------------------- // Purpose: // Input : flInterval - // - // *pTraceResult - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CAI_BaseNPC::AutoMovement( float flInterval, CBaseEntity *pTarget, AIMoveTrace_t *pTraceResult ) { bool ignored; Vector newPos; QAngle newAngles; if (flInterval <= 0.0) return true; m_ScheduleState.bTaskRanAutomovement = true; if (GetIntervalMovement( flInterval, ignored, newPos, newAngles )) { // DevMsg( "%.2f : (%.1f) %.1f %.1f %.1f\n", gpGlobals->curtime, (newPos - GetLocalOrigin()).Length(), newPos.x, newPos.y, newAngles.y ); if ( m_hCine ) { m_hCine->ModifyScriptedAutoMovement( &newPos ); } if (GetMoveType() == MOVETYPE_STEP) { if (!(GetFlags() & FL_FLY)) { if ( !pTarget ) { pTarget = GetNavTargetEntity(); } // allow NPCs to adjust the automatic movement if ( ModifyAutoMovement( newPos ) ) { // Set our motor's speed here Vector vecOriginalPosition = GetAbsOrigin(); bool bResult = false; if (!TaskIsComplete()) { bResult = ( GetMotor()->MoveGroundStep( newPos, pTarget, newAngles.y, false, true, pTraceResult ) == AIM_SUCCESS ); } Vector change = GetAbsOrigin() - vecOriginalPosition; if (flInterval != 0) { change /= flInterval; } GetMotor()->SetMoveVel(change); return bResult; } return ( GetMotor()->MoveGroundStep( newPos, pTarget, newAngles.y, false, true, pTraceResult ) == AIM_SUCCESS ); } else { // FIXME: here's no direct interface to a fly motor, plus this needs to support a state where going through the world is okay. // FIXME: add callbacks into the script system for validation // FIXME: add function on scripts to force only legal movements // FIXME: GetIntervalMovement deals in Local space, nor global. Currently now way to communicate that through these interfaces. SetLocalOrigin( newPos ); SetLocalAngles( newAngles ); return true; } } else if (GetMoveType() == MOVETYPE_FLY) { Vector dist = newPos - GetLocalOrigin(); VectorScale( dist, 1.0 / flInterval, dist ); SetLocalVelocity( dist ); return true; } } return false; }
//----------------------------------------------------------------------------- // Purpose: // Input : fTimeDelta - //----------------------------------------------------------------------------- void C_ExtinguisherJet::Update( float fTimeDelta ) { if ( m_bEmit == false ) return; C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if ( m_bUseMuzzlePoint ) { C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); Vector origin; QAngle angles; vm->GetAttachment( iAttachment, origin, angles ); Assert( !GetMoveParent() ); SetLocalOrigin( origin ); SetLocalAngles( angles ); } } trace_t tr; Vector shotDir, vRight, vUp; AngleVectors( GetAbsAngles(), &shotDir, &vRight, &vUp ); //FIXME: Muzzle point is incorrect on the model! if ( m_bUseMuzzlePoint ) { shotDir.Negate(); } Vector endPoint = GetAbsOrigin() + ( shotDir * 150.0f ); UTIL_TraceLine( GetAbsOrigin(), endPoint, MASK_SHOT, NULL, COLLISION_GROUP_NONE, &tr ); bool hitWall = ( tr.fraction < 1.0f ); //Add normal jet if ( m_pEmitter.IsValid() ) { SimpleParticle *pParticle; m_pEmitter->SetSortOrigin( GetAbsOrigin() ); float tempDelta = fTimeDelta; //FIXME: All particles need to be within this loop while( m_ParticleSpawn.NextEvent( tempDelta ) ) { pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, GetAbsOrigin() ); if ( pParticle ) { pParticle->m_flDieTime = 0.2f; pParticle->m_flLifetime = 0.0f; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta= random->RandomFloat( -4.0f, 4.0f ); pParticle->m_uchStartSize = 1; pParticle->m_uchEndSize = random->RandomInt( 32, 48 ); pParticle->m_uchStartAlpha = random->RandomInt( 128, 164 ); pParticle->m_uchEndAlpha = 0; int cScale = random->RandomInt( 192, 255 ); pParticle->m_uchColor[0] = cScale; pParticle->m_uchColor[1] = cScale; pParticle->m_uchColor[2] = cScale; Vector dir; QAngle ofsAngles; ofsAngles.Random( -8.0f, 8.0f ); ofsAngles += GetAbsAngles(); AngleVectors( ofsAngles, &dir ); if ( m_bUseMuzzlePoint ) { dir.Negate(); } pParticle->m_vecVelocity = dir * random->RandomInt( 400, 800 ); } //Add muzzle effect pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, GetAbsOrigin() ); if ( pParticle ) { pParticle->m_flDieTime = 0.1f; pParticle->m_flLifetime = 0.0f; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta= random->RandomFloat( -4.0f, 4.0f ); pParticle->m_uchStartSize = 1; pParticle->m_uchEndSize = random->RandomInt( 8, 16 ); pParticle->m_uchStartAlpha = random->RandomInt( 128, 255 ); pParticle->m_uchEndAlpha = 0; int cScale = random->RandomInt( 192, 255 ); pParticle->m_uchColor[0] = cScale; pParticle->m_uchColor[1] = cScale; pParticle->m_uchColor[2] = cScale; Vector dir; QAngle ofsAngles; ofsAngles.Random( -64.0f, 64.0f ); ofsAngles += GetAbsAngles(); AngleVectors( ofsAngles, &dir ); if ( m_bUseMuzzlePoint ) { dir.Negate(); } pParticle->m_vecVelocity = dir * random->RandomInt( 32, 64 ); } //Add a wall effect if needed if ( hitWall ) { AddExtinguisherDecal( tr ); Vector offDir; offDir.Random( -16.0f, 16.0f ); pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, ( tr.endpos + ( tr.plane.normal * 8.0f ) ) + offDir ); if ( pParticle ) { pParticle->m_flDieTime = 0.4f; pParticle->m_flLifetime = 0.0f; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta= random->RandomFloat( -2.0f, 2.0f ); pParticle->m_uchStartSize = random->RandomInt( 8, 16 ); pParticle->m_uchEndSize = random->RandomInt( 24, 32 ); pParticle->m_uchStartAlpha = random->RandomInt( 64, 128 ); pParticle->m_uchEndAlpha = 0; int cScale = random->RandomInt( 192, 255 ); pParticle->m_uchColor[0] = cScale; pParticle->m_uchColor[1] = cScale; pParticle->m_uchColor[2] = cScale; Vector rDir; rDir = tr.plane.normal; rDir[0] += random->RandomFloat( -0.9f, 0.9f ); rDir[1] += random->RandomFloat( -0.9f, 0.9f ); rDir[2] += random->RandomFloat( -0.9f, 0.9f ); pParticle->m_vecVelocity = rDir * random->RandomInt( 32, 64 ); } } //Add small ember-like particles if ( random->RandomInt( 0, 1 ) == 0 ) { m_pEmberEmitter->SetSortOrigin( GetAbsOrigin() ); pParticle = (SimpleParticle *) m_pEmberEmitter->AddParticle( sizeof(SimpleParticle), m_pEmberEmitter->GetPMaterial( "particle/particle_smokegrenade" ), GetAbsOrigin() ); assert(pParticle); if ( pParticle ) { pParticle->m_flLifetime = 0.0f; pParticle->m_flDieTime = 1.0f; pParticle->m_flRoll = 0; pParticle->m_flRollDelta = 0; pParticle->m_uchColor[0] = 255; pParticle->m_uchColor[1] = 255; pParticle->m_uchColor[2] = 255; pParticle->m_uchStartAlpha = 255; pParticle->m_uchEndAlpha = 0; pParticle->m_uchStartSize = 1; pParticle->m_uchEndSize = 0; Vector dir; QAngle ofsAngles; ofsAngles.Random( -8.0f, 8.0f ); ofsAngles += GetAbsAngles(); AngleVectors( ofsAngles, &dir ); if ( m_bUseMuzzlePoint ) { dir.Negate(); } pParticle->m_vecVelocity = dir * random->RandomInt( 400, 800 ); } } } } // Inner beam CBeamSegDraw beamDraw; CBeamSeg seg; const int numPoints = 4; Vector beamPoints[numPoints]; beamPoints[0] = GetAbsOrigin(); // Create our beam points int i; for ( i = 0; i < numPoints; i++ ) { beamPoints[i] = GetAbsOrigin() + ( shotDir * (32*i*i) ); beamPoints[i] += vRight * sin( gpGlobals->curtime * 4.0f ) * (2.0f*i); beamPoints[i] += vUp * sin( gpGlobals->curtime * 8.0f ) * (1.0f*i); beamPoints[i] += shotDir * sin( gpGlobals->curtime * (16.0f*i) ) * (1.0f*i); } IMaterial *pMat = materials->FindMaterial( "particle/particle_smokegrenade", NULL ); beamDraw.Start( numPoints, pMat ); //Setup and draw those points for( i = 0; i < numPoints; i++ ) { float t = (float) i / (numPoints - 1); float color = 1.0f * (1.0f - t); seg.m_vColor = Vector( color, color, color ); seg.m_vPos = beamPoints[i]; seg.m_flTexCoord = (float)i/(float)(numPoints-1) - ((gpGlobals->curtime - (int)gpGlobals->curtime) * 4.0f ); seg.m_flWidth = 4.0f + ( (64.0f*t) * (fabs( sin( gpGlobals->curtime * 16.0f ) )) ); seg.m_flAlpha = color; beamDraw.NextSeg( &seg ); } beamDraw.End(); }
void CBaseParticleEntity::FollowEntity(CBaseEntity *pEntity) { BaseClass::FollowEntity( pEntity ); SetLocalOrigin( vec3_origin ); }
AIMoveResult_t CAI_Motor::MoveClimbExecute( const Vector &climbDest, const Vector &climbDir, float climbDist, float yaw, int climbNodesLeft ) { if ( fabsf( climbDir.z ) > .1 ) { if ( GetActivity() != ACT_CLIMB_DISMOUNT ) { Activity desiredActivity = (climbDir.z > -0.01 ) ? ACT_CLIMB_UP : ACT_CLIMB_DOWN; if ( GetActivity() != desiredActivity ) { SetActivity( desiredActivity ); } } if ( GetActivity() != ACT_CLIMB_UP && GetActivity() != ACT_CLIMB_DOWN && GetActivity() != ACT_CLIMB_DISMOUNT ) { DevMsg( "Climber not in a climb activity!\n" ); return AIMR_ILLEGAL; } if (m_nDismountSequence != ACT_INVALID) { if (GetActivity() == ACT_CLIMB_UP ) { if (climbNodesLeft <= 2 && climbDist < fabs( m_vecDismount.z )) { // fixme: No other way to force m_nIdealSequence? GetOuter()->SetActivity( ACT_CLIMB_DISMOUNT ); GetOuter()->SetCycle( GetOuter()->GetMovementFrame( m_vecDismount.z - climbDist ) ); } } } } float climbSpeed = GetOuter()->GetInstantaneousVelocity(); if (m_nDismountSequence != ACT_INVALID) { // catch situations where the climb mount/dismount finished before reaching goal climbSpeed = MAX( climbSpeed, 30.0 ); } else { // FIXME: assume if they don't have a dismount animation then they probably don't really support climbing. climbSpeed = 100.0; } SetSmoothedVelocity( climbDir * climbSpeed ); if ( climbDist < climbSpeed * GetMoveInterval() ) { if (climbDist <= 1e-2) climbDist = 0; const float climbTime = climbDist / climbSpeed; SetMoveInterval( GetMoveInterval() - climbTime ); SetLocalOrigin( climbDest ); return AIMR_CHANGE_TYPE; } else { SetMoveInterval( 0 ); } // -------------------------------------------- // Turn to face the climb // -------------------------------------------- SetIdealYawAndUpdate( yaw ); return AIMR_OK; }
void CBaseViewModel::CalcViewModelView( CBasePlayer *owner, const Vector& eyePosition, const QAngle& eyeAngles ) { // UNDONE: Calc this on the server? Disabled for now as it seems unnecessary to have this info on the server #if defined( CLIENT_DLL ) QAngle vmangoriginal = eyeAngles; QAngle vmangles = eyeAngles; Vector vmorigin = eyePosition; CBaseCombatWeapon *pWeapon = m_hWeapon.Get(); //Allow weapon lagging if ( pWeapon != NULL ) { #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) #endif { // add weapon-specific bob pWeapon->AddViewmodelBob( this, vmorigin, vmangles ); #if defined ( CSTRIKE_DLL ) CalcViewModelLag( vmorigin, vmangles, vmangoriginal ); #endif } } // Add model-specific bob even if no weapon associated (for head bob for off hand models) AddViewModelBob( owner, vmorigin, vmangles ); #if !defined ( CSTRIKE_DLL ) // This was causing weapon jitter when rotating in updated CS:S; original Source had this in above InPrediction block 07/14/10 // Add lag CalcViewModelLag( vmorigin, vmangles, vmangoriginal ); #endif #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) { // Let the viewmodel shake at about 10% of the amplitude of the player's view vieweffects->ApplyShake( vmorigin, vmangles, 0.1 ); } #endif if( UseVR() ) { g_ClientVirtualReality.OverrideViewModelTransform( vmorigin, vmangles, pWeapon && pWeapon->ShouldUseLargeViewModelVROverride() ); } SetLocalOrigin( vmorigin ); SetLocalAngles( vmangles ); #ifdef SIXENSE if( g_pSixenseInput->IsEnabled() && (owner->GetObserverMode()==OBS_MODE_NONE) && !UseVR() ) { const float max_gun_pitch = 20.0f; float viewmodel_fov_ratio = g_pClientMode->GetViewModelFOV()/owner->GetFOV(); QAngle gun_angles = g_pSixenseInput->GetViewAngleOffset() * -viewmodel_fov_ratio; // Clamp pitch a bit to minimize seeing back of viewmodel if( gun_angles[PITCH] < -max_gun_pitch ) { gun_angles[PITCH] = -max_gun_pitch; } #ifdef WIN32 // ShouldFlipViewModel comes up unresolved on osx? Mabye because it's defined inline? fixme if( ShouldFlipViewModel() ) { gun_angles[YAW] *= -1.0f; } #endif vmangles = EyeAngles() + gun_angles; SetLocalAngles( vmangles ); } #endif #endif }
void CASW_Parasite::InfestMarine(CASW_Marine* pMarine) { if ( !pMarine ) return; pMarine->BecomeInfested(this); // attach int attachment = pMarine->LookupAttachment( "chest" ); if ( attachment ) { SetSolid( SOLID_NONE ); SetMoveType( MOVETYPE_NONE ); QAngle current(0,0,0); Vector diff = pMarine->GetAbsOrigin() - GetAbsOrigin(); float angle = UTIL_VecToYaw(diff); angle -= pMarine->GetAbsAngles()[YAW]; // get the diff between our angle from the marine and the marine's facing; current = GetAbsAngles(); Vector vAttachmentPos; pMarine->GetAttachment( attachment, vAttachmentPos ); // Make sure it's near the chest attachement before parenting Teleport( &vAttachmentPos, &vec3_angle, &vec3_origin ); SetParent( pMarine, attachment ); float flRaise = RandomFloat( 15.0f, 18.0f ); float flForward = RandomFloat( -3.0f, 0.0f ); float flSide = RandomFloat( 1.75f, 3.0f ) * ( RandomInt( 0, 1 ) == 0 ? 1.0f : -1.0f ); if ( asw_debug_alien_damage.GetBool() ) { Msg( "INFEST: flRaise = %f flForward = %f flSide = %f yaw = %f\n", flRaise, flForward, flSide, angle + asw_infest_angle.GetFloat() ); } SetLocalOrigin( Vector( flForward, flSide, flRaise ) ); SetLocalAngles( QAngle( asw_infest_pitch.GetFloat(), angle + asw_infest_angle.GetFloat(), 0 ) ); // play our infesting anim if ( asw_parasite_inside.GetBool() ) { SetActivity(ACT_RANGE_ATTACK2); } else { int iInfestAttack = LookupSequence("Infest_attack"); if (GetSequence() != iInfestAttack) { ResetSequence(iInfestAttack); } } AddFlag( FL_NOTARGET ); SetThink( &CASW_Parasite::InfestThink ); SetTouch( NULL ); m_bInfesting = true; } else { FinishedInfesting(); } }
void CCharacter::MoveThink() { if (!GetGroundEntity()) return; if (m_vecGoalVelocity.LengthSqr()) m_vecGoalVelocity.Normalize(); m_vecMoveVelocity.x = Approach(m_vecGoalVelocity.x, m_vecMoveVelocity.x, GameServer()->GetFrameTime()*4); m_vecMoveVelocity.y = 0; m_vecMoveVelocity.z = Approach(m_vecGoalVelocity.z, m_vecMoveVelocity.z, GameServer()->GetFrameTime()*4); if (m_vecMoveVelocity.LengthSqr() > 0) { TMatrix m = GetLocalTransform(); Vector vecUp = GetUpVector(); if (HasMoveParent()) { TMatrix mGlobalToLocal = GetMoveParent()->GetGlobalToLocalTransform(); vecUp = mGlobalToLocal.TransformNoTranslate(vecUp); } Vector vecRight = m.GetForwardVector().Cross(vecUp).Normalized(); Vector vecForward = vecUp.Cross(vecRight).Normalized(); m.SetColumn(0, vecForward); m.SetColumn(1, vecUp); m.SetColumn(2, vecRight); TVector vecMove = m_vecMoveVelocity * CharacterSpeed(); TVector vecLocalVelocity = m.TransformNoTranslate(vecMove); SetLocalVelocity(vecLocalVelocity); } else SetLocalVelocity(TVector()); eastl::vector<CEntityHandle<CBaseEntity> > apCollisionList; size_t iMaxEntities = GameServer()->GetMaxEntities(); for (size_t j = 0; j < iMaxEntities; j++) { CBaseEntity* pEntity2 = CBaseEntity::GetEntity(j); if (!pEntity2) continue; if (pEntity2->IsDeleted()) continue; if (pEntity2 == this) continue; if (!pEntity2->ShouldCollide()) continue; apCollisionList.push_back(pEntity2); } TMatrix mGlobalToLocalRotation; if (HasMoveParent()) { mGlobalToLocalRotation = GetMoveParent()->GetGlobalToLocalTransform(); mGlobalToLocalRotation.SetTranslation(TVector()); } float flSimulationFrameTime = 0.01f; // Break simulations up into consistent small steps to preserve accuracy. for (; m_flMoveSimulationTime < GameServer()->GetGameTime(); m_flMoveSimulationTime += flSimulationFrameTime) { TVector vecVelocity = GetLocalVelocity(); TVector vecLocalOrigin = GetLocalOrigin(); TVector vecGlobalOrigin = GetGlobalOrigin(); vecVelocity = vecVelocity * flSimulationFrameTime; TVector vecLocalDestination = vecLocalOrigin + vecVelocity; TVector vecGlobalDestination = vecLocalDestination; if (GetMoveParent()) vecGlobalDestination = GetMoveParent()->GetGlobalTransform() * vecLocalDestination; TVector vecNewLocalOrigin = vecLocalDestination; size_t iTries = 0; while (true) { iTries++; TVector vecPoint, vecNormal; TVector vecLocalCollisionPoint, vecGlobalCollisionPoint; bool bContact = false; for (size_t i = 0; i < apCollisionList.size(); i++) { CBaseEntity* pEntity2 = apCollisionList[i]; if (GetMoveParent() == pEntity2) { if (pEntity2->CollideLocal(vecLocalOrigin, vecLocalDestination, vecPoint, vecNormal)) { bContact = true; Touching(pEntity2); vecLocalCollisionPoint = vecPoint; vecGlobalCollisionPoint = GetMoveParent()->GetGlobalTransform() * vecPoint; } } else { if (pEntity2->Collide(vecGlobalOrigin, vecGlobalDestination, vecPoint, vecNormal)) { bContact = true; Touching(pEntity2); vecGlobalCollisionPoint = vecPoint; if (GetMoveParent()) { vecLocalCollisionPoint = GetMoveParent()->GetGlobalToLocalTransform() * vecPoint; vecNormal = GetMoveParent()->GetGlobalToLocalTransform().TransformNoTranslate(vecNormal); } else vecLocalCollisionPoint = vecGlobalCollisionPoint; } } } if (bContact) { vecNewLocalOrigin = vecLocalCollisionPoint; vecVelocity -= vecLocalCollisionPoint - vecLocalOrigin; } if (!bContact) break; if (iTries > 4) break; vecLocalOrigin = vecLocalCollisionPoint; vecGlobalOrigin = vecGlobalCollisionPoint; // Clip the velocity to the surface normal of whatever we hit. TFloat flDistance = vecVelocity.Dot(vecNormal); vecVelocity = vecVelocity - vecNormal * flDistance; // Do it one more time just to make sure we're not headed towards the plane. TFloat flAdjust = vecVelocity.Dot(vecNormal); if (flAdjust < 0.0f) vecVelocity -= (vecNormal * flAdjust); vecLocalDestination = vecLocalOrigin + vecVelocity; if (GetMoveParent()) vecGlobalDestination = GetMoveParent()->GetGlobalTransform() * vecLocalDestination; else vecGlobalDestination = vecLocalDestination; SetLocalVelocity(vecVelocity.Normalized() * GetLocalVelocity().Length()); } SetLocalOrigin(vecNewLocalOrigin); // Try to keep the player on the ground. // Untested. /*TVector vecStart = GetGlobalOrigin() + GetGlobalTransform().GetUpVector()*m_flMaxStepSize; TVector vecEnd = GetGlobalOrigin() - GetGlobalTransform().GetUpVector()*m_flMaxStepSize; // First go up a bit TVector vecHit, vecNormal; Game()->TraceLine(GetGlobalOrigin(), vecStart, vecHit, vecNormal, NULL); vecStart = vecHit; // Now see if there's ground underneath us. bool bHit = Game()->TraceLine(vecStart, vecEnd, vecHit, vecNormal, NULL); if (bHit && vecNormal.y >= TFloat(0.7f)) SetGlobalOrigin(vecHit);*/ m_flMoveSimulationTime += flSimulationFrameTime; } }