Fix CheckWorldWrap not correctly checking for bounce edge. Also fix teleport @ bounce edge
authorWuzzy <Wuzzy2@mail.ru>
Sat, 28 Oct 2017 04:53:21 +0200
changeset 12794 28782e03b8f0
parent 12793 8aa82e350b8e
child 12795 abc9a99418cc
Fix CheckWorldWrap not correctly checking for bounce edge. Also fix teleport @ bounce edge
ChangeLog.txt
hedgewars/uGearsHandlersMess.pas
hedgewars/uIO.pas
hedgewars/uUtils.pas
--- a/ChangeLog.txt	Fri Oct 27 19:54:27 2017 +0200
+++ b/ChangeLog.txt	Sat Oct 28 04:53:21 2017 +0200
@@ -45,7 +45,7 @@
  * Fixed air strikes drops being off-center
  * Fixed hedgehogs getting hurt while firing deagle / sniper rifle bullet in certain situations
  * Fixed bee, mine, sticky mine, air mine, seduction, resurrector not working correctly across wrap world edge
- * Fixed teleportation being able to teleport in land if you clicked across the wrap world edge
+ * Fixed teleportation being able to teleport in land if you clicked across the wrap or bounce world edge
  * Fixed turn not ending when sticky mine was trapped on rubberband
  * Rope is now destroyed when attempting to shoot it through wrap or bouncy world edge
  * Fixed possible to move rope angle below 0° while having secondary weapon selected
--- a/hedgewars/uGearsHandlersMess.pas	Fri Oct 27 19:54:27 2017 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Sat Oct 28 04:53:21 2017 +0200
@@ -2872,7 +2872,8 @@
     valid:= false;
 
     lx:= Gear^.Target.X - SpritesData[sprHHTelepMask].Width  div 2; // left
-    lx:= CalcWorldWrap(lx, SpritesData[sprHHTelepMask].Width); // Take world edge into account
+    if WorldEdge <> weBounce then
+        lx:= CalcWorldWrap(lx, SpritesData[sprHHTelepMask].Width div 2); // Take world edge into account
     ty:= Gear^.Target.Y - SpritesData[sprHHTelepMask].Height div 2; // top
 
     // remember original target location
@@ -2888,6 +2889,9 @@
         dec(Gear^.Target.Y);
         end;
 
+    if (WorldEdge = weBounce) and ((Gear^.Target.X < LeftX) or (Gear^.Target.X > RightX)) then
+        valid:= false;
+
     if not valid then
         begin
         HHGear^.Message := HHGear^.Message and (not gmAttack);
--- a/hedgewars/uIO.pas	Fri Oct 27 19:54:27 2017 +0200
+++ b/hedgewars/uIO.pas	Sat Oct 28 04:53:21 2017 +0200
@@ -491,7 +491,8 @@
                 TargetPoint.X:= CursorPoint.X - WorldDx;
                 TargetPoint.Y:= cScreenHeight - CursorPoint.Y - WorldDy;
                 end;
-            TargetPoint.X:= CalcWorldWrap(TargetPoint.X, 0);
+            if (WorldEdge <> weBounce) then
+                TargetPoint.X:= CalcWorldWrap(TargetPoint.X, 0);
             SendIPCXY('p', TargetPoint.X, TargetPoint.Y);
             end
         else
--- a/hedgewars/uUtils.pas	Fri Oct 27 19:54:27 2017 +0200
+++ b/hedgewars/uUtils.pas	Sat Oct 28 04:53:21 2017 +0200
@@ -600,15 +600,19 @@
 function CalcWorldWrap(X, radius: LongInt): LongInt;
 begin
     if WorldEdge = weWrap then
-        if X < LongInt(leftX) then
-             X:= X + (LongInt(rightX) - LongInt(leftX))
-        else if X > LongInt(rightX) then
-             X:= X - (LongInt(rightX) - LongInt(leftX))
+        begin
+        if X < leftX then
+             X:= X + (rightX - leftX)
+        else if X > rightX then
+             X:= X - (rightX - leftX);
+        end
     else if WorldEdge = weBounce then
-        if X - radius < LongInt(leftX) then
-            X:= LongInt(leftX) + radius
-        else if X + radius > LongInt(rightX) then
-            X:= LongInt(rightX) - radius;
+        begin
+        if (X + radius) < leftX then
+            X:= leftX + radius
+        else if (X - radius) > rightX then
+            X:= rightX - radius;
+        end;
     CalcWorldWrap:= X;
 end;