BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
Battlefield Heroes
On this page

Heroes: how damage is worked out

Heroes

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) distance damage min..max by the metres + item bonus the attacker's abilities x angle term 1 - k (1 - f f) x material factor projectile x bone the armor shield first, then hit points the sniper rifle: body 0.7, head 1.25; SMG, pistol, machine gun, shotgun: 1 everywhere; the anti tank rocket 0.9 A blast (0x0072a930, the splash hit 0x0072a3b0) fall-off 1 inside the hot spot x (damage + bonus) explosionDamage x material factor TNT 0.2, grenade 1 x two scales the caller's, the victim's the armor of every object asked fall-off = 1 - (distance - inner) / (radius - inner), inner = radius x hotSpotRadiusPercent (0.2 without a line) A critical hit adds its bonus by the weapon's chance; a damage over time item takes a step every 1.5 or 2 seconds. 0x00705480 (damage over the distance), 0x007281aa (fall-off), 0x0082898a (the armor's damage), 0x0072ef7f (falling)
A direct hit and a blast, each as its chain of factors.

A direct hit#

BFHeroes.exe@bfh126!0x007306dc (the projectile's hit in the server's game logic; its damage block is 0x00730966 to 0x00730b54):

text
damage = (angle term x (distance damage + the attacker's item bonus)) x the material table's factor
PartWhere it comes fromVerdict
distance damagethe projectile's own curve, below (0x00705480)SAME
the attacker's item bonuswhat his active abilities add: Piercing Shot's +13 to +23, for one (0x00753e45)read
the angle term1 - 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 angleread
the material factorthe 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 percentDamage above 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.

WeaponBodyHeadArms and lower legs
SMG, pistol, machine gun111
shotgun111
sniper rifle0.71.250.7
anti tank rocket, direct0.90.9no cell
TNT's blast0.2 on a soldier
hand grenade's blast1 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:

WeaponChanceBonus
knife8 %+25
sniper rifle6 %+15
shotgun5 %+2
pistol3 %+10
machine gun3 %+8
SMG2.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):

text
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 arm

The fall-off (0x007281aa; ours bfh_game::explosion::falloff, SAME):

text
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 1

A 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#

PartWhat is missing
the critical hit's rollthe fire's roll was not opened
a soldier's share of a blastthe exposure factor's shape is the same; its body was not compared line by line
regenerationthe 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 hitnot 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):

CrateWhat it is
crates/bfh-gameBattlefield Heroes game systems on the server: hero abilities, capture-the-flag

Files this page names: crates/bfh-game/src/crit/tests.rs.

Source: docs/dev/heroes/damage.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.