Skip to content

Commit

Permalink
Automatic merge of T1.5.1-680-gae3b5cfa9 and 7 pull requests
Browse files Browse the repository at this point in the history
- Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters
- Pull request #874 at f8dbeab: Dynamic brake controller refactoring
- Pull request #875 at 43bf33e: Bug fix for https://bugs.launchpad.net/or/+bug/2036346 Player train switching doesn't work with 3D cabs
- Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder
- Pull request #878 at ef944ab: Implement Polach Adhesion
- Pull request #879 at 5a0ff7b: chore: remove Website folder
- Pull request #880 at 084b404: fix: Refined comment summarising property SData1
  • Loading branch information
openrails-bot committed Oct 14, 2023
9 parents 03ad6ce + ae3b5cf + d00beb9 + f8dbeab + 43bf33e + f92de76 + ef944ab + 5a0ff7b + 084b404 commit bf0a66e
Show file tree
Hide file tree
Showing 26 changed files with 3,123 additions and 7,673 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -365,5 +365,4 @@ ASALocalRun/
healthchecksdb

# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
/Source/RunActivity/Properties/launchSettings.json
MigrationBackup/
3 changes: 0 additions & 3 deletions Source/ORTS.Common/Input/UserCommand.cs
Expand Up @@ -24,7 +24,6 @@ public enum UserCommand
[GetString("Game Change Cab")] GameChangeCab,
[GetString("Game Request Control")] GameRequestControl,
[GetString("Game Multi Player Dispatcher")] GameMultiPlayerDispatcher,
[GetString("Game Multi Player Dispatcher Beta")] GameMultiPlayerDispatcherBeta,
[GetString("Game Multi Player Texting")] GameMultiPlayerTexting,
[GetString("Game Switch Manual Mode")] GameSwitchManualMode,
[GetString("Game Reset Out Of Control Mode")] GameResetOutOfControlMode,
Expand Down Expand Up @@ -62,8 +61,6 @@ public enum UserCommand
[GetString("Debug Precipitation Decrease")] DebugPrecipitationDecrease,
[GetString("Debug Precipitation Liquidity Increase")] DebugPrecipitationLiquidityIncrease,
[GetString("Debug Precipitation Liquidity Decrease")] DebugPrecipitationLiquidityDecrease,
[GetString("Debug Daylight Offset Increase")] DebugDaylightOffsetIncrease,
[GetString("Debug Daylight Offset Decrease")] DebugDaylightOffsetDecrease,
[GetString("Debug Weather Change")] DebugWeatherChange,
[GetString("Debug Clock Forwards")] DebugClockForwards,
[GetString("Debug Clock Backwards")] DebugClockBackwards,
Expand Down
3 changes: 0 additions & 3 deletions Source/ORTS.Settings/InputSettings.cs
Expand Up @@ -480,8 +480,6 @@ static void InitializeCommands(UserCommandInput[] Commands)
Commands[(int)UserCommand.DebugLockShadows] = new UserCommandKeyInput(0x1F, KeyModifiers.Control | KeyModifiers.Alt);
Commands[(int)UserCommand.DebugLogger] = new UserCommandKeyInput(0x58);
Commands[(int)UserCommand.DebugLogRenderFrame] = new UserCommandKeyInput(0x58, KeyModifiers.Alt);
Commands[(int)UserCommand.DebugDaylightOffsetDecrease] = new UserCommandKeyInput(0x0C, KeyModifiers.Shift | KeyModifiers.Alt);
Commands[(int)UserCommand.DebugDaylightOffsetIncrease] = new UserCommandKeyInput(0x0D, KeyModifiers.Shift | KeyModifiers.Alt);
Commands[(int)UserCommand.DebugOvercastDecrease] = new UserCommandKeyInput(0x0C, KeyModifiers.Control);
Commands[(int)UserCommand.DebugOvercastIncrease] = new UserCommandKeyInput(0x0D, KeyModifiers.Control);
Commands[(int)UserCommand.DebugPhysicsForm] = new UserCommandKeyInput(0x3D, KeyModifiers.Alt);
Expand Down Expand Up @@ -522,7 +520,6 @@ static void InitializeCommands(UserCommandInput[] Commands)
Commands[(int)UserCommand.GameExternalCabController] = new UserCommandKeyInput(0x29);
Commands[(int)UserCommand.GameFullscreen] = new UserCommandKeyInput(0x1C, KeyModifiers.Alt);
Commands[(int)UserCommand.GameMultiPlayerDispatcher] = new UserCommandKeyInput(0x0A, KeyModifiers.Control);
Commands[(int)UserCommand.GameMultiPlayerDispatcherBeta] = new UserCommandKeyInput(0x0A, KeyModifiers.Control | KeyModifiers.Shift);
Commands[(int)UserCommand.GameMultiPlayerTexting] = new UserCommandKeyInput(0x14, KeyModifiers.Alt);
Commands[(int)UserCommand.GamePause] = new UserCommandKeyInput(Keys.Pause);
Commands[(int)UserCommand.GamePauseMenu] = new UserCommandKeyInput(0x01);
Expand Down
319 changes: 141 additions & 178 deletions Source/Orts.Simulation/Simulation/AIs/AI.cs

