hedgewars/uAIActions.pas
changeset 6474 42e9773eedfd
parent 6395 bb04d7a9f7e2
child 6535 51a7e71ad317
equal deleted inserted replaced
6473:2bed5ba1a7ea 6474:42e9773eedfd
   117      inc(Count);
   117      inc(Count);
   118      TryDo(Count < MAXACTIONS, 'AI: actions overflow', true);
   118      TryDo(Count < MAXACTIONS, 'AI: actions overflow', true);
   119      end
   119      end
   120 end;
   120 end;
   121 
   121 
       
   122 procedure CheckHang(Me: PGear);
       
   123 const PrevX: LongInt = 0;
       
   124       timedelta: Longword = 0;
       
   125 begin
       
   126 if hwRound(Me^.X) <> PrevX then
       
   127    begin
       
   128    PrevX:= hwRound(Me^.X);
       
   129    timedelta:= 0
       
   130    end else
       
   131    begin
       
   132    inc(timedelta);
       
   133    if timedelta > 1700 then
       
   134       begin
       
   135       timedelta:= 0;
       
   136       FreeActionsList
       
   137       end
       
   138    end
       
   139 end;
       
   140 
   122 procedure ProcessAction(var Actions: TActions; Me: PGear);
   141 procedure ProcessAction(var Actions: TActions; Me: PGear);
   123 var s: shortstring;
   142 var s: shortstring;
   124 
       
   125     procedure CheckHang;
       
   126     const PrevX: LongInt = 0;
       
   127           timedelta: Longword = 0;
       
   128     begin
       
   129     if hwRound(Me^.X) <> PrevX then
       
   130        begin
       
   131        PrevX:= hwRound(Me^.X);
       
   132        timedelta:= 0
       
   133        end else
       
   134        begin
       
   135        inc(timedelta);
       
   136        if timedelta > 1700 then
       
   137           begin
       
   138           timedelta:= 0;
       
   139           FreeActionsList
       
   140           end
       
   141        end
       
   142     end;
       
   143 
       
   144 begin
   143 begin
   145 repeat
   144 repeat
   146 if Actions.Pos >= Actions.Count then exit;
   145 if Actions.Pos >= Actions.Count then exit;
   147 with Actions.actions[Actions.Pos] do
   146 with Actions.actions[Actions.Pos] do
   148      begin
   147      begin
   163                                begin
   162                                begin
   164                                //OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false);
   163                                //OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false);
   165                                FreeActionsList;
   164                                FreeActionsList;
   166                                exit
   165                                exit
   167                                end
   166                                end
   168                           else begin CheckHang; exit end;
   167                           else begin CheckHang(Me); exit end;
   169            aia_WaitXR: if hwRound(Me^.X) = Param then
   168            aia_WaitXR: if hwRound(Me^.X) = Param then
   170                           begin
   169                           begin
   171                           Action:= aia_LookRight;
   170                           Action:= aia_LookRight;
   172                           Time:= GameTicks;
   171                           Time:= GameTicks;
   173                           exit
   172                           exit
   176                                begin
   175                                begin
   177                                //OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false);
   176                                //OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false);
   178                                FreeActionsList;
   177                                FreeActionsList;
   179                                exit
   178                                exit
   180                                end
   179                                end
   181                           else begin CheckHang; exit end;
   180                           else begin CheckHang(Me); exit end;
   182          aia_LookLeft: if not Me^.dX.isNegative then
   181          aia_LookLeft: if not Me^.dX.isNegative then
   183                           begin
   182                           begin
   184                           ParseCommand('+left', true);
   183                           ParseCommand('+left', true);
   185                           exit
   184                           exit
   186                           end else ParseCommand('-left', true);
   185                           end else ParseCommand('-left', true);