hedgewars/uAIAmmoTests.pas
changeset 3371 da73f471798f
parent 3370 37f4f83fedb1
child 3372 5d3daec0d0b5
--- a/hedgewars/uAIAmmoTests.pas	Tue Apr 27 12:51:29 2010 +0000
+++ b/hedgewars/uAIAmmoTests.pas	Tue Apr 27 21:49:52 2010 +0000
@@ -639,16 +639,24 @@
 
 function TestTeleport(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 var
-  i: longword;
+  i, failNum: longword;
 begin
   FillBonuses(true, [gtCase]);
   if bonuses.Count = 0 then
     TestTeleport := BadTurn
   else begin
-	i := random(bonuses.Count);
-	ap.AttackPutX := bonuses.ar[i].X;
-	ap.AttackPutY := bonuses.ar[i].Y - 50;
-	TestTeleport := 0;
+	failNum := 0;
+    repeat 
+		i := random(bonuses.Count);
+		inc(failNum);
+	until(not TestColl(bonuses.ar[i].X, bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius, cHHRadius) or (failNum = bonuses.Count*2));
+	if failNum < bonuses.Count*2 then begin
+	  ap.AttackPutX := bonuses.ar[i].X;
+	  ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius;
+	  TestTeleport := 0;
+	end
+    else
+	  TestTeleport := BadTurn;
   end;
 end;