//----------------------------------------------------------------------------- // Apply movement //----------------------------------------------------------------------------- void CLogicMeasureMovement::MeasureThink( ) { // FIXME: This is a hack to make measuring !player simpler. The player isn't // created at Activate time, so m_hMeasureTarget may be NULL because of that. if ( !m_hMeasureTarget.Get() && !Q_strnicmp( STRING(m_strMeasureTarget), "!player", 8 ) ) { SetMeasureTarget( STRING(m_strMeasureTarget) ); } // Make sure all entities are valid if ( m_hMeasureTarget.Get() && m_hMeasureReference.Get() && m_hTarget.Get() && m_hTargetReference.Get() ) { matrix3x4_t matRefToMeasure, matWorldToMeasure; switch( m_nMeasureType ) { case MEASURE_POSITION: MatrixInvert( m_hMeasureTarget->EntityToWorldTransform(), matWorldToMeasure ); break; case MEASURE_EYE_POSITION: AngleIMatrix( m_hMeasureTarget->EyeAngles(), m_hMeasureTarget->EyePosition(), matWorldToMeasure ); break; // FIXME: Could add attachment point measurement here easily } ConcatTransforms( matWorldToMeasure, m_hMeasureReference->EntityToWorldTransform(), matRefToMeasure ); // Apply the scale factor if ( ( m_flScale != 0.0f ) && ( m_flScale != 1.0f ) ) { Vector vecTranslation; MatrixGetColumn( matRefToMeasure, 3, vecTranslation ); vecTranslation /= m_flScale; MatrixSetColumn( vecTranslation, 3, matRefToMeasure ); } // Now apply the new matrix to the new reference point matrix3x4_t matMeasureToRef, matNewTargetToWorld; MatrixInvert( matRefToMeasure, matMeasureToRef ); ConcatTransforms( m_hTargetReference->EntityToWorldTransform(), matMeasureToRef, matNewTargetToWorld ); Vector vecNewOrigin; QAngle vecNewAngles; MatrixAngles( matNewTargetToWorld, vecNewAngles, vecNewOrigin ); m_hTarget->SetAbsOrigin( vecNewOrigin ); m_hTarget->SetAbsAngles( vecNewAngles ); } SetNextThink( gpGlobals->curtime + TICK_INTERVAL ); }
void CPhysicsEntitySolver::UpdateOnRemove() { //physenv->DestroyMotionController( m_pController ); //m_pController = NULL; CBaseEntity *pEntity = m_hMovingEntity.Get(); CBaseEntity *pPhysics = m_hPhysicsBlocker.Get(); if ( pEntity && pPhysics ) { PhysEnableEntityCollisions( pEntity, pPhysics ); } if ( pPhysics ) { pPhysics->SetCollisionGroup( m_savedCollisionGroup ); } BaseClass::UpdateOnRemove(); }
//----------------------------------------------------------------------------- // Purpose: Charge up, deal damage along our facing direction. //----------------------------------------------------------------------------- void CNPC_RocketTurret::FiringThink( void ) { //Allow descended classes a chance to do something before the think function if ( PreThink() ) return; SetNextThink( gpGlobals->curtime + ROCKET_TURRET_THINK_RATE ); CRocket_Turret_Projectile* pRocket = dynamic_cast<CRocket_Turret_Projectile*>(m_hCurRocket.Get()); if ( pRocket ) { // If this rocket has been out too long, detonate it and launch a new one if ( (gpGlobals->curtime - m_flTimeLastFired) > ROCKET_PROJECTILE_DEFAULT_LIFE ) { pRocket->ShotDown(); m_flTimeLastFired = gpGlobals->curtime; SetThink( &CNPC_RocketTurret::FollowThink ); } } else { // Set Locked sprite UpdateSkin( ROCKET_SKIN_IDLE ); // Rocket dead, or never created. Revert to follow think m_flTimeLastFired = gpGlobals->curtime; SetThink( &CNPC_RocketTurret::FollowThink ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponBugBait::Drop( const Vector &vecVelocity ) { BaseClass::Drop( vecVelocity ); // On touch, stick & stop moving. Increase our thinktime a bit so we don't stomp the touch for a bit SetNextThink( gpGlobals->curtime + 3.0 ); SetTouch( &CWeaponBugBait::BugbaitStickyTouch ); m_hSporeTrail = SporeExplosion::CreateSporeExplosion(); if ( m_hSporeTrail ) { SporeExplosion *pSporeExplosion = (SporeExplosion *)m_hSporeTrail.Get(); QAngle angles; VectorAngles( Vector(0,0,1), angles ); pSporeExplosion->SetAbsAngles( angles ); pSporeExplosion->SetAbsOrigin( GetAbsOrigin() ); pSporeExplosion->SetParent( this ); pSporeExplosion->m_flSpawnRate = 16.0f; pSporeExplosion->m_flParticleLifetime = 0.5f; pSporeExplosion->SetRenderColor( 0, (int)0.5f, (int)0.25f, (int)0.15f ); pSporeExplosion->m_flStartSize = 32; pSporeExplosion->m_flEndSize = 48; pSporeExplosion->m_flSpawnRadius = 4; pSporeExplosion->SetLifetime( 9999 ); } }
void CRocket_Turret_Projectile::NotifyLauncherOnDeath( void ) { CNPC_RocketTurret* pLauncher = (CNPC_RocketTurret*)m_hLauncher.Get(); if ( pLauncher ) { pLauncher->RocketDied(); } }
CSoundPatch *CSoundControllerImp::SoundCreate( IRecipientFilter& filter, int nEntIndex, int channel, const char *pSoundName, soundlevel_t soundlevel ) { CSoundPatch *pSound = new CSoundPatch; EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : NULL; pSound->Init( &filter, hEnt.Get(), channel, pSoundName, soundlevel ); return pSound; }
void CLogicMirrorMovement::Think() { // Attempt to get the player's handle because it didn't exist at Activate time if ( !m_hMirrorTarget.Get() ) { // If we will never find a target, we don't have a use... shutdown if ( m_strMirrorTarget == NULL_STRING ) SetNextThink ( NULL ); //BUGBUG: If m_strSetMirrorTarget doesn't exist in ent list, we get per-think searches with no results ever... SetMirrorTarget ( STRING(m_strMirrorTarget) ); } // Make sure all entities are valid if ( m_hMirrorTarget.Get() && m_hMovementTarget.Get() && m_hRemoteTarget.Get() && m_hMirrorRelative.Get() ) { // Get our two portal's world transforms transforms VMatrix matPortal1ToWorldInv, matPortal2ToWorld; MatrixInverseGeneral( m_hMirrorRelative->EntityToWorldTransform(), matPortal1ToWorldInv ); matPortal2ToWorld = m_hRemoteTarget->EntityToWorldTransform(); VMatrix matTransformToRemotePortal = matPortal1ToWorldInv * matPortal2ToWorld; // Get our scene camera's current orientation Vector ptCameraPosition, vCameraLook, vCameraRight, vCameraUp; ptCameraPosition = m_hMirrorTarget->EyePosition(); m_hMirrorTarget->GetVectors ( &vCameraLook, &vCameraRight, &vCameraUp ); // map this position and orientation to the remote portal, mirrored (invert the result) Vector ptNewPosition, vNewLook; ptNewPosition = matPortal1ToWorldInv * ptCameraPosition; ptNewPosition = matPortal2ToWorld*( Vector( -ptNewPosition.x, -ptNewPosition.y, ptNewPosition.z ) ); vNewLook = matPortal1ToWorldInv.ApplyRotation( vCameraLook ); vNewLook = matPortal2ToWorld.ApplyRotation( Vector( -vNewLook.x, -vNewLook.y, vNewLook.z) ); // Set the point camera to the new location/orientation QAngle qNewAngles; VectorAngles( vNewLook, qNewAngles ); m_hMovementTarget->Teleport( &ptNewPosition, &qNewAngles, NULL ); } SetNextThink( gpGlobals->curtime + TICK_INTERVAL ); }
CSoundPatch *CSoundControllerImp::SoundCreate( IRecipientFilter& filter, int nEntIndex, const char *pSoundName ) { CSoundPatch *pSound = new CSoundPatch; // FIXME: This is done so we don't have to futz with the public interface EHANDLE hEnt = (nEntIndex != -1) ? g_pEntityList->GetNetworkableHandle( nEntIndex ) : NULL; pSound->Init( &filter, hEnt.Get(), CHAN_AUTO, pSoundName, SNDLVL_NORM ); return pSound; }
bool CPhysicsNPCSolver::CheckTouching() { CAI_BaseNPC *pNPC = m_hNPC.Get(); if ( !pNPC ) return false; CBaseEntity *pPhysicsEnt = m_hEntity.Get(); if ( !pPhysicsEnt ) return false; IPhysicsObject *pPhysics = pPhysicsEnt->VPhysicsGetObject(); IPhysicsObject *pNPCPhysics = pNPC->VPhysicsGetObject(); if ( !pNPCPhysics || !pPhysics ) return false; IPhysicsFrictionSnapshot *pSnapshot = pPhysics->CreateFrictionSnapshot(); bool found = false; bool penetrate = false; while ( pSnapshot->IsValid() ) { IPhysicsObject *pOther = pSnapshot->GetObject(1); if ( pOther == pNPCPhysics ) { found = true; if ( IsContactOnNPCHead(pSnapshot, pPhysics, pNPC ) ) { penetrate = true; pSnapshot->MarkContactForDelete(); } break; } pSnapshot->NextFrictionData(); } pSnapshot->DeleteAllMarkedContacts( true ); pPhysics->DestroyFrictionSnapshot( pSnapshot ); // if the object is penetrating something, check to see if it's intersecting this NPC // if so, go ahead and switch over to penetration solver mode if ( !penetrate && (pPhysics->GetGameFlags() & FVPHYSICS_PENETRATING) ) { penetrate = IsIntersecting(); } if ( penetrate ) { pPhysicsEnt->ClearNavIgnore(); BecomePenetrationSolver(); } return found; }
CGameGibManager *GetGibManager( void ) { #ifndef HL2_EPISODIC return NULL; #endif if ( g_hGameGibManager == NULL ) { g_hGameGibManager = (CGameGibManager *)gEntList.FindEntityByClassname( NULL, "game_gib_manager" ); } return (CGameGibManager *)g_hGameGibManager.Get(); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_EntityParticleTrail::AddParticle( float flInitialDeltaTime, const Vector &vecMins, const Vector &vecMaxs, const matrix3x4_t &boxToWorld ) { // Select a random point somewhere in the hitboxes of the entity. Vector vecLocalPosition, vecWorldPosition; vecLocalPosition.x = Lerp( random->RandomFloat( 0.0f, 1.0f ), vecMins.x, vecMaxs.x ); vecLocalPosition.y = Lerp( random->RandomFloat( 0.0f, 1.0f ), vecMins.y, vecMaxs.y ); vecLocalPosition.z = Lerp( random->RandomFloat( 0.0f, 1.0f ), vecMins.z, vecMaxs.z ); VectorTransform( vecLocalPosition, boxToWorld, vecWorldPosition ); // Don't emit the particle unless it's inside the model if ( m_hConstraintEntity.Get() ) { Ray_t ray; trace_t tr; ray.Init( vecWorldPosition, vecWorldPosition ); enginetrace->ClipRayToEntity( ray, MASK_ALL, m_hConstraintEntity, &tr ); if ( !tr.startsolid ) return; } // Make a new particle SimpleParticle *pParticle = (SimpleParticle *)m_ParticleEffect.AddParticle( sizeof(SimpleParticle), m_hMaterial ); if ( pParticle == NULL ) return; pParticle->m_Pos = vecWorldPosition; pParticle->m_flRoll = Helper_RandomInt( 0, 360 ); pParticle->m_flRollDelta = Helper_RandomFloat( -2.0f, 2.0f ); pParticle->m_flLifetime = flInitialDeltaTime; pParticle->m_flDieTime = m_Info.m_flLifetime; pParticle->m_uchColor[0] = 64; pParticle->m_uchColor[1] = 140; pParticle->m_uchColor[2] = 225; pParticle->m_uchStartAlpha = Helper_RandomInt( 64, 64 ); pParticle->m_uchEndAlpha = 0; pParticle->m_uchStartSize = m_Info.m_flStartSize; pParticle->m_uchEndSize = m_Info.m_flEndSize; pParticle->m_vecVelocity = vec3_origin; VectorMA( pParticle->m_Pos, flInitialDeltaTime, pParticle->m_vecVelocity, pParticle->m_Pos ); }
void CPhysicsNPCSolver::BecomePenetrationSolver() { CBaseEntity *pEntity = m_hEntity.Get(); if ( pEntity ) { m_allowIntersection = true; IPhysicsObject *pList[VPHYSICS_MAX_OBJECT_LIST_COUNT]; int listCount = pEntity->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) ); PhysDisableEntityCollisions( m_hNPC, pEntity ); m_pController = physenv->CreateMotionController( this ); for ( int i = 0; i < listCount; i++ ) { m_pController->AttachObject( pList[i], false ); pList[i]->Wake(); } m_pController->SetPriority( IPhysicsMotionController::HIGH_PRIORITY ); } }
virtual void PostDataUpdate( DataUpdateType_t updateType ) { VPROF( "C_TEPlayerAnimEvent::PostDataUpdate" ); // Create the effect. if ( m_iPlayerIndex == MAX_PLAYERS+1 ) return; EHANDLE hPlayer = cl_entitylist->GetNetworkableHandle( m_iPlayerIndex ); if ( !hPlayer ) return; C_CFPlayer *pPlayer = dynamic_cast< C_CFPlayer* >( hPlayer.Get() ); if ( pPlayer && !pPlayer->IsDormant() ) { pPlayer->DoAnimationEvent( (PlayerAnimEvent_t)m_iEvent.Get(), m_nData, m_bSecondary ); } }
void CPhysicsNPCSolver::UpdateOnRemove() { if ( m_allowIntersection ) { physenv->DestroyMotionController( m_pController ); m_pController = NULL; PhysEnableEntityCollisions( m_hNPC, m_hEntity ); } else { if ( m_hEntity.Get() ) { m_hEntity->ClearNavIgnore(); } } //NDebugOverlay::EntityBounds(m_hNPC, 0, 255, 0, 64, 0.5f ); BaseClass::UpdateOnRemove(); }
bool CPhysicsNPCSolver::IsIntersecting() { CAI_BaseNPC *pNPC = m_hNPC.Get(); CBaseEntity *pPhysics = m_hEntity.Get(); if ( pNPC && pPhysics ) { Ray_t ray; // bloated bounds to force slight separation Vector mins = pNPC->WorldAlignMins() - Vector(1,1,1); Vector maxs = pNPC->WorldAlignMaxs() + Vector(1,1,1); ray.Init( pNPC->GetAbsOrigin(), pNPC->GetAbsOrigin(), mins, maxs ); trace_t tr; enginetrace->ClipRayToEntity( ray, pNPC->PhysicsSolidMaskForEntity(), pPhysics, &tr ); if ( tr.startsolid ) return true; } return false; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWeaponStriderBuster::OnRestore( void ) { BaseClass::OnRestore(); // If we have an entity we're attached to, attempt to reconstruct our bone follower setup if ( m_hConstrainedEntity != NULL ) { CNPC_Strider *pStrider = dynamic_cast<CNPC_Strider *>(m_hConstrainedEntity.Get()); if ( pStrider != NULL ) { // Make sure we've done this step or we'll have no controller to attach to pStrider->InitBoneFollowers(); // Attempt to make a connection to the same bone follower we attached to previously CBoneFollower *pBoneFollower = pStrider->GetBoneFollowerByIndex( m_nAttachedBoneFollowerIndex ); if ( CreateConstraintToObject( pBoneFollower ) == false ) { Msg( "Failed to reattach to bone follower %d\n", m_nAttachedBoneFollowerIndex ); } } } }
//--------------------------------------------------------- // Set velocity that will carry me towards a specified entity // Most often used to move along with the npc_blob that // is directing me. //--------------------------------------------------------- void CBlobElement::MoveTowardsTargetEntity( float speed ) { CBaseEntity *pTarget = m_hTargetEntity.Get(); if( pTarget != NULL ) { // Try to attack my target's enemy directly if I can. CBaseEntity *pTargetEnemy = pTarget->GetEnemy(); if( pTargetEnemy != NULL ) { pTarget = pTargetEnemy; } Vector vecDir = pTarget->WorldSpaceCenter() - GetAbsOrigin(); vecDir.NormalizeInPlace(); SetElementVelocity( vecDir * speed, true ); } else { SetElementVelocity( vec3_origin, true ); } }
int C_NEORagdoll::DrawModel( int flags ) { C_NEOPlayer *pPlayer = dynamic_cast<C_NEOPlayer*>(m_hPlayer.Get()); if ( pPlayer && (pPlayer->IsLocalNEOPlayer() || pPlayer->m_bIsOnDeathScreen) ) return 0; if ( pPlayer->m_iVision == 3 ) // Thermal vision { IMaterial* matThermal = g_pMaterialSystem->FindMaterial( "dev/thermal", "Other textures" ); if ( g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() ) { bool found = false; IMaterialVar* matVar = matThermal->FindVar( "$eyevec", &found ); if ( found ) { Vector forward; pPlayer->GetVectors( &forward, nullptr, nullptr ); matVar->SetVecValue( forward.x, forward.y, forward.z ); } } modelrender->ForcedMaterialOverride( matThermal ); int result = InternalDrawModel( flags ); modelrender->ForcedMaterialOverride( nullptr ); return result; } return BaseClass::DrawModel( flags ); }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- bool CEnvBeam::PassesTouchFilters(CBaseEntity *pOther) { bool fPassedSoFar = false; // Touched some player or NPC! if( m_TouchType != touch_npc_only ) { if( pOther->IsPlayer() ) { fPassedSoFar = true; } } if( m_TouchType != touch_player_only ) { if( pOther->IsNPC() ) { fPassedSoFar = true; } } if( m_TouchType == touch_player_or_npc_or_physicsprop ) { if( pOther->m_iClassname == g_iszPhysicsPropClassname ) { fPassedSoFar = true; } } if( fPassedSoFar ) { CBaseFilter* pFilter = (CBaseFilter*)(m_hFilter.Get()); return (!pFilter) ? true : pFilter->PassesFilter( this, pOther ); } return false; }
//----------------------------------------------------------------------------- // Purpose: Input handler for making the explosion explode. //----------------------------------------------------------------------------- void CASWEnvExplosion::InputExplode( inputdata_t &inputdata ) { trace_t tr; SetModelName( NULL_STRING );//invisible SetSolid( SOLID_NONE );// intangible Vector vecSpot = GetAbsOrigin() + Vector( 0 , 0 , 8 ); UTIL_TraceLine( vecSpot, vecSpot + Vector( 0, 0, -40 ), (MASK_SOLID_BRUSHONLY | MASK_WATER), this, COLLISION_GROUP_NONE, &tr ); // Pull out of the wall a bit. We used to move the explosion origin itself, but that seems unnecessary, not to mention a // little weird when you consider that it might be in hierarchy. Instead we just calculate a new virtual position at // which to place the explosion. We don't use that new position to calculate radius damage because according to Steve's // comment, that adversely affects the force vector imparted on explosion victims when they ragdoll. Vector vecExplodeOrigin = GetAbsOrigin(); if ( tr.fraction != 1.0 ) { vecExplodeOrigin = tr.endpos + (tr.plane.normal * 24 ); } // draw decal if (! ( m_spawnflags & SF_ENVEXPLOSION_NODECAL )) { if ( ! ( m_spawnflags & SF_ENVEXPLOSION_ICE )) UTIL_DecalTrace( &tr, "Scorch" ); else UTIL_DecalTrace( &tr, "Ice_Explosion_Decal" ); } //Get the damage override if specified float flRadius = ( m_iRadiusOverride > 0 ) ? ((float)m_iRadiusOverride/100.0f) : ( (float)m_iDamage / 100.0f ); // do damage if ( !( m_spawnflags & SF_ENVEXPLOSION_NODAMAGE ) ) { CBaseEntity *pAttacker = GetOwnerEntity() ? GetOwnerEntity() : this; // Only calculate damage type if we didn't get a custom one passed in int iDamageType = m_iCustomDamageType; if ( iDamageType == -1 ) { iDamageType = HasSpawnFlags( SF_ENVEXPLOSION_GENERIC_DAMAGE ) ? DMG_GENERIC : DMG_BLAST; } CTakeDamageInfo info( m_hInflictor ? m_hInflictor : this, pAttacker, m_iDamage, iDamageType ); if( HasSpawnFlags( SF_ENVEXPLOSION_SURFACEONLY ) ) { info.AddDamageType( DMG_BLAST_SURFACE ); } if ( m_flDamageForce ) { // Not the right direction, but it'll be fixed up by RadiusDamage. info.SetDamagePosition( GetAbsOrigin() ); info.SetDamageForce( Vector( m_flDamageForce, 0, 0 ) ); } ASWGameRules()->RadiusDamage( info, GetAbsOrigin(), flRadius, m_iClassIgnore, m_hEntityIgnore.Get() ); } // emit the sound if( !(m_spawnflags & SF_ENVEXPLOSION_NOSOUND) ) { EmitSound( STRING(m_iszExplosionSound) ); } // do the particle effect if( !(m_spawnflags & SF_ENVEXPLOSION_NOFIREBALL) ) { bool bOnGround = false; if ( tr.fraction != 1.0 ) bOnGround = true; UTIL_ASW_EnvExplosionFX( vecExplodeOrigin, flRadius, bOnGround ); } /* // do a dlight if ( !( m_spawnflags & SF_ENVEXPLOSION_NODLIGHTS ) ) { // Make an elight dlight_t *el = effects->CL_AllocDlight( LIGHT_INDEX_TE_DYNAMIC + entindex() ); el->origin = vecExplodeOrigin; el->radius = random->RandomFloat( flRadius + 54.0f, flRadius + 74.0f ); el->decay = el->radius / 0.05f; el->die = gpGlobals->curtime + 0.05f; Color c = Color( 255, 192, 64, 6 ); el->color.r = c.r(); el->color.g = c.g(); el->color.b = c.b(); el->color.exponent = c.a(); } */ if ( !(m_spawnflags & SF_ENVEXPLOSION_REPEATABLE) ) { SetThink( &CASWEnvExplosion::SUB_Remove ); SetNextThink( gpGlobals->curtime + 1.0f ); } }
IterationRetval_t CPortalCollideableEnumerator::EnumElement( IHandleEntity *pHandleEntity ) { EHANDLE hEnt = pHandleEntity->GetRefEHandle(); CBaseEntity *pEnt = hEnt.Get(); if( pEnt == NULL ) //I really never thought this would be necessary return ITERATION_CONTINUE; if( hEnt == m_hTestPortal ) return ITERATION_CONTINUE; //ignore this portal /*if( staticpropmgr->IsStaticProp( pHandleEntity ) ) { //we're dealing with a static prop, which unfortunately doesn't have everything I want to use for checking ICollideable *pCollideable = pEnt->GetCollideable(); Vector vMins, vMaxs; pCollideable->WorldSpaceSurroundingBounds( &vMins, &vMaxs ); Vector ptTest( (m_vPlaneNormal.x > 0.0f)?(vMaxs.x):(vMins.x), (m_vPlaneNormal.y > 0.0f)?(vMaxs.y):(vMins.y), (m_vPlaneNormal.z > 0.0f)?(vMaxs.z):(vMins.z) ); float fPtPlaneDist = m_vPlaneNormal.Dot( ptTest ) - m_fPlaneDist; if( fPtPlaneDist <= 0.0f ) return ITERATION_CONTINUE; } else*/ { //not a static prop, w00t CCollisionProperty *pEntityCollision = pEnt->CollisionProp(); if( !pEntityCollision->IsSolid() ) return ITERATION_CONTINUE; //not solid Vector ptEntCenter = pEntityCollision->WorldSpaceCenter(); float fBoundRadius = pEntityCollision->BoundingRadius(); float fPtPlaneDist = m_vPlaneNormal.Dot( ptEntCenter ) - m_fPlaneDist; if( fPtPlaneDist < -fBoundRadius ) return ITERATION_CONTINUE; //object wholly behind the portal if( !(fPtPlaneDist > fBoundRadius) && (fPtPlaneDist > -fBoundRadius) ) //object is not wholly in front of the portal, but could be partially in front, do more checks { Vector ptNearest; pEntityCollision->CalcNearestPoint( m_ptForward1000, &ptNearest ); fPtPlaneDist = m_vPlaneNormal.Dot( ptNearest ) - m_fPlaneDist; if( fPtPlaneDist < 0.0f ) return ITERATION_CONTINUE; //closest point was behind the portal plane, we don't want it } } //if we're down here, this entity needs to be added to our enumeration Assert( m_iHandleCount < 1024 ); if( m_iHandleCount < 1024 ) m_pHandles[m_iHandleCount] = pHandleEntity; ++m_iHandleCount; return ITERATION_CONTINUE; }
void C_SDKRagdoll::CreateRagdoll() { // First, initialize all our data. If we have the player's entity on our client, // then we can make ourselves start out exactly where the player is. C_SDKPlayer *pPlayer = dynamic_cast< C_SDKPlayer* >( m_hPlayer.Get() ); if ( pPlayer && !pPlayer->IsDormant() ) { // move my current model instance to the ragdoll's so decals are preserved. pPlayer->SnatchModelInstance( this ); VarMapping_t *varMap = GetVarMapping(); // Copy all the interpolated vars from the player entity. // The entity uses the interpolated history to get bone velocity. if ( !pPlayer->IsLocalPlayer() && pPlayer->IsInterpolationEnabled() ) { Interp_Copy( pPlayer ); SetAbsAngles( pPlayer->GetRenderAngles() ); GetRotationInterpolator().Reset(); m_flAnimTime = pPlayer->m_flAnimTime; SetSequence( pPlayer->GetSequence() ); m_flPlaybackRate = pPlayer->GetPlaybackRate(); } else { // This is the local player, so set them in a default // pose and slam their velocity, angles and origin SetAbsOrigin( m_vecRagdollOrigin ); SetAbsAngles( pPlayer->GetRenderAngles() ); SetAbsVelocity( m_vecRagdollVelocity ); int iSeq = LookupSequence( "RagdollSpawn" ); // hax, find a neutral standing pose if ( iSeq == -1 ) { Assert( false ); // missing look_idle? iSeq = 0; } SetSequence( iSeq ); // look_idle, basic pose SetCycle( 0.0 ); Interp_Reset( varMap ); } m_nBody = pPlayer->GetBody(); } else { // overwrite network origin so later interpolation will // use this position SetNetworkOrigin( m_vecRagdollOrigin ); SetAbsOrigin( m_vecRagdollOrigin ); SetAbsVelocity( m_vecRagdollVelocity ); Interp_Reset( GetVarMapping() ); } SetModelIndex( m_nModelIndex ); // Turn it into a ragdoll. if ( cl_ragdoll_physics_enable.GetInt() ) { // Make us a ragdoll.. m_nRenderFX = kRenderFxRagdoll; matrix3x4_t boneDelta0[MAXSTUDIOBONES]; matrix3x4_t boneDelta1[MAXSTUDIOBONES]; matrix3x4_t currentBones[MAXSTUDIOBONES]; const float boneDt = 0.05f; if ( pPlayer && pPlayer == C_BasePlayer::GetLocalPlayer() ) { pPlayer->GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); } else { GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); } InitAsClientRagdoll( boneDelta0, boneDelta1, currentBones, boneDt ); } else { ClientLeafSystem()->SetRenderGroup( GetRenderHandle(), RENDER_GROUP_TRANSLUCENT_ENTITY ); } // Fade out the ragdoll in a while StartFadeOut( cl_ragdoll_fade_time.GetFloat() ); SetNextClientThink( gpGlobals->curtime + 5.0f ); }
void C_CFRagdoll::CreateRagdoll() { // First, initialize all our data. If we have the player's entity on our client, // then we can make ourselves start out exactly where the player is. C_CFPlayer *pPlayer = dynamic_cast< C_CFPlayer* >( m_hPlayer.Get() ); if ( pPlayer && !pPlayer->IsDormant() ) { // move my current model instance to the ragdoll's so decals are preserved. pPlayer->SnatchModelInstance( this ); VarMapping_t *varMap = GetVarMapping(); // Copy all the interpolated vars from the player entity. // The entity uses the interpolated history to get bone velocity. bool bRemotePlayer = (pPlayer != C_BasePlayer::GetLocalPlayer()); if ( bRemotePlayer ) { Interp_Copy( pPlayer ); SetAbsAngles( pPlayer->GetRenderAngles() ); GetRotationInterpolator().Reset(); m_flAnimTime = pPlayer->m_flAnimTime; SetSequence( pPlayer->GetSequence() ); m_flPlaybackRate = pPlayer->GetPlaybackRate(); } else { // This is the local player, so set them in a default // pose and slam their velocity, angles and origin SetAbsOrigin( m_vecRagdollOrigin ); SetAbsAngles( pPlayer->GetRenderAngles() ); SetAbsVelocity( m_vecRagdollVelocity ); int iSeq = LookupSequence( "idle" ); if ( iSeq == -1 ) { Assert( false ); // missing walk_lower? iSeq = 0; } SetSequence( iSeq ); // walk_lower, basic pose SetCycle( 0.0 ); Interp_Reset( varMap ); } } else { // overwrite network origin so later interpolation will // use this position SetNetworkOrigin( m_vecRagdollOrigin ); SetAbsOrigin( m_vecRagdollOrigin ); SetAbsVelocity( m_vecRagdollVelocity ); Interp_Reset( GetVarMapping() ); } if (pPlayer) { SetModelIndex( m_nModelIndex ); m_nSkin = pPlayer->m_nSkin; SetBodygroup(1, pPlayer->m_bIsDecapitated); } // Turn it into a ragdoll. if ( cl_ragdoll_physics_enable.GetBool() ) { // Make us a ragdoll.. m_nRenderFX = kRenderFxRagdoll; matrix3x4_t boneDelta0[MAXSTUDIOBONES]; matrix3x4_t boneDelta1[MAXSTUDIOBONES]; matrix3x4_t currentBones[MAXSTUDIOBONES]; const float boneDt = 0.05f; // We have to make sure that we're initting this client ragdoll off of the same model. // GetRagdollInitBoneArrays uses the *player* Hdr, which may be a different model than // the ragdoll Hdr, if we try to create a ragdoll in the same frame that the player // changes their player model. CStudioHdr *pRagdollHdr = GetModelPtr(); CStudioHdr *pPlayerHdr = NULL; if ( pPlayer ) pPlayerHdr = pPlayer->GetModelPtr(); bool bChangedModel = false; if ( pRagdollHdr && pPlayerHdr ) { bChangedModel = pRagdollHdr->GetVirtualModel() != pPlayerHdr->GetVirtualModel(); Assert( !bChangedModel && "C_CFRagdoll::CreateRagdoll: Trying to create ragdoll with a different model than the player it's based on" ); } if ( pPlayer && !pPlayer->IsDormant() && !bChangedModel && pPlayerHdr ) { pPlayer->GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); } else { GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); } InitAsClientRagdoll( boneDelta0, boneDelta1, currentBones, boneDt ); } SetNextClientThink( CLIENT_THINK_ALWAYS ); }
bool CScriptedIconLesson::Mod_ProcessElementAction( int iAction, bool bNot, const char *pchVarName, EHANDLE &hVar, const CGameInstructorSymbol *pchParamName, float fParam, C_BaseEntity *pParam, const char *pchParam, bool &bModHandled ) { // Assume we're going to handle the action bModHandled = true; C_BaseEntity *pVar = hVar.Get(); switch ( iAction ) { case LESSON_ACTION_IS_ALLOWED_ITEM: { C_ASW_Marine *pMarine = NULL; C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar ); if ( pPlayer ) { pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() ); } if ( !pMarine ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->AllowedToPickup( [%s] )", pchParamName->String(), pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" ); } return false; } bool bIsAllowed = false; C_ASW_Pickup *pPickup = dynamic_cast< C_ASW_Pickup * >( pParam ); if ( !pPickup ) { C_ASW_Weapon *pWeapon = dynamic_cast< C_ASW_Weapon * >( pParam ); if ( !pWeapon ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->AllowedToPickup( [%s] )", pchParamName->String(), pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tParam handle as ASW_Weapon and ASW_Pickup returned NULL!\n" ); } return false; } else { bIsAllowed = pWeapon->AllowedToPickup( pMarine ); } } else { bIsAllowed = pPickup->AllowedToPickup( pMarine ); } if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->AllowedToPickup( [%s] )", pchParamName->String(), pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsAllowed ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bIsAllowed ) : ( bIsAllowed ); } case LESSON_ACTION_ITEM_WILL_SWAP: { C_ASW_Marine *pMarine = NULL; C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar ); if ( pPlayer ) { pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() ); } if ( !pMarine ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WillSwap( [%s] )", pchParamName->String(), pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" ); } return false; } bool bWillSwap = false; C_ASW_Pickup_Weapon *pPickup = dynamic_cast< C_ASW_Pickup_Weapon * >( pParam ); if ( !pPickup ) { C_ASW_Weapon *pWeapon = dynamic_cast< C_ASW_Weapon * >( pParam ); if ( !pWeapon ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WillSwap( [%s] )", pchParamName->String(), pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tParam handle as ASW_Weapon and ASW_Pickup returned NULL!\n" ); } return false; } else { int nSlot = pMarine->GetWeaponPositionForPickup( pWeapon->GetClassname() ); bWillSwap = ( pMarine->GetASWWeapon( nSlot ) != NULL ); } } else { int nSlot = pMarine->GetWeaponPositionForPickup( pPickup->GetWeaponClass() ); bWillSwap = ( pMarine->GetASWWeapon( nSlot ) != NULL ); } if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WillSwap( [%s] )", pchParamName->String(), pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bWillSwap ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bWillSwap ) : ( bWillSwap ); } case LESSON_ACTION_CAN_HACK: { C_ASW_Marine *pMarine = NULL; C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar ); if ( pPlayer ) { pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() ); } if ( !pMarine ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->CanHack()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" ); } return false; } bool bCanHack = pMarine->GetMarineProfile()->CanHack(); if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->AllowedToPickup()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bCanHack ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bCanHack ) : ( bCanHack ); } case LESSON_ACTION_CAN_OFFHAND: { C_ASW_Weapon *pWeapon = dynamic_cast< C_ASW_Weapon* >( pVar ); if ( !pWeapon ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->CanOffhand()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Weapon returned NULL!\n" ); } return false; } bool bCanOffhand = pWeapon->GetWeaponInfo()->m_bOffhandActivate; if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->CanOffhand()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bCanOffhand ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bCanOffhand ) : ( bCanOffhand ); } case LESSON_ACTION_HAS_SECONDARY: { C_ASW_Weapon *pWeapon = dynamic_cast< C_ASW_Weapon* >( pVar ); if ( !pWeapon ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasSecondary()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Weapon returned NULL!\n" ); } return false; } bool bHasSecondary = pWeapon->UsesSecondaryAmmo(); if ( bHasSecondary ) { bHasSecondary = !( ( pWeapon->UsesClipsForAmmo2() && pWeapon->m_iClip2 <= 0 ) || ( !pWeapon->UsesClipsForAmmo2() && pWeapon->GetOwner() && pWeapon->GetOwner()->GetAmmoCount( pWeapon->m_iSecondaryAmmoType ) <= 0 ) ); } if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasSecondary()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasSecondary ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bHasSecondary ) : ( bHasSecondary ); } case LESSON_ACTION_HAS_SECONDARY_EXPLOSIVES: { C_ASW_Marine *pMarine = NULL; C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar ); if ( pPlayer ) { pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() ); } if ( !pMarine ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasAnySecondary()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" ); } return false; } bool bHasAnySecondary = false; for ( int i = 0; i < ASW_MAX_EQUIP_SLOTS; ++i ) { C_ASW_Weapon *pWeapon = static_cast< C_ASW_Weapon* >( pMarine->GetWeapon( i ) ); if ( pWeapon && pWeapon->HasSecondaryExplosive() ) { if ( !( ( pWeapon->UsesClipsForAmmo2() && pWeapon->m_iClip2 <= 0 ) || ( !pWeapon->UsesClipsForAmmo2() && pWeapon->GetOwner() && pWeapon->GetOwner()->GetAmmoCount( pWeapon->m_iSecondaryAmmoType ) <= 0 ) ) ) { bHasAnySecondary = true; break; } } } if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasAnySecondary()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasAnySecondary ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bHasAnySecondary ) : ( bHasAnySecondary ); } case LESSON_ACTION_GET_MARINE: { int iTemp = static_cast<int>( fParam ); if ( iTemp <= 0 || iTemp > 2 ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[entityINVALID] = [%s]->GetMarine()\n", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tParam selecting string is out of range!\n" ); } return false; } CHandle<C_BaseEntity> *pHandle; char const *pchParamNameTemp = NULL; if ( iTemp == 2 ) { pHandle = &m_hEntity2; pchParamNameTemp = "entity2"; } else { pHandle = &m_hEntity1; pchParamNameTemp = "entity1"; } C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar ); if ( !pPlayer ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s] = [%s]->GetMarine()", pchParamNameTemp, pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "...\n" ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Player returned NULL!\n" ); } return false; } C_ASW_Marine *pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() ); pHandle->Set( pMarine ); if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s] = [%s]->GetMarine()\n", pchParamNameTemp, pchVarName ); } return true; } case LESSON_ACTION_IS_BOT: { C_ASW_Marine *pMarine = dynamic_cast< C_ASW_Marine* >( pVar ); if ( !pMarine ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t![%s]->IsInhabited()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" ); } return false; } bool bIsBot = !pMarine->IsInhabited(); if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t![%s]->IsInhabited()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsBot ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bIsBot ) : ( bIsBot ); } case LESSON_ACTION_WEAPON_HAS_SPARE: { C_ASW_Marine *pMarine = NULL; C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar ); if ( pPlayer ) { pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() ); } if ( !pMarine ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasSpareWeapon()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" ); } return false; } int nOffensiveWeaponCount = 0; for ( int i = 0; i < ASW_MAX_EQUIP_SLOTS; ++i ) { C_ASW_Weapon *pWeapon = static_cast< C_ASW_Weapon* >( pMarine->GetWeapon( i ) ); if ( pWeapon && pWeapon->IsOffensiveWeapon() ) { if ( !( ( pWeapon->UsesClipsForAmmo1() && pWeapon->m_iClip1 <= 0 ) || ( !pWeapon->UsesClipsForAmmo1() && pWeapon->GetOwner() && pWeapon->GetOwner()->GetAmmoCount( pWeapon->m_iPrimaryAmmoType ) <= 0 ) ) ) { nOffensiveWeaponCount++; } } } bool bHasSpare = ( nOffensiveWeaponCount > 1 ); if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->HasSpareWeapon()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bHasSpare ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bHasSpare ) : ( bHasSpare ); } case LESSON_ACTION_WEAPON_IS_OFFENSIVE: { C_ASW_Marine *pMarine = NULL; C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar ); if ( pPlayer ) { pMarine = dynamic_cast< C_ASW_Marine* >( pPlayer->GetMarine() ); } if ( !pMarine ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WeaponIsOffensive()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Marine returned NULL!\n" ); } return false; } bool bIsOffensive = false; C_ASW_Weapon *pWeapon = pMarine->GetActiveASWWeapon(); if ( pWeapon && pWeapon->IsOffensiveWeapon() ) { if ( !( ( pWeapon->UsesClipsForAmmo1() && pWeapon->m_iClip1 <= 0 ) || ( !pWeapon->UsesClipsForAmmo1() && pWeapon->GetOwner() && pWeapon->GetOwner()->GetAmmoCount( pWeapon->m_iPrimaryAmmoType ) <= 0 ) ) ) { bIsOffensive = true; } } if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WeaponIsOffensive()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsOffensive ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bIsOffensive ) : ( bIsOffensive ); } case LESSON_ACTION_WEAPON_LOCAL_HOTBAR_SLOT: { CASW_Hud_Master *pHUDMaster = GET_HUDELEMENT( CASW_Hud_Master ); if ( pHUDMaster ) { m_fOutput = pHUDMaster->GetHotBarSlot( pchParam ); if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tm_fOutput = GET_HUDELEMENT( CASW_Hud_Squad_Hotbar )->GetHotBarSlot( [%s] ", pchParamName->String() ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "\"%s\"", pchParam ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ")\n" ); } } return true; } case LESSON_ACTION_OWNS_HOTBAR_SLOT: { int iTemp = static_cast<int>( fParam ); C_ASW_Player *pPlayer = dynamic_cast< C_ASW_Player* >( pVar ); if ( !pPlayer ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tGET_HUDELEMENT( CASW_Hud_Squad_Hotbar )->OwnsHotBarSlot( [%s] ", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "..." ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ", [%s] ", pchParamName->String() ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "\"%i\" ", iTemp ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ") " ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Player returned NULL!\n" ); } return false; } bool bOwnsHotBarSlot = false; CASW_Hud_Master *pHUDMaster = GET_HUDELEMENT( CASW_Hud_Master ); if ( pHUDMaster ) { bOwnsHotBarSlot = pHUDMaster->OwnsHotBarSlot( pPlayer, iTemp ); if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tGET_HUDELEMENT( CASW_Hud_Squad_Hotbar )->OwnsHotBarSlot( [%s], [%s] ", pchVarName, pchParamName->String() ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "\"%i\" ", iTemp ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ") " ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bOwnsHotBarSlot ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } } return ( bNot ) ? ( !bOwnsHotBarSlot ) : ( bOwnsHotBarSlot ); } case LESSON_ACTION_SENTRY_WANTS_DISMANTLE: { C_ASW_Sentry_Base *pSentry = dynamic_cast< C_ASW_Sentry_Base* >( pVar ); if ( !pSentry ) { if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WantsDismantle()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "... " ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); ConColorMsg( CBaseLesson::m_rgbaVerboseClose, "\tVar handle as ASW_Sentry_Base returned NULL!\n" ); } return false; } bool bWantsDismantle = pSentry->WantsDismantle(); if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->WantsDismantle()", pchVarName ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bWantsDismantle ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bWantsDismantle ) : ( bWantsDismantle ); } case LESSON_ACTION_IS_TUTORIAL: { bool bIsTutorial = ASWGameRules()->IsTutorialMap(); if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tASWGameRules()->IsTutorialMap()" ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsTutorial ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bIsTutorial ) : ( bIsTutorial ); } case LESSON_ACTION_IS_SINGLEPLAYER: { bool bIsSingleplayer = ASWGameRules()->IsOfflineGame(); if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() ) { ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\tASWGameRules()->IsOfflineGame()" ); ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%s ", ( bIsSingleplayer ? "true" : "false" ) ); ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( "== false\n" ) : ( "== true\n" ) ); } return ( bNot ) ? ( !bIsSingleplayer ) : ( bIsSingleplayer ); } default: // Didn't handle this action bModHandled = false; break; } return false; }
//----------------------------------------------------------------------------- // Purpose: Input handler for making the explosion explode. //----------------------------------------------------------------------------- void CEnvExplosion::InputExplode( inputdata_t &inputdata ) { trace_t tr; SetModelName( NULL_STRING );//invisible SetSolid( SOLID_NONE );// intangible Vector vecSpot = GetAbsOrigin() + Vector( 0 , 0 , 8 ); UTIL_TraceLine( vecSpot, vecSpot + Vector( 0, 0, -40 ), (MASK_SOLID_BRUSHONLY | MASK_WATER), this, COLLISION_GROUP_NONE, &tr ); // Pull out of the wall a bit. We used to move the explosion origin itself, but that seems unnecessary, not to mention a // little weird when you consider that it might be in hierarchy. Instead we just calculate a new virtual position at // which to place the explosion. We don't use that new position to calculate radius damage because according to Steve's // comment, that adversely affects the force vector imparted on explosion victims when they ragdoll. Vector vecExplodeOrigin = GetAbsOrigin(); if ( tr.fraction != 1.0 ) { vecExplodeOrigin = tr.endpos + (tr.plane.normal * 24 ); } // draw decal if (! ( m_spawnflags & SF_ENVEXPLOSION_NODECAL)) { UTIL_DecalTrace( &tr, "Scorch" ); } // It's stupid that this entity's spawnflags and the flags for the // explosion temp ent don't match up. But because they don't, we // have to reinterpret some of the spawnflags to determine which // flags to pass to the temp ent. int nFlags = TE_EXPLFLAG_NONE; if( m_spawnflags & SF_ENVEXPLOSION_NOFIREBALL ) { nFlags |= TE_EXPLFLAG_NOFIREBALL; } if( m_spawnflags & SF_ENVEXPLOSION_NOSOUND ) { nFlags |= TE_EXPLFLAG_NOSOUND; } if ( m_spawnflags & SF_ENVEXPLOSION_RND_ORIENT ) { nFlags |= TE_EXPLFLAG_ROTATE; } if ( m_nRenderMode == kRenderTransAlpha ) { nFlags |= TE_EXPLFLAG_DRAWALPHA; } else if ( m_nRenderMode != kRenderTransAdd ) { nFlags |= TE_EXPLFLAG_NOADDITIVE; } if( m_spawnflags & SF_ENVEXPLOSION_NOPARTICLES ) { nFlags |= TE_EXPLFLAG_NOPARTICLES; } if( m_spawnflags & SF_ENVEXPLOSION_NODLIGHTS ) { nFlags |= TE_EXPLFLAG_NODLIGHTS; } if ( m_spawnflags & SF_ENVEXPLOSION_NOFIREBALLSMOKE ) { nFlags |= TE_EXPLFLAG_NOFIREBALLSMOKE; } //Get the damage override if specified int iRadius = ( m_iRadiusOverride > 0 ) ? m_iRadiusOverride : ( m_iMagnitude * 2.5f ); CPASFilter filter( vecExplodeOrigin ); te->Explosion( filter, 0.0, &vecExplodeOrigin, ( m_sFireballSprite < 1 ) ? g_sModelIndexFireball : m_sFireballSprite, !( m_spawnflags & SF_ENVEXPLOSION_NOFIREBALL ) ? ( m_spriteScale / 10.0 ) : 0.0, 15, nFlags, iRadius, m_iMagnitude ); // do damage if ( !( m_spawnflags & SF_ENVEXPLOSION_NODAMAGE ) ) { CBaseEntity *pAttacker = GetOwnerEntity() ? GetOwnerEntity() : this; // Only calculate damage type if we didn't get a custom one passed in int iDamageType = m_iCustomDamageType; if ( iDamageType == -1 ) { iDamageType = HasSpawnFlags( SF_ENVEXPLOSION_GENERIC_DAMAGE ) ? DMG_GENERIC : DMG_BLAST; } CTakeDamageInfo info( m_hInflictor ? m_hInflictor : this, pAttacker, m_iMagnitude, iDamageType ); if( HasSpawnFlags( SF_ENVEXPLOSION_SURFACEONLY ) ) { info.AddDamageType( DMG_BLAST_SURFACE ); } if ( m_flDamageForce ) { // Not the right direction, but it'll be fixed up by RadiusDamage. info.SetDamagePosition( GetAbsOrigin() ); info.SetDamageForce( Vector( m_flDamageForce, 0, 0 ) ); } RadiusDamage( info, GetAbsOrigin(), iRadius, m_iClassIgnore, m_hEntityIgnore.Get() ); } SetThink( &CEnvExplosion::Smoke ); SetNextThink( gpGlobals->curtime + 0.3 ); // Only do these effects if we're not submerged if ( UTIL_PointContents( GetAbsOrigin() ) & CONTENTS_WATER ) { // draw sparks if ( !( m_spawnflags & SF_ENVEXPLOSION_NOSPARKS ) ) { int sparkCount = random->RandomInt(0,3); for ( int i = 0; i < sparkCount; i++ ) { QAngle angles; VectorAngles( tr.plane.normal, angles ); Create( "spark_shower", vecExplodeOrigin, angles, NULL ); } } } }
//----------------------------------------------------------------------------- // Returns the ent index //----------------------------------------------------------------------------- inline int CSoundPatch::EntIndex() const { Assert( !m_hEnt.IsValid() || m_hEnt.Get() ); return m_hEnt.Get() ? m_hEnt->entindex() : -1; }
void C_NEORagdoll::CreateNEORagdoll() { // First, initialize all our data. If we have the player's entity on our client, // then we can make ourselves start out exactly where the player is. C_NEOPlayer *pPlayer = dynamic_cast<C_NEOPlayer*>(m_hPlayer.Get()); if ( pPlayer && !pPlayer->IsDormant() ) { pPlayer->SnatchModelInstance( this ); VarMapping_t *varMap = GetVarMapping(); // Copy all the interpolated vars from the player entity. // The entity uses the interpolated history to get bone velocity. bool bRemotePlayer = (pPlayer != C_BasePlayer::GetLocalPlayer()); if ( bRemotePlayer ) { Interp_Copy( pPlayer ); SetAbsAngles( pPlayer->GetRenderAngles() ); GetRotationInterpolator().Reset(); m_flAnimTime = pPlayer->m_flAnimTime; SetSequence( pPlayer->GetSequence() ); m_flPlaybackRate = pPlayer->GetPlaybackRate(); } else { // This is the local player, so set them in a default // pose and slam their velocity, angles and origin SetAbsOrigin( m_vecRagdollOrigin ); SetAbsAngles( pPlayer->GetRenderAngles() ); SetAbsVelocity( m_vecRagdollVelocity ); int iSeq = LookupSequence( "walk_lower" ); if ( iSeq == -1 ) { Assert( false ); // missing walk_lower? iSeq = 0; } SetSequence( iSeq ); // walk_lower, basic pose SetCycle( 0.0 ); Interp_Reset( varMap ); pPlayer->m_bIsOnDeathScreen = true; // Only these were added pPlayer->m_fRagdollCreationTime = gpGlobals->curtime; } } else { // overwrite network origin so later interpolation will // use this position SetNetworkOrigin( m_vecRagdollOrigin ); SetAbsOrigin( m_vecRagdollOrigin ); SetAbsVelocity( m_vecRagdollVelocity ); Interp_Reset( GetVarMapping() ); } SetModelByIndex( GetModelIndex() ); // Make us a ragdoll.. m_nRenderFX = kRenderFxRagdoll; matrix3x4_t boneDelta0[ MAXSTUDIOBONES ]; matrix3x4_t boneDelta1[ MAXSTUDIOBONES ]; matrix3x4_t currentBones[ MAXSTUDIOBONES ]; const float boneDt = 0.05f; if ( pPlayer && !pPlayer->IsDormant() ) { pPlayer->GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); } else { GetRagdollInitBoneArrays( boneDelta0, boneDelta1, currentBones, boneDt ); } InitAsClientRagdoll( boneDelta0, boneDelta1, currentBones, boneDt ); }
//----------------------------------------------------------------------------- // Purpose: Attaches fire to the hitboxes of an animating character. The fire // is distributed based on hitbox volumes -- it attaches to the larger // hitboxes first. //----------------------------------------------------------------------------- void C_EntityFlame::AttachToHitBoxes( void ) { m_pCachedModel = NULL; C_BaseCombatCharacter *pAnimating = (C_BaseCombatCharacter *)m_hEntAttached.Get(); if (!pAnimating || !pAnimating->GetModel()) { return; } studiohdr_t *pStudioHdr = modelinfo->GetStudiomodel( pAnimating->GetModel() ); if (!pStudioHdr) { return; } mstudiohitboxset_t *set = pStudioHdr->pHitboxSet( pAnimating->m_nHitboxSet ); if ( !set ) { return; } if ( !set->numhitboxes ) { return; } m_pCachedModel = pAnimating->GetModel(); int boneMask = BONE_USED_BY_HITBOX | BONE_USED_BY_ATTACHMENT; studiocache_t *pcache = Studio_GetBoneCache( pStudioHdr, pAnimating->GetSequence(), pAnimating->m_flAnimTime, pAnimating->GetAbsAngles(), pAnimating->GetAbsOrigin(), boneMask ); if ( !pcache ) { matrix3x4_t bonetoworld[MAXSTUDIOBONES]; pAnimating->SetupBones( bonetoworld, MAXSTUDIOBONES, boneMask, gpGlobals->curtime ); pcache = Studio_SetBoneCache( pStudioHdr, pAnimating->GetSequence(), pAnimating->m_flAnimTime, pAnimating->GetAbsAngles(), pAnimating->GetAbsOrigin(), boneMask, bonetoworld ); } matrix3x4_t *hitboxbones[MAXSTUDIOBONES]; Studio_LinkHitboxCache( hitboxbones, pcache, pStudioHdr, set ); // // Sort the hitboxes by volume. // HitboxVolume_t hitboxvolume[MAXSTUDIOBONES]; for ( int i = 0; i < set->numhitboxes; i++ ) { mstudiobbox_t *pBox = set->pHitbox(i); hitboxvolume[i].nIndex = i; hitboxvolume[i].flVolume = CalcBoxVolume(pBox->bbmin, pBox->bbmax); } qsort(hitboxvolume, set->numhitboxes, sizeof(hitboxvolume[0]), (int (__cdecl *)(const void *, const void *))SortHitboxVolumes); // // Attach fire to the hitboxes. // for ( i = 0; i < NUM_HITBOX_FIRES; i++ ) { // // Pick the 5 biggest hitboxes, or random ones if there are less than 5 hitboxes, // then pick random ones after that. // if (( i < 5 ) && ( i < set->numhitboxes )) { m_nHitbox[i] = hitboxvolume[i].nIndex; } else { m_nHitbox[i] = random->RandomInt( 0, set->numhitboxes - 1 ); } mstudiobbox_t *pBox = set->pHitbox(m_nHitbox[i]); m_pFireSmoke[i] = new C_FireSmoke; // // Calculate a position within the hitbox to place the fire. // m_vecFireOrigin[i] = Vector(random->RandomFloat(pBox->bbmin.x, pBox->bbmax.x), random->RandomFloat(pBox->bbmin.y, pBox->bbmax.y), random->RandomFloat(pBox->bbmin.z, pBox->bbmax.z)); Vector vecAbsOrigin; VectorTransform(m_vecFireOrigin[i], *hitboxbones[m_nHitbox[i]], vecAbsOrigin); m_pFireSmoke[i]->SetLocalOrigin( vecAbsOrigin ); // // The first 2 fires emit smoke, the rest do not. // m_pFireSmoke[i]->m_nFlags = bitsFIRESMOKE_ACTIVE | bitsFIRESMOKE_GLOW; if ( i < 2 ) { m_pFireSmoke[i]->m_nFlags |= bitsFIRESMOKE_SMOKE; } m_pFireSmoke[i]->m_nFlameModelIndex = modelinfo->GetModelIndex("sprites/fire1.vmt"); m_pFireSmoke[i]->m_flScale = 0; m_pFireSmoke[i]->m_flStartScale = 0; m_pFireSmoke[i]->m_flScaleTime = 1.5; m_pFireSmoke[i]->m_flScaleRegister = 0.1; m_pFireSmoke[i]->m_flChildFlameSpread = 20.0; m_pFireSmoke[i]->m_flScaleStart = 0; m_pFireSmoke[i]->m_flScaleEnd = 0.00012f * hitboxvolume[i].flVolume; m_pFireSmoke[i]->m_flScaleTimeStart = Helper_GetTime(); m_pFireSmoke[i]->m_flScaleTimeEnd = Helper_GetTime() + 2.0; m_pFireSmoke[i]->StartClientOnly(); } m_bAttachedToHitboxes = true; }
void C_StriderRagdoll::CreateStriderRagdoll( void ) { // First, initialize all our data. If we have the player's entity on our client, // then we can make ourselves start out exactly where the player is. C_QUA_Strider *pStrider = dynamic_cast< C_QUA_Strider* >( m_hStrider.Get()); if ( pStrider) { // move my current model instance to the ragdoll's so decals are preserved. pStrider->SnatchModelInstance( this ); VarMapping_t *varMap = GetVarMapping(); // Copy all the interpolated vars from the player entity. // The entity uses the interpolated history to get bone velocity. /*bool bRemotePlayer = (pPlayer != C_BasePlayer::GetLocalPlayer()); if ( bRemotePlayer ) {*/ Interp_Copy( varMap, this, pStrider, pStrider->C_BaseAnimating::GetVarMapping() ); SetAbsAngles( pStrider->GetRenderAngles() ); GetRotationInterpolator().Reset(); m_flAnimTime = pStrider->m_flAnimTime; SetSequence( pStrider->GetSequence() ); m_flPlaybackRate = pStrider->GetPlaybackRate(); SetPoseParameter(LookupPoseParameter("body_height"),200.0f); /*} else {*/ // This is the local player, so set them in a default // pose and slam their velocity, angles and origin // SetAbsOrigin( m_vecRagdollOrigin ); // // SetAbsAngles( pPlayer->GetRenderAngles() ); // SetAbsVelocity( m_vecRagdollVelocity ); // int iSeq = pPlayer->GetSequence(); // if ( iSeq == -1 ) // { // Assert( false ); // missing walk_lower? // iSeq = 0; // } // // SetSequence( iSeq ); // walk_lower, basic pose // SetCycle( 0.0 ); // Interp_Reset( varMap ); //} } else { // overwrite network origin so later interpolation will // use this position SetNetworkOrigin( m_vecRagdollOrigin ); SetAbsOrigin( m_vecRagdollOrigin ); SetAbsVelocity( m_vecRagdollVelocity ); SetSequence(LookupSequence("idle01")); SetPoseParameter(LookupPoseParameter("body_height"),m_fAltura); Interp_Reset( GetVarMapping() ); } SetModelIndex( m_nModelIndex ); //engine->Con_NPrintf(27,"Le volvemos a poner de altura: %f",m_fAltura); SetPoseParameter(LookupPoseParameter("body_height"),200.0f); // Make us a ragdoll.. m_nRenderFX = kRenderFxRagdoll; BecomeRagdollOnClient( /*false*/ ); //FixMe No? xd }
//------------------------------------------------------------------------------ // Purpose : //------------------------------------------------------------------------------ void CLookDoor::MoveThink(void) { // -------------------------------- // Make sure we have a looker // -------------------------------- if (m_hLooker == NULL) { m_hLooker = (CBaseEntity*)gEntList.FindEntityByName( NULL, m_target, NULL ); if (m_hLooker == NULL) { return; } } //-------------------------------------- // Calculate an orgin for the door //-------------------------------------- Vector vOrigin = 0.5*(GetAbsMaxs() + GetAbsMins()) - GetAbsOrigin(); // If FROM_OPEN flag is set, door proximity is measured // from the open and not the closed position if (FBitSet (m_spawnflags, SF_LDOOR_FROM_OPEN)) { vOrigin += m_vecPosition2; } // ------------------------------------------------------ // First add movement based on proximity // ------------------------------------------------------ float flProxMove = 0; if (m_flProximityDistance > 0) { float flDist = (m_hLooker->GetAbsOrigin() - vOrigin).Length()-m_flProximityOffset; if (flDist < 0) flDist = 0; if (flDist < m_flProximityDistance) { if (FBitSet (m_spawnflags, SF_LDOOR_THRESHOLD)) { flProxMove = 1.0; } else { flProxMove = 1-flDist/m_flProximityDistance; } } } // ------------------------------------------------------ // Then add movement based on view angle // ------------------------------------------------------ float flViewMove = 0; if (m_flFieldOfView > 0) { // ---------------------------------------- // Check that toucher is facing the target // ---------------------------------------- Assert( dynamic_cast< CBaseCombatCharacter* >( m_hLooker.Get() ) ); CBaseCombatCharacter* pBCC = (CBaseCombatCharacter*)m_hLooker.Get(); Vector vTouchDir = pBCC->EyeDirection3D( ); Vector vTargetDir = vOrigin - pBCC->EyePosition(); VectorNormalize(vTargetDir); float flDotPr = DotProduct(vTouchDir,vTargetDir); if (flDotPr < m_flFieldOfView) { flViewMove = 0.0; } else { flViewMove = (flDotPr-m_flFieldOfView)/(1.0 - m_flFieldOfView); } } //--------------------------------------- // Summate the two moves //--------------------------------------- float flMove = flProxMove + flViewMove; if (flMove > 1.0) { flMove = 1.0; } // If behavior is inverted do the reverse if (FBitSet (m_spawnflags, SF_LDOOR_INVERT)) { flMove = 1-flMove; } // Move the door SetPosition( flMove ); }