On this page
A vehicle's life: spawner, abandonment, wreck, the next one
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.
The spawner#
ObjectSpawner (template bf2_w32ded.exe!0x00571560, object 0x00571340), with the constructor's defaults:
| Property | Default | Meaning |
|---|---|---|
setObjectTemplate <team> <name> | what to spawn for which team: a spawner at a control point makes the owner's vehicle | |
minSpawnDelay, maxSpawnDelay | 30, 60 | seconds before the next one; see below |
spawnDelayAtStart | 0 | wait the delay before the first one too |
timeToLive | 60 | handed to the vehicle: its countdown once abandoned |
distance | 50 | within this many metres of the spawner a vehicle is "at home" and never counts down |
damageWhenLost | 50 | hit points a second once the countdown is over |
maxNrOfObjectSpawned | 1 | how many of its vehicles may exist at once |
nrOfObjectToSpawn | -1 | how many in all; -1 is without end |
controlPointId, team, teamOnVehicle | -1, 0, 0 | which control point's owner it follows; whether the vehicle itself carries the team |
holdObject | 0 | keep the vehicle attached to the spawner (stationary weapons) |
useButtonRadius | 0 | spawn 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.
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):
- 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;
- 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;
- 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; - 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#
| Part | State |
|---|---|
| the spawner's template, the update loop, the timer | verified |
spawnObject's blocking rules | the port's own implementation, checked on recorded runs of the original server |
| abandonment | verified: 514 of 514 armor events of a recorded run |
| the armor's damage, overkill limit, wreck countdown | verified (damage and armor) |
| destruction: event 0x18, the occupants, the explosions, the push | verified on the original server, as the notes head that section |
| the upside-down check's ground test | not run, as the notes say |
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.rsincrates/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#
| What | Where |
|---|---|
| the spawner | crates/bf2-gameplay/src/vehicle/spawner.rs |
| abandonment | crates/bf2-gameplay/src/vehicle/abandon.rs, crates/bf2-server/src/vehicles_abandon.rs |
| vehicle armor, destruction, explosions | crates/bf2-server/src/vehicles_armor.rs, crates/bf2-world/src/vehicle_armor.rs |
| seat exits at destruction | crates/bf2-world/src/vehicle_control.rs |
Notes: notes/subsystems/gameplay-vehicles.md (sections 4, 5 and "vehdrive5"), notes/subsystems/gameplay-damage.md.
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.