Threat

Threat is a mechanism in Dragon Age: Origins whereby enemies decide which characters in your party to attack.

Threat Level
Threat Level is the means by which a character's threat is deduced, and is often referred to as relating to "enemy hostility". Essentially, the higher threat level a character has, the more "hostile" or aggressive enemies will be towards that character, which will result in drawing more enemies to attack that character. The lower a threat level a character has, the less "hostile" enemies will be and the more likely an enemy will seek out a different target to attack.

Threat Mechanics in Combat
The strategic use of a party's varying threat levels is widely considered to be a key element of successfully overcoming the opposition, especially at higher levels of difficulty.

Initial Threat
The initial threat value for each party member upon being sighted is 10 (this value is relevant, since Mages can reset all threat, except for the distance component Mind Blast).

On difficulties lower than Nightmare, armor increases the initial threat. The bonus is 5 for light armor, 10 for medium / heavy / massive armor.

On difficulties lower than Nightmare, melee weapons increase the initial threat by 5.

Party members are added to an enemy's threat table in the order they are perceived (this is based on the distance). There is a small delay for distant party members.

Distance-based Threat
After a party member has been added to the threat table, a distance-based threat component is initialized (distance between enemy and party member). This threat component scales approximately like this (distance in m):

1.8m - 2m is the common melee-combat distance.

The distance-based threat component cannot be reset with Abilities / Spells like Disengage, Distraction, Mind Blast and is not affected by threat decay.

Damage Dealt
The amount of threat generated is: ThreatIncrease = 100 * DamageDealt / MaximumHealth of Enemy

For an enemy with 200 hit points:
 * Taking the enemy from 200 to 160 health (40 damage) draws 20 threat.
 * Taking the enemy from 60 to 20 health (40 damage) draws 20 threat as well.

Rogues will only draw 80% of the threat noted above.

Warrior
Warriors have special abilities that can increase the amount of threat drawn.
 * Taunt provides a one-time AoE threat increase of 300 (400 with Frightening Appearance).
 * Threaten doubles the threat amount due to damage dealt.
 * Most Activated Talents should draw additional threat from affected enemies. However, this is only working for very few talents:
 * Arrow of Slaying
 * Pinning Shot
 * Scattershot, primary target only.
 * Armor does not increase threat beyond the small bonus upon being sighted.

Mage
Some spells that affect enemies in a negative way draw additional threat, in addition to damage dealt. This is not working properly for many spells and noted in the spell descriptions.

Walking Bomb is a special case and draws 100 threat on Hard and Nightmare difficulties.

On Hard and Nightmare difficulties, an additional 20 threat (in addition to the threat above) is drawn for non-damaging hostile AoE spells (when an enemy enters the AoE): Affliction Hex, Earthquake, Miasma.

Items
Items supposed to increase hostility like Ageless and Cadash Stompers do not work properly and do not increase threat.

Mage

 * Non-hostile spells and all buffs do not draw threat.
 * Mind Blast clears all Threat drawn by the Mage, except for the distance-based component.

Rogue

 * Stealth causes the Rogue to disappear from perception by all enemies. After an event processing delay, the stealthed rogue will be dropped from all threat tables. However, if Stealth is broken quickly (within 1-2s, e.g. due to an automatic attack because the base AI forces the Rogue to defend himself or an attack was already queued), threat is not dropped. If the Rogue was dropped from the Stealth tables, his threat numbers will start from scratch with the Initial Threat and distance-based threat numbers.
 * Feign Death works similarly to Stealth. The same caveat applies, if Feign Death is given up too quickly, the drop from the Stealth tables (and subsequent drop of Threat) may not occur.

Note that the threat number for the Rogue may be higher than for other party members after being rediscovered, since the other party members will have lost some or all of the Initial Threat due to threat decay of 0.5 per second.


 * Distraction clears all Threat, except for the distance-based component.

Warrior
Disengage lowers threat by 100.

Items
Items like Bard's Dancing Shoes, Dalish Promise Ring, Amulet of Accord, Magister's Cinch, Adaia's Boots with the Reduces Hostility property do not work and do not reduce threat.

