added Bleed Consist button

This commit is contained in:
2024-06-23 02:30:13 -05:00
parent b6edc93636
commit 2e47536028
3 changed files with 27 additions and 8 deletions

View File

@@ -3,5 +3,6 @@
public enum MrocHelperType public enum MrocHelperType
{ {
Handbrake, Handbrake,
GladhandAndAnglecock GladhandAndAnglecock,
BleedAirSystem
} }

View File

@@ -36,5 +36,7 @@ namespace RMROC451.TweaksAndThings.Extensions
} }
return car; return car;
} }
public static bool NotMotivePower(this Car car) => car is not BaseLocomotive && car.Archetype != Model.Definition.CarArchetype.Tender;
} }
} }

View File

@@ -2,9 +2,9 @@
using Game.State; using Game.State;
using HarmonyLib; using HarmonyLib;
using KeyValue.Runtime; using KeyValue.Runtime;
using Model;
using Model.OpsNew; using Model.OpsNew;
using Railloader; using Railloader;
using RMROC451.TweaksAndThings;
using RMROC451.TweaksAndThings.Enums; using RMROC451.TweaksAndThings.Enums;
using RMROC451.TweaksAndThings.Extensions; using RMROC451.TweaksAndThings.Extensions;
using Serilog; using Serilog;
@@ -51,12 +51,18 @@ public class CarInspector_PopulateCarPanel_Patch
if (consist.Any(c => c.EndAirSystemIssue())) if (consist.Any(c => c.EndAirSystemIssue()))
{ {
hstack.AddButtonCompact("Connect Air Lines", delegate hstack.AddButtonCompact("Connect Air", delegate
{ {
MrocConsistHelper(__instance._car, MrocHelperType.GladhandAndAnglecock); MrocConsistHelper(__instance._car, MrocHelperType.GladhandAndAnglecock);
hstack.Rebuild(); hstack.Rebuild();
}).Tooltip("Connect Consist Air Lines", "Iterates over each car in this consist and connects gladhands and opens anglecocks."); }).Tooltip("Connect Consist Air", "Iterates over each car in this consist and connects gladhands and opens anglecocks.");
} }
hstack.AddButtonCompact("Bleed Consist", delegate
{
MrocConsistHelper(__instance._car, MrocHelperType.BleedAirSystem);
hstack.Rebuild();
}).Tooltip("Bleed Air Lines", "Iterates over each car in this consist and bleeds the air out of the lines.");
}); });
return true; return true;
@@ -111,16 +117,17 @@ public class CarInspector_PopulateCarPanel_Patch
IEnumerable<Model.Car> consist = car.EnumerateCoupled(LogicalEnd.A); IEnumerable<Model.Car> consist = car.EnumerateCoupled(LogicalEnd.A);
Log.Information($"{car} => {mrocHelperType} => {string.Join("/", consist.Select(c => c.ToString()))}"); Log.Information($"{car} => {mrocHelperType} => {string.Join("/", consist.Select(c => c.ToString()))}");
TrainController tc = UnityEngine.Object.FindObjectOfType<TrainController>();
switch (mrocHelperType) switch (mrocHelperType)
{ {
case MrocHelperType.Handbrake: case MrocHelperType.Handbrake:
if (consist.Any(c => c.HandbrakeApplied())) if (consist.Any(c => c.HandbrakeApplied()))
{ {
consist.Do(c => c.SetHandbrake(false)); consist.Do(c => c.SetHandbrake(false));
} else }
else
{ {
TrainController tc = UnityEngine.Object.FindObjectOfType<TrainController>(); consist = consist.Where(c => c is not BaseLocomotive && c.Archetype != Model.Definition.CarArchetype.Tender);
consist = consist.Where(c => c.DetermineFuelCar(true) != null);
Log.Information($"{car} => {mrocHelperType} => {string.Join("/", consist.Select(c => c.ToString()))}"); Log.Information($"{car} => {mrocHelperType} => {string.Join("/", consist.Select(c => c.ToString()))}");
//when ApplyHandbrakesAsNeeded is called, and the consist contains an engine, it stops applying brakes. //when ApplyHandbrakesAsNeeded is called, and the consist contains an engine, it stops applying brakes.
tc.ApplyHandbrakesAsNeeded(consist.ToList(), PlaceTrainHandbrakes.Automatic); tc.ApplyHandbrakesAsNeeded(consist.ToList(), PlaceTrainHandbrakes.Automatic);
@@ -135,7 +142,7 @@ public class CarInspector_PopulateCarPanel_Patch
StateManager.ApplyLocal( StateManager.ApplyLocal(
new PropertyChange( new PropertyChange(
c.id, c.id,
KeyValueKeyFor(EndGearStateKey.Anglecock, c.LogicalToEnd(end)), KeyValueKeyFor(EndGearStateKey.Anglecock, c.LogicalToEnd(end)),
new FloatPropertyValue(endGear.IsCoupled ? 1f : 0f) new FloatPropertyValue(endGear.IsCoupled ? 1f : 0f)
) )
@@ -149,6 +156,15 @@ public class CarInspector_PopulateCarPanel_Patch
}) })
); );
break; break;
case MrocHelperType.BleedAirSystem:
consist = consist.Where(c => c.NotMotivePower());
Log.Information($"{car} => {mrocHelperType} => {string.Join("/", consist.Select(c => c.ToString()))}");
foreach (Model.Car bleed in consist)
{
StateManager.ApplyLocal(new PropertyChange(bleed.id, PropertyChange.Control.Bleed, 1));
}
break;
} }
} }
} }