Uses Crt,Dos,Graphics,General,Sound,Road,Keyb,Perspect,Joys,ConfUnit,CdUnit,CdVars,SelCarUn,NetUnit;

Var SaveRouAva,
    Ntrack,Nmes   :byte;
    Auxi,Qpoints  :word;
    F             :File;
    CurrDirectory :String;
    Wins,GameOver,Selectable,Take1,Flash:boolean;
    Waiter,cnt,angle2   :integer;
    MyTrack       :word;
    Position      :array[1..8] of byte;
    EXcnt1,cnt1   :integer;
    ChiefMess     :array[0..10] of String[40];
    x1,x2,x3:integer;

Procedure PlaceCarsC;
Var Sectors: integer;
begin
 BanDis[1]:=100;
 BanDis[2]:=100;

 For Auxi:=1 to 8 do Car[auxi].Team:=0;

 if CarPl1<4 then Car[1].Team:=1 else Car[1].Team:=2;
 If NumPla=2 then begin if CarPl2<4 then Car[2].Team:=1 else Car[2].Team:=2 end;

if AllCars then Begin
 if NumPla=1 then Begin
  if Car[1].Team=1 then begin
   CopCar:=1;
   BanCar:=8; Car[BanCar].Team:=2;
  end else
  if Car[1].Team=2 then begin
   BanCar:=1;
   Car[2].Team:=1;
   CopCar:=2;
  end
 end else
 if NumPla=2 then Begin
  if (Car[1].Team=1) and (Car[2].Team=1) then begin
   CopCar:=1;
   BanCar:=8; Car[BanCar].Team:=2;
  end else
  if (Car[1].Team=1) and (Car[2].Team=2) then begin
   CopCar:=1;
   BanCar:=2;
  end else
  if (Car[1].Team=2) and (Car[2].Team=1) then begin
   CopCar:=2;
   BanCar:=1;
  end
 end
end else begin
 if NumPla=1 then Begin
  if Car[1].Team=1 then begin
   CopCar:=1;
   BanCar:=2; Car[BanCar].Team:=2;
  end else
  if Car[1].Team=2 then begin
   BanCar:=1;
   Car[2].Team:=1;
   CopCar:=2;
  end
 end else
 if NumPla=2 then Begin
  if (Car[1].Team=1) and (Car[2].Team=1) then Car[2].Team:=2;
  if (Car[1].Team=1) and (Car[2].Team=2) then begin
   BanCar:=2;
   CopCar:=1;
  end else
  if (Car[1].Team=2) and (Car[2].Team=1) then begin
   CopCar:=2;
   BanCar:=1;
  end
 end
end;
end;

Function KeyState2(Num:byte): Boolean;
begin
if Keystate(Num) then begin if Ch[1].st=0 then PlaySample(1,1,64,100,100); Keystate2:=True; waitSil; end else Keystate2:=False;
end;

Procedure VmapbobFreeS(xa,xb,y1,y2,y3,y4,num:integer);
begin
TMapbob(xa,y1,xb,y2,xb,y3,xa,y4,num);
end;

Procedure RotationItem(numbob,x,y:integer);
Var Kx1,Ky1,Aux:integer;
begin
 inc(angle2,Timing div 4); if angle2>359 then Dec(angle2,359);
 Aux:=(GetHy(NumBob) div 2) ;
 Kx1:=(cs[angle2]*GetHx(NumBob) div 256 ) ;
 Ky1:=(sn[angle2]*GetHx(NumBob) div 2560) ;
VMapbobFreeS((x-kx1    ),(x+kx1    ),
             (y+ky1-Aux),(y-ky1-Aux),
             (y+ky1+Aux),(y-ky1+Aux),numbob);
end;

Procedure RotationItem2(numbob,x,y:integer);
Var Kx1,Ky1,Aux:integer;
begin
 inc(angle2,Timing div 4); if angle2>359 then Dec(angle2,359);
 Aux:=(GetHy(NumBob)) ;
 Kx1:=(cs[angle2]*GetHx(NumBob) div 200 ) ;
 Ky1:=(sn[angle2]*GetHx(NumBob) div 2560) ;
VMapbobFreeS((x-kx1    ),(x+kx1    ),
             (y+ky1-Aux),(y-ky1-Aux),
             (y+ky1+Aux),(y-ky1+Aux),numbob);
