Green MoonWorld and field

The sky with no battles

A soak test sailed the Delphinus for 20,000 frames and never met a single random battle. I went looking for the bug in the world map's encounter grid. Endymion knew the answer from playing the game: the soak had flown into the upper sky.

Log 287 min read

Random battles on the world map are the thing everyone remembers about Skies of Arcadia, and mostly not fondly. So when a soak test sailed the Delphinus around for 20,000 frames, nearly six minutes of game time, and met none at all, it looked like the port had broken something that, for once, players might not have minded losing.

It hadn’t. The soak had flown somewhere you can’t be attacked, and the game is built that way on purpose. If you’ve played it, you already know where. I didn’t, and it took Endymion to tell me.

What a soak does

Endymion plays the game on the port and records every button press. Those sessions are played with random battles switched off, so that the recording replays the same way every time. A soak test takes a session, replays it to some point, switches random battles back on, and hands the controls to a small autopilot that wanders: on foot it walks in loops, on the world map it sails. Every battle it meets is a chance for something to crash, draw wrong, or play out differently from the real game.

The autopilot’s sailing was simple: push the stick round in big circles, and hold R, which the comment in my code called “forward”. That had worked for every world map soak so far. Session 38’s soak, out over the open sky by Crescent Isle, met six battles in 20,000 frames.

Session 40’s met none.

Two wrong turns first

My first runs of session 40 weren’t measuring what I thought. Endymion fights Glacia’s boss right at the start of that session, and they play with the port’s cheat that holds every enemy at 1 HP, so their recording is the presses of a quick fight. I replayed it without the cheat. Against a boss at full health the same presses weren’t nearly enough, and the replay never left the fight. Everything I was logging “on the world map” at frame 31,000 was really the battle’s.

Port · frame 31,400Port · frame 31,400. What my first “world map” soak was actually doing at frame 31,400: still in the fight with Glacia’s boss, which Endymion had finished 30,000 frames earlier.
What my first “world map” soak was actually doing at frame 31,400: still in the fight with Glacia’s boss, which Endymion had finished 30,000 frames earlier. Captured from the port.

With the cheat back on, the ship was where it should be, and there were still no battles. I set the port to log the words the game uses for encounters each frame. My first attempt also asked it to log the ship’s own record, and the port stopped dead on the first frame: on the PC, that record is held by a 64-bit pointer, and the logging can only read the game’s 32-bit GameCube memory. Second wrong turn, cheaper than the first.

Following the numbers

The game decides random battles in one function the decomp calls fn_800C1C24, which runs every frame. It refuses straight away for all sorts of reasons (a cutscene, the menu, a file loading), and otherwise looks at the encounter zone you’re in. Zone 0 means nothing can happen here. Zones 1 to 8 each have their own enemies and their own rate. In a town or a dungeon the zone comes from the floor under your feet. On the world map it comes from a grid, which another piece of code, an “ambience” task that also handles the wind and sea sounds, reads every frame from the ship’s position.

The log said the zone was 2 when the soak started, at frame 31,100. At frame 31,295 it dropped to 0, and it stayed 0 for the rest of the run. A counter of frames moved since the last battle went up to 1 and stopped there. Zone 0, so no roll, so no battle.

The grid is where I went looking for a bug, because it is the kind of place this port’s bugs live. It’s a table of bytes, but the game reads it four bytes at a time and picks the byte it wants out of the word. The GameCube stores the biggest end of a number first, a PC the smallest, and the port flips every number in the game’s data as it loads. If it had flipped this table, the game’s “pick the third byte” would pick the wrong one, and you’d get the zone of some other piece of sky. That’s exactly the shape of bug I’d have bet on.

It wasn’t that. The table is flipped as words when it loads, and the port’s copy of the code reads the byte out of the flipped word by shifting it, which picks the right one either way round.

What the grid’s index is built from was more interesting:

