UNIT PILUNIT;

interface
Uses CRT,ROAD,GRAPHICS,GENERAL,PERSPECT,SOUND,JOYS,KEYB,netunit;
Procedure PlaceCar  (PType: byte; Num:byte;iSec: PuntSec;iX,iZ,iY: extended; iAngle,iSpeed: Integer);
Procedure PlaceSpc  (Sec: PuntSec; Number:Byte);
Procedure PilotCar  (Num:byte; Xtrottle,YTrottle,CGear: shortint);
Procedure PilotSPC  (Num:byte);
Procedure ControlSPC(Num:byte);
Procedure ControlCar(NCar,Num:byte);

implementation
Procedure PlaceCar(Ptype: Byte; Num:byte;iSec: PuntSec;iX,iZ,iY: extended; iAngle,iSpeed: Integer);
var AuxSec: PuntSec;
begin

With car[Num] do begin
Dash          :=true;
Infos         :=true;
PilotType     :=Ptype;
X             :=iX;
Z             :=iZ;
Y             :=iY;
Angle1        :=iAngle;
Angle2        :=iAngle;
Velang        :=0;
Deangle       :=0;
Sterzo        :=0;
GAngle        :=0;
Grise         :=0;
Xrot          :=0;
Zrot          :=0;
Speed         :=iSpeed;
SpeedTim      :=0;
Sec           :=iSec;
intX          :=trunc(X);
intZ          :=trunc(Z);
intY          :=trunc(Y);
Sgom          :=0;
SgomTim       :=0;
CurrRise      :=0;
CurrDist      :=140;
Trab          :=False;
TrabVal       :=0;
ExGear        :=0;
Gear          :=0;
CPUx          :=IntX;
CpuEfX        :=IntX;
Wval          :=0;
EN1           :=0;
EN2           :=0;
Sosp          :=0;
Revs1         :=0;
Revs2         :=0;
Reverse       :=False;
Ahead         :=False;
Jump          :=False;
Fin           :=False;
FinPos        :=8;
DisPerc       :=0;
Wcnt          :=0;
Wval          :=0;
end;

Xtrottle[num]:=0;
Ytrottle[num]:=0;
Cgear   [num]:=0;
Touch   [num]:=false;

AuxSec:=Car[Num].Sec^.Next^.Next^.Next^.Next^.Next^.Next;
if (Num shr 1)shl 1=Num then Car[Num].CpuX:=AuxSec^.Maxroad-80
                        else Car[Num].CpuX:=AuxSec^.Minroad+80;
Car[Num].CpuEfx:=Car[num].CpuX;

if GAMEMODE<>2 then Han[Num]:=(4-Num shr 1)-(RDifficulty)*3+85 else begin
 if Car[num].team=2 then Han[Num]:=        -(RDifficulty)*3+55 else
                         Han[Num]:=        -(RDifficulty)*3+50;
end;

if Han[num]<0  then Han[Num]:=0;
if Han[num]>70 then Han[Num]:=70;

if Not AllCars then Han[Num]:=0;

Lap[Num]:=0;

SetTime(LapTime[Num],0,0,0,0);
SetTime(BestTime[Num],0,9,59,99);
StartTime[Num]:=0;
LapTimeS[Num]:=TimeToStr(LapTime[Num]);
BestTimeS[Num]:=TimeToStr(BestTime[Num]);

if (Car[Num].Sec^.special=1) then begin Copybob(97+word(Num)*50,61+word(Num)*50); Car[Num].Glass:=1 end else
                                  begin Copybob(96+word(Num)*50,61+word(Num)*50); Car[Num].Glass:=2 end;

if Num=1 then Car[Num].Id:=1   else
if Num=2 then Car[Num].Id:=2   else
if Num=3 then Car[Num].Id:=4   else
if Num=4 then Car[Num].Id:=8   else
if Num=5 then Car[Num].Id:=16  else
if Num=6 then Car[Num].Id:=32  else
if Num=7 then Car[Num].Id:=64  else
if Num=8 then Car[Num].Id:=128 ;

inc(Car[Num].Sec^.Numcar,Car[Num].Id);
end;

Procedure PlaceSpc(Sec: PuntSec; Number:Byte);
begin
SpecialObj[Number].X       :=SpecialObj[Number].SX;
SpecialObj[Number].Y       :=SpecialObj[Number].SY;
SpecialObj[Number].Z       :=SpecialObj[Number].SZ;
SpecialObj[Number].Angle   :=SpecialObj[Number].Sangle;
SpecialObj[Number].Speed   :=SpecialObj[Number].SSpeed;
SpecialObj[Number].Img     :=SpecialObj[Number].SImg;
SpecialObj[Number].Reverse :=SpecialObj[Number].Sreverse;
SpecialObj[Number].Sec     :=Sec;
SpecialObj[Number].SSec    :=Sec;
SpecialObj[Number].Id      :=1 shl (Number-21);
SpecialObj[Number].DisPerc :=0;
SpecialObj[Number].CurrDist:=140;
SpecialObj[Number].Number  :=0;
inc(Sec^.NumSpc,SpecialObj[Number].Id);
end;

Procedure PilotCar(Num:byte; Xtrottle,YTrottle,CGear: shortint);

var
NoCpuDrive      :boolean;
AuxX,AuxZ,PreSn,PreCs,
Alfa,CurSectDim :integer;
NoFren          :byte;
AuxAngle,Incr   :integer;
CurSect         :puntsec;
ExSpeed         :integer;
IncSpeed        :integer;
IncRevs         :integer;
IncVelan        :integer;


Procedure Acceleration;
var Help: integer;
begin
if (Car[Num].Speed<40) and (Car[Num].Speed>-40) then inc(Car[Num].Sosp,2*sgn(Car[Num].Gear));
if (Car[Num].Revs1<300+Car[Num].Gear*100) and (Car[Num].Gear>1) then
Help:=(300+Car[Num].Gear*100-Car[Num].Revs1) div 20 else Help:=0;

if Car[Num].Gear=0 then begin
                     IncRevs:=-60*Ytrottle div (20+Help)-Car[Num].Revs1 div 10;
end else
if Car[Num].Gear=-1then begin
                     IncRevs:=-26*Ytrottle div (20+Help)-Car[Num].Revs1 div 10;
end else
if Car[Num].Gear=1 then begin
                     IncRevs:=-26*Ytrottle div (20+Help)-Car[Num].Revs1 div 10;
end else
if Car[Num].Gear=2 then begin
                     IncRevs:=-12*Ytrottle div (20+Help)-Car[Num].Revs1 div 21;
end else
if Car[Num].Gear=3 then begin
                     IncRevs:=- 8*Ytrottle div (20+Help)-Car[Num].Revs1 div 30;
end else
if Car[Num].Gear=4 then begin
                     IncRevs:=- 4*Ytrottle div (20+Help)-Car[Num].Revs1 div 60;
end else
if Car[Num].Gear=5 then begin
                     IncRevs:=- 2*Ytrottle div (20+Help)-Car[Num].Revs1 div 120;
end;
if NoCpuDrive then IncRevs:=IncRevs*(Car[Num].Accel-Ord(Car[Num].Energy<=0)*10) div 100;
end;

begin
NoCpuDrive:=(Car[num].PilotType=1) or (Car[Num].PilotType=2) or (Car[Num].PilotType=3);
inc(Car[num].EnergyDec,sgn(Car[num].Energy-Car[num].EnergyDec));
CurSect :=Car[Num].Sec;
IncSpeed:=0;
IncVelan:=0;
IncRevs :=0;
Car[Num].Sgom:=0;
NoFren:=1;
ExSpeed:=Car[Num].speed;

Car[Num].DeAngle :=Car[Num].Angle1-Car[Num].Angle2;
if (Car[Num].Deangle>700) or (Car[Num].Deangle<-700) then Car[Num].Angle1:=Car[Num].Angle2+700*sgn(Car[Num].Deangle);
(************* SHIFTING *******************************************)

 if (Cgear<0) and (Car[Num].Gear>-1) then begin
  dec(Car[Num].Gear);
  AdjRevs(Num);
 end else
 if (Cgear>0) and ((Car[Num].Gear<Car[Num].Gears) or ((Car[Num].Gear<5) and Not NoCpuDrive) ) then begin
  inc(Car[Num].Gear);
  AdjRevs(Num);
 end;
Car[num].ExGear:=Car[num].Gear;
if Car[num].Jump then Car[Num].Gear:=0;

(************* TURNING ********************************************)

Car[Num].Sterzo:=-Xtrottle div 4;

if Car[Num].Fin then YTrottle:=40;

(************* SPEED UP *******************************************)
if Car[num].Gear<>0 then if (Car[Num].Revs1>1300)
or (sgn(Car[Num].Speed)=-sgn(Car[num].Gear)) then Ytrottle:=100;

if (Ytrottle<0) and (Car[Num].Revs1<1350) then Acceleration else

(************* BRAKING ********************************************)

if (Ytrottle>0) and (Car[Num].Speed<>0) then begin
 dec(Car[Num].Sosp,sgn(Car[Num].Speed)shl 1);
 NoFren:=0;
 if(Ytrottle> 50) and (abs(Car[Num].Speed)>40) then begin
  dec(IncSpeed,(sgn(Car[Num].Speed)*(150-Ytrottle) div 20));
  Car[Num].Sgom:=Ytrottle div 10+10;
 end else begin
  if abs(Car[Num].Speed)>-sgn(Car[Num].Speed)*Ytrottle div 30
  then dec(IncSpeed,sgn(Car[Num].Speed)*Ytrottle div 30) else Car[Num].Revs1:=0;
 end;
 inc(IncVelan,Car[Num].DeAngle div 30);
end;

if (Car[Num].Gear=0) or (Ytrottle=0) or (Car[Num].Speed=0) then begin
 if Car[Num].Gear<>0 then Dec(IncRevs,Car[Num].Revs1 div (100+abs(Car[Num].Gear)*20))
 else begin
       inc(Car[Num].Speedtim);
       if Car[Num].SpeedTim>3-abs(Car[Num].Speed) div 100 then
       begin
        Car[Num].SpeedTim:=0;
        dec(IncSpeed,sgn(Car[Num].Speed))
       end;
       dec(Car[Num].Revs1,Car[Num].Revs1 div 15);
      end;
