hedgewars/uGears.pas
changeset 386 21eeb5ac0486
parent 371 731ad6d27bd1
child 392 25be13ae29da
equal deleted inserted replaced
385:9201c85f7ff4 386:21eeb5ac0486
   827     CountNonZeroz:= Result
   827     CountNonZeroz:= Result
   828     end;
   828     end;
   829 
   829 
   830 var fx, x: LongInt;
   830 var fx, x: LongInt;
   831     y, sy: LongInt;
   831     y, sy: LongInt;
   832     ar: array[0..512] of TPoint;
   832     ar: array[0..511] of TPoint;
   833     cnt, delta: Longword;
   833     ar2: array[0..1023] of TPoint;
   834 begin
   834     cnt, cnt2, delta: Longword;
   835 fx:= Left + LongInt(GetRandom(Right - Left));
   835 begin
   836 x:= fx;
   836 delta:= 250;
   837 delta:= 130;
   837 cnt2:= 0;
   838 repeat
   838 repeat
       
   839   x:= Left + GetRandom(Delta);
   839   repeat
   840   repeat
   840      inc(x, Gear^.Radius);
   841      inc(x, Delta);
   841      if x > Right then x:= Left + (x mod (Right - left));
       
   842      cnt:= 0;
   842      cnt:= 0;
   843      y:= -Gear^.Radius * 2;
   843      y:= -Gear^.Radius * 2;
   844      while y < 1023 do
   844      while y < 1023 do
   845         begin
   845         begin
   846         repeat
   846         repeat
   857            ar[cnt].X:= x;
   857            ar[cnt].X:= x;
   858            if withFall then ar[cnt].Y:= sy + Gear^.Radius
   858            if withFall then ar[cnt].Y:= sy + Gear^.Radius
   859                        else ar[cnt].Y:= y - Gear^.Radius;
   859                        else ar[cnt].Y:= y - Gear^.Radius;
   860            inc(cnt)
   860            inc(cnt)
   861            end;
   861            end;
   862         inc(y, 80)
   862         inc(y, 45)
   863         end;
   863         end;
   864      if cnt > 0 then
   864      if cnt > 0 then
   865         with ar[GetRandom(cnt)] do
   865         with ar[GetRandom(cnt)] do
   866           begin
   866           begin
   867           Gear^.X:= x;
   867           ar2[cnt2].x:= x;
   868           Gear^.Y:= y;
   868           ar2[cnt2].y:= y;
   869          {$IFDEF DEBUGFILE}
   869           inc(cnt2)
   870          AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
       
   871          {$ENDIF}
       
   872           exit
       
   873           end
   870           end
   874   until (x - Gear^.Radius < fx) and (x + Gear^.Radius > fx);
   871   until (x + Delta > Right);
   875 dec(Delta, 20)
   872 dec(Delta, 60)
   876 until (Delta < 70);
   873 until (cnt2 > 0) or (Delta < 70);
   877 OutError('Couldn''t find place for Gear', false);
   874 if cnt2 > 0 then
   878 DeleteGear(Gear)
   875    with ar2[GetRandom(cnt2)] do
       
   876       begin
       
   877       Gear^.X:= x;
       
   878       Gear^.Y:= y;
       
   879       {$IFDEF DEBUGFILE}
       
   880       AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
       
   881       {$ENDIF}
       
   882       end
       
   883    else
       
   884    begin
       
   885    OutError('Can''t find place for Gear', false);
       
   886    DeleteGear(Gear)
       
   887    end
   879 end;
   888 end;
   880 
   889 
   881 initialization
   890 initialization
   882 
   891 
   883 finalization
   892 finalization