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

Damage and armor: from a hit to the hit points

BF22142Heroes

Two things do damage in this engine: a projectile that hits, and an explosion. Both end in one function of the game logic, which finds the victim's armor, scales the number for the teams, books the kill and takes the hit points. Everything that can be hurt (a soldier, a tank, a fence that breaks) has the same armor component.

Damage: two ways in, one way down a projectile's impact material pair's modifier x angle factor x damage by distance sent at once when above 0.01 an explosion falloff x sight factor x material modifier x explosionDamage queued; applied on the next tick GameLogic::addDamage the first armor up the parent chain; below 0.1 dropped; who is the attacker teamDamageScale the server's friendly fire settings handleDamage kill and assist bookkeeping, the events to the script the armor's addDamage the overkill limit, the hit points; wreck, destroyed, the armor's own explosion bf2_w32ded.exe!0x0056a530, 0x0056d620, 0x004599f0, 0x00586c80, 0x00586eb0, 0x006325d0
The two ways in and the one way down. An explosion's damage is queued and applied a tick later.

A projectile's hit#

At the impact (bf2_w32ded.exe!0x0056a530) the damage is three factors:

text
damage = damageMod(projectile's material, struck material) x angle factor x projectile.getDamage(hit point)
  • The material pair. Every surface has a material id, and so does every projectile. The material manager (0x005ed190) keeps a cell for each pair with a damage modifier, an effect, a decal and a sound. This table, in the game's data, is the whole of "what hurts what": that a rifle does little to a tank is a number in it, not a rule in the code. A pair without a cell takes the manager's default, 1.0.
  • The angle factor scales a glancing hit down, not below the armor template's angleMod.
  • getDamage is the damage over the distance.

Nothing is sent when the result is at or below 0.01.

The one way down#

GameLogic::addDamage (0x004599f0):

  1. the victim's armor is the first object with an armor component going up from the struck part to the root: a part may have its own armor, or pass the hit up;
  2. damage below 0.1 is dropped;
  3. the attacker's player, object and team are resolved;
  4. teamDamageScale (0x00586c80) applies the server's friendly fire settings;
  5. handleDamage (0x00586eb0) books the kill, the assists and the events (scoring);
  6. the armor's addDamage (0x006325d0) limits the overkill and sets the hit points; a change of state (wreck, destroyed) runs the destruction: effects, an explosion of its own, the removal.

Damage a thing does to itself (burning below its critical level, drowning, lying upside down, a wreck bleeding out, leaving the map) goes through the same function with the armor's own object as the victim.

The armor template#

Every ObjectTemplate.armor.* line sets a field of the armor template (0x0060db30). The ones that shape play, with the constructor's defaults:

PropertyDefaultMeaning
hitPoints, maxHitPoints10, 10where it starts, and the ceiling for repairs
wreckHitPoints10the hit points go down to minus this: the wreck's own health
criticalDamage, hpLostWhileCriticalDamage0, 1at or below the first it loses the second every second (a burning vehicle)
hpLostWhileUpSideDown0per second on its roof
hpLostWhileInWater, ...InDeepWater0, 0per second, after waterDamageDelay 3 s / deepWaterDamageDelay 1 s
waterLevel, deepWaterLevel-0.3, 1how deep counts
timeToStayAsWreck20seconds as a wreck; -1 is forever
explosionDamage, explosionRadius, explosionForce0the blast when it is destroyed
wreckExplosion*0the blast when the wreck goes
defaultMaterial-1the material an explosion's modifier is looked up against
canBeDestroyed10 for things that only take marks
angleMod0the floor of the angle factor

The port's reader was run over every armor line of the shipped server archives: 3,369 lines in 159 templates, every property known and every value parsed.

Over time#

The armor's update (0x00631510) runs on the server:

  • Critical: once a second, at or below criticalDamage, the armor damages itself by hpLostWhileCriticalDamage times the time passed.
  • Water (0x0062f910): the first damage after the delay, then every second while it stays in. Soldiers do not use this: they drown through their own update.
  • Wreck (0x0062fac0): a wreck bleeds wreckHitPoints / (timeToStayAsWreck x 30) each tick until it is at minus wreckHitPoints, and is then removed. A soldier's body does not bleed; it waits and fades.

Explosions#

An explosion (0x0056ddb0) asks every object within its radius and computes for each (0x0056d620):

text
d      = the smaller of the distances to the object's position and to its sight point
damage = falloff(radius, d) x scale x damageMod(explosion's material, armor's defaultMaterial) x explosionDamage
falloff = 1 inside radius x 0.2, then a straight line down to 0 at the radius        (0x0056c5f0)

The 0.2 is an engine variable, the hot spot. Damage at or below 0.1 is dropped; the rest is queued and applied on the next tick.

Soldiers get two more tests.

  • Line of sight (0x0056d020): rays go from the centre, and from four points a little beside it, to three points of the soldier's skeleton with the weights 0.5, 0.35 and 0.15. The sum of the weights of the points that can be reached is the soldier's scale. Something in the way that this same explosion is about to destroy counts half. So a wall saves you, a crate that the blast breaks half saves you.
  • The cone (0x0056c640): an explosion with a cone angle (a claymore) hurts only soldiers inside the cone in front of it. Other objects are hurt as in a sphere.

The push (0x0056c7d0) is the same falloff times the explosion's force, times a ratio from the object's armor (explosionForceMod, capped by explosionForceMax) or, without an armor, from its mass. A soldier gets an upward part added, a tenth of the push under water, and a factor between 0.8 and 1.295 from the C runtime's random number.

A random number outside the game's state

That last factor comes from the process-wide rand(), not from a generator the game seeds. Two runs of the original with the same input throw a soldier differently. The port's function takes the drawn value as an input, and its test supplies it.

Heroes
Battlefield Heroes

Heroes changes the blast in several ways the sweeps read: its cover ray lets thrown things through, a stomp or gravity weapon takes no sight test at all, a ducked hero in a tank takes no share, and shields are the armor's own. They are on Heroes: damage and widgets, each with its state in the port.

How it is tested#

StepCheck
the armor templateevery armor line of the shipped data parses
the armor's update core (critical, attacker timer)20,000 generated cases against the original function, sub-calls stubbed
the water timers, the wreck countdownverified against the original functions
the falloff, damage to one object, the push, the cone, the sight factorverified against the original functions
team damage scaleverified
the whole chainrecorded runs of the original server beside the port's: who was hit, for how much, in which tick

Read as drafts in the notes, not verified: the explosion's entry function as a whole, the upside-down check's axis, and the kill bookkeeping's order of events.

In the code#

WhatWhere
armor template and componentcrates/bf2-gameplay/src/health (ArmorTemplate, Armor::tick_core, Armor::wreck_tick)
explosionscrates/bf2-gameplay/src/kills/explosion.rs (explosion_impulse, soldier_in_cone, soldier_sight_factor)
materialscrates/bf2-physics/src/material.rs
the chain on the servercrates/bf2-server/src/damage.rs, damage_explosion.rs, vehicles_armor.rs
the data testcrates/bf2-gameplay/tests/it_bf2/retail_armor.rs

Notes: notes/subsystems/gameplay-damage.md, notes/subsystems/physics-materials.md, notes/subsystems/gameplay-kills.md.

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