34 uVariables, uCommands, uUtils, uDebug, uAILandMarks; |
34 uVariables, uCommands, uUtils, uDebug, uAILandMarks; |
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: PSDL_Thread = nil; |
|
40 StartTicks: Longword; |
39 StartTicks: Longword; |
|
40 ThinkThread: PSDL_Thread; |
|
41 ThreadLock: PSDL_Mutex; |
41 |
42 |
42 procedure FreeActionsList; |
43 procedure FreeActionsList; |
43 begin |
44 begin |
44 AddFileLog('FreeActionsList called'); |
45 AddFileLog('FreeActionsList called'); |
|
46 SDL_LockMutex(ThreadLock); |
45 if (ThinkThread <> nil) then |
47 if (ThinkThread <> nil) then |
46 SDL_WaitThread(ThinkThread, nil); |
48 SDL_KillThread(ThinkThread); |
47 ThinkThread:=nil; |
49 ThinkThread:= nil; |
|
50 SDL_UnlockMutex(ThreadLock); |
48 |
51 |
49 with CurrentHedgehog^ do |
52 with CurrentHedgehog^ do |
50 if Gear <> nil then |
53 if Gear <> nil then |
51 if BotLevel <> 0 then |
54 if BotLevel <> 0 then |
52 StopMessages(Gear^.Message); |
55 StopMessages(Gear^.Message); |
358 switchCount: LongInt; |
361 switchCount: LongInt; |
359 StartTicks, currHedgehogIndex, itHedgehog, switchesNum, i: Longword; |
362 StartTicks, currHedgehogIndex, itHedgehog, switchesNum, i: Longword; |
360 switchImmediatelyAvailable: boolean; |
363 switchImmediatelyAvailable: boolean; |
361 Actions: TActions; |
364 Actions: TActions; |
362 begin |
365 begin |
363 AddFileLog('Thread started'); |
366 AddFileLog('Think thread started'); |
364 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent; |
367 dmgMod:= 0.01 * hwFloat2Float(cDamageModifier) * cDamagePercent; |
365 StartTicks:= GameTicks; |
368 StartTicks:= GameTicks; |
366 currHedgehogIndex:= CurrentTeam^.CurrHedgehog; |
369 currHedgehogIndex:= CurrentTeam^.CurrHedgehog; |
367 itHedgehog:= currHedgehogIndex; |
370 itHedgehog:= currHedgehogIndex; |
368 switchesNum:= 0; |
371 switchesNum:= 0; |
469 OutError('AI: no targets!?', false); |
474 OutError('AI: no targets!?', false); |
470 exit |
475 exit |
471 end; |
476 end; |
472 |
477 |
473 FillBonuses((Me^.State and gstAttacked) <> 0); |
478 FillBonuses((Me^.State and gstAttacked) <> 0); |
474 AddFileLog('Enter Think Thread'); |
479 |
|
480 SDL_LockMutex(ThreadLock); |
475 ThinkThread:= SDL_CreateThread(@Think{$IFDEF SDL13}, 'think'{$ENDIF}, Me); |
481 ThinkThread:= SDL_CreateThread(@Think{$IFDEF SDL13}, 'think'{$ENDIF}, Me); |
|
482 SDL_UnlockMutex(ThreadLock); |
476 end; |
483 end; |
477 |
484 |
478 //var scoreShown: boolean = false; |
485 //var scoreShown: boolean = false; |
479 |
486 |
480 procedure ProcessBot; |
487 procedure ProcessBot; |