Fix 'AI may break demos playing' message while loading saves
authorunc0rr
Sat, 17 May 2008 11:36:24 +0000
changeset 936 ba582673db7d
parent 935 f13a67ce3811
child 937 c1e6a770b043
Fix 'AI may break demos playing' message while loading saves
hedgewars/uAI.pas
hedgewars/uConsole.pas
hedgewars/uConsts.pas
--- a/hedgewars/uAI.pas	Fri May 16 13:21:18 2008 +0000
+++ b/hedgewars/uAI.pas	Sat May 17 11:36:24 2008 +0000
@@ -329,7 +329,12 @@
            if (BestActions.Pos >= BestActions.Count)
               and (TurnTimeLeft > cStopThinkTime) then
               begin
-              TryDo(Gear^.Message = 0, 'Engine bug: AI may break demos playing', true);
+              if Gear^.Message <> 0 then
+                 begin
+                 StopMessages(Gear^.Message);
+                 TryDo((Gear^.Message and gmAllStoppable) = 0, 'Engine bug: AI may break demos playing', true);
+                 end;
+              if Gear^.Message <> 0 then exit;
               StartThink(Gear);
               StartTicks:= GameTicks
               end else ProcessAction(BestActions, Gear)
--- a/hedgewars/uConsole.pas	Fri May 16 13:21:18 2008 +0000
+++ b/hedgewars/uConsole.pas	Sat May 17 11:36:24 2008 +0000
@@ -29,6 +29,7 @@
 procedure WriteLnToConsole(s: shortstring);
 procedure KeyPressConsole(Key: Longword);
 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
+procedure StopMessages(Message: Longword);
 function  GetLastConsoleLine: shortstring;
 
 procedure doPut(putX, putY: LongInt; fromAI: boolean);
@@ -316,6 +317,15 @@
                 else GetLastConsoleLine:= ConsoleLines[Pred(CurrLine)].s
 end;
 
+procedure StopMessages(Message: Longword);
+begin
+if (Message and gm_Left) <> 0 then ParseCommand('/-left', true) else
+if (Message and gm_Right) <> 0 then ParseCommand('/-right', true) else
+if (Message and gm_Up) <> 0 then ParseCommand('/-up', true) else
+if (Message and gm_Down) <> 0 then ParseCommand('/-down', true) else
+if (Message and gm_Attack) <> 0 then ParseCommand('/-attack', true)
+end;
+
 {$INCLUDE CCHandlers.inc}
 
 initialization
--- a/hedgewars/uConsts.pas	Fri May 16 13:21:18 2008 +0000
+++ b/hedgewars/uConsts.pas	Sat May 17 11:36:24 2008 +0000
@@ -185,6 +185,7 @@
       gm_Slot   = $00000200; // with param
       gm_Weapon = $00000400; // with param
       gm_Timer  = $00000800; // with param
+      gmAllStoppable = gm_Left or gm_Right or gm_Up or gm_Down or gm_Attack;
 
       cMaxSlotIndex       = 8;
       cMaxSlotAmmoIndex   = 2;