Ignore all objects for fall tracing with shove to avoid considering checkins as obstacles. many objects will get knocked by the kick anyway, so end result should be pretty good. Oh, and ditch the sniper rifle doubling.
authornemo
Sat, 09 Jun 2012 10:28:45 -0400
changeset 7208 62e36dc45098
parent 7206 ce46b56ae9f5
child 7210 2ff30b79d2b0
Ignore all objects for fall tracing with shove to avoid considering checkins as obstacles. many objects will get knocked by the kick anyway, so end result should be pretty good. Oh, and ditch the sniper rifle doubling.
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
--- a/hedgewars/uAIAmmoTests.pas	Sat Jun 09 09:53:15 2012 -0400
+++ b/hedgewars/uAIAmmoTests.pas	Sat Jun 09 10:28:45 2012 -0400
@@ -624,7 +624,7 @@
 
 if Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 5 then
     begin
-    fallDmg:= TraceShoveFall(Me, Targ.X, Targ.Y, vX * 0.00125 * 20, vY * 0.00125 * 20);
+    fallDmg:= TraceShoveFall(Targ.X, Targ.Y, vX * 0.00125 * 20, vY * 0.00125 * 20);
     if fallDmg < 0 then
         valueResult:= 204800
     else valueResult:= Max(0, (4 - d div 50) * trunc((7+fallDmg)*dmgMod) * 1024)
@@ -652,7 +652,7 @@
 
 dmg:= sqrt(sqr(Targ.X - x)+sqr(Targ.Y-y));
 t:= 1.5 / dmg;
-dmg:= dmg * 0.05; // div 40
+dmg:= dmg * 0.025; // div 40
 Vx:= (Targ.X - x) * t;
 Vy:= (Targ.Y - y) * t;
 ap.Angle:= DxDy2AttackAnglef(Vx, -Vy);
@@ -673,7 +673,7 @@
 
 if Abs(Targ.X - trunc(x)) + Abs(Targ.Y - trunc(y)) < 4 then
     begin
-    fallDmg:= TraceShoveFall(Me, Targ.X, Targ.Y, vX * 0.00166 * dmg, vY * 0.00166 * dmg);
+    fallDmg:= TraceShoveFall(Targ.X, Targ.Y, vX * 0.00166 * dmg, vY * 0.00166 * dmg);
     if fallDmg < 0 then
         TestSniperRifle:= BadTurn
     else 
--- a/hedgewars/uAIMisc.pas	Sat Jun 09 09:53:15 2012 -0400
+++ b/hedgewars/uAIMisc.pas	Sat Jun 09 10:28:45 2012 -0400
@@ -59,8 +59,9 @@
 
 function  RatePlace(Gear: PGear): LongInt;
 function  TestColl(x, y, r: LongInt): boolean; inline;
+function  TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
 function  TestCollExcludingMe(Me: PGear; x, y, r: LongInt): boolean; inline;
-function  TraceShoveFall(Me: PGear; x, y, dX, dY: Real): LongInt;
+function  TraceShoveFall(x, y, dX, dY: Real): LongInt;
 
 function  RateExplosion(Me: PGear; x, y, r: LongInt): LongInt; inline;
 function  RateExplosion(Me: PGear; x, y, r: LongInt; Flags: LongWord): LongInt;
@@ -236,6 +237,28 @@
     TestCollExcludingMe:= TestColl(x, y, r)
 end;
 
+function TestCollExcludingObjects(x, y, r: LongInt): boolean; inline;
+var b: boolean;
+begin
+    b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] and $FF00 <> 0);
+    if b then
+        exit(true);
+    
+    b:= (((x-r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] and $FF00 <> 0);
+    if b then
+        exit(true);
+    
+    b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] and $FF00 <> 0);
+    if b then
+        exit(true);
+    
+    b:= (((x+r) and LAND_WIDTH_MASK) = 0) and (((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] and $FF00 <> 0);
+    if b then
+        exit(true);
+    
+    TestCollExcludingObjects:= false;
+end;
+
 function TestColl(x, y, r: LongInt): boolean; inline;
 var b: boolean;
 begin
@@ -311,7 +334,7 @@
     end;
 end;
 
-function TraceShoveFall(Me: PGear; x, y, dX, dY: Real): LongInt;
+function TraceShoveFall(x, y, dX, dY: Real): LongInt;
 var dmg: LongInt;
 begin
     while true do
@@ -319,8 +342,7 @@
         x:= x + dX;
         y:= y + dY;
         dY:= dY + cGravityf;
-        // consider adding dX/dY calc here for fall damage
-        if TestCollExcludingMe(Me, trunc(x), trunc(y), cHHRadius) then
+        if TestCollExcludingObjects(trunc(x), trunc(y), cHHRadius) then
         begin
             if 0.4 < dY then
             begin
@@ -418,7 +440,7 @@
             begin
             if (Flags and afSetSkip <> 0) then skip:= true;
             if (Flags and afTrackFall <> 0) then 
-                fallDmg:= trunc(TraceShoveFall(Me, Point.x, Point.y - 2, dX, dY) * dmgMod);
+                fallDmg:= trunc(TraceShoveFall(Point.x, Point.y - 2, dX, dY) * dmgMod);
             if fallDmg < 0 then // drowning. score healthier hogs higher, since their death is more likely to benefit the AI
                 if Score > 0 then
                     inc(rate, KillScore + Score div 10)   // Add a bit of a bonus for bigger hog drownings