end;

(******************************************************************)

if Car[Num].DeAngle> 80 then begin
inc(IncVelan,  (Car[Num].DeAngle-80) div 15);
Car[Num].Sgom:=(Car[Num].DeAngle-80) div 10+10;
end else
if Car[Num].DeAngle<-80 then begin
dec(IncVelan,  (-Car[Num].DeAngle-80) div 15);
Car[Num].Sgom:=(-Car[Num].DeAngle-80) div 10+10;
end;

if NoCpuDrive then begin
if Car[Num].Speed>50 then
inc(IncVelan,Ord(Car[Num].y<45)*(Car[Num].sterzo-Car[Num].Sterzo*(Car[num].Speed div 18-5) div 25)
             -(Car[Num].Velang+IncVelan) div 2) else
inc(IncVelan,Ord(Car[Num].y<45)*(Car[Num].sterzo*Car[Num].Speed div 50)
             -(Car[Num].Velang+IncVelan) div 2);
end else begin
if Car[Num].Speed>50 then
inc(IncVelan,-(Car[Num].Velang+IncVelan) div 2) else
inc(IncVelan,-(Car[Num].Velang+IncVelan) div 2);
end;

inc(Car[Num].Velang,IncVelan);

if NoCpuDrive then inc(IncSpeed,-abs(Car[Num].Velang) div (45-abs(Car[Num].Gear)*5)*NoFren)
              else inc(IncSpeed,-abs(Car[Num].Velang) div (55-abs(Car[Num].Gear)*3)*NoFren);

if Car[Num].Angle1>0 then PreSn:=sn[ Car[Num].Angle1 div 10] * 35 div 64
                     else PreSn:=sn[-Car[Num].Angle1 div 10] * 35 div 64;

if  Car[Num].x+PreSn>CurSect^.Maxspc then begin

    if Car[Num].Angle1>0 then PreCs:=Sn[ Car[Num].Angle1 div 10] div 32
                         else PreCs:=Sn[-Car[Num].Angle1 div 10] div 32;

   if NoCpuDrive then begin
    if not ((Gamemode=3) and (Myslot<>Num)) then begin
     if Car[Num].Speed*PreCs>100 then playsample(GetChFree,6,64,70,100) else
     if Car[Num].Speed*PreCs>50  then playsample(GetChFree,5,64,70,100);
    end;
    dec(IncSpeed,Car[Num].Speed*PreCs div 16)
   end else dec(IncSpeed,Car[Num].Speed*PreCs div (32+DDifficulty));

   Car[Num].x:=CurSect^.Maxspc-PreSn;
   end else


if  Car[Num].x-PreSn<CurSect^.Minspc then begin

    if Car[Num].Angle1>0 then PreCs:=Sn[ Car[Num].Angle1 div 10] div 32
                          else PreCs:=Sn[-Car[Num].Angle1 div 10] div 32;

    if NoCpuDrive then begin
     if not ((Gamemode=3) and (Myslot<>Num)) then begin
      if Car[Num].Speed*PreCs>100 then playsample(GetChFree,6,64,70,100) else
      if Car[Num].Speed*PreCs>50  then playsample(GetChFree,5,64,70,100);
     end;
     dec(IncSpeed,Car[Num].Speed*PreCs div 16)
    end else  dec(IncSpeed,Car[Num].Speed*PreCs div (32+DDifficulty));
    Car[Num].x:=CurSect^.Minspc+PreSn;
    end;

if((Car[Num].x+PreSn>CurSect^.Maxroad) or
   (Car[Num].x-PreSn<CurSect^.Minroad)) and (Car[Num].Speed<>0) then Car[Num].trab:=true else Car[Num].trab:=false;

if Car[Num].Trab then begin inc(Car[Num].trabval,2); if Car[num].Trabval>3 then dec(Car[num].Trabval,3);
  if NoCpuDrive then dec(IncSpeed,Car[Num].Speed div 40) else
     dec(IncSpeed,Car[Num].Speed div (60-TaddHan+DDifficulty));
  end;


if Car[Num].Gear<>0 then begin
if sgn(Car[Num].Gear)=sgn(Car[Num].Speed) then inc(IncRevs,IncSpeed * 25 div Car[Num].Gear)
                                          else dec(IncRevs,IncSpeed * 25 div Car[Num].Gear)
end;

if NoCpuDrive then begin
 if not ((IncRevs>0) and (Car[Num].Speed>Car[Num].MaxSpd)) then inc(Car[Num].Revs1,IncRevs);
end else begin
 if not ((IncRevs>0) and (Car[Num].Speed>200)) then inc(Car[Num].Revs1,IncRevs);
end;

if Car[Num].Revs1<0    then begin
Car[Num].Revs1:=0;
Car[Num].Revs2:=0;
end else
if Car[Num].Revs1>4000 then begin
Car[Num].Revs1:=4000;
Car[Num].Revs2:=4000;
end;
inc(Car[Num].Revs2,(Car[Num].Revs1-Car[Num].Revs2) div 3);

if (Car[Num].Gear<>0) then begin
if sgn(Car[Num].gear)=-sgn(Car[Num].Speed) then
Car[Num].Speed:=-Car[Num].Revs1*Car[Num].Gear div 25 else
Car[Num].Speed:= Car[Num].Revs1*Car[Num].Gear div 25
end else
inc(Car[Num].Speed,IncSpeed);

if abs(Exspeed-Car[Num].Speed)>3 then begin
Car[Num].Sgom:=Max(Car[Num].Sgom,abs(Exspeed-Car[Num].Speed)*3+10);
end;
dec(Car[Num].Sosp,sgn(car[Num].Sosp));
if Car[Num].sosp> 4 then Car[Num].Sosp:= 4 else
if Car[Num].sosp<-4 then Car[Num].Sosp:=-4;

Car[Num].Xrot:=  Car[Num].Sosp-Car[Num].EN2;
if NoCpuDrive then Car[Num].Zrot:=-longint(Car[Num].Velang)*Car[Num].Speed div 400-Car[Num].EN2 shl 1 else
                   Car[Num].Zrot:=-longint(Car[Num].Velang)*Car[Num].Speed div 150-Car[Num].EN2 shl 1;
if Car[Num].Zrot> 8 then Car[Num].Zrot:= 8 else
if Car[Num].Zrot<-8 then Car[Num].Zrot:=-8;

if (Car[Num].Speed < 2) and (Car[Num].Speed >-2) then Car[Num].Speed :=0;
if (Car[Num].Velang< 2) and (Car[Num].Velang>-2) then Car[Num].Velang:=0;

inc(Car[Num].Angle1,Car[Num].Velang);

if Car[Num].Angle1> 900 then begin
dec(Car[Num].Angle1,1800); Car[Num].Reverse:=not Car[Num].Reverse;
Car[Num].Angle2:=Car[Num].Angle1-Car[Num].DeAngle end else
if Car[Num].Angle1<-900 then begin
inc(Car[Num].Angle1,1800); Car[Num].Reverse:=not Car[Num].Reverse;
Car[Num].Angle2:=Car[Num].Angle1-Car[Num].DeAngle end;

inc(Car[Num].Angle2,(Car[Num].DeAngle div (abs(Car[Num].Speed div 15)+5)+
                     Sgn(Car[Num].Deangle)));

 auxAngle:=(Car[Num].Angle2 div 10) mod 360; if auxAngle<0 then inc(auxAngle,360);

dec(Car[Num].IntY,Car[Num].En1);
inc(Car[Num].En2,(Car[Num].En1-Car[Num].En2) div 3+sgn(Car[Num].En1-Car[Num].En2));

if Car[Num].intY<=41 then begin
 Car[Num].intY:=40;
 if (Car[Num].Sec^.Special=2) and (abs(Car[Num].Speed)>100) then begin
  Car[num].Gear:=0; Car[num].Jump:=true;
  Car[Num].En1:=Car[Num].Sec^.Rise div 10*(abs(Car[Num].Speed)) div 150
  end else begin
  Car[Num].En1:=-Car[Num].En1 shl 1 div 3;
  if Car[num].Jump and (Car[Num].En1=0) then begin
   Car[num].Jump:=false; Car[Num].Gear:=Car[num].ExGear; AdjRevs(Num);
  end;
  if NoCpuDrive and (Car[num].En1<-1) then Playsample(3,5,32,70,100);
 end
end else begin
inc(Car[Num].En1);
end;
Car[Num].Y:=trunc(Car[Num].IntY);
Car[Num].Gear:=Car[num].ExGear;

(******************************************************************************)
(************************** NORMAL RIDING *************************************)
(******************************************************************************)

if not Car[Num].Reverse then begin

Car[num].Gangle:=(Gangle(Car[num].Sec)+Car[num].Angle1 div 10) mod 360;
if Car[Num].GAngle<0 then inc(Car[Num].gAngle,360);

 Car[Num].x:=Car[Num].x+Car[Num].Speed*sn[auxAngle]/ConstSpeed;
 Car[Num].z:=Car[Num].z+Car[Num].Speed*cs[auxAngle]/ConstSpeed;

 Car[Num].intX:=trunc(Car[Num].x);
 Car[Num].intZ:=trunc(Car[Num].z);

if Car[Num].Speed>0 then begin
 if CurSect^.Next^.turn>0 then begin
  Car[Num].CurrDist:=CurSect^.Next^.Taxis+longint(Car[Num].intX)*Sn[CurSect^.Next^.Turn] div 128;
  if Car[Num].z>Car[Num].CurrDist then begin
