LTBOOL CAISenseHearEnemyWeaponFire::Update(HOBJECT hStimulus, LTFLOAT fTimeDelta) { if ( !IsCharacter(hStimulus) ) return LTFALSE; CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject(hStimulus); CharFireInfo info; pChar->GetLastFireInfo(info); // Make sure this is a recent firing of the weapon... if (info.fTime + 1.0 < g_pLTServer->GetTime() || info.nWeaponId == WMGR_INVALID_ID) return LTFALSE; WEAPON* pWeapon = g_pWeaponMgr->GetWeapon(info.nWeaponId); if (!pWeapon) return LTFALSE; // Get the Distance that fire noise carries LTFLOAT fWeaponFireNoiseDistance = (LTFLOAT)pWeapon->nAIFireSoundRadius; if (info.bSilenced) fWeaponFireNoiseDistance *= 0.25f; // Get the distance from the fire LTFLOAT fDistance = VEC_DIST(info.vFiredPos, m_pAI->GetPosition()); // Are we close enough to hear? if ( fDistance < (m_fDistance + fWeaponFireNoiseDistance) ) { React(); // Record the Timestamp m_fTimestamp = info.fTime; return LTTRUE; } return LTFALSE; }
LTBOOL CAISenseHearEnemyWeaponImpact::Update(HOBJECT hStimulus, LTFLOAT fTimeDelta) { if ( !IsCharacter(hStimulus) ) return LTFALSE; CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject(hStimulus); CharFireInfo info; pChar->GetLastFireInfo(info); // Make sure this is a recent firing of the weapon... if (info.fTime + 1.0 < g_pLTServer->GetTime() || info.nWeaponId == WMGR_INVALID_ID) return LTFALSE; AMMO* pAmmo = g_pWeaponMgr->GetAmmo(info.nAmmoId); if (!pAmmo || !pAmmo->pImpactFX) return LTFALSE; // Get the Distance that the impact noise carries LTFLOAT fWeaponImpactNoiseDistance = (LTFLOAT) pAmmo->pImpactFX->nAISoundRadius; // Scale based on surface types SURFACE* pSurf = g_pSurfaceMgr->GetSurface(info.eSurface); _ASSERT(pSurf); if ( pSurf && !pAmmo->pImpactFX->bAIIgnoreSurface ) { fWeaponImpactNoiseDistance *= pSurf->fImpactNoiseModifier; } // Get the distance from the impact LTFLOAT fDistance = VEC_DIST(info.vImpactPos, m_pAI->GetPosition()); // Are we close enough to hear? (or did it hit us?) if ( (fDistance < (m_fDistance + fWeaponImpactNoiseDistance)) || (info.hObject == GetAI()->GetObject()) ) { React(); // Record the Timestamp m_fTimestamp = info.fTime; return LTTRUE; } else { // If it hit a character (forget if we like him or not), and we can see that character, react. if ( info.hObject && IsCharacter(info.hObject) && (fDistance < (500.0f)) ) { LTVector vPosition; g_pLTServer->GetObjectPos(info.hObject, &vPosition); LTBOOL bVisible = LTFALSE; if ( m_pAI->CanSeeThrough() ) { bVisible = m_pAI->IsObjectPositionVisibleFromEye(CAI::SeeThroughFilterFn, CAI::SeeThroughPolyFilterFn, info.hObject, vPosition, (250000.0f), LTTRUE); } else { bVisible = m_pAI->IsObjectPositionVisibleFromEye(CAI::DefaultFilterFn, NULL, info.hObject, vPosition, (250000.0f), LTTRUE); } if ( bVisible ) { React(); // Record the Timestamp m_fTimestamp = info.fTime; return LTTRUE; } } } return LTFALSE; }