Fix AI jumping to wrong direction on the turn start
authorunc0rr
Sun, 01 Jul 2007 20:16:19 +0000
changeset 544 9e068d2398ca
parent 543 465e2ec8f05f
child 545 f527450337c1
Fix AI jumping to wrong direction on the turn start
hedgewars/uAI.pas
hedgewars/uAIActions.pas
--- a/hedgewars/uAI.pas	Sun Jul 01 11:02:47 2007 +0000
+++ b/hedgewars/uAI.pas	Sun Jul 01 20:16:19 2007 +0000
@@ -208,7 +208,6 @@
     AddAction(Actions, Me^.Message, aim_push, 250, 0, 0);
     if (Me^.Message and gm_Left) <> 0 then AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0)
                                       else AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0);
-    AddAction(Actions, Me^.Message, aim_release, 0, 0, 0);
     steps:= 0;
 
     while (not StopThinking) and (not PosInThinkStack(Me)) do
@@ -231,7 +230,7 @@
 
        if not CanGo then break;
        inc(steps);
-       Actions.actions[Actions.Count - 2].Param:= hwRound(Me^.X);
+       Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X);
        Rate:= RatePlace(Me);
        if Rate > BestRate then
           begin
--- a/hedgewars/uAIActions.pas	Sun Jul 01 11:02:47 2007 +0000
+++ b/hedgewars/uAIActions.pas	Sun Jul 01 20:16:19 2007 +0000
@@ -93,7 +93,7 @@
 else begin
    WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]);
    if (Action.Action = aia_WaitXL) or (Action.Action = aia_WaitXR) then
-      WriteLnToConsole('AI action Wait X = '+inttostr(Action.Param)+', current X = '+inttostr(round(Me.X)));
+      WriteLnToConsole('AI action Wait X = '+inttostr(Action.Param)+', current X = '+inttostr(hwRound(Me^.X)));
    end
 end;
 {$ENDIF}
@@ -147,18 +147,28 @@
      if (Action and ai_specmask) <> 0 then
         case Action of
            aia_Weapon: SetWeapon(TAmmoType(Param));
-           aia_WaitXL: if hwRound(Me^.X) = Param then Time:= GameTicks
+           aia_WaitXL: if hwRound(Me^.X) = Param then
+                          begin
+                          Action:= aia_LookLeft;
+                          Time:= GameTicks;
+                          exit
+                          end
                           else if hwRound(Me^.X) < Param then
                                begin
-                               OutError('AI: WaitXL assert', false);
+                               OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false);
                                FreeActionsList;
                                exit
                                end
                           else begin CheckHang; exit end;
-           aia_WaitXR: if hwRound(Me^.X) = Param then Time:= GameTicks
+           aia_WaitXR: if hwRound(Me^.X) = Param then
+                          begin
+                          Action:= aia_LookRight;
+                          Time:= GameTicks;
+                          exit
+                          end
                           else if hwRound(Me^.X) > Param then
                                begin
-                               OutError('AI: WaitXR assert', false);
+                               OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false);
                                FreeActionsList;
                                exit
                                end