hedgewars/uGears.pas
changeset 2659 947fa21d5cd8
parent 2622 39932161194e
child 2695 ed789a7ef68d
equal deleted inserted replaced
2658:cd9ab1f5bfdb 2659:947fa21d5cd8
  1953 	end
  1953 	end
  1954 end;
  1954 end;
  1955 
  1955 
  1956 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
  1956 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
  1957 
  1957 
  1958 	function CountNonZeroz(x, y, r: LongInt): LongInt;
  1958 	function CountNonZeroz(x, y, r, c: LongInt): LongInt;
  1959 	var i: LongInt;
  1959 	var i: LongInt;
  1960 		Result: LongInt;
  1960 		Result: LongInt;
  1961 	begin
  1961 	begin
  1962 	Result:= 0;
  1962 	Result:= 0;
  1963 	if (y and LAND_HEIGHT_MASK) = 0 then
  1963 	if (y and LAND_HEIGHT_MASK) = 0 then
  1964 		for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
  1964 		for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
  1965 			if Land[y, i] <> 0 then inc(Result);
  1965 			if Land[y, i] <> 0 then
       
  1966                begin
       
  1967                inc(Result);
       
  1968                if Result = c then exit(Result)
       
  1969                end;
  1966 	CountNonZeroz:= Result
  1970 	CountNonZeroz:= Result
  1967 	end;
  1971 	end;
  1968 
  1972 
  1969 var x: LongInt;
  1973 var x: LongInt;
  1970 	y, sy: LongInt;
  1974 	y, sy: LongInt;
  1986 		    y:= topY-Gear^.Radius * 2;
  1990 		    y:= topY-Gear^.Radius * 2;
  1987 		while y < LAND_HEIGHT do
  1991 		while y < LAND_HEIGHT do
  1988 			begin
  1992 			begin
  1989 			repeat
  1993 			repeat
  1990 				inc(y, 2);
  1994 				inc(y, 2);
  1991 			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0);
  1995 			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) = 0);
  1992 
  1996 
  1993 			sy:= y;
  1997 			sy:= y;
  1994 
  1998 
  1995 			repeat
  1999 			repeat
  1996 				inc(y);
  2000 				inc(y);
  1997 			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0);
  2001 			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0);
  1998 
  2002 
  1999 			if (y - sy > Gear^.Radius * 2)
  2003 			if (y - sy > Gear^.Radius * 2)
  2000 				and (y < LAND_HEIGHT)
  2004 				and (y < LAND_HEIGHT)
  2001 				and (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase], 110, 110) = nil) then
  2005 				and (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase], 110, 110) = nil) then
  2002 				begin
  2006 				begin