Skip to content
Merged
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
8 changes: 5 additions & 3 deletions assets/Controls/Default.controls
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ DECREASE_CUTOFF, keyboard, U, 2
ROUTE_INFORMATION, keyboard, F9, 0
SHOW_EVENTS, keyboard, E, 3
DEBUG_ATS, keyboard, F10, 2
ACCESSIBILITY_CURRENT_SPEED, keyboard, s, 3
ACCESSIBILITY_NEXT_SIGNAL, keyboard, a, 3
ACCESSIBILITY_NEXT_STATION, keyboard, t, 3
ACCESSIBILITY_CURRENT_SPEED, keyboard, S, 3
ACCESSIBILITY_NEXT_SIGNAL, keyboard, A, 3
ACCESSIBILITY_NEXT_STATION, keyboard, T, 3
UNCOUPLE_REAR, keyboard, Semicolon, 2
UNCOUPLE_FRONT, keyboard, Semicolon, 3
12 changes: 12 additions & 0 deletions assets/Languages/en-US.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,18 @@
<trans-unit id="mousegrab_off">
<source>Mouse grab: off</source>
</trans-unit>
<trans-unit id="switchexterior_uncouple">
<source>Please switch to exterior view to uncouple.</source>
</trans-unit>
<trans-unit id="unable_uncouple">
<source>Unable to uncouple this car.</source>
</trans-unit>
<trans-unit id="exterior_uncouplerear">
<source>Uncoupling the rear of car number</source>
</trans-unit>
<trans-unit id="exterior_uncouplefront">
<source>Uncoupling the front of car number</source>
</trans-unit>
</group>
<group id="score">
<trans-unit id="overspeed">
Expand Down
4 changes: 0 additions & 4 deletions source/ObjectViewer/Trains/NearestTrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ static NearestTrain()
private static TrainBase CreateDummyTrain()
{
TrainBase train = new TrainBase(TrainState.Available);

train.Handles.Reverser = new ReverserHandle(train);
train.Handles.Power = new PowerHandle(Specs.PowerNotches, Specs.PowerNotches, new double[] { }, new double[] { }, train);
if (Specs.IsAirBrake)
{
Expand All @@ -57,15 +55,13 @@ private static TrainBase CreateDummyTrain()
train.Handles.Brake = new BrakeHandle(Specs.BrakeNotches, Specs.BrakeNotches, null, new double[] { }, new double[] { }, train);
train.Handles.HasHoldBrake = Specs.HasHoldBrake;
}
train.Handles.EmergencyBrake = new EmergencyHandle(train);
train.Handles.HoldBrake = new HoldBrakeHandle(train);
train.Specs.HasConstSpeed = Specs.HasConstSpeed;

Array.Resize(ref train.Cars, Specs.NumberOfCars);
for (int i = 0; i < train.Cars.Length; i++)
{
train.Cars[i] = new CarBase(train, i);
train.Cars[i].Specs = new CarPhysics();

if (Specs.IsAirBrake)
{
Expand Down
35 changes: 35 additions & 0 deletions source/OpenBVE/System/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,41 @@ public override AbstractTrain[] Trains
}
}

public override void AddTrain(AbstractTrain ReferenceTrain, AbstractTrain NewTrain, bool Preccedes)
{
Array.Resize(ref Program.TrainManager.Trains, Program.TrainManager.Trains.Length + 1);
int trainIndex = -1;
// find index of train within trainmanager array
for (int i = 0; i < Program.TrainManager.Trains.Length; i++)
{
if (Program.TrainManager.Trains[i] == ReferenceTrain)
{
trainIndex = i;
break;
}
}

if (Preccedes && trainIndex > 0)
{
trainIndex--;
}

if (trainIndex == -1)
{
Program.TrainManager.Trains[Program.TrainManager.Trains.Length - 1] = (TrainBase)NewTrain;
}
else
{
for (int i = Program.TrainManager.Trains.Length - 2; i > trainIndex; i--)
{
Program.TrainManager.Trains[i + 1] = Program.TrainManager.Trains[i];
}

Program.TrainManager.Trains[trainIndex + 1] = (TrainBase)NewTrain;
}

}

public override AbstractTrain ClosestTrain(AbstractTrain Train)
{
TrainBase baseTrain = Train as TrainBase;
Expand Down
39 changes: 39 additions & 0 deletions source/OpenBVE/System/Input/ProcessControls.Digital.cs
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,45 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro
}
}

