From fa7e7dfcd2c02bf038deeedaf0d4d1b01411d391 Mon Sep 17 00:00:00 2001 From: RMROC451 Date: Sun, 24 Aug 2025 09:57:45 -0500 Subject: [PATCH] fixes #46; only care about caboose crew hours on certain actions, it's presence is enough in other cases. --- TweaksAndThings/Definition.json | 3 +-- .../Extensions/AutoEngineer_Extensions.cs | 6 +++--- TweaksAndThings/Extensions/Car_Extensions.cs | 14 +++++++++++--- ...erOrdersHelper_SendAutoEngineerCommand_Patch.cs | 2 +- .../Patches/CarInspector_PopulateCarPanel_Patch.cs | 4 ++-- .../Patches/CarPickable_Activate_Patch.cs | 2 +- .../Patches/EngineRosterRow_Refresh_Patch.cs | 2 +- ...psController_AnnounceCoalescedPayments_Patch.cs | 8 +++++--- .../Patches/StateManager_OnDayDidChange_Patch.cs | 4 ++-- .../Patches/TagController_UpdateTag_Patch.cs | 2 +- TweaksAndThings/Settings/Settings.cs | 2 +- 11 files changed, 29 insertions(+), 20 deletions(-) diff --git a/TweaksAndThings/Definition.json b/TweaksAndThings/Definition.json index 31fd06d..a29b876 100644 --- a/TweaksAndThings/Definition.json +++ b/TweaksAndThings/Definition.json @@ -21,7 +21,6 @@ "mixintos": { "container:ne-caboose01": "file(mroc-cabeese.json)", "container:ne-caboose02": "file(mroc-cabeese.json)", - "container:ne-caboose03": "file(mroc-cabeese.json)", - "game-graph": "file(tweakedLoadIDS.json)" + "container:ne-caboose03": "file(mroc-cabeese.json)" } } \ No newline at end of file diff --git a/TweaksAndThings/Extensions/AutoEngineer_Extensions.cs b/TweaksAndThings/Extensions/AutoEngineer_Extensions.cs index e96a908..e229595 100644 --- a/TweaksAndThings/Extensions/AutoEngineer_Extensions.cs +++ b/TweaksAndThings/Extensions/AutoEngineer_Extensions.cs @@ -19,7 +19,7 @@ namespace RMROC451.TweaksAndThings.Extensions public static IEnumerator MrocAutoOilerLoop(this AutoOiler oiler, Serilog.ILogger _log, bool cabooseRequired) { int originIndex = oiler.FindOriginIndex(); - Model.Car? foundCaboose = oiler._originCar.FindMyCaboose(0.0f, false); + Model.Car? foundCaboose = oiler._originCar.FindMyCabooseSansLoadRequirement(); if (originIndex < 0) { _log.Error("Couldn't find origin car {car}", oiler._originCar); @@ -41,7 +41,7 @@ namespace RMROC451.TweaksAndThings.Extensions while (true) { yield return new WaitForSeconds(AutoOiler.StartDelay.CabooseHalvedFloat(foundCaboose)); - foundCaboose = oiler._originCar.FindMyCaboose(0.0f,false); + foundCaboose = oiler._originCar.FindMyCabooseSansLoadRequirement(); int carIndex = originIndex; float adjustedTimeToWalk = AutoOiler.TimeToWalkCar.CabooseHalvedFloat(foundCaboose); do @@ -80,7 +80,7 @@ namespace RMROC451.TweaksAndThings.Extensions public static IEnumerator MrocAutoHotboxSpotterLoop(this AutoHotboxSpotter spotter, Serilog.ILogger _log, bool cabooseRequired) { - Func foundCaboose = () => spotter._locomotive.FindMyCaboose(0.0f, false); + Func foundCaboose = () => spotter._locomotive.FindMyCabooseSansLoadRequirement(); while (true) { if (!spotter.HasCars) diff --git a/TweaksAndThings/Extensions/Car_Extensions.cs b/TweaksAndThings/Extensions/Car_Extensions.cs index 67a6c2b..21fc3e8 100644 --- a/TweaksAndThings/Extensions/Car_Extensions.cs +++ b/TweaksAndThings/Extensions/Car_Extensions.cs @@ -7,6 +7,7 @@ using Model.Definition.Data; using Model.Ops; using Model.Ops.Timetable; using Railloader; +using RMROC451.TweaksAndThings.Patches; using Serilog; using System; using System.Collections.Generic; @@ -98,21 +99,28 @@ public static class Car_Extensions input.SelectedLocomotive.TryGetTimetableTrain(out Timetable.Train t) && t.TrainClass == Timetable.TrainClass.First; - public static Car? FindMyCaboose(this Car car, float timeNeeded, bool decrement = false) => + public static Car? FindMyCabooseSansLoadRequirement(this Car car) => + FindMyCaboose(car, 0f, decrement: false, requireLoad: false); + + public static Car? FindMyCabooseWithLoadRequirement(this Car car, float timeNeeded, bool decrement) => + FindMyCaboose(car, timeNeeded, decrement, requireLoad: false); + + private static Car? FindMyCaboose(this Car car, float timeNeeded, bool decrement = false, bool requireLoad = true) => ( car.CarCaboose() ?? car.CarsNearCurrentCar(timeNeeded, decrement).FindNearestCabooseFromNearbyCars() )?.CabooseWithSufficientCrewHours(timeNeeded, decrement); - public static Car? CabooseWithSufficientCrewHours(this Car car, float timeNeeded, bool decrement = false) + public static Car? CabooseWithSufficientCrewHours(this Car car, float timeNeeded, bool requireLoad, bool decrement = false) { Car? output = null; if (car is null || !car.IsCaboose()) return null; + if (!requireLoad) return car; List loadSlots = car.Definition.LoadSlots; for (int i = 0; i < loadSlots.Count; i++) { CarLoadInfo? loadInfo = car.GetLoadInfo(i); - if (loadInfo.HasValue) + if (loadInfo.HasValue && loadInfo.Value.LoadId == OpsController_AnnounceCoalescedPayments_Patch.CrewLoadHours.id) { CarLoadInfo valueOrDefault = loadInfo.GetValueOrDefault(); output = valueOrDefault.Quantity >= timeNeeded ? car : null; diff --git a/TweaksAndThings/Patches/AutoEngineerOrdersHelper_SendAutoEngineerCommand_Patch.cs b/TweaksAndThings/Patches/AutoEngineerOrdersHelper_SendAutoEngineerCommand_Patch.cs index 9869789..0f5ac19 100644 --- a/TweaksAndThings/Patches/AutoEngineerOrdersHelper_SendAutoEngineerCommand_Patch.cs +++ b/TweaksAndThings/Patches/AutoEngineerOrdersHelper_SendAutoEngineerCommand_Patch.cs @@ -72,7 +72,7 @@ internal class AutoEngineerOrdersHelper_SendAutoEngineerCommand_Patch Func noCaboose = () => { - var output = TrainController.Shared.SelectedLocomotive.FindMyCaboose(0.0f, false) == null; + bool output = (bool)TrainController.Shared.SelectedLocomotive.FindMyCabooseSansLoadRequirement(); logMessage += $"\ncaboose? {!output}"; return output; }; diff --git a/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs b/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs index ed52750..7bd4199 100644 --- a/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs +++ b/TweaksAndThings/Patches/CarInspector_PopulateCarPanel_Patch.cs @@ -227,8 +227,8 @@ internal class CarInspector_PopulateCarPanel_Patch float originalTimeCost = consist.CalculateCostForAutoEngineerEndGearSetting(); float timeCost = originalTimeCost; float crewCost = timeCost / 3600; //hours of time deducted from caboose. - var tsString = crewCost.FormatCrewHours(OpsController_AnnounceCoalescedPayments_Patch.CrewHoursLoad().description); - Car? cabooseWithAvailCrew = car.FindMyCaboose(crewCost, buttonsHaveCost); + var tsString = crewCost.FormatCrewHours(OpsController_AnnounceCoalescedPayments_Patch.CrewLoadHours.description); + Car? cabooseWithAvailCrew = car.FindMyCabooseWithLoadRequirement(crewCost, buttonsHaveCost); if (cabooseWithAvailCrew == null) timeCost *= 1.5f; var cabooseFoundDisplay = cabooseWithAvailCrew?.DisplayName ?? "No caboose"; diff --git a/TweaksAndThings/Patches/CarPickable_Activate_Patch.cs b/TweaksAndThings/Patches/CarPickable_Activate_Patch.cs index 32dfc7d..ae1678c 100644 --- a/TweaksAndThings/Patches/CarPickable_Activate_Patch.cs +++ b/TweaksAndThings/Patches/CarPickable_Activate_Patch.cs @@ -62,7 +62,7 @@ internal class CarPickable_Activate_Patch var consist = car.EnumerateCoupled(); bool handbrakesApplied = consist.Any(c => c.HandbrakeApplied()); bool airSystemIssues = consist.Any(c => c.EndAirSystemIssue()); - Func cabooseNear = () => (bool)car.FindMyCaboose(0.0f, false); + Func cabooseNear = () => (bool)car.FindMyCabooseSansLoadRequirement(); bool needsOiling = GameInput.IsShiftDown && consist.All(c => c.IsStopped()) && consist.Any(c => c.NeedsOiling || c.HasHotbox) && (!tweaksAndThings.RequireConsistCabooseForOilerAndHotboxSpotter() || cabooseNear()); var chargeIt = handbrakesApplied || airSystemIssues || needsOiling; //CTRL + ALT + SHIFT : BrakesAngleCocksAndOiling diff --git a/TweaksAndThings/Patches/EngineRosterRow_Refresh_Patch.cs b/TweaksAndThings/Patches/EngineRosterRow_Refresh_Patch.cs index b49e4b5..4a9883d 100644 --- a/TweaksAndThings/Patches/EngineRosterRow_Refresh_Patch.cs +++ b/TweaksAndThings/Patches/EngineRosterRow_Refresh_Patch.cs @@ -52,7 +52,7 @@ internal class EngineRosterRow_Refresh_Patch bool cabooseRequirementFulfilled = !tweaksAndThings.RequireConsistCabooseForOilerAndHotboxSpotter() || consist.ConsistNoFreight() - || (bool)engineOrTender.FindMyCaboose(0.0f, false); + || (bool)engineOrTender.FindMyCabooseSansLoadRequirement(); float offendingPercentage = 100f; foreach (Car loco in locos) diff --git a/TweaksAndThings/Patches/OpsController_AnnounceCoalescedPayments_Patch.cs b/TweaksAndThings/Patches/OpsController_AnnounceCoalescedPayments_Patch.cs index 6692686..6243673 100644 --- a/TweaksAndThings/Patches/OpsController_AnnounceCoalescedPayments_Patch.cs +++ b/TweaksAndThings/Patches/OpsController_AnnounceCoalescedPayments_Patch.cs @@ -24,7 +24,7 @@ internal class CarExtensions_LoadString_Patch { public static bool Prefix(CarLoadInfo info, Load load, ref string __result) { - bool output = load.id == OpsController_AnnounceCoalescedPayments_Patch.CrewHoursLoad().id; + bool output = load.id == OpsController_AnnounceCoalescedPayments_Patch.CrewLoadHours.id; if (output) __result = info.Quantity.FormatCrewHours(load.description); return !output; @@ -38,7 +38,7 @@ internal class CarPrototypeLibrary_LoadForId_Patch { public static bool Prefix(string loadId, ref Load __result) { - Load load = OpsController_AnnounceCoalescedPayments_Patch.CrewHoursLoad(); + Load load = OpsController_AnnounceCoalescedPayments_Patch.CrewLoadHours; if (loadId == load.id) __result = load; return __result == null; @@ -70,7 +70,9 @@ internal class OpsController_AnnounceCoalescedPayments_Patch typeof(RepairTrack) }; - public static Load CrewHoursLoad() + private static Load _crewLoadHours; + internal static Load CrewLoadHours => _crewLoadHours ?? CrewHoursLoad(); + private static Load CrewHoursLoad() { Load load = (Load)ScriptableObject.CreateInstance(typeof(Load)); load.name = "crew-hours"; diff --git a/TweaksAndThings/Patches/StateManager_OnDayDidChange_Patch.cs b/TweaksAndThings/Patches/StateManager_OnDayDidChange_Patch.cs index a760448..ccd0406 100644 --- a/TweaksAndThings/Patches/StateManager_OnDayDidChange_Patch.cs +++ b/TweaksAndThings/Patches/StateManager_OnDayDidChange_Patch.cs @@ -36,11 +36,11 @@ internal class StateManager_OnDayDidChange_Patch { foreach (var car in TrainController.Shared.Cars.Where(Car_Extensions.IsCaboose)) { - var data = car.QuantityCapacityOfLoad(OpsController_AnnounceCoalescedPayments_Patch.CrewHoursLoad()); + var data = car.QuantityCapacityOfLoad(OpsController_AnnounceCoalescedPayments_Patch.CrewLoadHours); if (data.quantity < data.capacity) { Multiplayer.Broadcast($"{Hyperlink.To(car)}: \"Caboose crew topped off.\""); - new OpsCarAdapter(car, OpsController.Shared).Load(OpsController_AnnounceCoalescedPayments_Patch.CrewHoursLoad(), data.capacity - data.quantity); + new OpsCarAdapter(car, OpsController.Shared).Load(OpsController_AnnounceCoalescedPayments_Patch.CrewLoadHours, data.capacity - data.quantity); } } } diff --git a/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs b/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs index 971dc0d..c349e2b 100644 --- a/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs +++ b/TweaksAndThings/Patches/TagController_UpdateTag_Patch.cs @@ -43,7 +43,7 @@ internal class TagController_UpdateTag_Patch //if (car.EnableOiling) tags.Add(car.HasHotbox ? TextSprites.Hotbox : $"{TextSprites.Warning}{car.Oiled.TriColorPiePercent(1)}"); if (car.EnableOiling) tags.Add(car.HasHotbox ? TextSprites.Hotbox : car.Oiled.TriColorPiePercent(1, oilSpriteName)); IEnumerable consist = car.EnumerateCoupled().Where(c => c.EnableOiling); - Func cabooseRequirementFulfilled = () => (!cabooseRequired || consist.ConsistNoFreight() || car.FindMyCaboose(0.0f, false)); + Func cabooseRequirementFulfilled = () => (!cabooseRequired || consist.ConsistNoFreight() || (bool)car.FindMyCabooseSansLoadRequirement()); if (StateManager.Shared.Storage.OilFeature && car.IsLocomotive && !car.NeedsOiling diff --git a/TweaksAndThings/Settings/Settings.cs b/TweaksAndThings/Settings/Settings.cs index 26ff960..79eae63 100644 --- a/TweaksAndThings/Settings/Settings.cs +++ b/TweaksAndThings/Settings/Settings.cs @@ -129,7 +129,7 @@ public static class SettingsExtensions public static bool RequireConsistCabooseForOilerAndHotboxSpotter(this TweaksAndThingsPlugin input) => input?.settings?.RequireConsistCabooseForOilerAndHotboxSpotter ?? false; public static bool CabooseNonMotiveAllowedSetting(this TweaksAndThingsPlugin input, Car car) => - input.EndGearHelpersRequirePayment() && !car.MotivePower() && (bool)car.FindMyCaboose(0.0f, false); + input.EndGearHelpersRequirePayment() && !car.MotivePower() && (bool)car.FindMyCabooseSansLoadRequirement(); public static bool CabooseRequiredForLocoOilIndicator(this TweaksAndThingsPlugin input) => input?.settings?.CabooseRequiredForLocoTagOilIndication ?? false; public static bool ServiceFundPenalties(this TweaksAndThingsPlugin input) =>