hedgewars/uAI.pas
changeset 6415 af2047bb4f70
parent 6395 bb04d7a9f7e2
parent 6346 db58a42bb5e7
child 6416 850b8dd3e6df
equal deleted inserted replaced
6414:8474b7fa84d6 6415:af2047bb4f70
    28 procedure ProcessBot;
    28 procedure ProcessBot;
    29 procedure FreeActionsList;
    29 procedure FreeActionsList;
    30 
    30 
    31 implementation
    31 implementation
    32 uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions,
    32 uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions,
    33      uAmmos, SysUtils{$IFDEF UNIX}, cthreads{$ENDIF}, uTypes,
    33      uAmmos, SysUtils{$IFDEF UNIX}{$IFNDEF ANDROID}, cthreads{$ENDIF}{$ENDIF}, uTypes,
    34      uVariables, uCommands, uUtils, uDebug;
    34      uVariables, uCommands, uUtils, uDebug;
    35 
    35 
    36 var BestActions: TActions;
    36 var BestActions: TActions;
    37     CanUseAmmo: array [TAmmoType] of boolean;
    37     CanUseAmmo: array [TAmmoType] of boolean;
    38     StopThinking: boolean;
    38     StopThinking: boolean;
    39     ThinkThread: TThreadID;
    39     ThinkThread: PSDL_Thread = nil;
    40     hasThread: LongInt;
    40     hasThread: LongInt;
    41 
    41 
    42 procedure FreeActionsList;
    42 procedure FreeActionsList;
    43 begin
    43 begin
    44 AddFileLog('FreeActionsList called');
    44 AddFileLog('FreeActionsList called');
   115     if (Targets.ar[i].Score >= 0) and (not StopThinking) then
   115     if (Targets.ar[i].Score >= 0) and (not StopThinking) then
   116        begin
   116        begin
   117        with CurrentHedgehog^ do
   117        with CurrentHedgehog^ do
   118             a:= CurAmmoType;
   118             a:= CurAmmoType;
   119        aa:= a;
   119        aa:= a;
   120        
   120        SDL_delay(0);    //ThreadSwitch was only a hint
   121        ThreadSwitch();
       
   122        
   121        
   123        repeat
   122        repeat
   124         if (CanUseAmmo[a]) and
   123         if (CanUseAmmo[a]) and
   125            ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then
   124            ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then
   126            begin
   125            begin
   364    exit
   363    exit
   365    end;
   364    end;
   366 
   365 
   367 FillBonuses((Me^.State and gstAttacked) <> 0);
   366 FillBonuses((Me^.State and gstAttacked) <> 0);
   368 AddFileLog('Enter Think Thread');
   367 AddFileLog('Enter Think Thread');
   369 BeginThread(@Think, Me, ThinkThread)
   368 {$IFDEF IPHONEOS}
       
   369 //TODO: sdl_thread works on device but crashes in simulator, most likely because of outdated toolchain
       
   370 BeginThread(@Think, Me, ThinkThread);
       
   371 {$ELSE}
       
   372 ThinkThread := SDL_CreateThread(@Think{$IFDEF SDL13}, nil{$ENDIF}, Me);
       
   373 {$ENDIF}
       
   374 {$ENDIF}
       
   375 AddFileLog('Thread started');
   370 end;
   376 end;
   371 
   377 
   372 procedure ProcessBot;
   378 procedure ProcessBot;
   373 const StartTicks: Longword = 0;
   379 const StartTicks: Longword = 0;
   374       cStopThinkTime = 40;
   380       cStopThinkTime = 40;
   395 end;
   401 end;
   396 
   402 
   397 procedure initModule;
   403 procedure initModule;
   398 begin
   404 begin
   399     hasThread:= 0;
   405     hasThread:= 0;
       
   406     ThinkThread:= ThinkThread;
   400 end;
   407 end;
   401 
   408 
   402 procedure freeModule;
   409 procedure freeModule;
   403 begin
   410 begin
   404 
   411