end;


Procedure PGameOver;
begin

  Lfbob('Pics\GameOver.pcx' ,'Data\GameOver.dat' ,550);

if gamemode=2 then begin
  loadpic('Pics/Chief.pcx',pseg,pofs); loadpal('Pics/BackMenu.pcx',20,255);
  GetFbob(1,0,0,319 shl SVGA,199 shl SVGA);
  resettime;angle:=0;
  clr(0);
end else begin
  loadpic('Pics/RacePan.pcx',pseg,pofs); loadpal('Pics/BackMenu.pcx',20,255);
  GetFbob(1,0,0,319 shl SVGA,199 shl SVGA);
  resettime;angle:=0;
  clr(0);
end;

  repeat
   Fbob(1,0,0);
   inc(angle,Timing div 2); if angle>360 then dec(angle,360);
   RotationItem2(550,160 shl SVGA,100 shl SVGA);
   repeat NextSound until Time>25;

   Auxi:=time;
   Timing :=10 * Auxi div 25;
   resettime;
   scrswap;
  until Keystate2(1) or (keystate2(28) or Keystate2(57));
  Fade(4);
  Clr(0);
  ScrSwap
end;

Procedure Recd;
Begin
inc(Waiter);
if (Waiter>50) then Begin
  Waiter:=0;
  DeviceStatus;
  if Audio and DiscinDrive then begin
   Audio_Disk_info;
   if not Busy then begin InitCD; PlayTrack(MyTrack); end;
   ResetTime;
  end
 end
end;

Procedure NextRound;

var xc,yc,Y,VY,Mag,InfX       :integer;
    Angle,Angle1,Angle2,Angle3:integer;
    Rotate                    :Byte;

begin
 Qpoints:=0;
 For Cnt:=1 to Cround do Qpoints:=Qpoints+Cround div 2+5;

 if Gamemode=2 then Begin
  PlaceCarsC;
  SelectionCar;
 end;

  if (GameMode<>2) and (Cround=0) then SelectionCar;

if CROUND>0 then begin (********* WARNING ************)
                 For cnt:=1 to 2 do LoadCar2(cnt,50+50*cnt,Carname[Car[cnt].Chassis]);
 if allcars then For cnt:=3 to 8 do LoadCar2(cnt,50+50*cnt,Carname[Car[cnt].Chassis]);


