hedgewars/uAIAmmoTests.pas
changeset 39 b78e7185ed13
parent 37 2b7f2a43b999
child 42 72ffe21f027c
--- a/hedgewars/uAIAmmoTests.pas	Thu Jan 05 22:55:45 2006 +0000
+++ b/hedgewars/uAIAmmoTests.pas	Sat Jan 07 15:21:44 2006 +0000
@@ -41,6 +41,7 @@
 function TestGrenade(Me, Targ: TPoint; Flags: Longword; out Time: Longword; out Angle, Power: integer): boolean;
 function TestBazooka(Me, Targ: TPoint; Flags: Longword; out Time: Longword; out Angle, Power: integer): boolean;
 function TestShotgun(Me, Targ: TPoint; Flags: Longword; out Time: Longword; out Angle, Power: integer): boolean;
+function TestDEagle(Me, Targ: TPoint; Flags: Longword; out Time: Longword; out Angle, Power: integer): boolean;
 
 type TAmmoTestProc = function (Me, Targ: TPoint; Flags: Longword; out Time: Longword; out Angle, Power: integer): boolean;
 const AmmoTests: array[TAmmoType] of
@@ -72,13 +73,16 @@
                     ( Test: nil;
                       Flags: 0;
                     ),
+                    ( Test: TestDEagle;
+                      Flags: 0;
+                    ),
                     ( Test: nil;
                       Flags: 0;
                     )
                     );
 
 implementation
-uses uMisc, uAIMisc;
+uses uMisc, uAIMisc, uLand;
 
 function TestGrenade(Me, Targ: TPoint; Flags: Longword; out Time: Longword; out Angle, Power: integer): boolean;
 var Vx, Vy, r: real;
@@ -198,5 +202,25 @@
 Result:= true
 end;
 
+function TestDEagle(Me, Targ: TPoint; Flags: Longword; out Time: Longword; out Angle, Power: integer): boolean;
+var Vx, Vy, x, y: real;
+    d: Longword;
+begin
+Time:= 0;
+Power:= 1;
+Vx:= (Targ.X - Me.X)/1024;
+Vy:= (Targ.Y - Me.Y)/1024;
+x:= Me.X;
+y:= Me.Y;
+Angle:= DxDy2Angle(Vx, -Vy);
+d:= 0;
+repeat
+  x:= x + vX;
+  y:= y + vY;
+  if ((round(x) and $FFFFF800) = 0)and((round(y) and $FFFFFC00) = 0)
+     and (Land[round(y), round(x)] <> 0) then inc(d);
+until (abs(Targ.X - x) + abs(Targ.Y - y) < 2) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
+Result:= d < 50
+end;
 
 end.