(*   if Cam[num].Mode=6 then inc(Cam[num].Angle,CurSect^.Next^.turn);*)
   inc(Car[Num].Angle1,CurSect^.Next^.turn*10);
   inc(Car[Num].Angle2,CurSect^.Next^.turn*10);
   inc(Car[Num].Grise ,CurSect^.Next^.rise*sgn(Car[num].Speed));
   Car[Num].intZ:=Car[Num].intZ-CurSect^.Next^.Taxis;
   Alfa:=CurSect^.Next^.Turn;
   AuxX:=(longint(Car[Num].intZ)*sn[alfa]+longint(Car[Num].intX)*cs[alfa]) div 128;
   AuxZ:=(longint(Car[Num].intZ)*cs[alfa]-longint(Car[Num].intX)*sn[alfa]) div 128;
   Car[Num].Z:=AuxZ;
   Car[Num].X:=AuxX;
   Car[Num].IntZ:=AuxZ;
   Car[Num].IntX:=AuxX;
   CarNextSec(Num);
   CurSect:=Car[Num].Sec;
  end;
 end else
 if CurSect^.Next^.turn<0 then begin

   Car[Num].CurrDist:=CurSect^.Next^.Taxis-longint(Car[Num].intX)*Sn[-CurSect^.Next^.Turn] div 128;
  if Car[Num].z>Car[Num].CurrDist then begin
(*   if Cam[num].Mode=6 then inc(Cam[num].Angle,CurSect^.Next^.turn);*)
   inc(Car[Num].Angle1,CurSect^.Next^.turn*10);
   inc(Car[Num].Angle2,CurSect^.Next^.turn*10);
   inc(Car[Num].Grise ,CurSect^.Next^.rise*sgn(Car[num].Speed));
   Car[Num].intZ:=Car[Num].intZ-CurSect^.Next^.Taxis;
   Alfa:=360+CurSect^.Next^.Turn;
   AuxX:=(longint(Car[Num].intZ)*sn[alfa]+longint(Car[Num].intX)*cs[alfa]) div 128;
   AuxZ:=(longint(Car[Num].intZ)*cs[alfa]-longint(Car[Num].intX)*sn[alfa]) div 128;
   Car[Num].Z:=AuxZ;
   Car[Num].X:=AuxX;
   Car[Num].intZ:=AuxZ;
   Car[Num].intX:=AuxX;
   CarNextSec(Num);
   CurSect:=Car[Num].Sec;
  end;
 end else begin
  Car[Num].CurrDist:=SecDistance;
  if Car[Num].z>Car[Num].CurrDist then begin
   Car[Num].z:=Car[Num].z-Car[Num].CurrDist;
   Car[Num].intz:=trunc(Car[Num].z);
   inc(Car[Num].Grise ,CurSect^.Next^.rise*sgn(Car[num].Speed));
   CarNextSec(Num);
   CurSect:=Car[Num].Sec;
  end;
 end;
 if Car[Num].CurrDist>0 then Car[Num].DisPerc:=10*(Car[Num].CurrDist-Car[Num].intz) div Car[Num].CurrDist;
 Car[Num].CurrRise:=CurSect^.Rise-CurSect^.Rise*Car[Num].DisPerc div 10;

end else begin
 if Car[Num].z<0 then begin
  if CurSect^.turn>0 then begin
   Car[Num].CurrDist:=CurSect^.taxis+Car[Num].intX*sn[CurSect^.turn] div 128;
(*   if Cam[num].Mode=6 then inc(Cam[num].Angle,-CurSect^.turn);*)
   inc(Car[Num].Angle1,-CurSect^.turn*10);
   inc(Car[Num].Angle2,-CurSect^.turn*10);
   inc(Car[Num].Grise , CurSect^.rise*sgn(Car[num].Speed));
   Alfa:=360-CurSect^.Turn;
   AuxX:=(longint(Car[Num].intZ)*sn[alfa]+longint(Car[Num].intX)*cs[alfa]) div 128;
   AuxZ:=(longint(Car[Num].intZ)*cs[alfa]-longint(Car[Num].intX)*sn[alfa]) div 128;
   Car[Num].intZ:=AuxZ+CurSect^.Taxis;
   Car[Num].intX:=AuxX;
   Car[Num].Z:=Car[Num].intZ;
   Car[Num].X:=Car[Num].intX;
   CarLastSec(Num);
   CurSect:=Car[Num].Sec;
  end else
  if CurSect^.turn<0 then begin
   Car[Num].CurrDist:=CurSect^.taxis+Car[Num].intX*sn[-CurSect^.turn] div 128;
(*   if Cam[num].Mode=6 then inc(Cam[num].Angle,-CurSect^.turn);*)
   inc(Car[Num].Angle1,-CurSect^.turn*10);
   inc(Car[Num].Angle2,-CurSect^.turn*10);
   inc(Car[Num].Grise , CurSect^.rise*sgn(Car[num].Speed));
   Alfa:=-CurSect^.Turn;
   AuxX:=(longint(Car[Num].intZ)*sn[alfa]+longint(Car[Num].intX)*cs[alfa]) div 128;
   AuxZ:=(longint(Car[Num].intZ)*cs[alfa]-longint(Car[Num].intX)*sn[alfa]) div 128;
   Car[Num].intZ:=AuxZ+CurSect^.Taxis;
   Car[Num].intX:=AuxX;
   Car[Num].Z:=Car[Num].intZ;
   Car[Num].X:=Car[Num].intX;
   CarLastSec(Num);
   CurSect:=Car[Num].Sec;
  end else begin
   Car[Num].CurrDist:=SecDistance;
   Car[Num].z:=Car[Num].z+Car[Num].CurrDist;
   Car[Num].intZ:=trunc(Car[Num].z);
   inc(Car[Num].Grise ,CurSect^.rise*sgn(Car[num].Speed));
   CarLastSec(Num);
   CurSect:=Car[Num].Sec;
  end
 end;
  Car[Num].DisPerc:=10*(Car[Num].CurrDist-Car[Num].intZ) div Car[Num].CurrDist;
  Car[Num].CurrRise:=CurSect^.Rise-CurSect^.Rise*Car[Num].DisPerc div 10;
 end;
end else begin

(*************************************************************)
(***************** GO IN REVERSE *****************************)
(*************************************************************)

Car[Num].Gangle:=(Gangle(Car[num].Sec)+Car[num].Angle1 div 10+180) mod 360;
if Car[Num].GAngle<0 then inc(Car[Num].gAngle,360);

 Car[Num].x:=Car[Num].x-Car[Num].Speed*sn[auxAngle]/ConstSpeed;
 Car[Num].z:=Car[Num].z-Car[Num].Speed*cs[auxAngle]/ConstSpeed;

 Car[Num].intX:=trunc(Car[Num].x);
 Car[Num].intZ:=trunc(Car[Num].z);

if Car[Num].Speed>0 then begin
 if CurSect^.turn>0 then begin
  if Car[Num].z<0 then begin
   Car[Num].CurrDist:=CurSect^.taxis+Car[Num].intX*sn[CurSect^.turn] div 128;
(*   if Cam[num].Mode=6 then inc(Cam[num].Angle,-CurSect^.turn);*)
   inc(Car[Num].Angle1,-CurSect^.turn*10);
   inc(Car[Num].Angle2,-CurSect^.turn*10);
   inc(Car[Num].Grise , CurSect^.rise*sgn(Car[num].Speed));
   Alfa:=360-CurSect^.Turn;
   AuxX:=(longint(Car[Num].intZ)*sn[alfa]+longint(Car[Num].intX)*cs[alfa]) div 128;
   AuxZ:=(longint(Car[Num].intZ)*cs[alfa]-longint(Car[Num].intX)*sn[alfa]) div 128;
   Car[Num].intZ:=AuxZ;
   Car[Num].intX:=AuxX;
   Car[Num].intZ:=Car[Num].intZ+CurSect^.Taxis;
   Car[Num].Z:=Car[Num].intZ;
   Car[Num].X:=Car[Num].intX;
   CarLastSec(Num);
   CurSect:=Car[Num].Sec;
  end;
 end else
 if CurSect^.turn<0 then begin
  if Car[Num].z<0 then begin
   Car[Num].CurrDist:=CurSect^.taxis+Car[Num].intX*sn[-CurSect^.turn] div 128;
(*   if Cam[num].Mode=6 then inc(Cam[num].Angle,-CurSect^.turn);*)
   inc(Car[Num].Angle1,-CurSect^.turn*10);
   inc(Car[Num].Angle2,-CurSect^.turn*10);
   inc(Car[Num].Grise , CurSect^.rise*sgn(Car[num].Speed));
   Alfa:=-CurSect^.Turn;
   AuxX:=(longint(Car[Num].intZ)*sn[alfa]+longint(Car[Num].intX)*cs[alfa]) div 128;
   AuxZ:=(longint(Car[Num].intZ)*cs[alfa]-longint(Car[Num].intX)*sn[alfa]) div 128;
   Car[Num].intZ:=AuxZ;
   Car[Num].intX:=AuxX;
   Car[Num].intZ:=Car[Num].intZ+CurSect^.Taxis;
   Car[Num].Z:=Car[Num].intZ;
   Car[Num].X:=Car[Num].intX;
   CarLastSec(Num);
   CurSect:=Car[Num].Sec;
  end;
 end else begin
  if Car[Num].z<=0 then begin
   Car[Num].CurrDist:=SecDistance;
   Car[Num].z:=Car[Num].z+Car[Num].CurrDist;
   Car[Num].intz:=trunc(Car[Num].z);
   inc(Car[Num].Grise ,CurSect^.rise*sgn(Car[num].Speed));
   CarLastSec(Num);
   CurSect:=Car[Num].Sec;
  end;
 end;
end else begin
if CurSect^.Next^.turn>0 then begin
  Car[Num].CurrDist:=CurSect^.Next^.Taxis+longint(Car[Num].intX)*Sn[CurSect^.Next^.Turn] div 128;
  if Car[Num].z>Car[Num].CurrDist then begin
