hedgewars/uAIAmmoTests.pas
changeset 70 82d93eeecebe
parent 66 9643d75baf1e
child 71 5f56c6979496
--- a/hedgewars/uAIAmmoTests.pas	Tue Jun 20 21:22:15 2006 +0000
+++ b/hedgewars/uAIAmmoTests.pas	Fri Jun 23 20:02:41 2006 +0000
@@ -4,6 +4,7 @@
 
 function TestBazooka(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
 function TestGrenade(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
+function TestShotgun(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
 
 type TAmmoTestProc = function (Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
 const AmmoTests: array[TAmmoType] of TAmmoTestProc =
@@ -11,7 +12,7 @@
 {amGrenade}       TestGrenade,
 {amBazooka}       TestBazooka,
 {amUFO}           nil,
-{amShotgun}       nil,
+{amShotgun}       TestShotgun,
 {amPickHammer}    nil,
 {amSkip}          nil,
 {amRope}          nil,
@@ -22,6 +23,7 @@
 
 implementation
 uses uMisc, uAIMisc;
+const BadTurn = Low(integer);
 
 function Metric(x1, y1, x2, y2: integer): integer;
 begin
@@ -49,13 +51,14 @@
       dY:= dY + cGravity;
       dec(t)
     until TestColl(round(x), round(y), 5) or (t <= 0);
-    Result:= RateExplosion(Me, round(x), round(y), 101) - Metric(Targ.X, Targ.Y, round(x), round(y)) div 16
+    Result:= RateExplosion(Me, round(x), round(y), 101);
+    if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64
     end;
 
 begin
 Time:= 0;
 rTime:= 10;
-Result:= Low(integer);
+Result:= BadTurn;
 repeat
   rTime:= rTime + 100 + random*250;
   Vx:= - cWindSpeed * rTime / 2 + (Targ.X - Me.X) / rTime;
@@ -76,7 +79,7 @@
 end;
 
 function TestGrenade(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
-const tDelta = 10;
+const tDelta = 24;
 var Vx, Vy, r: real;
     Score: integer;
     TestTime: Longword;
@@ -100,7 +103,7 @@
     end;
 
 begin
-Result:= Low(integer);
+Result:= BadTurn;
 TestTime:= 0;
 repeat
   inc(TestTime, 1000);
@@ -110,7 +113,7 @@
   if r <= 1 then
      begin
      Score:= CheckTrace;
-     if Result <= Score then
+     if Result < Score then
         begin
         r:= sqrt(r);
         Angle:= DxDy2AttackAngle(Vx, Vy);
@@ -122,4 +125,32 @@
 until (TestTime = 5000)
 end;
 
+function TestShotgun(Me: PGear; Targ: TPoint; out Time: Longword; out Angle, Power: integer): integer;
+var Vx, Vy, x, y: real;
+begin
+if Metric(round(Me.X), round(Me.Y), Targ.X, Targ.Y) < 80 then
+   begin
+   Result:= BadTurn;
+   exit
+   end;
+Time:= 0;
+Power:= 1;
+Vx:= (Targ.X - Me.X)/1024;
+Vy:= (Targ.Y - Me.Y)/1024;
+x:= Me.X;
+y:= Me.Y;
+Angle:= DxDy2AttackAngle(Vx, -Vy);
+repeat
+  x:= x + vX;
+  y:= y + vY;
+  if TestColl(round(x), round(y), 2) then
+     begin
+     Result:= RateExplosion(Me, round(x), round(y), 25) * 2;
+     if Result = 0 then Result:= - Metric(Targ.X, Targ.Y, round(x), round(y)) div 64;
+     exit
+     end
+until (abs(Targ.X - x) + abs(Targ.Y - y) < 4) or (x < 0) or (y < 0) or (x > 2048) or (y > 1024);
+Result:= BadTurn
+end;
+
 end.