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{$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF}, uTypes, |
33 uAmmos, SysUtils{$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF}, uTypes, |
34 uVariables, uCommands, uUtils, uDebug; |
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 {$IFDEF USE_SDLTHREADS} |
39 {$IFDEF USE_SDLTHREADS} |
210 or StopThinking |
210 or StopThinking |
211 end |
211 end |
212 end; |
212 end; |
213 |
213 |
214 procedure Walk(Me: PGear; var Actions: TActions); |
214 procedure Walk(Me: PGear; var Actions: TActions); |
215 const FallPixForBranching = cHHRadius * 2 + 8; |
215 const FallPixForBranching = cHHRadius; |
216 var |
216 var |
217 ticks, maxticks, steps, tmp: Longword; |
217 ticks, maxticks, steps, tmp: Longword; |
218 BaseRate, BestRate, Rate: integer; |
218 BaseRate, BestRate, Rate: integer; |
219 GoInfo: TGoInfo; |
219 GoInfo: TGoInfo; |
220 CanGo: boolean; |
220 CanGo: boolean; |
273 if ticks > maxticks then |
273 if ticks > maxticks then |
274 break; |
274 break; |
275 |
275 |
276 if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support |
276 if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support |
277 if Push(ticks, Actions, AltMe, Me^.Message) then |
277 if Push(ticks, Actions, AltMe, Me^.Message) then |
|
278 begin |
278 with Stack.States[Pred(Stack.Count)] do |
279 with Stack.States[Pred(Stack.Count)] do |
279 begin |
280 begin |
280 if Me^.dX.isNegative then |
281 if Me^.dX.isNegative then |
281 AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0) |
282 AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0) |
282 else |
283 else |
288 if Me^.dX.isNegative then |
289 if Me^.dX.isNegative then |
289 AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0) |
290 AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0) |
290 else |
291 else |
291 AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0); |
292 AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0); |
292 end; |
293 end; |
|
294 |
|
295 // check if we could go backwards and maybe ljump over a gap after this hjump |
|
296 Push(ticks, Stack.States[Pred(Stack.Count)].MadeActions, AltMe, Me^.Message xor 3) |
|
297 end; |
293 if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support |
298 if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support |
294 begin |
299 begin |
295 // push current position so we proceed from it after checking jump opportunities |
300 // at final check where we go after jump walking backward |
|
301 if Push(ticks, Actions, AltMe, Me^.Message xor 3) then |
|
302 with Stack.States[Pred(Stack.Count)] do |
|
303 AddAction(MadeActions, aia_LJump, 0, 305 + random(50), 0, 0); |
|
304 |
|
305 // push current position so we proceed from it after checking jump+forward walk opportunities |
296 if CanGo then Push(ticks, Actions, Me^, Me^.Message); |
306 if CanGo then Push(ticks, Actions, Me^, Me^.Message); |
297 // first check where we go after jump |
307 |
|
308 // first check where we go after jump walking forward |
298 if Push(ticks, Actions, AltMe, Me^.Message) then |
309 if Push(ticks, Actions, AltMe, Me^.Message) then |
299 with Stack.States[Pred(Stack.Count)] do |
310 with Stack.States[Pred(Stack.Count)] do |
300 AddAction(MadeActions, aia_LJump, 0, 305 + random(50), 0, 0); |
311 AddAction(MadeActions, aia_LJump, 0, 305 + random(50), 0, 0); |
301 break |
312 break |
302 end; |
313 end; |
315 BestRate:= Rate; |
326 BestRate:= Rate; |
316 Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo |
327 Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo |
317 end |
328 end |
318 else if Rate < BestRate then |
329 else if Rate < BestRate then |
319 break; |
330 break; |
|
331 |
320 if ((Me^.State and gstAttacked) = 0) and ((steps mod 4) = 0) then |
332 if ((Me^.State and gstAttacked) = 0) and ((steps mod 4) = 0) then |
|
333 begin |
|
334 if (steps > 4) and checkMark(hwRound(Me^.X), hwRound(Me^.Y), markWasHere) then |
|
335 break; |
|
336 addMark(hwRound(Me^.X), hwRound(Me^.Y), markWasHere); |
|
337 |
321 TestAmmos(Actions, Me, true); |
338 TestAmmos(Actions, Me, true); |
|
339 end; |
|
340 |
322 if GoInfo.FallPix >= FallPixForBranching then |
341 if GoInfo.FallPix >= FallPixForBranching then |
323 Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right |
342 Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right |
324 end {while}; |
343 end {while}; |
325 |
344 |
326 if BestRate > BaseRate then |
345 if BestRate > BaseRate then |