From 1e7d9423d949cda6c32f452566f42ab7ce5f53c9 Mon Sep 17 00:00:00 2001 From: Bates Larsson Date: Fri, 27 Mar 2026 14:30:37 +0000 Subject: [PATCH 1/3] Update Cruise Brake Type Incorrect independent brake used when cruising --- DVRouteManager/LocoCruiseControl.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DVRouteManager/LocoCruiseControl.cs b/DVRouteManager/LocoCruiseControl.cs index cc7c803..8d2dea5 100644 --- a/DVRouteManager/LocoCruiseControl.cs +++ b/DVRouteManager/LocoCruiseControl.cs @@ -176,9 +176,9 @@ protected float MaintainSpeed(float targetAcceleration, float dt, float speed, f } if (error < -3.0f || TargetSpeed < Mathf.Epsilon) - remoteControl.UpdateIndependentBrake(0.3f * error * -1.0f * dt); - else if (remoteControl.GetTargetIndependentBrake() > Mathf.Epsilon) - remoteControl.UpdateIndependentBrake(-30.0f * dt); + remoteControl.UpdateBrake(0.3f * error * -1.0f * dt); + else if (remoteControl.GetTargetBrake() > Mathf.Epsilon) + remoteControl.UpdateBrake(-30.0f * dt); remoteControl.UpdateThrottle(ThrottleCurveFactor(remoteControl.GetTargetThrottle(), controlValue > 0.0f) * controlValue); From b2ab3b592cc36e38d1003c60ff211bb75524f1f3 Mon Sep 17 00:00:00 2001 From: Bates Larsson Date: Fri, 27 Mar 2026 14:31:48 +0000 Subject: [PATCH 2/3] Added release break call When starting off or at the end of the hookup the breaks should be released. --- DVRouteManager/LocoAI.cs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/DVRouteManager/LocoAI.cs b/DVRouteManager/LocoAI.cs index d77c126..fdf2a52 100644 --- a/DVRouteManager/LocoAI.cs +++ b/DVRouteManager/LocoAI.cs @@ -1,4 +1,4 @@ -using CommandTerminal; +using CommandTerminal; using DV.Logic.Job; using System; using System.Collections; @@ -226,6 +226,29 @@ public bool StartAI(RouteTracker routeTracker) return true; } + private IEnumerator ReleaseAllBrakes() + { + //// ── Release handbrakes on wagons ───────────────────────────── + //foreach (TrainCar car in loco.trainset.cars) + //{ + // if (!car.IsLoco && car.brakeSystem.hasHandbrake) + // { + // car.brakeSystem.SetHandbrakePosition(0f); + // Terminal.Log($"Released handbrake on {car.logicCar.ID}"); + // } + //} + + // ── Release loco brakes (train + independent) ──────────────── + // Use a loop to step them down smoothly + for (int i = 0; i < 10; i++) + { + remoteControl.UpdateIndependentBrake(-1.0f); + remoteControl.UpdateBrake(-1.0f); + + yield return new WaitForSeconds(0.3f); + } + } + private IEnumerator AICoroutine() { const float TIME_WAIT = 0.3f; @@ -250,6 +273,8 @@ private IEnumerator AICoroutine() RouteTracker.TrackingState lastState = RouteTracker.TrackState; + yield return ReleaseAllBrakes(); + while (running) { float speed = Mathf.Abs(remoteControl.GetForwardSpeed() * 3.6f); @@ -390,6 +415,8 @@ IEnumerator Reverse() yield return null; remoteControl.UpdateReverser(direction ? ToggleDirection.DOWN : ToggleDirection.UP); yield return null; + + yield return ReleaseAllBrakes(); } IEnumerator BrakePulse(int level, float waitTime) From 9b919c6e7ee86df08947739f2f3dd566d3ec8f94 Mon Sep 17 00:00:00 2001 From: Bates Larsson Date: Fri, 27 Mar 2026 14:32:55 +0000 Subject: [PATCH 3/3] Skip freight pathing on already hooked up trains When the train is already hooked up to the cargo the second stage pathing can be skipped. --- DVRouteManager/LocoAI.cs | 55 ++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/DVRouteManager/LocoAI.cs b/DVRouteManager/LocoAI.cs index fdf2a52..dd5d206 100644 --- a/DVRouteManager/LocoAI.cs +++ b/DVRouteManager/LocoAI.cs @@ -1,4 +1,4 @@ -using CommandTerminal; +using CommandTerminal; using DV.Logic.Job; using System; using System.Collections; @@ -473,35 +473,46 @@ private IEnumerator FreightHaulCoroutine(RouteTask task, TrainCar loco) Track carTrack = freightTrainset.firstCar.Bogies[0].track.LogicTrack(); Track locoTrack = loco.trainset.firstCar.Bogies[0].track.LogicTrack(); - var toCarsTask = Route.FindRoute(locoTrack, carTrack, ReversingStrategy.ChooseBest, loco.trainset); - while (!toCarsTask.IsCompleted) yield return null; + bool alreadyCoupled = loco.trainset == freightTrainset; - if (!_freightHaulActive) yield break; - - if (toCarsTask.IsFaulted || toCarsTask.Result == null) + if (loco.trainset == freightTrainset) { - Terminal.Log("Freight haul: cannot find route to cars – " + (toCarsTask.Exception?.InnerException?.Message ?? "null")); - _freightHaulActive = false; - yield break; + Terminal.Log("Freight haul: already coupled to target trainset, skipping routing to cars"); } + else + { - var chain1 = RouteTaskChain.FromDestination(carTrack, loco.trainset); - var tracker1 = new RouteTracker(chain1, true); - tracker1.SetRoute(toCarsTask.Result, loco.trainset); - Module.ActiveRoute.Route = toCarsTask.Result; - Module.ActiveRoute.RouteTracker = tracker1; + var toCarsTask = Route.FindRoute(locoTrack, carTrack, ReversingStrategy.ChooseBest, loco.trainset); + while (!toCarsTask.IsCompleted) yield return null; - StartAI(tracker1); - while (running && _freightHaulActive) yield return null; + if (!_freightHaulActive) yield break; - if (!_freightHaulActive) { Stop(); yield break; } + if (toCarsTask.IsFaulted || toCarsTask.Result == null) + { + Terminal.Log("Freight haul: cannot find route to cars – " + (toCarsTask.Exception?.InnerException?.Message ?? "null")); + _freightHaulActive = false; + yield break; + } - // ── Phase 2: couple and release handbrakes ─────────────────────── - Terminal.Log("Freight haul: phase 2 – coupling"); - yield return TryCoupleAndReleaseHandbrakes(loco); - yield return new WaitForSeconds(1.5f); + var chain1 = RouteTaskChain.FromDestination(carTrack, loco.trainset); + var tracker1 = new RouteTracker(chain1, true); + tracker1.SetRoute(toCarsTask.Result, loco.trainset); + Module.ActiveRoute.Route = toCarsTask.Result; + Module.ActiveRoute.RouteTracker = tracker1; - if (!_freightHaulActive) yield break; + StartAI(tracker1); + while (running && _freightHaulActive) yield return null; + + if (!_freightHaulActive) { Stop(); yield break; } + + // ── Phase 2: couple and release handbrakes ─────────────────────── + Terminal.Log("Freight haul: phase 2 – coupling"); + yield return TryCoupleAndReleaseHandbrakes(loco); + yield return new WaitForSeconds(1.5f); + + if (!_freightHaulActive) yield break; + + } // ── Phase 3: drive to destination ──────────────────────────────── Terminal.Log($"Freight haul: phase 3 – routing to {task.DestinationTrack.ID.FullID}");