Unit SelCarUn;

interface
Procedure SelectionCar;
Procedure PlaceCarsNet;
Procedure PlaceCarsRace;
Procedure PlaceCarsChase;
implementation

uses Crt,Road,Pilunit,NetUnit,graphics;

Var
AuxSec:Puntsec;
Auxi  :integer;
Cnt   :integer;

Procedure SelectionCar;
var
Auxi,CarPro,CurPla,Cnt:integer;
begin

if (GameMode=0) or (Gamemode=1) then begin
 For CurPla:=1 to 8 do Car[CurPla].Chassis:=0;
 Car[1].Chassis:=CarPl1;
 if NumPla=2 then begin Car[2].Chassis:=CarPl2; Auxi:=3; end else Auxi:=2;
 CarPro:=0;
 For CurPla:= Auxi to 8 do begin
  CarPro:=Random(10);
  repeat
   inc(CarPro);if Carpro>10 then Carpro:=1;
   if (CarPro<>Car[1].Chassis) and (CarPro<>Car[2].Chassis) and
      (CarPro<>Car[3].Chassis) and (CarPro<>Car[4].Chassis) and
      (CarPro<>Car[5].Chassis) and (CarPro<>Car[6].Chassis) and
      (CarPro<>Car[7].Chassis) and (CarPro<>Car[8].Chassis) then Car[CurPla].Chassis:=CarPro;
  until Car[CurPla].Chassis<>0;
 end
end else

if GameMode=2 then begin
 For CurPla:=1 to 8 do Car[CurPla].Chassis:=0;

 if (NumPla=1) and (Car[1].Team=1)                     then CarBandit:=Cround+3;
 if (Numpla=1) and (Car[1].Team=2)                     then Begin CarBandit:=CarPl1; Car[2].Chassis:=Cround mod 3+1;end;
 if (NumPla=2) and (Car[1].Team=1) and (Car[2].Team=1) then CarBandit:=Cround+3;
 if (NumPla=2) and (Car[1].Team=2) and (Car[2].Team=1) then CarBandit:=CarPl1;
 if (NumPla=2) and (Car[1].Team=1) and (Car[2].Team=2) then CarBandit:=CarPl2;

 Car[1].Chassis:=CarPl1;
 if NumPla=2 then Car[2].Chassis:=CarPl2;
 Car[BanCar].Chassis:=CarBandit;

 For CurPla:= Numpla+1 to 8 do begin
 if (Car[CurPla].Team=0) then begin
  CarPro:=3+Random(7);
  repeat
   inc(CarPro);if CarPro>10 then CarPro:=4;
   if (CarPro<>Car[1].Chassis) and (CarPro<>Car[2].Chassis) and (CarPro<>CarBandit) and
      (CarPro<>Car[3].Chassis) and (CarPro<>Car[4].Chassis) and
      (CarPro<>Car[5].Chassis) and (CarPro<>Car[6].Chassis) and
      (CarPro<>Car[7].Chassis) and (CarPro<>Car[8].Chassis) then Car[CurPla].Chassis:=CarPro;
  until Car[CurPla].Chassis<>0;
  end;
 end;
end else

if GameMode=3 then begin
 For CurPla:=1+MaxNetPl to 8 do Car[curpla].chassis:=0;
 For CurPla:=1+MaxNetPl to 8 do begin
  CarPro:=0;
  repeat
   inc(CarPro);
   if (CarPro<>Car[1].Chassis) and (CarPro<>Car[2].Chassis) and
      (CarPro<>Car[3].Chassis) and (CarPro<>Car[4].Chassis) and
      (CarPro<>Car[5].Chassis) and (CarPro<>Car[6].Chassis) and
      (CarPro<>Car[7].Chassis) and (CarPro<>Car[8].Chassis) then Car[CurPla].Chassis:=CarPro;
  until Car[CurPla].Chassis<>0;
 end
end;

end;

Procedure PlaceCarsRace;
begin
 AuxSec:=Groad.curs;
 for auxi:=0 to 0 do Auxsec:=Auxsec^.next;
 PlaceCar(0,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to 4 do Auxsec:=Auxsec^.next;
 PlaceCar(0,2(*N*),Auxsec(*PSec*), 100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));

