AI: Add aiGravity and aiGravityf variables
authorWuzzy <Wuzzy2@mail.ru>
Mon, 06 Jul 2020 14:51:24 +0200
changeset 15712 c4d7eb75fd8a
parent 15711 975232e840c7
child 15713 c6675acd3c82
AI: Add aiGravity and aiGravityf variables
hedgewars/uAI.pas
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
--- a/hedgewars/uAI.pas	Mon Jul 06 14:43:19 2020 +0200
+++ b/hedgewars/uAI.pas	Mon Jul 06 14:51:24 2020 +0200
@@ -106,6 +106,8 @@
 begin
 BotLevel:= Me^.Hedgehog^.BotLevel;
 aiWindSpeed:= hwFloat2Float(cWindSpeed);
+aiGravity:= cGravity;
+aiGravityf:= cGravityf;
 aiLaserSighting:= (cLaserSighting) or (HHHasAmmo(Me^.Hedgehog^, amLaserSight) > 0);
 useThisActions:= false;
 Me^.AIHints:= Me^.AIHints and (not aihAmmosChanged);
@@ -310,7 +312,7 @@
     AddAction(Actions, aia_Weapon, Longword(amNothing), 100 + random(200), 0, 0);
 
 if ((CurrentHedgehog^.MultiShootAttacks = 0) or ((Ammoz[Me^.Hedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoMoveAfter) = 0))
-    and (CurrentHedgehog^.Effects[heArtillery] = 0) and (cGravityf <> 0) then
+    and (CurrentHedgehog^.Effects[heArtillery] = 0) and (aiGravityf <> 0) then
     begin
     tmp:= random(2) + 1;
     Push(Actions, Me^, tmp);
--- a/hedgewars/uAIAmmoTests.pas	Mon Jul 06 14:43:19 2020 +0200
+++ b/hedgewars/uAIAmmoTests.pas	Mon Jul 06 14:51:24 2020 +0200
@@ -31,6 +31,8 @@
     amtest_NoInvulnerable  = $00000040; // don't use invulnerable with this with ammo
 
 var aiWindSpeed: real;
+    aiGravity: hwFloat;
+    aiGravityf: real;
     aiLaserSighting: boolean;
 
 type TAttackParams = record
@@ -179,7 +181,7 @@
     if (WorldEdge = weWrap) and (random(2)=0) then
          Vx:= - aiWindSpeed * rTime * 0.5 + (targXWrap + AIrndSign(2) + AIrndOffset(Targ, Level) - mX) / rTime
     else Vx:= - aiWindSpeed * rTime * 0.5 + (Targ.Point.X + AIrndSign(2) + AIrndOffset(Targ, Level) - mX) / rTime;
-    Vy:= cGravityf * rTime * 0.5 - (Targ.Point.Y + 1 - mY) / rTime;
+    Vy:= aiGravityf * rTime * 0.5 - (Targ.Point.Y + 1 - mY) / rTime;
     r:= sqr(Vx) + sqr(Vy);
     if not (r > 1) then
         begin
@@ -195,7 +197,7 @@
             y:= y + dY;
             dX:= dX + aiWindSpeed;
             //dX:= CheckBounce(x,dX);
-            dY:= dY + cGravityf;
+            dY:= dY + aiGravityf;
             dec(t)
         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 5))) or (t < -cExtraTime);
@@ -240,7 +242,7 @@
     repeat
         x:= x + dx;
         y:= y + dy;
-        dy:= dy + cGravityf;
+        dy:= dy + aiGravityf;
         f:= ((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
            ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 5));
         dec(t)
@@ -369,7 +371,7 @@
         if (WorldEdge = weWrap) and (random(2)=0) then
              Vx:= - aiWindSpeed * rTime * 0.5 + (targXWrap + AIrndSign(2) - mX) / rTime
         else Vx:= - aiWindSpeed * rTime * 0.5 + (Targ.Point.X + AIrndSign(2) - mX) / rTime;
-        Vy:= cGravityf * rTime * 0.5 - (Targ.Point.Y - 35 - mY) / rTime;
+        Vy:= aiGravityf * rTime * 0.5 - (Targ.Point.Y - 35 - mY) / rTime;
         r:= sqr(Vx) + sqr(Vy);
         if not (r > 1) then
             begin