Large diffs are not rendered by default.

356 changes: 141 additions & 215 deletions Source/Orts.Simulation/Simulation/AIs/AIAuxAction.cs

Large diffs are not rendered by default.

121 changes: 57 additions & 64 deletions Source/Orts.Simulation/Simulation/AIs/AIPath.cs
Expand Up @@ -22,14 +22,14 @@
* Could this be used for player trains also?
*
*/
using Orts.Formats.Msts;
using Orts.Formats.OR;
using ORTS.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Orts.Formats.Msts;
using Orts.Formats.OR;
using ORTS.Common;

namespace Orts.Simulation.AIs
{
Expand All @@ -42,10 +42,10 @@ public class AIPath
#if ACTIVITY_EDITOR
public ORRouteConfig orRouteConfig { get; protected set; }
#endif
public AIPathNode FirstNode; // path starting node
//public AIPathNode LastVisitedNode; not used anymore
public AIPathNode FirstNode; // Path starting node
//public AIPathNode LastVisitedNode; not used anymore --- TODO: Remove?
public List<AIPathNode> Nodes = new List<AIPathNode>();
public string pathName; //name of the path to be able to print it.
public string pathName; // Name of the path to be able to print it.

/// <summary>
/// Creates an AIPath from PAT file information.
Expand Down Expand Up @@ -84,11 +84,11 @@ public AIPath(TDBFile TDB, TSectionDatFile tsectiondat, string filePath)
node.Index = i;
TrPathNode tpn = patFile.TrPathNodes[i];

// find TVNindex to next main node.
// Find TVNindex to next main node.
if (tpn.HasNextMainNode)
{
node.NextMainNode = Nodes[(int)tpn.nextMainNode];
node.NextMainTVNIndex = node.FindTVNIndex(node.NextMainNode, TDB, tsectiondat, i == 0 ? -1 : Nodes[i-1].NextMainTVNIndex );
node.NextMainTVNIndex = node.FindTVNIndex(node.NextMainNode, TDB, tsectiondat, i == 0 ? -1 : Nodes[i - 1].NextMainTVNIndex);
if (node.JunctionIndex >= 0)
node.IsFacingPoint = TestFacingPoint(node.JunctionIndex, node.NextMainTVNIndex);
if (node.NextMainTVNIndex < 0)
Expand All @@ -99,7 +99,7 @@ public AIPath(TDBFile TDB, TSectionDatFile tsectiondat, string filePath)
}
}

// find TVNindex to next siding node
// Find TVNindex to next siding node
if (tpn.HasNextSidingNode)
{
node.NextSidingNode = Nodes[(int)tpn.nextSidingNode];
Expand All @@ -120,14 +120,13 @@ public AIPath(TDBFile TDB, TSectionDatFile tsectiondat, string filePath)

FindSidingEnds();

if (fatalerror) Nodes = null; // invalid path - do not return any nodes
if (fatalerror) Nodes = null; // Invalid path - do not return any nodes
}

/// <summary>
/// constructor out of other path
/// </summary>
/// <param name="otherPath"></param>

public AIPath(AIPath otherPath)
{
TrackDB = otherPath.TrackDB; ;
Expand All @@ -138,8 +137,7 @@ public AIPath(AIPath otherPath)
Nodes.Add(new AIPathNode(otherNode));
}

// set correct node references