break;
case Translations.Command.UncoupleFront:
if (Program.Renderer.Camera.CurrentMode != CameraViewMode.Exterior)
{
MessageManager.AddMessage(
Translations.GetInterfaceString("notification_switchexterior_uncouple"),
MessageDependency.None, GameMode.Expert,
MessageColor.White, Program.CurrentRoute.SecondsSinceMidnight + 5.0, null);
return;
}

if (TrainManager.PlayerTrain.CameraCar == 0)
{
MessageManager.AddMessage(
Translations.GetInterfaceString("notification_unable_uncouple"),
MessageDependency.None, GameMode.Expert,
MessageColor.White, Program.CurrentRoute.SecondsSinceMidnight + 5.0, null);
return;
}
MessageManager.AddMessage(
Translations.GetInterfaceString("notification_exterior_uncouplefront") + " " +TrainManager.PlayerTrain.CameraCar,
MessageDependency.None, GameMode.Expert,
MessageColor.White, Program.CurrentRoute.SecondsSinceMidnight + 5.0, null);
TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.CameraCar].Uncouple(true, false);
break;
case Translations.Command.UncoupleRear:
if (Program.Renderer.Camera.CurrentMode != CameraViewMode.Exterior)
{
MessageManager.AddMessage(
Translations.GetInterfaceString("notification_switchexterior_uncouple"),
MessageDependency.None, GameMode.Expert,
MessageColor.White, Program.CurrentRoute.SecondsSinceMidnight + 5.0, null);
return;
}
MessageManager.AddMessage(
Translations.GetInterfaceString("notification_exterior_uncouplerear") + " " + TrainManager.PlayerTrain.CameraCar,
MessageDependency.None, GameMode.Expert,
MessageColor.White, Program.CurrentRoute.SecondsSinceMidnight + 5.0, null);
TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.CameraCar].Uncouple(false, true);
break;
case Translations.Command.TimetableToggle:
// option: timetable
Expand Down
2 changes: 2 additions & 0 deletions source/OpenBveApi/Interface/Input/Commands.CommandInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public static CommandInfo TryGetInfo(this CommandInfo[] commandInfos, Command Va
new CommandInfo(Command.DeviceConstSpeed, CommandType.Digital, "DEVICE_CONSTSPEED"),
new CommandInfo(Command.PlayMicSounds, CommandType.Digital, "PLAY_MIC_SOUNDS"),
new CommandInfo(Command.Sanders, CommandType.Digital, "SANDERS"),
new CommandInfo(Command.UncoupleFront, CommandType.Digital, "UNCOUPLE_FRONT"),
new CommandInfo(Command.UncoupleRear, CommandType.Digital, "UNCOUPLE_REAR"),

//We only want to mark these as obsolete for new users of the API
#pragma warning disable 618
Expand Down
6 changes: 5 additions & 1 deletion source/OpenBveApi/Interface/Input/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ public enum Command
* Added in 1.8.4.3
*/
/// <summary>Toggles the sanders if fitted</summary>
Sanders
Sanders,
/// <summary>Uncouples the front coupling of a car</summary>
UncoupleFront,
/// <summary>Uncouples the rear coupling of a car</summary>
UncoupleRear
}

