Set dX sign early so jump calculations always get correct value
authorunc0rr
Sun, 01 Sep 2019 10:37:16 +0200
changeset 15394 7718bdf60d45
parent 15393 262003f2e19a
child 15395 56f2c70723c8
Set dX sign early so jump calculations always get correct value
hedgewars/uAIMisc.pas
--- a/hedgewars/uAIMisc.pas	Sat Aug 31 23:15:14 2019 +0300
+++ b/hedgewars/uAIMisc.pas	Sun Sep 01 10:37:16 2019 +0200
@@ -961,6 +961,9 @@
 begin
 HHGo:= false;
 Gear^.CollisionMask:= lfNotCurHogCrate;
+
+Gear^.dX.isNegative:= (Gear^.Message and gmLeft) <> 0;
+
 AltGear^:= Gear^;
 
 GoInfo.Ticks:= 0;
@@ -1012,21 +1015,15 @@
         continue
         end;
 
-        // usual walk
-        if (Gear^.Message and gmLeft) <> 0 then
-            Gear^.dX:= -cLittle
-        else
-            if (Gear^.Message and gmRight) <> 0 then
-                Gear^.dX:=  cLittle
-            else
-                exit(false);
+    // usual walk
+    Gear^.dX:= SignAs(cLittle, Gear^.dX);
 
-        if MakeHedgehogsStep(Gear) then
-            inc(GoInfo.Ticks, cHHStepTicks);
+    if MakeHedgehogsStep(Gear) then
+        inc(GoInfo.Ticks, cHHStepTicks);
 
-        // we have moved for 1 px
-        if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then
-            exit(true)
+    // we have moved for 1 px
+    if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then
+        exit(true)
 until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0);
 
 HHJump(AltGear, jmpHJump, GoInfo);