# HG changeset patch
# User unc0rr
# Date 1164575964 0
# Node ID 4d6e365befc10e12650929f57c0f1baa69dd52fe
# Parent  5df0ab96b60a36e06119e368edc97572c693b467
Watchdog for bots to prevent them from being stacked by bugs of engine physics

diff -r 5df0ab96b60a -r 4d6e365befc1 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');