Skip to content

Commit 3b85185

Browse files
committed
Automatic merge of T1.5.1-1695-gade019506 and 18 pull requests
- Pull request #570 at f11a428: glTF 2.0 support with PBR lighting - Pull request #900 at 4629736: DMI in 3D cab + two more dials - Pull request #1030 at d3ae4a2: Refactor settings, in prep for settings exporter - Pull request #1045 at cc4d53c: Bugfix: Empty Start Time for Explore, and other issues loading from Menu Selection and Content Routes - Pull request #1052 at 3b5cb90: Content Manager: Add axle count, and lowest derail force - Pull request #1062 at b96d6fa: Train Forces popup Window. - Pull request #1064 at 52410f9: Add Train Info tab to Help window (F1) - Pull request #1066 at 62c89c1: Log derailment, using TraceInformation. - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #896 at 335f998: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #1000 at d8d9709: Locomotive operation from control car - Pull request #1049 at 6a0c471: Re-organise document storage and access - Pull request #1057 at 254b6d4: Switchable brake system - Pull request #1069 at 3f153f0: Mouse wheel control only with Alt – Followup for #1051 - Pull request #1070 at f818e40: Fix a NullReferenceException in TCS scripts - Pull request #1071 at 722dd3f: Change cover image for v1.6 - Pull request #1074 at e9a66c1: Gradient - commit 2024-16-12 - Pull request #1055 at 5c78967: Route Based TTrack Sounds
20 parents efde146 + ade0195 + f11a428 + 4629736 + d3ae4a2 + cc4d53c + 3b5cb90 + b96d6fa + 52410f9 + 62c89c1 + 1f5ba4c + 335f998 + d8d9709 + 6a0c471 + 254b6d4 + 3f153f0 + f818e40 + 722dd3f + e9a66c1 + 5c78967 commit 3b85185

File tree

3 files changed

+143
-2
lines changed

3 files changed

+143
-2
lines changed

Source/Orts.Simulation/Simulation/AIs/AITrain.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3658,7 +3658,7 @@ public void AdjustControlsThrottleOff()
36583658
}
36593659
}
36603660

3661-
public void AdjustControlsAccelMore(float reqAccelMpSS, float timeS, int stepSize)
3661+
public virtual void AdjustControlsAccelMore(float reqAccelMpSS, float timeS, int stepSize)
36623662
{
36633663
if (AITrainBrakePercent > 0)
36643664
{

Source/Orts.Simulation/Simulation/Timetables/ProcessTimetable.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,6 +2164,61 @@ public void ProcessSpeedInfo(string speedInfo, float actSpeedConv)
21642164
}
21652165
break;
21662166

2167+
case "gradient":
2168+
foreach (TTTrainCommands.TTTrainComQualifiers thisComValue in thisCommand.CommandQualifiers)
2169+
{
2170+
switch (thisComValue.QualifierName)
2171+
{
2172+
case "perc":
2173+
try
2174+
{
2175+
float gradPerc = Convert.ToSingle(thisComValue.QualifierValues[0]);
2176+
if (gradPerc <= 0 || gradPerc > 25)
2177+
{
2178+
Trace.TraceInformation("Train {0} : invalid value for gradient percent in speed setting : {1} \n",
2179+
TTTrain.Name, gradPerc);
2180+
}
2181+
else
2182+
{
2183+
TTTrain.SpeedSettings.gradPerc = gradPerc;
2184+
}
2185+
}
2186+
catch
2187+
{
2188+
Trace.TraceInformation("Train {0} : invalid value for gradient percent in speed setting : {1} \n",
2189+
TTTrain.Name, thisComValue.QualifierValues[0]);
2190+
}
2191+
break;
2192+
2193+
case "speed":
2194+
try
2195+
{
2196+
float gradSpeed = Convert.ToSingle(thisComValue.QualifierValues[0]);
2197+
TTTrain.SpeedSettings.gradMinSpeed = gradSpeed;
2198+
}
2199+
catch
2200+
{
2201+
Trace.TraceInformation("Train {0} : invalid value for gradient min speed in speed setting : {1} \n",
2202+
TTTrain.Name, thisComValue.QualifierValues[0]);
2203+
}
2204+
break;
2205+
2206+
default:
2207+
Trace.TraceInformation("Invalid qualifier in gradient speed command : {0} for train : {1}", thisComValue.QualifierName, TTTrain.Name);
2208+
break;
2209+
}
2210+
}
2211+
2212+
if (TTTrain.SpeedSettings.gradPerc.HasValue && TTTrain.SpeedSettings.gradMinSpeed.HasValue)
2213+
{
2214+
TTTrain.SpeedSettings.gradient = true;
2215+
}
2216+
else
2217+
{
2218+
Trace.TraceInformation("Train {0} : incomplete definition for gradient\n", TTTrain.Name);
2219+
}
2220+
break;
2221+
21672222
default:
21682223
Trace.TraceInformation("Invalid token in speed command : {0} for train : {1}", thisCommand.CommandToken, TTTrain.Name);
21692224
break;

Source/Orts.Simulation/Simulation/Timetables/TTTrain.cs

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ public struct SpeedValues
181181
public float routeSpeedMpS; // Route defined max speed
182182
public float consistSpeedMpS; // Consist defined max speed
183183
public bool restrictedSet; // Special speed has been set
184+
public bool gradient; // gradient definition has been set
185+
public float? gradPerc; // gradient percentage
186+
public float? gradMinSpeed; // gradient minimum speed
184187
}
185188

