hedgewars/uAIActions.pas
changeset 280 4d6e365befc1
parent 195 edae828322a0
child 351 29bc9c36ad5f
equal deleted inserted replaced
279:5df0ab96b60a 280:4d6e365befc1
   112      end
   112      end
   113 end;
   113 end;
   114 
   114 
   115 procedure ProcessAction(var Actions: TActions; Me: PGear);
   115 procedure ProcessAction(var Actions: TActions; Me: PGear);
   116 var s: shortstring;
   116 var s: shortstring;
       
   117 
       
   118     procedure CheckHang;
       
   119     const PrevX: integer = 0;
       
   120           timedelta: Longword = 0;
       
   121     begin
       
   122     if Round(Me.X) <> PrevX then
       
   123        begin
       
   124        PrevX:= Round(Me.X);
       
   125        timedelta:= 0
       
   126        end else
       
   127        begin
       
   128        inc(timedelta);
       
   129        if timedelta > 2500 then
       
   130           begin
       
   131           timedelta:= 0;
       
   132           Actions.Count:= 0
       
   133           end
       
   134        end
       
   135     end;
       
   136 
   117 begin
   137 begin
   118 repeat
   138 repeat
   119 if Actions.Pos >= Actions.Count then exit;
   139 if Actions.Pos >= Actions.Count then exit;
   120 with Actions.actions[Actions.Pos] do
   140 with Actions.actions[Actions.Pos] do
   121      begin
   141      begin
   130                           else if Round(Me.X) < Param then
   150                           else if Round(Me.X) < Param then
   131                                begin
   151                                begin
   132                                OutError('AI: WaitXL assert');
   152                                OutError('AI: WaitXL assert');
   133                                Actions.Count:= 0
   153                                Actions.Count:= 0
   134                                end
   154                                end
   135                           else exit;
   155                           else begin CheckHang; exit end;
   136            aia_WaitXR: if round(Me.X) = Param then Time:= GameTicks
   156            aia_WaitXR: if round(Me.X) = Param then Time:= GameTicks
   137                           else if Round(Me.X) > Param then
   157                           else if Round(Me.X) > Param then
   138                                begin
   158                                begin
   139                                OutError('AI: WaitXR assert');
   159                                OutError('AI: WaitXR assert');
   140                                Actions.Count:= 0
   160                                Actions.Count:= 0
   141                                end
   161                                end
   142                           else exit;
   162                           else begin CheckHang; exit end;
   143          aia_LookLeft: if Me.dX >= 0 then
   163          aia_LookLeft: if Me.dX >= 0 then
   144                           begin
   164                           begin
   145                           ParseCommand('+left');
   165                           ParseCommand('+left');
   146                           exit
   166                           exit
   147                           end else ParseCommand('-left');
   167                           end else ParseCommand('-left');