using System;
using OpenBveApi.Runtime;
namespace OpenbveFcmbTrainPlugin
{
/// The interface to be implemented by the plugin.
public class OpenbveFcmbTrainPlugin : IRuntime
{
/// The train that is simulated by this plugin.
private Train Train;
/// The route where the train is running.
private Route Route;
/// Whether the train is initializing or reinitializing.
internal static bool Initializing = true;
/// Remembers which of the virtual keys are currently pressed down.
internal static bool[] KeysPressed = new bool[Enum.GetNames(typeof(VirtualKeys)).Length];
/// Is called when the plugin is loaded.
/// The properties supplied to the plugin on loading.
/// Whether the plugin was loaded successfully.
public bool Load(LoadProperties properties)
{
properties.AISupport = AISupport.Basic;
properties.Panel = new int[256];
Train = new Train(properties.Panel);
Route = new Route();
MessageManager.Initialize(properties.AddMessage, properties.AddScore);
SoundManager.Initialize(256, properties.PlaySound, properties.PlayCarSound, properties.PlayMultipleCarSound);
return true;
}
/// Is called when the plugin is unloaded.
public void Unload()
{
}
/// Is called after loading to inform the plugin about the specifications of the train.
/// The specifications of the train.
public void SetVehicleSpecs(VehicleSpecs specs)
{
Train.SetVehicleSpecs(specs);
}
/// Is called when the plugin should initialize or reinitialize.
/// The mode of initialization.
public void Initialize(InitializationModes mode)
{
// On initialization, a variable is set so the first call to Elapse() can be used for initialization
Initializing = true;
Train.Initialize(mode);
}
/// Is called every frame.
/// The data passed to the plugin.
public void Elapse(ElapseData data)
{
Route.Elapse(data);
Train.Elapse(data, Route);
Initializing = false;
}
/// Is called when the driver changes the reverser.
/// The new reverser position.
public void SetReverser(int reverser)
{
Train.SetReverser(reverser);
}
/// Is called when the driver changes the power notch.
/// The new power notch.
public void SetPower(int powerNotch)
{
Train.SetPower(powerNotch);
}
/// Is called when the driver changes the brake notch.
/// The new brake notch.
public void SetBrake(int brakeNotch)
{
Train.SetBrake(brakeNotch);
}
/// Is called when a virtual key is pressed.
/// The virtual key that was pressed.
public void KeyDown(VirtualKeys key)
{
Train.KeyDown(key);
KeysPressed[(int)key] = true;
}
/// Is called when a virtual key is released.
/// The virtual key that was released.
public void KeyUp(VirtualKeys key)
{
Train.KeyUp(key);
KeysPressed[(int)key] = false;
}
/// Is called when a horn is played or when the music horn is stopped.
/// The type of horn.
public void HornBlow(HornTypes type)
{
}
/// Is called when the state of the doors changes.
/// The old state of the doors.
/// The new state of the doors.
public void DoorChange(DoorStates oldState, DoorStates newState)
{
Route.DoorChange(oldState, newState);
Train.DoorChange(oldState, newState);
}
/// Is called when the aspect in the current or in any of the upcoming sections changes, or when passing section boundaries.
/// The signal array is guaranteed to have at least one element. When accessing elements other than index 0, you must check the bounds of the array first.
public void SetSignal(SignalData[] signal)
{
}
/// Is called when the train passes a beacon.
/// The beacon data.
public void SetBeacon(BeaconData beacon)
{
Train.SetBeacon(beacon);
}
/// Is called when the plugin should perform the AI.
/// The AI data.
public void PerformAI(AIData data)
{
Train.PerformAI(data, Route);
}
}
}