186189
public DelayedStartValues DelayedStartSettings = new DelayedStartValues();
@@ -259,6 +262,9 @@ public TTTrain(Simulator simulator)
259262
SpeedSettings.detachSpeedMpS = null;
260263
SpeedSettings.movingtableSpeedMpS = null;
261264
SpeedSettings.restrictedSet = false;
265+
SpeedSettings.gradient = false;
266+
SpeedSettings.gradPerc = null;
267+
SpeedSettings.gradMinSpeed = null;
262268
}
263269

264270
//================================================================================================//
@@ -528,9 +534,18 @@ public TTTrain(Simulator simulator, BinaryReader inf, AI airef)
528534
attachSpeedMpS = inf.ReadBoolean() ? inf.ReadSingle() : (float?)null,
529535
detachSpeedMpS = inf.ReadBoolean() ? inf.ReadSingle() : (float?)null,
530536
movingtableSpeedMpS = inf.ReadBoolean() ? inf.ReadSingle() : (float?)null,
531-
restrictedSet = inf.ReadBoolean()
537+
restrictedSet = inf.ReadBoolean(),
538+
gradient = inf.ReadBoolean(),
539+
gradPerc = null,
540+
gradMinSpeed = null
532541
};
533542

543+
if (SpeedSettings.gradient)
544+
{
545+
SpeedSettings.gradPerc = inf.ReadSingle();
546+
SpeedSettings.gradMinSpeed = inf.ReadSingle();
547+
}
548+
534549
DriverOnlyOperation = inf.ReadBoolean();
535550
ForceReversal = inf.ReadBoolean();
536551

@@ -841,6 +856,13 @@ public override void Save(BinaryWriter outf)
841856
outf.Write(SpeedSettings.movingtableSpeedMpS.Value);
842857
}
843858
outf.Write(SpeedSettings.restrictedSet);
859+
outf.Write(SpeedSettings.gradient);
860+
if (SpeedSettings.gradient)
861+
{
862+
outf.Write(SpeedSettings.gradPerc.Value);
863+
outf.Write(SpeedSettings.gradMinSpeed.Value);
864+
}
865+
844866
outf.Write(DriverOnlyOperation);
845867
outf.Write(ForceReversal);
846868
outf.Write(Briefing);
@@ -5806,6 +5828,70 @@ public override void StartMoving(AI_START_MOVEMENT reason)
58065828
#endif
58075829
}
58085830

5831+
//================================================================================================//
5832+
/// <summary>
5833+
/// Train control routine for full acceleration
5834+
/// Overrride for AITrain.cs
5835+
/// </summary>
5836+
5837+
public override void AdjustControlsAccelMore(float reqAccelMpSS, float timeS, int stepSize)
5838+
{
5839+
if (AITrainBrakePercent > 0)
5840+
{
5841+
AdjustControlsBrakeOff();
5842+
}
5843+
5844+
if (AITrainThrottlePercent < 100)
5845+
{
5846+
AITrainThrottlePercent += stepSize;
5847+
if (AITrainThrottlePercent > 100)
5848+
AITrainThrottlePercent = 100;
5849+
}
5850+
else if (LastSpeedMpS == 0 || (((SpeedMpS - LastSpeedMpS) / timeS) < 0.5f * MaxAccelMpSS))
5851+
{
5852+
bool forceaccreq = true;
5853+
5854+
// test for train on gradient
5855+
if (SpeedSettings.gradient)
5856+
{
5857+
bool ongrad = false;
5858+
foreach (TrainCar car in Cars)
5859+
{
5860+
if (car.CurrentElevationPercent > SpeedSettings.gradPerc)
5861+
{
5862+
ongrad = true;
5863+
continue;
5864+
}
5865+
}
5866+
if (ongrad && SpeedMpS > SpeedSettings.gradMinSpeed)
5867+
{
5868+
forceaccreq = false;
5869+
}
5870+
}
5871+
5872+
// forced acc is required
5873+
if (forceaccreq)
5874+
{
5875+
float ds = timeS * (reqAccelMpSS);
5876+
SpeedMpS = LastSpeedMpS + ds;
5877+
foreach (TrainCar car in Cars)
5878+
{
5879+
//TODO: next code line has been modified to flip trainset physics in order to get viewing direction coincident with loco direction when using rear cab.
5880+
// To achieve the same result with other means, without flipping trainset physics, the line should be changed as follows:
5881+
// car.SpeedMpS = car.Flipped ? -SpeedMpS : SpeedMpS;
5882+
car.SpeedMpS = car.Flipped ^ (car.IsDriveable && car.Train.IsActualPlayerTrain && ((MSTSLocomotive)car).UsingRearCab) ? -SpeedMpS : SpeedMpS;
5883+
}
5884+
5885+
if (CheckTrain)
5886+
{
5887+
File.AppendAllText(@"C:\temp\checktrain.txt", "Forced speed increase : was " + LastSpeedMpS + " - now " + SpeedMpS + "\n");
5888+
}
5889+
}
5890+
}
5891+
5892+
SetPercentsFromTrainToTrainset();
5893+
}
5894+
58095895
//================================================================================================//
58105896
/// <summary>
58115897
/// Calculate initial position

0 commit comments

Comments
 (0)