Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/ORTS.Settings/InputSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ static void InitializeCommands(UserCommandInput[] Commands)
Commands[(int)UserCommand.ControlSpeedRegulatorMaxAccelerationDecrease] = new UserCommandKeyInput(0x1E, KeyModifiers.Control | KeyModifiers.Shift);
Commands[(int)UserCommand.ControlSpeedRegulatorSelectedSpeedIncrease] = new UserCommandKeyInput(0x20, KeyModifiers.Shift);
Commands[(int)UserCommand.ControlSpeedRegulatorSelectedSpeedDecrease] = new UserCommandKeyInput(0x1E, KeyModifiers.Shift);
Commands[(int)UserCommand.ControlNumberOfAxlesIncrease] = new UserCommandKeyInput(0x48, KeyModifiers.Shift);
Commands[(int)UserCommand.ControlNumberOfAxlesDecrease] = new UserCommandKeyInput(0x50, KeyModifiers.Shift);
Commands[(int)UserCommand.ControlNumberOfAxlesIncrease] = new UserCommandKeyInput(0x48, KeyModifiers.Control | KeyModifiers.Shift);
Commands[(int)UserCommand.ControlNumberOfAxlesDecrease] = new UserCommandKeyInput(0x50, KeyModifiers.Control | KeyModifiers.Shift);
Commands[(int)UserCommand.ControlRestrictedSpeedZoneActive] = new UserCommandKeyInput(0x13, KeyModifiers.Control | KeyModifiers.Shift);
Commands[(int)UserCommand.ControlCruiseControlModeDecrease] = new UserCommandKeyInput(0x1E, KeyModifiers.Control);
Commands[(int)UserCommand.ControlCruiseControlModeIncrease] = new UserCommandKeyInput(0x20, KeyModifiers.Control);
Expand Down
22 changes: 21 additions & 1 deletion Source/Orts.Formats.Msts/CabViewFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,27 @@ public enum CABViewControlTypes
ORTS_NUMBER_OF_AXES_INCREASE,
ORTS_NUMBER_OF_AXES_DECREASE,
ORTS_MULTI_POSITION_CONTROLLER,

ORTS_CC_SPEED_0,
ORTS_CC_SPEED_10,
ORTS_CC_SPEED_20,
ORTS_CC_SPEED_30,
ORTS_CC_SPEED_40,
ORTS_CC_SPEED_50,
ORTS_CC_SPEED_60,
ORTS_CC_SPEED_70,
ORTS_CC_SPEED_80,
ORTS_CC_SPEED_90,
ORTS_CC_SPEED_100,
ORTS_CC_SPEED_110,
ORTS_CC_SPEED_120,
ORTS_CC_SPEED_130,
ORTS_CC_SPEED_140,
ORTS_CC_SPEED_150,
ORTS_CC_SPEED_160,
ORTS_CC_SPEED_170,
ORTS_CC_SPEED_180,
ORTS_CC_SPEED_190,
ORTS_CC_SPEED_200,

// Further CabViewControlTypes must be added above this line, to avoid their malfunction in 3DCabs
EXTERNALWIPERS,
Expand Down
90 changes: 75 additions & 15 deletions Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ public float OdometerM
public bool IsAPartOfPlayerTrain = false;
public float ThrottleOverriden = 0;
public int AccelerationBits = 0;
public bool
Speed0Pressed, Speed10Pressed, Speed20Pressed, Speed30Pressed, Speed40Pressed, Speed50Pressed
, Speed60Pressed, Speed70Pressed, Speed80Pressed, Speed90Pressed, Speed100Pressed
, Speed110Pressed, Speed120Pressed, Speed130Pressed, Speed140Pressed, Speed150Pressed
, Speed160Pressed, Speed170Pressed, Speed180Pressed, Speed190Pressed, Speed200Pressed;

public MSTSLocomotive(Simulator simulator, string wagPath)
: base(simulator, wagPath)
Expand Down Expand Up @@ -1685,15 +1690,27 @@ public override void Update(float elapsedClockSeconds)
//UpdateMotiveForce(elapsedClockSeconds, t, AbsSpeedMpS, AbsWheelSpeedMpS);
CheckAccelerationBits(elapsedClockSeconds, AbsWheelSpeedMpS);