/// <summary>Defines the possible command types</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void Update(AbstractTrain NearestTrain, double TimeElapsed, bool
{
double timeDelta = Object.SecondsSinceLastUpdate + TimeElapsed;
Object.SecondsSinceLastUpdate = 0.0;
Object.Update(NearestTrain, NearestTrain == null ? 0 : NearestTrain.DriverCar, TrackPosition, Position, Direction, Up, Side, true, true, timeDelta, true);
Object.Update(NearestTrain, NearestTrain?.DriverCar ?? 0, TrackPosition, Position, Direction, Up, Side, true, true, timeDelta, true);
if (this.Object.CurrentState != this.lastState && currentHost.SimulationState != SimulationState.Loading)
{
if (SingleBuffer)
Expand Down
9 changes: 9 additions & 0 deletions source/OpenBveApi/System/Hosts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,15 @@ public virtual AbstractTrain ClosestTrain(double TrackPosition)
return null;
}

/// <summary>Adds a new train</summary>
/// <param name="ReferenceTrain">The reference train, or a null reference to add the train at the end of the queue</param>
/// <param name="NewTrain">The new train</param>
/// <param name="Preceedes">Whether this train preceeds or follows the reference train</param>
public virtual void AddTrain(AbstractTrain ReferenceTrain, AbstractTrain NewTrain, bool Preceedes)
{

}

/*
* Used for interop with the 32-bit plugin host
*/
Expand Down
11 changes: 11 additions & 0 deletions source/OpenBveApi/Train/AbstractCar.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using OpenBveApi.Math;

namespace OpenBveApi.Trains
Expand Down Expand Up @@ -72,6 +73,10 @@ public virtual int Index
// A single car is by itself a train, hence index zero
return 0;
}
set
{
throw new NotSupportedException("Cannot set the index of a single car");
}
}

/// <summary>Call this method to reverse (flip) the car</summary>
Expand All @@ -85,5 +90,11 @@ public virtual void OpenDoors(bool Left, bool Right)
{

}

