//Focus on the car used by the script owner
rcar $car=get scriptowner car
float $rpm
float $throttle
float $upthrottle = 0
float $unthrottle = 0
float $clutch
float $diff
float $finalthrottle
int $gear
float $idle = 1000
float $speed
float $temp = 20.0
while 1
{
	$rpm = get $car rpm
	$throttle = get $car throttle
	$clutch = get $car clutch
	$diff=($idle/0.50*$rpm)
	$gear = get $car gear
	$speed = get $car tachovelocity
	$speed = $speed*3.60
	$temp+=0.016*($rpm/66000)
	if $temp > 89
	{
		$temp = 89
	}
	if $temp > 10 and $temp < 30
	{
		$idle=813+((3.10*(30-$temp)))
		if $idle < 813
		{
			$idle = 813
		}
	}
	if $temp > 30 and $temp < 40
	{
		$idle=775+((3.80*(40-$temp)))
		if $idle < 775
		{
			$idle = 775
		}
	}
	if $temp > 40 and $temp < 50
	{
		$idle=738+((3.70*(50-$temp)))
		if $idle < 738
		{
			$idle = 738
		}
	}
	if $temp > 50 and $temp < 60
	{
		$idle=700+(3.80*(60-$temp))
		if $idle < 700
		{
			$idle = 700
		}
	}
	if $temp > 60 and $temp < 70
	{
		$idle=650+(5.0*(70-$temp))
		if $idle < 650
		{
			$idle = 650
		}
	}
	if $temp > 70 and $temp < 90
	{
		$idle=650
	}
	if $gear == 0
	{
		if $rpm > 650
		{
			if $rpm < $idle
			{
				$upthrottle+=0.0001*($idle*2/$rpm)
			}
			else
			{
				$upthrottle-=0.0001*($idle*2/$rpm)
			}
		}
		if $rpm < 649
		{
			$upthrottle+=0.01
		}
		if $rpm > 1000
		{
			$upthrottle-=0.01
		}
	}
	if $clutch !=0 and abs($speed) < 10 and $gear !=0
	{
		if $rpm < ($idle*1.125)
		{
			$upthrottle+=0.0001*($idle*2/$rpm)
		}
		if $rpm > ($idle*1.125)
		{
			$upthrottle-=0.01
		}
	}
	if $upthrottle > 1
	{
		$upthrottle = 1
	}
	if $rpm > $idle*1.01
	{
		$upthrottle-=0.01
	}
	if $upthrottle < 0
	{
		$upthrottle = 0
	}
	if $unthrottle < -1
	{
		$unthrottle = -1
	}
	if $unthrottle > 0
	{
		$unthrottle = 0
	}
	$finalthrottle = $throttle + $upthrottle + $unthrottle
	if $finalthrottle > 1
	{
		$finalthrottle = 1
	}
	if $finalthrottle < 0
	{
		$finalthrottle = 0
	}
	set $car throttle $finalthrottle
	//paint $temp at float[2]{70,130}
	interrupt
}