hedgewars/uAIAmmoTests.pas
changeset 3439 a98984e4f458
parent 3438 670324167e42
child 3476 1ec68b8d3bd1
equal deleted inserted replaced
3438:670324167e42 3439:a98984e4f458
   642 end;
   642 end;
   643 
   643 
   644 
   644 
   645 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   645 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
   646 var
   646 var
   647   i, failNum: longword;
   647     i, failNum: longword;
   648   maxTop: longword;
   648     maxTop: longword;
   649 begin
   649 begin
   650   TestTeleport := BadTurn;
   650     TestTeleport := BadTurn;
   651   Level:= Level; // avoid compiler hint
   651     Level:= Level; // avoid compiler hint
   652   FillBonuses(true, [gtCase]);
   652     FillBonuses(true, [gtCase]);
   653   if bonuses.Count = 0 then begin
   653     if bonuses.Count = 0 then begin
   654     if Me^.Health <= 100  then begin
   654         if Me^.Health <= 100  then begin
   655 	  maxTop := Targ.Y - cHHRadius * 2; 
   655             maxTop := Targ.Y - cHHRadius * 2; 
   656 	  while(not TestColl(Targ.X, maxTop, cHHRadius) and (maxTop > topY + cHHRadius * 2 + 1)) do
   656             while not TestColl(Targ.X, maxTop, cHHRadius) and (maxTop > topY + cHHRadius * 2 + 1) do
   657 	  	dec(maxTop, cHHRadius*2);
   657             dec(maxTop, cHHRadius*2);
   658 	  if(not TestColl(Targ.X, maxTop + cHHRadius, cHHRadius)) then begin
   658             if not TestColl(Targ.X, maxTop + cHHRadius, cHHRadius) then begin
   659         ap.AttackPutX := Targ.X;
   659                 ap.AttackPutX := Targ.X;
   660         ap.AttackPutY := maxTop + cHHRadius;
   660                 ap.AttackPutY := maxTop + cHHRadius;
   661         TestTeleport := Targ.Y - maxTop;
   661                 TestTeleport := Targ.Y - maxTop;
   662 	  end;
   662             end;
       
   663         end;
   663     end
   664     end
   664   end
   665     else begin
   665   else begin
   666         failNum := 0;
   666 	failNum := 0;
   667         repeat 
   667     repeat 
   668             i := random(bonuses.Count);
   668 		i := random(bonuses.Count);
   669             inc(failNum);
   669 		inc(failNum);
   670         until not TestColl(bonuses.ar[i].X, bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius, cHHRadius) or (failNum = bonuses.Count*2);
   670 	until(not TestColl(bonuses.ar[i].X, bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius, cHHRadius) or (failNum = bonuses.Count*2));
   671         if failNum < bonuses.Count*2 then begin
   671 	if failNum < bonuses.Count*2 then begin
   672             ap.AttackPutX := bonuses.ar[i].X;
   672 	  ap.AttackPutX := bonuses.ar[i].X;
   673             ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius;
   673 	  ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius;
   674             TestTeleport := 0;
   674 	  TestTeleport := 0;
   675         end;
   675 	end
   676     end;
   676   end;
       
   677 end;
   677 end;
   678 
   678 
   679 end.
   679 end.