if (CruiseControl != null)
if (CruiseControl != null && !TrainBrakeController.TCSEmergencyBraking)
{
if (!IsPlayerTrain || CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Manual || CruiseControl.UseThrottle)
{
CruiseControl.WasForceReset = false;
UpdateMotiveForce(elapsedClockSeconds, t, AbsSpeedMpS, AbsWheelSpeedMpS);
else
}
else if (CruiseControl.SelectedSpeedMpS > 0)
CruiseControl.Update(elapsedClockSeconds, AbsWheelSpeedMpS);
else if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto)
CruiseControl.Update(elapsedClockSeconds, AbsWheelSpeedMpS);
else
UpdateMotiveForce(elapsedClockSeconds, t, AbsSpeedMpS, AbsWheelSpeedMpS);

}
else
{
if (CruiseControl != null && (TrainBrakeController.TCSEmergencyBraking || TrainBrakeController.TCSFullServiceBraking))
CruiseControl.WasBraking = true;
UpdateMotiveForce(elapsedClockSeconds, t, AbsSpeedMpS, AbsWheelSpeedMpS);
}

if (MultiPositionControllers != null)
{
Expand Down Expand Up @@ -2078,6 +2095,10 @@ protected virtual void UpdateMotiveForce(float elapsedClockSeconds, float t, flo
{
// Method to set force and power info
// An alternative method in the steam locomotive will override this and input force and power info for it.

if (IsAPartOfPlayerTrain) t = ThrottleOverriden;
if (t > 1)
t = 1;
if (PowerOn && Direction != Direction.N)
{
if (TractiveForceCurves == null)
Expand Down Expand Up @@ -2985,9 +3006,16 @@ public virtual void StartReverseDecrease(float? target)
#region ThrottleController
public void StartThrottleIncrease(float? target)
{
if (CruiseControl != null && target != null)
{
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto && CruiseControl.UseThrottleAsSpeedSelector)
{
CruiseControl.SpeedRegulatorSelectedSpeedStartIncrease();
return;
}
}
if (ThrottleController.CurrentValue >= ThrottleController.MaximumValue)
return;

if (target != null) ThrottleController.StartIncrease(target);
else new NotchedThrottleCommand(Simulator.Log, true);

Expand All @@ -3013,7 +3041,7 @@ public void StartThrottleIncrease()
}
}
}
if (CruiseControl != null)
if (CruiseControl != null && CombinedControlType == CombinedControl.None)
{
if (CruiseControl.UseThrottleAsForceSelector && CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto)
{
Expand All @@ -3024,12 +3052,20 @@ public void StartThrottleIncrease()
{
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto)
{
return;
if (!CruiseControl.UseThrottleAsSpeedSelector)
return;
}
}
}

if (DynamicBrakeController != null && DynamicBrakeController.CurrentValue >= 0 && (DynamicBrakePercent >= 0 || !(DynamicBrakePercent == -1 && !DynamicBrake || DynamicBrakePercent >= 0 && DynamicBrake)))
bool checkBraking = true;
if (CruiseControl != null)
{
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto && CruiseControl.UseThrottleAsSpeedSelector)
{
checkBraking = false;
}
}
if (DynamicBrakeController != null && DynamicBrakeController.CurrentValue >= 0 && (DynamicBrakePercent >= 0 || !(DynamicBrakePercent == -1 && !DynamicBrake || DynamicBrakePercent >= 0 && DynamicBrake)) && checkBraking)
{
if (!(CombinedControlType == CombinedControl.ThrottleDynamic
|| CombinedControlType == CombinedControl.ThrottleAir && TrainBrakeController.CurrentValue > 0))
Expand Down Expand Up @@ -3073,8 +3109,9 @@ public void StopThrottleIncrease()
}
else
{
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto)
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto && CruiseControl.UseThrottleAsSpeedSelector && CruiseControl.SelectedSpeedMpS > 0)
{
CruiseControl.SpeedRegulatorSelectedSpeedStopIncrease();
return;
}
}
Expand All @@ -3092,6 +3129,15 @@ public void StopThrottleIncrease()

