Repository navigation
73 worked example vehicle stock
Question: document 66's panel element FUN_004116a0 draws a count per vehicle type from bytes at 0x48c880 + player * 0xd0 + 0xb8 + type, and the ammo code (document 72) mentions a reserve at +0xbc.
Where do those numbers come from, and what changes them? Scripts and field names are in the tracing cheat sheet.
docs/PORTING_PLAN.md section 1.5 had decoded the .RFM's six VHCL bytes (or the [A3H5T2] filename suffix) as A, H, J, M, T and an unknown, "never traced for meaning". Their parser FUN_00413f00
(decompiled again) ends with the answer to where they go:
DAT_00443030 = local_9; DAT_0044301c = local_9; /* T */
DAT_00443031 = local_8; DAT_0044301d = local_8; /* J */
DAT_00443032 = local_7; DAT_0044301e = local_7; /* A */
DAT_00443033 = local_6; DAT_0044301f = local_6; /* H */
if (M == 0xff && players == 2) M = 0; DAT_00448e80 = M; DAT_00448e84 = unk4;with defaults T 3, J 8, A 3, H 3, M 0xff, unk4 0xff and limits T, A, H < 10, J 1-9, M < 201. The four bytes are stored in vehicle-type order (0 Tank, 1 Jeep, 2 MSV, 3 Heli), so T = Tanks,
J = Jeeps, A = MSVs (by position; the letter itself is not explained), H = Helicopters: the number of vehicles of each type the player has for the level (level 1 uses the defaults: 3, 8, 3, 3).
M is a separate count (FUN_0042a030(M) at match start, or a level-derived count when M is 0xff and the level's LEVL is above 5): not the mine reserve; what it spawns is untraced.
In the port the level converter reproduces the parser's layering (defaults, then the filename's brackets, then
the chunk), and the match start fills each player's stock from it. Which key a type reads (T, J, A, H) is
in the pack's roster (document 105), not in
code:
# tools/convert_rfm.py
VHCL_DEFAULTS = {"A": 3, "H": 3, "J": 8, "T": 3, "unk4": 0xFF, "M": 0xFF}
def resolve_vhcl(filename, vhcl_payload, mode_byte):
"""Layer defaults -> filename brackets -> VHCL chunk, matching FUN_00413f00."""
values = dict(VHCL_DEFAULTS)
...
if values["M"] == 0xFF and mode_byte == 2: # if (M == 0xff && players == 2) M = 0
values["M"] = 0# game/match_controller.gd, a player's slot at match start
var vp: Dictionary = level.vehicle_params
ps.stock = []
ps.stock.resize(pack.vehicle_order.size())
ps.stock.fill(0)
for entry in pack.roster_for(level):
var t := pack.vehicle_index(String(entry.get("id", "")))
if t >= 0:
ps.stock[t] = int(vp.get(String(entry.get("stock_key", "")), int(entry.get("default_stock", 0)))) # DAT_00443030 + typeThe per-player bytes at +0xb8 .. +0xbb are those four counts. Three sites (found with FindDispOps.java 0x401000 0x440000 "0xb8]"):
-
Creating a vehicle (
FUN_0040b6xx, disassembled at0x40b833):if (stock != 0xff && stock != 0) stock--. 255 is "unlimited" and 0 never goes negative. -
A vehicle docking at its base (
0x42f1b0-0x42f1d2, the function that runs when a vehicle reaches its base tile):if (stock != 0xff) stock++, and for an MSV (type == 2) it first adds the vehicle's remaining mines (state + 0x40) to the player's byte+0xbc(a mine reserve). -
The last vehicle:
0x40b330/0x40b694test whether all four bytes are 0; when a vehicle is lost with nothing left the player's state handler is set to0x418390: the lost condition. (What that handler shows is untraced.)
The creation code also gives an MSV min(reserve, 10) mines from the reserve byte +0xbc (0x40ba61: puVar1[0x10] = min(reserve, rec[+0x1dc]), reserve -= that), and the reserve is initialised to 0 (0x4095e7): so in the
original an MSV's mines may come from that reserve, filled by returning MSVs (and, probably, pick-up crates, 0x42f1bb context). The port keeps giving an MSV its full 10 mines (untraced choice) until the reserve's other writers are read.
In the port:
# game/match_controller.gd
func _take_stock(ps: PlayerSlot, t: int) -> bool: # creating a vehicle: if (stock != 0xff && stock != 0) stock--
if t < 0 or t >= ps.stock.size():
return true # not a roster vehicle (a mod's extra definition): no stock to count
if ps.stock[t] == 255:
return true
if ps.stock[t] <= 0:
return false
ps.stock[t] -= 1
return true
func _return_stock(ps: PlayerSlot, t: int) -> void: # docking: if (stock != 0xff) stock++
if t >= 0 and t < ps.stock.size() and ps.stock[t] != 255:
ps.stock[t] = mini(ps.stock[t] + 1, 254)The mini(..., 254) keeps a returned vehicle from turning a count into "unlimited". That is the port's own guard:
the original's byte would wrap at 255. The lost condition was later found to count Jeeps, not all four bytes
(document 95).
FUN_004116a0 (document 66) is therefore the vehicle-choice readout: it draws, for the type in its slot parameter, that vehicle's mini icon (cels 2163, 2161, 2164, 2162: Tank, Jeep, MSV, Heli in that order,
which settles the earlier doubt about the silhouettes), the count left (+0xb8 + type), and the vehicle's ammunition capacity (150, 16, 100, 100) with the second weapon's (Heli 50; MSV: the mine reserve +0xbc). What makes the game show it (the trip
back to the base, template slot 2's frame cel 1940) is not traced.
LevelData.vehicle_params; MatchController.vehicle_stock (from T, J, A, H; the starting Tank costs one), _take_stock / _return_stock with the 255 rule; the port's stand-ins: the V switch returns the current vehicle and
takes the next type in stock, a destroyed player vehicle is replaced from stock (same type, else the first type left), and with none left out_of_vehicles ends the match (a placeholder banner). A placeholder text line shows the counts.
tools/tests/stock_check.gd: with 2, 8, 3, 3 after the first Tank, 17 losses run through Tank, Jeep, MSV and Heli stock in turn and then end the match. All of the choice logic above is untraced; only the numbers, the spend/return rule
and the lost condition are from the code.
Correction (document 95): the loss test the loss sequence actually runs (FUN_0040b260) looks at the Jeep stock byte and a live Jeep only, not all four bytes; see document 95.
Next: sounds.
Addendum (2026-10-12): 0x443030..33 is player 1's copy of the counts. The level loader writes the same four bytes to player 0's 0x44301c..1f as well; both are +0xb8 of a per-player starting block at 0x443010 + p * 0x14 (document 135).
Return Fire, rebuilt
Elsewhere