Monday, June 14, 2010

Attract Mode Logic

The crash code is now complete, and it was more complex than I'd anticipated.

On the other hand, the logic to automatically control the player's car during Attract Mode is a lot simpler. The code can be quite basic, because the traffic in OutRun intelligently attempts to move out of your way. A simple detail most home conversions didn't pick up upon.

Here's a simplified pseudo-code conversion if you're interested:

AttractModeAI()
{
  // Check upcoming road segment for straight/curve.
  // Choose route from pre defined table at road split.
  AICheckRoad(); 
 
  // Set steering value based on upcoming road segment                  
  AISetSteering();  
  
  // If speed is below a certain amount, just accelerate
  if (car_speed < 0xFA)
  {
    accelerator = MAX_VALUE;
    return;
  }
  
  // If AI Traffic is close, set brake on
  if (traffic_close)
  {
    traffic_close = false;
    brake = 0xC0;
  }
  
  // If either wheel of the car is off-road
  else if (wheels_offroad)
  {
    brake = 0xC0;
  }
  
  // Upcoming road: Straight Road
  if (road_type == STRAIGHT)
  {
    curve_counter = 0;
  }
  
  // Upcoming road: Curved Road
  else
  {
    if (++curve_counter == 1)
    {
      // Set road curve value based on hard coded road data. 
      // High value = Sharper Bend
      road_curve_value = value - 1;
    }
    // toggle brake on bends. 
    // The brake flickers on/off in OutRun attract mode
    else if (road_curve_value != 0 && ((road_curve_value <= 0xA) 
            || (road_curve_value & 8)))
    {
      brake = 0xA0;
      road_curve_value--;
      return;
    }   
  }
  
  accelerator = MAX_VALUE;
  return;
}

Thursday, June 03, 2010

Collision

I'm currently working on disassembling the OutRun collision and crash handling code.

Once you start looking into the code in detail, you realise what an adventurous coding exercise OutRun is. I mean, how many ways do you need to crash in one game? Evidentally quite a lot... I can't quite fathom the level of detail they went into with regard to the collision routines. It's not sloppy coding as such, just simply attention to detail on an excessive scale. Sega  must have had a supply of strong caffeine in the 80s.

Check out the graph I produced in IDA below of one of the main crash routines. This isn't even all of the collision and crash code, it's simply one function which can be toggled by the master jump table!


On a positive note, all the code blocks covered by the above graph are now decompiled and commented. On a negative note, mainly for my sanity, there are still more. Argh!

There are two main types of crash in OutRun: hitting traffic and hitting scenery. Hitting scenery can be broken down into three new types of crash depending on the speed your travelling at. There's the low speed bump, where the car rises in the air (using the same movement lookup table as the birds flying on the logo in attract mode fact fans), the medium speed spin and the full speed flip. Each of these has multiple internal states to contend with and each crash factors in aspects like your speed, road curvature, height, whether there's a further crash resulting from the first crash and a selection of passenger animations. For example just the lower speed crashes offer a choice of the woman hitting the man, the man scratching head & girl tapping car, the man scratching head & girl pointing or man looking subdued and girl pointing.

Also, whilst the object format of the crash routines bears some similarity to previous bits of code I decompiled, actually most of it is new. Plus the animation sequencing format seems to be different, though I figured that out too.

PS I'm going to bed!