Prevent all portal loops the guaranteed way, at least until sheepluva's tests yield something reliable.
authornemo
Sun, 23 May 2010 23:51:54 +0000
changeset 3480 c4c3f3512404
parent 3479 972ae3ec178a
child 3481 c385a7dad025
Prevent all portal loops the guaranteed way, at least until sheepluva's tests yield something reliable.
hedgewars/GSHandlers.inc
hedgewars/uGears.pas
--- a/hedgewars/GSHandlers.inc	Sun May 23 22:05:59 2010 +0000
+++ b/hedgewars/GSHandlers.inc	Sun May 23 23:51:54 2010 +0000
@@ -3201,7 +3201,7 @@
         // end of list
 
         // don't port portals or other gear that wouldn't make sense
-        if (iterator^.Kind = gtPortal) or (iterator^.Kind = gtRope) then
+        if (iterator^.Kind = gtPortal) or (iterator^.Kind = gtRope) or (iterator^.PortalCounter > 20) then
             continue;
 
         // don't port hogs on rope
@@ -3247,6 +3247,9 @@
         iterator^.State := iterator^.State or gstMoving;
         DeleteCI(iterator);
 
+        // Until loops are reliably broken
+        inc(iterator^.PortalCounter);
+
         // TODO: more accurate porting
         cdxy := Distance(conPortal^.dX, conPortal^.dY);
         s := (Int2hwFloat(Gear^.Radius)) / cdxy;
@@ -3407,6 +3410,7 @@
                             iterator^.Health := newPortal^.Health;
                         end;
                     end;
+                iterator^.PortalCounter:= 0;
                 iterator := iterator^.NextGear
             end;
         end;
--- a/hedgewars/uGears.pas	Sun May 23 22:05:59 2010 +0000
+++ b/hedgewars/uGears.pas	Sun May 23 23:51:54 2010 +0000
@@ -60,7 +60,8 @@
             uid: Longword;
             ImpactSound: TSound; // first sound, others have to be after it in the sounds def.
             nImpactSounds: Word; // count of ImpactSounds
-            SoundChannel: LongInt
+            SoundChannel: LongInt;
+            PortalCounter: LongWord  // Hopefully temporary, but avoids infinite portal loops in a guaranteed fashion.
         end;
 
 var AllInactive: boolean;
@@ -829,6 +830,7 @@
 //If any of these are set as permanent toggles in the frontend, that needs to be checked and skipped here.
 procedure EndTurnCleanup;
 var  i: LongInt;
+     t: PGear;
 begin
     SpeechText:= ''; // in case it has not been consumed
 
@@ -845,7 +847,6 @@
 
     if (GameFlags and gfArtillery) = 0 then
         cArtillery:= false;
-
     // have to sweep *all* current team hedgehogs since it is theoretically possible if you have enough invulnerabilities and switch turns to make your entire team invulnerable
     if (CurrentTeam <> nil) then
        with CurrentTeam^ do
@@ -862,6 +863,12 @@
                      if (GameFlags and gfInvulnerable) = 0 then
                         Gear^.Invulnerable:= false;
                   end;
+    t:= GearsList;
+    while t <> nil do
+        begin
+        t^.PortalCounter:= 0;
+        t:= t^.NextGear
+        end
 end;
 
 procedure ApplyDamage(Gear: PGear; Damage: Longword);