Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initail build of duplex steam #877

Merged
merged 5 commits into from Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/ORTS.Common/Input/UserCommand.cs
Expand Up @@ -193,6 +193,8 @@ public enum UserCommand
[GetString("Control Blower Decrease")] ControlBlowerDecrease,
[GetString("Control Steam Heat Increase")] ControlSteamHeatIncrease,
[GetString("Control Steam Heat Decrease")] ControlSteamHeatDecrease,
[GetString("Control Steam Booster Increase")] ControlSteamBoosterIncrease,
[GetString("Control Steam Booster Decrease")] ControlSteamBoosterDecrease,
[GetString("Control Damper Increase")] ControlDamperIncrease,
[GetString("Control Damper Decrease")] ControlDamperDecrease,
[GetString("Control Firebox Open")] ControlFireboxOpen,
Expand Down
2 changes: 2 additions & 0 deletions Source/ORTS.Settings/InputSettings.cs
Expand Up @@ -356,6 +356,8 @@ static void InitializeCommands(UserCommandInput[] Commands)
Commands[(int)UserCommand.ControlBlowerIncrease] = new UserCommandKeyInput(0x31);
Commands[(int)UserCommand.ControlSteamHeatDecrease] = new UserCommandKeyInput(0x20, KeyModifiers.Alt);
Commands[(int)UserCommand.ControlSteamHeatIncrease] = new UserCommandKeyInput(0x16, KeyModifiers.Alt);
Commands[(int)UserCommand.ControlSteamBoosterDecrease] = new UserCommandKeyInput(0x11, KeyModifiers.Shift);
Commands[(int)UserCommand.ControlSteamBoosterIncrease] = new UserCommandKeyInput(0x11, KeyModifiers.Alt);
Commands[(int)UserCommand.ControlBrakeHoseConnect] = new UserCommandKeyInput(0x2B);
Commands[(int)UserCommand.ControlBrakeHoseDisconnect] = new UserCommandKeyInput(0x2B, KeyModifiers.Shift);
Commands[(int)UserCommand.ControlCabRadio] = new UserCommandKeyInput(0x13, KeyModifiers.Alt);
Expand Down
1 change: 1 addition & 0 deletions Source/Orts.Formats.Msts/CabViewFile.cs
Expand Up @@ -130,6 +130,7 @@ public enum CABViewControlTypes
DAMPERS_FRONT,
DAMPERS_BACK,
STEAM_HEAT,
STEAM_BOOSTER,
WATER_INJECTOR1,
WATER_INJECTOR2,
SMALL_EJECTOR,
Expand Down
22 changes: 22 additions & 0 deletions Source/Orts.Simulation/Common/Commands.cs
Expand Up @@ -1573,6 +1573,28 @@ public override void Redo()


// Steam controls

// Steam booster command
[Serializable()]
public sealed class ContinuousSteamBoosterCommand : ContinuousCommand
{
public static MSTSSteamLocomotive Receiver { get; set; }

public ContinuousSteamBoosterCommand(CommandLog log, int injector, bool toState, float? target, double startTime)
: base(log, toState, target, startTime)
{
Redo();
}

public override void Redo()
{
if (Receiver == null) return;
Receiver.SteamBoosterChangeTo(ToState, Target);
// Report();
}
}

// Steam heat command
[Serializable()]
public sealed class ContinuousSteamHeatCommand : ContinuousCommand
{
Expand Down
4 changes: 4 additions & 0 deletions Source/Orts.Simulation/Common/Events.cs
Expand Up @@ -272,6 +272,8 @@ public enum Event

MPCChangePosition,

SteamBoosterChange,

}

public static class Events
Expand Down Expand Up @@ -546,6 +548,8 @@ public static Event From(Source source, int eventID)

case 310: return Event.MPCChangePosition;

case 320: return Event.SteamBoosterChange;

