BAI

From Mm2kiwi
Revision as of 16:13, 5 March 2006 by Fre-Ber (talk | contribs) (Created initial article, based on mm2c BAI thread.)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

Each city may have one BAI-file. This file defines paths for controlling ambients such as pedestrians and automated traffic.

Format description

Intersections

A BAI-file is built up in three sections. The first section defines intersections.

Roads

The next section defines all the routes between the intersections.

Culling

Lists the roads to compute ambients for depending on the given PSDL block id.

Structure

In a pseudo-C style structure, a BAI-file looks like this:

struct BAI
{
    char[4]         header = "CAI1";
    unsigned short  nIntersections;                 // Number of intersections
    unsigned short  nRoads;                         // Number of roads
    BAIRoad         roads[nRoads];                  // Roads
    BAIIntersection intersections[nIntersections];  // Intersections
    BAICulling      culling;                        // AI culling ("bubbles")
}; 
struct BAIRoad
{
    unsigned short id;
    unsigned short nSections;          // Number of vertex sets
    unsigned short unknown0;           // No idea
    unsigned short nBlocks;            // Number of block references
    unsigned short blocks[nBlocks];    // References to the PSDL
    float          unknown1;           // Not sure. Speed threshold?
    float          unknown2;           // Always == 15

    BAIRoadData    right;              // Data for right side
    BAIRoadData    left;               // Data for left side

    float  centralDistance[nSections]; // Distances for central spline
    Vertex centralLine[nSections];     // Center spline for the entire road
    Vertex xOrientation[nSections];    // Orientation for pedestrians(?)
    Vertex yOrientation[nSections];
    Vertex zOrientation[nSections];
    Vertex wOrientation[nSections];

    BAIRoadEnd     end;                // End of the road
    BAIRoadEnd     start;              // Start of the road
};
struct BAIIntersection
{
    unsigned short id;
    unsigned short block;         // Reference to the PSDL, (index + 1)
    Vertex         center;        // Center point of intersection
    unsigned short nRoads;        // Number of connected roads
    unsigned long  roads[nRoads]; // References to roads
};
struct BAICulling
{
    unsigned long    nBlocks;     // Number of PSDL blocks + 1
    unsigned short **cull;        // Pointers to roads
};
struct BAIRoadData
{
    unsigned short nLanes;        // Number of lanes
    unsigned short nTrams;        // Number of tram rails (bool?)
    unsigned short nTrains;       // Number of train rails (bool?)
    unsigned short unknown3;      // Sidewalk? Always == 1 (bool?)
    unsigned short unknown4;      // Road type? 0, 1, 2 or 3

    float  lanesDistances[nLanes][nSections]; // Distances for right lanes
    float  distance[nSections];               // Outer edge distance
    float  Unknown[11 + nLanes];              // Something about the lanes, gladly padded with 0xcdcdcdcd
    Vertex lLanesVertices[nLanes][nSections]; // Vertices for driving lane splines
    Vertex sidewalkCenter[nSections];         // Vertices for sidewalk central spline
    Vertex tramVertices[nTrams][nSections];   // Vertices for tram rail splines
    Vertex trainVertices[nTrains][nSections]; // Vertices for train rail splines
    Vertex sidewalkInner[nSections];          // Vertices for sidewalk inner spline
    Vertex sidewalkOuter[nSections];          // Vertices for sidewalk outer spline
};
struct BAIRoadEnd
{
    unsigned long  intersectionID; // Reference to Intersection[].id
    unsigned short unknown0;       // Always 0xcdcd
    unsigned long  unknown1;       // trafficLightOn? 0, 1 and 3 observed...
    unsigned long  unknown2;       // trafficLightType? 0, 1, 2, 3 or 0xcdcdcdcd
    Vertex trafficLightOrigin;     // Origin of traffic light
    Vertex trafficLightAxis;       // Orientation of traffic light
};
struct Vertex
{
    float x;
    float y;
    float z;
}