Repository navigation
60 worked example mines
Update (document 174): the damage box now runs the record's script on integer progress (first step 0x10000), so it lives 145 ticks, and it is tested per scanned cell with the type-2 chain test like the original: tiles, gates, vehicles, soldiers, wrecks and Drones.
Update (document 173): mines come cooldown + 1 ticks apart (141), placed at the heading's direction step times the offsets in 16.16, not where the point is deep water.
Question: how does the MSV lay a mine, what does a mine do, and how does its explosion hurt things? Document 50
had found the one explosion that damages anything (record 0x445058) and guessed it belonged to a mine, without
tracing what spawns it. Field names and scripts are in the tracing cheat sheet.
The per-tick weapon dispatch is in FUN_0040b980's neighbour at 0x40bfbe-0x40c026. Reading its disassembly
(DumpDisasm.java 0x0040bf90 0x0040c130) shows three buttons, each testing a group of bits of the input flags
(state+8) and calling a handler stored in the vehicle's record:
0040bfc1 TEST AL,0xe0 ; bits 5-7 -> handler [record+0x17c], slot [record+0x188]
0040bfe2 TEST AH,0x7 ; bits 8-10 -> handler [record+0x180], slot [record+0x18c]
0040c007 TEST AH,0x38 ; bits 11-13 -> handler [record+0x184], slot [record+0x190]
For the MSV (record 0x445c88, dumped with DumpDwords.java 0x445df8 60) the handlers are 0x40d520 (rockets) for
the first two and 0x40d820 for button C, with slot 1. Slot 1 of the record's weapon table (+0x194 + 1*0x34)
reads: offsets 0 and 5.0 at +4 / +8, cooldown 0x8c = 140 ticks at +0x10, ammo 10 at +0x14.
if ((keys & 0x60) != 0 && 1 < DAT_00442fbc) {
slot = record + 0x194 + slot_no*0x34; st = state + 0x24 + slot_no*0x10;
if (st[+8] < now && st[+0xc] > 0 && state[+0x70] != 2) { // ready, has ammo, not in deep water
idx = obj[+0x4c] >> 16; // heading step
x = dir[idx].x * slot[+4] + obj.x;
y = dir[idx].y * slot[+8] + obj.y;
mine = FUN_00409e30(x, y); // create; refused on deep water
if (mine) { st[+0xc] -= 1; st[+8] = slot[+0x10] + now; }FUN_00409e30 checks the terrain at the spot (FUN_0042f410 == 2 refuses) and spawns class 0x4430c8.
Quirk kept as coded: the x offset field is 0 and the y field is 5.0, and each is multiplied by the matching
component of the heading's unit vector. So the mine lands 5 * dir.y units away in y only: 5 units ahead of a
vehicle facing along y, and exactly on top of a vehicle facing along x. (We cannot tell whether the original meant a
rotated offset; the code does not.)
In the port the layer is a behaviour module (engine, game/vehicle_modules/mine_layer.gd), with the slot's numbers as
its parameters (interval_ticks 140, offset_x 0, offset_y 5.0), the offset quirk kept:
# game/vehicle_modules/mine_layer.gd
func tick(v: Vehicle, delta: float) -> void:
v._mine_cooldown_remaining = maxf(v._mine_cooldown_remaining - delta, 0.0)
if v.mine_layer_enabled and v._wants_mine() and v._mine_cooldown_remaining <= 0.0: # 1 < DAT_00442fbc; ready
_drop(v)
func _drop(v: Vehicle) -> void:
var rad := deg_to_rad(v.heading_deg)
var at := v.position + Vector2(cos(rad) * f("offset_x"), sin(rad) * f("offset_y")) # dir.x * slot[+4], dir.y * slot[+8]
if v.water_class == 2 or (v.level != null and v.pack != null and Water.class_at(v.level, v.pack, at) == 2):
return # state[+0x70] == 2, or FUN_00409e30 refuses deep water
var slot := int(params["ammo_slot"])
if v.ammo[slot] < 1 and not v.infinite_ammo: # st[+0xc] > 0
return
if not v.infinite_ammo:
v.ammo[slot] -= 1
v._mine_cooldown_remaining = f("interval_ticks") / TICK_HZ # st[+8] = slot[+0x10] + now
v.mine_dropped.emit(at)Dumping the class table (DumpDwords.java 0x4430c8 24) gives: init 0x409ca0, destroy 0x409d80, update 0x409cd0,
draw descriptor 0x454200, priority 0x96 (150), object-collision callback 0x409dd0 (+0x38), hit callback
0x409e00 (+0x3c). None of these are recognised functions, so they were read with DisasmForce.java (the decompiler
gave the smaller ones):
-
Init: state (draw variant,
obj+0x10) = 0, ageobj+0x60= 5.0, blink counterobj+0x5c= 0, plays a sound. The object's descriptor (obj+0x3c, copied from the class's+0x14) is0x454200, whose shape-chain field (+8) is 0: with no shapes, the collision code (FUN_0042bd40, and the loop inFUN_0042bb10that runsFUN_0041e4c0) never reports a hit. So a fresh mine is inert. -
Update:
age += 8738 * dt(raw 16.16, so 0.1333 per tick); the blink counter counts ticks and wraps at 30; the variant is 2 while whole(age) > counter, else 0, and a beep plays on each switch to 2. When age reaches 26.0 (about 158 ticks) it doesobj+0x3c = 0x4542c8, callsFUN_0042c250, and sets the variant to 1. Descriptor0x4542c8is a copy of the mine's with+8=0x454288: a shape chain. From then on the mine collides. So the fast-beeping blink is a fuse that speeds up (5 of every 30 ticks lit at first, 25 of 30 at the end), and the steady variant 1 means armed. -
Destroy (
0x409d80): only if flag0x200is set (set by the two callbacks below) it spawns explosion record0x445058at its position. An armed mine stays until something sets it off. -
Collision callback (
0x409dd0): if the other object's class is 1 (a vehicle), set flag0x200and destroy. -
Hit callback (
0x409e00): if the damage is above 1.5 (0x18000), do the same. -
Art: descriptor
0x454200is one quad, cel0x439= 1081 with flag 8 (+ variant), corners +-6 in x and y at z = 1. The three cels are 8 x 8 "ember" sprites: a small blinking light on the ground.
Shapes (armed only). The chain from 0x454288 holds a 12 x 12 box (layer 1, mask 6) and, linked from it, the 32 x 32
box at 0x454248 (layer 1, mask 2); both span z from -50 to 0.1. Who triggers it, using the pair rule of
document 53: a vehicle (layer 2) touches either box; a shell (layer 4) could only
touch the small one, but a shell flies at z 7, above the boxes' 0.1 top, so level shots never touch mines.
In the port the mine (game/mine.gd) keeps the update's three numbers and its blink rule:
# game/mine.gd
const AGE_START := 5.0
const AGE_PER_TICK := 8738.0 / 65536.0
const AGE_EXPIRE := 26.0
const BLINK_PERIOD := 30
const TRIGGER_BOX := [-16.0, -16.0, 16.0, 16.0] ## shape 0x454248, mask 2
const SHELL_BOX := [-6.0, -6.0, 6.0, 6.0] ## shape 0x454288, mask 6
const HIT_DAMAGE_MIN := 1.5 ## FUN_00409e00: damage above 0x18000
func advance(ticks: float) -> void:
if armed:
return
age += AGE_PER_TICK * ticks
if age >= AGE_EXPIRE: # descriptor 0x4542c8: the shapes appear, variant 1
armed = true
variant = 1
return
_counter = fmod(_counter + ticks, float(BLINK_PERIOD))
var lit := int(floor(age)) > int(floor(_counter)) # variant 2 while whole(age) > counter
var v := 2 if lit else 0
if v != variant:
if v == 2:
beep.emit()
variant = vFUN_0042bb10 (read in full) decides between two overlapping objects by the classes' priorities at +0x30: the
callback of the higher-priority class runs, unless it has none. Vehicles have priority 100, mines 150, explosions
200. So a vehicle (the mover) touching a mine runs the mine's callback (0x409dd0); an explosion box touching a
vehicle runs the explosion's (0x42dd20). Only a mover is tested (FUN_0042bd40), so a vehicle that stands
still on a mine does not set it off, but one that starts to move does.
The explosion class (0x44bb70, priority 0xc8 = 200) runs its script every tick (FUN_0042dbe0), and ends when
its progress reaches the record's duration (the box is freed in FUN_0042dca0). The ops that make the box:
-
Op 13,
FUN_0042d640: allocates a box object;DAMAGE_BOX z_lo z_hi width height mask damagebecomes a type-2 shape with z fromz_lotoz_hi, half-widthwidth/2, half-heightheight/2, layer 0x20, the given mask, and the damage rate stored at+0x68. -
Op 14,
FUN_0042d710:BOX_EXTENT nsets x, y and z to +-n.
For record 0x445058 the script is DAMAGE_BOX -4 4 8 8 0x43 -1, sound, WAIT 4, BOX_EXTENT 25, (one tick) BOX_EXTENT 12, WAIT 8, BOX_EXTENT 16, WAIT 12, BOX_EXTENT 20, end; progress advances 1/6 per tick and the duration is 25,
so the explosion lasts 150 ticks (2.4 s): the box is +-4 for the first 24 ticks, +-12 until progress 8, +-16 until
12, then +-20 to the end.
Damage. The box's object callback FUN_0042dd20 passes |rate| * dt to the victim's hit callback (-1 in the op =
1.0 per tick; dt is the whole ticks since the last frame), and its tile callback FUN_0042dcd0 passes the same to the
tile damage function of document 45. The vehicle rule of document 47 then applies: a Tank (armour 0.3) loses 0.7 per
tick, an MSV (0.5) loses 0.5, and sitting in the box is fatal within a second or two. Which things a box can touch:
it needs each side's mask to contain the other's layer. Vehicles (layer 2, mask 0x27) and every tile shape (layer 1,
mask 0xff) qualify; mines (masks 2 and 6, no 0x20) do not, so explosions do not set off other mines.
In the port the box is ExplosionBox (game/explosion_box.gd), which runs the same script ops on the same
progress; MatchController applies damage_per_tick x the ticks to what the box overlaps:
# game/explosion_box.gd, advance()
_progress += float(_record.get("rate_per_tick", 0.25)) * ticks
if _progress >= float(_record.get("duration", 1.0)): # FUN_0042dca0 frees the box
finished = true
active = false
return false
...
"DAMAGE_BOX": # op 13, FUN_0042d640
z_lo = float(op[1])
z_hi = float(op[2])
half_x = float(op[3]) * 0.5
half_y = float(op[4]) * 0.5
mask = int(op[5])
damage_per_tick = -float(op[6]) # |rate|: -1 is 1.0 a tick
active = true
_pc += 1
"BOX_EXTENT": # op 14, FUN_0042d710: +-n on all three axes
half_x = float(op[1])
half_y = float(op[1])
z_lo = -float(op[1])
z_hi = float(op[1])
_pc += 1-
game/mine.gd(age, blink, beep, arming, and the trigger boxes),game/mine_view_3d.gd(the quad),game/explosion_box.gd(the timeline of the box, mirroring the script runner ofexplosion_effect_3d.gd). -
Vehicle(MSV only): keyM(orRF_DEBUG_MINE=1) lays a mine every 140 ticks at the traced offset. -
MatchController: mines age; any moving vehicle overlapping an armed mine's trigger box sets it off; the explosion plays record0x445058and its box damages vehicles and tile shapes every tick (a building with 6 hit points falls in six ticks)._damage_tilenow takes an amount. - Checked by a scripted run: a drop facing east lands on the vehicle, one facing south 5 units ahead; a mine arms after 158 ticks with 6 beeps; a vehicle that keeps driving over its own fresh mine does nothing until the fuse ends; armed, a stationary vehicle on it does not set it off but the first movement does, and the vehicle then loses 0.5 hit points per tick until it is gone. Screenshots: the unlit mine on the ground, and an explosion with the vehicle in its hit flash.
Document 60's first version kept a placeholder: it assumed a mine started colliding at once, so the MSV laying it would
set it off the moment it moved (the code has no owner rule). Reading the creation function (FUN_0042c290) and the
mine's descriptor showed the real mechanism: the mine has no collision shapes for its first 158 ticks, so the
dropper, which lays it inside its own shape and drives away in well under 2.5 s, is never in danger unless it stays
or comes back. The placeholder and its debug switch were removed.
- The offset quirk of step 2 is reproduced as coded.
-
Explosion clock.
FUN_0042dbe0has a first-tick special case (flag 0x40sets the progress to 1.0); the port's explosions (documents 50-51) start at 0, so the box timeline is up to 1 progress unit (6 ticks) late if the flag is set for this object. Not checked. - Not modelled: ammo (10), the deep-water refusal, the sound, the elevated rocket and everything the Jeep and Heli add.
Next: back to the next-steps doc.
Return Fire, rebuilt
Elsewhere