default: return 0;
}
case Source.MSTSCrossing:
Expand Down
6 changes: 4 additions & 2 deletions Source/Orts.Simulation/Simulation/Confirmer.cs
Expand Up @@ -66,6 +66,7 @@ public enum CabControl {
, FiringIsManual
, FireShovelfull
, CylinderCocks
, SteamBooster
, CylinderCompound
, LargeEjector
, SmallEjector
Expand Down Expand Up @@ -214,8 +215,9 @@ public Confirmer(Simulator simulator, double defaultDurationS)
, new string [] { GetString("Firebox Door"), null, null, null, GetString("close"), GetString("open") }
, new string [] { GetString("Firing Rate"), null, null, null, GetString("decrease"), GetString("increase") }
, new string [] { GetString("Manual Firing"), GetString("off"), null, GetString("on") }
, new string [] { GetString("Fire"), null, null, GetString("add shovel-full") }
, new string [] { GetString("Cylinder Cocks"), GetString("close"), null, GetString("open") }
, new string [] { GetString("Fire"), null, null, GetString("add shovel-full") }
, new string [] { GetString("Cylinder Cocks"), GetString("close"), null, GetString("open") }
, new string [] { GetString("SteamBooster"), null, null, null, GetString("decrease"), GetString("increase") }
, new string [] { GetString("Cylinder Compound"), GetString("close"), null, GetString("open") }
, new string [] { GetString("LargeEjector"), null, null, null, GetString("decrease"), GetString("increase") }
, new string [] { GetString("SmallEjector"), null, null, null, GetString("decrease"), GetString("increase") }
Expand Down
Expand Up @@ -77,6 +77,7 @@
using System.Text;
using Event = Orts.Common.Event;
using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies;
using Orts.Simulation;

namespace Orts.Simulation.RollingStocks
{
Expand All @@ -101,6 +102,7 @@ public class MSTSSteamLocomotive : MSTSLocomotive
public MSTSNotchController FuelController = new MSTSNotchController(0, 1, 0.01f); // Could be coal, wood, oil or even peat !
public MSTSNotchController SmallEjectorController = new MSTSNotchController(0, 1, 0.1f);
public MSTSNotchController LargeEjectorController = new MSTSNotchController(0, 1, 0.1f);
public MSTSNotchController SteamBoosterController = new MSTSNotchController(0, 1, 0.1f);

float DebugTimerS;

Expand All @@ -124,6 +126,7 @@ public class MSTSSteamLocomotive : MSTSLocomotive
bool FullBoilerHeat = false; // Boiler heat has exceeded max possible heat in boiler (max operating steam pressure)
bool FullMaxPressBoilerHeat = false; // Boiler heat has exceed the max total possible heat in boiler (max safety valve pressure)
bool ShovelAnyway = false; // Predicts when the AI fireman should be increasing the fire burn rate despite the heat in the boiler
bool SteamBoosterControllerFitted = false;
/// <summary>
/// Grate limit of locomotive exceedeed?
/// </summary>
Expand Down Expand Up @@ -820,6 +823,7 @@ public override void Parse(string lowercasetoken, STFReader stf)
case "engine(enginecontrollers(dampersfront": DamperController.Parse(stf); break;
case "engine(enginecontrollers(shovel": FiringRateController.Parse(stf); break;
case "engine(enginecontrollers(firedoor": FireboxDoorController.Parse(stf); break;
case "engine(enginecontrollers(ortssteambooster": SteamBoosterController.Parse(stf); SteamBoosterControllerFitted = true; break;
case "engine(effects(steamspecialeffects": ParseEffects(lowercasetoken, stf); break;
case "engine(ortsgratearea": GrateAreaM2 = stf.ReadFloatBlock(STFReader.UNITS.AreaDefaultFT2, null); break;
case "engine(superheater": SuperheaterFactor = stf.ReadFloatBlock(STFReader.UNITS.None, null); break;
Expand Down Expand Up @@ -933,6 +937,7 @@ public override void Copy(MSTSWagon copy)
FireboxDoorController = (MSTSNotchController)locoCopy.FireboxDoorController.Clone();
SmallEjectorController = (MSTSNotchController)locoCopy.SmallEjectorController.Clone();
LargeEjectorController = (MSTSNotchController)locoCopy.LargeEjectorController.Clone();
SteamBoosterController = (MSTSNotchController)locoCopy.SteamBoosterController.Clone();
GrateAreaM2 = locoCopy.GrateAreaM2;
SuperheaterFactor = locoCopy.SuperheaterFactor;
EvaporationAreaM2 = locoCopy.EvaporationAreaM2;
Expand All @@ -957,6 +962,7 @@ public override void Copy(MSTSWagon copy)
IsFixGeared = locoCopy.IsFixGeared;
IsSelectGeared = locoCopy.IsSelectGeared;
LargeEjectorControllerFitted = locoCopy.LargeEjectorControllerFitted;
SteamBoosterControllerFitted = locoCopy.SteamBoosterControllerFitted;
CylinderExhausttoCutoff = locoCopy.CylinderExhausttoCutoff;
CylinderCompressiontoCutoff = locoCopy.CylinderCompressiontoCutoff;
CylinderAdmissiontoCutoff = locoCopy.CylinderAdmissiontoCutoff;
Expand Down Expand Up @@ -1019,6 +1025,7 @@ public override void Save(BinaryWriter outf)
ControllerFactory.Save(FiringRateController, outf);
ControllerFactory.Save(SmallEjectorController, outf);
ControllerFactory.Save(LargeEjectorController, outf);
ControllerFactory.Save(SteamBoosterController, outf);
outf.Write(FuelBurnRateSmoothedKGpS);
outf.Write(BoilerHeatSmoothedBTU);
outf.Write(FuelRateSmoothed);
Expand Down Expand Up @@ -1082,6 +1089,7 @@ public override void Restore(BinaryReader inf)
ControllerFactory.Restore(FiringRateController, inf);
ControllerFactory.Restore(SmallEjectorController, inf);
ControllerFactory.Restore(LargeEjectorController, inf);
ControllerFactory.Restore(SteamBoosterController, inf);
FuelBurnRateSmoothedKGpS = inf.ReadSingle();
BurnRateSmoothKGpS.ForceSmoothValue(FuelBurnRateSmoothedKGpS);
BoilerHeatSmoothedBTU = inf.ReadSingle();
Expand Down Expand Up @@ -2595,6 +2603,15 @@ protected override void UpdateControllers(float elapsedClockSeconds)
}
}

