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
18 changes: 9 additions & 9 deletions source/ObjectViewer/FunctionScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
if (Train != null) {
Function.Stack[s] = 0.0;
for (int j = 0; j < Train.Cars.Length; j++) {
if (Train.Cars[j].Specs.IsMotorCar) {
if (Train.Cars[j].TractionModel.ProvidesPower) {
// hack: MotorAcceleration does not distinguish between forward/backward
if (Train.Cars[j].Specs.MotorAcceleration < 0.0) {
Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * (double)Math.Sign(Train.Cars[j].CurrentSpeed);
} else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) {
Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual;
if (Train.Cars[j].TractionModel.CurrentAcceleration < 0.0) {
Function.Stack[s] = Train.Cars[j].TractionModel.CurrentAcceleration * (double)Math.Sign(Train.Cars[j].CurrentSpeed);
} else if (Train.Cars[j].TractionModel.CurrentAcceleration > 0.0) {
Function.Stack[s] = Train.Cars[j].TractionModel.CurrentAcceleration * (double)Train.Handles.Reverser.Actual;
} else {
Function.Stack[s] = 0.0;
}
Expand All @@ -395,10 +395,10 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
if (j < 0) j += Train.Cars.Length;
if (j >= 0 & j < Train.Cars.Length) {
// hack: MotorAcceleration does not distinguish between forward/backward
if (Train.Cars[j].Specs.MotorAcceleration < 0.0) {
Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * (double)Math.Sign(Train.Cars[j].CurrentSpeed);
} else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) {
Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual;
if (Train.Cars[j].TractionModel.CurrentAcceleration < 0.0) {
Function.Stack[s - 1] = Train.Cars[j].TractionModel.CurrentAcceleration * (double)Math.Sign(Train.Cars[j].CurrentSpeed);
} else if (Train.Cars[j].TractionModel.CurrentAcceleration > 0.0) {
Function.Stack[s - 1] = Train.Cars[j].TractionModel.CurrentAcceleration * (double)Train.Handles.Reverser.Actual;
} else {
Function.Stack[s - 1] = 0.0;
}
Expand Down
3 changes: 2 additions & 1 deletion source/ObjectViewer/Trains/NearestTrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using TrainManager.BrakeSystems;
using TrainManager.Car;
using TrainManager.Handles;
using TrainManager.Motor;
using TrainManager.Trains;

namespace ObjectViewer.Trains
Expand Down Expand Up @@ -72,7 +73,7 @@ private static TrainBase CreateDummyTrain()
train.Cars[i].CarBrake = new ElectromagneticStraightAirBrake(EletropneumaticBrakeType.None, train.Cars[i]);
}

train.Cars[i].Specs.IsMotorCar = true;
train.Cars[i].TractionModel = new BVEMotorCar(train.Cars[i], null);
//At the minute, Object Viewer uses dummy brake systems
train.Cars[i].CarBrake.mainReservoir = new MainReservoir(Status.MainReservoirPressure * 1000.0);
train.Cars[i].CarBrake.equalizingReservoir = new EqualizingReservoir(Status.EqualizingReservoirPressure * 1000.0);
Expand Down
6 changes: 3 additions & 3 deletions source/OpenBVE/Game/AI/AI.SimpleHuman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ internal SimpleHumanDriverAI(TrainBase train, double Limit)
}
this.SpeedLimit = Limit;
MotorCar = train.DriverCar;
if (!train.Cars[train.DriverCar].Specs.IsMotorCar)
if (!train.Cars[train.DriverCar].TractionModel.ProvidesPower)
{
for (int i = 0; i < train.Cars.Length; i++)
{
if (train.Cars[i].Specs.IsMotorCar)
if (train.Cars[i].TractionModel.ProvidesPower)
{
MotorCar = i;
break;
Expand Down Expand Up @@ -415,7 +415,7 @@ private void PerformDefault()
BrakeDeceleration = Train.Cars[Train.DriverCar].CarBrake.DecelerationAtServiceMaximumPressure(Train.Handles.Brake.Actual, Train.Cars[Train.DriverCar].CurrentSpeed);
for (int i = 0; i < Train.Cars.Length; i++)
{
if (Train.Cars[i].Specs.IsMotorCar)
if (Train.Cars[i].TractionModel.ProvidesPower)
{
if (Train.Cars[Train.DriverCar].CarBrake.motorDeceleration != 0 && Train.Cars[Train.DriverCar].CarBrake.motorDeceleration < BrakeDeceleration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
if (Train != null) {
Function.Stack[s] = 0.0;
for (int j = 0; j < Train.Cars.Length; j++) {
if (Train.Cars[j].Specs.IsMotorCar) {
if (Train.Cars[j].TractionModel.ProvidesPower) {
// hack: MotorAcceleration does not distinguish between forward/backward
if (Train.Cars[j].Specs.MotorAcceleration < 0.0) {
Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * Math.Sign(Train.Cars[j].CurrentSpeed);
} else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) {
Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual;
if (Train.Cars[j].TractionModel.CurrentAcceleration < 0.0) {
Function.Stack[s] = Train.Cars[j].TractionModel.CurrentAcceleration * Math.Sign(Train.Cars[j].CurrentSpeed);
} else if (Train.Cars[j].TractionModel.CurrentAcceleration > 0.0) {
Function.Stack[s] = Train.Cars[j].TractionModel.CurrentAcceleration * (double)Train.Handles.Reverser.Actual;
} else {
Function.Stack[s] = 0.0;
}
Expand All @@ -394,10 +394,10 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
if (j < 0) j += Train.Cars.Length;
if (j >= 0 & j < Train.Cars.Length) {
// hack: MotorAcceleration does not distinguish between forward/backward
if (Train.Cars[j].Specs.MotorAcceleration < 0.0) {
Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * Math.Sign(Train.Cars[j].CurrentSpeed);
} else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) {
Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual;
if (Train.Cars[j].TractionModel.CurrentAcceleration < 0.0) {
Function.Stack[s - 1] = Train.Cars[j].TractionModel.CurrentAcceleration * Math.Sign(Train.Cars[j].CurrentSpeed);
} else if (Train.Cars[j].TractionModel.CurrentAcceleration > 0.0) {
Function.Stack[s - 1] = Train.Cars[j].TractionModel.CurrentAcceleration * (double)Train.Handles.Reverser.Actual;
} else {
Function.Stack[s - 1] = 0.0;
}
Expand Down Expand Up @@ -1696,9 +1696,9 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
bool isRunning = false;
for (int k = 0; k < Train.Cars.Length; k++)
{
if (Train.Cars[k].Specs.IsMotorCar && Train.Cars[k].Engine != null)
if (Train.Cars[k].TractionModel != null)
{
isRunning = Train.Cars[k].Engine.IsRunning;
isRunning = Train.Cars[k].TractionModel.IsRunning;
}

if (isRunning)
Expand All @@ -1720,7 +1720,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
if (j < 0) j += Train.Cars.Length;
if (j >= 0 & j < Train.Cars.Length)
{
if (Train.Cars[j].Specs.IsMotorCar && Train.Cars[j].Engine != null && Train.Cars[j].Engine.IsRunning)
if (Train.Cars[j].TractionModel != null && Train.Cars[j].TractionModel.IsRunning)
{
Function.Stack[s - 1] = 1.0;
}
Expand All @@ -1747,7 +1747,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
double rpmTotal = 0;
for (int k = 0; k < Train.Cars.Length; k++)
{
if (Train.Cars[k].Specs.IsMotorCar && Train.Cars[k].Engine is DieselEngine dieselEngine)
if (Train.Cars[k].TractionModel is DieselEngine dieselEngine)
{
numEngines++;
rpmTotal += dieselEngine.CurrentRPM;
Expand Down Expand Up @@ -1775,7 +1775,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
if (j < 0) j += Train.Cars.Length;
if (j >= 0 & j < Train.Cars.Length)
{
if (Train.Cars[j].Specs.IsMotorCar && Train.Cars[j].Engine is DieselEngine dieselEngine)
if (Train.Cars[j].TractionModel is DieselEngine dieselEngine)
{
Function.Stack[s - 1] = dieselEngine.CurrentRPM;
}
Expand All @@ -1802,7 +1802,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
double fuelTotal = 0;
for (int k = 0; k < Train.Cars.Length; k++)
{
if (Train.Cars[k].Specs.IsMotorCar && Train.Cars[k].Engine is DieselEngine dieselEngine)
if (Train.Cars[k].TractionModel is DieselEngine dieselEngine)
{
totalTanks++;
fuelTotal += dieselEngine.FuelTank.CurrentLevel;
Expand Down Expand Up @@ -1830,7 +1830,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
if (j < 0) j += Train.Cars.Length;
if (j >= 0 & j < Train.Cars.Length)
{
if (Train.Cars[j].Specs.IsMotorCar && Train.Cars[j].Engine is DieselEngine dieselEngine)
if (Train.Cars[j].TractionModel is DieselEngine dieselEngine)
{
Function.Stack[s - 1] = dieselEngine.FuelTank.CurrentLevel;
}
Expand All @@ -1857,7 +1857,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
double ampsTotal = 0;
for (int k = 0; k < Train.Cars.Length; k++)
{
if (Train.Cars[k].Specs.IsMotorCar && Train.Cars[k].Engine is DieselEngine dieselEngine)
if (Train.Cars[k].TractionModel is DieselEngine dieselEngine)
{
if (dieselEngine.Components[EngineComponent.TractionMotor] is TractionMotor t)
{
Expand Down Expand Up @@ -1888,7 +1888,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
if (j < 0) j += Train.Cars.Length;
if (j >= 0 & j < Train.Cars.Length)
{
if (Train.Cars[j].Specs.IsMotorCar && Train.Cars[j].Engine is DieselEngine dieselEngine)
if (Train.Cars[j].TractionModel is DieselEngine dieselEngine)
{
if (dieselEngine.Components[EngineComponent.TractionMotor] is TractionMotor t)
{
Expand Down
6 changes: 3 additions & 3 deletions source/OpenBVE/Graphics/Renderers/Overlays.Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private void RenderDebugOverlays()
int car = 0;
for (int i = 0; i < TrainManager.PlayerTrain.Cars.Length; i++)
{
if (TrainManager.PlayerTrain.Cars[i].Specs.IsMotorCar)
if (TrainManager.PlayerTrain.Cars[i].TractionModel.ProvidesPower)
{
car = i;
break;
Expand All @@ -161,7 +161,7 @@ private void RenderDebugOverlays()
string RPM = "Engine RPM: ";
for (int i = 0; i < TrainManager.PlayerTrain.Cars.Length; i++)
{
if (TrainManager.PlayerTrain.Cars[i].Engine is DieselEngine dieselEngine)
if (TrainManager.PlayerTrain.Cars[i].TractionModel is DieselEngine dieselEngine)
{
RPM += "Car " + i + " " + (int)dieselEngine.CurrentRPM + "rpm ";
hasRPM = true;
Expand All @@ -176,7 +176,7 @@ private void RenderDebugOverlays()
"",
"=train",
"speed: " + (Math.Abs(TrainManager.PlayerTrain.CurrentSpeed) * 3.6).ToString("0.00", Culture) + " km/h",
"power (car " + car.ToString(Culture) + "): " + (TrainManager.PlayerTrain.Cars[car].Specs.MotorAcceleration < 0.0 ? TrainManager.PlayerTrain.Cars[car].Specs.MotorAcceleration * Math.Sign(TrainManager.PlayerTrain.Cars[car].CurrentSpeed) : TrainManager.PlayerTrain.Cars[car].Specs.MotorAcceleration * (double)TrainManager.PlayerTrain.Handles.Reverser.Actual).ToString("0.0000", Culture) + " m/s²",
"power (car " + car.ToString(Culture) + "): " + (TrainManager.PlayerTrain.Cars[car].TractionModel.CurrentAcceleration < 0.0 ? TrainManager.PlayerTrain.Cars[car].TractionModel.CurrentAcceleration * Math.Sign(TrainManager.PlayerTrain.Cars[car].CurrentSpeed) : TrainManager.PlayerTrain.Cars[car].TractionModel.CurrentAcceleration * (double)TrainManager.PlayerTrain.Handles.Reverser.Actual).ToString("0.0000", Culture) + " m/s²",
"acceleration: " + TrainManager.PlayerTrain.Specs.CurrentAverageAcceleration.ToString("0.0000", Culture) + " m/s²",
"position: " + TrainManager.PlayerTrain.FrontCarTrackPosition.ToString("0.00", Culture) + " m",
"rain intensity: " + rainIntensity,
Expand Down
20 changes: 10 additions & 10 deletions source/OpenBVE/System/Scripting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ public static double accelerationMotor(TrainBase Train)
if (Train == null) return 0.0;
for (int j = 0; j < Train.Cars.Length; j++)
{
if (Train.Cars[j].Specs.IsMotorCar)
if (Train.Cars[j].TractionModel.ProvidesPower)
{
// hack: MotorAcceleration does not distinguish between forward/backward
if (Train.Cars[j].Specs.MotorAcceleration < 0.0)
if (Train.Cars[j].TractionModel.CurrentAcceleration < 0.0)
{
return Train.Cars[j].Specs.MotorAcceleration * Math.Sign(Train.Cars[j].CurrentSpeed);
return Train.Cars[j].TractionModel.CurrentAcceleration * Math.Sign(Train.Cars[j].CurrentSpeed);
}
if (Train.Cars[j].Specs.MotorAcceleration > 0.0)
if (Train.Cars[j].TractionModel.CurrentAcceleration > 0.0)
{
return Train.Cars[j].Specs.MotorAcceleration*
return Train.Cars[j].TractionModel.CurrentAcceleration*
(double) Train.Handles.Reverser.Actual;
}
}
Expand All @@ -146,16 +146,16 @@ public static double accelerationMotor(TrainBase Train)
public static double accelerationMotor(TrainBase Train, int CarIndex)
{
if (Train == null || Train.Cars.Length <= CarIndex) return 0.0;
if (Train.Cars[CarIndex].Specs.IsMotorCar)
if (Train.Cars[CarIndex].TractionModel.ProvidesPower)
{
// hack: MotorAcceleration does not distinguish between forward/backward
if (Train.Cars[CarIndex].Specs.MotorAcceleration < 0.0)
if (Train.Cars[CarIndex].TractionModel.CurrentAcceleration < 0.0)
{
return Train.Cars[CarIndex].Specs.MotorAcceleration * Math.Sign(Train.Cars[CarIndex].CurrentSpeed);
return Train.Cars[CarIndex].TractionModel.CurrentAcceleration * Math.Sign(Train.Cars[CarIndex].CurrentSpeed);
}
if (Train.Cars[CarIndex].Specs.MotorAcceleration > 0.0)
if (Train.Cars[CarIndex].TractionModel.CurrentAcceleration > 0.0)
{
return Train.Cars[CarIndex].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual;
return Train.Cars[CarIndex].TractionModel.CurrentAcceleration * (double)Train.Handles.Reverser.Actual;
}
}
return 0.0;
Expand Down
4 changes: 2 additions & 2 deletions source/Plugins/Route.Bve5/Components/ScriptedTrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ private static void LoadScriptedTrain(string FileName, bool PreviewOnly, MapData

for (int i = 0; i < Train.Cars.Length; i++)
{
Train.Cars[i].Specs.IsMotorCar = true;
Train.Cars[i].TractionModel = new BVEMotorCar(Train.Cars[i], null);
BVE5AITrainSounds carSounds = new BVE5AITrainSounds(Train.Cars[i], new BVE5AISoundEntry[OtherTrain.CarSounds.Count]);
for (int j = 0; j < carSounds.SoundEntries.Length; j++)
{
RouteData.Sound3Ds.TryGetValue(OtherTrain.CarSounds[j].Key, out SoundHandle soundHandle);
carSounds.SoundEntries[j] = new BVE5AISoundEntry(soundHandle as SoundBuffer, OtherTrain.CarSounds[j].Function);
}

Train.Cars[i].Sounds.Motor = carSounds;
Train.Cars[i].TractionModel.MotorSounds = carSounds;
}

List<TravelData> Data = new List<TravelData>();
Expand Down
10 changes: 5 additions & 5 deletions source/Plugins/Train.OpenBve/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ public override bool LoadTrain(Encoding encoding, string trainPath, ref Abstract
for (int i = 0; i < currentTrain.Cars.Length; i++)
{
currentTrain.Cars[i].DetermineDoorClosingSpeed();
if (currentTrain.Cars[i].Specs.IsMotorCar)
if (currentTrain.Cars[i].TractionModel.ProvidesPower)
{
numMotorCars++;
if (currentTrain.Cars[i].Sounds.Motor == null && TrainXmlParser.MotorSoundXMLParsed != null)
if (currentTrain.Cars[i].TractionModel.MotorSounds == null && TrainXmlParser.MotorSoundXMLParsed != null)
{
if(!TrainXmlParser.MotorSoundXMLParsed[i])
{
currentTrain.Cars[i].Sounds.Motor = new BVEMotorSound(currentTrain.Cars[i], 18.0, MotorSoundTables);
currentTrain.Cars[i].TractionModel.MotorSounds = new BVEMotorSound(currentTrain.Cars[i], 18.0, MotorSoundTables);
}
}

Expand All @@ -401,8 +401,8 @@ public override bool LoadTrain(Encoding encoding, string trainPath, ref Abstract
* Speed / physics are likely to be off, but let's at least do something
*/
CurrentHost.AddMessage(MessageType.Error, false, "Player train appears to have no motor cars, assigning Car 0 as a motor car.");
currentTrain.Cars[0].Specs.IsMotorCar = true;
currentTrain.Cars[0].Sounds.Motor = new BVEMotorSound(currentTrain.Cars[0], 18.0, MotorSoundTables);
currentTrain.Cars[0].TractionModel = new BVEMotorCar(currentTrain.Cars[0], null);
currentTrain.Cars[0].TractionModel.MotorSounds = new BVEMotorSound(currentTrain.Cars[0], 18.0, MotorSoundTables);
}
}
CurrentProgress = 1;
Expand Down
33 changes: 15 additions & 18 deletions source/Plugins/Train.OpenBve/Sound/SoundCfg.Bve2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,28 @@ internal void Parse(TrainBase train)
train.Cars[i].Suspension.SpringL = new CarSound(Plugin.CurrentHost, train.TrainFolder, "SpringL.wav", SoundCfgParser.smallRadius, left);
train.Cars[i].Suspension.SpringR = new CarSound(Plugin.CurrentHost, train.TrainFolder, "SpringR.wav", SoundCfgParser.smallRadius, right);
// motor sound
if (train.Cars[i].Specs.IsMotorCar)
if (train.Cars[i].TractionModel.MotorSounds == null)
{
if (train.Cars[i].Sounds.Motor == null)
BVEMotorSound motorSound = new BVEMotorSound(train.Cars[i], 18.0, Plugin.MotorSoundTables);
motorSound.Position = center;
for (int j = 0; j < motorSound.Tables.Length; j++)
{
BVEMotorSound motorSound = new BVEMotorSound(train.Cars[i], 18.0, Plugin.MotorSoundTables);
motorSound.Position = center;
for (int j = 0; j < motorSound.Tables.Length; j++)
for (int k = 0; k < motorSound.Tables[j].Entries.Length; k++)
{
for (int k = 0; k < motorSound.Tables[j].Entries.Length; k++)
int idx = motorSound.Tables[j].Entries[k].SoundIndex;
if (idx >= 0)
{
int idx = motorSound.Tables[j].Entries[k].SoundIndex;
if (idx >= 0)
{
CarSound snd = new CarSound(Plugin.CurrentHost, train.TrainFolder, "Motor" + idx.ToString(CultureInfo.InvariantCulture) + ".wav", SoundCfgParser.mediumRadius, center);
motorSound.Tables[j].Entries[k].Buffer = snd.Buffer;
}
CarSound snd = new CarSound(Plugin.CurrentHost, train.TrainFolder, "Motor" + idx.ToString(CultureInfo.InvariantCulture) + ".wav", SoundCfgParser.mediumRadius, center);
motorSound.Tables[j].Entries[k].Buffer = snd.Buffer;
}
}

train.Cars[i].Sounds.Motor = motorSound;
}
else
{
Plugin.CurrentHost.AddMessage(MessageType.Error, false, "Unexpected motor sound model found in car " + i);
}

train.Cars[i].TractionModel.MotorSounds = motorSound;
}
else
{
Plugin.CurrentHost.AddMessage(MessageType.Error, false, "Unexpected motor sound model found in car " + i);
}
}
}
Expand Down
Loading