bool CAI_ScriptConditions::IsInFOV( CBaseEntity *pViewer, CBaseEntity *pViewed, float fov, bool bTrueCone ) { CBaseCombatCharacter *pCombatantViewer = (pViewer) ? pViewer->MyCombatCharacterPointer() : NULL; if ( fov < 360 && pCombatantViewer /*&& pViewed*/ ) { Vector vLookDir; Vector vActorDir; // Halve the fov. As expressed here, fov is the full size of the viewcone. float flFovDotResult; flFovDotResult = cos( DEG2RAD( fov / 2 ) ); float fDotPr = 1; if( bTrueCone ) { // 3D Check vLookDir = pCombatantViewer->EyeDirection3D( ); vActorDir = pViewed->EyePosition() - pViewer->EyePosition(); vActorDir.NormalizeInPlace(); fDotPr = vLookDir.Dot(vActorDir); } else { // 2D Check vLookDir = pCombatantViewer->EyeDirection2D( ); vActorDir = pViewed->EyePosition() - pViewer->EyePosition(); vActorDir.z = 0.0; vActorDir.AsVector2D().NormalizeInPlace(); fDotPr = vLookDir.AsVector2D().Dot(vActorDir.AsVector2D()); } if ( fDotPr < flFovDotResult ) { if( fov < 0 ) { // Designer has requested that the player // NOT be looking at this place. return true; } return false; } } if( fov < 0 ) { return false; } return true; }
//----------------------------------------------------------------------------- // Purpose: // Input : // Output : //----------------------------------------------------------------------------- void CWeapon_SLAM::TripmineAttach( void ) { CBaseCombatCharacter *pOwner = GetOwner(); if (!pOwner) { return; } m_bAttachTripmine = false; Vector vecSrc = pOwner->Weapon_ShootPosition(); Vector vecAiming = pOwner->EyeDirection3D(); trace_t tr; UTIL_TraceLine( vecSrc, vecSrc + (vecAiming * 128), MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr ); if (tr.fraction < 1.0) { CBaseEntity *pEntity = tr.m_pEnt; if (pEntity && !(pEntity->GetFlags() & FL_CONVEYOR)) { QAngle angles; VectorAngles(tr.plane.normal, angles); angles.x += 90; CBaseEntity *pEnt = CBaseEntity::Create( "npc_tripmine", tr.endpos + tr.plane.normal * 3, angles, NULL ); CTripmineGrenade *pMine = (CTripmineGrenade *)pEnt; pMine->m_hOwner = GetOwner(); pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType ); EmitSound( "Weapon_SLAM.TripMineAttach" ); } } }
//------------------------------------------------------------------------------ // 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 ); }