using System.Collections.Generic; using OpenBveApi.Runtime; namespace OpenbveFcmbTrainPlugin { /// Represents a train that is simulated by this plugin. internal class Train { /// The train panel variables. internal int[] Panel; /// The specifications of the train. internal VehicleSpecs Specs { get; private set; } /// The current state of the train. internal VehicleState State { get; private set; } /// The current state of the train doors. internal DoorStates DoorState { get; private set; } /// The previous state of the train doors. internal DoorStates PreviousDoorState { get; private set; } /// The latest initialization mode of the train. internal InitializationModes InitializationMode { get; private set; } /// The devices equipped in the train. private List Devices; /// Whether the train's vigilance device is overridden. internal bool VigilanceOverride; /// Whether the train is using a continuous protection system instead of an intermittent protection system. internal bool ContinuousProtection; /// Creates a new train with the device configuration provided. /// The array of panel variables.(); Devices.Add(new Doors()); Devices.Add(new Deadman()); Devices.Add(new TrainStop()); } /// Is called when the train should initialize. /// The initialization mode. internal void Initialize(InitializationModes mode) { InitializationMode = mode; } /// Is called after loading to inform the plugin about the specifications of the train. /// The specifications of the train. internal void SetVehicleSpecs(VehicleSpecs specs) { Specs = specs; } /// Is called every frame. /// The data. /// The route data. internal void Elapse(ElapseData data, Route route) { State = data.Vehicle; // Reset data to be passed to the simulator data.DoorInterlockState = DoorInterlockStates.Unlocked; data.Handles.PowerNotch = data.Handles.PowerNotch; data.Handles.BrakeNotch = data.Handles.BrakeNotch; // Retrieve data from all devices foreach (Device dev in Devices) { dev.Update(this, route, OpenbveFcmbTrainPlugin.Initializing, data.ElapsedTime); data.DoorInterlockState |= dev.RequestedDoorInterlock; if (dev.RequestedPowerNotch != -1) data.Handles.PowerNotch = dev.RequestedPowerNotch; if (dev.RequestedBrakeNotch != -1) data.Handles.BrakeNotch = dev.RequestedBrakeNotch; } } /// Is called when the driver changes the reverser. /// The new reverser position. internal void SetReverser(int reverser) { } /// Is called when the driver changes the power notch. /// The new power notch. internal void SetPower(int powerNotch) { } /// Is called when the driver changes the brake notch. /// The new brake notch. internal void SetBrake(int brakeNotch) { } /// Is called when a key is pressed. /// The key. internal void KeyDown(VirtualKeys key) { foreach (Device dev in Devices) { dev.KeyChange(key, true, this); } } /// Is called when a key is released. /// The key. internal void KeyUp(VirtualKeys key) { foreach (Device dev in Devices) { dev.KeyChange(key, false, this); } } /// Is called when the state of the doors changes. /// The old state of the doors. /// The new state of the doors. internal void DoorChange(DoorStates oldState, DoorStates newState) { PreviousDoorState = oldState; DoorState = newState; foreach (Device dev in Devices) { dev.DoorChange(oldState, newState); } } /// Is called when a horn is played or when the music horn is stopped. /// The type of horn. internal void HornBlow(HornTypes type) { } /// Is called to inform about signals. /// The signal data. internal void SetSignal(SignalData[] signal) { } /// Is called when a beacon is passed. /// The beacon data. internal void SetBeacon(BeaconData beacon) { } /// Is called when the plugin should perform the AI. /// The AI data. /// The route data. internal void PerformAI(AIData data, Route route) { foreach (Device dev in Devices) { dev.PerformAI(data, this, route); } } } }