mirror of
https://github.com/rmroc451/TweaksAndThings.git
synced 2025-12-18 10:19:38 -06:00
Merge pull request #35 from rmroc451/26-caboose-auto-heal-hotbox-when-fully-oiled
#26 auto heal hotbox when found if caboose use is enabled and caboose…
This commit is contained in:
@@ -6,22 +6,22 @@ namespace RMROC451.TweaksAndThings.Extensions
|
|||||||
{
|
{
|
||||||
internal static class AutoEngineer_Extensions
|
internal static class AutoEngineer_Extensions
|
||||||
{
|
{
|
||||||
private static float CabooseHalvedFloat(this float input, bool hasCaboose) =>
|
private static float CabooseHalvedFloat(this float input, Model.Car? hasCaboose) =>
|
||||||
hasCaboose ? input / 2 : input;
|
hasCaboose ? input / 2 : input;
|
||||||
|
|
||||||
private static float CabooseAutoOilerLimit(this bool hasCaboose) =>
|
private static float CabooseAutoOilerLimit(this Model.Car? caboose) =>
|
||||||
hasCaboose ? 0.99f : AutoOiler.OilIfBelow;
|
caboose ? 0.99f : AutoOiler.OilIfBelow;
|
||||||
|
|
||||||
public static IEnumerator MrocAutoOilerLoop(this AutoOiler oiler, Serilog.ILogger _log, bool cabooseRequired)
|
public static IEnumerator MrocAutoOilerLoop(this AutoOiler oiler, Serilog.ILogger _log, bool cabooseRequired)
|
||||||
{
|
{
|
||||||
int originIndex = oiler.FindOriginIndex();
|
int originIndex = oiler.FindOriginIndex();
|
||||||
bool hasCaboose = oiler._cars.CabooseInConsist();
|
Model.Car? foundCaboose = oiler._cars.CabooseInConsist();
|
||||||
if (originIndex < 0)
|
if (originIndex < 0)
|
||||||
{
|
{
|
||||||
_log.Error("Couldn't find origin car {car}", oiler._originCar);
|
_log.Error("Couldn't find origin car {car}", oiler._originCar);
|
||||||
oiler._coroutine = null;
|
oiler._coroutine = null;
|
||||||
yield break;
|
yield break;
|
||||||
} else if (CabooseRequirementChecker(string.Format("{0} {1}", oiler.GetType().Name, oiler.name), cabooseRequired, hasCaboose, _log))
|
} else if (CabooseRequirementChecker(string.Format("{0} {1}", oiler.GetType().Name, oiler.name), cabooseRequired, foundCaboose, _log))
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
@@ -31,30 +31,35 @@ namespace RMROC451.TweaksAndThings.Extensions
|
|||||||
oiler.name,
|
oiler.name,
|
||||||
oiler._reverse,
|
oiler._reverse,
|
||||||
cabooseRequired,
|
cabooseRequired,
|
||||||
hasCaboose,
|
foundCaboose,
|
||||||
hasCaboose.CabooseAutoOilerLimit()
|
foundCaboose.CabooseAutoOilerLimit()
|
||||||
);
|
);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
yield return new WaitForSeconds(AutoOiler.StartDelay.CabooseHalvedFloat(hasCaboose));
|
yield return new WaitForSeconds(AutoOiler.StartDelay.CabooseHalvedFloat(foundCaboose));
|
||||||
int carIndex = originIndex;
|
int carIndex = originIndex;
|
||||||
float adjustedTimeToWalk = AutoOiler.TimeToWalkCar.CabooseHalvedFloat(hasCaboose);
|
float adjustedTimeToWalk = AutoOiler.TimeToWalkCar.CabooseHalvedFloat(foundCaboose);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (oiler.TryGetCar(carIndex, out var car))
|
if (oiler.TryGetCar(carIndex, out var car))
|
||||||
{
|
{
|
||||||
float num = 0f;
|
float num = 0f;
|
||||||
float origOil = car.Oiled;
|
float origOil = car.Oiled;
|
||||||
if (car.NeedsOiling && car.Oiled < hasCaboose.CabooseAutoOilerLimit())
|
if (car.NeedsOiling && car.Oiled < foundCaboose.CabooseAutoOilerLimit())
|
||||||
{
|
{
|
||||||
float num2 = 1f - car.Oiled;
|
float num2 = 1f - car.Oiled;
|
||||||
car.OffsetOiled(num2);
|
car.OffsetOiled(num2);
|
||||||
float num3 = num2 * AutoOiler.TimeToFullyOil.CabooseHalvedFloat(hasCaboose);
|
float num3 = num2 * AutoOiler.TimeToFullyOil.CabooseHalvedFloat(foundCaboose);
|
||||||
num += num3;
|
num += num3;
|
||||||
oiler._pendingRunDuration += num3;
|
oiler._pendingRunDuration += num3;
|
||||||
oiler._oiledCount++;
|
oiler._oiledCount++;
|
||||||
_log.Information("AutoOiler {name}: oiled {car} from {orig} => {new}", oiler.name, car, origOil, car.Oiled);
|
_log.Information("AutoOiler {name}: oiled {car} from {orig} => {new}", oiler.name, car, origOil, car.Oiled);
|
||||||
}
|
}
|
||||||
|
if (car.HasHotbox && car.Oiled == 1f && cabooseRequired && foundCaboose)
|
||||||
|
{
|
||||||
|
_log.Information("AutoOiler {name}: {foundCaboose} repaired hotbox {car}", oiler.name, foundCaboose, car);
|
||||||
|
car.AdjustHotboxValue(0f);
|
||||||
|
}
|
||||||
num += adjustedTimeToWalk;
|
num += adjustedTimeToWalk;
|
||||||
oiler._pendingRunDuration += adjustedTimeToWalk;
|
oiler._pendingRunDuration += adjustedTimeToWalk;
|
||||||
yield return new WaitForSeconds(num);
|
yield return new WaitForSeconds(num);
|
||||||
@@ -71,14 +76,16 @@ namespace RMROC451.TweaksAndThings.Extensions
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
bool hasCaboose = spotter._cars.CabooseInConsist();
|
Model.Car? foundCaboose = spotter._cars.CabooseInConsist();
|
||||||
if (!spotter.HasCars)
|
if (!spotter.HasCars)
|
||||||
{
|
{
|
||||||
yield return new WaitForSeconds(1f);
|
yield return new WaitForSeconds(1f);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_log.Information("AutoHotboxSpotter {name}: Hotbox Spotter Running, Has Caboose => {hasCaboose}; Has Cars {hasCars}; Requires Caboose {requiresCaboose}", spotter.name, hasCaboose, spotter.HasCars, cabooseRequired);
|
_log.Information("AutoHotboxSpotter {name}: Hotbox Spotter Running, Found Caboose => {hasCaboose}; Has Cars {hasCars}; Requires Caboose {requiresCaboose}",
|
||||||
if (CabooseRequirementChecker(string.Format("{0} {1}", spotter.GetType().Name, spotter.name), cabooseRequired, hasCaboose, _log))
|
spotter.name, foundCaboose, spotter.HasCars, cabooseRequired);
|
||||||
|
foundCaboose = spotter._cars.CabooseInConsist();
|
||||||
|
if (CabooseRequirementChecker(string.Format("{0} {1}", spotter.GetType().Name, spotter.name), cabooseRequired, foundCaboose, _log))
|
||||||
{
|
{
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
@@ -86,11 +93,12 @@ namespace RMROC451.TweaksAndThings.Extensions
|
|||||||
while (spotter.HasCars)
|
while (spotter.HasCars)
|
||||||
{
|
{
|
||||||
int num = Random.Range(60, 300);
|
int num = Random.Range(60, 300);
|
||||||
if (hasCaboose)
|
foundCaboose = spotter._cars.CabooseInConsist();
|
||||||
|
if (foundCaboose)
|
||||||
{
|
{
|
||||||
var numOrig = num;
|
var numOrig = num;
|
||||||
num = Random.Range(15, 30);
|
num = Random.Range(15, 30);
|
||||||
_log.Information("AutoHotboxSpotter {name}: Next check went from num(60,300) => {numOrig}; to num(15,30) => {hasCaboose}; Requires Caboose {requiresCaboose}", spotter.name, numOrig, num, hasCaboose, cabooseRequired);
|
_log.Information("AutoHotboxSpotter {name}: Next check went from num(60,300) => {numOrig}; to num(15,30) => {hasCaboose}; Requires Caboose {requiresCaboose}", spotter.name, numOrig, num, foundCaboose, cabooseRequired);
|
||||||
}
|
}
|
||||||
yield return new WaitForSeconds(num);
|
yield return new WaitForSeconds(num);
|
||||||
spotter.CheckForHotbox();
|
spotter.CheckForHotbox();
|
||||||
@@ -98,9 +106,9 @@ namespace RMROC451.TweaksAndThings.Extensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CabooseRequirementChecker(string name, bool cabooseRequired, bool hasCaboose, Serilog.ILogger _log)
|
private static bool CabooseRequirementChecker(string name, bool cabooseRequired, Model.Car? foundCaboose, Serilog.ILogger _log)
|
||||||
{
|
{
|
||||||
bool error = cabooseRequired && !hasCaboose;
|
bool error = cabooseRequired && foundCaboose == null;
|
||||||
if (error) {
|
if (error) {
|
||||||
_log.Debug("{name}: Couldn't find required caboose!", name);
|
_log.Debug("{name}: Couldn't find required caboose!", name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using Helpers;
|
using Game.Messages;
|
||||||
|
using Game.State;
|
||||||
|
using Helpers;
|
||||||
using Model;
|
using Model;
|
||||||
using Model.Definition.Data;
|
using Model.Definition.Data;
|
||||||
using Model.OpsNew;
|
using Model.OpsNew;
|
||||||
@@ -60,7 +62,9 @@ public static class Car_Extensions
|
|||||||
|
|
||||||
public static bool IsCaboose(this Car car) => car.Archetype == Model.Definition.CarArchetype.Caboose;
|
public static bool IsCaboose(this Car car) => car.Archetype == Model.Definition.CarArchetype.Caboose;
|
||||||
|
|
||||||
public static bool CabooseInConsist(this IEnumerable<Car> input) => input.FirstOrDefault(c => c.IsCaboose());
|
public static bool IsCabooseAndStoppedForLoadRefresh(this Car car) => car.IsCaboose() && car.IsStopped(30f);
|
||||||
|
|
||||||
|
public static Car? CabooseInConsist(this IEnumerable<Car> input) => input.FirstOrDefault(c => c.IsCaboose());
|
||||||
|
|
||||||
public static Car? CabooseWithSufficientCrewHours(this Car car, float timeNeeded, HashSet<string> carIdsCheckedAlready, bool decrement = false)
|
public static Car? CabooseWithSufficientCrewHours(this Car car, float timeNeeded, HashSet<string> carIdsCheckedAlready, bool decrement = false)
|
||||||
{
|
{
|
||||||
@@ -122,4 +126,12 @@ public static class Car_Extensions
|
|||||||
}).ToList();
|
}).ToList();
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void AdjustHotboxValue(this Car car, float hotboxValue) =>
|
||||||
|
StateManager.ApplyLocal(
|
||||||
|
new PropertyChange(
|
||||||
|
car.id, PropertyChange.KeyForControl(PropertyChange.Control.Hotbox),
|
||||||
|
new FloatPropertyValue(hotboxValue)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,10 +90,13 @@ public class TweaksAndThingsPlugin : SingletonPluginBase<TweaksAndThingsPlugin>,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string cabooseUse => "Caboose Use";
|
||||||
|
private static string autoAiRequirment => "AutoAI\nRequirement";
|
||||||
|
|
||||||
private void CabooseMods(UIPanelBuilder builder)
|
private void CabooseMods(UIPanelBuilder builder)
|
||||||
{
|
{
|
||||||
builder.AddField(
|
builder.AddField(
|
||||||
"Caboose Use",
|
cabooseUse,
|
||||||
builder.AddToggle(
|
builder.AddToggle(
|
||||||
() => settings?.EndGearHelpersRequirePayment ?? false,
|
() => settings?.EndGearHelpersRequirePayment ?? false,
|
||||||
delegate (bool enabled)
|
delegate (bool enabled)
|
||||||
@@ -109,12 +112,14 @@ public class TweaksAndThingsPlugin : SingletonPluginBase<TweaksAndThingsPlugin>,
|
|||||||
|
|
||||||
Caboose starts reloading `Crew Hours` at any Team or Repair track (no waybill), after being stationary for 30 seconds.
|
Caboose starts reloading `Crew Hours` at any Team or Repair track (no waybill), after being stationary for 30 seconds.
|
||||||
|
|
||||||
AutoOiler Update: Increases limit that crew will oiling a car from 75% -> 99%, also halves the time it takes (simulating crew from lead end and caboose handling half the train)
|
AutoOiler Update: Increases limit that crew will oiling a car from 75% -> 99%, also halves the time it takes (simulating crew from lead end and caboose handling half the train).
|
||||||
|
|
||||||
|
AutoOiler Update: if `{cabooseUse}` & `{autoAiRequirment.Replace("\n", " ")}` checked, then when a caboose is present, the AutoOiler will repair hotboxes afer oiling them to 100%.
|
||||||
|
|
||||||
AutoHotboxSpotter Update: decrease the random wait from 30 - 300 seconds to 15 - 30 seconds (Safety Is Everyone's Job)");
|
AutoHotboxSpotter Update: decrease the random wait from 30 - 300 seconds to 15 - 30 seconds (Safety Is Everyone's Job)");
|
||||||
|
|
||||||
builder.AddField(
|
builder.AddField(
|
||||||
$"AutoAI\nRequirement",
|
autoAiRequirment,
|
||||||
builder.AddToggle(
|
builder.AddToggle(
|
||||||
() => settings?.RequireConsistCabooseForOilerAndHotboxSpotter ?? false,
|
() => settings?.RequireConsistCabooseForOilerAndHotboxSpotter ?? false,
|
||||||
delegate (bool enabled)
|
delegate (bool enabled)
|
||||||
|
|||||||
Reference in New Issue
Block a user