@@ -923,12 +923,14 @@ DEFINE_HOOK(0x71ADE4, TemporalClass_Release_SlaveTargetFix, 0x5)
923923// which means it didn't consider the actual speed of the unit. Now we check it and the units won't get stuck
924924// even at high speeds - NetsuNegi
925925
926- DEFINE_HOOK (0x7295C5 , TunnelLocomotionClass_ProcessDigging_SlowdownDistance, 0x9 )
926+ DEFINE_HOOK (0x72958E , TunnelLocomotionClass_ProcessDigging_SlowdownDistance, 0x8 )
927927{
928928 enum { KeepMoving = 0x72980F , CloseEnough = 0x7295CE };
929929
930930 GET (TunnelLocomotionClass* const , pLoco, ESI);
931- GET (int const , distance, EAX);
931+
932+ auto & currLoc = pLoco->LinkedTo ->Location ;
933+ int distance = (int ) CoordStruct{currLoc.X - pLoco->Coords .X , currLoc.Y - pLoco->Coords .Y ,0 }.Magnitude () ;
932934
933935 // The movement speed was actually also hardcoded here to 19, so the distance check made sense
934936 // It can now be customized globally or per TechnoType however - Starkku
@@ -943,9 +945,14 @@ DEFINE_HOOK(0x7295C5, TunnelLocomotionClass_ProcessDigging_SlowdownDistance, 0x9
943945 speed = pLoco->LinkedTo ->GetCurrentSpeed ();
944946 pType->Speed = maxSpeed;
945947
946- TunnelLocomotionClass::TunnelMovementSpeed = speed;
947-
948- return distance >= speed + 1 ? KeepMoving : CloseEnough;
948+ if (distance > speed)
949+ {
950+ REF_STACK (CoordStruct, newLoc, STACK_OFFSET (0x40 , -0xC ));
951+ double angle = -Math::atan2 (currLoc.Y - pLoco->Coords .Y , pLoco->Coords .X - currLoc.X );
952+ newLoc = currLoc + CoordStruct { int ((double )speed * Math::cos (angle)), int ((double )speed * Math::sin (angle)), 0 };
953+ return 0x7298D3 ;
954+ }
955+ return 0x7295CE ;
949956}
950957
951958DEFINE_HOOK (0x75BD70 , WalkLocomotionClass_ProcessMoving_SlowdownDistance, 0x9 )
0 commit comments