AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
authornemo
Wed, 11 Nov 2009 21:54:28 +0000
changeset 2616 6e2b341dc408
parent 2615 b86abe068708
child 2617 ef0d93cd61b2
AI fire w/o moving for artillery. Needs testing, but seems to work quickly and w/o AI screwups.
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
--- a/hedgewars/uAIAmmoTests.pas	Wed Nov 11 19:48:16 2009 +0000
+++ b/hedgewars/uAIAmmoTests.pas	Wed Nov 11 21:54:28 2009 +0000
@@ -120,7 +120,7 @@
       dX:= dX + cWindSpeed;
       dY:= dY + cGravity;
       dec(t)
-    until TestColl(hwRound(x), hwRound(y), 5) or (t <= 0);
+    until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t <= 0);
     EX:= hwRound(x);
     EY:= hwRound(y);
     Result:= RateExplosion(Me, EX, EY, 101);
@@ -174,7 +174,7 @@
       y:= y + dY;
       dY:= dY + cGravity;
       dec(t)
-    until TestColl(hwRound(x), hwRound(y), 5) or (t = 0);
+    until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t = 0);
     EX:= hwRound(x);
     EY:= hwRound(y);
     if t < 50 then CheckTrace:= RateExplosion(Me, EX, EY, 101)
@@ -228,7 +228,7 @@
 			dY:= dY + cGravity;
 			EX:= hwRound(x);
 			EY:= hwRound(y);
-		until TestColl(EX, EY, 5) or (EY > 1000);
+		until TestCollExcludingMe(Me, EX, EY, 5) or (EY > 1000);
 
 		if (EY < 1000) and not dY.isNegative then
 			begin
@@ -315,7 +315,7 @@
   y:= y + vY;
   rx:= hwRound(x);
   ry:= hwRound(y);
-  if TestColl(rx, ry, 2) then
+  if TestCollExcludingMe(Me, rx, ry, 2) then
      begin
      x:= x + vX * 8;
      y:= y + vY * 8;
--- a/hedgewars/uAIMisc.pas	Wed Nov 11 19:48:16 2009 +0000
+++ b/hedgewars/uAIMisc.pas	Wed Nov 11 21:54:28 2009 +0000
@@ -41,6 +41,7 @@
 procedure FillBonuses(isAfterAttack: boolean);
 procedure AwareOfExplosion(x, y, r: LongInt);
 function RatePlace(Gear: PGear): LongInt;
+function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean;
 function TestColl(x, y, r: LongInt): boolean;
 function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt;
 function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt;
@@ -174,6 +175,22 @@
 	RatePlace:= Result
 end;
 
+// Wrapper to test various approaches.  If it works reasonably, will just replace.
+// Right now, converting to hwFloat is a tad inefficient since the x/y were hwFloat to begin with...
+function TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean;
+var MeX, MeY: LongInt;
+begin
+    if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then
+        begin
+        MeX:= hwRound(Me^.X);
+        MeY:= hwRound(Me^.Y);
+        // We are still inside the hog. Skip radius test
+        if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and 
+           ((Land[y, x] and $FF00) = 0) then exit(false);
+        end;
+    exit(TestColl(x, y, r))
+end;
+
 function TestColl(x, y, r: LongInt): boolean;
 var b: boolean;
 begin