(*   if Cam[num].Mode=6 then inc(Cam[num].Angle,CurSect^.Next^.turn);*)
   inc(Car[Num].Angle1,CurSect^.Next^.turn*10);
   inc(Car[Num].Angle2,CurSect^.Next^.turn*10);
   inc(Car[Num].Grise ,CurSect^.Next^.rise   );
   Car[Num].intZ:=Car[Num].intZ-CurSect^.Next^.Taxis;
   Alfa:=CurSect^.Next^.Turn;
   AuxX:=(longint(Car[Num].intZ)*sn[alfa]+longint(Car[Num].intX)*cs[alfa]) div 128;
   AuxZ:=(longint(Car[Num].intZ)*cs[alfa]-longint(Car[Num].intX)*sn[alfa]) div 128;
   Car[Num].Z:=AuxZ;
   Car[Num].X:=AuxX;
   Car[Num].IntZ:=AuxZ;
   Car[Num].IntX:=AuxX;
   CarNextSec(Num);
   CurSect:=Car[Num].Sec;
  end;
 end else
 if CurSect^.Next^.turn<0 then begin

   Car[Num].CurrDist:=CurSect^.Next^.Taxis-longint(Car[Num].intX)*Sn[-CurSect^.Next^.Turn] div 128;
  if Car[Num].z>Car[Num].CurrDist then begin
(*   if Cam[num].Mode=6 then inc(Cam[num].Angle,CurSect^.Next^.turn);*)
   inc(Car[Num].Angle1,CurSect^.Next^.turn*10);
   inc(Car[Num].Angle2,CurSect^.Next^.turn*10);
   inc(Car[Num].Grise ,CurSect^.Next^.rise   );
   Car[Num].intZ:=Car[Num].intZ-CurSect^.Next^.Taxis;
   Alfa:=360+CurSect^.Next^.Turn;
   AuxX:=(longint(Car[Num].intZ)*sn[alfa]+longint(Car[Num].intX)*cs[alfa]) div 128;
   AuxZ:=(longint(Car[Num].intZ)*cs[alfa]-longint(Car[Num].intX)*sn[alfa]) div 128;
   Car[Num].Z:=AuxZ;
   Car[Num].X:=AuxX;
   Car[Num].intZ:=AuxZ;
   Car[Num].intX:=AuxX;
   CarNextSec(Num);
   CurSect:=Car[Num].Sec;
  end;
 end else begin
  Car[Num].CurrDist:=SecDistance;
  if Car[Num].z>Car[Num].CurrDist then begin
   Car[Num].z:=Car[Num].z-Car[Num].CurrDist;
   Car[Num].intz:=trunc(Car[Num].z);
   inc(Car[Num].Grise ,CurSect^.Next^.rise   );
   CarNextSec(Num);
   CurSect:=Car[Num].Sec;
  end;
 end;
end;
if CurSect^.Next^.turn>0 then
 CurSectDim:=CurSect^.Next^.taxis+longint(Car[Num].IntX)*sn[CurSect^.Next^.turn] div 128
else if CurSect^.Next^.turn<0 then
 CurSectDim:=CurSect^.Next^.taxis-longint(Car[Num].IntX)*sn[-CurSect^.Next^.turn] div 128
else CurSectDim:=SecDistance;

if CurSectDim>0 then Car[Num].DisPerc:=10*(CurSectDim-Car[Num].intZ) div CurSectDim;
Car[Num].CurrRise:=CurSect^.rise*Car[Num].DisPerc div 10;

end;
end;

Procedure PilotSPC(Num:byte);
Var
AuxAngle      :integer;
Alfa,AuxX,AuxZ:integer;
SPX,SPZ       :integer;
CurSect       :puntSec;
CurSectDim    :integer;

begin
CurSect:=SpecialObj[num].Sec;

if SpecialObj[Num].Angle> 90 then begin
dec(SpecialObj[Num].Angle,180); SpecialObj[Num].Reverse:=not SpecialObj[Num].Reverse;
end else
if SpecialObj[Num].Angle<-90 then begin
inc(SpecialObj[Num].Angle,180); SpecialObj[Num].Reverse:=not SpecialObj[Num].Reverse;
end;
AuxAngle:=SpecialObj[num].Angle mod 360; if AuxAngle<0 then inc(AuxAngle,360);

(******************************************************************************)
(************************** SPECIAL NORMAL RIDING *****************************)
(******************************************************************************)

if not SpecialObj[Num].Reverse then begin

 SpecialObj[Num].X:=SpecialObj[Num].X+SpecialObj[num].Speed*sn[AuxAngle] / 500;
 SpecialObj[Num].Z:=SpecialObj[Num].Z+SpecialObj[Num].Speed*cs[AuxAngle] / 500;
 SPX:=trunc(SpecialObj[num].X);
 SPZ:=trunc(SpecialObj[num].Z);

 if SpecialObj[Num].Speed>0 then begin
  if CurSect^.Next^.turn>0 then begin
   SpecialObj[Num].CurrDist:=CurSect^.Next^.Taxis+longint(trunc(SpX))*Sn[CurSect^.Next^.Turn] div 128;
   if SpZ>SpecialObj[Num].CurrDist then begin
    inc(SpecialObj[Num].Angle,CurSect^.Next^.turn);
    dec(SpZ,CurSect^.Next^.Taxis);
    Alfa:=CurSect^.Next^.Turn;
    AuxX:=(longint(SpZ)*sn[alfa]+longint(SpX)*cs[alfa]) div 128;
    AuxZ:=(longint(SpZ)*cs[alfa]-longint(SpX)*sn[alfa]) div 128;
    SpZ:=AuxZ;
    SpX:=AuxX;
    SpecialObjNextSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end;
  end else
  if CurSect^.Next^.turn<0 then begin
   SpecialObj[Num].CurrDist:=CurSect^.Next^.Taxis-longint(SpX)*Sn[-CurSect^.Next^.Turn] div 128;
   if SpZ>SpecialObj[Num].CurrDist then begin
    inc(SpecialObj[Num].Angle,CurSect^.Next^.turn);
    dec(SpZ,CurSect^.Next^.Taxis);
    Alfa:=360+CurSect^.Next^.Turn;
    AuxX:=(longint(SpZ)*sn[alfa]+longint(SpX)*cs[alfa]) div 128;
    AuxZ:=(longint(SpZ)*cs[alfa]-longint(SpX)*sn[alfa]) div 128;
    SpZ:=AuxZ;
    SpX:=AuxX;
    SpecialObjNextSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end;
  end else begin
   SpecialObj[Num].CurrDist:=SecDistance;
   if SpZ>SpecialObj[Num].CurrDist then begin
    dec(SpZ,SpecialObj[Num].CurrDist);
    SpecialObjNextSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end;
  end;
 if SpecialObj[num].CurrDist>0 then SpecialObj[Num].DisPerc:=10*(SpecialObj[Num].CurrDist-SpZ) div SpecialObj[Num].CurrDist;
  SpecialObj[Num].CurrRise:=CurSect^.Rise-CurSect^.Rise*SpecialObj[Num].DisPerc div 10;
 end else begin
  if SpZ<0 then begin
   if CurSect^.turn>0 then begin
    SpecialObj[Num].CurrDist:=CurSect^.taxis+SpX*sn[CurSect^.turn] div 128;
    inc(SpecialObj[Num].Angle,-CurSect^.turn);
    Alfa:=360-CurSect^.Turn;
    AuxX:=(longint(SpZ)*sn[alfa]+longint(SpX)*cs[alfa]) div 128;
    AuxZ:=(longint(SpZ)*cs[alfa]-longint(SpX)*sn[alfa]) div 128;
    SpZ:=AuxZ+CurSect^.Taxis;
    SpX:=AuxX;
    SpecialObjLastSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end else
   if CurSect^.turn<0 then begin
    SpecialObj[Num].CurrDist:=CurSect^.taxis+SpX*sn[-CurSect^.turn] div 128;
    inc(SpecialObj[Num].Angle,-CurSect^.turn);
    Alfa:=-CurSect^.Turn;
    AuxX:=(longint(SpZ)*sn[alfa]+longint(SpX)*cs[alfa]) div 128;
    AuxZ:=(longint(SpZ)*cs[alfa]-longint(SpX)*sn[alfa]) div 128;
    SpZ:=AuxZ+CurSect^.Taxis;
    SpX:=AuxX;
    SpecialObjLastSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end else begin
    SpecialObj[Num].CurrDist:=SecDistance;
    inc(SpZ,SpecialObj[Num].CurrDist);
    SpecialObjLastSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end
  end;
if SpecialObj[num].CurrDist>0 then  SpecialObj[Num].DisPerc:=10*(SpecialObj[Num].CurrDist-SpZ) div SpecialObj[Num].CurrDist;
  SpecialObj[Num].CurrRise:=CurSect^.Rise-CurSect^.Rise*SpecialObj[Num].DisPerc div 10;
 end;
end else begin

