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
22 changes: 11 additions & 11 deletions source/ObjectViewer/Trains/NearestTrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,7 @@ static NearestTrain()
private static TrainBase CreateDummyTrain()
{
TrainBase train = new TrainBase(TrainState.Available, TrainType.LocalPlayerTrain);
train.Handles.Power = new PowerHandle(Specs.PowerNotches, train);
if (Specs.IsAirBrake)
{
train.Handles.Brake = new AirBrakeHandle(train);
}
else
{
train.Handles.Brake = new BrakeHandle(Specs.BrakeNotches, null, train);
train.Handles.HasHoldBrake = Specs.HasHoldBrake;
}
train.Handles.HoldBrake = new HoldBrakeHandle(train);

train.Specs.HasConstSpeed = Specs.HasConstSpeed;

Array.Resize(ref train.Cars, Specs.NumberOfCars);
Expand Down Expand Up @@ -88,6 +78,16 @@ private static TrainBase CreateDummyTrain()
train.Cars[i].Doors[1] = new Door(1, 1000.0, 0.0);
}

train.Handles.Power = new PowerHandle(Specs.PowerNotches, train);
if (Specs.IsAirBrake)
{
train.Handles.Brake = new AirBrakeHandle(train);
}
else
{
train.Handles.Brake = new BrakeHandle(Specs.BrakeNotches, null, train);
train.Handles.HasHoldBrake = Specs.HasHoldBrake;
}
if (Specs.HasLocoBrake)
{
train.Handles.HasLocoBrake = true;
Expand Down
1 change: 0 additions & 1 deletion source/Plugins/Route.Bve5/Components/ScriptedTrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ private static void LoadScriptedTrain(string FileName, bool PreviewOnly, MapData

TrainManager.Trains.ScriptedTrain Train = new TrainManager.Trains.ScriptedTrain(TrainState.Pending);
Train.Cars = new CarBase[OtherTrain.CarObjects.Count];
Train.Handles.Reverser = new ReverserHandle(Train);

for (int i = 0; i < Train.Cars.Length; i++)
{
Expand Down
8 changes: 0 additions & 8 deletions source/Plugins/Train.MsTs/Train/ConsistParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ internal void ReadConsist(string fileName, ref AbstractTrain parsedTrain)
{
throw new Exception();
}
train.Handles.Reverser = new ReverserHandle(train);
train.Handles.EmergencyBrake = new EmergencyHandle(train);
train.Handles.Power = new PowerHandle(8, train);
train.Handles.Brake = new BrakeHandle(8, train.Handles.EmergencyBrake, train);
train.Handles.LocoBrake = new LocoBrakeHandle(0, train.Handles.EmergencyBrake, train);
train.Handles.LocoBrakeType = LocoBrakeType.Independant;
train.Handles.HasLocoBrake = false;
train.Handles.HoldBrake = new HoldBrakeHandle(train);
train.Specs.AveragesPressureDistribution = true;
train.SafetySystems.Headlights = new LightSource(train, 2);
if(Directory.Exists(Plugin.FileSystem.MSTSDirectory))
Expand Down
40 changes: 21 additions & 19 deletions source/Plugins/Train.OpenBve/Train/BVE/TrainDatParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,28 @@ internal void Parse(string FileName, Encoding Encoding, TrainBase Train) {
Plugin.CurrentHost.AddMessage(MessageType.Error, false, "TrailerCarMass is expected to be positive in " + FileName);
TrailerCarMass = 1.0;
}

}


// apply data (need to set driver car first to ensure handles are assigned to the correct place)
if (MotorCars < 1) MotorCars = 1;
if (TrailerCars < 0) TrailerCars = 0;
int Cars = MotorCars + TrailerCars;
Train.Cars = new CarBase[Cars];
for (int i = 0; i < Train.Cars.Length; i++)
{
Train.Cars[i] = new CarBase(Train, i, CoefficientOfStaticFriction, CoefficientOfRollingResistance, AerodynamicDragCoefficient);
}
double DistanceBetweenTheCars = 0.3;

if (DriverCar < 0 || DriverCar >= Cars)
{
Plugin.CurrentHost.AddMessage(MessageType.Error, false, "DriverCar must point to an existing car in " + FileName);
}
else
{
Train.DriverCar = DriverCar;
}

if (powerNotches == 0)
{
Plugin.CurrentHost.AddMessage(MessageType.Error, false, "NumberOfPowerNotches was not set in " + FileName);
Expand Down Expand Up @@ -1078,24 +1097,7 @@ internal void Parse(string FileName, Encoding Encoding, TrainBase Train) {
Train.Handles.LocoBrake = new LocoBrakeHandle(locoBrakeNotches, Train.Handles.EmergencyBrake, locoBrakeDelayUp, locoBrakeDelayDown, Train);
}
Train.Handles.LocoBrakeType = (LocoBrakeType)locoBrakeType;
Train.Handles.HoldBrake = new HoldBrakeHandle(Train);
// apply data
if (MotorCars < 1) MotorCars = 1;
if (TrailerCars < 0) TrailerCars = 0;
int Cars = MotorCars + TrailerCars;
Train.Cars = new CarBase[Cars];
for (int i = 0; i < Train.Cars.Length; i++)
{
Train.Cars[i] = new CarBase(Train, i, CoefficientOfStaticFriction, CoefficientOfRollingResistance, AerodynamicDragCoefficient);
}
double DistanceBetweenTheCars = 0.3;

if (DriverCar < 0 | DriverCar >= Cars) {
Plugin.CurrentHost.AddMessage(MessageType.Error, false, "DriverCar must point to an existing car in " + FileName);
DriverCar = 0;

}
Train.DriverCar = DriverCar;
// brake system
double OperatingPressure;
if (BrakePipePressure <= 0.0) {
Expand Down
8 changes: 5 additions & 3 deletions source/TrainManager/Car/CarBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class CarBase : AbstractCar
public Door[] Doors;
/// <summary>The horns attached to this car</summary>
public Horn[] Horns;
/// <summary>The cab handles</summary>
/// <remarks>This property will be null if the vehicle does not posses a cab</remarks>
public CabHandles Handles;
/// <summary>Contains the physics properties for the car</summary>
public readonly CarPhysics Specs;
/// <summary>The car brake for this car</summary>
Expand Down Expand Up @@ -443,9 +446,8 @@ public override void Uncouple(bool Front, bool Rear)
// Create new train
TrainBase newTrain = new TrainBase(TrainState.Available, TrainType.StaticCars);
UncouplingBehaviour uncouplingBehaviour = UncouplingBehaviour.Emergency;
newTrain.Handles.Power = new PowerHandle(0, newTrain);
newTrain.Handles.Brake = new BrakeHandle(0, newTrain.Handles.EmergencyBrake, newTrain);
newTrain.Handles.HoldBrake = new HoldBrakeHandle(newTrain);
newTrain.Cars[0].Handles = new CabHandles(newTrain);

if (Front)
{
int totalPreceedingCars = trainCarIndex;
Expand Down
19 changes: 15 additions & 4 deletions source/TrainManager/Handles/CabHandles.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using OpenBveApi.Interface;
using TrainManager.Trains;

namespace TrainManager.Handles
{
/// <summary>The cab handles (controls) of a train</summary>
public struct CabHandles
public class CabHandles
{
/// <summary>The Reverser</summary>
public ReverserHandle Reverser;
public readonly ReverserHandle Reverser;
/// <summary>The Power</summary>
public AbstractHandle Power;
/// <summary>The Brake</summary>
public AbstractHandle Brake;
/// <summary>The Loco brake handle</summary>
public AbstractHandle LocoBrake;
/// <summary>The Emergency Brake</summary>
public EmergencyHandle EmergencyBrake;
public readonly EmergencyHandle EmergencyBrake;
/// <summary>The Hold Brake</summary>
public HoldBrakeHandle HoldBrake;
public readonly HoldBrakeHandle HoldBrake;
/// <summary>Whether the train has a combined power and brake handle</summary>
public HandleType HandleType;
/// <summary>Whether the train has the Hold Brake fitted</summary>
Expand All @@ -26,6 +27,16 @@ public struct CabHandles
/// <summary>The loco brake type</summary>
public LocoBrakeType LocoBrakeType;

public CabHandles(TrainBase train)
{
Reverser = new ReverserHandle(train);
EmergencyBrake = new EmergencyHandle(train);
HoldBrake = new HoldBrakeHandle(train);

Power = new PowerHandle(0, train);
Brake = new BrakeHandle(0, EmergencyBrake, train);
}

public void ControlDown(Control Control)
{
switch (Control.Command)
Expand Down
6 changes: 2 additions & 4 deletions source/TrainManager/Train/TrainBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class TrainBase : AbstractTrain
/// <summary>Contains information on the specifications of the train</summary>
public TrainSpecs Specs;
/// <summary>The cab handles</summary>
public CabHandles Handles;
public CabHandles Handles => Cars[DriverCar].Handles;
/// <summary>Holds the safety systems for the train</summary>
public TrainSafetySystems SafetySystems;
/// <summary>Holds the cars</summary>
Expand Down Expand Up @@ -152,11 +152,9 @@ public TrainBase(TrainState state, TrainType type)
Specs.DoorCloseMode = DoorMode.AutomaticManualOverride;
Specs.PantographState = PantographState.Lowered;
DriverBody = new DriverBody(this);
Handles.Reverser = new ReverserHandle(this);
Handles.EmergencyBrake = new EmergencyHandle(this);
}

/// <summary>Called once when the simulation loads to initalize the train</summary>
/// <summary>Called once when the simulation loads to initialize the train</summary>
public virtual void Initialize()
{
for (int i = 0; i < Cars.Length; i++)
Expand Down