Skip to content

Commit 2063988

Browse files
authored
2 parents 69600d7 + 93bbec3 commit 2063988

File tree

11 files changed

+100
-8
lines changed

11 files changed

+100
-8
lines changed

Source/Documentation/Manual/cabs.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,18 @@ Further OR cab controls
266266
-----------------------
267267

268268
OR supports the cabview control to open/close the left doors, the right doors
269-
and the mirrors.
269+
and the mirrors. Moreover it supports the controls for the battery state and for
270+
the key state; these two controls have no effect on the state of the locomotive.
270271

271272
.. index::
272273
single: ORTS_LEFTDOOR
273274
single: ORTS_RIGHTDOOR
274275
single: ORTS_MIRRORS
276+
single: ORTS_BATTERY
277+
single: ORTS_POWERKEY
275278

276279
The control blocks are like the one shown for the cab light. The Type strings
277-
are ORTS_LEFTDOOR, ORTS_RIGHTDOOR and ORTS_MIRRORS.
280+
are ORTS_LEFTDOOR, ORTS_RIGHTDOOR, ORTS_MIRRORS, ORTS_BATTERY and ORTS_POWERKEY.
278281

279282

280283
High-resolution Cab Backgrounds and Controls

Source/Documentation/Manual/sound.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ Trigger Function
280280
174 HotBoxBearingOff
281281
175 BoilerBlowdownOn
282282
176 BoilerBlowdownOff
283+
177 BatteryOn
284+
178 BatteryOff
285+
179 PowerKeyOn
286+
180 PowerKeyOff
283287
========= =====================================
284288

285289

Source/ORTS.Common/Input/UserCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,7 @@ public enum UserCommand
199199
[GetString("Control AI Fire On")] ControlAIFireOn,
200200
[GetString("Control AI Fire Off")] ControlAIFireOff,
201201
[GetString("Control AI Fire Reset")] ControlAIFireReset,
202+
[GetString("Control Battery")] ControlBattery,
203+
[GetString("Control PowerKey")] ControlPowerKey,
202204
}
203205
}

Source/ORTS.Settings/InputSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ static void InitializeCommands(UserCommandInput[] Commands)
345345
Commands[(int)UserCommand.ControlAlerter] = new UserCommandKeyInput(0x2C);
346346
Commands[(int)UserCommand.ControlBackwards] = new UserCommandKeyInput(0x1F);
347347
Commands[(int)UserCommand.ControlBailOff] = new UserCommandKeyInput(0x35);
348+
Commands[(int)UserCommand.ControlBattery] = new UserCommandKeyInput(0x30, KeyModifiers.Control);
348349
Commands[(int)UserCommand.ControlBell] = new UserCommandKeyInput(0x30);
349350
Commands[(int)UserCommand.ControlBellToggle] = new UserCommandKeyInput(0x30, KeyModifiers.Shift);
350351
Commands[(int)UserCommand.ControlBlowerDecrease] = new UserCommandKeyInput(0x31, KeyModifiers.Shift);
@@ -408,6 +409,7 @@ static void InitializeCommands(UserCommandInput[] Commands)
408409
Commands[(int)UserCommand.ControlPantograph2] = new UserCommandKeyInput(0x19, KeyModifiers.Shift);
409410
Commands[(int)UserCommand.ControlPantograph3] = new UserCommandKeyInput(0x19, KeyModifiers.Control);
410411
Commands[(int)UserCommand.ControlPantograph4] = new UserCommandKeyInput(0x19, KeyModifiers.Shift | KeyModifiers.Control);
412+
Commands[(int)UserCommand.ControlPowerKey] = new UserCommandKeyInput(0x25, KeyModifiers.Control);
411413
Commands[(int)UserCommand.ControlOdoMeterShowHide] = new UserCommandKeyInput(0x2C, KeyModifiers.Shift);
412414
Commands[(int)UserCommand.ControlOdoMeterReset] = new UserCommandKeyInput(0x2C, KeyModifiers.Control);
413415
Commands[(int)UserCommand.ControlOdoMeterDirection] = new UserCommandKeyInput(0x2C, KeyModifiers.Control | KeyModifiers.Shift);

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public enum CABViewControlTypes
181181
ORTS_BAILOFF,
182182
ORTS_QUICKRELEASE,
183183
ORTS_OVERCHARGE,
184+
ORTS_BATTERY,
185+
ORTS_POWERKEY,
184186

185187
// TCS Controls
186188
ORTS_TCS1,