(*********************************************************************)
(***************** SPECIAL GO IN REVERSE *****************************)
(*********************************************************************)

 SpecialObj[Num].x:=SpecialObj[Num].x-Specialobj[Num].Speed*sn[AuxAngle]/ 500;
 SpecialObj[Num].z:=SpecialObj[Num].z-Specialobj[Num].Speed*cs[AuxAngle]/ 500;
 SPX:=trunc(SpecialObj[num].X);
 SPZ:=trunc(SpecialObj[num].Z);

 if SpecialObj[Num].Speed>0 then begin
  if CurSect^.turn>0 then begin
   if SpZ<0 then begin
    SpecialObj[Num].CurrDist:=CurSect^.taxis+SpX*sn[CurSect^.turn] div 128;
    inc(SpecialObj[Num].Angle,-CurSect^.turn);
    Alfa:=360-CurSect^.Turn;
    AuxX:=(longint(SpZ)*sn[alfa]+longint(SpX)*cs[alfa]) div 128;
    AuxZ:=(longint(SpZ)*cs[alfa]-longint(SpX)*sn[alfa]) div 128;
    SpZ:=AuxZ+CurSect^.Taxis;;
    SpX:=AuxX;
    SpecialObjLastSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end;
  end else
  if CurSect^.turn<0 then begin
   if SpZ<0 then begin
    SpecialObj[Num].CurrDist:=CurSect^.taxis+SpX*sn[-CurSect^.turn] div 128;
    inc(SpecialObj[Num].Angle,-CurSect^.turn);
    Alfa:=-CurSect^.Turn;
    AuxX:=(longint(SpZ)*sn[alfa]+longint(SpX)*cs[alfa]) div 128;
    AuxZ:=(longint(SpZ)*cs[alfa]-longint(SpX)*sn[alfa]) div 128;
    SpZ:=AuxZ+CurSect^.Taxis;
    SpX:=AuxX;
    SpecialObjLastSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end;
  end else begin
   if SpZ<=0 then begin
    SpecialObj[Num].CurrDist:=SecDistance;
    inc(SpZ,SpecialObj[Num].CurrDist);
    SpecialObjLastSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end;
  end;
 end else begin
 if CurSect^.Next^.turn>0 then begin
   SpecialObj[Num].CurrDist:=CurSect^.Next^.Taxis+longint(SpX)*Sn[CurSect^.Next^.Turn] div 128;
   if SpZ>SpecialObj[Num].CurrDist then begin
    inc(SpecialObj[Num].Angle,CurSect^.Next^.turn);
    dec(SpZ,CurSect^.Next^.Taxis);
    Alfa:=CurSect^.Next^.Turn;
    AuxX:=(longint(SpZ)*sn[alfa]+longint(SpX)*cs[alfa]) div 128;
    AuxZ:=(longint(SpZ)*cs[alfa]-longint(SpX)*sn[alfa]) div 128;
    SpZ:=AuxZ;
    SpX:=AuxX;
    SpecialObjNextSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end;
  end else
  if CurSect^.Next^.turn<0 then begin

   SpecialObj[Num].CurrDist:=CurSect^.Next^.Taxis-longint(SpX)*Sn[-CurSect^.Next^.Turn] div 128;
   if SpZ>SpecialObj[Num].CurrDist then begin
    inc(SpecialObj[Num].Angle,CurSect^.Next^.turn);
    dec(SpZ,CurSect^.Next^.Taxis);
    Alfa:=360+CurSect^.Next^.Turn;
    AuxX:=(longint(SpZ)*sn[alfa]+longint(SpX)*cs[alfa]) div 128;
    AuxZ:=(longint(SpZ)*cs[alfa]-longint(SpX)*sn[alfa]) div 128;
    SpZ:=AuxZ;
    SpX:=AuxX;
    SpecialObjNextSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end;
  end else begin
   SpecialObj[Num].CurrDist:=SecDistance;
   if SpZ>SpecialObj[Num].CurrDist then begin
    dec(SpZ,SpecialObj[Num].CurrDist);
    SpecialObjNextSec(Num);
    CurSect:=SpecialObj[Num].Sec;
    SpecialObj[num].X:=SPX;
    SpecialObj[num].Z:=SPZ;
   end;
  end;
 end;
 if CurSect^.Next^.turn>0 then
 CurSectDim:=CurSect^.Next^.taxis+longint(SpX)*sn[CurSect^.Next^.turn] div 128
 else if CurSect^.Next^.turn<0 then
 CurSectDim:=CurSect^.Next^.taxis-longint(SpX)*sn[-CurSect^.Next^.turn] div 128
 else CurSectDim:=SecDistance;

if CurSectDim>0 then SpecialObj[Num].DisPerc:=10*(CurSectDim-SpZ) div CurSectDim;
 SpecialObj[Num].CurrRise:=CurSect^.rise*SpecialObj[Num].DisPerc div 10;
end
end;

Procedure ControlSpc (Num: byte);
Var Aux:integer;

begin

 if SpecialObj[Num].Tipo=1 then begin (************ AIRSHIP ********************)
  if abs(SpecialObj[num].X)>1200 then begin
   inc(Ran);if Ran>2 then Ran:=0;
   if Ran=0 then begin
    SpecialObj[num].X:=1100;
    SpecialObj[num].Angle:=-45;
    SpecialObj[num].reverse:=False;
   end else
   if Ran=1 then begin
    SpecialObj[num].X:=-1100;
    SpecialObj[num].Angle:=45;
    SpecialObj[num].reverse:=False;
   end else
   if Ran=2 then begin
    SpecialObj[num].X:=-1100;
    SpecialObj[num].Angle:=-45;
    SpecialObj[num].reverse:=True;
   end else
   if Ran=3 then begin
    SpecialObj[num].X:=1100;
    SpecialObj[num].Angle:=45;
    SpecialObj[num].reverse:=True;
   end;
   Dec(SpecialObj[Num].Sec^.NumSpc,SpecialObj[num].id);
   SpecialObj[Num].Sec:=SpecialObj[Num].SSec;
   inc(SpecialObj[Num].Sec^.NumSpc,SpecialObj[num].id);
  end;
 end else
 if SpecialObj[Num].Tipo=2 then begin  (************ GRU ********************)
  if ((SpecialObj[num].Img<3) and ((SpecialObj[num].Angle= 50) or (SpecialObj[num].Angle=-50))) or
      (SpecialObj[num].Img>50) then
    if SpecialObj[num].Img>2 then begin
     if SpecialObj[num].img>2 then SpecialObj[num].img:=1 else SpecialObj[num].img:=0;
     end else SpecialObj[num].img:=3;
  if SpecialObj[num].img=1 then inc(SpecialObj[num].Angle,2) else
  if SpecialObj[num].img=2 then dec(SpecialObj[num].Angle,2) else
  if SpecialObj[num].img>2 then inc(SpecialObj[num].Img);
 end else
 if SpecialObj[Num].Tipo=3 then begin  (************ BIDONE ********************)
  For Ran:=1 to 8 do begin
   if (Car[Ran].Sec^.NumSec=SpecialObj[Num].Sec^.NumSec) and
   (abs(trunc(Car[Ran].x-SpecialObj[Num].x))<60) and
   (abs(trunc(Car[Ran].z-SpecialObj[Num].z))<60) and
   (                     SpecialObj[Num].y  <20) then begin
    SpecialObj[Num].Reverse:=Car[Ran].Reverse;
    SpecialObj[Num].Speed  :=Car[Ran].Speed*3 div 2;
    SpecialObj[Num].Angle  :=Car[Ran].Angle2 div 10;
    SpecialObj[Num].img    :=-abs(Car[Ran].Speed div 6);
    Aux:=SpecialObj[Num].Angle mod 360; if Aux<0 then inc(Aux,360);
    SpecialObj[Num].X:=SpecialObj[Num].X+sn[Aux];
    SpecialObj[Num].Z:=SpecialObj[Num].Z+cs[Aux];
    if (Car[Ran].PilotType=1) or (Car[Ran].PilotType=2) or (Car[Ran].PilotType=3) then Playsample(4,5,64,70,100);
   end
  end;
  inc(SpecialObj[Num].Simg,SpecialObj[Num].Speed);
  if abs(SpecialObj[Num].Speed)<30 then
   while SpecialObj[Num].Number=2 do begin
    if Abs(SpecialObj[Num].Img)<5 then SpecialObj[Num].Speed:=0;
    Rotate(Num,90);SpecialObj[Num].Number:=3;
   end else
  if SpecialObj[Num].Simg>200 then begin
   SpecialObj[Num].Simg:=0;
   Rotate(Num,90);
   inc(SpecialObj[Num].Number);
   if SpecialObj[Num].Number>3 then SpecialObj[Num].Number:=0;
  end;
  inc(SpecialObj[Num].Img,2);
  SpecialObj[Num].y:=SpecialObj[Num].y-SpecialObj[Num].Img;
  if Abs(SpecialObj[Num].Speed)>16 then dec(SpecialObj[Num].Speed,sgn(SpecialObj[Num].Speed shl 4))
                                   else SpecialObj[Num].Speed:=0;
  if SpecialObj[Num].X>SpecialObj[Num].Sec^.MaxSpc then
   Begin SpecialObj[Num].Angle:=-SpecialObj[Num].Angle; SpecialObj[Num].X:=SpecialObj[Num].Sec^.MaxSpc end;
  if SpecialObj[Num].X<SpecialObj[Num].Sec^.MinSpc then
   Begin SpecialObj[Num].Angle:=-SpecialObj[Num].Angle; SpecialObj[Num].X:=SpecialObj[Num].Sec^.MinSpc end;
  if SpecialObj[num].Y<8 then
   Begin SpecialObj[Num].Img:=-SpecialObj[Num].Img div 2; SpecialObj[Num].Y:=0 end;
 end else
 if SpecialObj[Num].Tipo=4 then begin  (************ CABINA ********************)
  if SpecialObj[Num].x<-600 then begin SpecialObj[Num].x:=-600; SpecialObj[Num].Speed:=-SpecialObj[Num].Speed; end;
  if SpecialObj[Num].x> 600 then begin SpecialObj[Num].x:= 600; SpecialObj[Num].Speed:=-SpecialObj[Num].Speed; end;
 end else
 if SpecialObj[Num].Tipo=5 then begin  (************ SPAZZANEVE ********************)
  SpecialObj[Num].Angle:=0;
  if SpecialObj[num].Speed<SpecialObj[Num].SSpeed then inc(SpecialObj[Num].Speed,2);
  SpecialObj[Num].x:=SpecialObj[Num].x+Trunc(SpecialObj[Num].Sx-SpecialObj[Num].x) div 5;
  For Ran:=1 to MaxCars do CheckCollSpc(Ran,Num);
 end else
 if SpecialObj[Num].Tipo=6 then begin  (************ BIRDS ********************)
  if SpecialObj[Num].x<-700 then begin SpecialObj[Num].x:=700; SpecialObj[Num].Speed:=30 end;
  inc(SpecialObj[Num].Img); if SpecialObj[Num].Img>6 then SpecialObj[Num].Img:=0;
  ChgFace(Num,0,SpecialObj[Num].Img div 2+1);
 end
end;

Procedure ControlCar (NCar,Num: byte);
var Sorpasser                :boolean;
    AuxSec1,AuxSec2          :puntsec;
    Cnt,AHan,Dist            :integer;
    AuXtrottle,AuYtrottle    :integer;
    PCar                     :byte;
begin
(************************** CPU DRIVE ******************************)
if Num=0 then begin
AuxSec1:=Car[NCar].Sec^.next;

