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

Guided missiles and flares

BF22142Heroes

A guided missile is an ordinary projectile with two more components: one that seeks a target and one that follows it. A flare is not a special case anywhere in the code: it is a slow projectile that carries a heat source, and it works because the seeker's score likes it better than the aircraft. This page is the whole duel.

The flight and the hit of any projectile: projectiles.

A guided missile's update older than the tracking delay? 6 ticks by default; before it the missile flies as launched seek: the best target type, active, in the cone and range, a clear line; the lowest score of distance against angle take it? at once with no re-lock time or a living target; else a new target waits the re-lock time follow: the aim point the target's position plus a tenth of true lead follow: turn yaw and pitch toward it, each limited per update; only for a point ahead fly velocity = speed along the new nose; a reversal ends the guidance bf2_w32ded.exe!0x005ba4f0 (seek), 0x00466c40 (best target), 0x005ba1d0 (take it), 0x005bac90 (follow), 0x005b9ff0 (warning)
A missile's update. The seeker may change its mind every tick; the follower turns the nose a limited angle toward the aim point.

Targets#

Anything a missile can chase carries a TargetObject with a type: heat (an engine, a burning static object, a flare's heat object), or laser (what a designator paints). The game logic keeps them all in one map. A target can be switched inactive, which hides it from seekers.

Seeking#

The seek component (SeekClosestTargetComp, template bf2_w32ded.exe!0x005ba570) starts once the missile is older than its tracking delay (6 ticks by default), and then runs every update. It asks the game logic for the best target (GameLogic::findBestTargetObject, 0x00466c40). A candidate qualifies when:

  • its type is the seeker's (seek.targetType) and it is active;
  • its root is not the shooter's own vehicle;
  • for a short time after the launch, it is not on the shooter's team;
  • it is within maxDistLock (9,999 m by default) and within maxAngleLock of the missile's nose (a quarter turn by default: 45 degrees);
  • the line to it is clear of the terrain and of objects (a laser seeker skips both tests).

Among those, the lowest score wins, and of equals the first:

text
score = (1 - directionBonus) x distance + angle x directionBonus x 500        (angle in radians)

So directionBonus is the seeker's character: near 0 it takes whatever is nearest; near 1 it takes whatever is most nearly dead ahead.

The lock, and the missile that flies straight#

The launcher hands the missile a target at the launch: the target its own lock holds, or none. Here is the rule that surprises (seekForBestTarget, 0x005ba1d0):

  • with a reLockTime of 0 (the Hellfire), or while its current target lives, the missile takes the seeker's result at once;
  • otherwise a new target must wait reLockTime before it is taken: 30 seconds for the short-range heat seekers, 60 for the laser Maverick, as the shipped data has it.

A missile launched without a lock therefore finds a target at once, and then waits 30 or 60 seconds before following it. It lives for 10 to 12 seconds. It flies straight. In a recorded session of the original, none of 63 unlocked launches followed anything, and every locked one did. Waiting for the tone is not a courtesy; the missile is unguided without it.

The lock-on warning in the target's cockpit comes from the same place (lockVehicle, 0x005b9ff0): when the locked root changes, the old root is told "released" and the new one "locked", and the client plays the vehicle's warning sounds.

Following#

DefaultFollowComp::followTarget (0x005bac90), each update with a target:

  1. Lead: the aim point is the target's position plus its velocity times (distance / own speed) times a prediction factor of 0.1. A tenth of true lead: missiles in this game trail a turning target.
  2. The aim point is put into the missile's own frame; from it a yaw and a pitch in degrees.
  3. Only for a point ahead: the yaw is limited to maxYaw and the pitch to maxPitch, in degrees per update (the shipped values run from 0.5 to 30). A point behind gives no turn at all.
  4. The missile's frame is turned by the pitch, then the yaw; its velocity becomes its speed along its new nose.
  5. If the turn would reverse the velocity, guidance ends: the missile points down and falls.

One more exit: a target whose parent is marked killHeatSeekingMissile (burning oil towers and the like) makes a missile within 15 m of it lose its target for good and fly on straight. Hot scenery distracts a missile but does not swallow it.

Flares#

A flare launcher is a fire arm like any other, bound to the flare key, and its numbers are the game's data (as the notes read them): 300 rounds a minute in bursts of 5, a magazine of 5, a reload of 2 seconds that may not start until 28 seconds after the last shot. One press drops five flares 0.2 seconds apart, and the launcher is ready again half a minute later.

The flare itself is a projectile: launched at 10 m/s, falling under 0.75 of gravity, living 10 seconds, doing no damage, with two children: the visible effect and a heat object. Because the seeker runs every update and a living target does not hold it, a flare takes the missile the moment its score is lower: it is usually nearer, and right behind the aircraft it is nearly as well centred.

With a directionBonus near 1 the angle counts for more, and a flare off to the side loses to an aircraft dead ahead: the piece above shows the trade.

A fault this found

Flares come from an object cache: a dead flare is kept and reused for the next burst. The original leaves a cached flare's heat object in the target map, only hidden, so a reused flare is seekable again at once. The port used to take it out of the map and never put it back: every burst after an aircraft's first was invisible to missiles. In one test level guided SA-19s were decoyed 1 time in 48 against the original's 36 in 144; after the mend 21 in 86. A unit test holds it now.

Hitting#

A missile's contact is a projectile's (projectiles), with one subtlety at speed. Two objects closing at 320 m/s move more than ten metres toward each other in a tick, so the test sweeps the missile's ray from its previous relative position, using both objects' mean velocities. Leave out the aircraft's own motion and head-on missiles pass through. The port's pass reproduces every contact and miss of 81 recorded passes of the original.

2142
Battlefield 2142

2142 keeps the components. The missile silos of Titan mode fire by an automatic controller, not a seeker (game modes).

What the port has#

PartState
target selection and its scoreverified
the lock state and the re-lock waitverified against the original functions
guidance: lead, turn limits, the reversal exitverified, the same bits
the lock-on warning's callsverified; the HUD's side (the tones) is the client's and not traced in the notes
unlocked launches fly unguided; reused flares stay seekableported, each with a unit test, and compared with recorded sessions of the original
head-on contacts at speed81 of 81 recorded passes equal
wire-guided and TV-guided weaponsseparate paths: see the notes

How it is tested#

  • Guidance against the original (crates/bf2-gameplay/tests/it_bf2/tools_oracle.rs): the original's missile guidance component is run and the port must match bit for bit (the oracle).
  • Target choice in 2142 (seeker_target_twin_2142.rs): the twin's searches choose the same targets, with 2142's designated type.
  • On the server (crates/bf2-server/src/vehicles_missiles.rs, 25 tests): target objects as their constructor leaves them, launchers' slots; 2142's hand-held launchers' lock and the lost lock told to the missile have test programs.

Four of five addresses stand in a test. The lock warning's tones on the HUD are the client's and are not traced in the notes.

In the code#

WhatWhere
target selectioncrates/bf2-gameplay/src/vehicle/seek.rs (find_best_target)
lock state and guidancecrates/bf2-gameplay/src/tools/ (seek, guidance)
the server's missilescrates/bf2-server/src/vehicles_missiles.rs
rigid missiles against vehiclescrates/bf2-world/src/vehicle_pairs.rs

Notes: notes/subsystems/gameplay-vehicles.md ("Seekers", "Countermeasures"), notes/subsystems/gameplay-projectiles.md (section 15).

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