Make GearsNear and CheckGearNear check gears across wrap world edge
This fixes hog detection of mine, sticky mine, resurrector, seduction and crate across the world edge.
Air mine is only partially fixed.
--- a/ChangeLog.txt Mon Oct 23 14:49:01 2017 +0200
+++ b/ChangeLog.txt Mon Oct 23 17:29:56 2017 +0200
@@ -36,9 +36,10 @@
* Gameplay fix: Hammer damage is now rounded down. This means it will cause NO DAMAGE to a hedgehog with less than 3 hp.
* Fixed screenshots being too bright if taken in quick succession
* Video recording functionality is restored
- * Fixed bee not being affected by wrap world edge while still being thrown
- * Fixed bee homing incorrectly when target is across wrap world edge
+ * Fixed bee, mine, sticky mine, air mine, seduction, resurrector not working correctly across wrap world edge
* Rope is now destroyed when attempting to shoot it through wrap or bouncy world edge
+ * Fixed teleportation being able to teleport in land if you clicked in the "dark" area of the wrap world edge
+ * Fixed failure to collect crate across wrap world edge
* Fixed turn not ending when sticky mine was trapped on rubberband
* Fixed molotov cocktails bouncing off vertically off rubber
* Fixed sniper rifle disabling laser sight utility after using
@@ -53,7 +54,6 @@
* Fixed incorrect time box tooltip when in Sudden Death
* Fixed cake taking over 200 seconds to explode when its stuck and can't move
* Fixed Birdy descending into water when hog took damage or died before it got picked up
- * Fixed teleportation being able to teleport in land if you clicked in the "dark" area of the wrap world edge
* Fixed team getting infinite ammo when stockpiling >= 100 ammo (max. finite ammo is now limited to 99)
* Fixed short sound effect breakdown right after using a time box
* Fixed sticky mine sound sometimes playing when shooting portable portal device when a sticky mine is placed on terrain
--- a/hedgewars/uGearsHandlersMess.pas Mon Oct 23 14:49:01 2017 +0200
+++ b/hedgewars/uGearsHandlersMess.pas Mon Oct 23 17:29:56 2017 +0200
@@ -3417,7 +3417,12 @@
with hogs.ar^[i]^ do
if (hogs.ar^[i] <> CurrentHedgehog^.Gear) and (Hedgehog^.Effects[heFrozen] = 0) then
begin
- dX:= _50 * cGravity * (Gear^.X - X) / _25;
+ if (WorldEdge <> weWrap) or (not (hwAbs(Gear^.X - X) > int2hwFloat(Gear^.Radius))) then
+ dX:= _50 * cGravity * (Gear^.X - X) / _25
+ else if (not (hwAbs(Gear^.X + int2hwFloat(RightX-LeftX) - X) > int2hwFloat(Gear^.Radius))) then
+ dX:= _50 * cGravity * ((Gear^.X + int2hwFloat(RightX-LeftX)) - X) / _25
+ else
+ dX:= _50 * cGravity * ((Gear^.X - int2hwFloat(RightX-LeftX)) - X) / _25;
dY:= -_450 * cGravity;
Active:= true;
end
--- a/hedgewars/uGearsUtils.pas Mon Oct 23 14:49:01 2017 +0200
+++ b/hedgewars/uGearsUtils.pas Mon Oct 23 17:29:56 2017 +0200
@@ -1003,7 +1003,10 @@
while t <> nil do
begin
if (t <> Gear) and (t^.Kind = Kind) then
- if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then
+ if (not ((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1)) or
+ ((WorldEdge = weWrap) and (
+ (not ((hwSqr(Gear^.X - int2hwFloat(RightX-LeftX) - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1)) or
+ (not ((hwSqr(Gear^.X + int2hwFloat(RightX-LeftX) - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1)))) then
begin
CheckGearNear:= t;
exit;
@@ -1392,6 +1395,7 @@
var
t: PGear;
s: Longword;
+ xc, xc_left, xc_right, yc: hwFloat;
begin
r:= r*r;
s:= 0;
@@ -1399,15 +1403,22 @@
t := GearsList;
while t <> nil do
begin
- if (t^.Kind = Kind)
- and ((X - t^.X)*(X - t^.X) + (Y - t^.Y)*(Y-t^.Y) < int2hwFloat(r)) then
- begin
- inc(s);
- SetLength(GearsNearArray, s);
- GearsNearArray[s - 1] := t;
- end;
- t := t^.NextGear;
- end;
+ xc:= (X - t^.X)*(X - t^.X);
+ xc_left:= ((X - int2hwFloat(RightX-LeftX)) - t^.X)*((X - int2hwFloat(RightX-LeftX)) - t^.X);
+ xc_right := ((X + int2hwFloat(RightX-LeftX)) - t^.X)*((X + int2hwFloat(RightX-LeftX)) - t^.X);
+ yc:= (Y - t^.Y)*(Y - t^.Y);
+ if (t^.Kind = Kind)
+ and ((xc + yc < int2hwFloat(r))
+ or ((WorldEdge = weWrap) and
+ ((xc_left + yc < int2hwFloat(r)) or
+ (xc_right + yc < int2hwFloat(r))))) then
+ begin
+ inc(s);
+ SetLength(GearsNearArray, s);
+ GearsNearArray[s - 1] := t;
+ end;
+ t := t^.NextGear;
+ end;
GearsNear.size:= s;
GearsNear.ar:= @GearsNearArray