For cnt:=1 to Car[Ncar].Speed div 40 do AuxSec1:=AuxSec1^.Next;

AuxSec2:=AuxSec1^.Next;
 PCar:=ProxCar(Ncar);

if NCar=BanCar then begin
  Sorpasser:=(Car[NCar].Sec^.Numsec+8>Car[PCar].Sec^.Numsec) and
             (Car[NCar].Sec^.Numsec<Car[PCar].Sec^.Numsec+1) and
             (Car[Ncar].intX >Car[Pcar].intX-130)            and
             (Car[Ncar].intX <Car[Pcar].intX+130);
              spia:=Sorpasser

  end else begin
  Sorpasser:=(Car[NCar].Sec^.Numsec+7>Car[PCar].Sec^.Numsec) and
             (Car[NCar].Sec^.Numsec<Car[PCar].Sec^.Numsec+1) and
             (Car[Ncar].Speed>Car[Pcar].Speed)               and
             (Car[Ncar].intX >Car[Pcar].intX-130)            and
             (Car[Ncar].intX <Car[Pcar].intX+130);
  end;
  if (AuxSec1^.Turn<>0) then begin

   if (AuxSec1^.turn>0) and (AuxSec2^.turn>0) then Car[Ncar].CPUx:=AuxSec1^.Minroad+20 else
   if (AuxSec1^.turn<0) and (AuxSec2^.turn<0) then Car[Ncar].CPUx:=AuxSec1^.Maxroad-20;

   if sorpasser then begin
    if (Car[Ncar].IntX> Car[Pcar].intX) then
    if (-Car[Pcar].intX+Car[Pcar].Sec^.Maxroad>140) and
       (Car[Ncar].Sec^.Turn>0)                     then Car[Ncar].CPUx:=Car[Pcar].intX+120
    else
    if (Car[Ncar].IntX<=Car[Pcar].intX) then
    if (Car[Pcar].IntX-Car[Pcar].Sec^.Minroad>140) and
       (Car[Ncar].Sec^.Turn<0)                     then Car[Ncar].CPUx:=Car[Pcar].intX-120
   end
  end else

  if sorpasser and (Ncar=BanCar) then begin
   if (Car[Ncar].IntX>Car[Pcar].intX) then
   if (-Car[Pcar].intX+Car[Pcar].Sec^.Maxroad>140) then Car[Ncar].CPUx:=Car[Pcar].intX+120 else
                                                        Car[Ncar].CPUx:=Car[Pcar].intX-120
   else
   if (Car[Ncar].IntX<=Car[Pcar].intX) then
   if (Car[Pcar].IntX-Car[Pcar].Sec^.Minroad>140) then Car[Ncar].CPUx:=Car[Pcar].intX-120 else
                                                       Car[Ncar].CPUx:=Car[Pcar].intX+120;
   end else

  if sorpasser then begin
   if (Car[Ncar].IntX>Car[Pcar].intX) then
   if (-Car[Pcar].intX+Car[Pcar].Sec^.Maxroad>140) then Car[Ncar].CPUx:=Car[Pcar].intX+120 else
                                                        Car[Ncar].CPUx:=Car[Pcar].intX-120
   else
   if (Car[Ncar].IntX<=Car[Pcar].intX) then
   if (Car[Pcar].IntX-Car[Pcar].Sec^.Minroad>140) then Car[Ncar].CPUx:=Car[Pcar].intX-120 else
                                                       Car[Ncar].CPUx:=Car[Pcar].intX+120
  end else begin
   if Car[Ncar].CPUx>AuxSec1^.MaxRoad-80 then Car[Ncar].CPUx:=AuxSec1^.MaxRoad-80 else
   if Car[Ncar].CPUx<AuxSec1^.MinRoad+80 then Car[Ncar].CPUx:=AuxSec1^.MinRoad+80;
  end;

For cnt:=21 to 28 do begin
Dist:=abs(integer(Car[NCar].Sec^.NumSec)-integer(SpecialObj[cnt].Sec^.Numsec));
if Dist>Groad.MaxSec shr 1 then Dist:=Groad.Maxsec-Dist;

if (SpecialObj[cnt].Class=1) and
   (SpecialObj[cnt].id>0)    and
   (Car[Ncar].Sec^.NumSec<SpecialObj[Cnt].Sec^.NumSec+2) and
   (Dist<20) (*and (AuxSec1^.turn=0) and (AuxSec2^.turn=0)*)
   then
   begin
   if (SpecialObj[Cnt].X>Car[NCar].X) and (AuxSec1^.turn=0) and (AuxSec2^.turn=0)
                                            then Car[NCar].CpuX:=trunc(SpecialObj[cnt].X)-90
                                            else Car[NCar].CpuX:=trunc(SpecialObj[cnt].X)+90;

   if (SpecialObj[Cnt].X>Car[NCar].X) and (AuxSec1^.turn>0) and (AuxSec2^.turn>0)
                                            then Car[NCar].CpuX:=AuxSec1^.MinRoad+20
                                            else Car[NCar].CpuX:=Trunc(SpecialObj[cnt].x)+90;

   if (SpecialObj[Cnt].X>Car[NCar].X) and (AuxSec1^.turn<0) and (AuxSec2^.turn<0)
                                            then Car[NCar].CpuX:=Trunc(SpecialObj[cnt].x)-90
                                            else Car[NCar].CpuX:=AuxSec1^.MaxRoad-20;
  end;
end;

inc(Car[Ncar].CpuEfx,(Car[Ncar].CpuX-Car[Ncar].CPUefx) div 5);

Cnt:=((Car[Ncar].IntX-Car[Ncar].CPUEfx)*3+Car[Ncar].Angle1) div 2;


if (Car[Ncar].Sec^.Turn=0) then begin
 if Cnt> 50 then Cnt:= 50 else
 if Cnt<-50 then Cnt:=-50;
end else begin
 if Cnt> 70 then Cnt:= 70 else
 if Cnt<-70 then Cnt:=-70;
end;

if Car[Ncar].Reverse then Cnt:=-50*Sgn(Car[Ncar].Angle1) else begin
if (Car[Ncar].Angle1> 500) then Cnt:= 50;
if (Car[Ncar].Angle1<-500) then Cnt:=-50;
end;

inc(Xtrottle[NCar],(Cnt-Xtrottle[Ncar]) div 2);
if Start then inc(Car[NCar].Angle1,-Xtrottle[Ncar]);

if Car[Ncar].Speed<210-Han[Ncar]-TAddHan shl 2 then dec(Ytrottle[Ncar],25) else Ytrottle[Ncar]:=0;

if Car[Ncar].Trab and (Car[Ncar].Speed>80) then Ytrottle[Ncar]:=1;

if Ytrottle[NCar]> 100 then Ytrottle[NCar]:= 100;
if Ytrottle[NCar]<-100 then Ytrottle[NCar]:=-100;

if not Touch[NCar] and Start then begin
 if Car[NCar].Revs1>1200-Car[NCar].Gear*50-Han[Ncar]*2 then begin
  Touch[NCar]:=True;
  CGear[NCar]:= 1;
 end;
 if (Car[NCar].Revs1<400+Car[NCar].Gear*50) and (Car[NCar].Gear>1) then begin
  Touch[NCar]:=True;
  CGear[NCar]:=-1
 end
end else begin Touch[NCar]:=false; Cgear[NCar]:=0; end;
end else
(************************** KEYBOARD 1 ******************************)
if Num=1 then begin
if keystate(Lf1) then dec(Xtrottle[NCar],20) else
if keystate(Rg1) then inc(Xtrottle[NCar],20) ;
 if Xtrottle[NCar]> 100 then Xtrottle[NCar]:= 100 else
 if Xtrottle[NCar]<-100 then Xtrottle[NCar]:=-100;

 dec(Xtrottle[NCar],sgn(Xtrottle[NCar])+Xtrottle[NCar] div 4);
if keystate(Up1) then dec(Ytrottle[NCar],20) else
if keystate(Dw1) then begin
                       if Ytrottle[NCar]<0 then YTrottle[Ncar]:=0 else
                       inc(Ytrottle[NCar],20)
                      end else Ytrottle[NCar]:=0;

if Ytrottle[NCar]> 100 then Ytrottle[NCar]:= 100 else
if Ytrottle[NCar]<-100 then Ytrottle[NCar]:=-100;

if Car[Ncar].Automatic and (Car[NCar].Gear>0) then begin
 if not Touch[NCar] and Start then begin
  if (Car[NCar].Revs1>1200-Car[NCar].Gear*50) then begin
   Touch[NCar]:=True;
   CGear[NCar]:= 1;
  end;
  if (Car[NCar].Revs1< 500+Car[NCar].Gear*50-ord(Car[Ncar].gear=1)*350) and (Car[NCar].Gear>0) then begin
   Touch[NCar]:=True;
   CGear[NCar]:=-1
  end
 end else begin Touch[NCar]:=false; Cgear[NCar]:=0; end;
end else begin
 if not Touch[NCar] and Start then begin
  if keystate(Ba1) then begin
   Touch[NCar]:=True;
   CGear[NCar]:= 1;
  end;
  if keystate(Bb1) then begin
   Touch[NCar]:=True;
   CGear[NCar]:=-1
  end
 end else Cgear[NCar]:=0;
 if not keystate(Ba1) and not keystate(Bb1) then Touch[NCar]:=false;
end;
end else
(************************** KEYBOARD 2 ******************************)
if Num=2 then begin
if keystate(Lf2) then dec(Xtrottle[NCar],20) else
if keystate(Rg2) then inc(Xtrottle[NCar],20);
 if Xtrottle[NCar]> 100 then Xtrottle[NCar]:= 100 else
 if Xtrottle[NCar]<-100 then Xtrottle[NCar]:=-100;
 dec(Xtrottle[NCar],sgn(Xtrottle[NCar])+Xtrottle[NCar] div 4);
if keystate(Up2) then dec(Ytrottle[NCar],20) else
if keystate(Dw2) then begin
                       if Ytrottle[NCar]<0 then YTrottle[Ncar]:=0 else
                       inc(Ytrottle[NCar],20)
                      end else Ytrottle[NCar]:=0;
