Falsebound Archive
5 Bugs & quirks 5.12

A battle inside a wall freezes the game

When two units meet on the map, a battle starts, and its arena is the terrain under the meeting point. If both units are walking, that point is halfway between them. A meeting across a wall can therefore put it inside the wall, and wall cells carry the terrain id 99 (0x63). There is no arena 99: the arena lookup returns an empty pointer, the battle’s set-up reads through it, and the game stops.

Where
main.dol, unit contact map_unit_check_contact; arena lookup arena_def_get; arena set-up battle_build_arena
Arena given
99 (0x63), the terrain id of wall cells
Effect
The battle set-up reads through an empty pointer
Reachable in the retail game
No; no enemy unit on the walled maps ever walks
Tested in Dolphin
Stops 30 frames into the battle (attract demo patched to arena 99)

Units can meet across a wall at all because the contact test uses the units’ circles only, while walls stop only a unit’s centre. Only two maps have walls: map 016 (missions Y21 and S20) and map 017 (S21). (Map 025, which no mission uses, holds other ids that have no arena either.) On map 016 the corridors are 96 units wide and the thinnest walls three cells thick, and a unit’s circle can have a radius of up to 110, so a unit in one corridor can touch a unit in the next.

The freeze still needs both units walking with the wall between them, and on these maps an enemy unit never walks:

  • Every enemy unit starts inside a base. In S21, the units the script brings in later are put into a base too.
  • Each enemy’s orders, given at the start and again later in all three scripts, are the simplest kind: go to one base, and that base is the one it is already in. An enemy with these orders leaves its base only when the base it is sent to is a different one.
  • A beaten enemy unit normally comes back after a while in the enemy’s headquarters and sets off from there. None of the three missions gives the enemy a headquarters, so beaten units stay gone.

If a player unit runs into an enemy that is not walking, the battle takes place where the enemy stands, and that is never inside a wall. So the retail game cannot bring the freeze about. A changed mission with walking enemies on a walled map would.

Evidence

The contact code (map_unit_check_contact) takes the midpoint of two walking units and uses the terrain id under it as the arena. The arena lookup (arena_def_get) knows only arenas 0 to 19 and returns an empty pointer for anything else, which the arena set-up (battle_build_arena) reads through without a check. The walls and corridor widths were measured from the disc’s terrain grids of all 26 maps. The enemy placements, orders and bases were read from the three missions’ scripts: every unit placement and every unit the script places later is put into a base; every order command (16 in Y21 and S20, 8 in S21) is of the “go to base” kind, naming the base the unit was placed in; and no base record is an enemy headquarters. The enemy movement code (map_enemy_ai) gives a unit in a base with such an order no reason to leave, and the return of beaten units needs an enemy headquarters.

In the Dolphin emulator, the attract demo on the title screen was patched to pick arena 99 for its battle. The game stopped 30 frames into the battle and showed a black screen for the rest of a 160-second run; without the patch the demo ran on normally.