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