/// <summary>Uncouples the car</summary>
public virtual void Uncouple(bool Front, bool Rear)
{

}
}
}
25 changes: 25 additions & 0 deletions source/Plugins/Train.OpenBve/Sound/SoundCfg.Xml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ internal void Parse(string fileName, ref TrainBase Train, ref CarBase car, bool
Vector3 right = new Vector3(1.3, 0.0, 0.0);
//Positioned at the front of the car, centered X and Y
Vector3 front = new Vector3(0.0, 0.0, 0.5 * car.Length);
//Positioned at the rear of the car centered X and Y
Vector3 rear = new Vector3(0.0, 0.0, -0.5 * car.Length);
//Positioned at the position of the panel / 3D cab (Remember that the panel is just an object in the world...)
Vector3 panel = new Vector3(car.Driver.X, car.Driver.Y, car.Driver.Z + 1.0);

Expand Down Expand Up @@ -581,6 +583,29 @@ internal void Parse(string fileName, ref TrainBase Train, ref CarBase car, bool
}
}
break;
case "coupler":
if (!c.ChildNodes.OfType<XmlElement>().Any())
{
Plugin.currentHost.AddMessage(MessageType.Error, false, "An empty list of brake handle sounds was defined in in XML file " + fileName);
break;
}
if (!isDriverCar)
{
break;
}
foreach (XmlNode cc in c.ChildNodes)
{
switch (cc.Name.ToLowerInvariant())
{
case "uncouple":
ParseNode(cc, out car.Coupler.UncoupleSound, rear, SoundCfgParser.smallRadius);
break;
default:
Plugin.currentHost.AddMessage(MessageType.Error, false, "Declaration " + cc.Name + " is unsupported in a " + c.Name + " node.");
break;
}
}
break;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions source/Plugins/Train.OpenBve/Train/BVE/TrainDatParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ internal void Parse(string FileName, Encoding Encoding, TrainBase Train) {
double DoorTolerance = 0.0;
ReadhesionDeviceType ReAdhesionDevice = ReadhesionDeviceType.TypeA;
PassAlarmType passAlarm = PassAlarmType.None;
Train.Handles.EmergencyBrake = new EmergencyHandle(Train);
Train.Handles.HasLocoBrake = false;
double[] powerDelayUp = { }, powerDelayDown = { }, brakeDelayUp = { }, brakeDelayDown = { }, locoBrakeDelayUp = { }, locoBrakeDelayDown = { };
double electricBrakeDelayUp = 0, electricBrakeDelayDown = 0;
Expand Down Expand Up @@ -1027,7 +1026,6 @@ internal void Parse(string FileName, Encoding Encoding, TrainBase Train) {
}
driverBrakeNotches = brakeNotches;
}
Train.Handles.Reverser = new ReverserHandle(Train);
Train.Handles.Power = new PowerHandle(powerNotches, driverPowerNotches, powerDelayUp, powerDelayDown, Train);
if (powerReduceSteps != -1)
{
Expand Down
2 changes: 0 additions & 2 deletions source/RouteViewer/TrainManagerR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public TrainManager(HostInterface host, BaseRenderer renderer, BaseOptions optio
internal class Train : TrainBase {
internal Train() : base(TrainState.Pending)
{
Handles.Reverser = new ReverserHandle(this);
Handles.EmergencyBrake = new EmergencyHandle(this);
Handles.Power = new PowerHandle(8, 8, new double[] {}, new double[] {}, this);
Handles.Brake = new BrakeHandle(8, 8, null, new double[] {}, new double[] {}, this);
Handles.HoldBrake = new HoldBrakeHandle(this);
Expand Down
2 changes: 0 additions & 2 deletions source/TrainEditor2/Simulation/TrainManager/Car/Car.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using OpenBveApi.Math;
using OpenBveApi.Trains;
using SoundManager;
using TrainEditor2.Models.Sounds;
using TrainManager.Car;
Expand All @@ -20,7 +19,6 @@ internal class Car : CarBase
public Car() : base(null, 0)
{
Sounds = new CarSounds();
Specs = new CarPhysics();
Specs.IsMotorCar = true;
}

Expand Down
16 changes: 5 additions & 11 deletions source/TrainManager/Car/Bogie/Bogie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,14 @@ public class Bogie

/// <summary>Whether the bogie is the rear bogie</summary>
private readonly bool Rear;

/// <summary>Holds a reference to the base train</summary>
// We don't want this to be read-only if we ever manage to uncouple cars...
// ReSharper disable once FieldCanBeMadeReadOnly.Local
private AbstractTrain baseTrain;

public Bogie(AbstractTrain train, CarBase car, bool IsRear)

public Bogie(CarBase car, bool IsRear)
{
baseTrain = train;
baseCar = car;
Rear = IsRear;
CarSections = new CarSection[] { };
FrontAxle = new Axle(TrainManagerBase.currentHost, train, car);
RearAxle = new Axle(TrainManagerBase.currentHost, train, car);
FrontAxle = new Axle(TrainManagerBase.currentHost, car.baseTrain, car);
RearAxle = new Axle(TrainManagerBase.currentHost, car.baseTrain, car);
}

public void UpdateObjects(double TimeElapsed, bool ForceUpdate)
Expand Down Expand Up @@ -200,7 +194,7 @@ private void UpdateSectionElement(int SectionIndex, int ElementIndex, Vector3 Po
updatefunctions = true;
}

CarSections[SectionIndex].Groups[0].Elements[ElementIndex].Update(baseTrain, baseCar.Index, FrontAxle.Follower.TrackPosition - FrontAxle.Position, p, Direction, Up, Side, updatefunctions, Show, timeDelta, true);
CarSections[SectionIndex].Groups[0].Elements[ElementIndex].Update(baseCar.baseTrain, baseCar.Index, FrontAxle.Follower.TrackPosition - FrontAxle.Position, p, Direction, Up, Side, updatefunctions, Show, timeDelta, true);
}
}

Expand Down
Loading