Running Away
Once a distance of 60m is reached, enemies will lose perception of the party member. The party member will be dropped from the Stealth table. Once perceived again, threat starts from scratch (Initial Threat + distance-based threat).

If a party member runs faster than the enemy, running away and causing a chasing enemy to pass close by another party member can trigger a target switch to the other party member (if his threat due to distance is higher). This can be a useful tactic, if a Mage is attacked by several enemies at the beginning of combat (at Nightmare difficulty, the only threat difference between party members is due to distance at the beginning of combat).

Common Threat Strategies
Tank & Range: Perhaps the most common use of threat in combat is to elevate the threat level of one (or perhaps two) specific Warriors in your party, often who are equipped with a weapon & shield. The high threat levels draw most of the enemies attacks to the Warrior with a high threat level. They act as a "tank" whose job it is to soak up massive amounts of damage while the other 3 party members either heal & buff, do back stabbing damage, do massive two-handed damage, deal high magic damage, or use other ranged attacks.

Enemy Target Switching
Enemies will always try to attack the target they hate most (has the highest threat amount to this particular enemy).

Enemies with melee weapons have timers limiting how often they switch targets. The timer start value is initialized to 0 and increases by 5s (up to 25s), each time the target is switched. While the timer is counting down, targets will not be switched (unless the current target cannot be attacked).

If the target has 20% health left, enemies will not switch to a higher threat target with a probability of 50%. If the target has 10% health left, enemies will not switch to a higher threat target with a probability of 90%.

Special Attacks
An exception to targeting the most-hated enemy, are ranged AoE attacks some creatures can perform. Those are controlled by a Tactics system similar to the party AI. These tactics may contain ability / spell triggers based on clustered enemies.

Threat Decay
Threat decays at a rate of 0.5 per second (the distance-based threat component does not decay).

Hooking into the engine
Most of the threat management/updating is done in ai_threat_h.nss. This is a header file, so it cannot be directly recompiled. Root scripts with a main function using this header must be recompiled, e.g. rules_core.nss, player_core.nss, spell_aoe_instant.nss, spell_aoe_duration.nss, talent_model.nss, talent_singletarget.nss.

Useful script functions:
 * float threat = GetThreatValueByObjectID(oCreature, oAttacker); Returns current threat value.
 * GetName(oAttacker) Name of party member.
 * GetName(oCreature) Name of enemy, as displayed in game.
 * GetTag(oCreature) Base name of the *.utc file of the actual creature spawned.
 * ObjectToString(oCreature) Unique Object ID of the creature.
 * Logging

Verified Functionality
Testing was performed with Patch 1.02; Toolset 1.01.
 * Base threat upon sighting (including weapon / armor bonus at lower difficulties).
 * Threat based on damage (including Threaten functionality, Frightening Appearance does not give Threaten bonus).
 * Spells draw additional threat, taken from ABI_base.xls, threat_impact column. The threat_impact value is multiplied by 10. Walking Bomb special case verified. This is triggered by the EVENT_TYPE_CAST_AT event in rules_core.nss. This is working for about half the spells. Spell descriptions have been updated.
 * Most Talents do not draw additional threat, there are threat_impact values in ABI_base.xls as well. All activated Talents have been checked, only Archery talents Arrow of Slaying, Pinning Shot and Scattershot, as well as Shale talents Stone Roar, Regenerating Burst, Rock Barrage and Stone Aura draw additional Threat. The EVENT_TYPE_CAST_AT event is used as here as well to trigger the Threat update.
 * Taunt.
 * Feign Death, Stealth reduce threat if the Rogue has disappeared from perception long enough.
 * Reaching a distance of more than 60m drops threat.
 * Target switch counters, limiting melee target switch rate.
 * Mind Blast.
 * Items with Reduces Hostility and Increases Hostility and Intimidation properties do not work (tested items: Bard's Dancing Shoes, Ageless). The infrastructure for an ON_HIT property increasing threat by 5 points is actually there and Ageless does have this property, but it is not invoked (perhaps because Ageless has multiple properties, the +dmg vs darkspawn is triggered).
 * The distance-based threat generation is happening somewhere deep in the bowels of the engine and not performed using scripts. The values appear to be reproducible, but special cases that have not been discovered may exist.