Confidence

Confidence controls when an actor decides to avoid a potential threat, outside of combat and when an actor decides to flee in combat.

Rating
An actor's confidence rating is used to determine when to flee, and when to avoid a potential threat. The confidence rating is essentially a threshold of "what level of threat am I willing to face?".

Confidence is compared to the current threat ratio -- if the threat ratio is less than the actor's confidence level, he will flee/avoid.

Calculating Threat Ratio
Threat Ratio is the ratio of (My Survival Time)/(Enemy Survival Time).


 * My Survival Time = My Health / Enemy DPS
 * Enemy Survival Time = Enemy Health / My DPS

This is the same as:


 * My Combat Strength = My Health * My DPS
 * Enemy Combat Strength = Enemy Health * Enemy DPS
 * Threat ratio = ( My Combat Strength ) / ( Enemy Combat Strength )

Thus:
 * Threat Ratio > 1 : I am likely to win (I will live longer than you)
 * Threat Ratio = 1 : Even match
 * Threat Ratio < 1 : I am likely to lose (you will live longer than me)

NOTE: In combat, this will be calculated for the opposing groups as a whole (see Group Threat Ratio below).

NOTE: Frenzied enemies will not flee

Health Calculation
For the Threat Ratio calculations, "health" should include armor, so:

My Health = ( Current Health ) / ( 1.0 - ( Armor Rating / 100.0 ) )

For example, if I have armor with rating 10 and condition 50%. Based on the armor rating formula, the armor would have an armor rating of 6.75: My Health = ( Current Health ) / ( 1.0 - ( 6.75 / 100.0 ) ) = Current Health * 1.072

Confidence Ratings
Confidence will be set on an actor using a dropdown (replacing the old Confidence number). These are gamesettings:


 * 0: Cowardly = (fConfidenceCowardly=1000.0000) : I will always flee from combat.
 * 1: Cautious = (fConfidenceCautious=0.3750) : I will avoid/flee from threats unless I am at least twice as strong as them
 * 2: Average = (fConfidenceAverage=0.1875) : I will avoid/flee from threats that are stronger than me
 * 3: Brave = (fConfidenceBrave=0.0375) : I will avoid/flee from threats that outmatch me more than 2-1
 * 4: Foolhardy (fConfidenceFoolhardy=0.0) : I will never flee or avoid anyone (it is impossible for the threat ratio to be less than my confidence rating of 0)

Survival Checkbox
Actors can be marked to "Flee based on Personal Survival". This means that in combat, they value their invidual Threat Ratio over that of their combat group as a whole (see Flee section below for details).

Avoiding
Avoid is similar to the "non-combat flee" behavior in Oblivion -- deer running away as soon as they detected you. In Fallout, this is separated from Flee behavior to avoid having to initiate combat in order to flee.

When to avoid
When I detect another actor, I have 3 choices:
 * Attack -- this is determined by Aggression and whether the actor is Enemy or Neutral.
 * Avoid -- this is determined both by my Aggression level (who might I avoid?) and my Confidence level (is the actor strong enough for me to consider it a threat?)
 * Ignore -- if I'm not going to attack or avoid

Avoid Behavior
When someone chooses to avoid, they will run away from the threat. (Exactly the same as normal flee behavior.)

Fleeing
Fleeing is combat behavior -- what an actor does in combat when the threat ratio drops below his confidence rating. The actor performs a Flee Check as a normal part of combat strategy, with the following caveats:
 * Actors check to see if they should flee every fCombatThreatRatioUpdateTime( default: 5.0 ) seconds
 * Actors never decide to flee until they have taken some damage.
 * When combat starts, each actor gets a randomized "Confidence modifier", which is simply a +/- adjustment to their Confidence rating for the current combat only. The confidence modifier is a value between fCombatConfidenceModifierMin( default: -0.5 ) and fCombatConfidenceModifierMax( default: 0.5 ). A positive confidence modifier makes the actor more confident, a negative confidence modifier makes the actor less confident.
 * Note: The confidence modifier is only applied when the actor's confidence is not currently Foolhardy

Fleeing in Combat
An actor in combat decides to flee based on their confidence actor value and their current HP and DPS. Once the actor has decided to flee, they will try the following things:


 * 1) Try to find a nearby teleport door to run through
 * 2) Try to find a cover location away from the attacker to hide behind
 * 3) Try to run away from the attacker

At the Flee Position
Once an actor has reached their flee position, they will wait until one of the following happens:


 * 1) If they are damaged, they will boost their confidence and re-evaluate whether they should flee or not
 * 2) If they detect a target too close by, they will boost their confidence and re-evaluate whether they should flee or not