Source/Orts.Simulation/Common/Commands.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,42 @@ public override void Redo() {
994994
// Report();
995995
}
996996
}
997-
997+
998+
[Serializable()]
999+
public sealed class ToggleBatteryCommand : Command
1000+
{
1001+
public static MSTSLocomotive Receiver { get; set; }
1002+
1003+
public ToggleBatteryCommand(CommandLog log)
1004+
: base(log)
1005+
{
1006+
Redo();
1007+
}
1008+
1009+
public override void Redo()
1010+
{
1011+
Receiver.ToggleBattery();
1012+
// Report();
1013+
}
1014+
}
1015+
1016+
[Serializable()]
1017+
public sealed class TogglePowerKeyCommand : Command
1018+
{
1019+
public static MSTSLocomotive Receiver { get; set; }
1020+
1021+
public TogglePowerKeyCommand(CommandLog log)
1022+
: base(log)
1023+
{
1024+
Redo();
1025+
}
1026+
1027+
public override void Redo()
1028+
{
1029+
Receiver.TogglePowerKey();
1030+
// Report();
1031+
}
1032+
}
9981033
// Steam controls
9991034
[Serializable()]
10001035
public sealed class ContinuousSteamHeatCommand : ContinuousCommand

Source/Orts.Simulation/Common/Events.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public interface EventHandler
2727
public enum Event
2828
{
2929
None,
30+
BatteryOff,
31+
BatteryOn,
3032
BellOff,
3133
BellOn,
3234
BlowerChange,
@@ -101,6 +103,8 @@ public enum Event
101103
PermissionDenied,
102104
PermissionGranted,
103105
PermissionToDepart,
106+
PowerKeyOff,
107+
PowerKeyOn,
104108
ReverserChange,
105109
ReverserToForwardBackward,
106110
ReverserToNeutral,
@@ -400,11 +404,11 @@ public static Event From(bool mstsBinEnabled, Source source, int eventID)
400404
case 175: return Event.BoilerBlowdownOn;
401405
case 176: return Event.BoilerBlowdownOff;
402406

403-
// These triggers have been released in MG????
404-
// case 177: return Event.ORTS_BATTERY;
405-
// case 178: return Event.ORTS_BATTERY;
406-
// case 179: return Event.ORTS_POWERKEY;
407-
// case 180: return Event.ORTS_POWERKEY;
407+
case 177: return Event.BatteryOn;
408+
case 178: return Event.BatteryOff;
409+
410+
case 179: return Event.PowerKeyOn;
411+
case 180: return Event.PowerKeyOff;
408412

409413
case 181: return Event.GenericEvent1;
410414
case 182: return Event.GenericEvent2;

Source/Orts.Simulation/Simulation/Confirmer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public enum CabControl {
9797
, Wipers
9898
, ChangeCab
9999
, Odometer
100+
, Battery
101+
, PowerKey
100102
// Train Devices
101103
, DoorsLeft
102104
, DoorsRight
@@ -239,6 +241,8 @@ public Confirmer(Simulator simulator, double defaultDurationS)
239241
, new string [] { GetString("Wipers"), GetString("off"), null, GetString("on") }
240242
, new string [] { GetString("Cab"), null, null, GetParticularString("Cab", "change"), null, null, GetString("changing is not available"), GetString("changing disabled. Close throttle, set reverser to neutral, stop train then re-try.") }
241243
, new string [] { GetString("Odometer"), null, null, GetParticularString("Odometer", "reset"), GetParticularString("Odometer", "counting down"), GetParticularString("Odometer", "counting up") }
244+
, new string [] { GetString("Battery"), GetString("off"), null, GetString("on") }
245+
, new string [] { GetString("PowerKey"), GetString("off"), null, GetString("on")}
242246
// Train Devices
243247
, new string [] { GetString("Doors Left"), GetString("close"), null, GetString("open") }
244248
, new string [] { GetString("Doors Right"), GetString("close"), null, GetString("open") }

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public enum SoundState
143143
public bool CabRadioOn;
144144
public bool OnLineCabRadio;
145145
public string OnLineCabRadioURL;
146+
public bool Battery;
147+
public bool PowerKey;
146148

147149
// Water trough filling
148150
public bool HasWaterScoop = false; // indicates whether loco + tender have a water scoop or not
@@ -1103,6 +1105,8 @@ public override void Save(BinaryWriter outf)
11031105
ControllerFactory.Save(SteamHeatController, outf);
11041106
outf.Write(AcceptMUSignals);
11051107
outf.Write(PowerReduction);
1108+
outf.Write(Battery);
1109+
outf.Write(PowerKey);
11061110
outf.Write(ScoopIsBroken);
11071111
outf.Write(IsWaterScoopDown);
11081112
outf.Write(CurrentTrackSandBoxCapacityM3);
@@ -1145,6 +1149,8 @@ public override void Restore(BinaryReader inf)
11451149
ControllerFactory.Restore(SteamHeatController, inf);
11461150
AcceptMUSignals = inf.ReadBoolean();
11471151
PowerReduction = inf.ReadSingle();
1152+
Battery = inf.ReadBoolean();
1153+
PowerKey = inf.ReadBoolean();
11481154
ScoopIsBroken = inf.ReadBoolean();
11491155
IsWaterScoopDown = inf.ReadBoolean();
11501156
CurrentTrackSandBoxCapacityM3 = inf.ReadSingle();
@@ -3886,6 +3892,20 @@ public void ToggleCabLight()
38863892
Simulator.Confirmer.Confirm(CabControl.CabLight, CabLightOn ? CabSetting.On : CabSetting.Off);
38873893
}
38883894

3895+
public void ToggleBattery()
3896+
{
3897+
Battery = !Battery;
3898+
if (Battery) SignalEvent(Event.BatteryOn);
3899+
else SignalEvent(Event.BatteryOff);
3900+
if (Simulator.PlayerLocomotive == this) Simulator.Confirmer.Confirm(CabControl.Battery, Battery ? CabSetting.On : CabSetting.Off);
3901+
}
3902+
public void TogglePowerKey()
3903+
{
3904+
PowerKey = !PowerKey;
3905+
if (PowerKey) SignalEvent(Event.PowerKeyOn);
3906+
else SignalEvent(Event.PowerKeyOff);
3907+
if (Simulator.PlayerLocomotive == this) Simulator.Confirmer.Confirm(CabControl.PowerKey, PowerKey ? CabSetting.On : CabSetting.Off);
3908+
}
38893909
public void ToggleCabRadio( bool newState)
38903910
{
38913911
CabRadioOn = newState;
@@ -4838,6 +4858,12 @@ public virtual float GetDataOf(CabViewControl cvc)
48384858
case CABViewControlTypes.ORTS_MIRRORS:
48394859
data = MirrorOpen ? 1 : 0;
48404860
break;
4861+
case CABViewControlTypes.ORTS_BATTERY:
4862+
data = Battery ? 1 : 0;
4863+
break;
4864+
case CABViewControlTypes.ORTS_POWERKEY:
4865+
data = PowerKey ? 1 : 0;
4866+
break;
48414867
case CABViewControlTypes.ORTS_HOURDIAL:
48424868
float hour = (float)(Simulator.ClockTime / 3600) % 12;
48434869
if (hour < 0)

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ public override void InitializeUserInputCommands()
179179
UserInputCommands.Add(UserCommand.ControlOdoMeterDirection, new Action[] { Noop, () => new ToggleOdometerDirectionCommand(Viewer.Log) });
180180
UserInputCommands.Add(UserCommand.ControlCabRadio, new Action[] { Noop, () => new CabRadioCommand(Viewer.Log, !Locomotive.CabRadioOn) });
181181
UserInputCommands.Add(UserCommand.ControlDieselHelper, new Action[] { Noop, () => new ToggleHelpersEngineCommand(Viewer.Log) });
182+
UserInputCommands.Add(UserCommand.ControlBattery, new Action[] { Noop, () => new ToggleBatteryCommand(Viewer.Log) });
183+
UserInputCommands.Add(UserCommand.ControlPowerKey, new Action[] { Noop, () => new TogglePowerKeyCommand(Viewer.Log) });
182184
UserInputCommands.Add(UserCommand.ControlGeneric1, new Action[] {
183185
() => new TCSButtonCommand(Viewer.Log, false, 0),
184186
() => {
@@ -1943,6 +1945,8 @@ public int GetDrawIndex()
19431945
case CABViewControlTypes.ORTS_LEFTDOOR:
19441946
case CABViewControlTypes.ORTS_RIGHTDOOR:
19451947
case CABViewControlTypes.ORTS_MIRRORS:
1948+
case CABViewControlTypes.ORTS_BATTERY:
1949+
case CABViewControlTypes.ORTS_POWERKEY:
19461950
index = (int)data;
19471951
break;
19481952

@@ -2154,6 +2158,10 @@ public void HandleUserInput()
21542158
!= ChangedValue(Locomotive.GetCabFlipped() ? (Locomotive.DoorLeftOpen ? 1 : 0) : Locomotive.DoorRightOpen ? 1 : 0)) new ToggleDoorsRightCommand(Viewer.Log); break;
21552159
case CABViewControlTypes.ORTS_MIRRORS:
21562160
if ((Locomotive.MirrorOpen ? 1 : 0) != ChangedValue(Locomotive.MirrorOpen ? 1 : 0)) new ToggleMirrorsCommand(Viewer.Log); break;
2161+
case CABViewControlTypes.ORTS_BATTERY:
2162+
if ((Locomotive.Battery ? 1 : 0) != ChangedValue(Locomotive.Battery ? 1 : 0)) new ToggleBatteryCommand(Viewer.Log); break;
2163+
case CABViewControlTypes.ORTS_POWERKEY:
2164+
if ((Locomotive.PowerKey ? 1 : 0) != ChangedValue(Locomotive.PowerKey ? 1 : 0)) new TogglePowerKeyCommand(Viewer.Log); break;
21572165

21582166
// Train Control System controls
21592167
case CABViewControlTypes.ORTS_TCS1:

0 commit comments

Comments
 (0)