Watchdog for bots to prevent them from being stacked by bugs of engine physics
authorunc0rr
Sun, 26 Nov 2006 21:19:24 +0000
changeset 280 4d6e365befc1
parent 279 5df0ab96b60a
child 281 5b483aa9f2ab
Watchdog for bots to prevent them from being stacked by bugs of engine physics
hedgewars/uAIActions.pas
--- a/hedgewars/uAIActions.pas	Sun Nov 26 20:33:46 2006 +0000
+++ b/hedgewars/uAIActions.pas	Sun Nov 26 21:19:24 2006 +0000
@@ -114,6 +114,26 @@
 
 procedure ProcessAction(var Actions: TActions; Me: PGear);
 var s: shortstring;
+
+    procedure CheckHang;
+    const PrevX: integer = 0;
+          timedelta: Longword = 0;
+    begin
+    if Round(Me.X) <> PrevX then
+       begin
+       PrevX:= Round(Me.X);
+       timedelta:= 0
+       end else
+       begin
+       inc(timedelta);
+       if timedelta > 2500 then
+          begin
+          timedelta:= 0;
+          Actions.Count:= 0
+          end
+       end
+    end;
+
 begin
 repeat
 if Actions.Pos >= Actions.Count then exit;
@@ -132,14 +152,14 @@
                                OutError('AI: WaitXL assert');
                                Actions.Count:= 0
                                end
-                          else exit;
+                          else begin CheckHang; exit end;
            aia_WaitXR: if round(Me.X) = Param then Time:= GameTicks
                           else if Round(Me.X) > Param then
                                begin
                                OutError('AI: WaitXR assert');
                                Actions.Count:= 0
                                end
-                          else exit;
+                          else begin CheckHang; exit end;
          aia_LookLeft: if Me.dX >= 0 then
                           begin
                           ParseCommand('+left');