hedgewars/uAI.pas
changeset 74 42257fee61ae
parent 71 5f56c6979496
child 75 d2b737858ff7
equal deleted inserted replaced
73:fe1c62875a19 74:42257fee61ae
   113 Actions.Score:= 0;
   113 Actions.Score:= 0;
   114 Actions.Count:= 0;
   114 Actions.Count:= 0;
   115 Actions.Pos:= 0;
   115 Actions.Pos:= 0;
   116 BestActions.Count:= 0;
   116 BestActions.Count:= 0;
   117 if (Me.State and gstAttacked) = 0 then maxsteps:= (TurnTimeLeft - 4000) div cHHStepTicks
   117 if (Me.State and gstAttacked) = 0 then maxsteps:= (TurnTimeLeft - 4000) div cHHStepTicks
   118                                   else maxsteps:= 3000;
   118                                   else maxsteps:= TurnTimeLeft div cHHStepTicks;
   119 BackMe:= Me^;
   119 BackMe:= Me^;
   120 if (Me.State and gstAttacked) = 0 then TestAmmos(Actions, Me);
   120 if (Me.State and gstAttacked) = 0 then TestAmmos(Actions, Me);
   121 BestRate:= RatePlace(Me);
   121 BestRate:= RatePlace(Me);
   122 for Dir:= aia_Left to aia_Right do
   122 for Dir:= aia_Left to aia_Right do
   123     begin
   123     begin
   133        Rate:= RatePlace(Me);
   133        Rate:= RatePlace(Me);
   134        if Rate > BestRate then
   134        if Rate > BestRate then
   135           begin
   135           begin
   136           BestActions:= Actions;
   136           BestActions:= Actions;
   137           BestRate:= Rate;
   137           BestRate:= Rate;
   138           Me.State:= Me.State or gstAttacked // we have better place, go to it and don't use ammo
   138           Me.State:= Me.State or gstAttacked // we have better place, go there and don't use ammo
   139           end
   139           end
   140        else if Rate < BestRate then
   140        else if Rate < BestRate then
   141                if BestRate > 0 then exit
   141                if BestRate > 0 then exit
   142                                else break;
   142                                else break;
   143        if ((Me.State and gstAttacked) = 0)
   143        if ((Me.State and gstAttacked) = 0)
   147     Me^:= BackMe
   147     Me^:= BackMe
   148     end
   148     end
   149 end;
   149 end;
   150 
   150 
   151 procedure Think(Me: PGear); cdecl;
   151 procedure Think(Me: PGear); cdecl;
   152 var BackMe: TGear;
   152 var BackMe, WalkMe: TGear;
   153     StartTicks: Longword;
   153     StartTicks: Longword;
   154 begin
   154 begin
   155 StartTicks:= GameTicks;
   155 StartTicks:= GameTicks;
       
   156 BestActions.Count:= 0;
       
   157 BestActions.Pos:= 0;
   156 BestActions.Score:= Low(integer);
   158 BestActions.Score:= Low(integer);
   157 if Targets.Count > 0 then
   159 BackMe:= Me^;
   158    begin
   160 WalkMe:= BackMe;
   159    BackMe:= Me^;
   161 if (Me.State and gstAttacked) = 0 then
   160    Walk(@BackMe);
   162    if Targets.Count > 0 then
   161    end;
   163       begin
   162 if ((Me.State and gstAttacked) = 0)
   164       Walk(@WalkMe);
   163     and (StartTicks > GameTicks - 1000) then SDL_Delay(1000);
   165       if (StartTicks > GameTicks - 1500) then SDL_Delay(2000);
   164     
   166       end else OutError('AI: no targets!?')
   165 if BestActions.Count > 0 then Me.State:= Me.State and not gstHHThinking;
   167 else begin
       
   168       Walk(@WalkMe);
       
   169       while (not StopThinking) and (BestActions.Count = 0) do
       
   170             begin
       
   171             SDL_Delay(100);
       
   172             FillBonuses(true);
       
   173             WalkMe:= BackMe;
       
   174             Walk(@WalkMe)
       
   175             end;
       
   176       AwareOfExplosion(0, 0, 0)
       
   177       end;
       
   178 
       
   179 Me.State:= Me.State and not gstHHThinking;
   166 ThinkThread:= nil
   180 ThinkThread:= nil
   167 end;
   181 end;
   168 
   182 
   169 procedure StartThink(Me: PGear);
   183 procedure StartThink(Me: PGear);
   170 begin
   184 begin