diff --git a/src/Devices/Headlights.cs b/src/Devices/Headlights.cs
new file mode 100644
index 0000000..7d31ec6
--- /dev/null
+++ b/src/Devices/Headlights.cs
@@ -0,0 +1,55 @@
+using System;
+using OpenBveApi.Runtime;
+
+namespace OpenbveFcmbTrainPlugin
+{
+ /// A device handling the headlights.
+ internal class Headlights : Device
+ {
+ /// Is called when the device state should be updated.
+ /// The current train.
+ /// The current route.
+ /// Whether the device should initialize.
+ /// The time elapsed since the previous call.
+ internal override void Update(Train train, Route route, bool init, Time elapsedTime)
+ {
+ // Turn off headlights if the reverser is not set to forward
+ if (train.PhysicalHandles.Reverser < 1)
+ {
+ train.HeadlightState = 0;
+ }
+ }
+
+ /// Is called when the state of a key changes.
+ /// The key.
+ /// Whether the key is pressed or released.
+ /// The current train.
+ internal override void KeyChange(VirtualKeys key, bool pressed, Train train)
+ {
+ if (pressed)
+ {
+ switch (key)
+ {
+ case VirtualKeys.Headlights:
+ // Cycle through headlight states
+ if (!OpenbveFcmbTrainPlugin.KeysPressed[(int)key])
+ {
+ if (train.PhysicalHandles.Reverser == 1)
+ {
+ if (train.HeadlightState < train.Specs.HeadlightStates)
+ {
+ train.HeadlightState++;
+ }
+ else
+ {
+ train.HeadlightState = 0;
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+}
+
diff --git a/src/Managers/ConfigManager.cs b/src/Managers/ConfigManager.cs
index eae5311..631056d 100644
--- a/src/Managers/ConfigManager.cs
+++ b/src/Managers/ConfigManager.cs
@@ -13,6 +13,7 @@ namespace OpenbveFcmbTrainPlugin
{
internal double TrainLength;
+ internal bool HeadlightsDeviceEnabled;
internal bool DoorSelectionDeviceEnabled;
internal bool DoorClosingSoundDeviceEnabled;
internal bool DoorTractionCutDeviceEnabled;
@@ -93,6 +94,14 @@ namespace OpenbveFcmbTrainPlugin
break;
}
break;
+ case "headlights":
+ switch (Key)
+ {
+ case "enabled":
+ PluginSettings.HeadlightsDeviceEnabled = string.Compare(Value, "false", StringComparison.OrdinalIgnoreCase) != 0;
+ break;
+ }
+ break;
case "doorselection":
switch (Key)
{
diff --git a/src/OpenbveFcmbTrainPlugin.csproj b/src/OpenbveFcmbTrainPlugin.csproj
index 22a5da0..d1f03ac 100644
--- a/src/OpenbveFcmbTrainPlugin.csproj
+++ b/src/OpenbveFcmbTrainPlugin.csproj
@@ -49,6 +49,7 @@
+
diff --git a/src/Train/Train.cs b/src/Train/Train.cs
index 1925bda..4242f09 100644
--- a/src/Train/Train.cs
+++ b/src/Train/Train.cs
@@ -33,6 +33,9 @@ namespace OpenbveFcmbTrainPlugin
/// The previous state of the train doors.
internal DoorStates PreviousDoorState { get; private set; }
+ /// The state of the train's headlights.
+ internal int HeadlightState;
+
/// The latest initialization mode of the train.
internal InitializationModes InitializationMode { get; private set; }
@@ -75,6 +78,10 @@ namespace OpenbveFcmbTrainPlugin
// Create list of devices and populate it according to settings
Devices = new List();
ConfigManager.SettingsCollection settings = ConfigManager.PluginSettings;
+ if (settings.HeadlightsDeviceEnabled)
+ {
+ Devices.Add(new Headlights());
+ }
if (settings.DoorSelectionDeviceEnabled)
{
Devices.Add(new DoorSelection());
@@ -129,6 +136,7 @@ namespace OpenbveFcmbTrainPlugin
{
State = data.Vehicle;
DoorInterlockState = data.DoorInterlockState;
+ HeadlightState = data.HeadlightState;
// Reset data to be passed to the simulator
data.DoorInterlockState = DoorInterlockStates.Unlocked;