@@ -383,7 +385,7 @@
                 x:= x + dX;
                 y:= y + dY;
                 dX:= dX + aiWindSpeed;
-                dY:= dY + cGravityf;
+                dY:= dY + aiGravityf;
                 dec(t)
             until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
                    ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 5))) or (y > cWaterLine);
@@ -535,7 +537,7 @@
     if (WorldEdge = weWrap) and (random(2)=0) then
          Vx:= - aiWindSpeed * rTime * 0.5 + ((targXWrap + AIrndSign(2)) - meX) / rTime
     else Vx:= - aiWindSpeed * rTime * 0.5 + ((Targ.Point.X + AIrndSign(2)) - meX) / rTime;
-    Vy:= cGravityf * rTime * 0.5 - (Targ.Point.Y - meY) / rTime;
+    Vy:= aiGravityf * rTime * 0.5 - (Targ.Point.Y - meY) / rTime;
     r:= sqr(Vx) + sqr(Vy);
     if not (r > 1) then
         begin
@@ -549,7 +551,7 @@
             x:= x + dX;
             y:= y + dY;
             dX:= dX + aiWindSpeed;
-            dY:= dY + cGravityf;
+            dY:= dY + aiGravityf;
             dec(t)
         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 5))) or (t <= 0);
@@ -605,7 +607,7 @@
          Vx:= (Targ.Point.X + AIrndSign(2) + AIrndOffset(Targ, Level) - meX) / rTime;
     if (GameFlags and gfMoreWind) <> 0 then
          Vx:= -(aiWindSpeed / Density) * rTime * 0.5 + Vx;
-    Vy:= cGravityf * rTime * 0.5 - (Targ.Point.Y + 1 - meY) / rTime;
+    Vy:= aiGravityf * rTime * 0.5 - (Targ.Point.Y + 1 - meY) / rTime;
     r:= sqr(Vx) + sqr(Vy);
 
     if not (r > 1) then
@@ -622,7 +624,7 @@
                 dX:= dX + aiWindSpeed / Density;
 
             y:= y + dY;
-            dY:= dY + cGravityf;
+            dY:= dY + aiGravityf;
             dec(t)
         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 5))) or (t < -timeLimit);
@@ -690,7 +692,7 @@
          Vx:= (Targ.Point.X + AIrndOffset(Targ, Level) - meX) / (TestTime + tDelta);
     if (GameFlags and gfMoreWind) <> 0 then
          Vx:= -(aiWindSpeed / Density) * (TestTime + tDelta) * 0.5 + Vx;
-    Vy:= cGravityf * ((TestTime + tDelta) div 2) - (Targ.Point.Y - meY) / (TestTime + tDelta);
+    Vy:= aiGravityf * ((TestTime + tDelta) div 2) - (Targ.Point.Y - meY) / (TestTime + tDelta);
     r:= sqr(Vx) + sqr(Vy);
     if not (r > 1) then
         begin
@@ -705,7 +707,7 @@
             if (GameFlags and gfMoreWind) <> 0 then
                 dX:= dX + aiWindSpeed / Density;
             y:= y + dY;
-            dY:= dY + cGravityf;
+            dY:= dY + aiGravityf;
             dec(t)
         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 5))) or (t = 0);
@@ -759,7 +761,7 @@
         Vx:= ((Targ.Point.X+10) - meX) / (TestTime + tDelta)
     else
         Vx:= ((Targ.Point.X-10) - meX) / (TestTime + tDelta);
-    Vy:= cGravityf * ((TestTime + tDelta) div 2) - ((Targ.Point.Y-50) - meY) / (TestTime + tDelta);
+    Vy:= aiGravityf * ((TestTime + tDelta) div 2) - ((Targ.Point.Y-50) - meY) / (TestTime + tDelta);
     r:= sqr(Vx)+sqr(Vy);
     if not (r > 1) then
         begin
@@ -773,7 +775,7 @@
         if (GameFlags and gfMoreWind) <> 0 then
             dX:= dX + aiWindSpeed / Density;
         y:= y + dY;
