Skip to Content
The Alchemy Project

Battle & Effects

The battle engine runs every fight in Golden Sun: The Lost Age through one turn-and-action pipeline decoupled from its 2D and 3D visual effects.

Random encounters on land and sea, Mimics, story bosses, superbosses such as Dullahan, and Battle Arena matches all run through btRun in battle/. The sequel scales The Broken Seal's combat engine up to an eight-member roster, 660 enemy formations, multi-action enemies, and a software 3D polygon rasteriser in battle_effect/ that renders textured models directly in IWRAM.

This page follows a fight from formation spawning and reserve switching through two-phase enemy AI, the action pipeline, the hand-off between 2D and 3D spell animations and hit playback, and zoomed battlefield backdrops.

Entering a battle, formations, and 8-member Switch

A battle opens in the Kandorean Temple: watch the camera swing in as a Punch Ant, Giant Bat, and Wild Wolf are announced and the Fight menu opens
A battle opens in the Kandorean Temple: watch the camera swing in as a Punch Ant, Giant Bat, and Wild Wolf…

Random encounters, Mimics, and story scripts all trigger battle in the same way. They write a formation ID (Formations, 660 rows) into MainRoutineStateWork, snapshot field actors into SnapshotObjects, request ENGINE_BATTLE, and return to gmMainRoutineRun.

Formations spawn up to 6 screen slots (large enemies take two slots) into the same 332-byte UNIT struct as party members. Up to 4 heroes fight in the front row while up to 4 wait in reserve. The Switch command swaps front and back members mid-turn, and if the entire front row falls, living reserves take their place automatically and the fight continues.

Turn loop, two-phase & multi-action AI, and the action pipeline

One turn against a Wild Wolf, Punch Ant, and Giant Bat: watch Sheba and Felix fell the Giant Bat, Jenna defend, and the remaining enemies act in Agility order
One turn against a Wild Wolf, Punch Ant, and Giant Bat: watch Sheba and Felix fell the Giant Bat, Jenna…

Each turn collects commands (with select bosses and monsters acting multiple times per turn), sorts by Agility and priority, and checks for victory or defeat after every action. As in The Broken Seal, enemies choose twice. An enemy's turn-start choice counts only if it decides to guard or flee. Otherwise, the AI chooses again at execution time, so that it never spends an attack on a target that has already fallen.

  1. Build (battle_action.c): btActionRunBuild decides final targets, dead-target redirection, spread decay, dodges, critical hits, and weapon unleashes in advance.
  2. Stage (battle_staging.c): btStagingDispatchAction animates camera motion, attacker movement, and cast glow, installs btPlaybackRun on the tick pass, and launches the foreground battle effect.
  3. Impact and resolution (battle_playback.c, battle_ability.c): At the impact tick, the battle effect signals btPlaybackStart(). btPlaybackRun resolves each target via btAbilityApplyToTarget (applying HP and status math immediately and queueing reactions via btPlaybackPush) and drains flinches, damage numbers, and combat log entries while the effect finishes.

Decoupled battle effects, the playback queue, and 3D models

Felix casts Quake Sphere at Jenna, Sheba, and Piers. Watch the targets flinch while the rock pillars are still shaking the screen.
Felix casts Quake Sphere at Jenna, Sheba, and Piers
  • 2D brightness canvas and 3D IWRAM rasteriser (battle_effect/): Every battle effect is foreground blocking C that paints onto a 128×128 6-bit brightness canvas with palette ramps, VBlank trail decay, blitters, and particle motes. In TLA, effects can also draw software-rasterised 3D polygon models (btRenderDrawModelList in IWRAM), a capability absent from TBS, with perspective projection, textured and shaded faces, and depth sorting. That renderer draws summons such as Zagan, Coatlicue, Catastrophe, Charon, and Iris.
  • Concurrent playback queue (battle_playback.c): At the impact frame, the battle effect calls btPlaybackStart(). The call releases a tick-pass event that resolves targets and drains hit shakes, HP drops, damage lines, and enemy dissolves concurrently while the spell animation finishes.
A random battle in the Kandorean Temple ends: watch the final enemy dissolve, experience and coins tally up, and the cave return where the party stood
A random battle in the Kandorean Temple ends: watch the final enemy dissolve, experience and coins tally up…
  • Zoomed two-half backgrounds: 82 battle backdrops scale smoothly on the GBA's single affine background layer via HBlank DMA as the camera orbits.
  • Spoils and link battles: Victory gives 100% XP to surviving front-row fighters and 50% to conscious reserves, alongside coins and drops. Link-cable Battle Arena matches keep both consoles in lockstep by synchronising deterministic gmBattleRandom turns per action.

Code references