hedgewars/uGearsUtils.pas
changeset 11482 e425a6eb9da3
parent 11477 c55b3e09a04e
child 11483 8c95d5a4366c
--- a/hedgewars/uGearsUtils.pas	Thu Dec 31 10:17:15 2015 -0500
+++ b/hedgewars/uGearsUtils.pas	Thu Dec 31 12:47:33 2015 -0500
@@ -927,13 +927,42 @@
         AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
         end
     end
-    else
+else
     begin
     OutError('Can''t find place for Gear', false);
     if Gear^.Kind = gtHedgehog then
-        Gear^.Hedgehog^.Effects[heResurrectable] := 0;
-    DeleteGear(Gear);
-    Gear:= nil
+        begin
+        cnt:= 0;
+        if GameTicks = 0 then
+            begin
+            //AddFileLog('Trying to make a hole');
+            while (cnt < 1000) do
+                begin
+                inc(cnt);
+                x:= leftX+GetRandom(rightX-leftX-16)+8;
+                y:= topY+GetRandom(LAND_HEIGHT-topY-16)+8;
+                if NoGearsToAvoid(x, y, 100, 100) then
+                    begin
+                    Gear^.State:= Gear^.State or gsttmpFlag;
+                    Gear^.X:= int2hwFloat(x);
+                    Gear^.Y:= int2hwFloat(y);
+                    AddFileLog('Picked a spot for hog at coordinates (' + inttostr(hwRound(Gear^.X)) + ',' + inttostr(hwRound(Gear^.Y)) + ')');
+                    cnt:= 2000
+                    end
+                end;
+            end;
+        if cnt < 2000 then
+            begin
+            Gear^.Hedgehog^.Effects[heResurrectable] := 0;
+            DeleteGear(Gear);
+            Gear:= nil
+            end
+        end
+    else
+        begin
+        DeleteGear(Gear);
+        Gear:= nil
+        end
     end
 end;