-        dY:= dY + cGravityf;
+        dY:= dY + aiGravityf;
         dec(t)
     until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
            ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 5))) or (t = 0);
@@ -827,7 +829,7 @@
     if (GameFlags and gfMoreWind) <> 0 then
         Vx:= -(aiWindSpeed / Density) * (TestTime + tDelta) * 0.5 + Vx;
 
-    Vy:= cGravityf * ((TestTime + tDelta) div 2) - ((Targ.Point.Y-50) - meY) / (TestTime + tDelta);
+    Vy:= aiGravityf * ((TestTime + tDelta) div 2) - ((Targ.Point.Y-50) - meY) / (TestTime + tDelta);
     r:= sqr(Vx)+sqr(Vy);
     if not (r > 1) then
         begin
@@ -842,7 +844,7 @@
             if (GameFlags and gfMoreWind) <> 0 then
                  dX:= dX + aiWindSpeed / Density;
             y:= y + dY;
-            dY:= dY + cGravityf;
+            dY:= dY + aiGravityf;
             dec(t)
        until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 6)) or
                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 6))) or (t = 0);
@@ -874,8 +876,8 @@
     var A, B, D, T: real;
         C: LongInt;
     begin
-        A:= sqr(cGravityf);
-        B:= - cGravityf * (TY - MY) - 1;
+        A:= sqr(aiGravityf);
+        B:= - aiGravityf * (TY - MY) - 1;
         C:= sqr(TY - MY) + sqr(TX - MX);
         D:= sqr(B) - A * C;
         if D >= 0 then
@@ -916,7 +918,7 @@
     Vx:= (Targ.Point.X - meX) / TestTime;
     if (GameFlags and gfMoreWind) <> 0 then
         Vx:= -(aiWindSpeed / Density) * TestTime * 0.5 + Vx;
-    Vy:= cGravityf * (TestTime div 2) - (Targ.Point.Y - meY) / TestTime;
+    Vy:= aiGravityf * (TestTime div 2) - (Targ.Point.Y - meY) / TestTime;
 
     x:= meX;
     dX:= Vx;
@@ -928,7 +930,7 @@
         if (GameFlags and gfMoreWind) <> 0 then
             dX:= dX + aiWindSpeed / Density;
         y:= y + dY;
