Fix hog not returning from TimeBox when all land was destroyed
authorWuzzy <Wuzzy2@mail.ru>
Thu, 08 Oct 2020 11:12:22 +0200
changeset 15741 8997e212be4c
parent 15740 0a172cfe8840
child 15742 0b5aea8e5eab
Fix hog not returning from TimeBox when all land was destroyed
ChangeLog.txt
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsUtils.pas
--- a/ChangeLog.txt	Wed Oct 07 23:06:34 2020 +0200
+++ b/ChangeLog.txt	Thu Oct 08 11:12:22 2020 +0200
@@ -20,6 +20,7 @@
  * Fix hog getting stuck when opening parachute right after a shoryuken digging through land
  * Fix game hanging if computer hog has nothing to attack
  * Fix hog sometimes not falling after resurrection
+ * Fix hog not returning from TimeBox when all land was destroyed
 
 Campaigns:
  + A Space Adventure: Spacetrip: Meteorite appears blown-up after victory
--- a/hedgewars/uGearsHandlersMess.pas	Wed Oct 07 23:06:34 2020 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Thu Oct 08 11:12:22 2020 +0200
@@ -6470,7 +6470,7 @@
     if (cnt = 0) or SuddenDeathDmg or (Gear^.Timer = 0) then
         begin
         if HH^.GearHidden <> nil then
-            FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH,true);
+            FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH, true, false);
 
         if HH^.GearHidden <> nil then
             begin
--- a/hedgewars/uGearsUtils.pas	Wed Oct 07 23:06:34 2020 +0200
+++ b/hedgewars/uGearsUtils.pas	Thu Oct 08 11:12:22 2020 +0200
@@ -41,6 +41,7 @@
 
 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt); inline;
 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
+procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity, deleteOnFail: boolean);
 function CountLand(x, y, r, c: LongInt; mask, antimask: LongWord): LongInt;
 
 function  CheckGearNear(Kind: TGearType; X, Y: hwFloat; rX, rY: LongInt): PGear;
@@ -923,10 +924,15 @@
 
 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt); inline;
 begin
-    FindPlace(Gear, withFall, Left, Right, false);
+    FindPlace(Gear, withFall, Left, Right, false, true);
 end;
 
-procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
+procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean); inline;
+begin
+    FindPlace(Gear, withFall, Left, Right, skipProximity, true);
+end;
+
+procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity, deleteOnFail: boolean);
 var x: LongInt;
     y, sy, dir: LongInt;
     ar: array[0..1023] of TPoint;
@@ -1027,18 +1033,17 @@
         begin
         Gear^.X:= int2hwFloat(x);
         Gear^.Y:= int2hwFloat(y);
-        AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
+        AddFileLog('FindPlace: Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
         end
     end
 else
     begin
-    OutError('Can''t find place for Gear', false);
+    OutError('FindPlace: Can''t find place for Gear', false);
     if Gear^.Kind = gtHedgehog then
         begin
         cnt:= 0;
         if GameTicks = 0 then
             begin
-            //AddFileLog('Trying to make a hole');
             while (cnt < 1000) do
                 begin
                 inc(cnt);
@@ -1049,20 +1054,22 @@
                     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)) + ')');
+                    AddFileLog('FindPlace: Picked alternative spot for hog at coordinates (' + inttostr(hwRound(Gear^.X)) + ',' + inttostr(hwRound(Gear^.Y)) + ')');
                     cnt:= 2000
                     end
                 end;
             end;
-        if cnt < 2000 then
+        if (deleteOnFail) and (cnt < 2000) then
             begin
+            AddFileLog('FindPlace: No place found, deleting hog');
             Gear^.Hedgehog^.Effects[heResurrectable] := 0;
             DeleteGear(Gear);
             Gear:= nil
             end
         end
-    else
+    else if (deleteOnFail) then
         begin
+        AddFileLog('FindPlace: No place found, deleting Gear');
         DeleteGear(Gear);
         Gear:= nil
         end