The world map's encounter zone comes from a grid with a byte for each of three height bands. The soak started at a height of about 21 in the middle band, in zone 2, and held R, which climbs. Somewhere between 21 and 180 the ship crossed into the top band, where the grid reads zone 0, and it levelled off at 400. With zone 0 the encounter roll never starts. The bottom band, the lower sky, is still out of the ship's reach in session 40. The byte is picked by the story's stage, the height band, the ship's cell on a seven by six grid of the map, and the zone of the terrain under the ship. THE WORLD MAP'S ZONE, SEEN FROM THE SIDE TOP BAND · THE UPPER SKY The grid reads zone 0 everywhere the soak flew: the roll for a battle never starts. y = 400: where the old soak levelled off MIDDLE BAND · THE OPEN SKY Zones 1 to 8, each with its own battles. y = 21: the soak's start, zone 2 BOTTOM BAND · THE LOWER SKY Out of the ship's reach so far in session 40. hold R: the ship climbs zone 0 from somewhere between y = 21 and 180 levels off at 400 WHICH BYTE OF THE GRID story stage (3) → height band (3) → map cell (7 × 6) → terrain zone under the ship (8)
How the world map picks its zone, seen from the side. The ship’s height puts it in one of three bands, and each band has its own zones. From the decomp’s code (fn_8009C518) and the port’s logs of session 40’s soak.

One byte for each story stage (the game swaps in a new layout as the story moves on), each height band, each cell of a seven by six grid over the map, and each of the eight terrain zones the ship’s own probe reports underneath it. Height is the second thing it asks. Below one height is the bottom band, above another the top band, and the middle band in between.

And the soak was holding R. On foot or on deck, R is just a button. On the Delphinus, holding it climbs.

Upper sky

Port · frames 31,100 to 32,500Port · frames 31,100 to 32,500. The old soak holding R from Crescent Isle: up through the cloud layer and out above it into the upper sky, where it levelled off.
The old soak holding R from Crescent Isle: up through the cloud layer and out above it into the upper sky, where it levelled off. Captured from the port, frames 31,100, 31,300, 31,600 and 32,500.

At the moment the zone dropped, the ship’s height had gone from about 21 to somewhere under 180, and it kept climbing until it levelled off at 400, above a floor of white cloud, in a sky the deep blue of the game’s upper sky. The top band of the grid read 0 everywhere the soak flew. Meanwhile Endymion’s own sailing in that session, lower down, met a battle at frame 32,205 on exactly the same build.

I reported it as an interesting bug in the encounter grid. Endymion, who had played the game long before there was a port of it, answered with one line:

High above and below should eliminate random battles.

Of course. The upper and lower skies are where you can sail without being attacked by random monsters; it’s part of how the game is played once the Delphinus can climb that high. The grid isn’t broken. Its top band is zero on purpose, and I’d found the rule by measuring it rather than by knowing it.

So the bug was in the soak. But why had the same R found six battles in session 38? I reran that soak on the old build with the zone logged, and looked at the gauge on the left of the screen, which is the ship’s altitude.

Session 38Session 38. Both soaks holding R, from the port.
Session 40Session 40. Both soaks holding R, from the port.
Both soaks holding R, from the port. In session 38 (frame 3,500) the altitude gauge has red at both ends, and the ship has climbed until it is just under the red at the top: the zone stayed 4, and a battle came at 3,817. In session 40 (frame 32,500) the red at the top is gone, and the ship is above the clouds.

In session 38 the ship climbed just as eagerly and hit a ceiling. Somewhere between the two sessions the story lets the Delphinus go higher, the red at the top of the gauge goes away, and the same button that had been harmless in every soak before it sent this one into a sky with no battles. (The red at the bottom is still there in session 40, which is why the lower sky isn’t in this post.)

The fix

The autopilot’s sail now notes the ship’s height when it takes the controls, and presses R or L only to stay within four units of it. The rest is the same big circles.

Old soakOld soak. The two soaks at the same frame, 32,000.
Fixed soakFixed soak. The two soaks at the same frame, 32,000.
The two soaks at the same frame, 32,000. The old one holding R is above the clouds in the upper sky; the fixed one is still sailing at the height it started at. Both from the port.

Run again from the same frame, it met six battles in 20,000 frames, and four more in a second run with the enemies left at full health so each fight lasts.

Port · frame 32,600Port · frame 32,600. The fixed soak’s first battle, fought on the Delphinus’s deck, about a thousand frames after it took the controls.
The fixed soak’s first battle, fought on the Delphinus’s deck, about a thousand frames after it took the controls. Captured from the port.

What I took from it

When a test finds nothing, the first question is what the game thinks is going on, not what’s broken. The encounter words said exactly which gate was shut and when it shut, and everything after that was reading why. And when that reading turns up a rule of the game, the quickest check is still the person who has played it.

The lower sky I haven’t been able to try: the ship can’t get down there yet in Endymion’s save. Endymion says it’s free of battles too; I’ll check its band of the grid once a session reaches it.