-        dY:= dY + cGravityf;
+        dY:= dY + aiGravityf;
         EX:= trunc(x);
         EY:= trunc(y);
     until (((Me = CurrentHedgehog^.Gear) and TestColl(EX, EY, 4)) or
@@ -1408,7 +1410,7 @@
 Flags:= Flags; // avoid compiler hint
 ap.ExplR:= 0;
 ap.Time:= 0;
-if (Level > 3) or (cGravityf = 0) then
+if (Level > 3) or (aiGravityf = 0) then
     exit(BadTurn);
 
 ap.Angle:= 0;
@@ -1417,7 +1419,7 @@
 
 bombsSpeed:= hwFloat2Float(cBombsSpeed);
 X:= Targ.Point.X - 135 - cShift; // hh center - cShift
-X:= X - bombsSpeed * sqrt(((Targ.Point.Y + 128) * 2) / cGravityf);
+X:= X - bombsSpeed * sqrt(((Targ.Point.Y + 128) * 2) / aiGravityf);
 Y:= topY - 300;
 
 dX:= bombsSpeed;
@@ -1436,7 +1438,7 @@
     if (GameFlags and gfMoreWind) <> 0 then
         dX:= dX + aiWindSpeed / Density;
     Y:= Y + dY;
-    dY:= dY + cGravityf;
+    dY:= dY + aiGravityf;
     fexit:= true;
 
     for i:= 0 to 9 do
@@ -1538,7 +1540,7 @@
 begin
 Flags:= Flags; // avoid compiler hint
 ap.ExplR:= 0;
-if (Level > 3) or (cGravityf = 0) then
+if (Level > 3) or (aiGravityf = 0) then
     exit(BadTurn);
 
 ap.Angle:= 0;
@@ -1547,7 +1549,7 @@
 
 bombsSpeed:= hwFloat2Float(cBombsSpeed);
 X:= Targ.Point.X - 135 - cShift; // hh center - cShift
-X:= X - bombsSpeed * sqrt(((Targ.Point.Y + 128) * 2) / cGravityf);
+X:= X - bombsSpeed * sqrt(((Targ.Point.Y + 128) * 2) / aiGravityf);
 Y:= topY - 300;
 
 valueResult:= 0;
@@ -1576,7 +1578,7 @@
             drillY:= drillY + dY;
             if (GameFlags and gfMoreWind) <> 0 then
                 dX:= dX + aiWindSpeed / Density;
-            dY:= dY + cGravityf;
+            dY:= dY + aiGravityf;
 
             if timerRuns then
                 dec(drillTimer);
@@ -1699,7 +1701,7 @@
 // so they are unsupported.
 // TODO: Implement mine strike for other values of MineTime
 // TODO: Teach AI to avoid hitting their own with mines
-if (Level > 3) or (cGravityf = 0) or (cMinesTime <> 0) then
+if (Level > 3) or (aiGravityf = 0) or (cMinesTime <> 0) then
     exit(BadTurn);
 
 ap.Angle:= 0;
@@ -1708,7 +1710,7 @@
 
 minesSpeed:= hwFloat2Float(cBombsSpeed);
 X:= Targ.Point.X - 135 - cShift; // hh center - cShift
-X:= X - minesSpeed * sqrt(((Targ.Point.Y + 128) * 2) / cGravityf);
+X:= X - minesSpeed * sqrt(((Targ.Point.Y + 128) * 2) / aiGravityf);
 Y:= topY - 300;
 dX:= minesSpeed;
 dY:= 0;
@@ -1726,7 +1728,7 @@
     if (GameFlags and (gfMoreWind or gfInfAttack)) <> 0 then
         dX:= dX + aiWindSpeed / Density;
     Y:= Y + dY;
-    dY:= dY + cGravityf;
+    dY:= dY + aiGravityf;
     fexit:= true;
 
     for i:= 0 to 9 do
@@ -1805,7 +1807,7 @@
          Vx:= (Targ.Point.X + AIrndSign(2) + AIrndOffset(Targ, Level) - meX) / rTime;
     if (GameFlags and gfMoreWind) <> 0 then
          Vx:= -(aiWindSpeed / Density) * rTime * 0.5 + Vx;
-    Vy:= cGravityf * rTime * 0.5 - (Targ.Point.Y + 1 - meY) / rTime;
+    Vy:= aiGravityf * rTime * 0.5 - (Targ.Point.Y + 1 - meY) / rTime;
     r:= sqr(Vx) + sqr(Vy);
 
     if not (r > 1) then
@@ -1822,7 +1824,7 @@
                 dX:= dX + aiWindSpeed / Density;
 
             y:= y + dY;
-            dY:= dY + cGravityf;
+            dY:= dY + aiGravityf;
             dec(t)
         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 2)) or
                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 2))) or (t < -timeLimit);
@@ -1863,7 +1865,7 @@
 Flags:= Flags; // avoid compiler hint
 ap.ExplR:= 0;
 ap.Time:= 0;
-if (cGravityf <= 0) then
+if (aiGravityf <= 0) then
     exit(BadTurn);
 
 if (Level > 2) then
@@ -2098,7 +2100,7 @@
     if (GameFlags and gfMoreWind) <> 0 then
         dx:= dx + aiWindSpeed / Density;
     x:= x + dx;
-    dy:= dy + cGravityf;
+    dy:= dy + aiGravityf;
     y:= y + dy;
 
     if TestColl(trunc(x), trunc(y), 3) then
@@ -2148,7 +2150,7 @@
     if (GameFlags and gfMoreWind) <> 0 then
          dx:= dx + aiWindSpeed / Density;
     x:= x + dx;
-    dy:= dy + cGravityf;
+    dy:= dy + aiGravityf;
     y:= y + dy;
     if ((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 2)) or
         ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 2)) then
@@ -2213,7 +2215,7 @@
          Vx:= (Targ.Point.X - meX) / rTime;
     if (GameFlags and gfMoreWind) <> 0 then
          Vx:= -(aiWindSpeed / Density) * rTime * 0.5 + Vx;
