Skip to content

176 deterministic sim 21 dock test and match controller

Alex Diakovsky edited this page Nov 21, 2026 · 2 revisions

176. Deterministic sim 21: the dock test and the rest of the match controller in 16.16 (stage S6.4c)

Question: after stage S6.4b the match controller was the largest simulation file with floats left: the dock test measured the vehicle's distance from the pad in world units, the loss sequence counted fractions of a tick, the hangar's confirm script stepped floats, and the compass, the radar's enemy-direction sector and the pad's lift worked on float positions and degrees. What do FUN_0040b980, FUN_00418040, FUN_0040d990 and FUN_0042ec50 do on their integers, and what changes when the port does the same (document 155, issue #133)?

The deterministic simulation series: document 155 is the plan. Documents 156 to 160 are stages S0 to S4, and documents 161 to 170 are S5. S6 takes the last floats out of the simulation files before the check goes into CI: S6.1 the height and water (document 171); S6.2 the Heli's take-off and landing (document 172); S6.3 the weapons (document 173); S6.4 the rest, in four parts: S6.4a the explosion damage boxes (document 174), S6.4b the road assist (document 175), S6.4c the dock test and the rest of the match controller (this document), S6.4d the view code fenced off from the lint; then S6.5 the CI runs.

The dock was traced in documents 77 and 81, the hangar in 78, the loss sequence in 88, the compass in 71, the radar's direction cursor in 108 and the pad's lift in 99. This document reads each one again for its integers. Two of them turned out different from what the port did: the hangar scripts' continue flags, and the origin of the radar's direction sector.

Glossary

Term Meaning
16.16, raw As in document 161: 0x10000 is one unit.
raw angle 22 bits: 0x400000 is a full turn, 0x10000 one 5.625-degree step. 0 is north, clockwise.
cell One map tile, 32 units: the position >> 21. Its centre is cell * 0x200000 + 0x100000 (FUN_0042e480). The port's _tile_of and _cell_centre_fx.
view region #region view in a simulation file (document 155): code only the views read. The float lint does not count it, and simulation code may not read its names.
FUN_00422e70 The bearing from one point to another as a raw angle. The port's Projectile.bearing_fx.
FUN_0042cda0 The squared distance between two objects in whole units: ((x1 − x2) >> 16)² + ((y1 − y2) >> 16)².

The answer, up front

  1. The dock test (FUN_0040b980) asks the vehicle's cell, then its offset from the cell's centre in whole units, (x & 0x1f0000) − 0x100000, against the vehicle record's tolerance (+0x254). Within it, a fresh press of any button docks; either way the weapon dispatch is skipped, so a button held on the pad does not fire. The port fired then.
  2. The loss sequence is whole ticks and 16.16 fades: the view darkens 0x51e a tick, the skull and the post-drowning view fade 0x11eb, the icon row fades in 0x51e, and the out-of-vehicles phases count 0x51e a tick to 0x10000 (51 ticks). These were already exact as floats; nothing moves.
  3. The hangar's confirm scripts (FUN_00418040) carry a continue flag on each step: a step that ends with the flag at 0 ends the tick. The Tank's and the Heli's scripts wait after the slide; the Jeep's and the MSV's after the rise with the picture, and after the last step. The port waited after every slide. The fade step is 0x11eb (the pack had 0.0702, which is 0x11f8).
  4. The compass (FUN_0040d990) takes the exact bearing, not one rounded down to a step.
  5. The radar's direction sector is computed in the vehicle's own tick from the vehicle toward the other player's vehicle, 0 = north. Document 108 had read the origin as the player's base; the port also used 0 = east.
  6. The pad's lift (FUN_0042ec50) scans the pad's cell and its eight neighbours (table 0x44df90): a mine there whose whole-unit squared distance is under 400 goes, and any flag there is returned or captured.
  7. The rest moved onto the integers already there: the spawn and the pad are cell centres, the zone test is the traced chain test, the guard rocket starts from its 16.16 muzzle, the turrets wake in an integer square round each vehicle, and the decoration jitter has a 16.16 table.

The float lint counts nothing in match_controller.gd; the whole lint is down from 1160 to 632.

Step 1: the dock test, FUN_0040b980

// FUN_0040b980 (ForceDecompile.java 40b980), the dock block, names added
if (not_moving && (cell->art & 0x7f) == base->pad_art) {       // obj+0x1c, vehicle+0x5c +0x2c
    int dx = (obj->x & 0x1f0000) - 0x100000;
    int dy = (obj->y & 0x1f0000) - 0x100000;
    int tol = record->dock_tolerance;                            // +0x254: 4, 9, 4, 32
    if (-tol <= dx && dx <= tol && -tol <= dy && dy <= tol) {
        if ((keys & 0x920) == 0) FUN_0040b400(player);           // no fresh press
        else if (record->dock_handler == 0) { if (type != 3) FUN_0042f110(obj); }
        else state->handler = record->dock_handler;              // +0x258
        goto after_weapons;                                      // LAB_0040c029
    }
}
if ((keys & 0xe0) && record->weapon_a) record->weapon_a(...);    // only reached off the pad

The offset keeps whole units only: a vehicle 4.9 units from the centre is at 4. The port compared the float distance.

func can_dock(v: Vehicle) -> bool:
	...
	var dx := (v.pos_fx.x & 0x1f0000) - 0x100000
	var dy := (v.pos_fx.y & 0x1f0000) - 0x100000
	var tol := Pack.fx(pack.vehicle_value(v.vehicle_type, "stats.dock_tolerance", 4))
	return dx >= -tol and dx <= tol and dy >= -tol and dy <= tol
func _dock_pressed() -> bool:
	if not dock_check.is_valid() or not dock_check.call(self):
		return false
	var buttons := false
	if controls != null:
		buttons = input_state & (InputWord.A_PRESS | InputWord.B_PRESS | InputWord.C_PRESS) != 0
	...
	if buttons:
		dock_requested.emit()
	return true   # the weapons are skipped either way

Step 2: the loss sequence

The constants were already the original's (document 88); they were floats of exact 16.16 values, so every comparison came out the same. They are integers now:

const DEATH_DARKEN_PER_TICK_FX := 0x51e                  ## FUN_00418830
const DEATH_SKULL_FADE_PER_TICK_FX := 0x11eb             ## FUN_004189a0 (and 0x418390's view fade)
const ROW_FADE_PER_TICK_FX := 0x51e                      ## FUN_00418510
const OUT_PHASE_STEP_FX := 0x51e                         ## 0x418a50 / 0x418af0
	elif ps.death_phase == 3:
		ps.view_fade_fx = maxi(ps.view_fade_fx - DEATH_DARKEN_PER_TICK_FX, 0)
		if ps.view_fade_fx <= 0:
			ps.death_phase = 4

The slot keeps view_fade_fx, skull_alpha_fx, row_fade_fx, out_fx, spawn_fx and pad_fx; the float names the HUD reads (view_fade, skull_alpha, row_fade, spawn_px, pad_centre) are views of them.

Step 3: the hangar's confirm scripts, FUN_00418040

// FUN_00418040 (ForceDecompile.java 418040): state+0xc8 points at the current step {routine, p1, p2, p3, continue}
step = state->script;
while (step->routine != 0) {
    if (step->routine(state, step) == 0) goto draw;   // not done: again next tick
    state->script = step + 1;
    if (step->cont == 0) goto draw;                    // done, but the next step waits for the next tick
    step = step + 1;
}
// the end of the list: the vehicle is released (state+0xc0 = 0x4183e0)

The steps, dumped from the four scripts:

Script Steps (continue flag)
Tank 0x449108, Heli 0x449050 sound (1), platform up (1), sound (1), slide (0), sound (1), clear panel (1), rise with picture (1), rise and fade (1)
Jeep 0x448fc0, MSV 0x448f30 sound (1), slide (1), sound (1), clear panel (1), rise with picture (0), rise and fade (0)

The fade step's p2 is 0x11eb in all four. The extractor now writes the flags (selector.json "continue") and the exact fade (0.0699920654296875). SelectorAnim steps 16.16 values:

		if not done:
			return
		_i += 1
		if int(s[3]) == 0:
			return   # the continue flag is 0: the next step (or the end of the list) waits for the next tick
	running = false
	finished = true

Step 4: the compass, FUN_0040d990

// FUN_0040d990 (ForceDecompile.java 40d990), one target
b = FUN_00422e70(&obj->x, &target->x) - obj->heading;
if ((b & 0x3e0000) == 0) v = 16;
else {
    u = b & 0x3fffff; if (u > 0x1fffff) u = -u & 0x3fffff;
    v = u < 0x100000 ? min((0x10000 - ((u << 2) >> 8)) >> 12, 15) : -1;
}
func _compass_magnitude(v: Vehicle, target: Vector2i) -> int:
	var turn := Projectile.bearing_fx(v.pos_fx, target) - v.heading_fx
	if (turn & 0x3E0000) == 0:
		return 16
	turn &= 0x3FFFFF
	if turn > 0x1FFFFF:
		turn = (-turn) & 0x3FFFFF
	if turn < 0x100000:
		return mini((0x10000 - (turn >> 6)) >> 12, 15)
	return -1

The port had rounded the bearing down to a whole step first; the original does not.

Step 5: the radar's direction sector, FUN_0040b980's tail

// FUN_0040b980, the end of the vehicle's tick
if (record->radar_rects != 0 && base->next_sector_at < now) {        // +0x298; vehicle+0x5c +0x7c
    enemy = vehicles[player ^ 1];
    if (enemy == 0) base->sector = 0xffff;
    else if (FUN_0041d5b0(&enemy->x, &obj->x, record + 0x2ac)) base->sector = 8;   // the dead zone
    else base->sector = min((FUN_00422e70(&obj->x, &enemy->x) + 0x40000 & 0x380000) >> 19, 7);
    base->next_sector_at = now + 0x3c;
}

obj is the vehicle itself. Document 108 took vehicle+0x5c (where the sector is stored) for the origin; it is the per-player record, and the bearing starts at the vehicle. The sector counts from north like every raw angle; the port counted from east.

	var off := nearest.pos_fx - v.pos_fx   # FUN_0041d5b0(enemy, vehicle, record + 0x2ac)
	if off.x >= Pack.fx(dz[0]) and off.x <= Pack.fx(dz[2]) and off.y >= Pack.fx(dz[1]) and off.y <= Pack.fx(dz[3]):
		return 8
	var bearing := Projectile.bearing_fx(v.pos_fx, nearest.pos_fx)
	return mini(((bearing + 0x40000) & 0x380000) >> 0x13, 7)

Step 6: the pad's lift, FUN_0042ec50

// FUN_0042ec50 (ForceDecompile.java 42ec50)
for (off in {-129, -128, -127, -1, 0, 1, 127, 128, 129})            // table 0x44df90
    for (o in objects listed in cell (pad + off)) {
        if (o->class == 10 && FUN_0042cda0(&lift->x, &o->x) < 400) destroy(o);        // a mine, quietly
        else if (o->class == 12) { if (o->team == lift->team) return_flag(); else win(lift->team); }
    }
	var pad := _tile_of(ps.pad_fx)
	for m: Mine in mines.duplicate():
		var mt := _tile_of(m.pos_fx)
		var dx := (m.pos_fx.x - ps.pad_fx.x) >> 16
		var dy := (m.pos_fx.y - ps.pad_fx.y) >> 16
		if absi(mt.x - pad.x) <= 1 and absi(mt.y - pad.y) <= 1 and dx * dx + dy * dy < 0x190:
			...
	for idx in flags.keys():
		...
		var ft := _tile_of(f.pos_fx)
		if absi(ft.x - pad.x) > 1 or absi(ft.y - pad.y) > 1:
			continue

The port had a box of 1.5 tiles round the centre for the flags, which is the same cells except on their far edges.

Step 7: the rest

  • The zone test while standing still (FUN_0040c540, traced at the start of this stage) is FUN_0041e4c0 between the vehicle's chain and the zone tile's shape at the cell's centre, heading 0. The vehicle keeps zone_tile and zone_chain; the port's float box is gone.
  • The guard rocket starts at the guard's 16.16 position plus the muzzle, with raw launch angles (start_homing(target, heading, pitch)).
  • The turrets wake within an integer square of turret.wake.half_extent (288 units) round each live vehicle. The port had used the camera's view where there was one; a camera is not part of a lockstep simulation. (The original wakes a turret from its tile's draw callback; the square is the port's stand-in, as before.)
  • The spawn, the pad and the start mines are cell centres; the start mines' positions roll x first, as before.
  • The decoration jitter has a 16.16 table (LevelData.jitter_fx_at); jitter_at and facing_at are its views.
  • Ground marks, gates, wrecks and mines are called with their 16.16 positions; a shell's hit heading is raw (take_damage_fx(damage, heading)).
  • Debris, sounds, the drone voice, the effects and the drawing helpers are fenced as views; the AI's helpers (turret_threats, service_points, terrain_rule_at, tile_aim_point, ...) as ai. The lint now lets a connect(...) statement hand a view to a signal, like emit(...).

The golden check

A dump on RFMAP001 and RFMAP002, match seed 1996, once for each hangar bay (Tank, Jeep, MSV, Heli), 2400 ticks each, logging every tick the position, heading, speed, height, the dock and hangar state, the pad, the view fade, the loss sequence, the compass, the radar sector, the confirm script's offsets, the vehicle type, the ammunition, the mines and the turrets. The scripted player holds A from tick 280; at tick 300 the vehicle is set down beside its pad, off the centre by 0, 4.5, 3.0 or −4.7 units in x (half that in y) for bays 0 to 3; A is let go at 330 and pressed afresh at 340; the bay is chosen at 600 and confirmed at 800; it drives and fires from 1300, turns on the spot from 1650 to 2100, and is destroyed at 2150. The pack was re-imported first, so both runs read the new selector.json.

Every difference is one of the changes above:

  • The weapons on the pad. In the six runs where A is held within the tolerance (bays 0 and 2, and bay 1 after, on both levels) the ammunition is one round higher from tick 301: before, a held button fired on the pad; after, it does not.
  • The tolerance in whole units. At 4.5 units off (bay 1) the vehicle now docks at tick 340 (4.5 keeps 4, within the Tank's 4); before, 4.5 was outside. Everything after follows from that dock: the sink, the hangar, the Jeep confirmed, its drive. At −4.7 (bay 3) neither docks (−4.7 keeps −5).
  • The continue flags. For the MSV (bay 2) the rise with the picture ends with its flag at 0, so the rise and fade start a tick later (tick 871: 109.5 against 110 before), the fade ends a tick later (946), and the undock, the pad and the drive-off follow one tick later. The Tank's script waits after the slide as the port's already did: bay 0 is unchanged.
  • The compass. While the vehicle turns on the spot, each change of value comes two or three ticks of turning earlier or later (0x8000 to 0xc000 of heading): the exact bearing against the bearing rounded down to a step. At the 90-degree edge that is 12 against 0 (beyond).

The death sequence (the darkening, the skull, the row fade) is identical in all eight runs: its constants were exact 16.16 values already. The radar sector is not in the dump (the match has one player there); radar_direction_check covers it.

Tests

  • Engine suite and openfire suite: all pass. The checks that set float positions now pass 16.16 ones (mines, flags, respawn, gates, wrecks' water callbacks, the guard rocket's launcher).
  • openfire radar_direction_check: the sector from the vehicle itself, 0 = north: an enemy to the east is 2, south 4, west 6, north 0; the nearer of two is the one pointed at.
  • openfire dock_sink_check, death_sequence_check, flag_pad_check, compass_values: unchanged expectations on the integer state.
  • Engine float_lint_check: the self-test has a sig.connect(view) statement, allowed like emit. 0 hits in match_controller.gd; 632 in all (from 1160).
  • openfire importer_parity_check: the re-imported pack matches a fresh import (2898 files).

Known differences from the original, kept

  • Which enemy the radar's sector points at: the nearest live one (the original has one other player).
  • The turret wake square stands in for the tile's draw callback.
  • FUN_0040b400 (the dock test with no button pressed) is still not modelled (document 152).
  • Class 17 (debris splash markers) on the pad is not modelled: the port has no such objects.

Where the code is

  • Engine game/match_controller.gd: can_dock, _update_death, _death_tick, _compass_magnitude, _compute_direction_sector, _pad_clear, _update_slot_dock, confirm_selection, _wake_turrets, _launch_guard_rocket, _update_zone.
  • Engine game/vehicle.gd: _dock_pressed, respawn; game/player_slot.gd; game/selector_anim.gd; game/level_data.gd: jitter_fx_at.
  • Engine tests/float_lint_check.gd: the connect rule.
  • openfire tools/extract_selector.py (the continue flags and the fade), tools/tests/radar_direction_check.gd.

Commits: engine 6e2941c, openfire 66dc1e9.

S6.4c is done. Next: S6.4d, the view code fenced off from the lint (document 177).

Clone this wiki locally