hedgewars/uAIAmmoTests.pas
changeset 3433 566788d32e52
parent 3407 dcc129c4352e
child 3438 670324167e42
--- a/hedgewars/uAIAmmoTests.pas	Thu May 06 09:25:13 2010 +0000
+++ b/hedgewars/uAIAmmoTests.pas	Thu May 06 11:33:25 2010 +0000
@@ -645,17 +645,22 @@
 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 var
   i, failNum: longword;
+  maxTop: longword;
 begin
+  TestTeleport := BadTurn;
   Level:= Level; // avoid compiler hint
   FillBonuses(true, [gtCase]);
   if bonuses.Count = 0 then begin
     if Me^.Health <= 100  then begin
-      ap.AttackPutX := Targ.X;
-      ap.AttackPutY := topY + cHHRadius*2;
-      TestTeleport := Targ.Y - topY;
+	  maxTop := Targ.Y - cHHRadius * 2; 
+	  while(not TestColl(Targ.X, maxTop, cHHRadius) and (maxTop > topY)) do
+	  	dec(maxTop, cHHRadius*2);
+	  if(not TestColl(Targ.X, maxTop + cHHRadius, cHHRadius)) then begin
+        ap.AttackPutX := Targ.X;
+        ap.AttackPutY := maxTop + cHHRadius;
+        TestTeleport := Targ.Y - maxTop;
+	  end;
     end
-    else
-      TestTeleport := BadTurn;
   end
   else begin
 	failNum := 0;
@@ -668,8 +673,6 @@
 	  ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius;
 	  TestTeleport := 0;
 	end
-    else
-	  TestTeleport := BadTurn;
   end;
 end;