Fix laser sight wrapping sometimes wrapping too often
authorWuzzy <Wuzzy2@mail.ru>
Mon, 12 Oct 2020 00:46:19 +0200
changeset 15768 ff18f99f3f5d
parent 15767 bbcf037af2f2
child 15769 ed3c5c15dcbd
Fix laser sight wrapping sometimes wrapping too often
hedgewars/uGearsRender.pas
--- a/hedgewars/uGearsRender.pas	Thu Oct 08 20:38:19 2020 +0200
+++ b/hedgewars/uGearsRender.pas	Mon Oct 12 00:46:19 2020 +0200
@@ -549,8 +549,9 @@
                     ly:= ly + ay;
                     tx:= round(lx);
                     ty:= round(ly);
-                    // reached edge of land.
-                    if ((ty and LAND_HEIGHT_MASK) <> 0) and (((ty < LAND_HEIGHT) and (ay < 0)) or ((ty >= TopY) and (ay > 0))) then
+                    // reached top edge of land mask
+                    if ((ty and LAND_HEIGHT_MASK) <> 0) and (((ty < LAND_HEIGHT) and (ay < 0)) or ((ty >= TopY) and (ay > 0))) and
+                        (WorldEdge <> weWrap) and (WorldEdge <> weBounce) then
                         begin
                         // assume infinite beam. Extend it way out past camera
                         tx:= round(lx + ax * (max(LAND_WIDTH,4096) div 2));
@@ -573,16 +574,16 @@
                             // just stop
                             break;
 
-                    if ((tx and LAND_WIDTH_MASK) <> 0) and (((ax > 0) and (tx >= RightX)) or ((ax < 0) and (tx <= LeftX))) then
+                    // reached horizontal edge of land mask
+                    if ((tx and LAND_WIDTH_MASK) <> 0) and (((ax > 0) and (tx >= RightX)) or ((ax < 0) and (tx <= LeftX))) and
+                        (WorldEdge <> weWrap) and (WorldEdge <> weBounce) then
                         begin
-                        if (WorldEdge <> weWrap) and (WorldEdge <> weBounce) then
-                            // assume infinite beam. Extend it way out past camera
-                            begin
-                            tx:= round(lx + ax * (max(LAND_WIDTH,4096) div 2));
-                            ty:= round(ly + ay * (max(LAND_WIDTH,4096) div 2));
-                            end;
+                        // assume infinite beam. Extend it way out past camera
+                        tx:= round(lx + ax * (max(LAND_WIDTH,4096) div 2));
+                        ty:= round(ly + ay * (max(LAND_WIDTH,4096) div 2));
                         break;
                         end;
+
                     inWorldBounds := ((ty and LAND_HEIGHT_MASK) or (tx and LAND_WIDTH_MASK)) = 0;
                     end;