Teleport AI:
authormbait
Thu, 06 May 2010 11:33:25 +0000
changeset 3433 566788d32e52
parent 3432 83cef0f08a86
child 3434 6af73e7f2438
Teleport AI: * calculate max height from target and check collision
hedgewars/uAIAmmoTests.pas
--- 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;