--- a/ChangeLog.txt Mon Jul 30 13:20:01 2018 +0200
+++ b/ChangeLog.txt Mon Jul 30 16:30:03 2018 +0200
@@ -12,6 +12,7 @@
* Fix hammer and pickhammer not digging correctly at wrap world edge
* Fix freezer ray not working through wrap world edge
* Fix freezer ray going through bounce world edge
+ * Laser sight now works properly through wrap world edge
* Fix extreme amounts of droplets when shooting with minigun into ocean world edge
* Fix hog being unable to walk after using sniper rifle without firing both shots
* Fix video recorder not working when game audio was disabled
--- a/hedgewars/uConsts.pas Mon Jul 30 13:20:01 2018 +0200
+++ b/hedgewars/uConsts.pas Mon Jul 30 16:30:03 2018 +0200
@@ -361,6 +361,8 @@
cMinPlayWidth = 200;
cWorldEdgeDist = 200;
+ cMaxLaserSightWraps = 1;
+
implementation
end.
--- a/hedgewars/uGearsRender.pas Mon Jul 30 13:20:01 2018 +0200
+++ b/hedgewars/uGearsRender.pas Mon Jul 30 16:30:03 2018 +0200
@@ -265,6 +265,7 @@
amt: TAmmoType;
sign, hx, hy, tx, ty, sx, sy, m: LongInt; // hedgehog, crosshair, temp, sprite, direction
dx, dy, ax, ay, aAngle, dAngle, hAngle, lx, ly: real; // laser, change
+ wraps: LongWord; // numbe of wraps for laser in world wrap
defaultPos, HatVisible: boolean;
HH: PHedgehog;
CurWeapon: PAmmo;
@@ -407,26 +408,52 @@
ty:= round(ly);
hx:= tx;
hy:= ty;
- while ((ty and LAND_HEIGHT_MASK) = 0) and
- ((tx and LAND_WIDTH_MASK) = 0) and
- (Land[ty, tx] = 0) do // TODO: check for constant variable instead
+ wraps:= 0;
+ while ((Land[ty, tx] and lfAll) = 0) do
begin
+ if wraps > cMaxLaserSightWraps then
+ break;
lx:= lx + ax;
ly:= ly + ay;
tx:= round(lx);
- ty:= round(ly)
- end;
- // reached edge of land. assume infinite beam. Extend it way out past camera
- if ((ty and LAND_HEIGHT_MASK) <> 0) or ((tx and LAND_WIDTH_MASK) <> 0) then
- begin
- tx:= round(lx + ax * (max(LAND_WIDTH,4096) div 2));
- ty:= round(ly + ay * (max(LAND_WIDTH,4096) div 2));
+ ty:= round(ly);
+ // reached edge of land.
+ if ((ty and LAND_HEIGHT_MASK) <> 0) then
+ begin
+ // 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;
+
+ if ((sign*m < 0) and (tx < LeftX)) or ((sign*m > 0) and (tx >= RightX)) then
+ if (WorldEdge = weWrap) then
+ // wrap beam
+ begin
+ if (sign*m) < 0 then
+ lx:= RightX - (ax - (lx - LeftX))
+ else
+ lx:= LeftX + (ax - (RightX - lx));
+ tx:= round(lx);
+ inc(wraps);
+ end
+ else if (WorldEdge = weBounce) then
+ // just stop
+ break;
+
+ if ((tx and LAND_WIDTH_MASK) <> 0) 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;
+ break;
+ end;
end;
- //if (abs(lx-tx)>8) or (abs(ly-ty)>8) then
- begin
- DrawLine(hx, hy, tx, ty, 1.0, $FF, $00, $00, $C0);
- end;
+ DrawLineWrapped(hx, hy, tx, ty, 1.0, (sign*m) < 0, wraps, $FF, $00, $00, $C0);
end;
// draw crosshair
CrosshairX := Round(hwRound(Gear^.X) + dx * 80 + GetLaunchX(HH^.CurAmmoType, sign * m, Gear^.Angle));