Fix teleport allowing you to teleport in land if you clicked beyond the wrap-around border
authorWuzzy <almikes@aol.com>
Fri, 06 Oct 2017 14:03:13 +0200
changeset 12656 161c10db4f27
parent 12655 913d25669131
child 12657 2065819170ce
Fix teleport allowing you to teleport in land if you clicked beyond the wrap-around border
ChangeLog.txt
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsUtils.pas
--- a/ChangeLog.txt	Thu Oct 05 18:26:08 2017 +0200
+++ b/ChangeLog.txt	Fri Oct 06 14:03:13 2017 +0200
@@ -49,6 +49,7 @@
  * 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
  * Remove buggy /finish chat command
  * Various other fixes
 
--- a/hedgewars/uGearsHandlersMess.pas	Thu Oct 05 18:26:08 2017 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Fri Oct 06 14:03:13 2017 +0200
@@ -2865,6 +2865,7 @@
     valid:= false;
 
     lx:= Gear^.Target.X - SpritesData[sprHHTelepMask].Width  div 2; // left
+    lx:= CalcWorldWrap(lx, SpritesData[sprHHTelepMask].Width); // Take world edge into account
     ty:= Gear^.Target.Y - SpritesData[sprHHTelepMask].Height div 2; // top
 
     // remember original target location
--- a/hedgewars/uGearsUtils.pas	Thu Oct 05 18:26:08 2017 +0200
+++ b/hedgewars/uGearsUtils.pas	Fri Oct 06 14:03:13 2017 +0200
@@ -56,6 +56,7 @@
 function  GetUtility(Hedgehog: PHedgehog): TAmmoType;
 
 function WorldWrap(var Gear: PGear): boolean;
+function CalcWorldWrap(X, radius: LongInt): LongInt;
 
 function IsHogLocal(HH: PHedgehog): boolean;
 
@@ -1598,6 +1599,27 @@
     end;
 end;
 
+// Takes an X coordinate and corrects if according to the world edge rules
+// Wrap-around: X will be wrapped
+// Bouncy: X will be kept inside the legal land (taking radius into account)
+// Other world edges: Just returns X
+// radius is a radius (gear radius) tolerance for an appropriate distance from bouncy world edges.
+// Set radius to 0 if you don't care.
+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))
+    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;
+    CalcWorldWrap:= X;
+end;
+
 procedure AddBounceEffectForGear(Gear: PGear);
 var boing: PVisualGear;
 begin