public void StartThrottleDecrease(float? target)
{
if (CruiseControl != null)
{
if (CruiseControl.UseThrottleAsSpeedSelector && CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto && CruiseControl.SelectedSpeedMpS > 0)
{
CruiseControl.SpeedRegulatorSelectedSpeedStartDecrease();
return;
}
}

if (ThrottleController.CurrentValue <= ThrottleController.MinimumValue)
return;

Expand Down Expand Up @@ -3121,7 +3167,7 @@ public void StartThrottleDecrease()
}
}
}
if (CruiseControl != null)
if (CruiseControl != null && CombinedControlType == CombinedControl.None)
{
if (CruiseControl.UseThrottleAsForceSelector && CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto)
{
Expand All @@ -3130,12 +3176,19 @@ public void StartThrottleDecrease()
}
else
{
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto)
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto && !CruiseControl.UseThrottleAsSpeedSelector)
{
return;
}
}
}
if (CruiseControl != null)
{
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto && CruiseControl.UseThrottleAsSpeedSelector && CruiseControl.SelectedSpeedMpS > 0)
{
ThrottleController.CurrentValue = 1;
}
}
if (CombinedControlType == CombinedControl.ThrottleDynamic && ThrottleController.CurrentValue <= 0)
StartDynamicBrakeIncrease(null);
else if (CombinedControlType == CombinedControl.ThrottleAir && ThrottleController.CurrentValue <= 0)
Expand Down Expand Up @@ -3163,17 +3216,16 @@ public void StopThrottleDecrease()
}
if (CruiseControl != null)
{
if (CruiseControl.UseThrottleAsForceSelector && CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto)
if (CruiseControl.UseThrottleAsSpeedSelector && CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto && CruiseControl.SelectedSpeedMpS > 0)
{
CruiseControl.SpeedRegulatorMaxForceStopDecrease();
CruiseControl.SpeedRegulatorSelectedSpeedStopDecrease();
return;
}
else
{
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto)
if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Auto && CruiseControl.SelectedSpeedMpS > 0)
{
speedSelectorModeDecreasing = false;
return;
}
}
}
Expand Down Expand Up @@ -3428,8 +3480,12 @@ public float GetCombinedHandleValue(bool intermediateValue)
return CombinedControlSplitPosition + (1 - CombinedControlSplitPosition) * (intermediateValue ? DynamicBrakeController.IntermediateValue : DynamicBrakeController.CurrentValue);
else if (CombinedControlType == CombinedControl.ThrottleAir && TrainBrakeController.CurrentValue > 0)
return CombinedControlSplitPosition + (1 - CombinedControlSplitPosition) * (intermediateValue ? TrainBrakeController.IntermediateValue : TrainBrakeController.CurrentValue);
else
else if (CruiseControl == null)
return CombinedControlSplitPosition * (1 - (intermediateValue ? ThrottleController.IntermediateValue : ThrottleController.CurrentValue));
else if (CruiseControl.SpeedRegMode == CruiseControl.SpeedRegulatorMode.Manual)
return CombinedControlSplitPosition * (1 - (intermediateValue ? ThrottleController.IntermediateValue : ThrottleController.CurrentValue));
else
return CombinedControlSplitPosition * (1 - (CruiseControl.SelectedSpeedMpS / MaxSpeedMpS));
}
#endregion