-    Vy:= cGravityf * rTime * 0.5 - (Targ.Point.Y + 1 - meY) / rTime;
+    Vy:= aiGravityf * rTime * 0.5 - (Targ.Point.Y + 1 - meY) / rTime;
     r:= sqr(Vx) + sqr(Vy);
 
     if not (r > 1) then
@@ -2230,7 +2232,7 @@
                 dX:= dX + aiWindSpeed / Density;
 
             y:= y + dY;
-            dY:= dY + cGravityf;
+            dY:= dY + aiGravityf;
             dec(t)
         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 7)) or
                ((Me <> CurrentHedgehog^.Gear) and TestCollExcludingMe(Me^.Hedgehog^.Gear, trunc(x), trunc(y), 7))) or (t < -timeLimit);
--- a/hedgewars/uAIMisc.pas	Mon Jul 06 14:43:19 2020 +0200
+++ b/hedgewars/uAIMisc.pas	Mon Jul 06 14:51:24 2020 +0200
@@ -108,7 +108,7 @@
 var dmgMod: real = 1.0;
 
 implementation
-uses uCollisions, uVariables, uUtils, uGearsUtils;
+uses uCollisions, uVariables, uUtils, uGearsUtils, uAIAmmoTests;
 
 var
     KnownExplosion: record
@@ -447,7 +447,7 @@
         x:= CheckWrap(x);
         x:= x + dX;
         y:= y + dY;
-        dY:= dY + cGravityf;
+        dY:= dY + aiGravityf;
         skipLandCheck:= skipLandCheck and (r <> 0) and (abs(eX-x) + abs(eY-y) < r) and ((abs(eX-x) < rCorner) or (abs(eY-y) < rCorner));
         if not skipLandCheck and TestCollExcludingObjects(trunc(x), trunc(y), Target.Radius) then
             with Target do
@@ -494,7 +494,7 @@
         x:= CheckWrap(x);
         x:= x + dX;
         y:= y + dY;
-        dY:= dY + cGravityf;
+        dY:= dY + aiGravityf;
 
 {        if ((trunc(y) and LAND_HEIGHT_MASK) = 0) and ((trunc(x) and LAND_WIDTH_MASK) = 0) then
             begin
@@ -885,11 +885,11 @@
                     begin
 
                     if (WorldEdge <> weWrap) or (not (hwAbs(meX - int2hwFloat(pX)) > int2hwFloat(cSeductionDist))) then
-                        dX:= _50 * cGravity * (meX - int2hwFloat(pX)) / _25
+                        dX:= _50 * aiGravity * (meX - int2hwFloat(pX)) / _25
                     else if (not (hwAbs(meX + int2hwFloat((RightX-LeftX) - pX)) > int2hwFloat(cSeductionDist))) then
-                        dX:= _50 * cGravity * (meX + (int2hwFloat((RightX-LeftX) - pX))) / _25
+                        dX:= _50 * aiGravity * (meX + (int2hwFloat((RightX-LeftX) - pX))) / _25
                     else
-                        dX:= _50 * cGravity * (meX - (int2hwFloat((RightX-LeftX) - pX))) / _25;
+                        dX:= _50 * aiGravity * (meX - (int2hwFloat((RightX-LeftX) - pX))) / _25;
                     dY:= -_450 * cMaxWindSpeed * 2;
 
 
@@ -1069,7 +1069,7 @@
         if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then SetLittle(Gear^.dX);
             Gear^.X:= Gear^.X + Gear^.dX;
         inc(GoInfo.Ticks);
-        Gear^.dY:= Gear^.dY + cGravity;
+        Gear^.dY:= Gear^.dY + aiGravity;
         if Gear^.dY > _0_4 then
             exit(false);
         if (Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then
@@ -1135,7 +1135,7 @@
     if (Gear^.State and gstMoving) <> 0 then
         begin
         inc(GoInfo.Ticks);
-        Gear^.dY:= Gear^.dY + cGravity;
+        Gear^.dY:= Gear^.dY + aiGravity;
         if Gear^.dY > _0_4 then
             begin
             GoInfo.FallPix:= 0;