if gamemode<>2 then begin
 For cnt:=1 to 8 do Position[cnt]:=cnt;

 For cnt1:=1 to 7 do begin
  For cnt:=cnt1+1 to 8 do begin
   if Car[Position[cnt]].Points>Car[Position[cnt1]].points then swpb(Position[cnt],Position[cnt1]);
  end;
 end;

 loadpic('Pics/RacePan.pcx',pseg,pofs); loadpal('Pics/RacePan.pcx',20,255);

  if GameMode=3 then Synchro(100);

 GetFbob(1,0,0,319 shl SVGA,199 shl SVGA);
 resettime;angle:=0;
 clr(0);
 repeat
 Fbob(1,0,0);
 inc(angle,Timing div 2); if angle>360 then dec(angle,360);

 if gamemode<>3 then begin Maxcars:=2; if AllCars then Maxcars:=8 end else MaxCars:=MaxnetPl;

 (*Maxcars:=2; if AllCars then Maxcars:=8;*)

 for Cnt:=1 to MaxCars do begin
  Text( 60 shl SVGA,(28+19*cnt) shl SVGA,Tostr(cnt,-15)+']'+ids[Position[cnt]],True);
  Text(200 shl SVGA,(28+19*cnt) shl SVGA,Tostr(Car[position[cnt]].Points,-15),True);
  putobj(Position[cnt],0,300,1300,Angle,0,0,160 shl SVGA,((19*cnt)-22) shl SVGA);
 end;

   repeat NextSound until Time>25;
  Auxi:=time;
  Timing :=10 * Auxi div 25;
  resettime;
  scrswap;
  until Keystate2(1) or (keystate2(28) or Keystate2(57));
  Fade(4);
  Clr(0);
  ScrSwap
 end else

 if GameMode=2 then begin
  Lfbob('Pics\Acces.pcx' ,'Data\Position.dat' ,550);
  loadpic('Pics/Chief.pcx',pseg,pofs); loadpal('Pics/BackMenu.pcx',20,255);
  GetFbob(1,0,0,319 shl SVGA,199 shl SVGA);
  resettime;angle:=0;
  clr(0);
  repeat
   Fbob(1,0,0);
   inc(angle,Timing div 2); if angle>360 then dec(angle,360);

   x1:=100;
   x2:=160;
   x3:=220;

   if NumPla=1  then Begin
      if (Car[1].Team=1) then begin X1:=100;X2:=1000;X3:=220;end;
      if (Car[1].Team=2) then begin X2:=100;X1:=1000;X3:=220;end;
   end;
   if NumPla=2  then Begin
      if ((Car[1].Team=1) and (Car[2].Team=2)) or
         ((Car[1].Team=2) and (Car[2].Team=1)) then Begin X1:=100;X2:=220; X3:=1000; end;
      if ((Car[1].Team=1) and (Car[2].Team=1)) then begin X1:=100;X2:=160; X3:= 220; end;
   end;

   RotationItem(557+Car[1].Team      ,x1 shl SVGA,85 shl SVGA);
   putobj(     1,0,300,1300,Angle,0,0,x1 shl SVGA,55 shl SVGA);
   Text  (                            (x1-10) shl SVGA,120 shl SVGA,Tostr(Car[1].Points,-15),true);

   RotationItem(557+Car[2].Team      ,x2 shl SVGA,85 shl SVGA);
   putobj(     2,0,300,1300,Angle,0,0,x2 shl SVGA,55 shl SVGA);
   Text  (                            (x2-10) shl SVGA,120 shl SVGA,Tostr(Car[2].Points,-15),true);

   RotationItem(557+Car[Bancar].Team ,x3 shl SVGA,85 shl SVGA);
   putobj(BanCar,0,300,1300,Angle,0,0,x3 shl SVGA,55 shl SVGA);
   Text  (                            (x3-10) shl SVGA,120 shl SVGA,Tostr(Car[BanCar].Points,-15),true);


   Text(100 shl SVGA ,50 shl SVGA,'ROUND '+tostr(Cround,-15)+' RESULTS',true);

   repeat NextSound until Time>25;
   Auxi:=time;
   Timing :=10 * Auxi div 25;
   resettime;
   scrswap;
  until Keystate2(1) or (keystate2(28) or Keystate2(57));
  Fade(4);
  Clr(0);
  ScrSwap
 end;

 GameOver:=False;
 if Gamemode=1 then begin
  if AllCars then begin For cnt:=1 to 8 do if Car[Cnt].Points>0 then GameOver:=True end
             else begin For cnt:=1 to 2 do if Car[Cnt].Points>0 then GameOver:=True end;
 end else
 if Gamemode=0 then begin
  if NumPla=1 then if (Car[1].Points<Qpoints) then GameOver:=True;
  if NumPla=2 then if (Car[1].Points<Qpoints) and (Car[2].Points<Qpoints) then GameOver:=True;
  if (NumPla=2) and Not AllCars and (Cround>=RouAVA) and (Cround>0) then GameOver:=True;
 end else
 if GameMode=2 then begin
  if NumPla=1 then begin
   if (Car[1].Team=1) and     (Safe=0) and (Cround>0) then GameOver:=True;
   if (Car[1].Team=2) and not (Safe=0) and (Cround>0) then GameOver:=True;
  end;
  if NumPla=2 then begin
   if ((Car[1].Team=1) and (Car[2].Team=1)) and (Safe=0) and (Cround>0) then GameOver:=True;
   if (Car[1].Team<>Car[2].Team) and (Cround>0) and (Cround>=RouAva) then GameOver:=True;
  end
 end else
 if Gamemode=3 then begin
  if Cround=7 then Gameover:=True;
 end;

if GameOver then exit;

if (Cround=7) and (gamemode<>1) then begin
 if Gamemode=2 then begin
  if Numpla=1 then Begin WinCar:=Car[1].chassis;Auxi:=1; end
              else
   if (Car[1].Points>Car[2].Points) then Begin Auxi:=1; WinCar:=Car[1].Chassis end
                                    else Begin Auxi:=2; Wincar:=Car[2].Chassis end;

  LastWinner:=(difficulty-1)*3+1+Car[Auxi].team;
  Winners[LastWinner]:=ids[Auxi];
  Wincars[LastWinner]:=Wincar;
  Wins:=true;
 end else
 if (Gamemode=0) then begin
  Wincar:=Position[1];
  LastWinner:=(difficulty-1)*3+1;
  Winners[LastWinner]:=ids[Wincar];
  Wincars[LastWinner]:=Wincar;
  if Wincar<NumPla+1 then Wins:=True else GameOver:=True;
 end
