Skip to content

140 worked example the two player rules

Alex Diakovsky edited this page Oct 13, 2026 · 3 revisions

140. Worked example: the two-player rules

Question: step 4 of the two-player roadmap (issue #72): pass the traced two-player rules through, now that two people can play (document 139). Three things were still open (issue #119):

  • what the half of a player who is out shows;
  • what the skull state's +0x3a is;
  • what writes a joystick player's device bytes.

The Drone's spawn refusal (#108) had not been read either. Scripts and field names are in the tracing cheat sheet.

Short answer:

  • The out player's half stays black with the skull and the crossed grid, frozen, because the world is not drawn in it again.
  • +0x3a is the type of the vehicle that died, written when it was created.
  • The device bytes are always 0 (document 137).
  • A drowning, or a vehicle that ran out of fuel, skips the skull when it is not the player's last chance.
  • A Drone is not spawned inside the other player's rectangle.

The port now applies these and every other traced two-player rule.

Step 1: the out player's half (#119)

The skull's phases draw like this (DecompileMany.java 0x004184d0 0x00418a50 0x00418af0 0x00418c70):

FUN_004184d0(st) { FUN_00408d60(st); FUN_00418510(st, 0x10000); ... }   // phase 2: the world (FUN_00408d60), then the skull
0x418a50 / 0x418af0 / 0x418c70:                                          // the out-of-vehicles phases (document 135)
    FUN_00422e00(view, cel, +0xbc); FUN_00418510(st, 0x10000); ...     // the darkening and the skull (and the grid): no FUN_00408d60

Translation: only phase 2 draws the world under the skull. From phase 3 the view is darkened to black. The out-of-vehicles handlers never draw the world again, so setting the brightness back to full (+0xbc = 0x10000 in 0x418a50) darkens nothing more, and the black stays. The skull, and from 0x418af0 the crossed grid, are drawn over it. 0x418c70 draws that picture twice more (once into each buffer) and then nothing, so it stays on screen, frozen, until the match ends. Document 135 said the live view comes back there; it does not.

Step 2: +0x3a, and the skull skipped (#119)

A sweep for writes to +0x3a in the vehicle and interface code finds two: 0x418a84 (the out path sets it to 0) and 0x40b880, in the vehicle creation:

0040b87b  MOV ECX,dword ptr [EBP + -0x8]    ; the new vehicle's type record
0040b87e  MOV DL,byte ptr [ECX]             ; its first byte: the type number
0040b880  MOV byte ptr [ESI + 0x3a],DL      ; into the player's mode state

Translation: +0x3a is the player's current vehicle type, so at a death it is the type of the vehicle that died. The icon row shows that type, as the footage showed.

It is also read in FUN_0040b5c0, the second of the two callbacks the wreck schedules (DecompileMany.java 0x0040b5c0):

r = (the same count as FUN_0040b260);          // 3, 0, 1 or 2 (document 135)
if (r > 1 && st->+0x3a != 1) { st->handler = 0x418390; return; }   // can go on, and it was not a Jeep: no skull
FUN_00418440(st);                              // else the skull

0x418390 fades the live view out at 0x11eb a tick (about 14 ticks, the skull's own fade rate) and then opens the vehicle choice (FUN_00418290). The callback is chosen at 0x40c890: a wreck whose +0xf bit 0 (flag 0x1000000 of its +0xc word) is set takes FUN_0040b5c0, any other wreck FUN_0040b5a0 (always the skull). A drowning (FUN_0040cf90, 0x40d03b) always takes FUN_0040b5c0. The wreck's init sets that flag (DecompileMany.java 0x0040c7e0):

if (vehicle_state->+0x14 < 1) wreck->+0xc |= 0x1000000;   // state +0x14 is the fuel (document 118): the vehicle ran out

So a vehicle that drowns or runs out of fuel, when it was not a Jeep and the player can go on, gets no skull; a vehicle destroyed by damage always gets it. (The same bit means something else on a live vehicle: FUN_0040b980 uses it to mark that the vehicle's own voice is playing.)

The skull's frame while a player is out: 0x4188c0 leaves the mouth index at 0x3bffff, entry 59 of the mouth table, which is frame 1 (entries 53 to 59 are all 1), and FUN_00418b50 sets it to 0, entry 0, frame 1 as well: the closed mouth throughout.

Put together with documents 88 and 135, a death now runs like this:

After a death: the wreck's callback is FUN_0040b5a0 (always the skull) or FUN_0040b5c0 (drowned or out of fuel), which skips the skull when the player can go on and the dead vehicle was not a Jeep; otherwise the skull runs to phase 4 and FUN_0040b260 picks the end, the out phases, or the choice

Mermaid source
flowchart TB
  W(["the wreck's wait ends"]) --> CB{"wreck flag<br/>0x1000000?"}
  CB -- "destroyed by damage<br/>FUN_0040b5a0" --> SK
  CB -- "drowned or fuel below 1<br/>FUN_0040b5c0" --> Q{"can go on (2 or 3)<br/>and not a Jeep?"}
  Q -- yes --> F["0x418390: fade out<br/>about 14 ticks"]
  Q -- no --> SK["the skull, phases 2-4<br/>(document 88)"]
  SK --> R{"FUN_0040b260"}
  R -- 0 --> E["match ends, winner -1<br/>(loss, or draw with two)"]
  R -- 1 --> OUT["phases 6-8: out,<br/>frozen until the match ends"]
  R -- "2 or 3" --> P5["phase 5:<br/>the skull fades"]
  F --> CH(["FUN_00418290: the vehicle choice"])
  P5 --> CH
Loading

Step 3: the Drone's spawn refusal (#108)

FUN_0040aa90 (DecompileMany.java 0x0040aa90) picks the point on the chosen edge of the camping vehicle's rectangle, then:

for (p = 0; p < 2; p++) {
  v = FUN_0040b3c0(p);                         // player p's current vehicle, if it still exists
  if (v != camper && v != 0) {
    half = vehicle(v) ? record(v)->+0x27c, +0x280 (x 16) : 512, 512;
    if (inside(point, v->pos, half)) return 0; // refused: no Drone this time
  }
}
return 1;

Translation: the point is refused if it lies inside the other player's own rectangle, the box a Drone would be spawned on for that player (their type's extent x 16 each way). So a Drone never appears inside the second player's surroundings. With one player there is nobody to refuse it.

Applied in the port

MatchController (engine):

  • After a death: death_outcome(ps) is FUN_0040b260. Flag carriers are counted from the definitions' flags.carries_flag (the Jeep).
    • 3 or 2: the choice.
    • 0: the match ends with no winner, a loss alone and a draw with two (_end_without_winner).
    • 1: the player is out. Phases 6 (0x418a50, 50 ticks) and 7 (0x418af0, 50 ticks) lead to phase 8 (0x418c70), which lasts until the match ends. The view stays black and the skull shows its closed mouth (mouth index 0x3bffff, then 0: frame 1 both times).
  • The skull skip: a drowning, or a death with the fuel below 1, sets the slot's drowned (the path through FUN_0040b5c0). When the wreck's wait ends, a non-carrier on that path, while the player can go on, takes phase 9 (0x418390): the view fades out and the choice opens.
  • The dead vehicle's type is the slot's dead_type.
  • Turrets wake for both players' vehicles (_turret_viewers).
  • The submarine watches both players' vehicles.
  • Drones: a Drone counts as drawn if it is in any player's view, and _drone_point_refused is Step 3.
func death_outcome(ps: PlayerSlot) -> int:
	if _carriers(ps) > 0:
		return 3
	if players < 2:
		return 0
	...
	if other == null or _carriers(other) == 0:
		return 0
	for c in ps.stock:
		if c != 0:
			return 2
	return 1

DeathSkullView draws the icon row under the skull (issue #117, document 135):

  • one icon of the dead type per vehicle of it the level started with (at most 8, rows of 4, centred), the spent ones crossed;
  • it fades in with the mouth, and in the out phase it is shown at once.

In the out phases it draws the crossed 2 x 2 grid. Both come from the pack's ui/death_skull.json (icon_row, out_grid, cross), written by both importers from tables 0x449308 and 0x449378.

The ears (SoundManager, SoundMixer.two_ear_gains): with two players the left ear is player 0's view and the right player 1's, each with its own weight (the view's fade) and height (document 117).

The music (MusicManager) gives the director the player count, how many players are on the choice (Bunker waits for both) and player 2's game view (the sting's end), and both players' vehicles ask for their lines.

The hangar's panel shows the MSV's mine reserve with two players (document 78).

The end of the match (GameFlow): a two-player win is recorded in the Hall of Fame's Tournament table; a draw is recorded as one and returns to the list (no ribbon).

The synthetic fixture's second vehicle now declares carries_flag. Before, the engine had assumed type 1 carries the flag.

Checks: tests/two_player_rules_check.gd (23: the four answers, a one-player loss, the dead type, the out phases to the frozen end while the other plays on, the draw, the skull skipped after a drowning and after running out of fuel and kept after any other wreck, turrets, the Drone refusal with two players and with one, the submarine's watch, both ears and their weights, the music's count). A death screenshot on RFMAP001 shows three Tank icons under the skull, the first crossed.

Not traced

Nothing left from #119 or this step: the two points an earlier draft left open (which wrecks skip the skull, and the skull's frame while a player is out) are answered above.

Next: back to the issues list.

Clone this wiki locally