hedgewars/uAIAmmoTests.pas
changeset 8887 539380a498e4
parent 8862 85eb1f4b4a5f
child 8895 95177c18e38c
--- a/hedgewars/uAIAmmoTests.pas	Tue Mar 26 18:52:42 2013 +0100
+++ b/hedgewars/uAIAmmoTests.pas	Sun Apr 07 22:53:40 2013 +0200
@@ -197,7 +197,11 @@
     x, y, dX, dY: real;
     t: LongInt;
     value: LongInt;
+    t2: real;
+    timer: Longint;
 begin
+    if (Level > 3) then exit(BadTurn);
+
     mX:= hwFloat2Float(Me^.X);
     mY:= hwFloat2Float(Me^.Y);
     ap.Time:= 0;
@@ -224,14 +228,32 @@
                 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) and (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) > 21) 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)) < 22)
+                    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);
+            // Try to prevent AI from thinking firing into water will cause a drowning
+            if (EY < cWaterLine-5) and (Timer > 0) and (Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) > 21) then exit(BadTurn);
             if Level = 1 then
                 value:= RateExplosion(Me, EX, EY, 101, afTrackFall or afErasesLand)
             else value:= RateExplosion(Me, EX, EY, 101);
-            if value = 0 then
-                value:= 1024 - Metric(Targ.X, Targ.Y, EX, EY) div 64;
             if valueResult <= value then
                 begin
                 ap.Angle:= DxDy2AttackAnglef(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
@@ -239,7 +261,7 @@
                 ap.ExplR:= 100;
                 ap.ExplX:= EX;
                 ap.ExplY:= EY;
-                valueResult:= value
+                valueResult:= value-2500 // trying to make it slightly less attractive than a bazooka, to prevent waste.  AI could use awareness of weapon count
                 end;
             end
     until rTime > 4250;