SteamBoosterController.Update(elapsedClockSeconds);
if (IsPlayerTrain)
{
if (SteamBoosterController.UpdateValue > 0.0)
Simulator.Confirmer.UpdateWithPerCent(CabControl.SteamBooster, CabSetting.Increase, SteamBoosterController.CurrentValue * 100);
if (SteamBoosterController.UpdateValue < 0.0)
Simulator.Confirmer.UpdateWithPerCent(CabControl.SteamBooster, CabSetting.Decrease, SteamBoosterController.CurrentValue * 100);
}

Injector1Controller.Update(elapsedClockSeconds);
if (IsPlayerTrain)
{
Expand Down Expand Up @@ -6123,6 +6140,9 @@ public override float GetDataOf(CabViewControl cvc)
case CABViewControlTypes.REVERSER_PLATE:
data = Train.MUReverserPercent / 100f;
break;
case CABViewControlTypes.STEAM_BOOSTER:
data = SteamBoosterController.CurrentValue;
break;
case CABViewControlTypes.CYL_COCKS:
data = CylinderCocksAreOpen ? 1 : 0;
break;
Expand Down Expand Up @@ -7175,7 +7195,71 @@ public void SteamStopGearBoxDecrease()

}

//Small Ejector Controller
#region Steam booster controller

public void StartSteamBoosterIncrease(float? target)
{
SteamBoosterController.CommandStartTime = Simulator.ClockTime;
if (IsPlayerTrain)
Simulator.Confirmer.ConfirmWithPerCent(CabControl.SteamBooster, CabSetting.Increase, SteamBoosterController.CurrentValue * 100);
SteamBoosterController.StartIncrease(target);
SignalEvent(Event.SteamBoosterChange);
}

public void StopSteamBoosterIncrease()
{
SteamBoosterController.StopIncrease();
new ContinuousSteamBoosterCommand(Simulator.Log, 1, true, SteamBoosterController.CurrentValue, SteamBoosterController.CommandStartTime);
}

public void StartSteamBoosterDecrease(float? target)
{
if (IsPlayerTrain)
Simulator.Confirmer.ConfirmWithPerCent(CabControl.SteamBooster, CabSetting.Decrease, SteamBoosterController.CurrentValue * 100);
SteamBoosterController.StartDecrease(target);
SignalEvent(Event.SteamBoosterChange);
}

public void StopSteamBoosterDecrease()
{
SteamBoosterController.StopDecrease();
if (IsPlayerTrain)
new ContinuousSteamBoosterCommand(Simulator.Log, 1, false, SteamBoosterController.CurrentValue, SteamBoosterController.CommandStartTime);
}

public void SteamBoosterChangeTo(bool increase, float? target)
{
if (increase)
{
if (target > SteamBoosterController.CurrentValue)
{
StartSteamBoosterIncrease(target);
}
}
else
{
if (target < SteamBoosterController.CurrentValue)
{
StartSteamBoosterDecrease(target);
}
}
}

public void SetSteamBoosterValue(float value)
{
var controller = SteamBoosterController;
var oldValue = controller.IntermediateValue;
var change = controller.SetValue(value);
if (change != 0)
{
new ContinuousSteamBoosterCommand(Simulator.Log, 1, change > 0, controller.CurrentValue, Simulator.GameTime);
}
if (oldValue != controller.IntermediateValue)
Simulator.Confirmer.UpdateWithPerCent(CabControl.SteamBooster, oldValue < controller.IntermediateValue ? CabSetting.Increase : CabSetting.Decrease, controller.CurrentValue * 100);
}
#endregion

//Small Ejector Controller

#region Small Ejector controller

