//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CNPC_CombineCamera::DrawDebugGeometryOverlays(void) { // ------------------------------ // Draw viewcone if selected // ------------------------------ if ((m_debugOverlays & OVERLAY_NPC_VIEWCONE_BIT)) { float flViewRange = acos(CAMERA_FOV_NARROW); Vector vEyeDir = EyeDirection2D( ); Vector vLeftDir, vRightDir; float fSin, fCos; SinCos( flViewRange, &fSin, &fCos ); vLeftDir.x = vEyeDir.x * fCos - vEyeDir.y * fSin; vLeftDir.y = vEyeDir.x * fSin + vEyeDir.y * fCos; vLeftDir.z = vEyeDir.z; fSin = sin(-flViewRange); fCos = cos(-flViewRange); vRightDir.x = vEyeDir.x * fCos - vEyeDir.y * fSin; vRightDir.y = vEyeDir.x * fSin + vEyeDir.y * fCos; vRightDir.z = vEyeDir.z; NDebugOverlay::BoxDirection(EyePosition(), Vector(0,0,-40), Vector(200,0,40), vLeftDir, 255, 255, 0, 50, 0 ); NDebugOverlay::BoxDirection(EyePosition(), Vector(0,0,-40), Vector(200,0,40), vRightDir, 255, 255, 0, 50, 0 ); NDebugOverlay::Box(EyePosition(), -Vector(2,2,2), Vector(2,2,2), 255, 255, 0, 128, 0 ); } BaseClass::DrawDebugGeometryOverlays(); }
bool CBaseCombatCharacter::IsLineOfSightClear( const Vector &pos, LineOfSightCheckType checkType, CBaseEntity *entityToIgnore ) const { #if defined(GAME_DLL) && defined(COUNT_BCC_LOS) static int count, frame; if ( frame != gpGlobals->framecount ) { Msg( ">> %d\n", count ); frame = gpGlobals->framecount; count = 0; } count++; #endif if( checkType == IGNORE_ACTORS ) { // use the query cache unless it causes problems trace_t trace; CTraceFilterNoCombatCharacters traceFilter( entityToIgnore, COLLISION_GROUP_NONE ); UTIL_TraceLine( EyePosition(), pos, MASK_OPAQUE | CONTENTS_IGNORE_NODRAW_OPAQUE | CONTENTS_MONSTER, &traceFilter, &trace ); return trace.fraction == 1.0f; } else { trace_t trace; CTraceFilterSkipTwoEntities traceFilter( this, entityToIgnore, COLLISION_GROUP_NONE ); UTIL_TraceLine( EyePosition(), pos, MASK_OPAQUE | CONTENTS_IGNORE_NODRAW_OPAQUE, &traceFilter, &trace ); return trace.fraction == 1.0f; } }
//----------------------------------------------------------------------------- // Purpose: Sparks and fizzes to show it's broken. //----------------------------------------------------------------------------- void CNPC_RocketTurret::DeathThink( void ) { Vector vForward; AngleVectors( m_vecCurrentAngles, &vForward, NULL, NULL ); m_iLaserState = 0; SetEnemy( NULL ); g_pEffects->Sparks( EyePosition(), 1, 1, &vForward ); g_pEffects->Smoke( EyePosition(), 0, 6.0f, 20 ); SetNextThink( gpGlobals->curtime + RandomFloat( 2.0f, 8.0f ) ); }
void C_CFPlayer::PostThink() { if ( IsAlive() && (GetFlags() & FL_ONGROUND) && m_bPowerjump ) StopPowerjump(); BaseClass::PostThink(); Instructor_Think(); for (int i = 1; i < gpGlobals->maxClients; i++) { C_BasePlayer *pPlayer = UTIL_PlayerByIndex( i ); if (!pPlayer) continue; C_CFPlayer* pCFPlayer = ToCFPlayer(pPlayer); if (CFGameRules()->PlayerRelationship(this, pCFPlayer) == GR_TEAMMATE) continue; // Far enemies are not important. if ((EyePosition() - pCFPlayer->WorldSpaceCenter()).Length() > 500) continue; trace_t result; CTraceFilterNoNPCsOrPlayer traceFilter( NULL, COLLISION_GROUP_NONE ); UTIL_TraceLine( EyePosition(), pCFPlayer->WorldSpaceCenter(), MASK_VISIBLE_AND_NPCS, &traceFilter, &result ); if (result.fraction != 1.0f) //if (!pPlayer->IsVisible(pCFTarget)) // This is unfortunately a server-only function, though I'd love to use it here. continue; m_flLastEnemySeen = gpGlobals->curtime; break; } if (!IsInFollowMode() || !ShouldLockFollowModeView()) { Vector vecForward; GetVectors(&vecForward, NULL, NULL); if (m_flLastCameraTargetTime == 0) { if (!GetRecursedTarget()) m_hLastCameraTarget = NULL; m_vecLastCameraTarget = m_vecLastTargetPosition = EyePosition() + vecForward*100; } } }
void C_HL2MP_Player::CalcView( Vector &eyeOrigin, QAngle &eyeAngles, float &zNear, float &zFar, float &fov ) { // third or first person ragdolls if ( m_lifeState != LIFE_ALIVE && !IsObserver() ) { // First person ragdolls if ( cl_fp_ragdoll.GetBool() && m_hRagdoll.Get() ) { // pointer to the ragdoll C_HL2MPRagdoll *pRagdoll = (C_HL2MPRagdoll*)m_hRagdoll.Get(); // gets its origin and angles pRagdoll->GetAttachment( pRagdoll->LookupAttachment( "eyes" ), eyeOrigin, eyeAngles ); Vector vForward; AngleVectors( eyeAngles, &vForward ); if ( cl_fp_ragdoll_auto.GetBool() ) { // DM: Don't use first person view when we are very close to something trace_t tr; UTIL_TraceLine( eyeOrigin, eyeOrigin + ( vForward * 10000 ), MASK_ALL, pRagdoll, COLLISION_GROUP_NONE, &tr ); if ( (!(tr.fraction < 1) || (tr.endpos.DistTo(eyeOrigin) > 25)) ) return; } else return; } eyeOrigin = vec3_origin; eyeAngles = vec3_angle; Vector origin = EyePosition(); IRagdoll *pRagdoll = GetRepresentativeRagdoll(); if ( pRagdoll ) { origin = pRagdoll->GetRagdollOrigin(); origin.z += VEC_DEAD_VIEWHEIGHT.z; // look over ragdoll, not through } BaseClass::CalcView( eyeOrigin, eyeAngles, zNear, zFar, fov ); eyeOrigin = origin; Vector vForward; AngleVectors( eyeAngles, &vForward ); VectorNormalize( vForward ); VectorMA( origin, -CHASE_CAM_DISTANCE, vForward, eyeOrigin ); Vector WALL_MIN( -WALL_OFFSET, -WALL_OFFSET, -WALL_OFFSET ); Vector WALL_MAX( WALL_OFFSET, WALL_OFFSET, WALL_OFFSET ); trace_t trace; // clip against world // HACK don't recompute positions while doing RayTrace C_BaseEntity::EnableAbsRecomputations( false ); UTIL_TraceHull( origin, eyeOrigin, WALL_MIN, WALL_MAX, MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &trace ); C_BaseEntity::EnableAbsRecomputations( true ); if (trace.fraction < 1.0) { eyeOrigin = trace.endpos; } return; } BaseClass::CalcView( eyeOrigin, eyeAngles, zNear, zFar, fov ); }
void CBasePlayer::CalcObserverView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov ) { #if defined( CLIENT_DLL ) switch ( GetObserverMode() ) { case OBS_MODE_DEATHCAM : CalcDeathCamView( eyeOrigin, eyeAngles, fov ); break; case OBS_MODE_ROAMING : // just copy current position without view offset case OBS_MODE_FIXED : CalcRoamingView( eyeOrigin, eyeAngles, fov ); break; case OBS_MODE_IN_EYE : CalcInEyeCamView( eyeOrigin, eyeAngles, fov ); break; case OBS_MODE_CHASE : CalcChaseCamView( eyeOrigin, eyeAngles, fov ); break; case OBS_MODE_FREEZECAM : CalcFreezeCamView( eyeOrigin, eyeAngles, fov ); break; } #else // on server just copy target postions, final view positions will be calculated on client VectorCopy( EyePosition(), eyeOrigin ); VectorCopy( EyeAngles(), eyeAngles ); #endif }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- bool CBaseCombatCharacter::IsAbleToSee( const CBaseEntity *pEntity, FieldOfViewCheckType checkFOV ) { CBaseCombatCharacter *pBCC = const_cast<CBaseEntity *>( pEntity )->MyCombatCharacterPointer(); if ( pBCC ) return IsAbleToSee( pBCC, checkFOV ); // Test this every time; it's cheap. Vector vecEyePosition = EyePosition(); Vector vecTargetPosition = pEntity->WorldSpaceCenter(); #ifdef GAME_DLL Vector vecEyeToTarget; VectorSubtract( vecTargetPosition, vecEyePosition, vecEyeToTarget ); float flDistToOther = VectorNormalize( vecEyeToTarget ); // We can't see because they are too far in the fog if ( IsHiddenByFog( flDistToOther ) ) return false; #endif if ( !ComputeLOS( vecEyePosition, vecTargetPosition ) ) return false; return ( checkFOV != USE_FOV || IsInFieldOfView( vecTargetPosition ) ); }
void C_NEOPlayer::UpdateInCross() { if ( !IsLocalNEOPlayer() ) return; m_iInCrossIndex = 0; m_bAnyoneInCross = false; Vector forward; GetEyeVectors( &forward, nullptr, nullptr ); Vector eyes = EyePosition(); Vector start = eyes + forward * 10.f; Vector end = eyes + forward * 1500.f; trace_t trace; UTIL_TraceLine( start, end, CONTENTS_LADDER | CONTENTS_MOVEABLE | CONTENTS_GRATE | CONTENTS_AUX | CONTENTS_WINDOW | CONTENTS_SOLID, this, 0, &trace ); if ( !trace.startsolid && trace.DidHitNonWorldEntity() && trace.m_pEnt ) { if ( trace.m_pEnt != this && trace.m_pEnt->IsPlayer() && trace.m_pEnt->GetTeamNumber() == this->GetTeamNumber() ) { m_iInCrossIndex = trace.m_pEnt->entindex(); m_bAnyoneInCross = true; } } }
/** Returns true if we are looking towards something within a tolerence determined by our field of view */ bool CBaseCombatCharacter::IsInFieldOfView( CBaseEntity *entity ) const { CBasePlayer *pPlayer = ToBasePlayer( const_cast< CBaseCombatCharacter* >( this ) ); float flTolerance = pPlayer ? cos( (float)pPlayer->GetFOV() * 0.5f ) : BCC_DEFAULT_LOOK_TOWARDS_TOLERANCE; Vector vecForward; Vector vecEyePosition = EyePosition(); AngleVectors( EyeAngles(), &vecForward ); // FIXME: Use a faster check than this! // Check 3 spots, or else when standing right next to someone looking at their eyes, // the angle will be too great to see their center. Vector vecToTarget = entity->GetAbsOrigin() - vecEyePosition; vecToTarget.NormalizeInPlace(); if ( DotProduct( vecForward, vecToTarget ) >= flTolerance ) return true; vecToTarget = entity->WorldSpaceCenter() - vecEyePosition; vecToTarget.NormalizeInPlace(); if ( DotProduct( vecForward, vecToTarget ) >= flTolerance ) return true; vecToTarget = entity->EyePosition() - vecEyePosition; vecToTarget.NormalizeInPlace(); return ( DotProduct( vecForward, vecToTarget ) >= flTolerance ); }
void C_CFPlayer::CalcInEyeCamView(Vector& eyeOrigin, QAngle& eyeAngles, float& fov) { C_CFPlayer *pTarget = ToCFPlayer(GetObserverTarget()); if ( !pTarget ) { // just copy a save in-map position VectorCopy( EyePosition(), eyeOrigin ); VectorCopy( EyeAngles(), eyeAngles ); return; }; if ( pTarget->ShouldForceThirdPerson() ) { CalcChaseCamView( eyeOrigin, eyeAngles, fov ); return; } fov = GetFOV(); // TODO use tragets FOV m_flObserverChaseDistance = 0.0; eyeAngles = pTarget->EyeAngles(); eyeOrigin = pTarget->EyePosition(); // Apply punch angle VectorAdd( eyeAngles, GetPunchAngle(), eyeAngles ); engine->SetViewAngles( eyeAngles ); }
Vector CBasePlayer::Weapon_ShootPosition( ) { Vector shootPosition; VectorCopy(EyePosition(), shootPosition); shootPosition += weaponoffset; return shootPosition; }
//----------------------------------------------------------------------------- // Purpose: Input handler that makes the crow fly away. //----------------------------------------------------------------------------- void CNPC_Crow::InputFlyAway( inputdata_t &inputdata ) { string_t sTarget = MAKE_STRING( inputdata.value.String() ); if ( sTarget != NULL_STRING )// this npc has a target { CBaseEntity *pEnt = gEntList.FindEntityByName( NULL, sTarget ); if ( pEnt ) { trace_t tr; AI_TraceLine ( EyePosition(), pEnt->GetAbsOrigin(), MASK_NPCSOLID, this, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction != 1.0f ) return; // Find the npc's initial target entity, stash it SetGoalEnt( pEnt ); } } else SetGoalEnt( NULL ); SetCondition( COND_CROW_FORCED_FLY ); SetCondition( COND_PROVOKED ); }
//----------------------------------------------------------------------------- // Purpose: Find the center of the target entity as seen through the specified portal // Input : pPortal - The portal to look through // Output : Vector& output point in world space where the target *appears* to be as seen through the portal //----------------------------------------------------------------------------- bool CNPC_RocketTurret::FindAimPointThroughPortal( const CProp_Portal* pPortal, Vector* pVecOut ) { if ( pPortal && pPortal->m_bActivated ) { CProp_Portal* pLinked = pPortal->m_hLinkedPortal.Get(); CBaseEntity* pTarget = GetEnemy(); // Require that the portal is facing towards the beam to test through it Vector vRocketToPortal, vPortalForward; VectorSubtract ( pPortal->GetAbsOrigin(), EyePosition(), vRocketToPortal ); pPortal->GetVectors( &vPortalForward, NULL, NULL); float fDot = DotProduct( vRocketToPortal, vPortalForward ); // Portal must be facing the turret, and have a linked partner if ( fDot < 0.0f && pLinked && pLinked->m_bActivated && pTarget ) { VMatrix matToPortalView = pLinked->m_matrixThisToLinked; Vector vTargetAimPoint = pTarget->GetAbsOrigin() + (pTarget->WorldAlignMins() + pTarget->WorldAlignMaxs()) * 0.5f; *pVecOut = matToPortalView * vTargetAimPoint; return true; } } // Bad portal pointer, not linked, no target or otherwise failed return false; }
// here bot updates important info that is used multiple times along the thinking process void CSDKBot::InfoGathering() { if (!GetEnemy()) { m_flBotToEnemyDist = 9999; m_flHeightDifToEnemy = 0; m_bEnemyOnSights = false; m_flDistTraveled += fabs(GetLocalVelocity().Length()); // this is used for stuck checking, return; } m_flBotToEnemyDist = (GetLocalOrigin() - GetEnemy()->GetLocalOrigin()).Length(); trace_t tr; UTIL_TraceHull( EyePosition(), GetEnemy()->EyePosition() - Vector(0,0,20), -BotTestHull, BotTestHull, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr ); if( tr.m_pEnt == GetEnemy() ) // vision line between both m_bEnemyOnSights = true; else m_bEnemyOnSights = false; m_bInRangeToAttack = (m_flBotToEnemyDist < m_flMinRangeAttack) && FInViewCone( GetEnemy() ); m_flDistTraveled += fabs(GetLocalVelocity().Length()); // this is used for stuck checking, m_flHeightDifToEnemy = GetLocalOrigin().z - GetEnemy()->GetLocalOrigin().z; }
void CBasePlayer::CalcPlayerView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov ) { #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) { // FIXME: Move into prediction view->DriftPitch(); } #endif VectorCopy( EyePosition(), eyeOrigin ); #ifdef SIXENSE if ( g_pSixenseInput->IsEnabled() ) { VectorCopy( EyeAngles() + GetEyeAngleOffset(), eyeAngles ); } else { VectorCopy( EyeAngles(), eyeAngles ); } #else VectorCopy( EyeAngles(), eyeAngles ); #endif #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) #endif { SmoothViewOnStairs( eyeOrigin ); } // Snack off the origin before bob + water offset are applied Vector vecBaseEyePosition = eyeOrigin; CalcViewRoll( eyeAngles ); // Apply punch angle VectorAdd( eyeAngles, m_Local.m_vecPunchAngle, eyeAngles ); #if defined( CLIENT_DLL ) if ( !prediction->InPrediction() ) { // Shake it up baby! vieweffects->CalcShake(); vieweffects->ApplyShake( eyeOrigin, eyeAngles, 1.0 ); } #endif #if defined( CLIENT_DLL ) // Apply a smoothing offset to smooth out prediction errors. Vector vSmoothOffset; GetPredictionErrorSmoothingVector( vSmoothOffset ); eyeOrigin += vSmoothOffset; m_flObserverChaseDistance = 0.0; #endif // calc current FOV fov = GetFOV(); }
bool CEntity::FVisible(CEntity *pEntity) { // don't look through water if (IsInWater() != pEntity->IsInWater()) return false; return (TestLine(EyePosition(), pEntity->EyePosition(), true, pEntity).fraction >= 1.0); }
void CCSBot::UpdateLookAt() { Vector to = m_lookAtSpot - EyePosition(); Vector idealAngle = UTIL_VecToAngles(to); idealAngle.x = 360.0f - idealAngle.x; SetLookAngles(idealAngle.y, idealAngle.x); }
int CASW_Parasite::RangeAttack1Conditions( float flDot, float flDist ) { if ( gpGlobals->curtime < m_flNextAttack ) return 0; if ( ( GetFlags() & FL_ONGROUND ) == false ) return 0; // This code stops lots of headcrabs swarming you and blocking you // whilst jumping up and down in your face over and over. It forces // them to back up a bit. If this causes problems, consider using it // for the fast headcrabs only, rather than just removing it.(sjb) if ( flDist < ASW_PARASITE_MIN_JUMP_DIST ) return COND_TOO_CLOSE_TO_ATTACK; if ( flDist > ASW_PARASITE_MAX_JUMP_DIST ) return COND_TOO_FAR_TO_ATTACK; // Make sure the way is clear! CBaseEntity *pEnemy = GetEnemy(); if( pEnemy ) { bool bEnemyIsBullseye = ( dynamic_cast<CNPC_Bullseye *>(pEnemy) != NULL ); trace_t tr; AI_TraceLine( EyePosition(), pEnemy->EyePosition(), MASK_SOLID, this, COLLISION_GROUP_NONE, &tr ); if ( tr.m_pEnt != GetEnemy() ) { if ( !bEnemyIsBullseye || tr.m_pEnt != NULL ) return COND_NONE; } if( GetEnemy()->EyePosition().z - 36.0f > GetAbsOrigin().z ) { // Only run this test if trying to jump at a player who is higher up than me, else this // code will always prevent a headcrab from jumping down at an enemy, and sometimes prevent it // jumping just slightly up at an enemy. Vector vStartHullTrace = GetAbsOrigin(); vStartHullTrace.z += 1.0; Vector vEndHullTrace = GetEnemy()->EyePosition() - GetAbsOrigin(); vEndHullTrace.NormalizeInPlace(); vEndHullTrace *= 8.0; vEndHullTrace += GetAbsOrigin(); AI_TraceHull( vStartHullTrace, vEndHullTrace,GetHullMins(), GetHullMaxs(), MASK_NPCSOLID, this, GetCollisionGroup(), &tr ); if ( tr.m_pEnt != NULL && tr.m_pEnt != GetEnemy() ) { return COND_TOO_CLOSE_TO_ATTACK; } } } return COND_CAN_RANGE_ATTACK1; }
//----------------------------------------------------------------------------- // Purpose: // Input : eyeOrigin - // eyeAngles - // zNear - // zFar - // fov - //----------------------------------------------------------------------------- void CBasePlayer::CalcView( Vector &eyeOrigin, QAngle &eyeAngles, float &zNear, float &zFar, float &fov ) { eyeOrigin = EyePosition(); eyeAngles = EyeAngles(); #if defined( CLIENT_DLL ) Camera()->CalcView(eyeOrigin, eyeAngles, fov); #endif }
//========================================================= // FVisible - returns true if a line can be traced from // the caller's eyes to the target //========================================================= bool CEntity::FVisible(const Vector &vecDest) { // don't look through water if (IsLiquid(GetGunPosition()) != IsLiquid(vecDest)) return false; // check if line of sight to object is not blocked (i.e. visible) return (TestLine(EyePosition(), vecDest).fraction >= 1.0); }
//----------------------------------------------------------------------------- // Make sure our target is still valid, and if so, fire at it //----------------------------------------------------------------------------- void CObjectSentrygun::Attack() { StudioFrameAdvance( ); if ( !FindTarget() ) { m_iState.Set( SENTRY_STATE_SEARCHING ); m_hEnemy = NULL; return; } // Track enemy Vector vecMid = EyePosition(); Vector vecMidEnemy = m_hEnemy->WorldSpaceCenter(); Vector vecDirToEnemy = vecMidEnemy - vecMid; QAngle angToTarget; VectorAngles( vecDirToEnemy, angToTarget ); angToTarget.y = UTIL_AngleMod( angToTarget.y ); if (angToTarget.x < -180) angToTarget.x += 360; if (angToTarget.x > 180) angToTarget.x -= 360; // now all numbers should be in [1...360] // pin to turret limitations to [-50...50] if (angToTarget.x > 50) angToTarget.x = 50; else if (angToTarget.x < -50) angToTarget.x = -50; m_vecGoalAngles.y = angToTarget.y; m_vecGoalAngles.x = angToTarget.x; MoveTurret(); // Fire on the target if it's within 10 units of being aimed right at it if ( m_flNextAttack <= gpGlobals->curtime && (m_vecGoalAngles - m_vecCurAngles).Length() <= 10 ) { Fire(); if ( m_iUpgradeLevel == 1 ) { // Level 1 sentries fire slower m_flNextAttack = gpGlobals->curtime + 0.2; } else { m_flNextAttack = gpGlobals->curtime + 0.1; } } else { // SetSentryAnim( TFTURRET_ANIM_SPIN ); } }
//========================================================= // FVisible - returns true if a line can be traced from // the caller's eyes to the target vector //========================================================= BOOL CBaseEntity :: FVisible ( const Vector &vecOrigin ) { TraceResult tr; Vector vecLookerOrigin; vecLookerOrigin = EyePosition();//look through the caller's 'eyes' return AvHCheckLineOfSight(vecLookerOrigin, vecOrigin, ENT(pev)); }
/** Return true if our view direction is pointing at the given target, within the cosine of the angular tolerance. LINE OF SIGHT IS NOT CHECKED. */ bool CBaseCombatCharacter::IsLookingTowards( const Vector &target, float cosTolerance ) const { Vector toTarget = target - EyePosition(); toTarget.NormalizeInPlace(); Vector forward; AngleVectors( EyeAngles(), &forward ); return ( DotProduct( forward, toTarget ) >= cosTolerance ); }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- void CNPC_GroundTurret::Shoot() { FireBulletsInfo_t info; Vector vecSrc = EyePosition(); Vector vecDir; GetVectors( &vecDir, NULL, NULL ); for( int i = 0 ; i < 1 ; i++ ) { info.m_vecSrc = vecSrc; if( i > 0 || !GetEnemy()->IsPlayer() ) { // Subsequent shots or shots at non-players random GetVectors( &info.m_vecDirShooting, NULL, NULL ); info.m_vecSpread = m_vecSpread; } else { // First shot is at the enemy. info.m_vecDirShooting = GetActualShootTrajectory( vecSrc ); info.m_vecSpread = VECTOR_CONE_PRECALCULATED; } info.m_iTracerFreq = 1; info.m_iShots = 1; info.m_pAttacker = this; info.m_flDistance = MAX_COORD_RANGE; info.m_iAmmoType = m_iAmmoType; FireBullets( info ); } // Do the AR2 muzzle flash CEffectData data; data.m_nEntIndex = entindex(); data.m_nAttachmentIndex = LookupAttachment( "eyes" ); data.m_flScale = 1.0f; data.m_fFlags = MUZZLEFLASH_COMBINE; DispatchEffect( "MuzzleFlash", data ); EmitSound( "NPC_FloorTurret.ShotSounds", m_ShotSounds ); if( IsX360() ) { m_flTimeNextShoot = gpGlobals->curtime + 0.2; } else { m_flTimeNextShoot = gpGlobals->curtime + 0.09; } }
//----------------------------------------------------------------------------- // Purpose: Creates, destroys, and updates the flashlight effect as needed. //----------------------------------------------------------------------------- void C_HL2MP_Player::UpdateFlashlight() { // The dim light is the flashlight. if ( IsEffectActive( EF_DIMLIGHT ) ) { if (!m_pHL2MPFlashLightEffect) { // Turned on the headlight; create it. m_pHL2MPFlashLightEffect = new CHL2MPFlashlightEffect(index); if (!m_pHL2MPFlashLightEffect) return; m_pHL2MPFlashLightEffect->TurnOn(); } Vector vecForward, vecRight, vecUp; Vector position = EyePosition(); if ( ::input->CAM_IsThirdPerson() ) { int iAttachment = LookupAttachment( "anim_attachment_RH" ); if ( iAttachment >= 0 ) { Vector vecOrigin; //Tony; EyeAngles will return proper whether it's local player or not. QAngle eyeAngles = EyeAngles(); GetAttachment( iAttachment, vecOrigin, eyeAngles ); Vector vForward; AngleVectors( eyeAngles, &vecForward, &vecRight, &vecUp ); position = vecOrigin; } else EyeVectors( &vecForward, &vecRight, &vecUp ); } else EyeVectors( &vecForward, &vecRight, &vecUp ); // Update the light with the new position and direction. m_pHL2MPFlashLightEffect->UpdateLight( position, vecForward, vecRight, vecUp, FLASHLIGHT_DISTANCE ); } else if (m_pHL2MPFlashLightEffect) { // Turned off the flashlight; delete it. delete m_pHL2MPFlashLightEffect; m_pHL2MPFlashLightEffect = NULL; } }
bool Bot::IsFriendInLineOfFire (float distance) { // bot can't hurt teammates, if friendly fire is not enabled... if (!engine->IsFriendlyFireOn ()) return false; MakeVectors (pev->v_angle); TraceResult tr; TraceLine (EyePosition (), EyePosition () + pev->v_angle.Normalize () * distance, false, false, GetEntity (), &tr); // check if we hit something if (!FNullEnt (tr.pHit)) { int playerIndex = ENTINDEX (tr.pHit) - 1; // check valid range if (playerIndex >= 0 && playerIndex < engine->GetMaxClients () && g_clients[playerIndex].team == GetTeam (GetEntity ()) && (g_clients[playerIndex].flags & CFLAG_ALIVE)) return true; } // search the world for players for (int i = 0; i < engine->GetMaxClients (); i++) { if (!(g_clients[i].flags & CFLAG_USED) || !(g_clients[i].flags & CFLAG_ALIVE) || g_clients[i].team != GetTeam (GetEntity ()) || g_clients[i].ent == GetEntity ()) continue; edict_t *ent = g_clients[i].ent; float friendDistance = (GetEntityOrigin (ent) - pev->origin).GetLength (); float squareDistance = sqrtf (1089.0f + (friendDistance * friendDistance)); if ((GetShootingConeDeviation (GetEntity (), &GetEntityOrigin (ent))) > ((friendDistance * friendDistance) / (squareDistance * squareDistance)) && friendDistance <= distance) return true; } return false; }
//========================================================= // FVisible - returns true if a line can be traced from // the caller's eyes to the target vector //========================================================= bool CNPC_Bullsquid::FVisible ( Vector vecOrigin ) { trace_t tr; Vector vecLookerOrigin; vecLookerOrigin = EyePosition();//look through the caller's 'eyes' UTIL_TraceLine(vecLookerOrigin, vecOrigin, MASK_BLOCKLOS, this/*pentIgnore*/, COLLISION_GROUP_NONE, &tr); if ( tr.fraction != 1.0 ) return false; // Line of sight is not established else return true;// line of sight is valid. }
//--------------------------------------------------------- //--------------------------------------------------------- bool CNPC_GroundTurret::QuerySeeEntity( CBaseEntity *pEntity, bool bOnlyHateOrFearIfNPC) { float flDist; flDist = (pEntity->GetAbsOrigin() - EyePosition()).Length2DSqr(); if( flDist <= m_flSensingDist * m_flSensingDist ) { return BaseClass::QuerySeeEntity(pEntity, bOnlyHateOrFearIfNPC); } return false; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Vector CUnitBase::BodyTarget( const Vector &posSrc, bool bNoisy ) { Vector result; if( m_bBodyTargetOriginBased ) { Vector vUpdatedWorldSpaceCenter = GetAbsOrigin(); vUpdatedWorldSpaceCenter.z = GetAbsOrigin().z + (CollisionProp()->OBBMaxs().z / 2.0f); Vector low = vUpdatedWorldSpaceCenter - ( vUpdatedWorldSpaceCenter - GetAbsOrigin() ) * .25; Vector high = EyePosition(); Vector delta = high - low; if ( bNoisy ) { // bell curve float rand1 = random->RandomFloat( 0.0, 0.5 ); float rand2 = random->RandomFloat( 0.0, 0.5 ); result = low + delta * rand1 + delta * rand2; } else result = low + delta * 0.5; } else { Vector low = WorldSpaceCenter() - ( WorldSpaceCenter() - GetAbsOrigin() ) * .25; Vector high = EyePosition(); Vector delta = high - low; if ( bNoisy ) { // bell curve float rand1 = random->RandomFloat( 0.0, 0.5 ); float rand2 = random->RandomFloat( 0.0, 0.5 ); result = low + delta * rand1 + delta * rand2; } else result = low + delta * 0.5; } return result; }
// SyPB Pro P.21 - New Shootable Thru Obstacle bool Bot::IsShootableThruObstacle (Vector dest) { if (m_skill < 70) return false; int currentWeaponPenetrationPower = CorrectGun (m_currentWeapon); if (currentWeaponPenetrationPower == 0) return false; TraceResult tr; Vector source = EyePosition (); float obstacleDistance = 0.0f; TraceLine (source, dest, true, GetEntity (), &tr); if (tr.fStartSolid) { source = tr.vecEndPos; TraceLine (dest, source, true, GetEntity (), &tr); if (tr.flFraction != 1.0f) { if (((tr.vecEndPos - dest).GetLength ()) > 800) return false; // SyPB Pro P.22 - Strengthen Shootable Thru Obstacle if (tr.vecEndPos.z >= dest.z + 200) return false; obstacleDistance = (tr.vecEndPos - source).GetLength (); } } if (obstacleDistance > 0.0) { while (currentWeaponPenetrationPower > 0) { if (obstacleDistance > 75.0) { obstacleDistance -= 75.0f; currentWeaponPenetrationPower--; continue; } return true; } } return false; }