if Ytrottle[NCar]> 100 then Ytrottle[NCar]:= 100 else
if Ytrottle[NCar]<-100 then Ytrottle[NCar]:=-100;





if Car[Ncar].Automatic and (Car[NCar].Gear>0) then begin
 if not Touch[NCar] and Start then begin
  if (Car[NCar].Revs1>1200-Car[NCar].Gear*50) then begin
   Touch[NCar]:=True;
   CGear[NCar]:= 1;
  end;
  if (Car[NCar].Revs1< 500+Car[NCar].Gear*50-ord(Car[Ncar].gear=1)*350) and (Car[NCar].Gear>0) then begin
   Touch[NCar]:=True;
   CGear[NCar]:=-1
  end
 end else begin Touch[NCar]:=false; Cgear[NCar]:=0; end;
end else begin
 if not Touch[NCar] and Start then begin
  if keystate(Ba2) then begin
   Touch[NCar]:=True;
   CGear[Ncar]:=1;
  end;
  if keystate(Bb2) then begin
   Touch[NCar]:=True;
   CGear[Ncar]:=-1;
  end
 end else Cgear[NCar]:=0;
if not keystate(Ba2) and not keystate(Bb2) then Touch[NCar]:=false;
end;
end else
(************************** JOY 1 ******************************)
if Num=3 then begin
if JoyOn1 then begin
  if not Drawing then delay(5);
  if Oscil then JoyX1 else JoyY1;
  Oscil:=not Oscil;
 end;
if Xvalue1<XNegTol1 then auXtrottle:=-Longint(Xvalue1-XNegTol1)*14 div MinX1 else
if Xvalue1>XPosTol1 then auXtrottle:= Longint(Xvalue1-XPosTol1)*14 div MaxX1 else auXtrottle:=0;
if Yvalue1<YNegTol1 then auYtrottle:=-Longint(Yvalue1-YNegTol1)*14 div MinY1 else
if Yvalue1>YPosTol1 then auYtrottle:= Longint(Yvalue1-YPosTol1)*14 div MaxY1 else auYtrottle:=0;
if auXtrottle>  120 then auXtrottle:=  120 else
if auXtrottle< -120 then auXtrottle:= -120 ;
if auYtrottle>  60  then auYtrottle:=  60 else
if auYtrottle< -60  then auYtrottle:= -60 ;
Cnt:=(AuXtrottle-Xtrottle[Ncar]);
if Cnt> 25 then Cnt:= 25 else
if Cnt<-25 then Cnt:=-25;

inc(Xtrottle[Ncar],Cnt); dec(Xtrottle[NCar],sgn(Xtrottle[NCar])+Xtrottle[NCar] div 4);
inc(Ytrottle[Ncar],(AuYtrottle shl 1-Ytrottle[Ncar]) div 2);

if (Ytrottle[Ncar]<10) and (Ytrottle[Ncar]>-10) then Ytrottle[Ncar]:=0;
if YTrottle[Ncar]> 100 then yTrottle[Ncar]:= 100 else
if YTrottle[Ncar]<-100 then yTrottle[Ncar]:=-100;

if Car[Ncar].Automatic and (Car[NCar].Gear>0) then begin
 if not Touch[NCar] and Start then begin
  if (Car[NCar].Revs1>1200-Car[NCar].Gear*50) then begin
   Touch[NCar]:=True;
   CGear[NCar]:= 1;
  end;
  if (Car[NCar].Revs1< 500+Car[NCar].Gear*50-ord(Car[Ncar].gear=1)*350) and (Car[NCar].Gear>0) then begin
   Touch[NCar]:=True;
   CGear[NCar]:=-1
  end
 end else begin Touch[NCar]:=false; Cgear[NCar]:=0; end;
end else begin
 if not Touch[NCar] and Start then begin
  if joy11 then begin
   Touch[NCar]:=True;
   CGear[NCar]:= 1;
  end;
  if joy12 then begin
   Touch[NCar]:=True;
   CGear[NCar]:=-1
  end
 end else Cgear[NCar]:=0;
 if not joy11 and not joy12 then Touch[NCar]:=false;
end;
end else
(************************** CPU DRIVE SLOW ******************************)
if Num=4 then begin
 AuxSec1:=Car[NCar].Sec^.next;

 For cnt:=1 to Car[Ncar].Speed div 40 do AuxSec1:=AuxSec1^.Next;

 AuxSec2:=AuxSec1^.Next;
 PCar:=ProxCar(Ncar);

(*if (Car[Pcar].Team=1) or (Car[Pcar].Team=1) then
 Sorpasser:=(Car[NCar].Sec^.Numsec>Car[PCar].Sec^.Numsec)  and
            (Car[NCar].Sec^.Numsec<Car[PCar].Sec^.Numsec+4)  and
            (Car[Ncar].intX >Car[Pcar].intX-120)             and
            (Car[Ncar].intX <Car[Pcar].intX+120)            else*)

 Sorpasser:=(Car[NCar].Sec^.Numsec+7>Car[PCar].Sec^.Numsec) and
            (Car[NCar].Sec^.Numsec<Car[PCar].Sec^.Numsec+1) and
            (Car[Ncar].Speed>Car[Pcar].Speed)               and
            (Car[Ncar].intX >Car[Pcar].intX-130)            and
            (Car[Ncar].intX <Car[Pcar].intX+130);

 if (AuxSec1^.Turn<>0) and not Sorpasser then begin

  if (AuxSec1^.turn>0) and (AuxSec2^.turn>0) then Car[Ncar].CPUx:=AuxSec1^.Minroad+20 else
  if (AuxSec1^.turn<0) and (AuxSec2^.turn<0) then Car[Ncar].CPUx:=AuxSec1^.Maxroad-20;

  if sorpasser then begin
   if (Car[Ncar].IntX> Car[Pcar].intX) then
   if (-Car[Pcar].intX+Car[Pcar].Sec^.Maxroad>140) and
      (Car[Ncar].Sec^.Turn>0)                     then Car[Ncar].CPUx:=Car[Pcar].intX+120
   else
   if (Car[Ncar].IntX<=Car[Pcar].intX) then
   if (Car[Pcar].IntX-Car[Pcar].Sec^.Minroad>140) and
      (Car[Ncar].Sec^.Turn<0)                     then Car[Ncar].CPUx:=Car[Pcar].intX-120
  end
 end else

 if sorpasser then begin
  if (Car[Ncar].IntX> Car[Pcar].intX) then
  if (-Car[Pcar].intX+Car[Pcar].Sec^.Maxroad>140) then Car[Ncar].CPUx:=Car[Pcar].intX+120 else
                                                       Car[Ncar].CPUx:=Car[Ncar].intX-120
  else
  if (Car[Ncar].IntX<=Car[Pcar].intX) then
  if (Car[Pcar].IntX-Car[Pcar].Sec^.Minroad>140) then Car[Ncar].CPUx:=Car[Pcar].intX-120 else
                                                       Car[Ncar].CPUx:=Car[Ncar].intX+120
 end else
 if Car[Ncar].CPUx>AuxSec1^.MaxRoad-80 then Car[Ncar].CPUx:=AuxSec1^.MaxRoad-80 else
 if Car[Ncar].CPUx<AuxSec1^.MinRoad+80 then Car[Ncar].CPUx:=AuxSec1^.MinRoad+80;

For cnt:=21 to 28 do begin
Dist:=abs(integer(Car[NCar].Sec^.NumSec)-integer(SpecialObj[cnt].Sec^.Numsec));
if Dist>Groad.MaxSec div 2 then Dist:=Groad.Maxsec-Dist;

if (SpecialObj[cnt].Class=1) and
   (SpecialObj[cnt].id>0)    and
   (Car[Ncar].Sec^.NumSec<SpecialObj[Cnt].Sec^.NumSec+2) and
   (Dist<20) (*and (AuxSec1^.turn=0) and (AuxSec2^.turn=0)*)
   then
   begin
   if (SpecialObj[Cnt].X>Car[NCar].X) and (AuxSec1^.turn=0) and (AuxSec2^.turn=0)
                                            then Car[NCar].CpuX:=trunc(SpecialObj[cnt].X)-90
                                            else Car[NCar].CpuX:=trunc(SpecialObj[cnt].X)+90;

   if (SpecialObj[Cnt].X>Car[NCar].X) and (AuxSec1^.turn>0) and (AuxSec2^.turn>0)
                                            then Car[NCar].CpuX:=AuxSec1^.MinRoad+20
                                            else Car[NCar].CpuX:=Trunc(SpecialObj[cnt].x)+90;

   if (SpecialObj[Cnt].X>Car[NCar].X) and (AuxSec1^.turn<0) and (AuxSec2^.turn<0)
                                            then Car[NCar].CpuX:=Trunc(SpecialObj[cnt].x)-90
                                            else Car[NCar].CpuX:=AuxSec1^.MaxRoad-20;
 end;
end;

 inc(Car[Ncar].CpuEfx,(Car[Ncar].CpuX-Car[Ncar].CPUefx) div 5);

 Cnt:=((Car[Ncar].IntX-Car[Ncar].CPUEfx)*3+Car[Ncar].Angle1) div 2;

 if (Car[Ncar].Sec^.Turn=0) then begin
  if Cnt> 50 then Cnt:= 50 else
  if Cnt<-50 then Cnt:=-50;
 end else begin
  if Cnt> 70 then Cnt:= 70 else
  if Cnt<-70 then Cnt:=-70;
 end;

 if Car[Ncar].Reverse then Cnt:=-50*Sgn(Car[Ncar].Angle1) else begin
  if (Car[Ncar].Angle1> 500) then Cnt:= 50;
  if (Car[Ncar].Angle1<-500) then Cnt:=-50;
 end;

 inc(Xtrottle[NCar],(Cnt-Xtrottle[Ncar]) div 2);
 if Start then inc(Car[NCar].Angle1,-Xtrottle[Ncar]);

 PCar:=ProxCar2(Ncar);

 Dist:=80-Cround*5+50*Ord((Car[Pcar].Team=0) and (integer(Car[ncar].Sec^.Numsec)-integer(Car[pcar].Sec^.Numsec)<20)
                                      and (integer(Car[ncar].Sec^.Numsec)-integer(Car[pcar].Sec^.Numsec)> 0));

 if Car[Ncar].Speed<Dist then Ytrottle[Ncar]:=-90 else Ytrottle[Ncar]:=0;

 if Car[Ncar].Trab and (Car[Ncar].Speed>80) then Ytrottle[Ncar]:=1;

 if not Touch[NCar] and Start then begin
  if Car[NCar].Revs1>1000-Car[NCar].Gear*40 then begin
   Touch[NCar]:=True;
   CGear[NCar]:= 1;
  end;
  if (Car[NCar].Revs1<400+Car[NCar].Gear*50) and (Car[NCar].Gear>1) then begin
   Touch[NCar]:=True;
   CGear[NCar]:=-1
  end
 end else begin Touch[NCar]:=false; Cgear[NCar]:=0; end;
