Skip to content

Commit

Permalink
Internal: Rename TrackFollowingObject to ScriptedTrain
Browse files Browse the repository at this point in the history
Better name for what it actually does these days
#1009
  • Loading branch information
leezer3 committed Apr 10, 2024
1 parent 194f288 commit 10f791d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions source/OpenBVE/Game/TrainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal void UpdateTrains(double TimeElapsed)
}

// ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
foreach (TrackFollowingObject Train in TFOs) //Must not use var, as otherwise the wrong inferred type
foreach (ScriptedTrain Train in TFOs) //Must not use var, as otherwise the wrong inferred type
{
Train.Update(TimeElapsed);
}
Expand Down Expand Up @@ -379,7 +379,7 @@ internal void UpdateTrains(double TimeElapsed)
{
if (TFOs[i].State != TrainState.Disposed & TFOs[i].State != TrainState.Bogus)
{
TrackFollowingObject t = (TrackFollowingObject) TFOs[i];
ScriptedTrain t = (ScriptedTrain) TFOs[i];
foreach (var Car in t.Cars)
{
Car.FrontAxle.Follower.UpdateWorldCoordinates(true);
Expand Down
17 changes: 8 additions & 9 deletions source/OpenBVE/Parsers/Script/TrackFollowingObjectParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using OpenBveApi.Trains;
using TrainManager.Trains;
using Path = OpenBveApi.Path;
using TrackFollowingObject = TrainManager.Trains.TrackFollowingObject;

namespace OpenBve
{
Expand All @@ -23,24 +22,24 @@ internal static class TrackFollowingObjectParser
/// <summary>Parses a track following object</summary>
/// <param name="ObjectPath">Absolute path to the object folder of route data</param>
/// <param name="FileName">The XML file to parse</param>
internal static TrackFollowingObject ParseTrackFollowingObject(string ObjectPath, string FileName)
internal static ScriptedTrain ParseTrackFollowingObject(string ObjectPath, string FileName)
{
// The current XML file to load
XDocument CurrentXML = XDocument.Load(FileName, LoadOptions.SetLineInfo);
List<XElement> TfoElements = CurrentXML.XPathSelectElements("/openBVE/TrackFollowingObject").ToList();
List<XElement> ScriptedTrainElements = CurrentXML.XPathSelectElements("/openBVE/TrackFollowingObject").ToList();

// Check this file actually contains OpenBVE other train definition elements
if (!TfoElements.Any())
if (!ScriptedTrainElements.Any())
{
// We couldn't find any valid XML, so return false
throw new InvalidDataException();
}

TrackFollowingObject Train = new TrackFollowingObject(TrainState.Pending);
ScriptedTrain Train = new ScriptedTrain(TrainState.Pending);

foreach (XElement Element in TfoElements)
foreach (XElement Element in ScriptedTrainElements)
{
ParseTrackFollowingObjectNode(ObjectPath, FileName, Element, Train);
ParseScriptedTrainNode(ObjectPath, FileName, Element, Train);
}

return Train;
Expand All @@ -51,7 +50,7 @@ internal static TrackFollowingObject ParseTrackFollowingObject(string ObjectPath
/// <param name="FileName">The filename of the containing XML file</param>
/// <param name="SectionElement">The XElement to parse</param>
/// <param name="Train">The track following object to parse this node into</param>
private static void ParseTrackFollowingObjectNode(string ObjectPath, string FileName, XElement SectionElement, TrackFollowingObject Train)
private static void ParseScriptedTrainNode(string ObjectPath, string FileName, XElement SectionElement, ScriptedTrain Train)
{
string Section = SectionElement.Name.LocalName;

Expand Down Expand Up @@ -155,7 +154,7 @@ private static void ParseTrackFollowingObjectNode(string ObjectPath, string File
/// <param name="FileName">The filename of the containing XML file</param>
/// <param name="SectionElement">The XElement to parse</param>
/// <param name="Train">The track following object to parse this node into</param>
private static void ParseDefinitionNode(string FileName, XElement SectionElement, TrackFollowingObject Train)
private static void ParseDefinitionNode(string FileName, XElement SectionElement, ScriptedTrain Train)
{
string Section = SectionElement.Name.LocalName;

Expand Down
2 changes: 1 addition & 1 deletion source/OpenBVE/System/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ private void SetupSimulation()
}

// ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
foreach (TrackFollowingObject Train in Program.TrainManager.TFOs) //Must not use var, as otherwise the wrong inferred type
foreach (ScriptedTrain Train in Program.TrainManager.TFOs) //Must not use var, as otherwise the wrong inferred type
{
Train.Initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace TrainManager.Trains
/// <summary>The AI class used to operate a TFO</summary>
public class TrackFollowingObjectAI : GeneralAI
{
private readonly TrackFollowingObject Train;
private readonly ScriptedTrain Train;

// Time to operate the door
private readonly double OpeningDoorsTime;
Expand All @@ -24,7 +24,7 @@ public class TrackFollowingObjectAI : GeneralAI
private double TimeLastProcessed;
private double CurrentPosition;

public TrackFollowingObjectAI(TrackFollowingObject train, TravelData[] data)
public TrackFollowingObjectAI(ScriptedTrain train, TravelData[] data)
{
Train = train;
Data = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace TrainManager.Trains
{
/// <summary>A more advanced type of AnimatedObject, which follows a rail and a travel plan</summary>
public class TrackFollowingObject : TrainBase
/// <summary>A scripted train, which follows a rail and a travel plan</summary>
public class ScriptedTrain : TrainBase
{
/// <summary>The time the train appears in-game</summary>
public double AppearanceTime;
Expand All @@ -17,7 +17,7 @@ public class TrackFollowingObject : TrainBase
public double LeaveTime;
private double InternalTimerTimeElapsed;

public TrackFollowingObject(TrainState state) : base(state)
public ScriptedTrain(TrainState state) : base(state)
{
}

Expand Down
6 changes: 3 additions & 3 deletions source/TrainManager/TrainManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using OpenBveApi.Trains;
using RouteManager2;
using TrainManager.Trains;
using TrackFollowingObject = TrainManager.Trains.TrackFollowingObject;
using ScriptedTrain = TrainManager.Trains.ScriptedTrain;

namespace TrainManager
{
Expand Down Expand Up @@ -77,7 +77,7 @@ public void UpdateTrainObjects(double TimeElapsed, bool ForceUpdate)
}

// ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
foreach (TrackFollowingObject Train in TFOs) //Must not use var, as otherwise the wrong inferred type
foreach (ScriptedTrain Train in TFOs) //Must not use var, as otherwise the wrong inferred type
{
Train.UpdateObjects(TimeElapsed, ForceUpdate);
}
Expand All @@ -87,7 +87,7 @@ public void UpdateTrainObjects(double TimeElapsed, bool ForceUpdate)
public void JumpTFO()
{
// ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
foreach (TrackFollowingObject Train in TFOs) //Must not use var, as otherwise the wrong inferred type
foreach (ScriptedTrain Train in TFOs) //Must not use var, as otherwise the wrong inferred type
{
Train.Jump(-1, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion source/TrainManager/TrainManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<Compile Include="TrackFollowingObject\AI\TravelData.cs" />
<Compile Include="TrackFollowingObject\AI\TravelPointData.cs" />
<Compile Include="TrackFollowingObject\AI\TravelStopData.cs" />
<Compile Include="TrackFollowingObject\TrackFollowingObject.cs" />
<Compile Include="TrackFollowingObject\ScriptedTrain.cs" />
<Compile Include="TrainManager.cs" />
<Compile Include="Train\BrakeSystem.cs" />
<Compile Include="Train\CommandEntry.cs" />
Expand Down

0 comments on commit 10f791d

Please sign in to comment.