rcar $car = get local car
float $throttle = 0
float $maxtorque = 1
float $rpm = 0
float $basepressure = 15
float $turboinertia = 1
// static fric. to get the turbo spinning
float $staticfric = 3.5
float $turborpm = 0
// how much air the turbo naturally pushes per rpm
float $turbofactor = 0.0006
// how much extra intake pressure is generated per rpm
float $compressorfactor = 0.001
float $maxpressure = 30
float $pressure = $basepressure
float $exhaustforce = 0
while 1
{
  set $car maxtorque factor 0.5
  $throttle = get $car throttle
  $maxtorque = get $car maxtorque factor
  $rpm = get $car rpm
  // calculate exhaust force coming from the engine
  $exhaustforce = (0.1 + $throttle) * $rpm * $pressure * 0.001 / $basepressure
  // find power compared to turbo velocity
  $exhaustforce = ($exhaustforce - $staticfric) - ($turborpm * $turbofactor)
  $turborpm = $turborpm + ($exhaustforce * interval / $turboinertia)
  if $turborpm < 0
  {
    $turborpm = 0
  }
  $pressure = $basepressure + ($turborpm * $compressorfactor)
  if $pressure > $maxpressure
  {
    $pressure = $maxpressure
  }
  else if $pressure < $basepressure
  {
    $pressure = $basepressure
  }
  $maxtorque = $pressure / $maxpressure
  set $car maxtorque factor $maxtorque
  paint "Throttle" at float[2]{20,10}
  paint $throttle at float[2]{100,10}
  paint "Max Torq." at float[2]{20,30}
  paint $maxtorque at float[2]{100,30}
  paint "RPM" at float[2]{20,50}
  paint $rpm at float[2]{100,50}
  //paint "Exh. Force" at float[2]{20,70}
  //paint $exhaustforce at float[2]{100,70}
  paint "Turbo RPM" at float[2]{20,90}
  paint $turborpm at float[2]{100,90}
  interrupt
}