Detection is a complicated process involving many variables. The factors break down into three categories: skill, visibility, sound. These three factors are added together to determine whether one actor detects another. Actors can also detect Detection Events -- sounds directly or indirectly generated by a target actor -- even if they don't detect the target directly.
The basic formula is as follows:
Detection Value = fSneakBaseValue + (Sound factor * Distance attenuation ) + (Visual factor * Distance attenuation) + (Actor Skill factor * Distance attenuation) + ( Actor Skill factor - Target Skill factor )
Each of the three detection factors is modified by distance using the following formula:
( ( fSneakMaxDistance - distance ) / fSneakMaxDistance ) ^ fSneakDistanceAttenuationExponent
Sound is further attenuated if there is no line of sight between the actor and the target using fSneakSoundLosMult (0.3).
Sound is made up of 2 factors: movement and action.
Movement is the sound made when moving. If the target is stationary, this is 0. Otherwise:
Movement Sound = ( fSneakEquippedWeightBase + fSneakEquippedWeightMult * armor weight)
If running, use fSneakRunningMult.
Action is the "action sound" made by the target -- the sound of any weapon being used.
Action Sound = Action * fSneakActionMult
Sound factor = Attenuation * fSneakSoundsMult * (Movement + Action)
The visual factor is determined as follows:
Visual Contact: If can't see target, visual element is 0 Movement Multiplier: 1 + Moving * fSneakLightMoveMult + Running * fSneakLightRunMult Light: ( fDetectionSneakLightMod + light level ) * fSneakLightMult Blindness: ( 100 - blindness )/100 Invisibility: If Invisible== 1, multiply by fSneakStealthboyMult
Visual factor = Attenuation * VisualContact * Light * Movement * Blindness * Invisibility
The actor running detection uses Sneak skill to determine a base Sneak skill:
Base Sneak Skill = fSneakPerceptionSkillMin + (fSneakPerceptionSkillMax - fSneakPerceptionSkillMin) * Sneak / 100
This can be further modified by various factors: is the actor in the Alert state; is the actor sleeping; is the actor in combat with something else.
Modified Sneak Skill = Base Sneak Skill * (1 + Alert * fSneakAlertMod + Sleeping * fSneakSleepBonus + NotCombatTarget * fSneakCombatMod)
The detection value is used to determine when an actor changes its detection state.
Actors pass through 4 detection states: Normal->Alert->Combat->Lost->Normal. Actors enter the Alert state when they either "almost" detect an enemy, or detect a "detection event" generated by an enemy. Alerted actors will search towards detection events, which will allow them to detect enemies and enter the Combat state. If all targets become undetected, an actor will drop out of combat into the Lost state, searching towards the last known locations of its targets until it either redetects them or all targets regain their full Stealth Points and they return to Normal state.
Actors are always in one of the following detection states:
- Default state of all actors.
- I am aware of a Detection Event. May include search behavior, but always includes "weapon out". Actors have increased Perception when in this state.
- I am in combat with at least one actor in my target list.
- I've transitioned from Combat because all of my targets became undetected. Similar to Alert state in most respects.
Actors transition between detection states according to the following rules:
Normal --> Alert
This transition happens when a hostile actor (an actor that I would attack if I detected it) either:
- Comes within my detection threshold (detection > 0). Add a detection event to my alert list at the actor's current location with the magnitude of current detection.
- Creates a "Detection Event" that I detect (e.g. firing a weapon). Add the detection event to my alert list.
- Damages me. Add a detection event to my alert list at the enemy's current location with magnitude of current detection.
Normal --> Combat
This transition happens when a hostile actor suddenly becomes detected without triggering the Alert state on me. This can happen in several ways:
- The hostile actor goes very rapidly from detection < 0 to detection above the combat detection threshold (iCombatStealthPointSneakDetectionThreshold or iCombatStealthPointDetectionThreshold, depending on if the target is sneaking or not) - in which case the target's Stealth Points are ignored.
- The state changes such that the target is suddenly considered hostile (this is usually a quest situation, or due to the player committing a crime).
Alert --> Combat
This transition happens when I fully detect any actor to which I'm hostile:
- Detection against the target exceeds the combat detection threshold - in this case, the target is immediately detected regardless of its remaining Stealth Points.
- Target's Stealth Points reach 0, and my detection against the actor is > 0.
Alert --> Normal
This transition happens when my detection against all targets in my alert list is < 0, AND all the targets have Stealth Points = 100.
Combat --> Normal
This transition occurs whenever I have no targets in my combat list (i.e. they're all dead or no longer considered hostile), and I have nothing in my alert list.
Combat --> Lost
This transition occurs whenever all my targets are undetected (detection < 0) AND their timers have all expired (see below), and I have events in my alert list.
Lost --> Normal
This transition occurs whenever all my targets < 0 AND all the targets have Stealth Points = 100.
Lost --> Combat
This transition occurs whenever one of these happens:
- I detect any of my targets (detection > 0), AND the target's Stealth Points = 0
- I detect any of my targets > combat detection threshold (iCombatStealthPointSneakDetectionThreshold or iCombatStealthPointDetectionThreshold, depending on if the target is sneaking or not).
Actors in combat (which includes Alert, Combat, and Lost states) hold a list of hostile actors in their target list.
Whenever an actor in my target list becomes undetected (detection < 0), start running a timer on that target. If timer expires and target is still undetected AND not currently being searched for (either I'm searching for someone else, or still in combat with someone else), remove the target from my list.
The Alert State is a combat state -- the actor is in combat, although it has not located a target to attack. If allowed by its current package, the actor will engage in search behavior towards detection events in its alert list (see Combat Search).
The Lost State is also a combat state -- the actor remains in combat, but has lost detection on its targets. The actor will engage in search behavior, starting with its current combat target if more than one target remains in its list (see Combat Search).
When actors are in a combat search (Alert or Lost states), they will occasionally use these default Detection topics for dialogue barks.
- LostIdle: Used when actors are in the Lost state. Examples: "Nothing yet.", "Keep looking. He's got to be here somewhere."
- AlertIdle: Used when actors are in the Alert state. Examples: "I could have sworn I heard something.", "Hmm. Maybe I'm just hearing things.", "I'll check over here.", "Anybody there?"
Transitions: there also default Detection topics for the transitions between detection states:
A detection event is a sound/action at a location, that can be detected by an actor in a similar manner that it detects other actors. In general, actors will only respond to a detection event if it was produced by an actor that they are aggressive towards.
A Detection Event has the following data attached to it:
- Owner -- Actor that caused it
- Action rating -- this plugs into the detection formula, and is the main component of how "loud" the event is. This comes from the projectile or explosion.
- Location -- used by alerted actors as the location of their search.
Generating a Detection Event
A detection event is generated when a projectile impacts something -- arrow, spell, etc. Action rating = taken from the projectile.
When a detection event is generated:
- Actors within the detection radius (fSneakMaxDistance) run detection on the event to see if they detect it. Actors who would not respond aggressively toward the detection event owner ignore the event, as do actors who are already in Combat state.
- If an actor detects the event (>fSneakNoticedMin), they are immediately put into Alert state. If they are already Alert, add the event owner to their target list.