diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index a9732a8f77..ae1b878131 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -923,12 +923,14 @@ DEFINE_HOOK(0x71ADE4, TemporalClass_Release_SlaveTargetFix, 0x5) // which means it didn't consider the actual speed of the unit. Now we check it and the units won't get stuck // even at high speeds - NetsuNegi -DEFINE_HOOK(0x7295C5, TunnelLocomotionClass_ProcessDigging_SlowdownDistance, 0x9) +DEFINE_HOOK(0x72958E, TunnelLocomotionClass_ProcessDigging_SlowdownDistance, 0x8) { enum { KeepMoving = 0x72980F, CloseEnough = 0x7295CE }; GET(TunnelLocomotionClass* const, pLoco, ESI); - GET(int const, distance, EAX); + + auto& currLoc = pLoco->LinkedTo->Location; + int distance = (int) CoordStruct{currLoc.X - pLoco->Coords.X, currLoc.Y - pLoco->Coords.Y,0}.Magnitude() ; // The movement speed was actually also hardcoded here to 19, so the distance check made sense // It can now be customized globally or per TechnoType however - Starkku @@ -943,9 +945,14 @@ DEFINE_HOOK(0x7295C5, TunnelLocomotionClass_ProcessDigging_SlowdownDistance, 0x9 speed = pLoco->LinkedTo->GetCurrentSpeed(); pType->Speed = maxSpeed; - TunnelLocomotionClass::TunnelMovementSpeed = speed; - - return distance >= speed + 1 ? KeepMoving : CloseEnough; + if (distance > speed) + { + REF_STACK(CoordStruct, newLoc, STACK_OFFSET(0x40, -0xC)); + double angle = -Math::atan2(currLoc.Y - pLoco->Coords.Y, pLoco->Coords.X - currLoc.X); + newLoc = currLoc + CoordStruct { int((double)speed * Math::cos(angle)), int((double)speed * Math::sin(angle)), 0 }; + return 0x7298D3; + } + return 0x7295CE; } DEFINE_HOOK(0x75BD70, WalkLocomotionClass_ProcessMoving_SlowdownDistance, 0x9)