basic AI bazooka wrapping.
authornemo
Fri, 17 Aug 2018 20:13:33 -0400
changeset 13673 2b194214732d
parent 13672 bfc2727daead
child 13674 c6ee1b0b957f
basic AI bazooka wrapping.
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
--- a/hedgewars/uAIAmmoTests.pas	Thu Aug 16 19:41:54 2018 +0300
+++ b/hedgewars/uAIAmmoTests.pas	Fri Aug 17 20:13:33 2018 -0400
@@ -142,7 +142,7 @@
     rTime: LongInt;
     EX, EY: LongInt;
     valueResult: LongInt;
-    x, y, dX, dY: real;
+    targXWrap, x, y, dX, dY: real;
     t: LongInt;
     value: LongInt;
 begin
@@ -151,10 +151,15 @@
 ap.Time:= 0;
 rTime:= 350;
 ap.ExplR:= 0;
+if (Targ.Point.X < mX) then
+     targXWrap:= Targ.Point.X + (RightX-LeftX)
+else targXWrap:= Targ.Point.X - (RightX-LeftX);
 valueResult:= BadTurn;
 repeat
     rTime:= rTime + 300 + Level * 50 + random(300);
-    Vx:= - windSpeed * rTime * 0.5 + (Targ.Point.X + AIrndSign(2) - mX) / rTime;
+    if (WorldEdge = weWrap) and (random(2)=0) then
+         Vx:= - windSpeed * rTime * 0.5 + (Targ.Point.X + AIrndSign(2) - mX) / rTime
+    else Vx:= - windSpeed * rTime * 0.5 + (targXWrap + AIrndSign(2) - mX) / rTime;
     Vy:= cGravityf * rTime * 0.5 - (Targ.Point.Y + 1 - mY) / rTime;
     r:= sqr(Vx) + sqr(Vy);
     if not (r > 1) then
@@ -165,9 +170,12 @@
         dY:= -Vy;
         t:= rTime;
         repeat
+            x:= CheckWrap(x);
             x:= x + dX;
+
             y:= y + dY;
             dX:= dX + windSpeed;
+            //dX:= CheckBounce(x,dX);
             dY:= dY + cGravityf;
             dec(t)
         until (((Me = CurrentHedgehog^.Gear) and TestColl(trunc(x), trunc(y), 5)) or
--- a/hedgewars/uAIMisc.pas	Thu Aug 16 19:41:54 2018 +0300
+++ b/hedgewars/uAIMisc.pas	Fri Aug 17 20:13:33 2018 -0400
@@ -76,6 +76,7 @@
 procedure AwareOfExplosion(x, y, r: LongInt); inline;
 
 function  RatePlace(Gear: PGear): LongInt;
+function  CheckWrap(x: real): real; inline;
 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;
@@ -330,6 +331,16 @@
     RatePlace:= rate;
 end;
 
+function CheckWrap(x: real): real; inline;
+begin
+    if WorldEdge = weWrap then
+        if (x < leftX) then
+             x:= x + (rightX - leftX)
+        else if x > rightX then    
+             x:= x - (rightX - leftX);
+    CheckWrap:= x;
+end;
+
 function CheckBounds(x, y, r: Longint): boolean; inline;
 begin
     CheckBounds := (((x-r) and LAND_WIDTH_MASK) = 0) and
@@ -412,6 +423,7 @@
     rCorner:= r * 0.75;
     while true do
         begin
+        x:= CheckWrap(x);
         x:= x + dX;
         y:= y + dY;
         dY:= dY + cGravityf;
@@ -458,6 +470,7 @@
 //v:= random($FFFFFFFF);
     while true do
         begin
+        x:= CheckWrap(x);
         x:= x + dX;
         y:= y + dY;
         dY:= dY + cGravityf;
@@ -519,6 +532,7 @@
     pX, pY, dX, dY: real;
     hadSkips: boolean;
 begin
+x:= round(CheckWrap(real(x)));
 fallDmg:= 0;
 rate:= 0;
 // add our virtual position