end else
(***************************** CPU COP ****************************************)
if Num=5 then begin
 BanDis[NCar]:=abs(integer(Car[NCar].Sec^.Numsec)-integer(Car[BanCar].Sec^.Numsec));
 if ((ExTipoMess[NCar]<>TipoMess[NCar]) and (TimeMess>70)) or (TimeMess>150) then begin TimeMess:=0; ExtipoMess:=TipoMess end;
 if BanDis[NCar]>Groad.MaxSec shr 1 Then BanDis[NCar]:=integer(Groad.Maxsec)-BanDis[NCar];
   if BanDis[NCar]>Groad.MaxSec shr 1 Then BanDis[NCar]:=integer(Groad.Maxsec)-BanDis[NCar];
   if BanDis[NCar]> 60 then TipoMess[NCar]:=5 else
   if BanDis[NCar]> 40 then TipoMess[NCar]:=4 else
   if BanDis[NCar]> 15 then TipoMess[NCar]:=3 else
   if BanDis[NCar]>  5 then TipoMess[NCar]:=2 else
   if BanDis[NCar]>  1 then TipoMess[NCar]:=1 ;
   inc(TimeMess);

 AuxSec1:=Car[NCar].Sec^.next;

 if Car[Ncar].Ahead then For cnt:=1 to Car[Ncar].Speed div 20 do AuxSec1:=AuxSec1^.Next
                    else For cnt:=1 to Car[Ncar].Speed div 20 do AuxSec1:=AuxSec1^.Last;

 if Car[Ncar].Ahead then AuxSec2:=AuxSec1^.Next else AuxSec2:=AuxSec1^.Last;

 PCar:=ProxCar(Ncar);

 Sorpasser:=(Pcar<>BanCar)                                  and
            (Car[NCar].Sec^.Numsec+7>Car[PCar].Sec^.Numsec) and
            (Car[NCar].Sec^.Numsec<Car[PCar].Sec^.Numsec+1) and
            (Car[Ncar].Speed  >Car[Pcar].Speed)             and
            (Car[Ncar].intX   >Car[Pcar].intX-130)          and
            (Car[Ncar].intX   <Car[Pcar].intX+130);

 if (AuxSec1^.Turn<>0) then begin

  if (AuxSec1^.turn>0) and (AuxSec2^.turn>0) then Car[Ncar].CPUx:=AuxSec1^.Minroad+20 else
  if (AuxSec1^.turn<0) and (AuxSec2^.turn<0) then Car[Ncar].CPUx:=AuxSec1^.Maxroad-20;

  if sorpasser then begin
   if (Car[Ncar].IntX> Car[Pcar].intX) then
   if (-Car[Pcar].intX+Car[Pcar].Sec^.Maxroad>140) and
      (Car[Ncar].Sec^.Turn>0)                     then Car[Ncar].CPUx:=Car[Pcar].intX+120
   else
   if (Car[Ncar].IntX<=Car[Pcar].intX) then
   if (Car[Pcar].IntX-Car[Pcar].Sec^.Minroad>140) and
      (Car[Ncar].Sec^.Turn<0)                     then Car[Ncar].CPUx:=Car[Pcar].intX-120
  end
 end;

  if sorpasser then begin
   if (Car[Ncar].IntX> Car[Pcar].intX) then
   if (-Car[Pcar].intX+Car[Pcar].Sec^.Maxroad>140) then Car[Ncar].CPUx:=Car[Pcar].intX+120 else
                                                        Car[Ncar].CPUx:=Car[Ncar].intX-120
   else
   if (Car[Ncar].IntX<=Car[Pcar].intX) then
   if (Car[Pcar].IntX-Car[Pcar].Sec^.Minroad>140) then Car[Ncar].CPUx:=Car[Pcar].intX-120 else
                                                       Car[Ncar].CPUx:=Car[Ncar].intX+120
  end else
  if Car[Ncar].CPUx>AuxSec1^.MaxRoad-80 then Car[Ncar].CPUx:=AuxSec1^.MaxRoad-80 else
  if Car[Ncar].CPUx<AuxSec1^.MinRoad+80 then Car[Ncar].CPUx:=AuxSec1^.MinRoad+80;

 if not Sorpasser and (BanDis[NCar]<4) and
   (Car[Ncar].Speed>Car[Bancar].Speed+20) then Car[NCar].CpuX:=Trunc(Car[BanCar].IntX);

For cnt:=21 to 28 do begin
Dist:=abs(integer(Car[NCar].Sec^.NumSec)-integer(SpecialObj[cnt].Sec^.Numsec));
if Dist>Groad.MaxSec div 2 then Dist:=Groad.Maxsec-Dist;

if (SpecialObj[cnt].Class=1) and
   (SpecialObj[cnt].id>0)    and
   (Car[Ncar].Sec^.NumSec<SpecialObj[Cnt].Sec^.NumSec+2) and
   (Dist<20)(* and (AuxSec1^.turn=0) and (AuxSec2^.turn=0)*)
   then
   begin
   if (SpecialObj[Cnt].X>Car[NCar].X) and (AuxSec1^.turn=0) and (AuxSec2^.turn=0)
                                            then Car[NCar].CpuX:=trunc(SpecialObj[cnt].X)-90
                                            else Car[NCar].CpuX:=trunc(SpecialObj[cnt].X)+90;

   if (SpecialObj[Cnt].X>Car[NCar].X) and (AuxSec1^.turn>0) and (AuxSec2^.turn>0)
                                            then Car[NCar].CpuX:=AuxSec1^.MinRoad+20
                                            else Car[NCar].CpuX:=Trunc(SpecialObj[cnt].x)+90;

   if (SpecialObj[Cnt].X>Car[NCar].X) and (AuxSec1^.turn<0) and (AuxSec2^.turn<0)
                                            then Car[NCar].CpuX:=Trunc(SpecialObj[cnt].x)-90
                                            else Car[NCar].CpuX:=AuxSec1^.MaxRoad-20;

    end;
end;

 inc(Car[Ncar].CpuEfx,(Car[Ncar].CpuX-Car[Ncar].CPUefx) div 5);

 if Car[Ncar].Ahead then Cnt:= ( (Car[Ncar].IntX-Car[Ncar].CPUEfx)*3+Car[Ncar].Angle1) div 2 else
                         Cnt:= (-(Car[Ncar].IntX-Car[Ncar].CPUEfx)*3+Car[Ncar].Angle1) div 2;

 if (Car[Ncar].Sec^.Turn=0) then begin
  if Cnt> 90 then Cnt:= 90 else
  if Cnt<-90 then Cnt:=-90;
 end else begin
  if Cnt> 110 then Cnt:= 110 else
  if Cnt<-110 then Cnt:=-110;
 end;

 if Car[NCar].Ahead then begin
  if Car[Ncar].Reverse then Cnt:=-50*Sgn(Car[Ncar].Angle1) else begin
   if (Car[Ncar].Angle1> 500) then Cnt:= 50;
   if (Car[Ncar].Angle1<-500) then Cnt:=-50;
  end
 end else begin
  if Not Car[Ncar].Reverse then Cnt:=-50*Sgn(Car[Ncar].Angle1) else begin
   if (Car[Ncar].Angle1> 500) then Cnt:= 50;
   if (Car[Ncar].Angle1<-500) then Cnt:=-50;
  end
 end;

 inc(Xtrottle[NCar],(Cnt-Xtrottle[Ncar]) div 2);
 if Start then inc(Car[NCar].Angle1,-Xtrottle[Ncar]);

 if Car[Ncar].Speed<210-Han[Ncar]-TAddHan shl 2 then Ytrottle[Ncar]:=-100 else Ytrottle[Ncar]:=1;

 if Car[Ncar].Trab and (Car[Ncar].Speed>80) then Ytrottle[Ncar]:=1;

 Car[NCar].Ahead:=True;
 AhAn:=(integer(Car[NCar].Sec^.Numsec)-integer(Car[BanCar].Sec^.Numsec));
 if Abs(Ahan)>Groad.MaxSec shr 1 Then Ahan:=-Sgn(Ahan)*(integer(Groad.Maxsec)-abs(AhAn));

 if (Car[BanCar].Speed<10) or (Car[BanCar].Reverse) then begin
  if  Ahan>0 then Car[NCar].Ahead:=False;
 end else begin
  if  Ahan>0 then YTrottle[NCar]:=100;
 end;

 if Ytrottle[NCar]> 100 then Ytrottle[NCar]:= 100;
 if Ytrottle[NCar]<-100 then Ytrottle[NCar]:=-100;

 if not Touch[NCar] and Start then begin
  if Car[NCar].Revs1>1200-Car[NCar].Gear*40-Han[Ncar]*2 then begin
   Touch[NCar]:=True;
   CGear[NCar]:= 1;
  end;
  if (Car[NCar].Revs1<400+Car[NCar].Gear*50) and (Car[NCar].Gear>1) then begin
   Touch[NCar]:=True;
   CGear[NCar]:=-1
  end
 end else begin Touch[NCar]:=false; Cgear[NCar]:=0; end
end;
end;

begin
end.