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
8 changes: 4 additions & 4 deletions source/OpenBVE/Game/AI/AI.SimpleHuman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class SimpleHumanDriverAI : GeneralAI
/// <summary>The index to the first motor car, if the driver car is not a motor car</summary>
private readonly int MotorCar;
// functions
internal SimpleHumanDriverAI(TrainBase train, double Limit)
internal SimpleHumanDriverAI(TrainBase train, double speedLimit)
{
Train = train;
TimeLastProcessed = 0.0;
Expand All @@ -57,7 +57,7 @@ internal SimpleHumanDriverAI(TrainBase train, double Limit)
{
LastStation = -1;
}
SpeedLimit = Limit;
SpeedLimit = speedLimit;
MotorCar = train.DriverCar;
if (!train.Cars[train.DriverCar].TractionModel.ProvidesPower)
{
Expand Down Expand Up @@ -921,7 +921,7 @@ private void LookAheadForwards()

if (dist > 25)
{
var edec = Train.CurrentSpeed * Train.CurrentSpeed / (2.0 * dist);
double edec = Train.CurrentSpeed * Train.CurrentSpeed / (2.0 * dist);
if (edec > dec) dec = edec;
}

Expand Down Expand Up @@ -952,7 +952,7 @@ private void LookAheadForwards()
dist -= 5.0;
}

var edec = Train.CurrentSpeed * Train.CurrentSpeed / (2.0 * dist);
double edec = Train.CurrentSpeed * Train.CurrentSpeed / (2.0 * dist);
if (edec > dec) dec = edec;
}
}
Expand Down
14 changes: 11 additions & 3 deletions source/OpenBVE/UserInterface/formMain.Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,11 @@ private void PopulateTrainList(string selectedFolder, ListView listView, bool pa
{
File = Path.CombineFile(Folders[i], "train.xml");
}
Item.ImageKey = System.IO.File.Exists(File) ? "train" : "folder";
if (!System.IO.File.Exists(File))
{
File = Path.CombineFile(Folders[i], "vehicle.txt");
}
Item.ImageKey = System.IO.File.Exists(File) ? "train" : "folder";
Item.Tag = Folders[i];
}
}
Expand Down Expand Up @@ -818,8 +822,12 @@ private void listviewTrainFolders_SelectedIndexChanged(object sender, EventArgs
{
File = Path.CombineFile(t, "train.xml");
}

if (System.IO.File.Exists(File))
if (!System.IO.File.Exists(File))
{
File = Path.CombineFile(t, "vehicle.txt");
}

if (System.IO.File.Exists(File))
{
Result.TrainFolder = t;
ShowTrain(false);
Expand Down
15 changes: 14 additions & 1 deletion source/OpenBveApi/Math/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static double SqrtC(double X)
return System.Math.Sqrt(X);
}

/// <summary>Returns the tamgent of the specified angle</summary>
/// <summary>Returns the tangent of the specified angle</summary>
/// <remarks>This function will return 0 if the result would be ComplexInfinity</remarks>
public static double TanC(double X)
{
Expand All @@ -38,5 +38,18 @@ public static double TanC(double X)
}
return System.Math.Tan(X);
}