GameSettings
There are several game settings used to control flee behavior


 * fCombatFleeMaxDoorDistance( default: 2048.0 ) - The maximum distance the actor will search for a teleport door to go through
 * fCombatFleeMinCoverDistance( default: 1536.0 ) - The minimum distance away from the attacker that the actor will search for cover
 * fCombatFleeMaxCoverDistance( default: 3072.0 ) - The maximum distance away from the attacker that the actor will search for cover
 * fCombatFleeNormalDistance( default: 2048.0 ) - The distance the actor will attempt to move if they cannot find a door or cover
 * fCombatFleeBoostConfidenceTargetRadius( default: 512.0 ) - Once at their flee position, when a target gets within this distance and is detected, the fleeing actor will boost their confidence and re-evaluate
 * fCombatFleeWaitTime ( default: 60 )

Group Threat Ratio
When determining the threat ratio in combat, each group's values are considered as a whole, i.e.:


 * My Group Survival Time = (Sum of the Health of everyone in my group) / (Sum of the DPS of everyone in the enemy group)
 * Enemy Group Survival Time = (Sum of the Health of everyone in the enemy group) / (Sum of the DPS of everyone in my group)

So the Group Threat Ratio in combat would be:
 * (My Group Survival Time)/(Enemy Group Survival Time)

Mathematically, this is the same as
 * Threat Ratio = Sum( Ally Combat Strength ) / Sum( Enemy Combat Strength )

When an actor does a Flee check, he will flee if the Group Threat Ratio is less than his Confidence.

Personal Survival
Actors marked as "Flee based on Personal Survival" in their Combat Style perform an additional "flee check" if they pass the Group check. This check is based on the threat ratio of:


 * My Personal Survival Time = (My Health)/(Average DPS of enemy group)
 * Enemy Average Survival Time = (Average Health of enemy group)/(Average DPS of my group)

So the Group Threat Ratio in combat would be:
 * (My Personal Survival Time)/(Enemy Average Survival Time)

If the actor's Personal Survival Threat Ratio is less than his Confidence, he will flee.

Note that in the case where the group is outclassed, the actor will flee based on the Group Threat Ratio -- but even if he passes that check, the actor may flee because his own health is low and therefore his Personal Survival Threat Ratio is too low for his Confidence.

Flee Behavior
When an actor flees from combat, he tries to leave the combat area and find cover a minimum distance from enemies. Once he reaches a "flee spot", he will stay there (in combat) until one of the following happens:
 * He is attacked by an enemy.
 * An enemy comes within (gamesetting) distance.
 * He heals himself.

In the first two cases, before making a new Flee Check, the actor's Confidence is boosted by one level (if he started Cowardly, he becomes Cautious -- during this combat) -- so an actor that has fled is more likely to stand and fight if you attack him again or "corner" him (approach him too closely).

In the third case, every time an actor is healed, he makes a normal Flee Check -- if he is now back above his threshold, he can stop fleeing and reenter normal combat. In this case, Confidence is NOT modified.

Otherwise, the actor stays in his "flee spot" until he drops out of combat normally (due to losing detection on his enemies).

Aggression
Aggression settings determine what actors I might avoid:


 * Unaggressive -- all Enemies, and Neutrals who would attack me
 * Aggressive -- never avoid
 * Very Aggressive -- never avoid

Note that the only actors that might avoid the player will be Unaggressive actors who are Enemies of the player. Once I've determined the actor is someone I might avoid, do I consider it enough of a threat to actually avoid? If the calculated Threat Ratio is below my Confidence, I will avoid the threat.


 * Example: I am Cowardly (Confidence Rating of 3) and Unaggressive. I encounter an Enemy actor (say the player) whose Threat Ratio is 2.3 (meaning I am 2.3 times stronger than the player); because I am Cowardly, I avoid the player. If I was more confident (Cautious or better), I would ignore the player because I don't consider him a threat.

Alarms
Actors will send out alarms, or not, based on a similar calculation used for Fleeing. If the actor determines the enemy to be a minimal threat, he will not send out an alarm to summon help.

Calculate "Alarm Confidence":


 * Alarm Confidence = ( Confidence + .5 ) * (Alarm Confidence Multiplier)

(Alarm Confidence Multiplier is a gamesetting -- say it is 3.)

An actor will send an alarm if Group Threat Ratio < Alarm Confidence.

Example 1
Foolhardy actor runs into an evenly matched opponent -- GTR = 1.0, Confidence = 0.

Alarm Confidence = ( 0 + .5 ) * 3 = 1.5

GTR of 1 is less than Alarm Confidence of 1.5, so he sends an alarm. If he had outmatched his opponent by 2 (GTR = 2), he would not send an alarm.

Example 2
Brave actor runs into a weak opponent -- GTR = 4, Confidence = .5.

Alarm Confidence = ( .5 + .5 ) * 3 = 3, which is less than the GTR, so this actor does not send out an alarm about this combat.