if Allcars then begin
 AuxSec:=Groad.curs;
 for auxi:=0 to 6 do Auxsec:=Auxsec^.next;
 PlaceCar(0,3(*N*),Auxsec(*PSec*),  -100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to 8 do Auxsec:=Auxsec^.next;
 PlaceCar(0,4(*N*),Auxsec(*PSec*),   100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to 12 do Auxsec:=Auxsec^.next;
 PlaceCar(0,5(*N*),Auxsec(*PSec*),  -100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to 16 do Auxsec:=Auxsec^.next;
 PlaceCar(0,6(*N*),Auxsec(*PSec*),   100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to 20 do Auxsec:=Auxsec^.next;
 PlaceCar(0,7(*N*),Auxsec(*PSec*),  -100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to 24 do Auxsec:=Auxsec^.next;
 PlaceCar(0,8(*N*),Auxsec(*PSec*),   100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
end;

for Auxi:=1 to 8 do begin
Lap[auxi]:=1;
Car[auxi].Team:=0;
Car[Auxi].PilotType:=0;
end;
BanCar:=1;CopCar:=2;
end;

Procedure PlaceCarsNet;
var cnt,xcnt:integer;
begin
 xcnt:=-100;
 For cnt:=1 to MaxNetPl do begin
 AuxSec:=Groad.curs;
 for auxi:=0 to cnt*4-4 do Auxsec:=Auxsec^.next;
 PlaceCar(0,cnt(*N*),Auxsec(*PSec*),xcnt(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
 xcnt:=-xcnt;
 end;

 For Auxi:=1 to 8 do Lap[auxi]:=1;
 For Auxi:=1 to 8 do Car[auxi].Team:=0;
 For Auxi:=1 to 8 do begin
  if Auxi>MaxNetPl then Car[Auxi].PilotType:=0 else Car[Auxi].PilotType:=1;
 end;
 BanCar:=7;CopCar:=8;
end;


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

 Sectors:=Groad.MaxSec div 10;
 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;
   AuxSec:=Groad.curs;
   PlaceCar(1,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   for auxi:=0 to Sectors*1-20 do Auxsec:=Auxsec^.next;
   PlaceCar(4,2(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),50(*S*));
   AuxSec:=Groad.curs;
   for auxi:=0 to 2 do Auxsec:=Auxsec^.last;
   PlaceCar(0,BanCar,Auxsec(*PSec*),100(*X*),0(*Z*),40(*Y*),0(*A*),100(*S*));
  end else
  if Car[1].Team=2 then begin
   BanCar:=1;
   AuxSec:=Groad.curs;
   for auxi:=0 to 5 do Auxsec:=Auxsec^.next;
   PlaceCar(1,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   PlaceCar(5,2(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   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;
   AuxSec:=Groad.curs;
   PlaceCar(1,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   for auxi:=0 to 2 do Auxsec:=Auxsec^.next;
   PlaceCar(1,2(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   for auxi:=0 to 2 do Auxsec:=Auxsec^.last;
   PlaceCar(0,BanCar,Auxsec(*PSec*),100(*X*),0(*Z*),40(*Y*),0(*A*),100(*S*));
  end else
  if (Car[1].Team=1) and (Car[2].Team=2) then begin
   CopCar:=1;
   BanCar:=2;
   AuxSec:=Groad.curs;
   PlaceCar(1,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   for auxi:=0 to 5 do Auxsec:=Auxsec^.next;
   PlaceCar(1,2(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
  end else
  if (Car[1].Team=2) and (Car[2].Team=1) then begin
   CopCar:=2;
   BanCar:=1;
   AuxSec:=Groad.curs;
   for auxi:=0 to 5 do Auxsec:=Auxsec^.next;
   PlaceCar(1,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   PlaceCar(1,2(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
  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;
   AuxSec:=Groad.curs;
   PlaceCar(1,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   for auxi:=0 to 2 do Auxsec:=Auxsec^.Last;
   PlaceCar(0,BanCar(*N*),Auxsec(*PSec*),100(*X*),0(*Z*),40(*Y*),0(*A*),100(*S*));
  end else
  if Car[1].Team=2 then begin
   BanCar:=1;
   Car[2].Team:=1;
   CopCar:=2;
   AuxSec:=Groad.curs;
   for auxi:=0 to 5 do Auxsec:=Auxsec^.next;
   PlaceCar(1,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   PlaceCar(5,2(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
  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;
   AuxSec:=Groad.curs;
   PlaceCar(1,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   for auxi:=0 to 5 do Auxsec:=Auxsec^.next;
   PlaceCar(1,2(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
  end else
  if (Car[1].Team=2) and (Car[2].Team=1) then begin
   CopCar:=2;
   BanCar:=1;
   AuxSec:=Groad.curs;
   for auxi:=0 to 5 do Auxsec:=Auxsec^.next;
   PlaceCar(1,1(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
   AuxSec:=Groad.curs;
   PlaceCar(1,2(*N*),Auxsec(*PSec*),-100(*X*),0(*Z*),40(*Y*),0(*A*),0(*S*));
  end
 end
end;

if AllCars then begin
 AuxSec:=Groad.curs;
 for auxi:=0 to Sectors*2-20 do Auxsec:=Auxsec^.next;
 if BanCar<>3 then PlaceCar(4,3(*N*),Auxsec(*PSec*),  -100(*X*),0(*Z*),40(*Y*),0(*A*),50(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to Sectors*3-20  do Auxsec:=Auxsec^.next;
 if BanCar<>4 then PlaceCar(4,4(*N*),Auxsec(*PSec*),   100(*X*),0(*Z*),40(*Y*),0(*A*),50(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to Sectors*4-20  do Auxsec:=Auxsec^.next;
 if BanCar<>5 then PlaceCar(4,5(*N*),Auxsec(*PSec*),  -100(*X*),0(*Z*),40(*Y*),0(*A*),50(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to Sectors*5-20  do Auxsec:=Auxsec^.next;
 if BanCar<>6 then PlaceCar(4,6(*N*),Auxsec(*PSec*),   100(*X*),0(*Z*),40(*Y*),0(*A*),50(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to Sectors*6-20  do Auxsec:=Auxsec^.next;
 if BanCar<>7 then PlaceCar(4,7(*N*),Auxsec(*PSec*),  -100(*X*),0(*Z*),40(*Y*),0(*A*),50(*S*));
 AuxSec:=Groad.curs;
 for auxi:=0 to Sectors*7-20  do Auxsec:=Auxsec^.next;
 if BanCar<>8 then PlaceCar(4,8(*N*),Auxsec(*PSec*),   100(*X*),0(*Z*),40(*Y*),0(*A*),50(*S*));
 for Cnt:=3 to 8 do Lap[Cnt]:=1;
end;

end;


 (*
LoadCar( 1,100,Carname[CarPl1]);

if AllCars then begin
 auxi:=1;
 repeat inc(auxi);if auxi>10 then auxi:=1;
 until (auxi<>Carpl1) and (auxi<>Carpl2) and ((Auxi<>CarBandit) or (GameMode<>2));
 LoadCar(3,200,Carname[auxi]);
 repeat inc(auxi);if auxi>10 then auxi:=1;
 until (auxi<>Carpl1) and (auxi<>Carpl2) and ((Auxi<>CarBandit) or (GameMode<>2));
 LoadCar(4,250,Carname[auxi]);
 repeat inc(auxi);if auxi>10 then auxi:=1;
 until (auxi<>Carpl1) and (auxi<>Carpl2) and ((Auxi<>CarBandit) or (GameMode<>2));
 LoadCar(5,300,Carname[auxi]);
 repeat inc(auxi);if auxi>10 then auxi:=1;
 until (auxi<>Carpl1) and (auxi<>Carpl2) and ((Auxi<>CarBandit) or (GameMode<>2));
 LoadCar(6,350,Carname[auxi]);
 repeat inc(auxi);if auxi>10 then auxi:=1;
 until (auxi<>Carpl1) and (auxi<>Carpl2) and ((Auxi<>CarBandit) or (GameMode<>2));
 LoadCar(7,400,Carname[auxi]);
 repeat inc(auxi);if auxi>10 then auxi:=1;
 until (auxi<>Carpl1) and (auxi<>Carpl2) and ((Auxi<>CarBandit) or (GameMode<>2));
 if BanCar=8 then LoadCar( 8,450,Carname[CarBandit]) else
                  LoadCar( 8,450,Carname[auxi])
end;

if Numpla=2 then LoadCar( 2,150,Carname[CarPl2]) else begin
 if GameMode<2 then begin
  repeat inc(auxi);if auxi>10 then auxi:=1;
  until (auxi<>Carpl1) and (auxi<>Carpl2);
  LoadCar(2,150,Carname[auxi]);
 end else
 if Gamemode=2 then begin
  if BanCar=2      then LoadCar(2,150,Carname[CarBandit]) else
  if Car[2].Team=1 then LoadCar(2,150,Carname[Random(3)+1]) else begin
                         repeat inc(auxi);if auxi>10 then auxi:=1;
                         until (auxi<>Carpl1) and (auxi<>Carpl2) and (Auxi<>CarBandit);
                         LoadCar( 2,150,Carname[auxi]);
 end;
 end;
 end;*)


begin
end.