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

A vehicle's life: spawner, abandonment, wreck, the next one

BF22142Heroes

Vehicles in a level are not placed: spawners are, and a spawner makes a vehicle, watches it, and makes the next one when the first is gone. Three clocks run a vehicle's life: the spawner's delay, the abandoned vehicle's countdown, and the wreck's. This page puts them on one line.

A spawned vehicle's life at its spawner whole, within 5 m: the spawner's timer stands in use or at home somebody aboard, or within the spawner's distance abandoned timeToLive counts down, half a second a check burning damageWhenLost a second a wreck bleeds for timeToStayAsWreck gone the wreck explosion, then removed the slot is free from the wreck on: minSpawnDelay later the spawner makes the next one bf2_w32ded.exe!0x00570eb0 (spawner), 0x00594c10 (abandoned), 0x00630d00 (destroyed), 0x0062fac0 (wreck)
The states of a spawned vehicle and what moves it on. The spawner only counts while its slot is free.

The spawner#

ObjectSpawner (template bf2_w32ded.exe!0x00571560, object 0x00571340), with the constructor's defaults:

PropertyDefaultMeaning
setObjectTemplate <team> <name>what to spawn for which team: a spawner at a control point makes the owner's vehicle
minSpawnDelay, maxSpawnDelay30, 60seconds before the next one; see below
spawnDelayAtStart0wait the delay before the first one too
timeToLive60handed to the vehicle: its countdown once abandoned
distance50within this many metres of the spawner a vehicle is "at home" and never counts down
damageWhenLost50hit points a second once the countdown is over
maxNrOfObjectSpawned1how many of its vehicles may exist at once
nrOfObjectToSpawn-1how many in all; -1 is without end
controlPointId, team, teamOnVehicle-1, 0, 0which control point's owner it follows; whether the vehicle itself carries the team
holdObject0keep the vehicle attached to the spawner (stationary weapons)
useButtonRadius0spawn only when a player presses use nearby

On a server with sv.noVehicles every spawner's template name becomes a dummy: that is all the setting does.

maxSpawnDelay does nothing#

The delay is computed as (max - min) x 0.0 + min (0x0056f6a0): the random share is multiplied by a constant zero. In Battlefield 2 every respawn waits exactly minSpawnDelay. A level can set both values; only one is read. The port keeps the zero.

The update#

0x00570eb0, each tick on the server, for each of its slots:

  • a taken slot is freed when its vehicle no longer exists or is a wreck;
  • only the first free slot of a tick acts: its timer counts down. It is paused while the last vehicle it made still stands whole within 5 m: a vehicle nobody took blocks the next one;
  • at zero, a wreck still lying within 5 m is removed and the new vehicle is made at the spawner's place plus spawnOffset. A failed spawn tries again after a second.

Making it (spawnObject, 0x00570930): an occupied vehicle within 10 m stops the spawn; empty ones within 10 m make the spawner wait five updates and are then removed, unless a soldier stands within 7 m. The new vehicle is told its spawner, its timeToLive and the time.

Read, not reproduced

The update loop and the timer are verified. The notes mark spawnObject itself as not reproduced function for function; the port's server has its own implementation of the blocking rules, checked against recorded runs of the original server (parked vehicles after a respawn, the snap ray that puts a vehicle on the ground).

Abandoned#

A vehicle away from home with nobody in it counts down and then burns (0x00594c10; seats and cameras has the four checks). In short: the check runs every 5 s while somebody sits in it or it stands within the spawner's distance or a living soldier is within three of its explosion radii; else every half second, taking half a second off the countdown; at zero it takes damageWhenLost x 0.5 each check.

Destroyed#

When the hit points first fall to 0 or below (ArmorGLComp::onHitPointsChanged, 0x00630d00):

  1. the vehicle becomes a wreck: it switches to its destroyed meshes and its destroyed collision geometry at the end of the frame, and cannot be hurt for one second;
  2. the root gets event 0x18, which every child receives: engines stop; each seat that still holds a soldier resets its weapons, puts him out and, on the server, destroys him. Nobody survives a destroyed vehicle from inside;
  3. the armor's destruction explosion goes off (explosionDamage, explosionRadius), and the hull is pushed upward by the explosion force: the hop of an exploding tank;
  4. the kill is booked for everyone aboard (kills and scoring).

One hit cannot take a whole vehicle from healthy to gone. The armor limits the overkill (ArmorGLComp::addDamage, 0x006325d0): a hit larger than what is left leaves the wreck with most of its own wreck health.

The wreck#

A wreck bleeds wreckHitPoints / (timeToStayAsWreck x 30) every tick (0x0062fac0) and is gone when it reaches minus wreckHitPoints, after timeToStayAsWreck seconds: 20 by default, and for ever when the template says -1. At the end the wreck explosion goes off (wreckExplosion*), which is why standing on a burning hull is unwise twice. The object is removed timeToStayAfterDestroyed seconds later.

A wreck can be repaired only if canBeRepairedWhenWreck says so.

What the port has#

PartState
the spawner's template, the update loop, the timerverified
spawnObject's blocking rulesthe port's own implementation, checked on recorded runs of the original server
abandonmentverified: 514 of 514 armor events of a recorded run
the armor's damage, overkill limit, wreck countdownverified (damage and armor)
destruction: event 0x18, the occupants, the explosions, the pushverified on the original server, as the notes head that section
the upside-down check's ground testnot run, as the notes say
2142
Battlefield 2142 and Heroes

In 2142 and Heroes the spawn delay does use its random draw: a delay between the minimum and the maximum (random numbers). 2142's spawner never counts a Titan as a blocking empty vehicle, and passes a control point's change of team on to the vehicles it made where the template asks (the missile silos: game modes); its wrecks bleed with another material id. Heroes adds pocket vehicles, which a hero calls from an item instead of a spawner (widgets).

How it is tested#

  • Oracle tests: the original's object spawner update and abandon check, and the armor's state, damage, repair, tick and water timers are run in a process of its own on a list of inputs, and the port must give the same output bit for bit (the oracle) (vehicle_oracle.rs, damage_oracle.rs in crates/bf2-gameplay/tests).
  • Per-game rules (crates/bf2-server/src/vehicles_armor.rs): the wreck's fast bleed, self damage, how long a wreck is invulnerable, in Battlefield 2, 2142 and Heroes each.
  • In play: scenarios destroy a vehicle and wait for its wreck and its respawn.

All nine addresses of this page stand in a test. The upside-down check's ground test was not run.

In the code#

WhatWhere
the spawnercrates/bf2-gameplay/src/vehicle/spawner.rs
abandonmentcrates/bf2-gameplay/src/vehicle/abandon.rs, crates/bf2-server/src/vehicles_abandon.rs
vehicle armor, destruction, explosionscrates/bf2-server/src/vehicles_armor.rs, crates/bf2-world/src/vehicle_armor.rs
seat exits at destructioncrates/bf2-world/src/vehicle_control.rs

Notes: notes/subsystems/gameplay-vehicles.md (sections 4, 5 and "vehdrive5"), notes/subsystems/gameplay-damage.md.

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