rcar $car = get local car

shared int $cccon=0
shared int $cclon=0
shared int $speed=0

float $factor=1.0
float $rate=0.001
float $throttle=0.0
float $carthrottle=0.0
float $carbrake=0.0

int $current=0
int $test=0

while 1
{
  $current = get $car tachovelocity
  $carthrottle = get $car throttle
  $carbrake = get $car brake
  
  if $carthrottle > 0.9
  { $cccon = 0 }
  if $carbrake > 0
  { $cccon = 0 }

  if $cccon > 0
  {
    if $current > $speed
     { $factor -= $rate }
    if $current < $speed
     { $factor += $rate }
    set $car throttle ($throttle * $factor)
  }

  if $cclon > 0
  {
    if $current > $speed
     { $factor -= $rate }
    if $current < $speed
    { 
      if $factor < 1.0
        { $factor += $rate } 
    }
    set $car throttle ($carthrottle * $factor)
  }

  $test = $cccon + $cclon
  if $test == 0
   { 
     $throttle = 0.5
     $factor = 1.0
   }

  interrupt
}