Expand Down Expand Up @@ -3551,6 +3607,10 @@ public void StartTrainBrakeIncrease(float? target)
AlerterReset(TCSEvent.TrainBrakeChanged);
TrainBrakeController.StartIncrease(target);
TrainBrakeController.CommandStartTime = Simulator.ClockTime;
if (CruiseControl != null)
{
CruiseControl.TrainBrakePriority = true;
}
Simulator.Confirmer.Confirm(CabControl.TrainBrake, CabSetting.Increase, GetTrainBrakeStatus());
SignalEvent(Event.TrainBrakeChange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public MultiPositionController(MSTSLocomotive locomotive)
public bool StateChanged = false;

public ControllerPosition controllerPosition = new ControllerPosition();
public ControllerCruiseControlLogic cruiseControlLogic = new ControllerCruiseControlLogic();
public ControllerBinding controllerBinding = new ControllerBinding();
protected float elapsedSecondsFromLastChange = 0;
protected bool checkNeutral = false;
Expand Down Expand Up @@ -123,24 +122,6 @@ public void Parse(string lowercasetoken, STFReader stf)
break;
case "engine(ortsmultipositioncontroller(controllerid": ControllerId = stf.ReadIntBlock(0); break;
case "engine(ortsmultipositioncontrollercancontroltrainbrake": CanControlTrainBrake = stf.ReadBoolBlock(false); break;
case "engine(ortscruisecontrol(controllercruisecontrollogic":
{
String speedControlLogic = stf.ReadStringBlock("none").ToLower();
switch (speedControlLogic)
{
case "full":
{
cruiseControlLogic = ControllerCruiseControlLogic.Full;
break;
}
case "speedonly":
{
cruiseControlLogic = ControllerCruiseControlLogic.SpeedOnly;
break;
}
}
break;
}
}
}
public void Update(float elapsedClockSeconds)
Expand Down Expand Up @@ -177,8 +158,8 @@ public void Update(float elapsedClockSeconds)
{
emergencyBrake = false;
}
if (Locomotive.TrainBrakeController.TCSEmergencyBraking)
Locomotive.TrainBrakeController.TCSEmergencyBraking = false;
/* if (Locomotive.TrainBrakeController.TCSEmergencyBraking)
Locomotive.TrainBrakeController.TCSEmergencyBraking = false; */
elapsedSecondsFromLastChange += elapsedClockSeconds;
// Simulator.Confirmer.MSG(currentPosition.ToString());
if (checkNeutral)
Expand Down Expand Up @@ -450,22 +431,36 @@ public void Update(float elapsedClockSeconds)
}
else if (haveCruiseControl && ccAutoMode)
{
if (cruiseControlLogic == ControllerCruiseControlLogic.SpeedOnly)
if (Locomotive.CruiseControl.CruiseControlLogic == CruiseControl.ControllerCruiseControlLogic.SpeedOnly)
{
if (controllerPosition == ControllerPosition.ThrottleIncrease || controllerPosition == ControllerPosition.ThrottleIncreaseFast)
if (controllerPosition == ControllerPosition.ThrottleIncrease)
{
if (!Locomotive.CruiseControl.ContinuousSpeedIncreasing && movedForward) return;
movedForward = true;
Locomotive.CruiseControl.SelectedSpeedMpS = Locomotive.CruiseControl.SelectedSpeedMpS + Locomotive.CruiseControl.SpeedRegulatorNominalSpeedStepMpS;
if (Locomotive.CruiseControl.SelectedSpeedMpS > Locomotive.MaxSpeedMpS) Locomotive.CruiseControl.SelectedSpeedMpS = Locomotive.MaxSpeedMpS;
}
if (controllerPosition == ControllerPosition.ThrottleDecrease || controllerPosition == ControllerPosition.ThrottleDecreaseFast)
if (controllerPosition == ControllerPosition.ThrottleIncreaseFast)
{
if (!Locomotive.CruiseControl.ContinuousSpeedIncreasing && movedForward) return;
movedForward = true;
Locomotive.CruiseControl.SelectedSpeedMpS = Locomotive.CruiseControl.SelectedSpeedMpS + Locomotive.CruiseControl.SpeedRegulatorNominalSpeedStepMpS * 2;
if (Locomotive.CruiseControl.SelectedSpeedMpS > Locomotive.MaxSpeedMpS) Locomotive.CruiseControl.SelectedSpeedMpS = Locomotive.MaxSpeedMpS;
}
if (controllerPosition == ControllerPosition.ThrottleDecrease)
{
if (!Locomotive.CruiseControl.ContinuousSpeedDecreasing && movedAft) return;
movedAft = true;
Locomotive.CruiseControl.SelectedSpeedMpS = Locomotive.CruiseControl.SelectedSpeedMpS - Locomotive.CruiseControl.SpeedRegulatorNominalSpeedStepMpS;
if (Locomotive.CruiseControl.SelectedSpeedMpS < 0) Locomotive.CruiseControl.SelectedSpeedMpS = 0;
}
if (controllerPosition == ControllerPosition.ThrottleDecreaseFast)
{
if (!Locomotive.CruiseControl.ContinuousSpeedDecreasing && movedAft) return;
movedAft = true;
Locomotive.CruiseControl.SelectedSpeedMpS = Locomotive.CruiseControl.SelectedSpeedMpS - Locomotive.CruiseControl.SpeedRegulatorNominalSpeedStepMpS * 2;
if (Locomotive.CruiseControl.SelectedSpeedMpS < 0) Locomotive.CruiseControl.SelectedSpeedMpS = 0;
}
return;
}
if (controllerPosition == ControllerPosition.ThrottleIncrease)
Expand Down Expand Up @@ -886,12 +881,6 @@ public enum ControllerPosition
SelectedSpeedDecrease,
SelectSpeedZero
};
public enum ControllerCruiseControlLogic
{
None,
Full,
SpeedOnly
}

public enum ControllerBinding
{
Expand Down
Loading