Skip to content
Closed
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
44 changes: 27 additions & 17 deletions source/ObjectViewer/FunctionScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,26 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
}
break;
case Instructions.PlayerTrainDistance:
double playerDist = double.MaxValue;
for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
if (TrainManager.PlayerTrain != null)
{
double fx = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.X - Position.X;
double fy = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Y - Position.Y;
double fz = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Z - Position.Z;
double f = fx * fx + fy * fy + fz * fz;
if (f < playerDist) playerDist = f;
double rx = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.X - Position.X;
double ry = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Y - Position.Y;
double rz = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Z - Position.Z;
double r = rx * rx + ry * ry + rz * rz;
if (r < playerDist) playerDist = r;
}
Function.Stack[s] = Math.Sqrt(playerDist);
double playerDist = double.MaxValue;
for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
{
double fx = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.X - Position.X;
double fy = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Y - Position.Y;
double fz = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Z - Position.Z;
double f = fx * fx + fy * fy + fz * fz;
if (f < playerDist) playerDist = f;
double rx = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.X - Position.X;
double ry = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Y - Position.Y;
double rz = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Z - Position.Z;
double r = rx * rx + ry * ry + rz * rz;
if (r < playerDist) playerDist = r;
}
Function.Stack[s] = Math.Sqrt(playerDist);
} else {
Function.Stack[s] = 0.0;
}
s++; break;
case Instructions.TrainDistance:
if (Train != null) {
Expand Down Expand Up @@ -463,9 +468,14 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
}
break;
case Instructions.PlayerTrackDistance:
double pt0 = TrainManager.PlayerTrain.FrontCarTrackPosition;
double pt1 = TrainManager.PlayerTrain.RearCarTrackPosition;
Function.Stack[s] = TrackPosition > pt0 ? TrackPosition - pt0 : TrackPosition < pt1 ? TrackPosition - pt1 : 0.0;
if (TrainManager.PlayerTrain != null)
{
double pt0 = TrainManager.PlayerTrain.FrontCarTrackPosition;
double pt1 = TrainManager.PlayerTrain.RearCarTrackPosition;
Function.Stack[s] = TrackPosition > pt0 ? TrackPosition - pt0 : TrackPosition < pt1 ? TrackPosition - pt1 : 0.0;
} else {
Function.Stack[s] = 0.0;
}
s++; break;
case Instructions.TrainTrackDistance:
if (Train != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,28 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
}
break;
case Instructions.PlayerTrainDistance:
double playerDist = double.MaxValue;
for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
{
double fx = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.X - Position.X;
double fy = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Y - Position.Y;
double fz = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Z - Position.Z;
double f = fx * fx + fy * fy + fz * fz;
if (f < playerDist) playerDist = f;
double rx = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.X - Position.X;
double ry = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Y - Position.Y;
double rz = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Z - Position.Z;
double r = rx * rx + ry * ry + rz * rz;
if (r < playerDist) playerDist = r;
}
Function.Stack[s] = Math.Sqrt(playerDist);
if (TrainManager.PlayerTrain != null)
{
double playerDist = double.MaxValue;
for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
{
double fx = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.X - Position.X;
double fy = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Y - Position.Y;
double fz = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Z - Position.Z;
double f = fx * fx + fy * fy + fz * fz;
if (f < playerDist) playerDist = f;
double rx = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.X - Position.X;
double ry = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Y - Position.Y;
double rz = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Z - Position.Z;
double r = rx * rx + ry * ry + rz * rz;
if (r < playerDist) playerDist = r;
}
Function.Stack[s] = Math.Sqrt(playerDist);
}
else
{
Function.Stack[s] = 0.0;
}
s++; break;
case Instructions.TrainDistance:
if (Train != null) {
Expand Down Expand Up @@ -462,9 +469,16 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr
}
break;
case Instructions.PlayerTrackDistance:
double pt0 = TrainManager.PlayerTrain.FrontCarTrackPosition;
double pt1 = TrainManager.PlayerTrain.RearCarTrackPosition;
Function.Stack[s] = TrackPosition > pt0 ? TrackPosition - pt0 : TrackPosition < pt1 ? TrackPosition - pt1 : 0.0;
if (TrainManager.PlayerTrain != null)
{
double pt0 = TrainManager.PlayerTrain.FrontCarTrackPosition;
double pt1 = TrainManager.PlayerTrain.RearCarTrackPosition;
Function.Stack[s] = TrackPosition > pt0 ? TrackPosition - pt0 : TrackPosition < pt1 ? TrackPosition - pt1 : 0.0;
}
else
{
Function.Stack[s] = 0.0;
}
s++; break;
case Instructions.TrainTrackDistance:
if (Train != null) {
Expand Down
101 changes: 82 additions & 19 deletions source/RouteViewer/FunctionScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,28 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager
}
break;
case Instructions.PlayerTrainDistance:
double playerDist = double.MaxValue;
for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
if (TrainManager.PlayerTrain != null)
{
double fx = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.X - Position.X;
double fy = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Y - Position.Y;
double fz = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Z - Position.Z;
double f = fx * fx + fy * fy + fz * fz;
if (f < playerDist) playerDist = f;
double rx = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.X - Position.X;
double ry = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Y - Position.Y;
double rz = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Z - Position.Z;
double r = rx * rx + ry * ry + rz * rz;
if (r < playerDist) playerDist = r;
}
Function.Stack[s] = Math.Sqrt(playerDist);
double playerDist = double.MaxValue;
for (int j = 0; j < TrainManager.PlayerTrain.Cars.Length; j++)
{
double fx = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.X - Position.X;
double fy = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Y - Position.Y;
double fz = TrainManager.PlayerTrain.Cars[j].FrontAxle.Follower.WorldPosition.Z - Position.Z;
double f = fx * fx + fy * fy + fz * fz;
if (f < playerDist) playerDist = f;
double rx = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.X - Position.X;
double ry = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Y - Position.Y;
double rz = TrainManager.PlayerTrain.Cars[j].RearAxle.Follower.WorldPosition.Z - Position.Z;
double r = rx * rx + ry * ry + rz * rz;
if (r < playerDist) playerDist = r;
}
Function.Stack[s] = Math.Sqrt(playerDist);
}
else
{
Function.Stack[s] = 0;
}
s++; break;
case Instructions.TrainDistance:
if (Train != null) {
Expand Down Expand Up @@ -461,9 +468,12 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager
}
break;
case Instructions.PlayerTrackDistance:
double pt0 = TrainManager.PlayerTrain.FrontCarTrackPosition;
double pt1 = TrainManager.PlayerTrain.RearCarTrackPosition;
Function.Stack[s] = TrackPosition > pt0 ? TrackPosition - pt0 : TrackPosition < pt1 ? TrackPosition - pt1 : 0.0;
if (TrainManager.PlayerTrain != null)
{
double pt0 = TrainManager.PlayerTrain.FrontCarTrackPosition;
double pt1 = TrainManager.PlayerTrain.RearCarTrackPosition;
Function.Stack[s] = TrackPosition > pt0 ? TrackPosition - pt0 : TrackPosition < pt1 ? TrackPosition - pt1 : 0.0;
}
s++; break;
case Instructions.TrainTrackDistance:
if (Train != null) {
Expand Down Expand Up @@ -879,8 +889,61 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager
}
s++; break;
case Instructions.Klaxon:
//Object Viewer doesn't actually have a sound player, so we can't test against it, thus return zero..
Function.Stack[s] = 0.0;
if (Train != null && TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns != null)
{
for (int j = 0; j < TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns.Length; j++)
{
/* Return the index of the currently playing horn sound
*
* 1 ==> Primary horn
* 2 ==> Secondary horn
* 3 ==> Music horn
*/
if (Program.Sounds.IsPlaying(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns[j].Source))
{
Function.Stack[s] = j + 1;
break;
}
if (j == TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns.Length -1)
{
Function.Stack[s] = 0.0;
}
}
}
else
{
Function.Stack[s] = 0.0;
}
s++; break;
case Instructions.PrimaryKlaxon:
if (Train != null)
{
Function.Stack[s] = Program.Sounds.IsPlaying(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns[0].Source) ? 1.0 : 0.0;
}
else
{
Function.Stack[s] = 0.0;
}
s++; break;
case Instructions.SecondaryKlaxon:
if (Train != null)
{
Function.Stack[s] = Program.Sounds.IsPlaying(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns[1].Source) ? 1.0 : 0.0;
}
else
{
Function.Stack[s] = 0.0;
}
s++; break;
case Instructions.MusicKlaxon:
if (Train != null)
{
Function.Stack[s] = Program.Sounds.IsPlaying(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns[2].Source) ? 1.0 : 0.0;
}
else
{
Function.Stack[s] = 0.0;
}
s++; break;
case Instructions.HasAirBrake:
if (Train != null) {
Expand Down
2 changes: 1 addition & 1 deletion source/RouteViewer/System/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public override Dictionary<int, Track> Tracks

public override AbstractTrain ParseTrackFollowingObject(string objectPath, string tfoFile)
{
Interface.AddMessage(MessageType.Warning, false, "Track Following Objects are not shown in Route Viewer. Please test using the main simulation.");
Interface.AddMessage(MessageType.Information, false, "Track Following Objects are not shown in Route Viewer. Please test using the main simulation.");
return null;
}

Expand Down