hedgewars/uGears.pas
changeset 2659 947fa21d5cd8
parent 2622 39932161194e
child 2695 ed789a7ef68d
--- a/hedgewars/uGears.pas	Tue Dec 08 17:46:58 2009 +0000
+++ b/hedgewars/uGears.pas	Wed Dec 09 17:35:42 2009 +0000
@@ -1955,14 +1955,18 @@
 
 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
 
-	function CountNonZeroz(x, y, r: LongInt): LongInt;
+	function CountNonZeroz(x, y, r, c: LongInt): LongInt;
 	var i: LongInt;
 		Result: LongInt;
 	begin
 	Result:= 0;
 	if (y and LAND_HEIGHT_MASK) = 0 then
 		for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
-			if Land[y, i] <> 0 then inc(Result);
+			if Land[y, i] <> 0 then
+               begin
+               inc(Result);
+               if Result = c then exit(Result)
+               end;
 	CountNonZeroz:= Result
 	end;
 
@@ -1988,13 +1992,13 @@
 			begin
 			repeat
 				inc(y, 2);
-			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0);
+			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) = 0);
 
 			sy:= y;
 
 			repeat
 				inc(y);
-			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0);
+			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0);
 
 			if (y - sy > Gear^.Radius * 2)
 				and (y < LAND_HEIGHT)