On this page
Heroes: how damage is worked out
A hit in Heroes is a short chain of multiplications. The weapon's template gives a damage that depends on the distance; the attacker's abilities add to it; the angle of the hit and the material of what was hit scale it; and a shield, when there is one, takes it first. This page walks the chain with the functions of the original that were read and says where the port's verdict is SAME and where a part was not read yet.
A direct hit#
BFHeroes.exe@bfh126!0x007306dc (the projectile's hit in the server's game logic; its damage block is 0x00730966 to 0x00730b54):
damage = (angle term x (distance damage + the attacker's item bonus)) x the material table's factor| Part | Where it comes from | Verdict |
|---|---|---|
| distance damage | the projectile's own curve, below (0x00705480) | SAME |
| the attacker's item bonus | what his active abilities add: Piercing Shot's +13 to +23, for one (0x00753e45) | read |
| the angle term | 1 - k x (1 - f x f), with f = min(1, max(angleMod, cosine) + a constant): the armor's angleMod and the cosine of the hit's angle | read |
| the material factor | the table's cell of (the projectile's material, the hit bone's material) | SAME in what was read |
A hit on the thrower's own vehicle is passed over; the hit thing's armor takes the damage.
The damage over the distance#
Each projectile template has eight numbers: initialMinDamage, initialMaxDamage, mediumDistance, mediumMinDamage, mediumMaxDamage, longDistance, longMinDamage, longMaxDamage. From the launch point the minimum and the maximum each run in a straight line from the initial value at 0 m to the medium value at the medium distance, on to the long value at the long distance, and stay there. The damage is the projectile's own random point between the two.
- A medium distance of 0 gives the initial values at every distance.
- A template with
percentDamageabove 0 answers that percent of a base instead. - Many weapons are strongest at their medium distance and weaker both nearer and farther: the pistol at 12 m, the SMG at 18 m, the machine gun at 13 m. The sniper rifle and the anti tank weapon only grow with the distance.
The class page has each default weapon's numbers and a curve to play with. Ours: bfh_game::crit::ProjectileDamage (range_at, damage_at).
The material table: where a hit lands#
Every bone of a hero's skeleton has a material, and every projectile has one; the table (Material/materialManagerSettings.con of the game's common archive) holds a factor for each pair.
| Weapon | Body | Head | Arms and lower legs |
|---|---|---|---|
| SMG, pistol, machine gun | 1 | 1 | 1 |
| shotgun | 1 | 1 | 1 |
| sniper rifle | 0.7 | 1.25 | 0.7 |
| anti tank rocket, direct | 0.9 | 0.9 | no cell |
| TNT's blast | 0.2 on a soldier | ||
| hand grenade's blast | 1 on a soldier |
So only the sniper rifle rewards a head shot, and only by a quarter over its base; with every other default bullet weapon a hit is a hit. The two teams' heroes have their own material numbers for the same bones. A knife's material has a 0 against its own team's bones: a knife does not hurt a team mate.
Critical hits#
A weapon's template gives a chance and a bonus:
| Weapon | Chance | Bonus |
|---|---|---|
| knife | 8 % | +25 |
| sniper rifle | 6 % | +15 |
| shotgun | 5 % | +2 |
| pistol | 3 % | +10 |
| machine gun | 3 % | +8 |
| SMG | 2.5 % | +20 |
The roll itself was not read in the sweep; the port's is in bfh_game::crit. Poisoned Blade raises the knife's chance to 10 to 30 % by its level.
A blast#
An exploding thing (a grenade, TNT, a rocket, most thrown widgets) goes through the explosion (0x0072a930), which asks every object with an armor or a detonation component, and for each the splash hit (0x0072a3b0):
damage = fall-off x (the explosion's damage + the attacker's item bonus) x the material factor
x a scale of the caller x the factor of the victim's own fire armThe fall-off (0x007281aa; ours bfh_game::explosion::falloff, SAME):
inner = radius x hotSpotRadiusPercent (0.2 when the template has no line)
distance <= inner: 1
else: 1 - (distance - inner) / (radius - inner), held between 0 and 1A hand grenade (radius 5, damage 60) does its 60 within 1 m and nothing at 5 m. The distance is the smaller of two, to two points of the victim.
Filed for blasts (widgets): the cover ray is stopped by thrown things in the port and passes them in the original. The splash hit was read in the original alone, in part.
Shields and the last hit point#
- A shield (Hero Shield, Elixir, the Tank Shield) is the armor's own: its damage function handles it (
0x0082898a, read in part). - During the delayed death of the two machine gun abilities the armor holds 1 hit point: a hit larger than the hit points sets them to 1 and returns. The original's HUD shows an empty bar and 0 then (the HUD).
Damage over time#
Burning Bullets, the fire bombs and the poisons put a damage item on the victim that takes a step every 1.5 or 2 s for its duration. The item's start and its update (0x0052e617) against ours (bfh_game::abilities, update_damage): the first step, the step's length and the end are SAME. A Bandage ends every such item on its user (abilities).
Falling#
0x0072ef7f (ours bfh_game::fall_damage::terrain_collision, SAME in the statements read): the up part of the contact speed loses 15 m/s and is 0 when that goes under 0; the speed is the length of what is left; the damage term is (speed - 10.5) x speed, scaled by the larger of the armor's angleMod and the cosine. A fall hurts only when what is left of its speed passes 10.5 m/s.
What is not settled#
| Part | What is missing |
|---|---|
| the critical hit's roll | the fire's roll was not opened |
| a soldier's share of a blast | the exposure factor's shape is the same; its body was not compared line by line |
| regeneration | the armor template has no regeneration property; whether the armor's update heals by itself was not read |
| the second to fourth status items of a hit | not read |
Notes: notes/bfheroes/class_sweep.md, widget_sweep.md, ability_sweep.md, crit.md, combat.md. Code: crates/bfh-game (crit, explosion, fall_damage, abilities).
How it is tested#
- Critical hits and damage by distance (
crates/bfh-game/src/crit/tests.rs): the generator of the roll, chance and damage from the templates, the order of the damage's terms, a splash crit added after the wrapper, health back at every n-th critical hit. - Upgrades (
customization/weapon_gear/tests.rs): equipped upgrades changing the fire arm and its components, "replace" winning over "add". - Blasts (
abilities/stomp.rs,explosion.rs): the push and the hot spot.
Seven of eleven addresses stand in a test. The roll itself was not read in the sweep, as the page says; a played comparison of a whole fight with the original does not exist, because the original's server cannot be run beside the port for Heroes.
In the code#
The crates this page names, each with its line of docs/release/LAYOUT.md (the list is gathered by the wiki's build from the page itself):
| Crate | What it is |
|---|---|
crates/bfh-game | Battlefield Heroes game systems on the server: hero abilities, capture-the-flag |
Files this page names: crates/bfh-game/src/crit/tests.rs.
docs/dev/heroes/damage.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.