The online racing simulator
Replay Analyser File Version 2
==============================

RAF format for LFS S2


NOTE 1 : (about reading the file)
========

Please take note of and use the following variable fields :

(A) header size         (first data block's offset within file)
(B) block size          (size of one data block)
(C) wheel block size    (size of a dynamic wheel block)
(D) wheel block offset  (offset of wheel block within data block)

The above numbers may be increased with no change to the RAF version.


NOTE 2 : (about centre of gravity and reference positions)
========

In S1 time, position of car was the position of the CoG, so
wheel positions were given relative to the CoG.

In earlier versions of S2, CoG changed with fuel usage,
so the wheel positions were given relative to the CoG with no fuel.

Since S2 Alpha 0.5V the car's position is given as the position of
a fixed, central reference point at approximately the lowest point of
the car's body.  Wheel positions are given relative to this point.

More static info can be extracted from the CAR_info.bin files,
which can be exported from the Garage by pressing the letter O.


NOTE 3 :
========
Added for version 0.5X : short track name (at offset 24)


NOTE 4 :
========
Added for version 0.5Z : approximate G values in data blocks
Added for version 0.5Z : update interval and slip fraction


FILE DESCRIPTION :
==================

num   unit    offset  description
---   ----    ------  -----------

HEADER BLOCK : 1024 bytes (A)

6     char    0       LFSRAF              : do not read file if no match
1     byte    6       game version        : ignore
1     byte    7       game revision       : ignore
1     byte    8       RAF version (2)     : do not read if increased
1     byte    9       update interval     : ms (normally 10 / hlvc 100)
2     byte    10      0                   :
1     word    12      header size         : data blocks start    (A)
1     word    14      block size          : size of a data block (B)
1     word    16      wheel block size    : inside data block    (C)
1     word    18      wheel block offset  : within data block    (D)
1     int     20      number of blocks    : total number of data blocks
4     char    24      short track name    : e.g. BL2R
1     float   28      track ruler length  : total index distance
32    char    32      player              : text
32    char    64      car                 : text
32    char    96      track               : text
16    char    128     config              : text
16    char    144     weather             : text
8     char    160     LFS version         : text
1     byte    168     player flags        : driver aids etc (see NOTES)
1     byte    169     number of wheels    : usually 4
1     byte    170     HLVC legal          : 0=UNKNOWN 1=LEGAL 2=ILLEGAL
1     byte    171     number of splits    : including lap time
1     int     172     split 1             : ms
1     int     176     split 2             : ms
1     int     180     split 3             : ms
1     int     184     split 4             : ms
1     float   188     mass                : kg including driver
1     float   192     sprung mass         : kg including driver
1     float   196     R antiroll          : N/m
1     float   200     F antiroll          : N/m
1     float   204     final drive         : final drive ratio
1     byte    208     number of gears     : forward gears
3     byte    209     0                   :
7     float   212     gear ratios         : forward gear ratios
272   byte    240     0                   :
4     wheel   512     STATIC WHEEL INFO   : (see below)

STATIC WHEEL INFO : size 128 bytes per wheel

1     float   0       X                   : relative to reference point
1     float   4       Y                   : relative to reference point
1     float   8       Z                   : relative to reference point
1     float   12      radius              : unloaded
1     float   16      width               : at widest point
1     float   20      maximum deflect     : suspension travel
4     byte    24      0                   :
1     byte    28      0                   :
1     byte    29      tyre type           : (see NOTES)
2     byte    30      0                   :
1     float   32      spring constant     : N/m
1     float   36      damping (C)         : Ns/m
1     float   40      damping (R)         : Ns/m
1     float   44      max brake torque    : Nm
80    byte    48      0                   :

DATA BLOCKS : 192 bytes (B) every 100th of a second

1     float   0       throttle            : 0 to 1
1     float   4       brake               : 0 to 1
1     float   8       input steer         : radians
1     float   12      clutch              : 0 to 1
1     float   16      handbrake           : 0 to 1
1     byte    20      gear                : 0=R, 1=N, 2=first gear
1     char    21      lateral G * 20      : -120 to 120 = -6 to 6 G
1     char    22      forward G * 20      : -120 to 120 = -6 to 6 G
1     char    23      upwards G * 20      : -120 to 120 = -6 to 6 G
1     float   24      speed               : m/s
1     float   28      car distance        : m - travelled by car
1     int     32      position X          : map X    (1m = 65536)
1     int     36      position Y          : map Y    (1m = 65536)
1     int     40      position Z          : altitude (1m = 65536)
1     float   44      engine speed        : radians/s
1     float   48      index distance      : m - track ruler measurement
1     short   52      RX                  : x of right-vector
1     short   54      RY                  : y of right-vector
1     short   56      RZ                  : z of right-vector
1     short   58      FX                  : x of forward-vector
1     short   60      FY                  : y of forward-vector
1     short   62      FZ                  : z of forward-vector
4     wheel   64 (D)  DYNAMIC WHEEL INFO  : (see below)

DYNAMIC WHEEL INFO : size 32 bytes (C) per wheel

1     float   0       suspension deflect  : compression from unloaded
1     float   4       steer               : including Ackermann and toe
1     float   12      X force             : force right
1     float   16      Y force             : force forward
1     float   8       vertical load       : perpendicular to surface
1     float   20      angular velocity    : radians/s
1     float   24      lean rel. to road   : radians a-c viewed from rear
1     byte    28      air temperature     : degrees C
1     byte    29      slip fraction       : (0 to 255 - see below)
1     byte    30      0                   :
1     byte    31      0                   :


NOTES :
=======

Axes
----
X - right
Y - forward
Z - up

To work out heading from the forward-vector
-------------------------------------------
float b = FX / 32767.0f;        // convert FX to a float from -1 to 1
float e = FY / 32767.0f;        // convert FY to a float from -1 to 1
float heading = atan2(-b, e);   // heading (anti-clockwise from above)

Player flags
------------
LEFT HAND DRIVE     1
GEAR CHANGE CUT     2
GEAR CHANGE BLIP    4
AUTO SHIFT          8
SHIFTER             16
RESERVED            32
BRAKING HELP        64
AXIS CLUTCH         128

Tyre types
----------
RACE R1             0
RACE R2             1
RACE R3             2
RACE R4             3
ROAD SUPER          4
ROAD NORMAL         5
HYBRID              6
KNOBBLY             7

Slip fraction
-------------
This is the dynamic value of the current combined slip ratio relative
to the combined slip ratio that would provide the greatest force.

0 to 254 - slip ratio increasing up to maximum force available
255 - slip ratio exceeds the maximum force slip ratio
FGED GREDG RDFGDR GSFDG