/// <summary>Linearly interpolates a value in a range, using keys</summary>
/// <param name="x0">The first number</param>
/// <param name="y0">The first key</param>
/// <param name="x1">The second number</param>
/// <param name="y1">The second key</param>
/// <param name="x">The interpolation value between keys</param>
/// <returns>The interpolated number</returns>
public static double LinearInterpolation(double x0, double y0, double x1, double y1, double x)
{
// ReSharper disable once CompareOfFloatsByEqualityOperator
return x0 == x1 ? y0 : y0 + (y1 - y0) * (x - x0) / (x1 - x0);
}
}
}
12 changes: 6 additions & 6 deletions source/Plugins/Formats.OpenBve/CFG/ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public class ConfigFile<T1, T2> : Block<T1, T2> where T1 : struct, Enum where T2
{
/// <summary>The version of the file (if set)</summary>
public readonly double Version;
public ConfigFile(string fileName, HostInterface currentHost, string expectedHeader = null, double minVersion = 0, double maxVersion = 0, bool defaultFirstBlock = false)
: this(File.ReadAllLines(fileName, TextEncoding.GetSystemEncodingFromFile(fileName)), currentHost, expectedHeader, minVersion, maxVersion, defaultFirstBlock)
public ConfigFile(string fileName, HostInterface currentHost, string expectedHeader = null, double minVersion = 0, double maxVersion = 0, char commentSeparator = ';', bool defaultFirstBlock = false)
: this(File.ReadAllLines(fileName, TextEncoding.GetSystemEncodingFromFile(fileName)), currentHost, expectedHeader, minVersion, maxVersion, commentSeparator, defaultFirstBlock)
{
}

public ConfigFile(string[] lines, HostInterface currentHost, string expectedHeader = null, double minVersion = 0, double maxVersion = 0, bool defaultFirstBlock = false) : base(-1, default, currentHost)
public ConfigFile(string[] lines, HostInterface currentHost, string expectedHeader = null, double minVersion = 0, double maxVersion = 0, char commentSeparator = ';', bool defaultFirstBlock = false) : base(-1, default, currentHost)
{
List<string> blockLines = new List<string>();
bool addToBlock = defaultFirstBlock;
Expand All @@ -66,14 +66,14 @@ public ConfigFile(string[] lines, HostInterface currentHost, string expectedHead

for (int i = 0; i < lines.Length; i++)
{
int j = lines[i].IndexOf(';');
int j = lines[i].IndexOf(commentSeparator);
if (j >= 0)
{
lines[i] = lines[i].Substring(0, j).Trim();
lines[i] = lines[i].Substring(0, j).Trim().Trim(',');
}
else
{
lines[i] = lines[i].Trim();
lines[i] = lines[i].Trim().Trim(',');
}
if (headerOK == false)
{
Expand Down
8 changes: 8 additions & 0 deletions source/Plugins/Formats.OpenBve/Enums/BVE5/MotorNoiseTxtKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Formats.OpenBve
{
public enum MotorNoiseTxtKey
{
Volume,
Frequency
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Formats.OpenBve
{
public enum MotorNoiseTxtSection
{
Power,
Brake
}
}
66 changes: 66 additions & 0 deletions source/Plugins/Formats.OpenBve/Enums/BVE5/ParametersTxtKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
namespace Formats.OpenBve
{
public enum ParametersTxtKey
{
FirstCar,
LoadCompensating,
BrakeNotchCount,
PowerNotchCount,
HoldingSpeedNotchCount,
AtsCancelNotch,
MotorBrakeNotch,
ReverserText,
PowerText,
BrakeText,
HoldingSpeedText,
Power,
Neutral,
Brake,
RegenerationLimit,
RegenerationStartLimit,
LeverDelay,
BrakePriority,
SlipVelocityCoefficient,
SlipVelocity,
SlipAcceleration,
BalanceAcceleration,
HoldingTime,
ReferenceAcceleration,
ReferenceDeceleration,
CurrentDecrease,
CurrentIncrease,
MaximumPressure,
PressureRates,
SapBcRatio,
SapBcOffset,
BpInitialPressure,
ApplySpeed,
ReleaseSpeed,
RapidReleaseSpeed,
VolumeRatio,
InitialPressure,
ApplyStart,
ApplyStop,
ReleaseStart,
ReleaseStop,
PistonArea,
UpperPressure,
LowerPressure,
CompressionSpeed,
MotorCarWeight,
TrailerWeight,
MotorCarCount,
TrailerCount,
MotorcarInertiaFactor,
TrailerInertiaFactor,
CarLength,
Capacity,
BodyWeight,
BoardingSpeed,
AlightingSpeed,
CloseTime,
X,
Y,
Z
}
}
25 changes: 25 additions & 0 deletions source/Plugins/Formats.OpenBve/Enums/BVE5/ParametersTxtSection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Formats.OpenBve
{
public enum ParametersTxtSection
{
Default,
Cab,
OneLeverCab,
ConstantSpeedControl,
MainCircuit,
PowerReAdhesion,
ECB,
SMEE,
CI,
SAP,
ER,
BP,
BC,
Brake,
Compressor,
Dynamics,
Passengers,
Door,
ViewPoint
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Formats.OpenBve
{
public enum PerformanceCurveTxtKey
{
Params,
Force,
MaxForce,
Current,
MaxCurrent,
NoLoadCurrent
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Formats.OpenBve
{
public enum PerformanceCurveTxtSection
{
Power,
Brake
}
}
16 changes: 16 additions & 0 deletions source/Plugins/Formats.OpenBve/Enums/BVE5/VehicleTxtKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Formats.OpenBve
{
public enum VehicleTxtKey
{
Title,
Author,
Image,
Comment,
PerformanceCurve,
Parameters,
Panel,
Sound,
ATS,
MotorNoise
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Formats.OpenBve
{
public enum VehicleTxtSection
{
Summary
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public enum SoundCfgSection
/// <summary>Motor sounds</summary>
Motor,
/// <summary>Switch sounds</summary>
Switch,
Switch = 4,
Joint = 4,
/// <summary>Brake sounds</summary>
Brake,
/// <summary>Compressor sounds</summary>
Compressor,
/// <summary>Air suspension sounds</summary>
Suspension = 7,
Spring = 7,
AirSpring = 7,
/// <summary>Horn sounds</summary>
Horn,
/// <summary>Door open / close sounds</summary>
Expand All @@ -36,7 +38,7 @@ public enum SoundCfgSection
/// <summary>Sounds played when the power handle is moved</summary>
MasterController = 14,
PowerHandle = 14,
/// <summary>Sounds played when the reverseer is moved</summary>
/// <summary>Sounds played when the reverser is moved</summary>
Reverser = 15,
ReverserHandle = 15,
/// <summary>Breaker sounds</summary>
Expand Down
8 changes: 8 additions & 0 deletions source/Plugins/Formats.OpenBve/Formats.OpenBve.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CFG\ConfigFile.cs" />
<Compile Include="Enums\BVE5\MotorNoiseTxtKey.cs" />
<Compile Include="Enums\BVE5\MotorNoiseTxtSection.cs" />
<Compile Include="Enums\BVE5\PerformanceCurveTxtKey.cs" />
<Compile Include="Enums\BVE5\PerformanceCurveTxtSection.cs" />
<Compile Include="Enums\BVE5\ParametersTxtKey.cs" />
<Compile Include="Enums\BVE5\ParametersTxtSection.cs" />
<Compile Include="Enums\ExtensionsCfg\ExtensionsCfgKey.cs" />
<Compile Include="Enums\ExtensionsCfg\ExtensionsCfgSection.cs" />
<Compile Include="Enums\HUD\HUDKey.cs" />
Expand All @@ -64,6 +70,8 @@
<Compile Include="Enums\TrainXML\Brake.cs" />
<Compile Include="Enums\TrainXML\Handle.cs" />
<Compile Include="Enums\TrainXML\Train.cs" />
<Compile Include="Enums\BVE5\VehicleTxtKey.cs" />
<Compile Include="Enums\BVE5\VehicleTxtSection.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Block.cs" />
<Compile Include="NumberRange.cs" />
Expand Down
4 changes: 2 additions & 2 deletions source/Plugins/Route.Bve5/MapParser/ConfirmComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private static void ConfirmGradient(IList<Block> Blocks)
for (int k = StartBlock; k < i; k++)
{
double CurrentDistance = Blocks[k].StartingDistance;
double CurrentPitch = LinearInterpolation(StartDistance, StartPitch, EndDistance, EndPitch, CurrentDistance);
double CurrentPitch = Extensions.LinearInterpolation(StartDistance, StartPitch, EndDistance, EndPitch, CurrentDistance);

Blocks[k].Pitch = CurrentPitch;
}
Expand Down Expand Up @@ -238,7 +238,7 @@ private static void ConfirmGradient(IList<Block> Blocks)
for (int k = StartBlock + 1; k < i; k++)
{
double CurrentDistance = Blocks[k].StartingDistance;
double CurrentPitch = LinearInterpolation(StartDistance, StartPitch, EndDistance, EndPitch, CurrentDistance);
double CurrentPitch = Extensions.LinearInterpolation(StartDistance, StartPitch, EndDistance, EndPitch, CurrentDistance);

Blocks[k].Pitch = CurrentPitch;
}
Expand Down
7 changes: 1 addition & 6 deletions source/Plugins/Route.Bve5/MapParser/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ private static double Multiple(double x, int y)
return x % y == 0 ? x : x + (y - x % y);
}

private static double LinearInterpolation(double x0, double y0, double x1, double y1, double x)
{
return x0 == x1 ? y0 : y0 + (y1 - y0) * (x - x0) / (x1 - x0);
}

private static void SineHalfWavelengthDiminishingTangentCurve(double Length, double TargetRadius, double TargetCant, double CurrentPosition, out double CurrentRadius, out double CurrentCant)
{
// Sine Half-Wavelength Diminishing Tangent Curve
Expand Down Expand Up @@ -191,7 +186,7 @@ private static double GetTrackCoordinate(double distance0, double xy0, double di
return center.Y + Math.Sqrt(squaring);
}

return LinearInterpolation(distance0, xy0, distance1, xy1, distance);
return Extensions.LinearInterpolation(distance0, xy0, distance1, xy1, distance);
}

private static double RZtoRoll(double RY, double RZ)
Expand Down
10 changes: 10 additions & 0 deletions source/Plugins/Train.OpenBve/Enums/TrainFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Train.OpenBve
{
internal enum TrainFormat
{
OpenBVE,
TrainAI,
XML,
BVE5
}
}
Loading