hedgewars/uGearsUtils.pas
branchqmlfrontend
changeset 11408 b894922d58cc
parent 11197 283b6e6cf7ea
child 11477 c55b3e09a04e
equal deleted inserted replaced
11076:fcbdee9cdd74 11408:b894922d58cc
   827     FindPlace(Gear, withFall, Left, Right, false);
   827     FindPlace(Gear, withFall, Left, Right, false);
   828 end;
   828 end;
   829 
   829 
   830 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
   830 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
   831 var x: LongInt;
   831 var x: LongInt;
   832     y, sy: LongInt;
   832     y, sy, dir: LongInt;
   833     ar: array[0..1023] of TPoint;
   833     ar: array[0..1023] of TPoint;
   834     ar2: array[0..2047] of TPoint;
   834     ar2: array[0..2047] of TPoint;
   835     temp: TPoint;
   835     temp: TPoint;
   836     cnt, cnt2: Longword;
   836     cnt, cnt2: Longword;
   837     delta: LongInt;
   837     delta: LongInt;
   848 while tryAgain do
   848 while tryAgain do
   849     begin
   849     begin
   850     delta:= LAND_WIDTH div 16;
   850     delta:= LAND_WIDTH div 16;
   851     cnt2:= 0;
   851     cnt2:= 0;
   852     repeat
   852     repeat
   853         x:= Left + max(LAND_WIDTH div 2048, LongInt(GetRandom(Delta)));
   853         if GetRandom(2) = 0 then dir:= -1 else dir:= 1;
       
   854         x:= max(LAND_WIDTH div 2048, LongInt(GetRandom(Delta)));
       
   855         if dir = 1 then x:= Left + x else x:= Right - x; 
   854         repeat
   856         repeat
   855             inc(x, Delta);
       
   856             cnt:= 0;
   857             cnt:= 0;
   857             y:= min(1024, topY) - Gear^.Radius shl 1;
   858             y:= min(1024, topY) - Gear^.Radius shl 1;
   858             while y < cWaterLine do
   859             while y < cWaterLine do
   859                 begin
   860                 begin
   860                 repeat
   861                 repeat
   899                 with temp do
   900                 with temp do
   900                     begin
   901                     begin
   901                     ar2[cnt2].x:= x;
   902                     ar2[cnt2].x:= x;
   902                     ar2[cnt2].y:= y;
   903                     ar2[cnt2].y:= y;
   903                     inc(cnt2)
   904                     inc(cnt2)
   904                     end
   905                     end;
   905                 end
   906                 end;
   906         until (x + Delta > Right);
   907             inc(x, Delta*dir)
       
   908         until ((dir = 1) and (x > Right)) or ((dir = -1) and (x < Left));
   907 
   909 
   908         dec(Delta, 60)
   910         dec(Delta, 60)
   909     until (cnt2 > 0) or (Delta < 70);
   911     until (cnt2 > 0) or (Delta < 70);
   910     // if either of these has not been tried, do another pass
   912     // if either of these has not been tried, do another pass
   911     if (cnt2 = 0) and skipProximity and (not ignoreOverlap) then
   913     if (cnt2 = 0) and skipProximity and (not ignoreOverlap) then