hedgewars/uAI.pas
changeset 143 3dacbd83209b
parent 139 340ded7cc336
child 144 e6084b0c9316
equal deleted inserted replaced
142:1ff0b02fe367 143:3dacbd83209b
   244 if (Me.State and gstAttacked) = 0 then
   244 if (Me.State and gstAttacked) = 0 then
   245    if Targets.Count > 0 then
   245    if Targets.Count > 0 then
   246       begin
   246       begin
   247       Walk(@WalkMe);
   247       Walk(@WalkMe);
   248       if (StartTicks > GameTicks - 1500) and not StopThinking then SDL_Delay(2000);
   248       if (StartTicks > GameTicks - 1500) and not StopThinking then SDL_Delay(2000);
       
   249       if BestActions.Score = BadTurn then AddAction(BestActions, aia_Skip, 0, 250);
   249       end else
   250       end else
   250 else begin
   251 else begin
   251       Walk(@WalkMe);
   252       Walk(@WalkMe);
   252       while (not StopThinking) and (BestActions.Count = 0) do
   253       while (not StopThinking) and (BestActions.Count = 0) do
   253             begin
   254             begin
   280 {$IFDEF DEBUGFILE}AddFileLog('Enter Think Thread');{$ENDIF}
   281 {$IFDEF DEBUGFILE}AddFileLog('Enter Think Thread');{$ENDIF}
   281 ThinkThread:= SDL_CreateThread(@Think, Me)
   282 ThinkThread:= SDL_CreateThread(@Think, Me)
   282 end;
   283 end;
   283 
   284 
   284 procedure ProcessBot;
   285 procedure ProcessBot;
       
   286 const StartTicks: Longword = 0;
   285 begin
   287 begin
   286 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
   288 with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
   287      if (Gear <> nil)
   289      if (Gear <> nil)
   288         and ((Gear.State and gstHHDriven) <> 0)
   290         and ((Gear.State and gstHHDriven) <> 0)
   289         and (TurnTimeLeft < cHedgehogTurnTime - 5)
   291         and (TurnTimeLeft < cHedgehogTurnTime - 5) then
   290         and ((Gear.State and gstHHThinking) = 0) then
   292         if ((Gear.State and gstHHThinking) = 0) then
   291            if (BestActions.Pos >= BestActions.Count) then StartThink(Gear)
   293            if (BestActions.Pos >= BestActions.Count) then
   292                                                      else ProcessAction(BestActions, Gear)
   294               begin
       
   295               StartThink(Gear);
       
   296               StartTicks:= GameTicks
       
   297               end else ProcessAction(BestActions, Gear)
       
   298         else if (GameTicks - StartTicks) > cMaxAIThinkTime then StopThinking:= true
   293 end;
   299 end;
   294 
   300 
   295 end.
   301 end.