hedgewars/uAIAmmoTests.pas
changeset 8777 cce79a042cfc
parent 8751 4609823efc94
child 8822 fc9877ff7f1a
--- a/hedgewars/uAIAmmoTests.pas	Tue Mar 26 17:47:06 2013 -0400
+++ b/hedgewars/uAIAmmoTests.pas	Tue Mar 26 17:52:27 2013 -0400
@@ -197,6 +197,8 @@
     x, y, dX, dY: real;
     t: LongInt;
     value: LongInt;
+    t2: real;
+    timer: Longint;
 begin
     mX:= hwFloat2Float(Me^.X);
     mY:= hwFloat2Float(Me^.Y);
@@ -224,7 +226,25 @@
                 dec(t)
             until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or 
                    ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me, trunc(x), trunc(y), 5))) or (y > cWaterLine);
-            
+
+            if TestCollWithLand(trunc(x), trunc(y), 5) then
+                begin
+                timer := 500;
+                t2 := 0.5 / sqrt(sqr(dX) + sqr(dY));
+                dX := dX * t2;
+                dY := dY * t2;
+                repeat
+                    x:= x + dX;
+                    y:= y + dY;
+                    dec(timer);
+                until (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 5)
+                    or (x < 0)
+                    or (y < 0)
+                    or (trunc(x) > LAND_WIDTH)
+                    or (trunc(y) > LAND_HEIGHT)
+                    or not TestCollWithLand(trunc(x), trunc(y), 5)
+                    or (timer = 0)
+                end;
             EX:= trunc(x);
             EY:= trunc(y);
             if Level = 1 then