Expand Down Expand Up @@ -7250,7 +7334,7 @@ public void StartLargeEjectorIncrease(float? target)
{
LargeEjectorController.CommandStartTime = Simulator.ClockTime;
if (IsPlayerTrain)
Simulator.Confirmer.ConfirmWithPerCent(CabControl.LargeEjector, CabSetting.Increase, LargeEjectorController.CurrentValue* 100);
Simulator.Confirmer.ConfirmWithPerCent(CabControl.LargeEjector, CabSetting.Increase, LargeEjectorController.CurrentValue * 100);
LargeEjectorController.StartIncrease(target);
SignalEvent(Event.LargeEjectorChange);
}
Expand All @@ -7264,7 +7348,7 @@ public void StopLargeEjectorIncrease()
public void StartLargeEjectorDecrease(float? target)
{
if (IsPlayerTrain)
Simulator.Confirmer.ConfirmWithPerCent(CabControl.LargeEjector, CabSetting.Decrease, LargeEjectorController.CurrentValue* 100);
Simulator.Confirmer.ConfirmWithPerCent(CabControl.LargeEjector, CabSetting.Decrease, LargeEjectorController.CurrentValue * 100);
LargeEjectorController.StartDecrease(target);
SignalEvent(Event.LargeEjectorChange);
}
Expand Down Expand Up @@ -7304,7 +7388,7 @@ public void SetLargeEjectorValue(float value)
new ContinuousLargeEjectorCommand(Simulator.Log, 1, change > 0, controller.CurrentValue, Simulator.GameTime);
}
if (oldValue != controller.IntermediateValue)
Simulator.Confirmer.UpdateWithPerCent(CabControl.LargeEjector, oldValue<controller.IntermediateValue? CabSetting.Increase : CabSetting.Decrease, controller.CurrentValue* 100);
Simulator.Confirmer.UpdateWithPerCent(CabControl.LargeEjector, oldValue<controller.IntermediateValue? CabSetting.Increase : CabSetting.Decrease, controller.CurrentValue * 100);
}

#endregion
Expand Down
Expand Up @@ -2112,6 +2112,7 @@ public virtual int GetDrawIndex()
case CABViewControlTypes.BLOWER:
case CABViewControlTypes.DAMPERS_FRONT:
case CABViewControlTypes.STEAM_HEAT:
case CABViewControlTypes.STEAM_BOOSTER:
case CABViewControlTypes.ORTS_WATER_SCOOP:
case CABViewControlTypes.WATER_INJECTOR1:
case CABViewControlTypes.WATER_INJECTOR2:
Expand Down Expand Up @@ -2429,6 +2430,7 @@ public void HandleUserInput()
}
break;
case CABViewControlTypes.STEAM_HEAT: Locomotive.SetSteamHeatValue(ChangedValue(Locomotive.SteamHeatController.IntermediateValue)); break;
case CABViewControlTypes.STEAM_BOOSTER: (Locomotive as MSTSSteamLocomotive).SetSteamBoosterValue(ChangedValue((Locomotive as MSTSSteamLocomotive).SteamBoosterController.IntermediateValue)); break;
case CABViewControlTypes.ORTS_WATER_SCOOP: if (((Locomotive as MSTSSteamLocomotive).WaterScoopDown ? 1 : 0) != ChangedValue(Locomotive.WaterScoopDown ? 1 : 0)) new ToggleWaterScoopCommand(Viewer.Log); break;
case CABViewControlTypes.ORTS_CIRCUIT_BREAKER_DRIVER_CLOSING_ORDER:
new CircuitBreakerClosingOrderCommand(Viewer.Log, ChangedValue((Locomotive as MSTSElectricLocomotive).ElectricPowerSupply.CircuitBreaker.DriverClosingOrder ? 1 : 0) > 0);
Expand Down
Expand Up @@ -204,6 +204,8 @@ public override void InitializeUserInputCommands()
UserInputCommands.Add(UserCommand.ControlSmallEjectorDecrease, new Action[] { () => SteamLocomotive.StopSmallEjectorDecrease(), () => SteamLocomotive.StartSmallEjectorDecrease(null) });
UserInputCommands.Add(UserCommand.ControlLargeEjectorIncrease, new Action[] { () => SteamLocomotive.StopLargeEjectorIncrease(), () => SteamLocomotive.StartLargeEjectorIncrease(null) });
UserInputCommands.Add(UserCommand.ControlLargeEjectorDecrease, new Action[] { () => SteamLocomotive.StopLargeEjectorDecrease(), () => SteamLocomotive.StartLargeEjectorDecrease(null) });
UserInputCommands.Add(UserCommand.ControlSteamBoosterIncrease, new Action[] { () => SteamLocomotive.StopSteamBoosterIncrease(), () => SteamLocomotive.StartSteamBoosterIncrease(null) });
UserInputCommands.Add(UserCommand.ControlSteamBoosterDecrease, new Action[] { () => SteamLocomotive.StopSteamBoosterDecrease(), () => SteamLocomotive.StartSteamBoosterDecrease(null) });
base.InitializeUserInputCommands();
}

Expand Down