end;

if Wins or GameOver then exit;

end; (************ WARNING **************)

Selectable:=True;

 Lbob('Pics/Hidernd.pcx','Data/Hidernd.dat',30);
 LoadLogo(MaxBobs-1);
 Loadpic('Pics/BackTrac.pcx',pseg,pofs); loadpal('Pics/BackTrac.pcx',20,255);
 PlaceLogo;
 Getfbob(MaxBobs,0,0,319 shl SVGA,199 shl SVGA); CLR(0);Lbob('Pics\Acces2.pcx','Data\Acces2.Dat',20);

if (GameMode=0) or (GameMode=3) then begin
 inc(CRound);
 if Cround<1 then Cround:=1;
 NTrack:=Cround; if Cround>RouAva then RouAva:=Cround;
 ResetTime; Y:=0; Vy:=0;
 Qpoints:=0;
 For Cnt:=1 to Cround do Qpoints:=Qpoints+Cround div 2+5;

 repeat
 Fbob(MaxBobs,0,0);

 if Cround<1 then Cround:=1  else
 if Cround>7 then Cround:=7;
 if CRound=1 then begin Xc:= 79;Yc:=73  end else
 if CRound=2 then begin Xc:=138;Yc:=73  end else
 if CRound=3 then begin Xc:=197;Yc:=73  end else
 if CRound=4 then begin Xc:=256;Yc:=73  end else
 if CRound=5 then begin Xc:=107;Yc:=128 end else
 if CRound=6 then begin Xc:=166;Yc:=128 end else
 if CRound=7 then begin Xc:=225;Yc:=128 end;

 repeat until not keystate(75) and not keystate(77) and not keystate(80) and not keystate(72);

 For Cnt:=RouAva+1 to 7 do begin
  if Cnt=1 then Bob(30, 78 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=2 then Bob(30,137 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=3 then Bob(30,196 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=4 then Bob(30,255 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=5 then Bob(30,106 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=6 then Bob(30,165 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=7 then Bob(30,224 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
 end;

 For Cnt:=1 to Cround-1 do begin
  if Cnt=1 then Bob(31, 79 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=2 then Bob(31,138 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=3 then Bob(31,197 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=4 then Bob(31,256 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=5 then Bob(31,107 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=6 then Bob(31,166 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=7 then Bob(31,225 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
 end;

 Bob(20,Xc shl SVGA-GetHx(20) shr 1,Yc shl SVGA);
 Bob(21,Xc shl SVGA-GetHx(21) shr 1,(Yc-30+Y) shl SVGA);
 inc(y); inc(y,vy); inc(vy); if y>20 then vy:=-8;
 repeat NextSound until Time>25;
 Auxi:=time;
 Recd;
 Timing :=10 * Auxi div 25;

  if DemoRel=1 then begin
   if Cround<>1 then Text(70 shl SVGA,80 shl SVGA,' Not Available On Demo',True);
   Selectable:=not (Cround<>1);
  end;

 ResetTime;
 scrswap;
 until Selectable and (keystate2(28) or Keystate2(57));
end else
 (******************************* END GAMEMODE 0 **************************************)
if (GameMode=1) then begin
 Cround:=1;
 if Cround<1 then Cround:=1;
 NTrack:=Cround; if Cround>RouAva then RouAva:=Cround;
 ResetTime; Y:=0; Vy:=0;
 repeat
 Fbob(MaxBobs,0,0);

 if Cround<1 then Cround:=1  else
 if Cround>7 then Cround:=7;
 if CRound=1 then begin Xc:= 79;Yc:=73  end else
 if CRound=2 then begin Xc:=138;Yc:=73  end else
 if CRound=3 then begin Xc:=197;Yc:=73  end else
 if CRound=4 then begin Xc:=256;Yc:=73  end else
 if CRound=5 then begin Xc:=107;Yc:=128 end else
 if CRound=6 then begin Xc:=166;Yc:=128 end else
 if CRound=7 then begin Xc:=225;Yc:=128 end;

 if keystate2(75) then dec(Cround  ) else
 if keystate2(77) then inc(Cround  ) else
 if keystate2(80) and (Cround<5) then inc(Cround,4) else
 if keystate2(72) and (Cround>4) then dec(Cround,4);
 if Cround>RouAva then Cround:=RouAva;

 repeat until not keystate(75) and not keystate(77) and not keystate(80) and not keystate(72);
 For Cnt:=RouAva+1 to 7 do begin
  if Cnt=1 then Bob(30, 78 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=2 then Bob(30,137 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=3 then Bob(30,196 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=4 then Bob(30,255 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=5 then Bob(30,106 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=6 then Bob(30,165 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=7 then Bob(30,224 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
 end;

 Bob(20,Xc shl SVGA-GetHx(20) shr 1,Yc shl SVGA);
 Bob(21,Xc shl SVGA-GetHx(21) shr 1,(Yc-30+Y) shl SVGA);
 inc(y); inc(y,vy); inc(vy); if y>20 then vy:=-8;
 repeat NextSound until Time>25;
 Auxi:=time;
 Recd;
 Timing :=10 * Auxi div 25;

  if DemoRel=1 then begin
   if Cround<>1 then Text(70 shl SVGA,80 shl SVGA,' Not Available On Demo',True);
   Selectable:=not (Cround<>1);
  end;

 ResetTime;
 scrswap;
 until Selectable and (keystate2(28) or Keystate2(57));
end else
 (******************************* END GAMEMODE 1 **************************************)
 if GameMode=2 then begin
 inc(CRound);
 if Cround<1 then Cround:=1;
 NTrack:=Cround; if Cround>RouAva then RouAva:=Cround;
 ResetTime; Y:=0; Vy:=0;
 repeat
 Fbob(MaxBobs,0,0);

 if Cround<1 then Cround:=1  else
 if Cround>7 then Cround:=7;
 if CRound=1 then begin Xc:= 79;Yc:=73  end else
 if CRound=2 then begin Xc:=138;Yc:=73  end else
 if CRound=3 then begin Xc:=197;Yc:=73  end else
 if CRound=4 then begin Xc:=256;Yc:=73  end else
 if CRound=5 then begin Xc:=107;Yc:=128 end else
 if CRound=6 then begin Xc:=166;Yc:=128 end else
 if CRound=7 then begin Xc:=225;Yc:=128 end;

 For Cnt:=RouAva+1 to 7 do begin
  if Cnt=1 then Bob(30, 78 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=2 then Bob(30,137 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=3 then Bob(30,196 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=4 then Bob(30,255 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=5 then Bob(30,106 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=6 then Bob(30,165 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=7 then Bob(30,224 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
 end;

 For Cnt:=1 to Cround-1 do begin
  if Cnt=1 then Bob(31, 79 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=2 then Bob(31,138 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=3 then Bob(31,197 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=4 then Bob(31,256 shl SVGA+SVGA*2-GetHx(30) shr 1, 76 shl SVGA);
  if Cnt=5 then Bob(31,107 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=6 then Bob(31,166 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
  if Cnt=7 then Bob(31,225 shl SVGA+SVGA*2-GetHx(30) shr 1,131 shl SVGA);
 end;

 Bob(20,Xc shl SVGA-GetHx(20) shr 1,Yc shl SVGA);
 Bob(21,Xc shl SVGA-GetHx(21) shr 1,(Yc-30+Y) shl SVGA);
 inc(y); inc(y,vy); inc(vy); if y>20 then vy:=-8;
 repeat NextSound until Time>25;
 Auxi:=time;
 Recd;
 Timing :=10 * Auxi div 25;

  if DemoRel=1 then begin
   if Cround<>1 then Text(70 shl SVGA,80 shl SVGA,' Not Available On Demo',True);
   Selectable:=not (Cround<>1);
  end;

 ResetTime;
 scrswap;
 until Selectable and (keystate2(28) or Keystate2(57));
end;
 (******************************* END GAMEMODE 2 **************************************)

 Ntrack:=CRound;

 Mag:=34; Angle:=225;Rotate:=0;infX:=320;
 LoadRec(NTrack);RecTimes:=TimeToStr(RecTime);
 LoadLogo(MaxBobs-1);
 Loadpic('Pics/BackMenu.pcx',pseg,pofs); loadpal('Pics/BackMenu.pcx',20,255);
 PlaceLogo;
 Getfbob(MaxBobs,0,0,319 shl SVGA,199 shl SVGA);clr(0);
 Lfbob('Pics\Infotr'+tostr(NTrack,0)+'.pcx','Data\infotr1.Dat',20);
 ResetTime;
 repeat
 Fbob(MaxBobs,0,0);
 if Mag<53 then inc(Mag,Timing div 10) else Mag:=53;

 if Xc<115-Timing shr 2 then inc(xc,Timing shr 2) else if Xc>115+Timing shr 2 then dec(xc,Timing shr 2)
 else Xc:=115;
 if Yc< 90-Timing shr 2 then inc(yc,Timing shr 2) else if Yc> 90+Timing shr 2 then dec(yc,Timing shr 2)
 else Yc:=90;

 inc(Angle,Timing shr 1); if Angle>360 then begin inc(Rotate); dec(Angle,360) end;

 if (Rotate>0) and (Angle>225) then Begin
 Rotate:=2;
 Angle:=225;
 end;

 Angle1:=(Angle+ 90) mod 360; if Angle1<0 then inc(Angle1,360);
 Angle2:=(Angle+180) mod 360; if Angle2<0 then inc(Angle2,360);
 Angle3:=(Angle+270) mod 360; if Angle3<0 then inc(Angle3,360);

  Polygon((xc+5)shl SVGA               +Cs[Angle ]*Mag div 128 shl SVGA,
          (yc+5)shl SVGA+GetHy(20)shr 1+Sn[Angle ]*Mag div 128 shl SVGA,
          (xc+5)shl SVGA               +Cs[Angle1]*Mag div 128 shl SVGA,
          (yc+5)shl SVGA+GetHy(20)shr 1+Sn[Angle1]*Mag div 128 shl SVGA,
          (xc+5)shl SVGA               +Cs[Angle2]*Mag div 128 shl SVGA,
          (yc+5)shl SVGA+GetHy(20)shr 1+Sn[Angle2]*Mag div 128 shl SVGA,
          (xc+5)shl SVGA               +Cs[Angle3]*Mag div 128 shl SVGA,
          (yc+5)shl SVGA+GetHy(20)shr 1+Sn[Angle3]*Mag div 128 shl SVGA,112);

  if infX>160 then dec(Infx,(Infx-152)*Timing div 50) else infX:=160;

  Bar((InfX+5) shl SVGA          ,(Yc+5) shl SVGA,
      (Infx+5) shl SVGA+GetHx(21),(Yc+5) shl SVGA+GetHy(21),112);

  FBob(21,InfX Shl SVGA,Yc shl SVGA);

  if (Rotate>0) and (Angle=225) then Fbob(20,xc shl SVGA-GetHx(20) Shr 1,Yc shl SVGA) else

  MapBob (xc shl SVGA               +Cs[Angle ]*Mag div 128 shl SVGA,
          yc shl SVGA+GetHy(20)shr 1+Sn[Angle ]*Mag div 128 shl SVGA,
          xc shl SVGA               +Cs[Angle1]*Mag div 128 shl SVGA,
          yc shl SVGA+GetHy(20)shr 1+Sn[Angle1]*Mag div 128 shl SVGA,
          xc shl SVGA               +Cs[Angle2]*Mag div 128 shl SVGA,
          yc shl SVGA+GetHy(20)shr 1+Sn[Angle2]*Mag div 128 shl SVGA,
          xc shl SVGA               +Cs[Angle3]*Mag div 128 shl SVGA,
          yc shl SVGA+GetHy(20)shr 1+Sn[Angle3]*Mag div 128 shl SVGA,20);


 Text( 75 shl SVGA,180 shl SVGA,'Track Record:'+RecTimes+' '+RecId,true);
 Bar (186 shl SVGA,188 shl SVGA,186 shl SVGA+SVGA,188 shl SVGA+SVGA,78);
 Bar (202 shl SVGA,188 Shl SVGA,202 shl SVGA+SVGA,188 shl SVGA+SVGA,78);
 if Gamemode<>2 then if Qpoints>0 then Text(78 shl SVGA,70 shl SVGA,Tostr(QPoints,-15)+' Points To Qualify',true);
 repeat NextSound until Time>25;
 Auxi:=time;
 REcd;
 Timing :=10 * Auxi div 25;
 ResetTime;
 scrswap;
 until (keypush>0);

fade(4); clr(0); scrswap;

 if gamemode=2 then begin
  clipgraph(0,0,318 shl SVGA,198 shl SVGA-SVGA);
  Mag:=0;
(*  Cround:=1;(*/////////////////////////////////////////////*)
  loadpic('Pics/NewsL.pcx',pseg,pofs);
  GetFbob(101,0,0,240,146);
  loadpic('Pics/News.pcx',pseg,pofs); loadpal('Pics/News.pcx',20,255);
  GetFbob(1,0,0,319 shl SVGA,199 shl SVGA);
  Lfbob('Pics\Photos1.pcx','Data\Photos.Dat',11);
  Lfbob('Pics\Photos2.pcx','Data\Photos.Dat',17);
  Lfbob('Pics\TNew1.pcx'  ,'Data\tNew.Dat'  ,31);
  Lfbob('Pics\TNew2.pcx'  ,'Data\tNew.Dat'  ,36);
  Fbob(1,0,0);
  if NumPla=1 then begin
   if CarPl1<4 then Fbob(10+Cround,19 shl SVGA-SVGA shl 1,88 shl SVGA+SVGA shl 1)
               else Fbob( 7+Carpl1,19 shl SVGA-SVGA shl 1,88 shl SVGA+SVGA shl 1);
  end else
  if NumPla=2 then begin
   if (CarPl1<4) and (CarPl2<4) then Fbob(10+Cround,19 shl SVGA-SVGA shl 1,88 shl SVGA+SVGA shl 1) else
   if (CarPl1<4) and (CarPl2>3) then Fbob( 7+Carpl2,19 shl SVGA-SVGA shl 1,88 shl SVGA+SVGA shl 1) else
   if (CarPl1>3) and (CarPl2<4) then Fbob( 7+Carpl1,19 shl SVGA-SVGA shl 1,88 shl SVGA+SVGA shl 1);
  end;

  Fbob(30+Cround,0,43 shl SVGA);
  GetFbob(100,0,0,319 shl SVGA,199 shl SVGA);
  LoadPic('Pics/Chief.Pcx',Pseg,Pofs);
  LoadPal('Pics/Chief.Pcx',20,255);
  GetFbob(1,0,0,319 shl SVGA,199 shl SVGA);
  LBob('Pics/ChiefSpr.PCX','Data/ChiefSpr.Dat',2);
  Angle:=185; cnt:=0;cnt1:=0;Timing:=0; Resettime;Take1:=False;

   if NumPla=1 then begin
    if Car[1].Team=1 then Nmes:=Random(4)+0;
    if Car[1].Team=2 then Nmes:=Random(4)+4;
   end else begin
    if Car[1].Team=2 then Nmes:=Random(4)+0;
   end;

  repeat
   Fbob(1,0,0);
   if Excnt1<>Cnt1 then cnt:=0;
   Excnt1:=Cnt1;
   Bob(2,119 shl SVGA,85 shl SVGA);
   if cnt1=0 then begin
    Bob(3,199 shl SVGA,147 shl SVGA);
    inc(Cnt); if cnt>20 then inc(cnt1);
   end else
   if cnt1=1 then begin
    inc(cnt);
    Bob(3,199 shl SVGA,147 shl SVGA);
    if cnt>10 then Bob(5,161 shl SVGA,95 shl SVGA);
    if cnt>20 then begin inc(Cnt1); cnt:=0; end;
   end else
   if cnt1=2 then begin
    inc(Cnt);
    if Cnt<10 then Bob(3,199 shl SVGA,142 shl SVGA)
    else Bob(3,199 shl SVGA,147 shl SVGA);
    if Cnt>40 then Begin inc(Cnt1); cnt:=0; end;
   end;
    if (Cnt1=2) then Bob(4,164 shl SVGA,111 shl SVGA);

   if Cnt1>2 then Cnt1:=0;

   if Take1 then begin
    Bob(3,199 shl SVGA,147 shl SVGA);
    if Mag<178 then begin
     inc(Angle,Timing);
     Angle :=(Angle+  0) mod 360; if Angle <0 then inc(Angle ,360);
     Angle1:=(Angle+110) mod 360; if Angle1<0 then inc(Angle1,360);
     Angle2:=(Angle+180) mod 360; if Angle2<0 then inc(Angle2,360);
     Angle3:=(Angle+290) mod 360; if Angle3<0 then inc(Angle3,360);
     inc(Mag,Timing div 2);
     xc:=160;Yc:=100;
     MapBob (xc shl SVGA+Cs[Angle ]*Mag div 128 shl SVGA,
             yc shl SVGA+Sn[Angle ]*Mag div 128 shl SVGA,
             xc shl SVGA+Cs[Angle1]*Mag div 128 shl SVGA,
             yc shl SVGA+Sn[Angle1]*Mag div 128 shl SVGA,
             xc shl SVGA+Cs[Angle2]*Mag div 128 shl SVGA,
             yc shl SVGA+Sn[Angle2]*Mag div 128 shl SVGA,
             xc shl SVGA+Cs[Angle3]*Mag div 128 shl SVGA,
             yc shl SVGA+Sn[Angle3]*Mag div 128 shl SVGA,101);
    end else begin
     clr(0);
     Fbob(100,0,0);
     Mag:=178; Angle:=215;
     Angle :=(Angle+  0) mod 360; if Angle <0 then inc(Angle ,360);
     Angle1:=(Angle+110) mod 360; if Angle1<0 then inc(Angle1,360);
     Angle2:=(Angle+180) mod 360; if Angle2<0 then inc(Angle2,360);
     Angle3:=(Angle+290) mod 360; if Angle3<0 then inc(Angle3,360);
    end;

   end else begin
     Text(25 shl SVGA,50 shl SVGA,ChiefMess[NMes],True);
   end;
   ScrSwap;
   repeat NextSound until Time>25;
   Auxi:=time;
   Timing :=10 * Auxi div 25;
   resettime;
   if Not Take1 then begin
    Take1:=(Keystate2(1) or keystate2(28) or Keystate2(57));
    if Take1 then Repeat until Not (Keystate(1) or keystate(28) or Keystate(57));
   end;
  until (Keystate2(1) or keystate2(28) or Keystate2(57)) and Take1;
  Fade(4);
  Clr(0);
  ScrSwap;
 end;

end;

begin
GetDir(0,CurrDirectory);
chdir(CurrDirectory);

ChiefMess[0]:='I Have a Hard Job for you, Boy....';
ChiefMess[1]:='         Look Here man ....';
ChiefMess[2]:='         Look Here man ....';
ChiefMess[3]:='         Look Here man ....';

ChiefMess[4]:='I Have a Hard Job for you, Boy....';
ChiefMess[5]:='         Look Here man ....';
ChiefMess[6]:='         Look Here man ....';
ChiefMess[7]:='         Look Here man ....';


InitCD;
delay(1000);

Initgraph(3000);
clipgraph(0,0,319 shl SVGA,199 shl SVGA+SVGA*2);

Initkeyb;
Initpros;
InitMisc;

LoadRace;
LoadStatus;
LoadSlot;
LoadConfig;
LoadWinner;

if MaxNetPl<1 then MaxNetPl:=1;
Solo:=MaxNetPl=1;

SoundOn:=False;

initsound(512);
SoundOn:=SbOn;
Loadsample(1 ,'Samples\CDClick.Raw');

initfont;
Loadfont('Pics\Font.pcx');

Mytrack:=2+1;
PlayTrack(MyTrack);

Randomize;

SaveRouAva:=RouAva;

NextRound;

if Gamemode=3 then Rouava:=SaveRouAva;

if not wins then begin

 if GameOver then pGameOver;
 if GameMode=2 then SelectionCar;

 SaveRace;
 SaveStatus;
 SaveConfig;
 FadeAudio(100);

 StopAudio;

if GameOver then begin
(********* EXIT *************)
  assign(F,'password.WWW');
  rewrite(f,1);
  writefile('Menu',8,f);
  close(f);
(****************************)
end else begin
(********* EXIT *************)
  assign(F,'password.WWW');
  rewrite(f,1);
  writefile('Game',8,f);
  close(f);
(****************************)
end;

end else begin
 SaveWinner;
(********* EXIT *************)
  assign(F,'password.WWW');
  rewrite(f,1);
  writefile('Final',8,f);
  close(f);
(****************************)
end;

 KillGraph;
 KillFont;
 KillKeyb;
 KillSound;

end.