// Set correct node references
for (int iNode = 0; iNode <= otherPath.Nodes.Count - 1; iNode++)
{
AIPathNode otherNode = otherPath.Nodes[iNode];
Expand Down Expand Up @@ -190,7 +188,7 @@ private void FindSidingEnds()
// kvp.Value.IsLastSwitchUse = true;
}

// restore game state
// Restore game state
public AIPath(TrackDatabaseFile TDB, TrackSectionsFile tsectiondat, BinaryReader inf)
{
pathName = inf.ReadString();
Expand All @@ -211,13 +209,10 @@ public AIPath(TrackDatabaseFile TDB, TrackSectionsFile tsectiondat, BinaryReader
public AIPathNode ReadNode(BinaryReader inf)
{
int index = inf.ReadInt32();
if (index < 0 || index > Nodes.Count)
return null;
else
return Nodes[index];
return index < 0 || index > Nodes.Count ? null : Nodes[index];
}

// save game state
// Save game state
public void Save(BinaryWriter outf)
{
outf.Write(pathName);
Expand All @@ -234,7 +229,7 @@ public void Save(BinaryWriter outf)
public static void WriteNode(BinaryWriter outf, AIPathNode node)
{
if (node == null)
outf.Write((int)-1);
outf.Write(-1);
else
outf.Write(node.Index);
}
Expand All @@ -248,9 +243,7 @@ private bool TestFacingPoint(int junctionIndex, int vectorIndex)
if (junctionIndex < 0 || vectorIndex < 0)
return false;
TrackNode tn = TrackDB.TrackNodes[junctionIndex];
if (tn.TrJunctionNode == null || tn.TrPins[0].Link == vectorIndex)
return false;
return true;
return tn.TrJunctionNode != null && tn.TrPins[0].Link != vectorIndex;
}
}

Expand Down Expand Up @@ -292,7 +285,6 @@ public AIPathNode(TrPathNode tpn, TrackPDP pdp, TrackDB trackDB, bool isTimetabl
/// Constructor from other AIPathNode
/// </summary>
/// <param name="otherNode"></param>

public AIPathNode(AIPathNode otherNode)
{
ID = otherNode.ID;
Expand All @@ -301,8 +293,8 @@ public AIPathNode(AIPathNode otherNode)
WaitTimeS = otherNode.WaitTimeS;
WaitUntil = otherNode.WaitUntil;
NCars = otherNode.NCars;
NextMainNode = null; // set after completion of copying to get correct reference
NextSidingNode = null; // set after completion of copying to get correct reference
NextMainNode = null; // Set after completion of copying to get correct reference
NextSidingNode = null; // Set after completion of copying to get correct reference
NextMainTVNIndex = otherNode.NextMainTVNIndex;
NextSidingTVNIndex = otherNode.NextSidingTVNIndex;
Location = otherNode.Location;
Expand All @@ -327,60 +319,61 @@ public AIPathNode(AIPathNode otherNode)
private void InterpretPathNodeFlags(TrPathNode tpn, TrackPDP pdp, bool isTimetableMode)
{
if ((tpn.pathFlags & 03) == 0) return;
// bit 0 and/or bit 1 is set.
// Bit 0 and/or bit 1 is set.

if ((tpn.pathFlags & 01) != 0)
{
// if bit 0 is set: reversal
// If bit 0 is set: reversal
Type = AIPathNodeType.Reverse;
}
else
{
// bit 0 is not set, but bit 1 is set:waiting point
// Bit 0 is not set, but bit 1 is set: waiting point
Type = AIPathNodeType.Stop;
//<CSComment> tests showed me that value 9 in pdp is generated when the waiting point (or also
//a path start or end point) are dragged within the path editor of the MSTS activity editor; the points are still valid;
// <CSComment> Tests showed me that value 9 in pdp is generated when the waiting point (or also
// a path start or end point) are dragged within the path editor of the MSTS activity editor; the points are still valid;
// however, as a contradictory case of the past has been reported, the check is skipped only when the enhanced compatibility flag is on;
if (pdp.IsInvalid && isTimetableMode) // not a valid point
if (pdp.IsInvalid && isTimetableMode) // Not a valid point
{
Type = AIPathNodeType.Invalid;
}
}

WaitTimeS = (int)((tpn.pathFlags >> 16) & 0xffff); // get the AAAA part.
// computations for absolute wait times are made within AITrain.cs
/* if (WaitTimeS >= 30000 && WaitTimeS < 40000)
{
// real wait time.
// waitTimeS (in decimal notation) = 3HHMM (hours and minuts)
int hour = (WaitTimeS / 100) % 100;
int minute = WaitTimeS % 100;
WaitUntil = 60 * (minute + 60 * hour);
WaitTimeS = 0;
}*/
// computations for absolute wait times are made within AITrain.cs
// TODO: Remove?
/* if (WaitTimeS >= 30000 && WaitTimeS < 40000)
{
// real wait time.
// waitTimeS (in decimal notation) = 3HHMM (hours and minuts)
int hour = (WaitTimeS / 100) % 100;
int minute = WaitTimeS % 100;
WaitUntil = 60 * (minute + 60 * hour);
WaitTimeS = 0;
}*/
// computations are made within AITrain.cs
/* else if (WaitTimeS >= 40000 && WaitTimeS < 60000)
{
// Uncouple if a wait=stop point
// waitTimeS (in decimal notation) = 4NNSS (uncouple NN cars, wait SS seconds)
// or 5NNSS (uncouple NN cars, keep rear, wait SS seconds)
NCars = (WaitTimeS / 100) % 100;
if (WaitTimeS >= 50000)
NCars = -NCars;
WaitTimeS %= 100;
if (Type == AIPathNodeType.Stop)
Type = AIPathNodeType.Uncouple;
}
else if (WaitTimeS >= 60000) // this is old and should be removed/reused
{
// waitTimes = 6xSSS with waitTime SSS seconds.
WaitTimeS %= 1000;
} */
/* else if (WaitTimeS >= 40000 && WaitTimeS < 60000)
{
// Uncouple if a wait=stop point
// waitTimeS (in decimal notation) = 4NNSS (uncouple NN cars, wait SS seconds)
// or 5NNSS (uncouple NN cars, keep rear, wait SS seconds)
NCars = (WaitTimeS / 100) % 100;
if (WaitTimeS >= 50000)
NCars = -NCars;
WaitTimeS %= 100;
if (Type == AIPathNodeType.Stop)
Type = AIPathNodeType.Uncouple;
}
else if (WaitTimeS >= 60000) // this is old and should be removed/reused
{
// waitTimes = 6xSSS with waitTime SSS seconds.
WaitTimeS %= 1000;
} */

}


// restore game state
// Restore game state
public AIPathNode(BinaryReader inf)
{
ID = inf.ReadInt32();
Expand All @@ -401,7 +394,7 @@ public AIPathNode(BinaryReader inf)
Location.Location.Z = inf.ReadSingle();
}

// save game state
// Save game state
public void Save(BinaryWriter outf)
{
outf.Write(ID);
Expand Down Expand Up @@ -429,7 +422,7 @@ public int FindTVNIndex(AIPathNode nextNode, TrackDatabaseFile TDB, TrackSection
int junctionIndexThis = JunctionIndex;
int junctionIndexNext = nextNode.JunctionIndex;

// if this is no junction, try to find the TVN index
// If this is no junction, try to find the TVN index
if (junctionIndexThis < 0)
{
try
Expand All @@ -455,7 +448,7 @@ public int FindTVNIndex(AIPathNode nextNode, TrackDatabaseFile TDB, TrackSection
}
}

//both this node and the next node are junctions: find the vector node connecting them.
// Both this node and the next node are junctions: find the vector node connecting them.
var iCand = -1;
for (int i = 0; i < TDB.TrackDB.TrackNodes.Count(); i++)
{
Expand Down Expand Up @@ -516,7 +509,7 @@ public static int FindJunctionOrEndIndex(WorldLocation location, TrackDB trackDB
float dz = tn.UiD.Z - location.Location.Z;
dz += (tn.UiD.TileZ - location.TileZ) * 2048;
float dy = tn.UiD.Y - location.Location.Y;
float d = dx * dx + dy * dy + dz * dz;
float d = (dx * dx) + (dy * dy) + (dz * dz);
if (bestDistance2 > d)
{
bestIndex = j;
Expand Down

0 comments on commit bf0a66e

Please sign in to comment.