From 2044ee7999803550ca8508f06d8279d3f167ffbc Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Mon, 11 Nov 2024 16:58:39 +0000 Subject: [PATCH 1/7] Change: Enforce lowerCamelCase for parameter names (P1) TrainManager --- source/ObjectViewer/FunctionScripts.cs | 20 +- source/ObjectViewer/Trains/NearestTrain.cs | 10 +- .../ObjectViewer/Trains/NearestTrainStatus.cs | 10 +- source/OpenBVE/Game/AI/AI.SimpleHuman.cs | 12 +- .../AnimatedObjects/FunctionScripts.cs | 20 +- .../Graphics/Renderers/Overlays.Debug.cs | 32 +- source/OpenBVE/System/Scripting.cs | 8 +- .../Train.OpenBve/Panel/Panel2CfgParser.cs | 18 +- .../Train.OpenBve/Panel/PanelCfgParser.cs | 14 +- .../Train.OpenBve/Sound/SoundCfg.Bve2.cs | 8 +- .../Train.OpenBve/Sound/SoundCfg.Bve4.cs | 8 +- .../Train.OpenBve/Sound/SoundCfg.Xml.cs | 8 +- .../Train.OpenBve/Train/BVE/TrainDatParser.cs | 44 +- .../Train/XML/TrainXmlParser.BrakeNode.cs | 18 +- .../Train/XML/TrainXmlParser.CarNode.cs | 2 +- source/RouteViewer/FunctionScripts.cs | 20 +- .../Brake/AirBrake/AutomaticAirBrake.cs | 218 ++++----- .../AirBrake/Components/AirCompressor.cs | 8 +- .../Brake/AirBrake/ElectricCommandBrake.cs | 138 +++--- .../ElectromagneticStraightAirBrake.cs | 246 +++++----- .../Brake/AirBrake/ThroughPiped.cs | 8 +- source/TrainManager/Brake/CarBrake.cs | 72 +-- source/TrainManager/Car/Bogie/Bogie.cs | 58 +-- source/TrainManager/Car/CarBase.cs | 432 +++++++++--------- source/TrainManager/Car/Coupler/Coupler.cs | 72 +-- .../Car/Systems/AbstractReAdhesionDevice.cs | 4 +- .../Car/Systems/ConstantSpeedDevice.cs | 26 +- .../TrainManager/Car/Systems/FlangeSounds.cs | 10 +- source/TrainManager/Car/Systems/HoldBrake.cs | 16 +- .../Car/Systems/ReadhesionDevice.cs | 6 +- source/TrainManager/Car/Systems/RunSounds.cs | 26 +- source/TrainManager/Car/Systems/Suspension.cs | 4 +- .../TrainManager/Car/Windscreen/Windscreen.cs | 26 +- source/TrainManager/Car/Windscreen/Wiper.cs | 24 +- source/TrainManager/Cargo/CargoBase.cs | 6 +- source/TrainManager/Cargo/Passengers.cs | 18 +- source/TrainManager/Handles/AbstractHandle.cs | 38 +- .../TrainManager/Handles/Handles.AirBrake.cs | 34 +- source/TrainManager/Handles/Handles.Brake.cs | 52 +-- .../Handles/Handles.EmergencyBrake.cs | 6 +- .../TrainManager/Handles/Handles.HoldBrake.cs | 4 +- .../TrainManager/Handles/Handles.LocoBrake.cs | 54 +-- source/TrainManager/Handles/Handles.Power.cs | 42 +- .../TrainManager/Handles/Handles.Reverser.cs | 12 +- .../TrainManager/Motor/AbstractMotorSound.cs | 2 +- source/TrainManager/Motor/BVE4/MotorSound.cs | 20 +- .../TrainManager/Motor/BVE5/AITrainSound.cs | 6 +- source/TrainManager/Motor/BVE5/MotorSound.cs | 14 +- .../TrainManager/Power/AccelerationCurve.cs | 26 +- source/TrainManager/Power/Breaker.cs | 8 +- .../DSD/DriverSupervisionDevice.cs | 42 +- .../TrainManager/SafetySystems/Overspeed.cs | 4 +- .../TrainManager/SafetySystems/PassAlarm.cs | 8 +- .../Plugin/AI/PluginAI.HeiAts.cs | 42 +- .../Plugin/AI/PluginAI.MTRAuto.cs | 18 +- .../SafetySystems/Plugin/AI/PluginAI.UKDt.cs | 68 +-- .../SafetySystems/Plugin/AI/PluginAI.UKMUt.cs | 72 +-- .../SafetySystems/Plugin/AI/PluginAI.UKSpt.cs | 76 +-- .../SafetySystems/Plugin/AI/PluginAI.cs | 8 +- .../SafetySystems/Plugin/LegacyPlugin.cs | 6 +- .../SafetySystems/Plugin/NetPlugin.cs | 50 +- .../SafetySystems/Plugin/Plugin.Functions.cs | 58 +-- .../SafetySystems/Plugin/Plugin.cs | 18 +- .../SafetySystems/Plugin/ProxyPlugin.cs | 6 +- .../SafetySystems/StationAdjustAlarm.cs | 2 +- .../AI/TrackFollowingObject.AI.cs | 266 +++++------ .../TrackFollowingObject/ScriptedTrain.cs | 36 +- source/TrainManager/Train/BrakeSystem.cs | 140 +++--- source/TrainManager/Train/Doors.cs | 64 +-- source/TrainManager/Train/DriverBody.cs | 22 +- source/TrainManager/Train/Horn.cs | 36 +- source/TrainManager/Train/RequestStop.cs | 6 +- source/TrainManager/Train/Station.cs | 36 +- source/TrainManager/Train/TrainBase.cs | 230 +++++----- source/TrainManager/TrainManager.cs | 24 +- 75 files changed, 1663 insertions(+), 1663 deletions(-) diff --git a/source/ObjectViewer/FunctionScripts.cs b/source/ObjectViewer/FunctionScripts.cs index 8dc2de540..1b7bed6e4 100644 --- a/source/ObjectViewer/FunctionScripts.cs +++ b/source/ObjectViewer/FunctionScripts.cs @@ -939,7 +939,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr // brake case Instructions.BrakeMainReservoir: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.mainReservoir.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.MainReservoir.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -951,7 +951,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.mainReservoir.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.MainReservoir.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -959,7 +959,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr break; case Instructions.BrakeEqualizingReservoir: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.equalizingReservoir.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.EqualizingReservoir.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -971,7 +971,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.equalizingReservoir.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.EqualizingReservoir.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -979,7 +979,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr break; case Instructions.BrakeBrakePipe: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.brakePipe.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakePipe.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -991,7 +991,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.brakePipe.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakePipe.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -999,7 +999,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr break; case Instructions.BrakeBrakeCylinder: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.brakeCylinder.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakeCylinder.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -1011,7 +1011,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.brakeCylinder.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakeCylinder.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -1019,7 +1019,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr break; case Instructions.BrakeStraightAirPipe: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.straightAirPipe.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.StraightAirPipe.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -1031,7 +1031,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.straightAirPipe.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.StraightAirPipe.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } diff --git a/source/ObjectViewer/Trains/NearestTrain.cs b/source/ObjectViewer/Trains/NearestTrain.cs index d047a2a4d..4e39a51e4 100644 --- a/source/ObjectViewer/Trains/NearestTrain.cs +++ b/source/ObjectViewer/Trains/NearestTrain.cs @@ -74,11 +74,11 @@ private static TrainBase CreateDummyTrain() train.Cars[i].Specs.IsMotorCar = true; //At the minute, Object Viewer uses dummy brake systems - train.Cars[i].CarBrake.mainReservoir = new MainReservoir(Status.MainReservoirPressure * 1000.0); - train.Cars[i].CarBrake.equalizingReservoir = new EqualizingReservoir(Status.EqualizingReservoirPressure * 1000.0); - train.Cars[i].CarBrake.brakePipe = new BrakePipe(Status.BrakePipePressure * 1000.0); - train.Cars[i].CarBrake.brakeCylinder = new BrakeCylinder(Status.BrakeCylinderPressure * 1000.0); - train.Cars[i].CarBrake.straightAirPipe = new StraightAirPipe(Status.StraightAirPipePressure * 1000.0); + train.Cars[i].CarBrake.MainReservoir = new MainReservoir(Status.MainReservoirPressure * 1000.0); + train.Cars[i].CarBrake.EqualizingReservoir = new EqualizingReservoir(Status.EqualizingReservoirPressure * 1000.0); + train.Cars[i].CarBrake.BrakePipe = new BrakePipe(Status.BrakePipePressure * 1000.0); + train.Cars[i].CarBrake.BrakeCylinder = new BrakeCylinder(Status.BrakeCylinderPressure * 1000.0); + train.Cars[i].CarBrake.StraightAirPipe = new StraightAirPipe(Status.StraightAirPipePressure * 1000.0); train.Cars[i].Coupler = new Coupler(0.9 * 0.3, 1.1 * 0.3, train.Cars[i], i < train.Cars.Length - 1 ? train.Cars[i + 1] : null, train); diff --git a/source/ObjectViewer/Trains/NearestTrainStatus.cs b/source/ObjectViewer/Trains/NearestTrainStatus.cs index bfbe83800..02e6946f0 100644 --- a/source/ObjectViewer/Trains/NearestTrainStatus.cs +++ b/source/ObjectViewer/Trains/NearestTrainStatus.cs @@ -58,11 +58,11 @@ internal void Apply(TrainBase train) if (!NearestTrain.IsExtensionsCfg) { - car.CarBrake.mainReservoir.CurrentPressure = MainReservoirPressure * 1000.0; - car.CarBrake.equalizingReservoir.CurrentPressure = EqualizingReservoirPressure * 1000.0; - car.CarBrake.brakePipe.CurrentPressure = BrakePipePressure * 1000.0; - car.CarBrake.brakeCylinder.CurrentPressure = BrakeCylinderPressure * 1000.0; - car.CarBrake.straightAirPipe.CurrentPressure = StraightAirPipePressure * 1000.0; + car.CarBrake.MainReservoir.CurrentPressure = MainReservoirPressure * 1000.0; + car.CarBrake.EqualizingReservoir.CurrentPressure = EqualizingReservoirPressure * 1000.0; + car.CarBrake.BrakePipe.CurrentPressure = BrakePipePressure * 1000.0; + car.CarBrake.BrakeCylinder.CurrentPressure = BrakeCylinderPressure * 1000.0; + car.CarBrake.StraightAirPipe.CurrentPressure = StraightAirPipePressure * 1000.0; } car.Doors[0].State = LeftDoorState; diff --git a/source/OpenBVE/Game/AI/AI.SimpleHuman.cs b/source/OpenBVE/Game/AI/AI.SimpleHuman.cs index f17478741..6eaf4227a 100644 --- a/source/OpenBVE/Game/AI/AI.SimpleHuman.cs +++ b/source/OpenBVE/Game/AI/AI.SimpleHuman.cs @@ -243,11 +243,11 @@ private void PerformDefault() Train.Handles.Power.ApplyState(-1, true); if (Train.Handles.Brake is AirBrakeHandle) { - if (Train.StationDepartureTime - Program.CurrentRoute.SecondsSinceMidnight > 10 || Train.Cars[Train.DriverCar].CarBrake.brakeCylinder.CurrentPressure < 0.3 * Train.Cars[Train.DriverCar].CarBrake.brakeCylinder.ServiceMaximumPressure) + if (Train.StationDepartureTime - Program.CurrentRoute.SecondsSinceMidnight > 10 || Train.Cars[Train.DriverCar].CarBrake.BrakeCylinder.CurrentPressure < 0.3 * Train.Cars[Train.DriverCar].CarBrake.BrakeCylinder.ServiceMaximumPressure) { Train.Handles.Brake.ApplyState(AirBrakeHandleState.Service); } - else if (Train.Cars[Train.DriverCar].CarBrake.brakeCylinder.CurrentPressure > 0.9 * Train.Cars[Train.DriverCar].CarBrake.brakeCylinder.EmergencyMaximumPressure) + else if (Train.Cars[Train.DriverCar].CarBrake.BrakeCylinder.CurrentPressure > 0.9 * Train.Cars[Train.DriverCar].CarBrake.BrakeCylinder.EmergencyMaximumPressure) { Train.Handles.Brake.ApplyState(AirBrakeHandleState.Release); } @@ -417,9 +417,9 @@ private void PerformDefault() { if (Train.Cars[i].Specs.IsMotorCar) { - if (Train.Cars[Train.DriverCar].CarBrake.motorDeceleration != 0 && Train.Cars[Train.DriverCar].CarBrake.motorDeceleration < BrakeDeceleration) + if (Train.Cars[Train.DriverCar].CarBrake.MotorDeceleration != 0 && Train.Cars[Train.DriverCar].CarBrake.MotorDeceleration < BrakeDeceleration) { - BrakeDeceleration = Train.Cars[Train.DriverCar].CarBrake.motorDeceleration; + BrakeDeceleration = Train.Cars[Train.DriverCar].CarBrake.MotorDeceleration; } break; } @@ -681,14 +681,14 @@ private void PerformDefault() { if (wiperTimer < 0) { - if (Train.Cars[Train.DriverCar].Windscreen.currentDrops < Train.Cars[Train.DriverCar].Windscreen.RainDrops.Length / 4) + if (Train.Cars[Train.DriverCar].Windscreen.CurrentDrops < Train.Cars[Train.DriverCar].Windscreen.RainDrops.Length / 4) { if(Train.Cars[Train.DriverCar].Windscreen.Wipers.CurrentSpeed != WiperSpeed.Off) { Train.Cars[Train.DriverCar].Windscreen.Wipers.ChangeSpeed(Translations.Command.WiperSpeedDown); } } - else if (Train.Cars[Train.DriverCar].Windscreen.currentDrops > Train.Cars[Train.DriverCar].Windscreen.RainDrops.Length / 4 && Train.Cars[Train.DriverCar].Windscreen.currentDrops < Train.Cars[Train.DriverCar].Windscreen.RainDrops.Length / 2) + else if (Train.Cars[Train.DriverCar].Windscreen.CurrentDrops > Train.Cars[Train.DriverCar].Windscreen.RainDrops.Length / 4 && Train.Cars[Train.DriverCar].Windscreen.CurrentDrops < Train.Cars[Train.DriverCar].Windscreen.RainDrops.Length / 2) { switch (Train.Cars[Train.DriverCar].Windscreen.Wipers.CurrentSpeed) { diff --git a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs index b634418d5..f3aca3f2c 100644 --- a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs +++ b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs @@ -1090,7 +1090,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr // brake case Instructions.BrakeMainReservoir: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.mainReservoir.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.MainReservoir.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -1102,7 +1102,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.mainReservoir.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.MainReservoir.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -1110,7 +1110,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr break; case Instructions.BrakeEqualizingReservoir: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.equalizingReservoir.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.EqualizingReservoir.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -1122,7 +1122,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.equalizingReservoir.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.EqualizingReservoir.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -1130,7 +1130,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr break; case Instructions.BrakeBrakePipe: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.brakePipe.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakePipe.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -1142,7 +1142,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.brakePipe.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakePipe.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -1150,7 +1150,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr break; case Instructions.BrakeBrakeCylinder: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.brakeCylinder.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakeCylinder.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -1162,7 +1162,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.brakeCylinder.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakeCylinder.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -1170,7 +1170,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr break; case Instructions.BrakeStraightAirPipe: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.straightAirPipe.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.StraightAirPipe.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -1182,7 +1182,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.straightAirPipe.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.StraightAirPipe.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } diff --git a/source/OpenBVE/Graphics/Renderers/Overlays.Debug.cs b/source/OpenBVE/Graphics/Renderers/Overlays.Debug.cs index 2ff90b1b0..5e5229de9 100644 --- a/source/OpenBVE/Graphics/Renderers/Overlays.Debug.cs +++ b/source/OpenBVE/Graphics/Renderers/Overlays.Debug.cs @@ -146,7 +146,7 @@ private void RenderDebugOverlays() mass += TrainManager.PlayerTrain.Cars[i].CurrentMass; } - string rainIntensity = TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Windscreen != null && TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Windscreen.legacyRainEvents ? "Legacy beacon based." : TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].FrontAxle.Follower.RainIntensity + "%"; + string rainIntensity = TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Windscreen != null && TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Windscreen.LegacyRainEvents ? "Legacy beacon based." : TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].FrontAxle.Follower.RainIntensity + "%"; double elevation = Program.Renderer.Camera.AbsolutePosition.Y + Program.CurrentRoute.Atmosphere.InitialElevation; double airTemperature = Program.CurrentRoute.Atmosphere.GetAirTemperature(elevation); double airPressure = Program.CurrentRoute.Atmosphere.GetAirPressure(elevation, airTemperature); @@ -318,8 +318,8 @@ private void RenderBrakeSystemDebug() heading[0] = true; } renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2(w, h), Color128.Black); - double p = TrainManager.PlayerTrain.Cars[i].CarBrake.brakePipe.CurrentPressure; - double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.brakePipe.NormalPressure; + double p = TrainManager.PlayerTrain.Cars[i].CarBrake.BrakePipe.CurrentPressure; + double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.BrakePipe.NormalPressure; renderer.Rectangle.Draw(null, new Vector2((float)x, (float)y), new Vector2(r * w, h), Color128.Yellow); } x += w + 8.0; @@ -332,8 +332,8 @@ private void RenderBrakeSystemDebug() heading[1] = true; } renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2(w, h), Color128.Black); - double p = TrainManager.PlayerTrain.Cars[i].CarBrake.auxiliaryReservoir.CurrentPressure; - double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.auxiliaryReservoir.MaximumPressure; + double p = TrainManager.PlayerTrain.Cars[i].CarBrake.AuxiliaryReservoir.CurrentPressure; + double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.AuxiliaryReservoir.MaximumPressure; renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2(r * w, h), Color128.Grey); } x += w + 8.0; @@ -346,13 +346,13 @@ private void RenderBrakeSystemDebug() } renderer.Rectangle.Draw(null, new Vector2((float) x, (float) y), new Vector2(w, h), Color128.Black); - double p = TrainManager.PlayerTrain.Cars[i].CarBrake.brakeCylinder.CurrentPressure; - double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.brakeCylinder.EmergencyMaximumPressure; + double p = TrainManager.PlayerTrain.Cars[i].CarBrake.BrakeCylinder.CurrentPressure; + double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.BrakeCylinder.EmergencyMaximumPressure; renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2(r * w, h), new Color128(0.75f, 0.5f, 0.25f, 1.0f)); } x += w + 8.0; // main reservoir - if (TrainManager.PlayerTrain.Cars[i].CarBrake.brakeType == BrakeType.Main) + if (TrainManager.PlayerTrain.Cars[i].CarBrake.BrakeType == BrakeType.Main) { if (!heading[3]) { @@ -360,13 +360,13 @@ private void RenderBrakeSystemDebug() heading[3] = true; } renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2(w, h), Color128.Black); - double p = TrainManager.PlayerTrain.Cars[i].CarBrake.mainReservoir.CurrentPressure; - double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.mainReservoir.MaximumPressure; + double p = TrainManager.PlayerTrain.Cars[i].CarBrake.MainReservoir.CurrentPressure; + double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.MainReservoir.MaximumPressure; renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2(r * w, h), Color128.Red); } x += w + 8.0; // equalizing reservoir - if (TrainManager.PlayerTrain.Cars[i].CarBrake.brakeType == BrakeType.Main) + if (TrainManager.PlayerTrain.Cars[i].CarBrake.BrakeType == BrakeType.Main) { if (!heading[4]) { @@ -374,13 +374,13 @@ private void RenderBrakeSystemDebug() heading[4] = true; } renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2(w, h), Color128.Black); - double p = TrainManager.PlayerTrain.Cars[i].CarBrake.equalizingReservoir.CurrentPressure; - double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.equalizingReservoir.NormalPressure; + double p = TrainManager.PlayerTrain.Cars[i].CarBrake.EqualizingReservoir.CurrentPressure; + double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.EqualizingReservoir.NormalPressure; renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2(r * w, h), new Color128(0.0f, 0.75f, 0.0f, 1.0f)); } x += w + 8.0; // straight air pipe - if (TrainManager.PlayerTrain.Cars[i].CarBrake is ElectromagneticStraightAirBrake & TrainManager.PlayerTrain.Cars[i].CarBrake.brakeType == BrakeType.Main) + if (TrainManager.PlayerTrain.Cars[i].CarBrake is ElectromagneticStraightAirBrake & TrainManager.PlayerTrain.Cars[i].CarBrake.BrakeType == BrakeType.Main) { if (!heading[5]) { @@ -388,8 +388,8 @@ private void RenderBrakeSystemDebug() heading[5] = true; } renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2((float)w, (float)h), Color128.Black); - double p = TrainManager.PlayerTrain.Cars[i].CarBrake.straightAirPipe.CurrentPressure; - double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.brakeCylinder.EmergencyMaximumPressure; + double p = TrainManager.PlayerTrain.Cars[i].CarBrake.StraightAirPipe.CurrentPressure; + double r = p / TrainManager.PlayerTrain.Cars[i].CarBrake.BrakeCylinder.EmergencyMaximumPressure; renderer.Rectangle.Draw(null, new Vector2(x, y), new Vector2(r * w, h), Color128.DeepSkyBlue); } y += h + 8.0; diff --git a/source/OpenBVE/System/Scripting.cs b/source/OpenBVE/System/Scripting.cs index 78e964973..4c9943fa8 100644 --- a/source/OpenBVE/System/Scripting.cs +++ b/source/OpenBVE/System/Scripting.cs @@ -245,7 +245,7 @@ public static double mainReservoir(TrainBase Train, int CarIndex) { return 0.0; } - return Train.Cars[CarIndex].CarBrake.mainReservoir.CurrentPressure; + return Train.Cars[CarIndex].CarBrake.MainReservoir.CurrentPressure; } /// Returns the brake pipe pressure of the selected car of the selected train @@ -259,7 +259,7 @@ public static double brakePipe(TrainBase Train, int CarIndex) { return 0.0; } - return Train.Cars[CarIndex].CarBrake.brakePipe.CurrentPressure; + return Train.Cars[CarIndex].CarBrake.BrakePipe.CurrentPressure; } /// Returns the brake cylinder pressure of the selected car of the selected train @@ -273,7 +273,7 @@ public static double brakeCylinder(TrainBase Train, int CarIndex) { return 0.0; } - return Train.Cars[CarIndex].CarBrake.brakeCylinder.CurrentPressure; + return Train.Cars[CarIndex].CarBrake.BrakeCylinder.CurrentPressure; } /// Returns the brake pipe pressure of the selected car of the selected train @@ -287,7 +287,7 @@ public static double straightAirPipe(TrainBase Train, int CarIndex) { return 0.0; } - return Train.Cars[CarIndex].CarBrake.straightAirPipe.CurrentPressure; + return Train.Cars[CarIndex].CarBrake.StraightAirPipe.CurrentPressure; } /// Returns the doors state of the selected train diff --git a/source/Plugins/Train.OpenBve/Panel/Panel2CfgParser.cs b/source/Plugins/Train.OpenBve/Panel/Panel2CfgParser.cs index f28a54cfc..0e58288ec 100644 --- a/source/Plugins/Train.OpenBve/Panel/Panel2CfgParser.cs +++ b/source/Plugins/Train.OpenBve/Panel/Panel2CfgParser.cs @@ -324,7 +324,7 @@ internal void ParsePanel2Config(string PanelFile, string TrainPath, CarBase Car) int w = tday.Width; int h = tday.Height; int j = CreateElement(ref Car.CarSections[0].Groups[GroupIndex], LocationX, LocationY, w, h, new Vector2(0.5, 0.5), Layer * StackDistance, PanelResolution, PanelBottom, PanelCenter, Car.Driver, tday, tnight, Color32.White); - string f = GetStackLanguageFromSubject(Car.baseTrain, Subject, Section + " in " + FileName); + string f = GetStackLanguageFromSubject(Car.BaseTrain, Subject, Section + " in " + FileName); try { if (!string.IsNullOrEmpty(Function)) @@ -532,7 +532,7 @@ internal void ParsePanel2Config(string PanelFile, string TrainPath, CarBase Car) f = Smoothed ? "time 60 mod" : "time floor"; break; default: - f = GetStackLanguageFromSubject(Car.baseTrain, Subject, Section + " in " + FileName); + f = GetStackLanguageFromSubject(Car.BaseTrain, Subject, Section + " in " + FileName); break; } @@ -692,7 +692,7 @@ internal void ParsePanel2Config(string PanelFile, string TrainPath, CarBase Car) Plugin.currentHost.AddMessage(MessageType.Error, false, "Maximum value must be greater than minimum value " + Section + " in " + FileName); break; } - string tf = GetInfixFunction(Car.baseTrain, Subject, Minimum, Maximum, Width, tday.Width, Section + " in " + FileName); + string tf = GetInfixFunction(Car.BaseTrain, Subject, Minimum, Maximum, Width, tday.Width, Section + " in " + FileName); if (!string.IsNullOrEmpty(tf) || !string.IsNullOrEmpty(Function)) { Car.CarSections[0].Groups[GroupIndex].Elements[j].TextureShiftXDirection = Direction; @@ -813,14 +813,14 @@ internal void ParsePanel2Config(string PanelFile, string TrainPath, CarBase Car) switch (Subject) { case "power": - if (Car.baseTrain.Handles.Power.MaximumNotch > numFrames) + if (Car.BaseTrain.Handles.Power.MaximumNotch > numFrames) { - numFrames = Car.baseTrain.Handles.Power.MaximumNotch; + numFrames = Car.BaseTrain.Handles.Power.MaximumNotch; } break; case "brake": - int b = Car.baseTrain.Handles.Brake.MaximumNotch + 2; - if (Car.baseTrain.Handles.HasHoldBrake) + int b = Car.BaseTrain.Handles.Brake.MaximumNotch + 2; + if (Car.BaseTrain.Handles.HasHoldBrake) { b++; } @@ -878,7 +878,7 @@ internal void ParsePanel2Config(string PanelFile, string TrainPath, CarBase Car) int l = CreateElement(ref Car.CarSections[0].Groups[GroupIndex], LocationX, LocationY, wday, Interval, new Vector2(0.5, 0.5), Layer * StackDistance, PanelResolution, PanelBottom, PanelCenter, Car.Driver, tday[k], tnight[k], Color32.White, k != 0); if (k == 0) j = l; } - string f = GetStackLanguageFromSubject(Car.baseTrain, Subject, Section + " in " + FileName); + string f = GetStackLanguageFromSubject(Car.BaseTrain, Subject, Section + " in " + FileName); try { if (!string.IsNullOrEmpty(Function)) @@ -1070,7 +1070,7 @@ internal void ParsePanel2Config(string PanelFile, string TrainPath, CarBase Car) new Vector3(x3, y3, z3), new Vector3(cx, cy, cz) }; - string f = GetStackLanguageFromSubject(Car.baseTrain, Subject, Section + " in " + FileName); + string f = GetStackLanguageFromSubject(Car.BaseTrain, Subject, Section + " in " + FileName); double a0 = (InitialAngle * Maximum - LastAngle * Minimum) / (Maximum - Minimum); double a1 = (LastAngle - InitialAngle) / (Maximum - Minimum); if (Step == 1.0) { diff --git a/source/Plugins/Train.OpenBve/Panel/PanelCfgParser.cs b/source/Plugins/Train.OpenBve/Panel/PanelCfgParser.cs index 9aa22f335..c26c36f2e 100644 --- a/source/Plugins/Train.OpenBve/Panel/PanelCfgParser.cs +++ b/source/Plugins/Train.OpenBve/Panel/PanelCfgParser.cs @@ -1375,25 +1375,25 @@ internal void ParsePanelConfig(string TrainPath, System.Text.Encoding Encoding, } } - if (Car.baseTrain.Handles.Brake is AirBrakeHandle) + if (Car.BaseTrain.Handles.Brake is AirBrakeHandle) { - int maxpow = Car.baseTrain.Handles.Power.MaximumNotch; + int maxpow = Car.BaseTrain.Handles.Power.MaximumNotch; int em = maxpow + 3; Car.CarSections[0].Groups[0].Elements[k].StateFunction = new FunctionScript(Plugin.currentHost, "emergencyBrake " + em.ToString(Culture) + " brakeNotch 0 > " + maxpow.ToString(Culture) + " BrakeNotch + " + maxpow.ToString(Culture) + " powerNotch - ? ?", false); } else { - if (Car.baseTrain.Handles.HasHoldBrake) + if (Car.BaseTrain.Handles.HasHoldBrake) { - int em = Car.baseTrain.Handles.Power.MaximumNotch + 2 + Car.baseTrain.Handles.Brake.MaximumNotch; - int maxpow = Car.baseTrain.Handles.Power.MaximumNotch; + int em = Car.BaseTrain.Handles.Power.MaximumNotch + 2 + Car.BaseTrain.Handles.Brake.MaximumNotch; + int maxpow = Car.BaseTrain.Handles.Power.MaximumNotch; int maxpowp1 = maxpow + 1; Car.CarSections[0].Groups[0].Elements[k].StateFunction = new FunctionScript(Plugin.currentHost, "emergencyBrake " + em.ToString(Culture) + " holdBrake " + maxpowp1.ToString(Culture) + " brakeNotch 0 > brakeNotch " + maxpowp1.ToString(Culture) + " + " + maxpow.ToString(Culture) + " powerNotch - ? ? ?", false); } else { - int em = Car.baseTrain.Handles.Power.MaximumNotch + 1 + Car.baseTrain.Handles.Brake.MaximumNotch; - int maxpow = Car.baseTrain.Handles.Power.MaximumNotch; + int em = Car.BaseTrain.Handles.Power.MaximumNotch + 1 + Car.BaseTrain.Handles.Brake.MaximumNotch; + int maxpow = Car.BaseTrain.Handles.Power.MaximumNotch; Car.CarSections[0].Groups[0].Elements[k].StateFunction = new FunctionScript(Plugin.currentHost, "emergencyBrake " + em.ToString(Culture) + " brakeNotch 0 > brakeNotch " + maxpow.ToString(Culture) + " + " + maxpow.ToString(Culture) + " powerNotch - ? ?", false); } } diff --git a/source/Plugins/Train.OpenBve/Sound/SoundCfg.Bve2.cs b/source/Plugins/Train.OpenBve/Sound/SoundCfg.Bve2.cs index 7c0338254..c005cc4c8 100644 --- a/source/Plugins/Train.OpenBve/Sound/SoundCfg.Bve2.cs +++ b/source/Plugins/Train.OpenBve/Sound/SoundCfg.Bve2.cs @@ -57,11 +57,11 @@ internal void Parse(TrainBase train) train.Cars[i].CarBrake.Air = new CarSound(Plugin.currentHost, train.TrainFolder, "Air.wav", SoundCfgParser.smallRadius, center); train.Cars[i].CarBrake.AirHigh = new CarSound(Plugin.currentHost, train.TrainFolder, "AirHigh.wav", SoundCfgParser.smallRadius, center); train.Cars[i].CarBrake.AirZero = new CarSound(Plugin.currentHost, train.TrainFolder, "AirZero.wav", SoundCfgParser.smallRadius, center); - if (train.Cars[i].CarBrake.brakeType == BrakeType.Main) + if (train.Cars[i].CarBrake.BrakeType == BrakeType.Main) { - train.Cars[i].CarBrake.airCompressor.EndSound = new CarSound(Plugin.currentHost, train.TrainFolder, "CpEnd.wav", SoundCfgParser.mediumRadius, center); - train.Cars[i].CarBrake.airCompressor.LoopSound = new CarSound(Plugin.currentHost, train.TrainFolder, "CpLoop.wav", SoundCfgParser.mediumRadius, center); - train.Cars[i].CarBrake.airCompressor.StartSound = new CarSound(Plugin.currentHost, train.TrainFolder, "CpStart.wav", SoundCfgParser.mediumRadius, center); + train.Cars[i].CarBrake.AirCompressor.EndSound = new CarSound(Plugin.currentHost, train.TrainFolder, "CpEnd.wav", SoundCfgParser.mediumRadius, center); + train.Cars[i].CarBrake.AirCompressor.LoopSound = new CarSound(Plugin.currentHost, train.TrainFolder, "CpLoop.wav", SoundCfgParser.mediumRadius, center); + train.Cars[i].CarBrake.AirCompressor.StartSound = new CarSound(Plugin.currentHost, train.TrainFolder, "CpStart.wav", SoundCfgParser.mediumRadius, center); } train.Cars[i].Doors[0].CloseSound = new CarSound(Plugin.currentHost, train.TrainFolder, "DoorClsL.wav", SoundCfgParser.smallRadius, left); train.Cars[i].Doors[1].CloseSound = new CarSound(Plugin.currentHost, train.TrainFolder, "DoorClsR.wav", SoundCfgParser.smallRadius, right); diff --git a/source/Plugins/Train.OpenBve/Sound/SoundCfg.Bve4.cs b/source/Plugins/Train.OpenBve/Sound/SoundCfg.Bve4.cs index 7b60bcb78..10412e10e 100644 --- a/source/Plugins/Train.OpenBve/Sound/SoundCfg.Bve4.cs +++ b/source/Plugins/Train.OpenBve/Sound/SoundCfg.Bve4.cs @@ -330,18 +330,18 @@ internal void Parse(string FileName, string trainFolder, TrainBase train) string b = Lines[i].Substring(j + 1).TrimStart(); for (int c = 0; c < train.Cars.Length; c++) { - if (train.Cars[c].CarBrake.brakeType == BrakeType.Main) + if (train.Cars[c].CarBrake.BrakeType == BrakeType.Main) { switch (a.ToLowerInvariant()) { case "attack": - train.Cars[c].CarBrake.airCompressor.StartSound = new CarSound(Plugin.currentHost, trainFolder, FileName, i, b, SoundCfgParser.mediumRadius, center); + train.Cars[c].CarBrake.AirCompressor.StartSound = new CarSound(Plugin.currentHost, trainFolder, FileName, i, b, SoundCfgParser.mediumRadius, center); break; case "loop": - train.Cars[c].CarBrake.airCompressor.LoopSound = new CarSound(Plugin.currentHost, trainFolder, FileName, i, b, SoundCfgParser.mediumRadius, center); + train.Cars[c].CarBrake.AirCompressor.LoopSound = new CarSound(Plugin.currentHost, trainFolder, FileName, i, b, SoundCfgParser.mediumRadius, center); break; case "release": - train.Cars[c].CarBrake.airCompressor.EndSound = new CarSound(Plugin.currentHost, trainFolder, FileName, i, b, SoundCfgParser.mediumRadius, center); + train.Cars[c].CarBrake.AirCompressor.EndSound = new CarSound(Plugin.currentHost, trainFolder, FileName, i, b, SoundCfgParser.mediumRadius, center); break; default: Plugin.currentHost.AddMessage(MessageType.Warning, false, "Unsupported key " + a + " encountered at line " + (i + 1).ToString(Culture) + " in file " + FileName); diff --git a/source/Plugins/Train.OpenBve/Sound/SoundCfg.Xml.cs b/source/Plugins/Train.OpenBve/Sound/SoundCfg.Xml.cs index 43fdd29cb..66e07417b 100644 --- a/source/Plugins/Train.OpenBve/Sound/SoundCfg.Xml.cs +++ b/source/Plugins/Train.OpenBve/Sound/SoundCfg.Xml.cs @@ -214,7 +214,7 @@ internal void Parse(string fileName, ref TrainBase Train, ref CarBase car, bool Plugin.currentHost.AddMessage(MessageType.Error, false, "An empty list of compressor sounds was defined in in XML file " + fileName); break; } - if (car.CarBrake.brakeType != BrakeType.Main) + if (car.CarBrake.BrakeType != BrakeType.Main) { break; } @@ -225,17 +225,17 @@ internal void Parse(string fileName, ref TrainBase Train, ref CarBase car, bool case "attack": case "start": //Compressor starting sound - ParseNode(cc, out car.CarBrake.airCompressor.StartSound, center, SoundCfgParser.mediumRadius); + ParseNode(cc, out car.CarBrake.AirCompressor.StartSound, center, SoundCfgParser.mediumRadius); break; case "loop": //Compressor loop sound - ParseNode(cc, out car.CarBrake.airCompressor.LoopSound, center, SoundCfgParser.mediumRadius); + ParseNode(cc, out car.CarBrake.AirCompressor.LoopSound, center, SoundCfgParser.mediumRadius); break; case "release": case "stop": case "end": //Compressor end sound - ParseNode(cc, out car.CarBrake.airCompressor.EndSound, center, SoundCfgParser.mediumRadius); + ParseNode(cc, out car.CarBrake.AirCompressor.EndSound, center, SoundCfgParser.mediumRadius); break; default: Plugin.currentHost.AddMessage(MessageType.Error, false, "Declaration " + cc.Name + " is unsupported in a " + c.Name + " node."); diff --git a/source/Plugins/Train.OpenBve/Train/BVE/TrainDatParser.cs b/source/Plugins/Train.OpenBve/Train/BVE/TrainDatParser.cs index a308c480d..0e6ce30b6 100644 --- a/source/Plugins/Train.OpenBve/Train/BVE/TrainDatParser.cs +++ b/source/Plugins/Train.OpenBve/Train/BVE/TrainDatParser.cs @@ -1225,26 +1225,26 @@ internal void Parse(string FileName, Encoding Encoding, TrainBase Train) { if (Train.Cars[i].Specs.IsMotorCar || Train.IsPlayerTrain && i == Train.DriverCar || trainBrakeType == BrakeSystemType.ElectricCommandBrake) { - Train.Cars[i].CarBrake.brakeType = BrakeType.Main; + Train.Cars[i].CarBrake.BrakeType = BrakeType.Main; } else { - Train.Cars[i].CarBrake.brakeType = BrakeType.Auxiliary; + Train.Cars[i].CarBrake.BrakeType = BrakeType.Auxiliary; } - Train.Cars[i].CarBrake.mainReservoir = new MainReservoir(MainReservoirMinimumPressure, MainReservoirMaximumPressure, 0.01, (trainBrakeType == BrakeSystemType.AutomaticAirBrake ? 0.25 : 0.075) / Cars); - Train.Cars[i].CarBrake.airCompressor = new Compressor(5000.0, Train.Cars[i].CarBrake.mainReservoir, Train.Cars[i]); - Train.Cars[i].CarBrake.equalizingReservoir = new EqualizingReservoir(50000.0, 250000.0, 200000.0); - Train.Cars[i].CarBrake.equalizingReservoir.NormalPressure = 1.005 * OperatingPressure; + Train.Cars[i].CarBrake.MainReservoir = new MainReservoir(MainReservoirMinimumPressure, MainReservoirMaximumPressure, 0.01, (trainBrakeType == BrakeSystemType.AutomaticAirBrake ? 0.25 : 0.075) / Cars); + Train.Cars[i].CarBrake.AirCompressor = new Compressor(5000.0, Train.Cars[i].CarBrake.MainReservoir, Train.Cars[i]); + Train.Cars[i].CarBrake.EqualizingReservoir = new EqualizingReservoir(50000.0, 250000.0, 200000.0); + Train.Cars[i].CarBrake.EqualizingReservoir.NormalPressure = 1.005 * OperatingPressure; - Train.Cars[i].CarBrake.brakePipe = new BrakePipe(OperatingPressure, 10000000.0, 1500000.0, 5000000.0, trainBrakeType == BrakeSystemType.ElectricCommandBrake); + Train.Cars[i].CarBrake.BrakePipe = new BrakePipe(OperatingPressure, 10000000.0, 1500000.0, 5000000.0, trainBrakeType == BrakeSystemType.ElectricCommandBrake); { double r = 200000.0 / BrakeCylinderEmergencyMaximumPressure - 1.0; if (r < 0.1) r = 0.1; if (r > 1.0) r = 1.0; - Train.Cars[i].CarBrake.auxiliaryReservoir = new AuxiliaryReservoir(0.975 * OperatingPressure, 200000.0, 0.5, r); + Train.Cars[i].CarBrake.AuxiliaryReservoir = new AuxiliaryReservoir(0.975 * OperatingPressure, 200000.0, 0.5, r); } - Train.Cars[i].CarBrake.brakeCylinder = new BrakeCylinder(BrakeCylinderServiceMaximumPressure, BrakeCylinderEmergencyMaximumPressure, trainBrakeType == BrakeSystemType.AutomaticAirBrake ? BrakeCylinderUp : 0.3 * BrakeCylinderUp, BrakeCylinderUp, BrakeCylinderDown); - Train.Cars[i].CarBrake.straightAirPipe = new StraightAirPipe(300000.0, 400000.0, 200000.0); + Train.Cars[i].CarBrake.BrakeCylinder = new BrakeCylinder(BrakeCylinderServiceMaximumPressure, BrakeCylinderEmergencyMaximumPressure, trainBrakeType == BrakeSystemType.AutomaticAirBrake ? BrakeCylinderUp : 0.3 * BrakeCylinderUp, BrakeCylinderUp, BrakeCylinderDown); + Train.Cars[i].CarBrake.StraightAirPipe = new StraightAirPipe(300000.0, 400000.0, 200000.0); Train.Cars[i].CarBrake.JerkUp = JerkBrakeUp; Train.Cars[i].CarBrake.JerkDown = JerkBrakeDown; } @@ -1266,10 +1266,10 @@ internal void Parse(string FileName, Encoding Encoding, TrainBase Train) { // starting mode case TrainStartMode.ServiceBrakesAts: for (int i = 0; i < Cars; i++) { - Train.Cars[i].CarBrake.brakeCylinder.CurrentPressure = Train.Cars[i].CarBrake.brakeCylinder.ServiceMaximumPressure; - Train.Cars[i].CarBrake.brakePipe.CurrentPressure = Train.Cars[i].CarBrake.brakePipe.NormalPressure; - Train.Cars[i].CarBrake.straightAirPipe.CurrentPressure = Train.Cars[i].CarBrake.brakeCylinder.ServiceMaximumPressure; - Train.Cars[i].CarBrake.equalizingReservoir.CurrentPressure = Train.Cars[i].CarBrake.equalizingReservoir.NormalPressure; + Train.Cars[i].CarBrake.BrakeCylinder.CurrentPressure = Train.Cars[i].CarBrake.BrakeCylinder.ServiceMaximumPressure; + Train.Cars[i].CarBrake.BrakePipe.CurrentPressure = Train.Cars[i].CarBrake.BrakePipe.NormalPressure; + Train.Cars[i].CarBrake.StraightAirPipe.CurrentPressure = Train.Cars[i].CarBrake.BrakeCylinder.ServiceMaximumPressure; + Train.Cars[i].CarBrake.EqualizingReservoir.CurrentPressure = Train.Cars[i].CarBrake.EqualizingReservoir.NormalPressure; } if (trainBrakeType == BrakeSystemType.AutomaticAirBrake) @@ -1291,10 +1291,10 @@ internal void Parse(string FileName, Encoding Encoding, TrainBase Train) { break; case TrainStartMode.EmergencyBrakesAts: for (int i = 0; i < Cars; i++) { - Train.Cars[i].CarBrake.brakeCylinder.CurrentPressure = Train.Cars[i].CarBrake.brakeCylinder.EmergencyMaximumPressure; - Train.Cars[i].CarBrake.brakePipe.CurrentPressure = 0.0; - Train.Cars[i].CarBrake.straightAirPipe.CurrentPressure = 0.0; - Train.Cars[i].CarBrake.equalizingReservoir.CurrentPressure = 0.0; + Train.Cars[i].CarBrake.BrakeCylinder.CurrentPressure = Train.Cars[i].CarBrake.BrakeCylinder.EmergencyMaximumPressure; + Train.Cars[i].CarBrake.BrakePipe.CurrentPressure = 0.0; + Train.Cars[i].CarBrake.StraightAirPipe.CurrentPressure = 0.0; + Train.Cars[i].CarBrake.EqualizingReservoir.CurrentPressure = 0.0; } if (trainBrakeType == BrakeSystemType.AutomaticAirBrake) @@ -1314,10 +1314,10 @@ internal void Parse(string FileName, Encoding Encoding, TrainBase Train) { break; default: for (int i = 0; i < Cars; i++) { - Train.Cars[i].CarBrake.brakeCylinder.CurrentPressure = Train.Cars[i].CarBrake.brakeCylinder.EmergencyMaximumPressure; - Train.Cars[i].CarBrake.brakePipe.CurrentPressure = 0.0; - Train.Cars[i].CarBrake.straightAirPipe.CurrentPressure = 0.0; - Train.Cars[i].CarBrake.equalizingReservoir.CurrentPressure = 0.0; + Train.Cars[i].CarBrake.BrakeCylinder.CurrentPressure = Train.Cars[i].CarBrake.BrakeCylinder.EmergencyMaximumPressure; + Train.Cars[i].CarBrake.BrakePipe.CurrentPressure = 0.0; + Train.Cars[i].CarBrake.StraightAirPipe.CurrentPressure = 0.0; + Train.Cars[i].CarBrake.EqualizingReservoir.CurrentPressure = 0.0; } if (trainBrakeType == BrakeSystemType.AutomaticAirBrake) diff --git a/source/Plugins/Train.OpenBve/Train/XML/TrainXmlParser.BrakeNode.cs b/source/Plugins/Train.OpenBve/Train/XML/TrainXmlParser.BrakeNode.cs index d88c1a910..9f77935b6 100644 --- a/source/Plugins/Train.OpenBve/Train/XML/TrainXmlParser.BrakeNode.cs +++ b/source/Plugins/Train.OpenBve/Train/XML/TrainXmlParser.BrakeNode.cs @@ -24,7 +24,7 @@ private void ParseBrakeNode(XmlNode Node, string fileName, int Car, ref TrainBas switch (c.Name.ToLowerInvariant()) { case "compressor": - Train.Cars[Car].CarBrake.brakeType = BrakeType.Main; //We have a compressor so must be a main brake type + Train.Cars[Car].CarBrake.BrakeType = BrakeType.Main; //We have a compressor so must be a main brake type if (c.ChildNodes.OfType().Any()) { foreach (XmlNode cc in c.ChildNodes) @@ -244,20 +244,20 @@ private void ParseBrakeNode(XmlNode Node, string fileName, int Car, ref TrainBas } } - Train.Cars[Car].CarBrake.mainReservoir = new MainReservoir(compressorMinimumPressure, compressorMaximumPressure, 0.01, (Train.Handles.Brake is AirBrakeHandle ? 0.25 : 0.075) / Train.Cars.Length); - Train.Cars[Car].CarBrake.airCompressor = new Compressor(compressorRate, Train.Cars[Car].CarBrake.mainReservoir, Train.Cars[Car]); - Train.Cars[Car].CarBrake.equalizingReservoir = new EqualizingReservoir(equalizingReservoirServiceRate, equalizingReservoirEmergencyRate, equalizingReservoirChargeRate); - Train.Cars[Car].CarBrake.equalizingReservoir.NormalPressure = 1.005 * brakePipeNormalPressure; + Train.Cars[Car].CarBrake.MainReservoir = new MainReservoir(compressorMinimumPressure, compressorMaximumPressure, 0.01, (Train.Handles.Brake is AirBrakeHandle ? 0.25 : 0.075) / Train.Cars.Length); + Train.Cars[Car].CarBrake.AirCompressor = new Compressor(compressorRate, Train.Cars[Car].CarBrake.MainReservoir, Train.Cars[Car]); + Train.Cars[Car].CarBrake.EqualizingReservoir = new EqualizingReservoir(equalizingReservoirServiceRate, equalizingReservoirEmergencyRate, equalizingReservoirChargeRate); + Train.Cars[Car].CarBrake.EqualizingReservoir.NormalPressure = 1.005 * brakePipeNormalPressure; - Train.Cars[Car].CarBrake.brakePipe = new BrakePipe(brakePipeNormalPressure, brakePipeChargeRate, brakePipeServiceRate, brakePipeEmergencyRate, Train.Cars[0].CarBrake is ElectricCommandBrake); + Train.Cars[Car].CarBrake.BrakePipe = new BrakePipe(brakePipeNormalPressure, brakePipeChargeRate, brakePipeServiceRate, brakePipeEmergencyRate, Train.Cars[0].CarBrake is ElectricCommandBrake); { double r = 200000.0 / brakeCylinderEmergencyMaximumPressure - 1.0; if (r < 0.1) r = 0.1; if (r > 1.0) r = 1.0; - Train.Cars[Car].CarBrake.auxiliaryReservoir = new AuxiliaryReservoir(0.975 * brakePipeNormalPressure, auxiliaryReservoirChargeRate, 0.5, r); + Train.Cars[Car].CarBrake.AuxiliaryReservoir = new AuxiliaryReservoir(0.975 * brakePipeNormalPressure, auxiliaryReservoirChargeRate, 0.5, r); } - Train.Cars[Car].CarBrake.brakeCylinder = new BrakeCylinder(brakeCylinderServiceMaximumPressure, brakeCylinderEmergencyMaximumPressure, Train.Handles.Brake is AirBrakeHandle ? brakeCylinderEmergencyRate : 0.3 * brakeCylinderEmergencyRate, brakeCylinderEmergencyRate, brakeCylinderReleaseRate); - Train.Cars[Car].CarBrake.straightAirPipe = new StraightAirPipe(straightAirPipeServiceRate, straightAirPipeEmergencyRate, straightAirPipeReleaseRate); + Train.Cars[Car].CarBrake.BrakeCylinder = new BrakeCylinder(brakeCylinderServiceMaximumPressure, brakeCylinderEmergencyMaximumPressure, Train.Handles.Brake is AirBrakeHandle ? brakeCylinderEmergencyRate : 0.3 * brakeCylinderEmergencyRate, brakeCylinderEmergencyRate, brakeCylinderReleaseRate); + Train.Cars[Car].CarBrake.StraightAirPipe = new StraightAirPipe(straightAirPipeServiceRate, straightAirPipeEmergencyRate, straightAirPipeReleaseRate); } } } diff --git a/source/Plugins/Train.OpenBve/Train/XML/TrainXmlParser.CarNode.cs b/source/Plugins/Train.OpenBve/Train/XML/TrainXmlParser.CarNode.cs index f32c962a6..35355bf0d 100644 --- a/source/Plugins/Train.OpenBve/Train/XML/TrainXmlParser.CarNode.cs +++ b/source/Plugins/Train.OpenBve/Train/XML/TrainXmlParser.CarNode.cs @@ -85,7 +85,7 @@ private void ParseCarNode(XmlNode Node, string fileName, int Car, ref TrainBase } break; case "brake": - Train.Cars[Car].CarBrake.brakeType = BrakeType.Auxiliary; + Train.Cars[Car].CarBrake.BrakeType = BrakeType.Auxiliary; if (c.ChildNodes.OfType().Any()) { ParseBrakeNode(c, fileName, Car, ref Train); diff --git a/source/RouteViewer/FunctionScripts.cs b/source/RouteViewer/FunctionScripts.cs index 843caac17..d8f41c11a 100644 --- a/source/RouteViewer/FunctionScripts.cs +++ b/source/RouteViewer/FunctionScripts.cs @@ -920,7 +920,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager // brake case Instructions.BrakeMainReservoir: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.mainReservoir.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.MainReservoir.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -932,7 +932,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.mainReservoir.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.MainReservoir.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -940,7 +940,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager break; case Instructions.BrakeEqualizingReservoir: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.equalizingReservoir.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.EqualizingReservoir.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -952,7 +952,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.equalizingReservoir.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.EqualizingReservoir.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -960,7 +960,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager break; case Instructions.BrakeBrakePipe: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.brakePipe.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakePipe.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -972,7 +972,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.brakePipe.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakePipe.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -980,7 +980,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager break; case Instructions.BrakeBrakeCylinder: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.brakeCylinder.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakeCylinder.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -992,7 +992,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.brakeCylinder.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakeCylinder.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } @@ -1000,7 +1000,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager break; case Instructions.BrakeStraightAirPipe: if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.straightAirPipe.CurrentPressure; + Function.Stack[s] = Train.Cars[CarIndex].CarBrake.StraightAirPipe.CurrentPressure; } else { Function.Stack[s] = 0.0; } @@ -1012,7 +1012,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager int j = (int)Math.Round(Function.Stack[s - 1]); if (j < 0) j += Train.Cars.Length; if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.straightAirPipe.CurrentPressure; + Function.Stack[s - 1] = Train.Cars[j].CarBrake.StraightAirPipe.CurrentPressure; } else { Function.Stack[s - 1] = 0.0; } diff --git a/source/TrainManager/Brake/AirBrake/AutomaticAirBrake.cs b/source/TrainManager/Brake/AirBrake/AutomaticAirBrake.cs index b86f984bb..72ce68627 100644 --- a/source/TrainManager/Brake/AirBrake/AutomaticAirBrake.cs +++ b/source/TrainManager/Brake/AirBrake/AutomaticAirBrake.cs @@ -6,30 +6,30 @@ namespace TrainManager.BrakeSystems { public class AutomaticAirBrake : CarBrake { - public AutomaticAirBrake(EletropneumaticBrakeType type, CarBase car, double BrakeControlSpeed, double MotorDeceleration, AccelerationCurve[] DecelerationCurves) : base(car) + public AutomaticAirBrake(EletropneumaticBrakeType type, CarBase car, double brakeControlSpeed, double motorDeceleration, AccelerationCurve[] decelerationCurves) : base(car) { - electropneumaticBrakeType = type; - brakeControlSpeed = BrakeControlSpeed; - motorDeceleration = MotorDeceleration; - decelerationCurves = DecelerationCurves; + ElectropneumaticBrakeType = type; + BrakeControlSpeed = brakeControlSpeed; + MotorDeceleration = motorDeceleration; + DecelerationCurves = decelerationCurves; } - public override void Update(double TimeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double deceleration) + public override void Update(double timeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double deceleration) { - airSound = null; - if (Car.baseTrain.Handles.EmergencyBrake.Actual) + AirSound = null; + if (Car.BaseTrain.Handles.EmergencyBrake.Actual) { - if (brakeType == BrakeType.Main) + if (BrakeType == BrakeType.Main) { - double r = equalizingReservoir.EmergencyRate; - double d = equalizingReservoir.CurrentPressure; - double m = equalizingReservoir.NormalPressure; - r = GetRate(d / m, r * TimeElapsed); - if (r > equalizingReservoir.CurrentPressure) + double r = EqualizingReservoir.EmergencyRate; + double d = EqualizingReservoir.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; + r = GetRate(d / m, r * timeElapsed); + if (r > EqualizingReservoir.CurrentPressure) { - r = equalizingReservoir.CurrentPressure; + r = EqualizingReservoir.CurrentPressure; } - equalizingReservoir.CurrentPressure -= r; + EqualizingReservoir.CurrentPressure -= r; } } //First update the main reservoir pressure from the equalizing reservoir @@ -38,99 +38,99 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan { case AirBrakeHandleState.Service: { - double r = equalizingReservoir.ServiceRate; //50000 - double d = equalizingReservoir.CurrentPressure; - double m = equalizingReservoir.NormalPressure; //1.05 * max service pressure from train.dat in pascals - r = GetRate(d / m, r * TimeElapsed); - if (r > equalizingReservoir.CurrentPressure) + double r = EqualizingReservoir.ServiceRate; //50000 + double d = EqualizingReservoir.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; //1.05 * max service pressure from train.dat in pascals + r = GetRate(d / m, r * timeElapsed); + if (r > EqualizingReservoir.CurrentPressure) { - r = equalizingReservoir.CurrentPressure; + r = EqualizingReservoir.CurrentPressure; } - equalizingReservoir.CurrentPressure -= r; + EqualizingReservoir.CurrentPressure -= r; break; } case AirBrakeHandleState.Release: { - double r = equalizingReservoir.ChargeRate; - double d = equalizingReservoir.NormalPressure - equalizingReservoir.CurrentPressure; - double m = equalizingReservoir.NormalPressure; - r = GetRate(d / m, r * TimeElapsed); + double r = EqualizingReservoir.ChargeRate; + double d = EqualizingReservoir.NormalPressure - EqualizingReservoir.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; + r = GetRate(d / m, r * timeElapsed); if (r > d) { r = d; } - d = mainReservoir.CurrentPressure - equalizingReservoir.CurrentPressure; + d = MainReservoir.CurrentPressure - EqualizingReservoir.CurrentPressure; if (r > d) { r = d; } - double f = mainReservoir.EqualizingReservoirCoefficient; - double s = r * f * TimeElapsed; - if (s > mainReservoir.CurrentPressure) + double f = MainReservoir.EqualizingReservoirCoefficient; + double s = r * f * timeElapsed; + if (s > MainReservoir.CurrentPressure) { - r *= mainReservoir.CurrentPressure / s; - s = mainReservoir.CurrentPressure; + r *= MainReservoir.CurrentPressure / s; + s = MainReservoir.CurrentPressure; } - equalizingReservoir.CurrentPressure += 0.5 * r; - mainReservoir.CurrentPressure -= 0.5 * s; + EqualizingReservoir.CurrentPressure += 0.5 * r; + MainReservoir.CurrentPressure -= 0.5 * s; break; } } //Fill the brake pipe from the main reservoir - if (brakeType == BrakeType.Main) + if (BrakeType == BrakeType.Main) { - if (brakePipe.CurrentPressure > equalizingReservoir.CurrentPressure + Tolerance) + if (BrakePipe.CurrentPressure > EqualizingReservoir.CurrentPressure + Tolerance) { // brake pipe exhaust valve - double r = Car.baseTrain.Handles.EmergencyBrake.Actual ? brakePipe.EmergencyRate : brakePipe.ServiceRate; - double d = brakePipe.CurrentPressure - equalizingReservoir.CurrentPressure; - double m = equalizingReservoir.NormalPressure; - r = (0.5 + 1.5 * d / m) * r * TimeElapsed; + double r = Car.BaseTrain.Handles.EmergencyBrake.Actual ? BrakePipe.EmergencyRate : BrakePipe.ServiceRate; + double d = BrakePipe.CurrentPressure - EqualizingReservoir.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; + r = (0.5 + 1.5 * d / m) * r * timeElapsed; if (r > d) r = d; - brakePipe.CurrentPressure -= r; + BrakePipe.CurrentPressure -= r; } - else if (brakePipe.CurrentPressure + Tolerance < equalizingReservoir.CurrentPressure) + else if (BrakePipe.CurrentPressure + Tolerance < EqualizingReservoir.CurrentPressure) { // fill brake pipe from main reservoir - double r = brakePipe.ChargeRate; - double d = equalizingReservoir.CurrentPressure - brakePipe.CurrentPressure; - double m = equalizingReservoir.NormalPressure; - r = (0.5 + 1.5 * d / m) * r * TimeElapsed; + double r = BrakePipe.ChargeRate; + double d = EqualizingReservoir.CurrentPressure - BrakePipe.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; + r = (0.5 + 1.5 * d / m) * r * timeElapsed; if (r > d) r = d; - d = brakePipe.NormalPressure - brakePipe.CurrentPressure; + d = BrakePipe.NormalPressure - BrakePipe.CurrentPressure; if (r > d) r = d; - double f = mainReservoir.BrakePipeCoefficient; + double f = MainReservoir.BrakePipeCoefficient; double s = r * f; - if (s > mainReservoir.CurrentPressure) + if (s > MainReservoir.CurrentPressure) { - r *= mainReservoir.CurrentPressure / s; - s = mainReservoir.CurrentPressure; + r *= MainReservoir.CurrentPressure / s; + s = MainReservoir.CurrentPressure; } - brakePipe.CurrentPressure += 0.5 * r; - mainReservoir.CurrentPressure -= 0.5 * s; + BrakePipe.CurrentPressure += 0.5 * r; + MainReservoir.CurrentPressure -= 0.5 * s; } } - if (brakePipe.CurrentPressure + Tolerance < auxiliaryReservoir.CurrentPressure) + if (BrakePipe.CurrentPressure + Tolerance < AuxiliaryReservoir.CurrentPressure) { - if (auxiliaryReservoir.CurrentPressure + Tolerance < brakeCylinder.CurrentPressure) + if (AuxiliaryReservoir.CurrentPressure + Tolerance < BrakeCylinder.CurrentPressure) { // back-flow from brake cylinder to auxillary reservoir - double u = (brakeCylinder.CurrentPressure - auxiliaryReservoir.CurrentPressure - Tolerance) / Tolerance; + double u = (BrakeCylinder.CurrentPressure - AuxiliaryReservoir.CurrentPressure - Tolerance) / Tolerance; if (u > 1.0) u = 1.0; - double f = auxiliaryReservoir.BrakeCylinderCoefficient; - double r = brakeCylinder.ServiceChargeRate * f; - double d = brakeCylinder.CurrentPressure - auxiliaryReservoir.CurrentPressure; - double m = auxiliaryReservoir.MaximumPressure; - r = GetRate(d * u / m, r * TimeElapsed); - if (auxiliaryReservoir.CurrentPressure + r > m) + double f = AuxiliaryReservoir.BrakeCylinderCoefficient; + double r = BrakeCylinder.ServiceChargeRate * f; + double d = BrakeCylinder.CurrentPressure - AuxiliaryReservoir.CurrentPressure; + double m = AuxiliaryReservoir.MaximumPressure; + r = GetRate(d * u / m, r * timeElapsed); + if (AuxiliaryReservoir.CurrentPressure + r > m) { - r = m - auxiliaryReservoir.CurrentPressure; + r = m - AuxiliaryReservoir.CurrentPressure; } if (r > d) r = d; @@ -141,28 +141,28 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan s = d; } - if (s > brakeCylinder.CurrentPressure) + if (s > BrakeCylinder.CurrentPressure) { - r *= brakeCylinder.CurrentPressure / s; - s = brakeCylinder.CurrentPressure; + r *= BrakeCylinder.CurrentPressure / s; + s = BrakeCylinder.CurrentPressure; } - auxiliaryReservoir.CurrentPressure += 0.5 * r; - brakeCylinder.CurrentPressure -= 0.5 * s; + AuxiliaryReservoir.CurrentPressure += 0.5 * r; + BrakeCylinder.CurrentPressure -= 0.5 * s; } - else if (auxiliaryReservoir.CurrentPressure > brakeCylinder.CurrentPressure + Tolerance) + else if (AuxiliaryReservoir.CurrentPressure > BrakeCylinder.CurrentPressure + Tolerance) { // refill brake cylinder from auxillary reservoir - double u = (auxiliaryReservoir.CurrentPressure - brakeCylinder.CurrentPressure - Tolerance) / Tolerance; + double u = (AuxiliaryReservoir.CurrentPressure - BrakeCylinder.CurrentPressure - Tolerance) / Tolerance; if (u > 1.0) u = 1.0; - double f = auxiliaryReservoir.BrakeCylinderCoefficient; - double r = brakeCylinder.ServiceChargeRate * f; - double d = auxiliaryReservoir.CurrentPressure - brakeCylinder.CurrentPressure; - double m = auxiliaryReservoir.MaximumPressure; - r = GetRate(d * u / m, r * TimeElapsed); - if (r > auxiliaryReservoir.CurrentPressure) + double f = AuxiliaryReservoir.BrakeCylinderCoefficient; + double r = BrakeCylinder.ServiceChargeRate * f; + double d = AuxiliaryReservoir.CurrentPressure - BrakeCylinder.CurrentPressure; + double m = AuxiliaryReservoir.MaximumPressure; + r = GetRate(d * u / m, r * timeElapsed); + if (r > AuxiliaryReservoir.CurrentPressure) { - r = auxiliaryReservoir.CurrentPressure; + r = AuxiliaryReservoir.CurrentPressure; } if (r > d) r = d; @@ -173,15 +173,15 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan s = d; } - d = brakeCylinder.EmergencyMaximumPressure - brakeCylinder.CurrentPressure; + d = BrakeCylinder.EmergencyMaximumPressure - BrakeCylinder.CurrentPressure; if (s > d) { r *= d / s; s = d; } - auxiliaryReservoir.CurrentPressure -= 0.5 * r; - brakeCylinder.CurrentPressure += 0.5 * s; + AuxiliaryReservoir.CurrentPressure -= 0.5 * r; + BrakeCylinder.CurrentPressure += 0.5 * s; // as the pressure is now *increasing* stop our decrease sounds AirHigh?.Stop(); Air?.Stop(); @@ -189,32 +189,32 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan } // air sound - brakeCylinder.SoundPlayedForPressure = brakeCylinder.EmergencyMaximumPressure; + BrakeCylinder.SoundPlayedForPressure = BrakeCylinder.EmergencyMaximumPressure; } - else if (brakePipe.CurrentPressure > auxiliaryReservoir.CurrentPressure + Tolerance) + else if (BrakePipe.CurrentPressure > AuxiliaryReservoir.CurrentPressure + Tolerance) { - double u = (brakePipe.CurrentPressure - auxiliaryReservoir.CurrentPressure - Tolerance) / Tolerance; + double u = (BrakePipe.CurrentPressure - AuxiliaryReservoir.CurrentPressure - Tolerance) / Tolerance; if (u > 1.0) u = 1.0; { // refill auxillary reservoir from brake pipe - double r = auxiliaryReservoir.ChargeRate; - double d = brakePipe.CurrentPressure - auxiliaryReservoir.CurrentPressure; - double m = auxiliaryReservoir.MaximumPressure; - r = GetRate(d * u / m, r * TimeElapsed); - if (r > brakePipe.CurrentPressure) + double r = AuxiliaryReservoir.ChargeRate; + double d = BrakePipe.CurrentPressure - AuxiliaryReservoir.CurrentPressure; + double m = AuxiliaryReservoir.MaximumPressure; + r = GetRate(d * u / m, r * timeElapsed); + if (r > BrakePipe.CurrentPressure) { - r = brakePipe.CurrentPressure; + r = BrakePipe.CurrentPressure; } if (r > d) r = d; - d = auxiliaryReservoir.MaximumPressure - auxiliaryReservoir.CurrentPressure; + d = AuxiliaryReservoir.MaximumPressure - AuxiliaryReservoir.CurrentPressure; if (r > d) r = d; - double f = auxiliaryReservoir.BrakePipeCoefficient; + double f = AuxiliaryReservoir.BrakePipeCoefficient; double s = r / f; - if (s > brakePipe.CurrentPressure) + if (s > BrakePipe.CurrentPressure) { - r *= brakePipe.CurrentPressure / s; - s = brakePipe.CurrentPressure; + r *= BrakePipe.CurrentPressure / s; + s = BrakePipe.CurrentPressure; } if (s > d) @@ -223,33 +223,33 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan s = d; } - auxiliaryReservoir.CurrentPressure += 0.5 * r; - brakePipe.CurrentPressure -= 0.5 * s; + AuxiliaryReservoir.CurrentPressure += 0.5 * r; + BrakePipe.CurrentPressure -= 0.5 * s; } { // brake cylinder release - double r = brakeCylinder.ReleaseRate; - double d = brakeCylinder.CurrentPressure; - double m = brakeCylinder.EmergencyMaximumPressure; - r = GetRate(d * u / m, r * TimeElapsed); - if (r > brakeCylinder.CurrentPressure) r = brakeCylinder.CurrentPressure; - brakeCylinder.CurrentPressure -= r; + double r = BrakeCylinder.ReleaseRate; + double d = BrakeCylinder.CurrentPressure; + double m = BrakeCylinder.EmergencyMaximumPressure; + r = GetRate(d * u / m, r * timeElapsed); + if (r > BrakeCylinder.CurrentPressure) r = BrakeCylinder.CurrentPressure; + BrakeCylinder.CurrentPressure -= r; // air sound - if (r > 0.0 & brakeCylinder.CurrentPressure < brakeCylinder.SoundPlayedForPressure) + if (r > 0.0 & BrakeCylinder.CurrentPressure < BrakeCylinder.SoundPlayedForPressure) { - double p = 0.8 * brakeCylinder.CurrentPressure - 0.2 * brakeCylinder.EmergencyMaximumPressure; + double p = 0.8 * BrakeCylinder.CurrentPressure - 0.2 * BrakeCylinder.EmergencyMaximumPressure; if (p < 0.0) p = 0.0; - brakeCylinder.SoundPlayedForPressure = p; - airSound = p < Tolerance ? AirZero : brakeCylinder.CurrentPressure > m - Tolerance ? AirHigh : Air; + BrakeCylinder.SoundPlayedForPressure = p; + AirSound = p < Tolerance ? AirZero : BrakeCylinder.CurrentPressure > m - Tolerance ? AirHigh : Air; } } } else { // air sound - brakeCylinder.SoundPlayedForPressure = brakeCylinder.EmergencyMaximumPressure; + BrakeCylinder.SoundPlayedForPressure = BrakeCylinder.EmergencyMaximumPressure; } - double pressureratio = brakeCylinder.CurrentPressure / brakeCylinder.ServiceMaximumPressure; + double pressureratio = BrakeCylinder.CurrentPressure / BrakeCylinder.ServiceMaximumPressure; deceleration = pressureratio * DecelerationAtServiceMaximumPressure(brakeHandle.Actual, currentSpeed); } } diff --git a/source/TrainManager/Brake/AirBrake/Components/AirCompressor.cs b/source/TrainManager/Brake/AirBrake/Components/AirCompressor.cs index 9150c6bde..45a704096 100644 --- a/source/TrainManager/Brake/AirBrake/Components/AirCompressor.cs +++ b/source/TrainManager/Brake/AirBrake/Components/AirCompressor.cs @@ -36,7 +36,7 @@ public Compressor(double rate, MainReservoir reservoir, AbstractCar car) baseCar = car; } - public void Update(double TimeElapsed) + public void Update(double timeElapsed) { if (Enabled) { @@ -49,10 +49,10 @@ public void Update(double TimeElapsed) } else { - mainReservoir.CurrentPressure += Rate * TimeElapsed; + mainReservoir.CurrentPressure += Rate * timeElapsed; if (!LoopStarted) { - if ((StartSound.Buffer == null && TrainManagerBase.currentHost.InGameTime > TimeStarted + 5.0) || (StartSound.Buffer != null && !StartSound.IsPlaying)) + if ((StartSound.Buffer == null && TrainManagerBase.CurrentHost.InGameTime > TimeStarted + 5.0) || (StartSound.Buffer != null && !StartSound.IsPlaying)) { /* * If no start sound, assume a run-up time of 5s for the compressor @@ -69,7 +69,7 @@ public void Update(double TimeElapsed) if (mainReservoir.CurrentPressure < mainReservoir.MinimumPressure) { Enabled = true; - TimeStarted = TrainManagerBase.currentHost.InGameTime; + TimeStarted = TrainManagerBase.CurrentHost.InGameTime; StartSound.Play(baseCar, false); } } diff --git a/source/TrainManager/Brake/AirBrake/ElectricCommandBrake.cs b/source/TrainManager/Brake/AirBrake/ElectricCommandBrake.cs index 1986106be..73be8c323 100644 --- a/source/TrainManager/Brake/AirBrake/ElectricCommandBrake.cs +++ b/source/TrainManager/Brake/AirBrake/ElectricCommandBrake.cs @@ -7,49 +7,49 @@ namespace TrainManager.BrakeSystems { public class ElectricCommandBrake : CarBrake { - public ElectricCommandBrake(EletropneumaticBrakeType type, CarBase car, double BrakeControlSpeed, double MotorDeceleration, double MotorDecelerationDelayUp, double MotorDecelerationDelayDown, AccelerationCurve[] DecelerationCurves) : base(car) + public ElectricCommandBrake(EletropneumaticBrakeType type, CarBase car, double brakeControlSpeed, double motorDeceleration, double motorDecelerationDelayUp, double motorDecelerationDelayDown, AccelerationCurve[] decelerationCurves) : base(car) { - electropneumaticBrakeType = type; - brakeControlSpeed = BrakeControlSpeed; - motorDeceleration = MotorDeceleration; - motorDecelerationDelayUp = MotorDecelerationDelayUp; - motorDecelerationDelayDown = MotorDecelerationDelayDown; - decelerationCurves = DecelerationCurves; + ElectropneumaticBrakeType = type; + BrakeControlSpeed = brakeControlSpeed; + MotorDeceleration = motorDeceleration; + MotorDecelerationDelayUp = motorDecelerationDelayUp; + MotorDecelerationDelayDown = motorDecelerationDelayDown; + DecelerationCurves = decelerationCurves; } - public override void Update(double TimeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double deceleration) + public override void Update(double timeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double deceleration) { - airSound = null; + AirSound = null; double targetPressure; - if (Car.baseTrain.Handles.EmergencyBrake.Actual) + if (Car.BaseTrain.Handles.EmergencyBrake.Actual) { - if (brakeType == BrakeType.Main) + if (BrakeType == BrakeType.Main) { - double r = equalizingReservoir.EmergencyRate; - double d = equalizingReservoir.CurrentPressure; - double m = equalizingReservoir.NormalPressure; - r = GetRate(d / m, r * TimeElapsed); - if (r > equalizingReservoir.CurrentPressure) + double r = EqualizingReservoir.EmergencyRate; + double d = EqualizingReservoir.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; + r = GetRate(d / m, r * timeElapsed); + if (r > EqualizingReservoir.CurrentPressure) { - r = equalizingReservoir.CurrentPressure; + r = EqualizingReservoir.CurrentPressure; } - equalizingReservoir.CurrentPressure -= r; + EqualizingReservoir.CurrentPressure -= r; } - targetPressure = brakeCylinder.EmergencyMaximumPressure; + targetPressure = BrakeCylinder.EmergencyMaximumPressure; } else { targetPressure = brakeHandle.Actual / (double)brakeHandle.MaximumNotch; - targetPressure *= brakeCylinder.ServiceMaximumPressure; + targetPressure *= BrakeCylinder.ServiceMaximumPressure; } - if (!Car.baseTrain.Handles.EmergencyBrake.Actual & Car.baseTrain.Handles.Reverser.Actual != 0) + if (!Car.BaseTrain.Handles.EmergencyBrake.Actual & Car.BaseTrain.Handles.Reverser.Actual != 0) { // brake control system - if (Car.Specs.IsMotorCar & Math.Abs(currentSpeed) > brakeControlSpeed) + if (Car.Specs.IsMotorCar & Math.Abs(currentSpeed) > BrakeControlSpeed) { - switch (electropneumaticBrakeType) + switch (ElectropneumaticBrakeType) { case EletropneumaticBrakeType.ClosingElectromagneticValve: // closing electromagnetic valve (lock-out valve) @@ -57,15 +57,15 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan break; case EletropneumaticBrakeType.DelayFillingControl: // delay-filling control - double a = motorDeceleration; - double pr = targetPressure / brakeCylinder.ServiceMaximumPressure; + double a = MotorDeceleration; + double pr = targetPressure / BrakeCylinder.ServiceMaximumPressure; double b = pr * DecelerationAtServiceMaximumPressure(brakeHandle.Actual, currentSpeed); double d = b - a; if (d > 0.0) { targetPressure = d / DecelerationAtServiceMaximumPressure(brakeHandle.Actual, currentSpeed); if (targetPressure > 1.0) targetPressure = 1.0; - targetPressure *= brakeCylinder.ServiceMaximumPressure; + targetPressure *= BrakeCylinder.ServiceMaximumPressure; } else { @@ -77,57 +77,57 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan } } - if (brakeCylinder.CurrentPressure > targetPressure + Tolerance | targetPressure == 0.0) + if (BrakeCylinder.CurrentPressure > targetPressure + Tolerance | targetPressure == 0.0) { // brake cylinder exhaust valve - double r = brakeCylinder.ReleaseRate; - double d = brakeCylinder.CurrentPressure; - double m = brakeCylinder.EmergencyMaximumPressure; - r = GetRate(d / m, r * TimeElapsed); + double r = BrakeCylinder.ReleaseRate; + double d = BrakeCylinder.CurrentPressure; + double m = BrakeCylinder.EmergencyMaximumPressure; + r = GetRate(d / m, r * timeElapsed); if (r > d) r = d; // air sound - if (r > 0.0 & brakeCylinder.CurrentPressure < brakeCylinder.SoundPlayedForPressure) + if (r > 0.0 & BrakeCylinder.CurrentPressure < BrakeCylinder.SoundPlayedForPressure) { - brakeCylinder.SoundPlayedForPressure = targetPressure; - airSound = targetPressure < Tolerance ? AirZero : brakeCylinder.CurrentPressure > m - Tolerance ? AirHigh : Air; + BrakeCylinder.SoundPlayedForPressure = targetPressure; + AirSound = targetPressure < Tolerance ? AirZero : BrakeCylinder.CurrentPressure > m - Tolerance ? AirHigh : Air; } // pressure change - brakeCylinder.CurrentPressure -= r; + BrakeCylinder.CurrentPressure -= r; } - else if ((brakeCylinder.CurrentPressure + Tolerance < targetPressure | targetPressure == brakeCylinder.EmergencyMaximumPressure) & brakeCylinder.CurrentPressure + Tolerance < mainReservoir.CurrentPressure) + else if ((BrakeCylinder.CurrentPressure + Tolerance < targetPressure | targetPressure == BrakeCylinder.EmergencyMaximumPressure) & BrakeCylinder.CurrentPressure + Tolerance < MainReservoir.CurrentPressure) { // fill brake cylinder from main reservoir double r; - if (Car.baseTrain.Handles.EmergencyBrake.Actual) + if (Car.BaseTrain.Handles.EmergencyBrake.Actual) { - r = 2.0 * brakeCylinder.EmergencyChargeRate; + r = 2.0 * BrakeCylinder.EmergencyChargeRate; } else { - r = 2.0 * brakeCylinder.ServiceChargeRate; + r = 2.0 * BrakeCylinder.ServiceChargeRate; } - double pm = targetPressure < mainReservoir.CurrentPressure ? targetPressure : mainReservoir.CurrentPressure; - double d = pm - brakeCylinder.CurrentPressure; - double m = brakeCylinder.EmergencyMaximumPressure; - r = GetRate(d / m, r * TimeElapsed); + double pm = targetPressure < MainReservoir.CurrentPressure ? targetPressure : MainReservoir.CurrentPressure; + double d = pm - BrakeCylinder.CurrentPressure; + double m = BrakeCylinder.EmergencyMaximumPressure; + r = GetRate(d / m, r * timeElapsed); if (r > d) r = d; - double f1 = auxiliaryReservoir.BrakeCylinderCoefficient; - double f2 = mainReservoir.BrakePipeCoefficient; - double f3 = auxiliaryReservoir.BrakePipeCoefficient; + double f1 = AuxiliaryReservoir.BrakeCylinderCoefficient; + double f2 = MainReservoir.BrakePipeCoefficient; + double f3 = AuxiliaryReservoir.BrakePipeCoefficient; double f = f1 * f2 / f3; // MainReservoirBrakeCylinderCoefficient double s = r * f; - if (s > mainReservoir.CurrentPressure) + if (s > MainReservoir.CurrentPressure) { - r *= mainReservoir.CurrentPressure / s; - s = mainReservoir.CurrentPressure; + r *= MainReservoir.CurrentPressure / s; + s = MainReservoir.CurrentPressure; } - brakeCylinder.CurrentPressure += 0.5 * r; - mainReservoir.CurrentPressure -= 0.5 * s; + BrakeCylinder.CurrentPressure += 0.5 * r; + MainReservoir.CurrentPressure -= 0.5 * s; // air sound - brakeCylinder.SoundPlayedForPressure = brakeCylinder.EmergencyMaximumPressure; + BrakeCylinder.SoundPlayedForPressure = BrakeCylinder.EmergencyMaximumPressure; // as the pressure is now *increasing* stop our decrease sounds AirHigh?.Stop(); Air?.Stop(); @@ -136,42 +136,42 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan else { // air sound - brakeCylinder.SoundPlayedForPressure = brakeCylinder.EmergencyMaximumPressure; + BrakeCylinder.SoundPlayedForPressure = BrakeCylinder.EmergencyMaximumPressure; } double pp; - if (Car.baseTrain.Handles.EmergencyBrake.Actual) + if (Car.BaseTrain.Handles.EmergencyBrake.Actual) { - pp = brakeCylinder.EmergencyMaximumPressure; + pp = BrakeCylinder.EmergencyMaximumPressure; } else { pp = brakeHandle.Actual / (double)brakeHandle.MaximumNotch; - pp *= brakeCylinder.ServiceMaximumPressure; + pp *= BrakeCylinder.ServiceMaximumPressure; } - straightAirPipe.CurrentPressure = pp; - double pressureratio = brakeCylinder.CurrentPressure / brakeCylinder.ServiceMaximumPressure; + StraightAirPipe.CurrentPressure = pp; + double pressureratio = BrakeCylinder.CurrentPressure / BrakeCylinder.ServiceMaximumPressure; deceleration = pressureratio * DecelerationAtServiceMaximumPressure(brakeHandle.Actual, currentSpeed); } - public override double CurrentMotorDeceleration(double TimeElapsed, AbstractHandle BrakeHandle) + public override double CurrentMotorDeceleration(double timeElapsed, AbstractHandle brakeHandle) { double actualDeceleration = 0; - if (lastHandlePosition != BrakeHandle.Actual) + if (LastHandlePosition != brakeHandle.Actual) { - motorDecelerationDelayTimer = BrakeHandle.Actual > lastHandlePosition ? motorDecelerationDelayUp : motorDecelerationDelayDown; - lastHandlePosition = BrakeHandle.Actual; + MotorDecelerationDelayTimer = brakeHandle.Actual > LastHandlePosition ? MotorDecelerationDelayUp : MotorDecelerationDelayDown; + LastHandlePosition = brakeHandle.Actual; } - if (BrakeHandle.Actual != 0) + if (brakeHandle.Actual != 0) { - motorDecelerationDelayTimer -= TimeElapsed; - if (motorDecelerationDelayTimer < 0) + MotorDecelerationDelayTimer -= timeElapsed; + if (MotorDecelerationDelayTimer < 0) { - actualDeceleration = (BrakeHandle.Actual / (double)BrakeHandle.MaximumNotch) * motorDeceleration; - lastMotorDeceleration = actualDeceleration; + actualDeceleration = (brakeHandle.Actual / (double)brakeHandle.MaximumNotch) * MotorDeceleration; + LastMotorDeceleration = actualDeceleration; } - else if (lastHandlePosition != 0) + else if (LastHandlePosition != 0) { - actualDeceleration = lastMotorDeceleration; + actualDeceleration = LastMotorDeceleration; } } return actualDeceleration; diff --git a/source/TrainManager/Brake/AirBrake/ElectromagneticStraightAirBrake.cs b/source/TrainManager/Brake/AirBrake/ElectromagneticStraightAirBrake.cs index af63e2235..73502bd53 100644 --- a/source/TrainManager/Brake/AirBrake/ElectromagneticStraightAirBrake.cs +++ b/source/TrainManager/Brake/AirBrake/ElectromagneticStraightAirBrake.cs @@ -7,110 +7,110 @@ namespace TrainManager.BrakeSystems { public class ElectromagneticStraightAirBrake : CarBrake { - public ElectromagneticStraightAirBrake(EletropneumaticBrakeType type, CarBase car, double BrakeControlSpeed, double MotorDeceleration, double MotorDecelerationDelayUp, double MotorDecelerationDelayDown, AccelerationCurve[] DecelerationCurves) : base(car) + public ElectromagneticStraightAirBrake(EletropneumaticBrakeType type, CarBase car, double brakeControlSpeed, double motorDeceleration, double motorDecelerationDelayUp, double motorDecelerationDelayDown, AccelerationCurve[] decelerationCurves) : base(car) { - electropneumaticBrakeType = type; - brakeControlSpeed = BrakeControlSpeed; - motorDeceleration = MotorDeceleration; - motorDecelerationDelayUp = MotorDecelerationDelayUp; - motorDecelerationDelayDown = MotorDecelerationDelayDown; - decelerationCurves = DecelerationCurves; + ElectropneumaticBrakeType = type; + BrakeControlSpeed = brakeControlSpeed; + MotorDeceleration = motorDeceleration; + MotorDecelerationDelayUp = motorDecelerationDelayUp; + MotorDecelerationDelayDown = motorDecelerationDelayDown; + DecelerationCurves = decelerationCurves; } - public override void Update(double TimeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double deceleration) + public override void Update(double timeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double deceleration) { - airSound = null; - if (Car.baseTrain.Handles.EmergencyBrake.Actual) + AirSound = null; + if (Car.BaseTrain.Handles.EmergencyBrake.Actual) { - if (brakeType == BrakeType.Main) + if (BrakeType == BrakeType.Main) { - double r = equalizingReservoir.EmergencyRate; - double d = equalizingReservoir.CurrentPressure; - double m = equalizingReservoir.NormalPressure; - r = GetRate(d / m, r * TimeElapsed); - if (r > equalizingReservoir.CurrentPressure) + double r = EqualizingReservoir.EmergencyRate; + double d = EqualizingReservoir.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; + r = GetRate(d / m, r * timeElapsed); + if (r > EqualizingReservoir.CurrentPressure) { - r = equalizingReservoir.CurrentPressure; + r = EqualizingReservoir.CurrentPressure; } - equalizingReservoir.CurrentPressure -= r; + EqualizingReservoir.CurrentPressure -= r; } } //First update the main reservoir pressure { - double r = equalizingReservoir.ChargeRate; - double d = equalizingReservoir.NormalPressure - equalizingReservoir.CurrentPressure; - double m = equalizingReservoir.NormalPressure; - r = GetRate(d / m, r * TimeElapsed); + double r = EqualizingReservoir.ChargeRate; + double d = EqualizingReservoir.NormalPressure - EqualizingReservoir.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; + r = GetRate(d / m, r * timeElapsed); if (r > d) r = d; - d = mainReservoir.CurrentPressure - equalizingReservoir.CurrentPressure; + d = MainReservoir.CurrentPressure - EqualizingReservoir.CurrentPressure; if (r > d) r = d; - double f = mainReservoir.EqualizingReservoirCoefficient; - double s = r * f * TimeElapsed; - if (s > mainReservoir.CurrentPressure) + double f = MainReservoir.EqualizingReservoirCoefficient; + double s = r * f * timeElapsed; + if (s > MainReservoir.CurrentPressure) { - r *= mainReservoir.CurrentPressure / s; - s = mainReservoir.CurrentPressure; + r *= MainReservoir.CurrentPressure / s; + s = MainReservoir.CurrentPressure; } - equalizingReservoir.CurrentPressure += 0.5 * r; - mainReservoir.CurrentPressure -= 0.5 * s; + EqualizingReservoir.CurrentPressure += 0.5 * r; + MainReservoir.CurrentPressure -= 0.5 * s; } //Fill the brake pipe from the main reservoir - if (brakeType == BrakeType.Main) + if (BrakeType == BrakeType.Main) { - if (brakePipe.CurrentPressure > equalizingReservoir.CurrentPressure + Tolerance) + if (BrakePipe.CurrentPressure > EqualizingReservoir.CurrentPressure + Tolerance) { // brake pipe exhaust valve - double r = Car.baseTrain.Handles.EmergencyBrake.Actual ? brakePipe.EmergencyRate : brakePipe.ServiceRate; - double d = brakePipe.CurrentPressure - equalizingReservoir.CurrentPressure; - double m = equalizingReservoir.NormalPressure; - r = (0.5 + 1.5 * d / m) * r * TimeElapsed; + double r = Car.BaseTrain.Handles.EmergencyBrake.Actual ? BrakePipe.EmergencyRate : BrakePipe.ServiceRate; + double d = BrakePipe.CurrentPressure - EqualizingReservoir.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; + r = (0.5 + 1.5 * d / m) * r * timeElapsed; if (r > d) r = d; - brakePipe.CurrentPressure -= r; + BrakePipe.CurrentPressure -= r; } - else if (brakePipe.CurrentPressure + Tolerance < equalizingReservoir.CurrentPressure) + else if (BrakePipe.CurrentPressure + Tolerance < EqualizingReservoir.CurrentPressure) { // fill brake pipe from main reservoir - double r = brakePipe.ChargeRate; - double d = equalizingReservoir.CurrentPressure - brakePipe.CurrentPressure; - double m = equalizingReservoir.NormalPressure; - r = (0.5 + 1.5 * d / m) * r * TimeElapsed; + double r = BrakePipe.ChargeRate; + double d = EqualizingReservoir.CurrentPressure - BrakePipe.CurrentPressure; + double m = EqualizingReservoir.NormalPressure; + r = (0.5 + 1.5 * d / m) * r * timeElapsed; if (r > d) r = d; - d = brakePipe.NormalPressure - brakePipe.CurrentPressure; + d = BrakePipe.NormalPressure - BrakePipe.CurrentPressure; if (r > d) r = d; - double f = mainReservoir.BrakePipeCoefficient; + double f = MainReservoir.BrakePipeCoefficient; double s = r * f; - if (s > mainReservoir.CurrentPressure) + if (s > MainReservoir.CurrentPressure) { - r *= mainReservoir.CurrentPressure / s; - s = mainReservoir.CurrentPressure; + r *= MainReservoir.CurrentPressure / s; + s = MainReservoir.CurrentPressure; } - brakePipe.CurrentPressure += 0.5 * r; - mainReservoir.CurrentPressure -= 0.5 * s; + BrakePipe.CurrentPressure += 0.5 * r; + MainReservoir.CurrentPressure -= 0.5 * s; } } // refill auxillary reservoir from brake pipe - if (brakePipe.CurrentPressure > auxiliaryReservoir.CurrentPressure + Tolerance) + if (BrakePipe.CurrentPressure > AuxiliaryReservoir.CurrentPressure + Tolerance) { - double r = 2.0 * auxiliaryReservoir.ChargeRate; - double d = brakePipe.CurrentPressure - auxiliaryReservoir.CurrentPressure; - double m = auxiliaryReservoir.MaximumPressure; - r = GetRate(d / m, r * TimeElapsed); - if (r > brakePipe.CurrentPressure) + double r = 2.0 * AuxiliaryReservoir.ChargeRate; + double d = BrakePipe.CurrentPressure - AuxiliaryReservoir.CurrentPressure; + double m = AuxiliaryReservoir.MaximumPressure; + r = GetRate(d / m, r * timeElapsed); + if (r > BrakePipe.CurrentPressure) { - r = brakePipe.CurrentPressure; + r = BrakePipe.CurrentPressure; } if (r > d) r = d; - d = auxiliaryReservoir.MaximumPressure - auxiliaryReservoir.CurrentPressure; + d = AuxiliaryReservoir.MaximumPressure - AuxiliaryReservoir.CurrentPressure; if (r > d) r = d; - double f = auxiliaryReservoir.BrakePipeCoefficient; + double f = AuxiliaryReservoir.BrakePipeCoefficient; double s = r / f; - if (s > brakePipe.CurrentPressure) + if (s > BrakePipe.CurrentPressure) { - r *= brakePipe.CurrentPressure / s; - s = brakePipe.CurrentPressure; + r *= BrakePipe.CurrentPressure / s; + s = BrakePipe.CurrentPressure; } if (s > d) @@ -119,42 +119,42 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan s = d; } - auxiliaryReservoir.CurrentPressure += 0.5 * r; - brakePipe.CurrentPressure -= 0.5 * s; + AuxiliaryReservoir.CurrentPressure += 0.5 * r; + BrakePipe.CurrentPressure -= 0.5 * s; } // electric command - bool emergency = brakePipe.CurrentPressure + Tolerance < auxiliaryReservoir.CurrentPressure || Car.baseTrain.Handles.EmergencyBrake.Actual; + bool emergency = BrakePipe.CurrentPressure + Tolerance < AuxiliaryReservoir.CurrentPressure || Car.BaseTrain.Handles.EmergencyBrake.Actual; double targetPressure; if (emergency) { //If EB is selected, then target pressure must be that required for EB - targetPressure = brakeCylinder.EmergencyMaximumPressure; + targetPressure = BrakeCylinder.EmergencyMaximumPressure; } else { //Otherwise [BVE2 / BVE4 train.dat format] work out target pressure as a proportion of the max notch: targetPressure = brakeHandle.Actual / (double) brakeHandle.MaximumNotch; - targetPressure *= brakeCylinder.ServiceMaximumPressure; + targetPressure *= BrakeCylinder.ServiceMaximumPressure; } - if (Car.Specs.IsMotorCar & !Car.baseTrain.Handles.EmergencyBrake.Actual & Car.baseTrain.Handles.Reverser.Actual != 0) + if (Car.Specs.IsMotorCar & !Car.BaseTrain.Handles.EmergencyBrake.Actual & Car.BaseTrain.Handles.Reverser.Actual != 0) { //If we meet the conditions for brake control system to activate - if (Math.Abs(currentSpeed) > brakeControlSpeed) + if (Math.Abs(currentSpeed) > BrakeControlSpeed) { - if (electropneumaticBrakeType == EletropneumaticBrakeType.ClosingElectromagneticValve) + if (ElectropneumaticBrakeType == EletropneumaticBrakeType.ClosingElectromagneticValve) { //When above the brake control speed, pressure to the BC is nil & electric brakes are used //Thus target pressure must be zero targetPressure = 0.0; } - else if (electropneumaticBrakeType == EletropneumaticBrakeType.DelayFillingControl) + else if (ElectropneumaticBrakeType == EletropneumaticBrakeType.DelayFillingControl) { //Motor is used to brake the train, until not enough deceleration, at which point the air brake is also used - double a = motorDeceleration; - double pr = targetPressure / brakeCylinder.ServiceMaximumPressure; + double a = MotorDeceleration; + double pr = targetPressure / BrakeCylinder.ServiceMaximumPressure; double b = pr * DecelerationAtServiceMaximumPressure(brakeHandle.Actual, currentSpeed); double d = b - a; @@ -163,7 +163,7 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan //Deceleration provided by the motor is not enough, so increase the BC target pressure targetPressure = d / DecelerationAtServiceMaximumPressure(brakeHandle.Actual, currentSpeed); if (targetPressure > 1.0) targetPressure = 1.0; - targetPressure *= brakeCylinder.ServiceMaximumPressure; + targetPressure *= BrakeCylinder.ServiceMaximumPressure; } else { @@ -174,45 +174,45 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan } } - if (brakeCylinder.CurrentPressure > targetPressure + Tolerance | targetPressure == 0.0) + if (BrakeCylinder.CurrentPressure > targetPressure + Tolerance | targetPressure == 0.0) { //BC pressure is greater than the target pressure, so release pressure - double r = brakeCylinder.ReleaseRate; - double d = brakeCylinder.CurrentPressure - targetPressure; - double m = brakeCylinder.EmergencyMaximumPressure; - r = GetRate(d / m, r * TimeElapsed); - if (r > brakeCylinder.CurrentPressure) r = brakeCylinder.CurrentPressure; + double r = BrakeCylinder.ReleaseRate; + double d = BrakeCylinder.CurrentPressure - targetPressure; + double m = BrakeCylinder.EmergencyMaximumPressure; + r = GetRate(d / m, r * timeElapsed); + if (r > BrakeCylinder.CurrentPressure) r = BrakeCylinder.CurrentPressure; if (r > d) r = d; // air sound - if (r > 0.0 & brakeCylinder.CurrentPressure < brakeCylinder.SoundPlayedForPressure) + if (r > 0.0 & BrakeCylinder.CurrentPressure < BrakeCylinder.SoundPlayedForPressure) { - brakeCylinder.SoundPlayedForPressure = targetPressure; - airSound = targetPressure < Tolerance ? AirZero : brakeCylinder.CurrentPressure > m - Tolerance ? AirHigh : Air; + BrakeCylinder.SoundPlayedForPressure = targetPressure; + AirSound = targetPressure < Tolerance ? AirZero : BrakeCylinder.CurrentPressure > m - Tolerance ? AirHigh : Air; } // pressure change - brakeCylinder.CurrentPressure -= r; + BrakeCylinder.CurrentPressure -= r; } - else if (brakeCylinder.CurrentPressure + Tolerance < targetPressure) + else if (BrakeCylinder.CurrentPressure + Tolerance < targetPressure) { //BC pressure is less than target pressure, so increase pressure - double f = auxiliaryReservoir.BrakeCylinderCoefficient; + double f = AuxiliaryReservoir.BrakeCylinderCoefficient; double r; if (emergency) { - r = 2.0 * brakeCylinder.EmergencyChargeRate * f; + r = 2.0 * BrakeCylinder.EmergencyChargeRate * f; } else { - r = 2.0 * brakeCylinder.ServiceChargeRate * f; + r = 2.0 * BrakeCylinder.ServiceChargeRate * f; } - double d = auxiliaryReservoir.CurrentPressure - brakeCylinder.CurrentPressure; - double m = brakeCylinder.EmergencyMaximumPressure; - r = GetRate(d / m, r * TimeElapsed); - if (r > auxiliaryReservoir.CurrentPressure) + double d = AuxiliaryReservoir.CurrentPressure - BrakeCylinder.CurrentPressure; + double m = BrakeCylinder.EmergencyMaximumPressure; + r = GetRate(d / m, r * timeElapsed); + if (r > AuxiliaryReservoir.CurrentPressure) { - r = auxiliaryReservoir.CurrentPressure; + r = AuxiliaryReservoir.CurrentPressure; } if (r > d) r = d; @@ -223,17 +223,17 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan s = d; } - d = brakeCylinder.EmergencyMaximumPressure - brakeCylinder.CurrentPressure; + d = BrakeCylinder.EmergencyMaximumPressure - BrakeCylinder.CurrentPressure; if (s > d) { r *= d / s; s = d; } - auxiliaryReservoir.CurrentPressure -= 0.5 * r; - brakeCylinder.CurrentPressure += 0.5 * s; + AuxiliaryReservoir.CurrentPressure -= 0.5 * r; + BrakeCylinder.CurrentPressure += 0.5 * s; // air sound - brakeCylinder.SoundPlayedForPressure = brakeCylinder.EmergencyMaximumPressure; + BrakeCylinder.SoundPlayedForPressure = BrakeCylinder.EmergencyMaximumPressure; // as the pressure is now *increasing* stop our decrease sounds AirHigh?.Stop(); Air?.Stop(); @@ -242,64 +242,64 @@ public override void Update(double TimeElapsed, double currentSpeed, AbstractHan else { // air sound - brakeCylinder.SoundPlayedForPressure = brakeCylinder.EmergencyMaximumPressure; + BrakeCylinder.SoundPlayedForPressure = BrakeCylinder.EmergencyMaximumPressure; } double p; - if (Car.baseTrain.Handles.EmergencyBrake.Actual) + if (Car.BaseTrain.Handles.EmergencyBrake.Actual) { p = 0.0; } else { p = brakeHandle.Actual / (double)brakeHandle.MaximumNotch; - p *= brakeCylinder.ServiceMaximumPressure; + p *= BrakeCylinder.ServiceMaximumPressure; } - if (p + Tolerance < straightAirPipe.CurrentPressure) + if (p + Tolerance < StraightAirPipe.CurrentPressure) { - double r = Car.baseTrain.Handles.EmergencyBrake.Actual ? straightAirPipe.EmergencyRate : straightAirPipe.ReleaseRate; - double d = straightAirPipe.CurrentPressure - p; - double m = brakeCylinder.EmergencyMaximumPressure; - r = GetRate(d / m, r * TimeElapsed); + double r = Car.BaseTrain.Handles.EmergencyBrake.Actual ? StraightAirPipe.EmergencyRate : StraightAirPipe.ReleaseRate; + double d = StraightAirPipe.CurrentPressure - p; + double m = BrakeCylinder.EmergencyMaximumPressure; + r = GetRate(d / m, r * timeElapsed); if (r > d) r = d; - straightAirPipe.CurrentPressure -= r; + StraightAirPipe.CurrentPressure -= r; } - else if (p > straightAirPipe.CurrentPressure + Tolerance) + else if (p > StraightAirPipe.CurrentPressure + Tolerance) { - double r = straightAirPipe.ServiceRate; - double d = p - straightAirPipe.CurrentPressure; - double m = brakeCylinder.EmergencyMaximumPressure; - r = GetRate(d / m, r * TimeElapsed); + double r = StraightAirPipe.ServiceRate; + double d = p - StraightAirPipe.CurrentPressure; + double m = BrakeCylinder.EmergencyMaximumPressure; + r = GetRate(d / m, r * timeElapsed); if (r > d) r = d; - straightAirPipe.CurrentPressure += r; + StraightAirPipe.CurrentPressure += r; } - double pressureratio = brakeCylinder.CurrentPressure / brakeCylinder.ServiceMaximumPressure; + double pressureratio = BrakeCylinder.CurrentPressure / BrakeCylinder.ServiceMaximumPressure; deceleration = pressureratio * DecelerationAtServiceMaximumPressure(brakeHandle.Actual, currentSpeed); } - public override double CurrentMotorDeceleration(double TimeElapsed, AbstractHandle BrakeHandle) + public override double CurrentMotorDeceleration(double timeElapsed, AbstractHandle brakeHandle) { double actualDeceleration = 0; - if (lastHandlePosition != BrakeHandle.Actual) + if (LastHandlePosition != brakeHandle.Actual) { - motorDecelerationDelayTimer = BrakeHandle.Actual > lastHandlePosition ? motorDecelerationDelayUp : motorDecelerationDelayDown; - lastHandlePosition = BrakeHandle.Actual; + MotorDecelerationDelayTimer = brakeHandle.Actual > LastHandlePosition ? MotorDecelerationDelayUp : MotorDecelerationDelayDown; + LastHandlePosition = brakeHandle.Actual; } - if (BrakeHandle.Actual != 0) + if (brakeHandle.Actual != 0) { - motorDecelerationDelayTimer -= TimeElapsed; - if (motorDecelerationDelayTimer < 0) + MotorDecelerationDelayTimer -= timeElapsed; + if (MotorDecelerationDelayTimer < 0) { - actualDeceleration = (BrakeHandle.Actual / (double)BrakeHandle.MaximumNotch) * motorDeceleration; - lastMotorDeceleration = actualDeceleration; + actualDeceleration = (brakeHandle.Actual / (double)brakeHandle.MaximumNotch) * MotorDeceleration; + LastMotorDeceleration = actualDeceleration; } - else if (lastHandlePosition != 0) + else if (LastHandlePosition != 0) { - actualDeceleration = lastMotorDeceleration; + actualDeceleration = LastMotorDeceleration; } } return actualDeceleration; diff --git a/source/TrainManager/Brake/AirBrake/ThroughPiped.cs b/source/TrainManager/Brake/AirBrake/ThroughPiped.cs index 73d2048cd..dbf68270f 100644 --- a/source/TrainManager/Brake/AirBrake/ThroughPiped.cs +++ b/source/TrainManager/Brake/AirBrake/ThroughPiped.cs @@ -8,13 +8,13 @@ public class ThroughPiped : CarBrake { public ThroughPiped(CarBase car) : base(car) { - decelerationCurves = new AccelerationCurve[] { }; - brakeType = BrakeType.None; + DecelerationCurves = new AccelerationCurve[] { }; + BrakeType = BrakeType.None; } - public override void Update(double TimeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double Deceleration) + public override void Update(double timeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double deceleration) { - Deceleration = 0.0; + deceleration = 0.0; } } } diff --git a/source/TrainManager/Brake/CarBrake.cs b/source/TrainManager/Brake/CarBrake.cs index 1083c0883..7b64bbb13 100644 --- a/source/TrainManager/Brake/CarBrake.cs +++ b/source/TrainManager/Brake/CarBrake.cs @@ -14,47 +14,47 @@ public abstract class CarBrake internal readonly CarBase Car; /// Whether this is a main or auxiliary brake system - public BrakeType brakeType; + public BrakeType BrakeType; - public EqualizingReservoir equalizingReservoir; + public EqualizingReservoir EqualizingReservoir; - public MainReservoir mainReservoir; + public MainReservoir MainReservoir; - public AuxiliaryReservoir auxiliaryReservoir; + public AuxiliaryReservoir AuxiliaryReservoir; - public BrakePipe brakePipe; + public BrakePipe BrakePipe; - public BrakeCylinder brakeCylinder; + public BrakeCylinder BrakeCylinder; - public Compressor airCompressor; + public Compressor AirCompressor; - internal EletropneumaticBrakeType electropneumaticBrakeType; + internal EletropneumaticBrakeType ElectropneumaticBrakeType; - public StraightAirPipe straightAirPipe; + public StraightAirPipe StraightAirPipe; /// The speed at which the brake control system activates in m/s - public double brakeControlSpeed; + public double BrakeControlSpeed; /// The current deceleration provided by the electric motor - public double motorDeceleration; + public double MotorDeceleration; /// The delay between motor deceleration being requested and it activating - internal double motorDecelerationDelayUp; + internal double MotorDecelerationDelayUp; /// The delay between motor deceleration stopping and this being reflected - internal double motorDecelerationDelayDown; + internal double MotorDecelerationDelayDown; /// Timer used for motor deceleration delay - internal double motorDecelerationDelayTimer; + internal double MotorDecelerationDelayTimer; /// The last motor deceleration figure returned - internal double lastMotorDeceleration; + internal double LastMotorDeceleration; /// The last brake handle position - internal int lastHandlePosition; + internal int LastHandlePosition; /// The air sound currently playing - public CarSound airSound = new CarSound(); + public CarSound AirSound = new CarSound(); /// Played when the pressure in the brake cylinder is decreased from a non-high to a non-zero value public CarSound Air = new CarSound(); /// Played when the pressure in the brake cylinder is decreased from a high value @@ -66,7 +66,7 @@ public abstract class CarBrake /// The sound played when the brakes are released public CarSound Release = new CarSound(); - internal AccelerationCurve[] decelerationCurves; + internal AccelerationCurve[] DecelerationCurves; /// A non-negative floating point number representing the jerk in m/s when the deceleration produced by the electric brake is increased. public double JerkUp; /// A non-negative floating point number representing the jerk in m/s when the deceleration produced by the electric brake is decreased. @@ -78,42 +78,42 @@ protected CarBrake(CarBase car) } /// Updates the brake system - /// The frame time elapsed + /// The frame time elapsed /// The current speed of the train /// The controlling brake handle (NOTE: May either be the loco brake if fitted or the train brake) - /// The deceleration output provided - public abstract void Update(double TimeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double Deceleration); + /// The deceleration output provided + public abstract void Update(double timeElapsed, double currentSpeed, AbstractHandle brakeHandle, out double deceleration); - internal double GetRate(double Ratio, double Factor) + internal double GetRate(double ratio, double factor) { - Ratio = Ratio < 0.0 ? 0.0 : Ratio > 1.0 ? 1.0 : Ratio; - Ratio = 1.0 - Ratio; - return 1.5 * Factor * (1.01 - Ratio * Ratio); + ratio = ratio < 0.0 ? 0.0 : ratio > 1.0 ? 1.0 : ratio; + ratio = 1.0 - ratio; + return 1.5 * factor * (1.01 - ratio * ratio); } /// Calculates the max possible deceleration given a brake notch and speed - /// The brake notch + /// The brake notch /// The speed /// The deceleration in m/s - public double DecelerationAtServiceMaximumPressure(int Notch, double currentSpeed) + public double DecelerationAtServiceMaximumPressure(int notch, double currentSpeed) { - if (Notch == 0) + if (notch == 0) { - return this.decelerationCurves[0].GetAccelerationOutput(currentSpeed, 1.0); + return this.DecelerationCurves[0].GetAccelerationOutput(currentSpeed, 1.0); } - if (this.decelerationCurves.Length >= Notch) + if (this.DecelerationCurves.Length >= notch) { - return this.decelerationCurves[Notch - 1].GetAccelerationOutput(currentSpeed, 1.0); + return this.DecelerationCurves[notch - 1].GetAccelerationOutput(currentSpeed, 1.0); } - return this.decelerationCurves[this.decelerationCurves.Length - 1].GetAccelerationOutput(currentSpeed, 1.0); + return this.DecelerationCurves[this.DecelerationCurves.Length - 1].GetAccelerationOutput(currentSpeed, 1.0); } /// Gets the current motor deceleration figure - /// The time elapsed since the last time this was updated - /// The controlling brake handle - public virtual double CurrentMotorDeceleration(double TimeElapsed, AbstractHandle BrakeHandle) + /// The time elapsed since the last time this was updated + /// The controlling brake handle + public virtual double CurrentMotorDeceleration(double timeElapsed, AbstractHandle brakeHandle) { - return motorDeceleration; + return MotorDeceleration; } } } diff --git a/source/TrainManager/Car/Bogie/Bogie.cs b/source/TrainManager/Car/Bogie/Bogie.cs index 877b884a6..602d1a0bf 100644 --- a/source/TrainManager/Car/Bogie/Bogie.cs +++ b/source/TrainManager/Car/Bogie/Bogie.cs @@ -41,19 +41,19 @@ public class Bogie /// Whether the bogie is the rear bogie private readonly bool Rear; - public Bogie(CarBase car, bool IsRear) + public Bogie(CarBase car, bool isRear) { baseCar = car; - Rear = IsRear; + Rear = isRear; CarSections = new CarSection[] { }; CurrentCarSection = -1; - FrontAxle = new Axle(TrainManagerBase.currentHost, car.baseTrain, car); + FrontAxle = new Axle(TrainManagerBase.CurrentHost, car.BaseTrain, car); FrontAxle.Follower.TriggerType = EventTriggerType.FrontBogieAxle; - RearAxle = new Axle(TrainManagerBase.currentHost, car.baseTrain, car); + RearAxle = new Axle(TrainManagerBase.CurrentHost, car.BaseTrain, car); RearAxle.Follower.TriggerType = EventTriggerType.RearBogieAxle; } - public void UpdateObjects(double TimeElapsed, bool ForceUpdate) + public void UpdateObjects(double timeElapsed, bool forceUpdate) { //Same hack: Check if any car sections are defined for the offending bogie if (CarSections.Length == 0) @@ -94,7 +94,7 @@ public void UpdateObjects(double TimeElapsed, bool ForceUpdate) { for (int i = 0; i < CarSections[cs].Groups[0].Elements.Length; i++) { - UpdateSectionElement(cs, i, p, d, s, CurrentlyVisible, TimeElapsed, ForceUpdate); + UpdateSectionElement(cs, i, p, d, s, CurrentlyVisible, timeElapsed, forceUpdate); // brightness change if (CarSections[cs].Groups[0].Elements[i].internalObject != null) @@ -128,10 +128,10 @@ public void LoadCarSections(UnifiedObject currentObject, bool visibleFromInterio { int j = CarSections.Length; Array.Resize(ref CarSections, j + 1); - CarSections[j] = new CarSection(TrainManagerBase.currentHost, ObjectType.Dynamic, visibleFromInterior, currentObject); + CarSections[j] = new CarSection(TrainManagerBase.CurrentHost, ObjectType.Dynamic, visibleFromInterior, currentObject); } - public void ChangeSection(int SectionIndex) + public void ChangeSection(int sectionIndex) { if (CarSections.Length == 0) { @@ -144,61 +144,61 @@ public void ChangeSection(int SectionIndex) { for (int j = 0; j < CarSections[i].Groups[0].Elements.Length; j++) { - TrainManagerBase.currentHost.HideObject(CarSections[i].Groups[0].Elements[j].internalObject); + TrainManagerBase.CurrentHost.HideObject(CarSections[i].Groups[0].Elements[j].internalObject); } } - if (SectionIndex >= 0) + if (sectionIndex >= 0) { - CarSections[SectionIndex].Initialize(CurrentlyVisible); - for (int j = 0; j < CarSections[SectionIndex].Groups[0].Elements.Length; j++) + CarSections[sectionIndex].Initialize(CurrentlyVisible); + for (int j = 0; j < CarSections[sectionIndex].Groups[0].Elements.Length; j++) { - TrainManagerBase.currentHost.ShowObject(CarSections[SectionIndex].Groups[0].Elements[j].internalObject, ObjectType.Dynamic); + TrainManagerBase.CurrentHost.ShowObject(CarSections[sectionIndex].Groups[0].Elements[j].internalObject, ObjectType.Dynamic); } } - CurrentCarSection = SectionIndex; + CurrentCarSection = sectionIndex; UpdateObjects(0.0, true); } - private void UpdateSectionElement(int SectionIndex, int ElementIndex, Vector3 Position, Vector3 Direction, Vector3 Side, bool Show, double TimeElapsed, bool ForceUpdate) + private void UpdateSectionElement(int sectionIndex, int elementIndex, Vector3 position, Vector3 direction, Vector3 side, bool show, double timeElapsed, bool forceUpdate) { //TODO: Check whether the UP and SIDE vectors should actually be recalculated, as this just uses that of the root car { - Vector3 p = Position; + Vector3 p = position; double timeDelta; bool updatefunctions; - if (CarSections[SectionIndex].Groups[0].Elements[ElementIndex].RefreshRate != 0.0) + if (CarSections[sectionIndex].Groups[0].Elements[elementIndex].RefreshRate != 0.0) { - if (CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate >= CarSections[SectionIndex].Groups[0].Elements[ElementIndex].RefreshRate) + if (CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate >= CarSections[sectionIndex].Groups[0].Elements[elementIndex].RefreshRate) { timeDelta = - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate; - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate = - TimeElapsed; + CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate; + CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate = + timeElapsed; updatefunctions = true; } else { - timeDelta = TimeElapsed; - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate += TimeElapsed; + timeDelta = timeElapsed; + CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate += timeElapsed; updatefunctions = false; } } else { - timeDelta = CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate; - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate = TimeElapsed; + timeDelta = CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate; + CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate = timeElapsed; updatefunctions = true; } - if (ForceUpdate) + if (forceUpdate) { updatefunctions = true; } - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].Update(baseCar.baseTrain, baseCar.Index, FrontAxle.Follower.TrackPosition - FrontAxle.Position, p, Direction, Up, Side, updatefunctions, Show, timeDelta, true); + CarSections[sectionIndex].Groups[0].Elements[elementIndex].Update(baseCar.BaseTrain, baseCar.Index, FrontAxle.Follower.TrackPosition - FrontAxle.Position, p, direction, Up, side, updatefunctions, show, timeDelta, true); } } @@ -227,8 +227,8 @@ public void UpdateTopplingCantAndSpring() { double a = baseCar.Specs.RollDueToTopplingAngle + baseCar.Specs.RollDueToCantAngle; - double x = Math.Sign(a) * 0.5 * TrainManagerBase.currentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge * (1.0 - Math.Cos(a)); - double y = Math.Abs(0.5 * TrainManagerBase.currentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge * Math.Sin(a)); + double x = Math.Sign(a) * 0.5 * TrainManagerBase.CurrentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge * (1.0 - Math.Cos(a)); + double y = Math.Abs(0.5 * TrainManagerBase.CurrentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge * Math.Sin(a)); Vector3 c = new Vector3(s.X * x + Up.X * y, s.Y * x + Up.Y * y, s.Z * x + Up.Z * y); FrontAxle.Follower.WorldPosition += c; RearAxle.Follower.WorldPosition += c; diff --git a/source/TrainManager/Car/CarBase.cs b/source/TrainManager/Car/CarBase.cs index 329054a3f..fd400ab7e 100644 --- a/source/TrainManager/Car/CarBase.cs +++ b/source/TrainManager/Car/CarBase.cs @@ -28,7 +28,7 @@ namespace TrainManager.Car public class CarBase : AbstractCar { /// A reference to the base train - public TrainBase baseTrain; + public TrainBase BaseTrain; /// The front bogie public Bogie FrontBogie; /// The rear bogie @@ -98,18 +98,18 @@ public class CarBase : AbstractCar private int trainCarIndex; - public CarBase(TrainBase train, int index, double CoefficientOfFriction, double CoefficientOfRollingResistance, double AerodynamicDragCoefficient) + public CarBase(TrainBase train, int index, double coefficientOfFriction, double coefficientOfRollingResistance, double aerodynamicDragCoefficient) { Specs = new CarPhysics(); Brightness = new Brightness(this); - baseTrain = train; + BaseTrain = train; trainCarIndex = index; CarSections = new CarSection[] { }; - FrontAxle = new Axle(TrainManagerBase.currentHost, train, this, CoefficientOfFriction, CoefficientOfRollingResistance, AerodynamicDragCoefficient); + FrontAxle = new Axle(TrainManagerBase.CurrentHost, train, this, coefficientOfFriction, coefficientOfRollingResistance, aerodynamicDragCoefficient); FrontAxle.Follower.TriggerType = index == 0 ? EventTriggerType.FrontCarFrontAxle : EventTriggerType.OtherCarFrontAxle; - RearAxle = new Axle(TrainManagerBase.currentHost, train, this, CoefficientOfFriction, CoefficientOfRollingResistance, AerodynamicDragCoefficient); - RearAxle.Follower.TriggerType = index == baseTrain.Cars.Length - 1 ? EventTriggerType.RearCarRearAxle : EventTriggerType.OtherCarRearAxle; - BeaconReceiver = new TrackFollower(TrainManagerBase.currentHost, train); + RearAxle = new Axle(TrainManagerBase.CurrentHost, train, this, coefficientOfFriction, coefficientOfRollingResistance, aerodynamicDragCoefficient); + RearAxle.Follower.TriggerType = index == BaseTrain.Cars.Length - 1 ? EventTriggerType.RearCarRearAxle : EventTriggerType.OtherCarRearAxle; + BeaconReceiver = new TrackFollower(TrainManagerBase.CurrentHost, train); FrontBogie = new Bogie(this, false); RearBogie = new Bogie(this, true); Doors = new Door[2]; @@ -132,13 +132,13 @@ public CarBase(TrainBase train, int index, double CoefficientOfFriction, double public CarBase(TrainBase train, int index) { - baseTrain = train; + BaseTrain = train; trainCarIndex = index; CarSections = new CarSection[] { }; CurrentCarSection = -1; - FrontAxle = new Axle(TrainManagerBase.currentHost, train, this); - RearAxle = new Axle(TrainManagerBase.currentHost, train, this); - BeaconReceiver = new TrackFollower(TrainManagerBase.currentHost, train); + FrontAxle = new Axle(TrainManagerBase.CurrentHost, train, this); + RearAxle = new Axle(TrainManagerBase.CurrentHost, train, this); + BeaconReceiver = new TrackFollower(TrainManagerBase.CurrentHost, train); FrontBogie = new Bogie(this, false); RearBogie = new Bogie(this, true); Doors = new Door[2]; @@ -158,43 +158,43 @@ public CarBase(TrainBase train, int index) } /// Moves the car - /// The delta to move - public void Move(double Delta) + /// The delta to move + public void Move(double delta) { - if (baseTrain.State != TrainState.Disposed) + if (BaseTrain.State != TrainState.Disposed) { - FrontAxle.Follower.UpdateRelative(Delta, true, true); - FrontBogie.FrontAxle.Follower.UpdateRelative(Delta, true, true); - FrontBogie.RearAxle.Follower.UpdateRelative(Delta, true, true); - if (baseTrain.State != TrainState.Disposed) - { - RearAxle.Follower.UpdateRelative(Delta, true, true); - RearBogie.FrontAxle.Follower.UpdateRelative(Delta, true, true); - RearBogie.RearAxle.Follower.UpdateRelative(Delta, true, true); - if (baseTrain.State != TrainState.Disposed) + FrontAxle.Follower.UpdateRelative(delta, true, true); + FrontBogie.FrontAxle.Follower.UpdateRelative(delta, true, true); + FrontBogie.RearAxle.Follower.UpdateRelative(delta, true, true); + if (BaseTrain.State != TrainState.Disposed) + { + RearAxle.Follower.UpdateRelative(delta, true, true); + RearBogie.FrontAxle.Follower.UpdateRelative(delta, true, true); + RearBogie.RearAxle.Follower.UpdateRelative(delta, true, true); + if (BaseTrain.State != TrainState.Disposed) { - BeaconReceiver.UpdateRelative(Delta, true, false); + BeaconReceiver.UpdateRelative(delta, true, false); } } } } /// Call this method to update all track followers attached to the car - /// The track position change - /// Whether to update the world co-ordinates - /// Whether to add track innaccuarcy - public void UpdateTrackFollowers(double NewTrackPosition, bool UpdateWorldCoordinates, bool AddTrackInaccurary) + /// The track position change + /// Whether to update the world co-ordinates + /// Whether to add track innaccuarcy + public void UpdateTrackFollowers(double newTrackPosition, bool updateWorldCoordinates, bool addTrackInaccurary) { //Car axles - FrontAxle.Follower.UpdateRelative(NewTrackPosition, UpdateWorldCoordinates, AddTrackInaccurary); - RearAxle.Follower.UpdateRelative(NewTrackPosition, UpdateWorldCoordinates, AddTrackInaccurary); + FrontAxle.Follower.UpdateRelative(newTrackPosition, updateWorldCoordinates, addTrackInaccurary); + RearAxle.Follower.UpdateRelative(newTrackPosition, updateWorldCoordinates, addTrackInaccurary); //Front bogie axles - FrontBogie.FrontAxle.Follower.UpdateRelative(NewTrackPosition, UpdateWorldCoordinates, AddTrackInaccurary); - FrontBogie.RearAxle.Follower.UpdateRelative(NewTrackPosition, UpdateWorldCoordinates, AddTrackInaccurary); + FrontBogie.FrontAxle.Follower.UpdateRelative(newTrackPosition, updateWorldCoordinates, addTrackInaccurary); + FrontBogie.RearAxle.Follower.UpdateRelative(newTrackPosition, updateWorldCoordinates, addTrackInaccurary); //Rear bogie axles - RearBogie.FrontAxle.Follower.UpdateRelative(NewTrackPosition, UpdateWorldCoordinates, AddTrackInaccurary); - RearBogie.RearAxle.Follower.UpdateRelative(NewTrackPosition, UpdateWorldCoordinates, AddTrackInaccurary); + RearBogie.FrontAxle.Follower.UpdateRelative(newTrackPosition, updateWorldCoordinates, addTrackInaccurary); + RearBogie.RearAxle.Follower.UpdateRelative(newTrackPosition, updateWorldCoordinates, addTrackInaccurary); } /// Initializes the car @@ -230,28 +230,28 @@ public void Syncronize() BeaconReceiver.UpdateAbsolute(b, false, false); } - public override void CreateWorldCoordinates(Vector3 Car, out Vector3 Position, out Vector3 Direction) + public override void CreateWorldCoordinates(Vector3 car, out Vector3 position, out Vector3 direction) { - Direction = FrontAxle.Follower.WorldPosition - RearAxle.Follower.WorldPosition; - double t = Direction.NormSquared(); + direction = FrontAxle.Follower.WorldPosition - RearAxle.Follower.WorldPosition; + double t = direction.NormSquared(); if (t != 0.0) { t = 1.0 / Math.Sqrt(t); - Direction *= t; - double sx = Direction.Z * Up.Y - Direction.Y * Up.Z; - double sy = Direction.X * Up.Z - Direction.Z * Up.X; - double sz = Direction.Y * Up.X - Direction.X * Up.Y; + direction *= t; + double sx = direction.Z * Up.Y - direction.Y * Up.Z; + double sy = direction.X * Up.Z - direction.Z * Up.X; + double sz = direction.Y * Up.X - direction.X * Up.Y; double rx = 0.5 * (FrontAxle.Follower.WorldPosition.X + RearAxle.Follower.WorldPosition.X); double ry = 0.5 * (FrontAxle.Follower.WorldPosition.Y + RearAxle.Follower.WorldPosition.Y); double rz = 0.5 * (FrontAxle.Follower.WorldPosition.Z + RearAxle.Follower.WorldPosition.Z); - Position.X = rx + sx * Car.X + Up.X * Car.Y + Direction.X * Car.Z; - Position.Y = ry + sy * Car.X + Up.Y * Car.Y + Direction.Y * Car.Z; - Position.Z = rz + sz * Car.X + Up.Z * Car.Y + Direction.Z * Car.Z; + position.X = rx + sx * car.X + Up.X * car.Y + direction.X * car.Z; + position.Y = ry + sy * car.X + Up.Y * car.Y + direction.Y * car.Z; + position.Z = rz + sz * car.X + Up.Z * car.Y + direction.Z * car.Z; } else { - Position = FrontAxle.Follower.WorldPosition; - Direction = Vector3.Down; + position = FrontAxle.Follower.WorldPosition; + direction = Vector3.Down; } } @@ -320,16 +320,16 @@ public override void Reverse(bool flipInterior = false) RearBogie.RearAxle.Follower.UpdateAbsolute(RearAxle.Position + RearBogie.RearAxle.Position, true, false); } - public override void OpenDoors(bool Left, bool Right) + public override void OpenDoors(bool left, bool right) { bool sl = false, sr = false; - if (Left & !Doors[0].AnticipatedOpen & (baseTrain.SafetySystems.DoorInterlockState == DoorInterlockStates.Left | baseTrain.SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) + if (left & !Doors[0].AnticipatedOpen & (BaseTrain.SafetySystems.DoorInterlockState == DoorInterlockStates.Left | BaseTrain.SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) { Doors[0].AnticipatedOpen = true; sl = true; } - if (Right & !Doors[1].AnticipatedOpen & (baseTrain.SafetySystems.DoorInterlockState == DoorInterlockStates.Right | baseTrain.SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) + if (right & !Doors[1].AnticipatedOpen & (BaseTrain.SafetySystems.DoorInterlockState == DoorInterlockStates.Right | BaseTrain.SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) { Doors[1].AnticipatedOpen = true; sr = true; @@ -369,11 +369,11 @@ public override void OpenDoors(bool Left, bool Right) } } - public override void Uncouple(bool Front, bool Rear) + public override void Uncouple(bool front, bool rear) { - lock (baseTrain.updateLock) + lock (BaseTrain.UpdateLock) { - if (!Front && !Rear) + if (!front && !rear) { return; } @@ -384,49 +384,49 @@ public override void Uncouple(bool Front, bool Rear) newTrain.Handles.Power = new PowerHandle(0, 0, new double[0], new double[0], newTrain); newTrain.Handles.Brake = new BrakeHandle(0, 0, newTrain.Handles.EmergencyBrake, new double[0], new double[0], newTrain); newTrain.Handles.HoldBrake = new HoldBrakeHandle(newTrain); - if (Front) + if (front) { int totalPreceedingCars = trainCarIndex; newTrain.Cars = new CarBase[trainCarIndex]; for (int i = 0; i < totalPreceedingCars; i++) { - newTrain.Cars[i] = baseTrain.Cars[i]; - newTrain.Cars[i].baseTrain = newTrain; + newTrain.Cars[i] = BaseTrain.Cars[i]; + newTrain.Cars[i].BaseTrain = newTrain; } - for (int i = totalPreceedingCars; i < baseTrain.Cars.Length; i++) + for (int i = totalPreceedingCars; i < BaseTrain.Cars.Length; i++) { - baseTrain.Cars[i - totalPreceedingCars] = baseTrain.Cars[i]; - baseTrain.Cars[i].Index = i - totalPreceedingCars; + BaseTrain.Cars[i - totalPreceedingCars] = BaseTrain.Cars[i]; + BaseTrain.Cars[i].Index = i - totalPreceedingCars; } - Array.Resize(ref baseTrain.Cars, baseTrain.Cars.Length - totalPreceedingCars); - baseTrain.Cars[baseTrain.Cars.Length - 1].Coupler.UncoupleSound.Play(baseTrain.Cars[baseTrain.Cars.Length - 1], false); - uncouplingBehaviour = baseTrain.Cars[baseTrain.Cars.Length - 1].Coupler.UncouplingBehaviour; - TrainManagerBase.currentHost.AddTrain(baseTrain, newTrain, false); + Array.Resize(ref BaseTrain.Cars, BaseTrain.Cars.Length - totalPreceedingCars); + BaseTrain.Cars[BaseTrain.Cars.Length - 1].Coupler.UncoupleSound.Play(BaseTrain.Cars[BaseTrain.Cars.Length - 1], false); + uncouplingBehaviour = BaseTrain.Cars[BaseTrain.Cars.Length - 1].Coupler.UncouplingBehaviour; + TrainManagerBase.CurrentHost.AddTrain(BaseTrain, newTrain, false); - if (baseTrain.DriverCar - totalPreceedingCars >= 0) + if (BaseTrain.DriverCar - totalPreceedingCars >= 0) { - baseTrain.DriverCar -= totalPreceedingCars; + BaseTrain.DriverCar -= totalPreceedingCars; } } - if (Rear) + if (rear) { - int totalFollowingCars = baseTrain.Cars.Length - (Index + 1); + int totalFollowingCars = BaseTrain.Cars.Length - (Index + 1); if (totalFollowingCars > 0) { newTrain.Cars = new CarBase[totalFollowingCars]; // Move following cars to new train for (int i = 0; i < totalFollowingCars; i++) { - newTrain.Cars[i] = baseTrain.Cars[Index + i + 1]; - newTrain.Cars[i].baseTrain = newTrain; + newTrain.Cars[i] = BaseTrain.Cars[Index + i + 1]; + newTrain.Cars[i].BaseTrain = newTrain; newTrain.Cars[i].Index = i; } - Array.Resize(ref baseTrain.Cars, baseTrain.Cars.Length - totalFollowingCars); - baseTrain.Cars[baseTrain.Cars.Length - 1].Coupler.connectedCar = baseTrain.Cars[baseTrain.Cars.Length - 1]; + Array.Resize(ref BaseTrain.Cars, BaseTrain.Cars.Length - totalFollowingCars); + BaseTrain.Cars[BaseTrain.Cars.Length - 1].Coupler.ConnectedCar = BaseTrain.Cars[BaseTrain.Cars.Length - 1]; } else { @@ -435,7 +435,7 @@ public override void Uncouple(bool Front, bool Rear) Coupler.UncoupleSound.Play(this, false); uncouplingBehaviour = Coupler.UncouplingBehaviour; - TrainManagerBase.currentHost.AddTrain(baseTrain, newTrain, true); + TrainManagerBase.CurrentHost.AddTrain(BaseTrain, newTrain, true); } for (int i = 0; i < newTrain.Cars.Length; i++) @@ -452,7 +452,7 @@ public override void Uncouple(bool Front, bool Rear) newTrain.Cars[i].Coupler.ChangeSection(0); } - if (baseTrain.DriverCar >= baseTrain.Cars.Length) + if (BaseTrain.DriverCar >= BaseTrain.Cars.Length) { /* * The driver car is no longer in the train @@ -461,16 +461,16 @@ public override void Uncouple(bool Front, bool Rear) * If not found, this will stop at Car 0 */ - for (int i = baseTrain.Cars.Length; i > 0; i--) + for (int i = BaseTrain.Cars.Length; i > 0; i--) { - baseTrain.DriverCar = i - 1; - if (!baseTrain.Cars[i - 1].HasInteriorView) + BaseTrain.DriverCar = i - 1; + if (!BaseTrain.Cars[i - 1].HasInteriorView) { /* * Set the eye position to something vaguely sensible, rather than leaving it on the rails * Whilst there will be no cab, at least it's a bit more usable like this */ - baseTrain.Cars[i - 1].InteriorCamera = new CameraAlignment() + BaseTrain.Cars[i - 1].InteriorCamera = new CameraAlignment() { Position = new Vector3(0, 2, 0.5 * Length) }; @@ -482,34 +482,34 @@ public override void Uncouple(bool Front, bool Rear) } } - if (Front) + if (front) { // Uncoupling the front will always make the car our first - baseTrain.CameraCar = 0; + BaseTrain.CameraCar = 0; } else { - if (baseTrain.CameraCar >= baseTrain.Cars.Length) + if (BaseTrain.CameraCar >= BaseTrain.Cars.Length) { - baseTrain.CameraCar = baseTrain.DriverCar; + BaseTrain.CameraCar = BaseTrain.DriverCar; } } switch (uncouplingBehaviour) { case UncouplingBehaviour.Emergency: - baseTrain.Handles.EmergencyBrake.Apply(); + BaseTrain.Handles.EmergencyBrake.Apply(); newTrain.Handles.EmergencyBrake.Apply(); break; case UncouplingBehaviour.EmergencyUncoupledConsist: newTrain.Handles.EmergencyBrake.Apply(); break; case UncouplingBehaviour.EmergencyPlayer: - baseTrain.Handles.EmergencyBrake.Apply(); + BaseTrain.Handles.EmergencyBrake.Apply(); break; case UncouplingBehaviour.Released: - baseTrain.Handles.Brake.ApplyState(0, false); - baseTrain.Handles.EmergencyBrake.Release(); + BaseTrain.Handles.Brake.ApplyState(0, false); + BaseTrain.Handles.EmergencyBrake.Release(); newTrain.Handles.Brake.ApplyState(0, false); newTrain.Handles.EmergencyBrake.Release(); break; @@ -523,15 +523,15 @@ public override void Uncouple(bool Front, bool Rear) } /// Returns the combination of door states what encountered at the specified car in a train. - /// Whether to include left doors. - /// Whether to include right doors. + /// Whether to include left doors. + /// Whether to include right doors. /// A bit mask combining encountered door states. - public TrainDoorState GetDoorsState(bool Left, bool Right) + public TrainDoorState GetDoorsState(bool left, bool right) { bool opened = false, closed = false, mixed = false; for (int i = 0; i < Doors.Length; i++) { - if (Left & Doors[i].Direction == -1 | Right & Doors[i].Direction == 1) + if (left & Doors[i].Direction == -1 | right & Doors[i].Direction == 1) { if (Doors[i].State == 0.0) { @@ -548,14 +548,14 @@ public TrainDoorState GetDoorsState(bool Left, bool Right) } } - TrainDoorState Result = TrainDoorState.None; - if (opened) Result |= TrainDoorState.Opened; - if (closed) Result |= TrainDoorState.Closed; - if (mixed) Result |= TrainDoorState.Mixed; - if (opened & !closed & !mixed) Result |= TrainDoorState.AllOpened; - if (!opened & closed & !mixed) Result |= TrainDoorState.AllClosed; - if (!opened & !closed & mixed) Result |= TrainDoorState.AllMixed; - return Result; + TrainDoorState result = TrainDoorState.None; + if (opened) result |= TrainDoorState.Opened; + if (closed) result |= TrainDoorState.Closed; + if (mixed) result |= TrainDoorState.Mixed; + if (opened & !closed & !mixed) result |= TrainDoorState.AllOpened; + if (!opened & closed & !mixed) result |= TrainDoorState.AllClosed; + if (!opened & !closed & mixed) result |= TrainDoorState.AllMixed; + return result; } /// Loads Car Sections (Exterior objects etc.) for this car @@ -565,7 +565,7 @@ public void LoadCarSections(UnifiedObject currentObject, bool visibleFromInterio { int j = CarSections.Length; Array.Resize(ref CarSections, j + 1); - CarSections[j] = new CarSection(TrainManagerBase.currentHost, ObjectType.Dynamic, visibleFromInterior, currentObject); + CarSections[j] = new CarSection(TrainManagerBase.CurrentHost, ObjectType.Dynamic, visibleFromInterior, currentObject); } /// Changes the currently visible car section @@ -592,7 +592,7 @@ public void ChangeCarSection(CarSectionType newCarSection, bool trainVisible = f { for (int k = 0; k < CarSections[i].Groups[j].Elements.Length; k++) { - TrainManagerBase.currentHost.HideObject(CarSections[i].Groups[j].Elements[k].internalObject); + TrainManagerBase.CurrentHost.HideObject(CarSections[i].Groups[j].Elements[k].internalObject); } } } @@ -639,10 +639,10 @@ public void ChangeCarSection(CarSectionType newCarSection, bool trainVisible = f } /// Updates the currently displayed objects for this car - /// The time elapsed - /// Whether this is a forced update - /// Whether damping is applied during this update (Skipped on transitions between camera views etc.) - public void UpdateObjects(double TimeElapsed, bool ForceUpdate, bool EnableDamping) + /// The time elapsed + /// Whether this is a forced update + /// Whether damping is applied during this update (Skipped on transitions between camera views etc.) + public void UpdateObjects(double timeElapsed, bool forceUpdate, bool enableDamping) { // calculate positions and directions for section element update @@ -679,7 +679,7 @@ public void UpdateObjects(double TimeElapsed, bool ForceUpdate, bool EnableDampi { for (int i = 0; i < CarSections[cs].Groups[0].Elements.Length; i++) { - UpdateCarSectionElement(cs, 0, i, p, d, s, CurrentlyVisible, TimeElapsed, ForceUpdate, EnableDamping); + UpdateCarSectionElement(cs, 0, i, p, d, s, CurrentlyVisible, timeElapsed, forceUpdate, enableDamping); // brightness change if (CarSections[cs].Groups[0].Elements[i].internalObject != null) @@ -694,7 +694,7 @@ public void UpdateObjects(double TimeElapsed, bool ForceUpdate, bool EnableDampi { for (int i = 0; i < CarSections[cs].Groups[add].Elements.Length; i++) { - UpdateCarSectionElement(cs, add, i, p, d, s, CurrentlyVisible, TimeElapsed, ForceUpdate, EnableDamping); + UpdateCarSectionElement(cs, add, i, p, d, s, CurrentlyVisible, timeElapsed, forceUpdate, enableDamping); // brightness change if (CarSections[cs].Groups[add].Elements[i].internalObject != null) @@ -707,7 +707,7 @@ public void UpdateObjects(double TimeElapsed, bool ForceUpdate, bool EnableDampi { for (int i = 0; i < CarSections[cs].Groups[add].TouchElements.Length; i++) { - UpdateCarSectionTouchElement(cs, add, i, p, d, s, false, TimeElapsed, ForceUpdate, EnableDamping); + UpdateCarSectionTouchElement(cs, add, i, p, d, s, false, timeElapsed, forceUpdate, enableDamping); } } } @@ -726,113 +726,113 @@ public void UpdateObjects(double TimeElapsed, bool ForceUpdate, bool EnableDampi } /// Updates the given car section element - /// The car section - /// The group within the car section - /// The element within the group - /// - /// - /// - /// - /// - /// - /// - private void UpdateCarSectionElement(int SectionIndex, int GroupIndex, int ElementIndex, Vector3 Position, Vector3 Direction, Vector3 Side, bool Show, double TimeElapsed, bool ForceUpdate, bool EnableDamping) + /// The car section + /// The group within the car section + /// The element within the group + /// + /// + /// + /// + /// + /// + /// + private void UpdateCarSectionElement(int sectionIndex, int groupIndex, int elementIndex, Vector3 position, Vector3 direction, Vector3 side, bool show, double timeElapsed, bool forceUpdate, bool enableDamping) { Vector3 p; - if (CarSections[SectionIndex].Type == ObjectType.Overlay & (TrainManagerBase.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.NotAvailable && TrainManagerBase.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.Restricted3D)) + if (CarSections[sectionIndex].Type == ObjectType.Overlay & (TrainManagerBase.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.NotAvailable && TrainManagerBase.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.Restricted3D)) { p = new Vector3(Driver.X, Driver.Y, Driver.Z); } else { - p = Position; + p = position; } double timeDelta; bool updatefunctions; - if (CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].RefreshRate != 0.0) + if (CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].RefreshRate != 0.0) { - if (CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].SecondsSinceLastUpdate >= CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].RefreshRate) + if (CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].SecondsSinceLastUpdate >= CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].RefreshRate) { - timeDelta = CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].SecondsSinceLastUpdate; - CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].SecondsSinceLastUpdate = TimeElapsed; + timeDelta = CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].SecondsSinceLastUpdate; + CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].SecondsSinceLastUpdate = timeElapsed; updatefunctions = true; } else { - timeDelta = TimeElapsed; - CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].SecondsSinceLastUpdate += TimeElapsed; + timeDelta = timeElapsed; + CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].SecondsSinceLastUpdate += timeElapsed; updatefunctions = false; } } else { - timeDelta = CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].SecondsSinceLastUpdate; - CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].SecondsSinceLastUpdate = TimeElapsed; + timeDelta = CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].SecondsSinceLastUpdate; + CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].SecondsSinceLastUpdate = timeElapsed; updatefunctions = true; } - if (ForceUpdate) + if (forceUpdate) { updatefunctions = true; } - CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].Update(baseTrain, Index, FrontAxle.Follower.TrackPosition - FrontAxle.Position, p, Direction, Up, Side, updatefunctions, Show, timeDelta, EnableDamping, false, CarSections[SectionIndex].Type == ObjectType.Overlay ? TrainManagerBase.Renderer.Camera : null); - if (!TrainManagerBase.Renderer.ForceLegacyOpenGL && CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].UpdateVAO) + CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].Update(BaseTrain, Index, FrontAxle.Follower.TrackPosition - FrontAxle.Position, p, direction, Up, side, updatefunctions, show, timeDelta, enableDamping, false, CarSections[sectionIndex].Type == ObjectType.Overlay ? TrainManagerBase.Renderer.Camera : null); + if (!TrainManagerBase.Renderer.ForceLegacyOpenGL && CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].UpdateVAO) { - VAOExtensions.CreateVAO(ref CarSections[SectionIndex].Groups[GroupIndex].Elements[ElementIndex].internalObject.Prototype.Mesh, true, TrainManagerBase.Renderer.DefaultShader.VertexLayout, TrainManagerBase.Renderer); + VAOExtensions.CreateVAO(ref CarSections[sectionIndex].Groups[groupIndex].Elements[elementIndex].internalObject.Prototype.Mesh, true, TrainManagerBase.Renderer.DefaultShader.VertexLayout, TrainManagerBase.Renderer); } } - private void UpdateCarSectionTouchElement(int SectionIndex, int GroupIndex, int ElementIndex, Vector3 Position, Vector3 Direction, Vector3 Side, bool Show, double TimeElapsed, bool ForceUpdate, bool EnableDamping) + private void UpdateCarSectionTouchElement(int sectionIndex, int groupIndex, int elementIndex, Vector3 position, Vector3 direction, Vector3 side, bool show, double timeElapsed, bool forceUpdate, bool enableDamping) { Vector3 p; - if (CarSections[SectionIndex].Type == ObjectType.Overlay & (TrainManagerBase.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.NotAvailable && TrainManagerBase.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.Restricted3D)) + if (CarSections[sectionIndex].Type == ObjectType.Overlay & (TrainManagerBase.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.NotAvailable && TrainManagerBase.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.Restricted3D)) { p = new Vector3(Driver.X, Driver.Y, Driver.Z); } else { - p = Position; + p = position; } double timeDelta; bool updatefunctions; - if (CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.RefreshRate != 0.0) + if (CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.RefreshRate != 0.0) { - if (CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.SecondsSinceLastUpdate >= CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.RefreshRate) + if (CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.SecondsSinceLastUpdate >= CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.RefreshRate) { - timeDelta = CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.SecondsSinceLastUpdate; - CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.SecondsSinceLastUpdate = TimeElapsed; + timeDelta = CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.SecondsSinceLastUpdate; + CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.SecondsSinceLastUpdate = timeElapsed; updatefunctions = true; } else { - timeDelta = TimeElapsed; - CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.SecondsSinceLastUpdate += TimeElapsed; + timeDelta = timeElapsed; + CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.SecondsSinceLastUpdate += timeElapsed; updatefunctions = false; } } else { - timeDelta = CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.SecondsSinceLastUpdate; - CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.SecondsSinceLastUpdate = TimeElapsed; + timeDelta = CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.SecondsSinceLastUpdate; + CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.SecondsSinceLastUpdate = timeElapsed; updatefunctions = true; } - if (ForceUpdate) + if (forceUpdate) { updatefunctions = true; } - CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.Update(baseTrain, Index, FrontAxle.Follower.TrackPosition - FrontAxle.Position, p, Direction, Up, Side, updatefunctions, Show, timeDelta, EnableDamping, true, CarSections[SectionIndex].Type == ObjectType.Overlay ? TrainManagerBase.Renderer.Camera : null); - if (!TrainManagerBase.Renderer.ForceLegacyOpenGL && CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.UpdateVAO) + CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.Update(BaseTrain, Index, FrontAxle.Follower.TrackPosition - FrontAxle.Position, p, direction, Up, side, updatefunctions, show, timeDelta, enableDamping, true, CarSections[sectionIndex].Type == ObjectType.Overlay ? TrainManagerBase.Renderer.Camera : null); + if (!TrainManagerBase.Renderer.ForceLegacyOpenGL && CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.UpdateVAO) { - VAOExtensions.CreateVAO(ref CarSections[SectionIndex].Groups[GroupIndex].TouchElements[ElementIndex].Element.internalObject.Prototype.Mesh, true, TrainManagerBase.Renderer.DefaultShader.VertexLayout, TrainManagerBase.Renderer); + VAOExtensions.CreateVAO(ref CarSections[sectionIndex].Groups[groupIndex].TouchElements[elementIndex].Element.internalObject.Prototype.Mesh, true, TrainManagerBase.Renderer.DefaultShader.VertexLayout, TrainManagerBase.Renderer); } } - public void UpdateTopplingCantAndSpring(double TimeElapsed) + public void UpdateTopplingCantAndSpring(double timeElapsed) { // get direction, up and side vectors Vector3 d = new Vector3(FrontAxle.Follower.WorldPosition - RearAxle.Follower.WorldPosition); @@ -877,29 +877,29 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) double dr = 0.5 + Specs.RollShakeDirection * Specs.RollShakeDirection; if (Specs.RollShakeDirection < 0.0) { - Specs.RollShakeDirection += dr * TimeElapsed; + Specs.RollShakeDirection += dr * timeElapsed; if (Specs.RollShakeDirection > 0.0) Specs.RollShakeDirection = 0.0; } else { - Specs.RollShakeDirection -= dr * TimeElapsed; + Specs.RollShakeDirection -= dr * timeElapsed; if (Specs.RollShakeDirection < 0.0) Specs.RollShakeDirection = 0.0; } } - double SpringAcceleration; + double springAcceleration; if (!Derailed) { - SpringAcceleration = 15.0 * Math.Abs(a1 - a0); + springAcceleration = 15.0 * Math.Abs(a1 - a0); } else { - SpringAcceleration = 1.5 * Math.Abs(a1 - a0); + springAcceleration = 1.5 * Math.Abs(a1 - a0); } - double SpringDeceleration = 0.25 * SpringAcceleration; - Specs.RollDueToShakingAngularSpeed += Math.Sign(a1 - a0) * SpringAcceleration * TimeElapsed; - double x = Math.Sign(Specs.RollDueToShakingAngularSpeed) * SpringDeceleration * TimeElapsed; + double springDeceleration = 0.25 * springAcceleration; + Specs.RollDueToShakingAngularSpeed += Math.Sign(a1 - a0) * springAcceleration * timeElapsed; + double x = Math.Sign(Specs.RollDueToShakingAngularSpeed) * springDeceleration * timeElapsed; if (Math.Abs(x) < Math.Abs(Specs.RollDueToShakingAngularSpeed)) { Specs.RollDueToShakingAngularSpeed -= x; @@ -909,12 +909,12 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) Specs.RollDueToShakingAngularSpeed = 0.0; } - a0 += Specs.RollDueToShakingAngularSpeed * TimeElapsed; + a0 += Specs.RollDueToShakingAngularSpeed * timeElapsed; Specs.RollDueToShakingAngle = a0; } // roll due to cant (incorporates shaking) { - double cantAngle = Math.Atan(Math.Tan(0.5 * (Math.Atan(FrontAxle.Follower.CurveCant) + Math.Atan(RearAxle.Follower.CurveCant))) / TrainManagerBase.currentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge); + double cantAngle = Math.Atan(Math.Tan(0.5 * (Math.Atan(FrontAxle.Follower.CurveCant) + Math.Atan(RearAxle.Follower.CurveCant))) / TrainManagerBase.CurrentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge); Specs.RollDueToCantAngle = cantAngle + Specs.RollDueToShakingAngle; } // pitch due to acceleration @@ -944,12 +944,12 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) double da = a - v; if (da < 0.0) { - v -= j * TimeElapsed; + v -= j * timeElapsed; if (v < a) v = a; } else { - v += j * TimeElapsed; + v += j * timeElapsed; if (v > a) v = a; } @@ -973,14 +973,14 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) } { double a = 3.0 * Math.Sign(Specs.PitchDueToAccelerationTargetAngle - Specs.PitchDueToAccelerationAngle); - Specs.PitchDueToAccelerationAngularSpeed += a * TimeElapsed; + Specs.PitchDueToAccelerationAngularSpeed += a * timeElapsed; double ds = Math.Abs(Specs.PitchDueToAccelerationTargetAngle - Specs.PitchDueToAccelerationAngle); if (Math.Abs(Specs.PitchDueToAccelerationAngularSpeed) > ds) { Specs.PitchDueToAccelerationAngularSpeed = ds * Math.Sign(Specs.PitchDueToAccelerationAngularSpeed); } - Specs.PitchDueToAccelerationAngle += Specs.PitchDueToAccelerationAngularSpeed * TimeElapsed; + Specs.PitchDueToAccelerationAngle += Specs.PitchDueToAccelerationAngularSpeed * timeElapsed; } } // derailment @@ -990,7 +990,7 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) double sa = Math.Sign(a); if (a * sa > Specs.CriticalTopplingAngle) { - baseTrain.Derail(Index, TimeElapsed); + BaseTrain.Derail(Index, timeElapsed); } } @@ -1001,7 +1001,7 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) double ab = Specs.RollDueToTopplingAngle + Specs.RollDueToCantAngle; double h = Specs.CenterOfGravityHeight; double sr = Math.Abs(CurrentSpeed); - double rmax = 2.0 * h * sr * sr / (TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity * TrainManagerBase.currentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge); + double rmax = 2.0 * h * sr * sr / (TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity * TrainManagerBase.CurrentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge); double ta; Topples = false; if (Derailed) @@ -1015,7 +1015,7 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) { if (r < rmax) { - double s0 = Math.Sqrt(r * TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity * TrainManagerBase.currentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge / (2.0 * h)); + double s0 = Math.Sqrt(r * TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity * TrainManagerBase.CurrentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge / (2.0 * h)); const double fac = 0.25; // arbitrary coefficient ta = -fac * (sr - s0) * rs; Topples = true; @@ -1044,13 +1044,13 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) { double da = a - ta; if (td > da) td = da; - a -= td * TimeElapsed; + a -= td * timeElapsed; } else if (a < ta) { double da = ta - a; if (td > da) td = da; - a += td * TimeElapsed; + a += td * timeElapsed; } Specs.RollDueToTopplingAngle = a; @@ -1063,8 +1063,8 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) // apply position due to cant/toppling { double a = Specs.RollDueToTopplingAngle + Specs.RollDueToCantAngle; - double x = Math.Sign(a) * 0.5 * TrainManagerBase.currentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge * (1.0 - Math.Cos(a)); - double y = Math.Abs(0.5 * TrainManagerBase.currentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge * Math.Sin(a)); + double x = Math.Sign(a) * 0.5 * TrainManagerBase.CurrentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge * (1.0 - Math.Cos(a)); + double y = Math.Abs(0.5 * TrainManagerBase.CurrentHost.Tracks[FrontAxle.Follower.TrackIndex].RailGauge * Math.Sin(a)); Vector3 cc = new Vector3(s.X * x + Up.X * y, s.Y * x + Up.Y * y, s.Z * x + Up.Z * y); FrontAxle.Follower.WorldPosition += cc; RearAxle.Follower.WorldPosition += cc; @@ -1088,8 +1088,8 @@ public void UpdateTopplingCantAndSpring(double TimeElapsed) RearAxle.Follower.WorldPosition += cc; } - Suspension.Update(TimeElapsed); - Flange.Update(TimeElapsed); + Suspension.Update(timeElapsed); + Flange.Update(timeElapsed); } /// Updates the position of the camera relative to this car @@ -1104,7 +1104,7 @@ public void UpdateCamera() double ry = 0.5 * (FrontAxle.Follower.WorldPosition.Y + RearAxle.Follower.WorldPosition.Y); double rz = 0.5 * (FrontAxle.Follower.WorldPosition.Z + RearAxle.Follower.WorldPosition.Z); Vector3 cameraPosition; - Vector3 driverPosition = this.HasInteriorView ? Driver : this.baseTrain.Cars[this.baseTrain.DriverCar].Driver; + Vector3 driverPosition = this.HasInteriorView ? Driver : this.BaseTrain.Cars[this.BaseTrain.DriverCar].Driver; cameraPosition.X = rx + sx * driverPosition.X + Up.X * driverPosition.Y + direction.X * driverPosition.Z; cameraPosition.Y = ry + sy * driverPosition.X + Up.Y * driverPosition.Y + direction.Y * driverPosition.Z; cameraPosition.Z = rz + sz * driverPosition.X + Up.Z * driverPosition.Y + direction.Z * driverPosition.Z; @@ -1118,25 +1118,25 @@ public void UpdateCamera() TrainManagerBase.Renderer.CameraTrackFollower.UpdateAbsolute(tp, false, false); } - public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, double DecelerationDueToBrake, out double Speed) + public void UpdateSpeed(double timeElapsed, double decelerationDueToMotor, double decelerationDueToBrake, out double speed) { - double PowerRollingCouplerAcceleration; + double powerRollingCouplerAcceleration; // rolling on an incline { double a = FrontAxle.Follower.WorldDirection.Y; double b = RearAxle.Follower.WorldDirection.Y; - PowerRollingCouplerAcceleration = + powerRollingCouplerAcceleration = -0.5 * (a + b) * TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity; } // friction - double FrictionBrakeAcceleration; + double frictionBrakeAcceleration; { double v = Math.Abs(CurrentSpeed); - double t = Index == 0 & CurrentSpeed >= 0.0 || Index == baseTrain.NumberOfCars - 1 & CurrentSpeed <= 0.0 ? Specs.ExposedFrontalArea : Specs.UnexposedFrontalArea; + double t = Index == 0 & CurrentSpeed >= 0.0 || Index == BaseTrain.NumberOfCars - 1 & CurrentSpeed <= 0.0 ? Specs.ExposedFrontalArea : Specs.UnexposedFrontalArea; double a = FrontAxle.GetResistance(v, t, TrainManagerBase.CurrentRoute.Atmosphere.GetAirDensity(FrontAxle.Follower.WorldPosition.Y), TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity); double b = RearAxle.GetResistance(v, t, TrainManagerBase.CurrentRoute.Atmosphere.GetAirDensity(FrontAxle.Follower.WorldPosition.Y), TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity); - FrictionBrakeAcceleration = 0.5 * (a + b); + frictionBrakeAcceleration = 0.5 * (a + b); } // power double wheelspin = 0.0; @@ -1152,21 +1152,21 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl wheelSlipAccelerationBrakeRear = RearAxle.CriticalWheelSlipAccelerationForFrictionBrake(TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity); } - if (DecelerationDueToMotor == 0.0) + if (decelerationDueToMotor == 0.0) { double a; - if (DecelerationDueToMotor == 0.0 || !Specs.IsMotorCar) + if (decelerationDueToMotor == 0.0 || !Specs.IsMotorCar) { - if (baseTrain.Handles.Reverser.Actual != 0 & baseTrain.Handles.Power.Actual > 0 & - !baseTrain.Handles.HoldBrake.Actual & - !baseTrain.Handles.EmergencyBrake.Actual) + if (BaseTrain.Handles.Reverser.Actual != 0 & BaseTrain.Handles.Power.Actual > 0 & + !BaseTrain.Handles.HoldBrake.Actual & + !BaseTrain.Handles.EmergencyBrake.Actual) { // target acceleration - if (baseTrain.Handles.Power.Actual - 1 < Specs.AccelerationCurves.Length) + if (BaseTrain.Handles.Power.Actual - 1 < Specs.AccelerationCurves.Length) { // Load factor is a constant 1.0 for anything prior to BVE5 // This will need to be changed when the relevant branch is merged in - a = Specs.AccelerationCurves[baseTrain.Handles.Power.Actual - 1].GetAccelerationOutput((double)baseTrain.Handles.Reverser.Actual * CurrentSpeed, 1.0); + a = Specs.AccelerationCurves[BaseTrain.Handles.Power.Actual - 1].GetAccelerationOutput((double)BaseTrain.Handles.Reverser.Actual * CurrentSpeed, 1.0); } else { @@ -1198,7 +1198,7 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl else { FrontAxle.CurrentWheelSlip = true; - wheelspin += (double)baseTrain.Handles.Reverser.Actual * a * CurrentMass; + wheelspin += (double)BaseTrain.Handles.Reverser.Actual * a * CurrentMass; } if (a < wheelSlipAccelerationMotorRear) @@ -1208,12 +1208,12 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl else { RearAxle.CurrentWheelSlip = true; - wheelspin += (double)baseTrain.Handles.Reverser.Actual * a * CurrentMass; + wheelspin += (double)BaseTrain.Handles.Reverser.Actual * a * CurrentMass; } Specs.MaxMotorAcceleration = a; // Update constant speed device - this.ConstSpeed.Update(ref a, baseTrain.Specs.CurrentConstSpeed, baseTrain.Handles.Reverser.Actual); + this.ConstSpeed.Update(ref a, BaseTrain.Specs.CurrentConstSpeed, BaseTrain.Handles.Reverser.Actual); // finalize if (wheelspin != 0.0) a = 0.0; @@ -1241,11 +1241,11 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl { if (Specs.MotorAcceleration < 0.0) { - Specs.MotorAcceleration += CarBrake.JerkDown * TimeElapsed; + Specs.MotorAcceleration += CarBrake.JerkDown * timeElapsed; } else { - Specs.MotorAcceleration += Specs.JerkPowerUp * TimeElapsed; + Specs.MotorAcceleration += Specs.JerkPowerUp * timeElapsed; } if (Specs.MotorAcceleration > a) @@ -1255,7 +1255,7 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl } else { - Specs.MotorAcceleration -= Specs.JerkPowerDown * TimeElapsed; + Specs.MotorAcceleration -= Specs.JerkPowerDown * timeElapsed; if (Specs.MotorAcceleration < a) { Specs.MotorAcceleration = a; @@ -1268,25 +1268,25 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl } } - ReAdhesionDevice.Update(TimeElapsed); + ReAdhesionDevice.Update(timeElapsed); // brake bool wheellock = wheelspin == 0.0 & Derailed; if (!Derailed & wheelspin == 0.0) { double a; // motor - if (Specs.IsMotorCar & DecelerationDueToMotor != 0.0) + if (Specs.IsMotorCar & decelerationDueToMotor != 0.0) { - a = -DecelerationDueToMotor; + a = -decelerationDueToMotor; if (Specs.MotorAcceleration > a) { if (Specs.MotorAcceleration > 0.0) { - Specs.MotorAcceleration -= Specs.JerkPowerDown * TimeElapsed; + Specs.MotorAcceleration -= Specs.JerkPowerDown * timeElapsed; } else { - Specs.MotorAcceleration -= CarBrake.JerkUp * TimeElapsed; + Specs.MotorAcceleration -= CarBrake.JerkUp * timeElapsed; } if (Specs.MotorAcceleration < a) @@ -1296,7 +1296,7 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl } else { - Specs.MotorAcceleration += CarBrake.JerkDown * TimeElapsed; + Specs.MotorAcceleration += CarBrake.JerkDown * timeElapsed; if (Specs.MotorAcceleration > a) { Specs.MotorAcceleration = a; @@ -1305,7 +1305,7 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl } // brake - a = DecelerationDueToBrake; + a = decelerationDueToBrake; if (CurrentSpeed >= -0.01 & CurrentSpeed <= 0.01) { double rf = FrontAxle.Follower.WorldDirection.Y; @@ -1322,7 +1322,7 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl } else { - FrictionBrakeAcceleration += 0.5 * a * factor; + frictionBrakeAcceleration += 0.5 * a * factor; } if (a >= wheelSlipAccelerationBrakeRear) @@ -1331,23 +1331,23 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl } else { - FrictionBrakeAcceleration += 0.5 * a * factor; + frictionBrakeAcceleration += 0.5 * a * factor; } } else if (Derailed) { - FrictionBrakeAcceleration += TrainBase.CoefficientOfGroundFriction * + frictionBrakeAcceleration += TrainBase.CoefficientOfGroundFriction * TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity; } // motor - if (baseTrain.Handles.Reverser.Actual != 0) + if (BaseTrain.Handles.Reverser.Actual != 0) { double factor = EmptyMass / CurrentMass; if (Specs.MotorAcceleration > 0.0) { - PowerRollingCouplerAcceleration += - (double) baseTrain.Handles.Reverser.Actual * Specs.MotorAcceleration * factor; + powerRollingCouplerAcceleration += + (double) BaseTrain.Handles.Reverser.Actual * Specs.MotorAcceleration * factor; } else { @@ -1358,7 +1358,7 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl } else if (!Derailed) { - FrictionBrakeAcceleration += 0.5 * a * factor; + frictionBrakeAcceleration += 0.5 * a * factor; } if (a >= wheelSlipAccelerationMotorRear) @@ -1367,7 +1367,7 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl } else { - FrictionBrakeAcceleration += 0.5 * a * factor; + frictionBrakeAcceleration += 0.5 * a * factor; } } } @@ -1394,7 +1394,7 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl double diff = target - Specs.PerceivedSpeed; double rate = (diff < 0.0 ? 5.0 : 1.0) * TrainManagerBase.CurrentRoute.Atmosphere.AccelerationDueToGravity * - TimeElapsed; + timeElapsed; rate *= 1.0 - 0.7 / (diff * diff + 1.0); double factor = rate * rate; factor = 1.0 - factor / (factor + 1000.0); @@ -1411,45 +1411,45 @@ public void UpdateSpeed(double TimeElapsed, double DecelerationDueToMotor, doubl // calculate new speed { int d = Math.Sign(CurrentSpeed); - double a = PowerRollingCouplerAcceleration; - double b = FrictionBrakeAcceleration; + double a = powerRollingCouplerAcceleration; + double b = frictionBrakeAcceleration; if (Math.Abs(a) < b) { if (Math.Sign(a) == d) { if (d == 0) { - Speed = 0.0; + speed = 0.0; } else { - double c = (b - Math.Abs(a)) * TimeElapsed; + double c = (b - Math.Abs(a)) * timeElapsed; if (Math.Abs(CurrentSpeed) > c) { - Speed = CurrentSpeed - d * c; + speed = CurrentSpeed - d * c; } else { - Speed = 0.0; + speed = 0.0; } } } else { - double c = (Math.Abs(a) + b) * TimeElapsed; + double c = (Math.Abs(a) + b) * timeElapsed; if (Math.Abs(CurrentSpeed) > c) { - Speed = CurrentSpeed - d * c; + speed = CurrentSpeed - d * c; } else { - Speed = 0.0; + speed = 0.0; } } } else { - Speed = CurrentSpeed + (a - b * d) * TimeElapsed; + speed = CurrentSpeed + (a - b * d) * timeElapsed; } } } @@ -1520,7 +1520,7 @@ public void DetermineDoorClosingSpeed() public override void Derail() { - baseTrain.Derail(this, 0.0); + BaseTrain.Derail(this, 0.0); } } } diff --git a/source/TrainManager/Car/Coupler/Coupler.cs b/source/TrainManager/Car/Coupler/Coupler.cs index 0830c7f90..f6b100fbe 100644 --- a/source/TrainManager/Car/Coupler/Coupler.cs +++ b/source/TrainManager/Car/Coupler/Coupler.cs @@ -18,11 +18,11 @@ public class Coupler : AbstractCoupler /// The base car which the coupling is attached to /// This is the FRONT car when travelling in the notional forwards direction - internal CarBase baseCar; + internal CarBase BaseCar; /// The connected car /// This is the REAR car when travelling in the notional forwards direction - internal CarBase connectedCar; + internal CarBase ConnectedCar; /// The sound played when this coupler is uncoupled public CarSound UncoupleSound; @@ -32,17 +32,17 @@ public class Coupler : AbstractCoupler private bool canUncouple; - internal AbstractTrain baseTrain; + internal AbstractTrain BaseTrain; public Coupler(double minimumDistance, double maximumDistance, CarBase frontCar, CarBase rearCar, AbstractTrain train) { MinimumDistanceBetweenCars = minimumDistance; MaximumDistanceBetweenCars = maximumDistance; - baseCar = frontCar; - connectedCar = rearCar ?? frontCar; + BaseCar = frontCar; + ConnectedCar = rearCar ?? frontCar; CarSections = new CarSection[] { }; - baseTrain = train; + BaseTrain = train; ChangeSection(-1); UncoupleSound = new CarSound(); canUncouple = true; @@ -51,21 +51,21 @@ public Coupler(double minimumDistance, double maximumDistance, CarBase frontCar, public override bool CanUncouple { - get => connectedCar != baseCar && canUncouple; + get => ConnectedCar != BaseCar && canUncouple; set => canUncouple = value; } - public void UpdateObjects(double TimeElapsed, bool ForceUpdate) + public void UpdateObjects(double timeElapsed, bool forceUpdate) { // calculate positions and directions for section element update - Vector3 d = new Vector3(baseCar.RearAxle.Follower.WorldPosition - connectedCar.FrontAxle.Follower.WorldPosition); + Vector3 d = new Vector3(BaseCar.RearAxle.Follower.WorldPosition - ConnectedCar.FrontAxle.Follower.WorldPosition); Vector3 u, s; double t = d.NormSquared(); if (t != 0.0) { t = 1.0 / Math.Sqrt(t); d *= t; - u = new Vector3((baseCar.Up + connectedCar.Up) * 0.5); + u = new Vector3((BaseCar.Up + ConnectedCar.Up) * 0.5); s.X = d.Z * u.Y - d.Y * u.Z; s.Y = d.X * u.Z - d.Z * u.X; s.Z = d.Y * u.X - d.X * u.Y; @@ -76,14 +76,14 @@ public void UpdateObjects(double TimeElapsed, bool ForceUpdate) s = Vector3.Right; } - Vector3 p = new Vector3(0.5 * (baseCar.RearAxle.Follower.WorldPosition + connectedCar.FrontAxle.Follower.WorldPosition)); + Vector3 p = new Vector3(0.5 * (BaseCar.RearAxle.Follower.WorldPosition + ConnectedCar.FrontAxle.Follower.WorldPosition)); // determine visibility Vector3 cd = new Vector3(p - TrainManagerBase.Renderer.Camera.AbsolutePosition); double dist = cd.NormSquared(); - double bid = TrainManagerBase.Renderer.Camera.ViewingDistance + baseCar.Length; - bool CurrentlyVisible = dist < bid * bid; + double bid = TrainManagerBase.Renderer.Camera.ViewingDistance + BaseCar.Length; + bool currentlyVisible = dist < bid * bid; // Updates the brightness value - byte dnb = (byte)baseCar.Brightness.CurrentBrightness(TrainManagerBase.Renderer.Lighting.DynamicCabBrightness, 1.0); + byte dnb = (byte)BaseCar.Brightness.CurrentBrightness(TrainManagerBase.Renderer.Lighting.DynamicCabBrightness, 1.0); // update current section int cs = CurrentCarSection; @@ -93,7 +93,7 @@ public void UpdateObjects(double TimeElapsed, bool ForceUpdate) { for (int i = 0; i < CarSections[cs].Groups[0].Elements.Length; i++) { - UpdateSectionElement(cs, i, p, d, u, s, CurrentlyVisible, TimeElapsed, ForceUpdate); + UpdateSectionElement(cs, i, p, d, u, s, currentlyVisible, timeElapsed, forceUpdate); // brightness change if (CarSections[cs].Groups[0].Elements[i].internalObject != null) @@ -105,7 +105,7 @@ public void UpdateObjects(double TimeElapsed, bool ForceUpdate) } } - public void ChangeSection(int SectionIndex) + public void ChangeSection(int sectionIndex) { if (CarSections.Length == 0) { @@ -118,60 +118,60 @@ public void ChangeSection(int SectionIndex) { for (int j = 0; j < CarSections[i].Groups[0].Elements.Length; j++) { - TrainManagerBase.currentHost.HideObject(CarSections[i].Groups[0].Elements[j].internalObject); + TrainManagerBase.CurrentHost.HideObject(CarSections[i].Groups[0].Elements[j].internalObject); } } - if (SectionIndex >= 0) + if (sectionIndex >= 0) { - CarSections[SectionIndex].Initialize(baseCar.CurrentlyVisible); - for (int j = 0; j < CarSections[SectionIndex].Groups[0].Elements.Length; j++) + CarSections[sectionIndex].Initialize(BaseCar.CurrentlyVisible); + for (int j = 0; j < CarSections[sectionIndex].Groups[0].Elements.Length; j++) { - TrainManagerBase.currentHost.ShowObject(CarSections[SectionIndex].Groups[0].Elements[j].internalObject, ObjectType.Dynamic); + TrainManagerBase.CurrentHost.ShowObject(CarSections[sectionIndex].Groups[0].Elements[j].internalObject, ObjectType.Dynamic); } } - CurrentCarSection = SectionIndex; + CurrentCarSection = sectionIndex; UpdateObjects(0.0, true); } - private void UpdateSectionElement(int SectionIndex, int ElementIndex, Vector3 Position, Vector3 Direction, Vector3 Up, Vector3 Side, bool Show, double TimeElapsed, bool ForceUpdate) + private void UpdateSectionElement(int sectionIndex, int elementIndex, Vector3 position, Vector3 direction, Vector3 up, Vector3 side, bool show, double timeElapsed, bool forceUpdate) { { - Vector3 p = Position; + Vector3 p = position; double timeDelta; bool updatefunctions; - if (CarSections[SectionIndex].Groups[0].Elements[ElementIndex].RefreshRate != 0.0) + if (CarSections[sectionIndex].Groups[0].Elements[elementIndex].RefreshRate != 0.0) { - if (CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate >= CarSections[SectionIndex].Groups[0].Elements[ElementIndex].RefreshRate) + if (CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate >= CarSections[sectionIndex].Groups[0].Elements[elementIndex].RefreshRate) { timeDelta = - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate; - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate = - TimeElapsed; + CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate; + CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate = + timeElapsed; updatefunctions = true; } else { - timeDelta = TimeElapsed; - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate += TimeElapsed; + timeDelta = timeElapsed; + CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate += timeElapsed; updatefunctions = false; } } else { - timeDelta = CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate; - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].SecondsSinceLastUpdate = TimeElapsed; + timeDelta = CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate; + CarSections[sectionIndex].Groups[0].Elements[elementIndex].SecondsSinceLastUpdate = timeElapsed; updatefunctions = true; } - if (ForceUpdate) + if (forceUpdate) { updatefunctions = true; } - CarSections[SectionIndex].Groups[0].Elements[ElementIndex].Update(baseTrain, baseCar.Index, (baseCar.RearAxle.Follower.TrackPosition + connectedCar.FrontAxle.Follower.TrackPosition) * 0.5, p, Direction, Up, Side, updatefunctions, Show, timeDelta, true); + CarSections[sectionIndex].Groups[0].Elements[elementIndex].Update(BaseTrain, BaseCar.Index, (BaseCar.RearAxle.Follower.TrackPosition + ConnectedCar.FrontAxle.Follower.TrackPosition) * 0.5, p, direction, up, side, updatefunctions, show, timeDelta, true); } } @@ -179,7 +179,7 @@ public void LoadCarSections(UnifiedObject currentObject, bool visibleFromInterio { int j = CarSections.Length; Array.Resize(ref CarSections, j + 1); - CarSections[j] = new CarSection(TrainManagerBase.currentHost, ObjectType.Dynamic, visibleFromInterior, currentObject); + CarSections[j] = new CarSection(TrainManagerBase.CurrentHost, ObjectType.Dynamic, visibleFromInterior, currentObject); } } } diff --git a/source/TrainManager/Car/Systems/AbstractReAdhesionDevice.cs b/source/TrainManager/Car/Systems/AbstractReAdhesionDevice.cs index b372dbf0e..3c3662055 100644 --- a/source/TrainManager/Car/Systems/AbstractReAdhesionDevice.cs +++ b/source/TrainManager/Car/Systems/AbstractReAdhesionDevice.cs @@ -12,8 +12,8 @@ internal AbstractReAdhesionDevice(CarBase car) } /// Called once a frame to update the re-adhesion device when powering - /// The elapsed time - public virtual void Update(double TimeElapsed) + /// The elapsed time + public virtual void Update(double timeElapsed) { } diff --git a/source/TrainManager/Car/Systems/ConstantSpeedDevice.cs b/source/TrainManager/Car/Systems/ConstantSpeedDevice.cs index 3ea56a47a..54fbc6d8d 100644 --- a/source/TrainManager/Car/Systems/ConstantSpeedDevice.cs +++ b/source/TrainManager/Car/Systems/ConstantSpeedDevice.cs @@ -19,33 +19,33 @@ public CarConstSpeed(CarBase car) } /// Called once a frame to update the constant speed device - /// The current acceleration output of the train - /// Whether the constant speed device is enabled (As this refers to the whole train) - /// The current position of the reverser handle - public void Update(ref double Acceleration, bool Enabled, ReverserPosition ReverserPosition) + /// The current acceleration output of the train + /// Whether the constant speed device is enabled (As this refers to the whole train) + /// The current position of the reverser handle + public void Update(ref double acceleration, bool enabled, ReverserPosition reverserPosition) { - if (!Enabled) + if (!enabled) { - this.CurrentAccelerationOutput = Acceleration; + this.CurrentAccelerationOutput = acceleration; return; } - if (TrainManagerBase.currentHost.InGameTime >= this.NextUpdateTime) + if (TrainManagerBase.CurrentHost.InGameTime >= this.NextUpdateTime) { - this.NextUpdateTime = TrainManagerBase.currentHost.InGameTime + UpdateInterval; - this.CurrentAccelerationOutput -= 0.8 * this.Car.Specs.Acceleration * (double)ReverserPosition; + this.NextUpdateTime = TrainManagerBase.CurrentHost.InGameTime + UpdateInterval; + this.CurrentAccelerationOutput -= 0.8 * this.Car.Specs.Acceleration * (double)reverserPosition; if (this.CurrentAccelerationOutput < 0.0) { this.CurrentAccelerationOutput = 0.0; } } - if (Acceleration > CurrentAccelerationOutput) + if (acceleration > CurrentAccelerationOutput) { - Acceleration = CurrentAccelerationOutput; + acceleration = CurrentAccelerationOutput; } - if (Acceleration < 0.0) + if (acceleration < 0.0) { - Acceleration = 0.0; + acceleration = 0.0; } } } diff --git a/source/TrainManager/Car/Systems/FlangeSounds.cs b/source/TrainManager/Car/Systems/FlangeSounds.cs index 2bdb3529d..38f58e01d 100644 --- a/source/TrainManager/Car/Systems/FlangeSounds.cs +++ b/source/TrainManager/Car/Systems/FlangeSounds.cs @@ -21,7 +21,7 @@ public Flange(CarBase car) Sounds = new Dictionary(); } - public void Update(double TimeElapsed) + public void Update(double timeElapsed) { if (Sounds.Count == 0) { @@ -55,12 +55,12 @@ public void Update(double TimeElapsed) if (basegain > 0.75) basegain = 0.75; if (pitch > Pitch) { - Pitch += TimeElapsed; + Pitch += timeElapsed; if (Pitch > pitch) Pitch = pitch; } else { - Pitch -= TimeElapsed; + Pitch -= timeElapsed; if (Pitch < pitch) Pitch = pitch; } @@ -75,12 +75,12 @@ public void Update(double TimeElapsed) if (key == baseCar.FrontAxle.FlangeIndex | key == baseCar.RearAxle.FlangeIndex) { - Sounds[key].TargetVolume += TimeElapsed; + Sounds[key].TargetVolume += timeElapsed; if (Sounds[key].TargetVolume > 1.0) Sounds[key].TargetVolume = 1.0; } else { - Sounds[key].TargetVolume -= TimeElapsed; + Sounds[key].TargetVolume -= timeElapsed; if (Sounds[key].TargetVolume < 0.0) Sounds[key].TargetVolume = 0.0; } diff --git a/source/TrainManager/Car/Systems/HoldBrake.cs b/source/TrainManager/Car/Systems/HoldBrake.cs index 99fae9529..c330e39b7 100644 --- a/source/TrainManager/Car/Systems/HoldBrake.cs +++ b/source/TrainManager/Car/Systems/HoldBrake.cs @@ -19,27 +19,27 @@ public CarHoldBrake(CarBase car) } /// Called once a frame to update the Car Hold Brake - /// The current motor deceleration output of the train - /// Whether the Car Hold Brake is enabled (As this refers to the whole train) - public void Update(ref double Deceleration, bool Enabled) + /// The current motor deceleration output of the train + /// Whether the Car Hold Brake is enabled (As this refers to the whole train) + public void Update(ref double deceleration, bool enabled) { - if (Enabled & Deceleration == 0.0) + if (enabled & deceleration == 0.0) { - if (TrainManagerBase.currentHost.InGameTime >= NextUpdateTime) + if (TrainManagerBase.CurrentHost.InGameTime >= NextUpdateTime) { - NextUpdateTime = TrainManagerBase.currentHost.InGameTime + UpdateInterval; + NextUpdateTime = TrainManagerBase.CurrentHost.InGameTime + UpdateInterval; this.CurrentDecelerationOutput += 0.8 * Car.Specs.Acceleration * Math.Sign(Car.Specs.PerceivedSpeed); if (this.CurrentDecelerationOutput < 0.0) { this.CurrentDecelerationOutput = 0.0; } - double a = Car.CarBrake.motorDeceleration; + double a = Car.CarBrake.MotorDeceleration; if (this.CurrentDecelerationOutput > a) { this.CurrentDecelerationOutput = a; } } - Deceleration = this.CurrentDecelerationOutput; + deceleration = this.CurrentDecelerationOutput; } else { diff --git a/source/TrainManager/Car/Systems/ReadhesionDevice.cs b/source/TrainManager/Car/Systems/ReadhesionDevice.cs index 6bc09671b..3967f5ab8 100644 --- a/source/TrainManager/Car/Systems/ReadhesionDevice.cs +++ b/source/TrainManager/Car/Systems/ReadhesionDevice.cs @@ -67,14 +67,14 @@ public BveReAdhesionDevice(CarBase car, ReadhesionDeviceType type) : base(car) } } - public override void Update(double TimeElapsed) + public override void Update(double timeElapsed) { - if (TrainManagerBase.currentHost.InGameTime < NextUpdateTime || Car.Specs.MaxMotorAcceleration == -1) + if (TrainManagerBase.CurrentHost.InGameTime < NextUpdateTime || Car.Specs.MaxMotorAcceleration == -1) { return; } - NextUpdateTime = TrainManagerBase.currentHost.InGameTime + this.UpdateInterval; + NextUpdateTime = TrainManagerBase.CurrentHost.InGameTime + this.UpdateInterval; if (Car.FrontAxle.CurrentWheelSlip | Car.RearAxle.CurrentWheelSlip) { MaximumAccelerationOutput = Car.Specs.MaxMotorAcceleration * this.ApplicationFactor; diff --git a/source/TrainManager/Car/Systems/RunSounds.cs b/source/TrainManager/Car/Systems/RunSounds.cs index d33a8e60e..b70fa7569 100644 --- a/source/TrainManager/Car/Systems/RunSounds.cs +++ b/source/TrainManager/Car/Systems/RunSounds.cs @@ -21,8 +21,8 @@ public RunSounds(CarBase car) } /// Updates all run sounds - /// The elapsed time - public void Update(double TimeElapsed) + /// The elapsed time + public void Update(double timeElapsed) { if (Sounds.Count == 0) { @@ -42,7 +42,7 @@ public void Update(double TimeElapsed) { if (baseCar.Index != 0) { - NextReasynchronizationPosition = baseCar.baseTrain.Cars[0].FrontAxle.Follower.TrackPosition; + NextReasynchronizationPosition = baseCar.BaseTrain.Cars[0].FrontAxle.Follower.TrackPosition; } } else if (NextReasynchronizationPosition == double.MaxValue & baseCar.FrontAxle.RunIndex >= 0) @@ -59,7 +59,7 @@ public void Update(double TimeElapsed) if (runSound.Buffer.Duration > 0.0) { double offset = distance > maxDistance ? 25.0 : 300.0; - NextReasynchronizationPosition = runSound.Buffer.Duration * Math.Ceiling((baseCar.baseTrain.Cars[0].FrontAxle.Follower.TrackPosition + offset) / runSound.Buffer.Duration); + NextReasynchronizationPosition = runSound.Buffer.Duration * Math.Ceiling((baseCar.BaseTrain.Cars[0].FrontAxle.Follower.TrackPosition + offset) / runSound.Buffer.Duration); } } } @@ -81,12 +81,12 @@ public void Update(double TimeElapsed) int key = Sounds.ElementAt(j).Key; if (key == baseCar.FrontAxle.RunIndex | key == baseCar.RearAxle.RunIndex) { - Sounds[key].TargetVolume += 3.0 * TimeElapsed; + Sounds[key].TargetVolume += 3.0 * timeElapsed; if (Sounds[key].TargetVolume > 1.0) Sounds[key].TargetVolume = 1.0; } else { - Sounds[key].TargetVolume -= 3.0 * TimeElapsed; + Sounds[key].TargetVolume -= 3.0 * timeElapsed; if (Sounds[key].TargetVolume < 0.0) Sounds[key].TargetVolume = 0.0; } @@ -119,9 +119,9 @@ public void Update(double TimeElapsed) /// Updates the sounds for a specific run index /// Used by TE2 only - /// The elapsed time - /// The run index to update - public void Update(double TimeElapsed, int RunIndex) + /// The elapsed time + /// The run index to update + public void Update(double timeElapsed, int runIndex) { if (Sounds.Count == 0) { @@ -136,9 +136,9 @@ public void Update(double TimeElapsed, int RunIndex) for (int i = 0; i < Sounds.Count; i++) { int key = Sounds.ElementAt(i).Key; - if (key == RunIndex) + if (key == runIndex) { - Sounds[key].TargetVolume += 3.0 * TimeElapsed; + Sounds[key].TargetVolume += 3.0 * timeElapsed; if (Sounds[key].TargetVolume > 1.0) { @@ -147,7 +147,7 @@ public void Update(double TimeElapsed, int RunIndex) } else { - Sounds[key].TargetVolume -= 3.0 * TimeElapsed; + Sounds[key].TargetVolume -= 3.0 * timeElapsed; if (Sounds[key].TargetVolume < 0.0) { @@ -181,7 +181,7 @@ public void Stop() for (int j = 0; j < Sounds.Count; j++) { int key = Sounds.ElementAt(j).Key; - TrainManagerBase.currentHost.StopSound(Sounds[key].Source); + TrainManagerBase.CurrentHost.StopSound(Sounds[key].Source); } } diff --git a/source/TrainManager/Car/Systems/Suspension.cs b/source/TrainManager/Car/Systems/Suspension.cs index 3f0717ed5..b176e786a 100644 --- a/source/TrainManager/Car/Systems/Suspension.cs +++ b/source/TrainManager/Car/Systems/Suspension.cs @@ -22,7 +22,7 @@ public Suspension(CarBase car) SpringPlayedAngle = 0; } - public void Update(double TimeElapsed) + public void Update(double timeElapsed) { double a = baseCar.Specs.RollDueToShakingAngle; double diff = a - SpringPlayedAngle; @@ -60,7 +60,7 @@ public void Update(double TimeElapsed) SpringPlayedAngle = a; springTimer = 0; } - springTimer += TimeElapsed; + springTimer += timeElapsed; } } } diff --git a/source/TrainManager/Car/Windscreen/Windscreen.cs b/source/TrainManager/Car/Windscreen/Windscreen.cs index 121dca292..a55cd7ae2 100644 --- a/source/TrainManager/Car/Windscreen/Windscreen.cs +++ b/source/TrainManager/Car/Windscreen/Windscreen.cs @@ -15,7 +15,7 @@ internal int Intensity { get { - if (legacyRainEvents) + if (LegacyRainEvents) { return rainIntensity; } @@ -26,7 +26,7 @@ internal int Intensity /// Backing property storing the current legacy rain intensity private int rainIntensity; /// Whether legacy rain events are in use - public bool legacyRainEvents; + public bool LegacyRainEvents; /// The raindrop array public Raindrop[] RainDrops; /// The sound played when a raindrop hits the windscreen @@ -39,13 +39,13 @@ internal int Intensity internal readonly double DropLife; private double dropTimer; /// The number of drops currently visible on the windscreen - public int currentDrops; + public int CurrentDrops; public Windscreen(int numberOfDrops, double dropLife, CarBase car) { RainDrops = new Raindrop[numberOfDrops]; DropLife = dropLife; - currentDrops = 0; + CurrentDrops = 0; Car = car; } @@ -53,7 +53,7 @@ public Windscreen(int numberOfDrops, double dropLife, CarBase car) public void SetRainIntensity(int intensity) { //Must assume that the .rain command and legacy rain are not mixed in a routefile - legacyRainEvents = true; + LegacyRainEvents = true; if (intensity < 0) { intensity = 0; @@ -66,8 +66,8 @@ public void SetRainIntensity(int intensity) } /// Updates the windscreen - /// The time elapsed since the previous call to this method - public void Update(double TimeElapsed) + /// The time elapsed since the previous call to this method + public void Update(double timeElapsed) { if (RainDrops == null || RainDrops.Length == 0) { @@ -77,7 +77,7 @@ public void Update(double TimeElapsed) if (CurrentlyRaining) { int nextDrop = PickDrop(); - dropTimer += TimeElapsed * 1000; + dropTimer += timeElapsed * 1000; var dev = (int)(0.4 * 2000 / Intensity); int dropInterval = 2000 / Intensity + TrainManagerBase.RandomNumberGenerator.Next(dev, dev * 2); if (dropTimer > dropInterval) @@ -86,10 +86,10 @@ public void Update(double TimeElapsed) { if (!RainDrops[nextDrop].Visible) { - currentDrops++; + CurrentDrops++; } RainDrops[nextDrop].Visible = true; - if (!legacyRainEvents) + if (!LegacyRainEvents) { int snowProbability = TrainManagerBase.RandomNumberGenerator.Next(100); if ((snowProbability < Car.FrontAxle.Follower.SnowIntensity) || Car.FrontAxle.Follower.RainIntensity == 0) @@ -108,16 +108,16 @@ public void Update(double TimeElapsed) for (int i = 0; i < RainDrops.Length; i++) { - RainDrops[i].RemainingLife -= TimeElapsed; + RainDrops[i].RemainingLife -= timeElapsed; if (RainDrops[i].RemainingLife <= 0 && RainDrops[i].Visible) { RainDrops[i].Visible = false; RainDrops[i].IsSnowFlake = false; - currentDrops--; + CurrentDrops--; RainDrops[i].RemainingLife = 0.5 * TrainManagerBase.RandomNumberGenerator.NextDouble() * DropLife; } } - Wipers.Update(TimeElapsed); + Wipers.Update(timeElapsed); } private int PickDrop() diff --git a/source/TrainManager/Car/Windscreen/Wiper.cs b/source/TrainManager/Car/Windscreen/Wiper.cs index d3af56214..3952470db 100644 --- a/source/TrainManager/Car/Windscreen/Wiper.cs +++ b/source/TrainManager/Car/Windscreen/Wiper.cs @@ -44,11 +44,11 @@ public WindscreenWiper(Windscreen windscreen, WiperPosition restPosition, WiperP } /// Changes the wiper speed - public void ChangeSpeed(Translations.Command Command) + public void ChangeSpeed(Translations.Command command) { SwitchSound.Play(Windscreen.Car, false); - switch (Command) + switch (command) { case Translations.Command.WiperSpeedUp: if (CurrentSpeed < WiperSpeed.Fast) @@ -67,10 +67,10 @@ public void ChangeSpeed(Translations.Command Command) } /// Updates the windscreen wipers - /// The time elapsed since the last call to this method - internal void Update(double TimeElapsed) + /// The time elapsed since the last call to this method + internal void Update(double timeElapsed) { - wiperTimer += TimeElapsed; + wiperTimer += timeElapsed; if (CurrentSpeed == WiperSpeed.Off) { if (RestPosition == WiperPosition.Left && CurrentPosition == 100) @@ -113,7 +113,7 @@ internal void Update(double TimeElapsed) { if (HoldPosition == WiperPosition.Right && CurrentSpeed != WiperSpeed.Fast) { - holdTimer += TimeElapsed; + holdTimer += timeElapsed; if (holdTimer > HoldTime) { holdTimer = 0; @@ -131,7 +131,7 @@ internal void Update(double TimeElapsed) { if (HoldPosition == WiperPosition.Right) { - holdTimer += TimeElapsed; + holdTimer += timeElapsed; if (holdTimer > HoldTime) { holdTimer = 0; @@ -150,7 +150,7 @@ internal void Update(double TimeElapsed) { if (HoldPosition == WiperPosition.Left && CurrentSpeed != WiperSpeed.Fast) { - holdTimer += TimeElapsed; + holdTimer += timeElapsed; if (holdTimer > HoldTime) { holdTimer = 0; @@ -168,7 +168,7 @@ internal void Update(double TimeElapsed) { if (HoldPosition == WiperPosition.Left) { - holdTimer += TimeElapsed; + holdTimer += timeElapsed; if (holdTimer > HoldTime) { holdTimer = 0; @@ -186,7 +186,7 @@ internal void Update(double TimeElapsed) case 1: if (currentDirection == WiperPosition.Right) { - if(Windscreen.currentDrops / (double)Windscreen.RainDrops.Length > 0.8) + if(Windscreen.CurrentDrops / (double)Windscreen.RainDrops.Length > 0.8) { if (soundTriggered == false) { @@ -207,7 +207,7 @@ internal void Update(double TimeElapsed) case 99: if (currentDirection == WiperPosition.Left) { - if(Windscreen.currentDrops / (double)Windscreen.RainDrops.Length > 0.8) + if(Windscreen.CurrentDrops / (double)Windscreen.RainDrops.Length > 0.8) { if (soundTriggered == false) { @@ -232,7 +232,7 @@ internal void Update(double TimeElapsed) Windscreen.RainDrops[dropToRemove].Visible = false; Windscreen.RainDrops[dropToRemove].IsSnowFlake = false; Windscreen.RainDrops[dropToRemove].RemainingLife = 0.5 * TrainManagerBase.RandomNumberGenerator.NextDouble() * Windscreen.DropLife; - Windscreen.currentDrops--; + Windscreen.CurrentDrops--; } } } diff --git a/source/TrainManager/Cargo/CargoBase.cs b/source/TrainManager/Cargo/CargoBase.cs index 464e0d0ed..c93d771fd 100644 --- a/source/TrainManager/Cargo/CargoBase.cs +++ b/source/TrainManager/Cargo/CargoBase.cs @@ -15,9 +15,9 @@ public abstract class CargoBase public virtual double Mass => 0.0; /// Called once a frame to update the cargo - /// The current acceleration of the train - /// The elapsed time - public virtual void Update(double Acceleration, double TimeElapsed) + /// The current acceleration of the train + /// The elapsed time + public virtual void Update(double newAcceleration, double timeElapsed) { } diff --git a/source/TrainManager/Cargo/Passengers.cs b/source/TrainManager/Cargo/Passengers.cs index 6e932f2e2..a79492065 100644 --- a/source/TrainManager/Cargo/Passengers.cs +++ b/source/TrainManager/Cargo/Passengers.cs @@ -35,27 +35,27 @@ public override void UpdateLoading(double ratio) } /// Called once a frame to update the status of the passengers - /// The current average acceleration of the train - /// The frame time elapsed - public override void Update(double Acceleration, double TimeElapsed) + /// The current average acceleration of the train + /// The frame time elapsed + public override void Update(double newAcceleration, double timeElapsed) { - double accelerationDifference = Acceleration - CurrentAcceleration; + double accelerationDifference = newAcceleration - CurrentAcceleration; double jerk = 0.25 + 0.10 * Math.Abs(accelerationDifference); - double accelerationQuanta = jerk * TimeElapsed; + double accelerationQuanta = jerk * timeElapsed; if (Math.Abs(accelerationDifference) < accelerationQuanta) { - CurrentAcceleration = Acceleration; + CurrentAcceleration = newAcceleration; accelerationDifference = 0.0; } else { CurrentAcceleration += Math.Sign(accelerationDifference) * accelerationQuanta; - accelerationDifference = Acceleration - CurrentAcceleration; + accelerationDifference = newAcceleration - CurrentAcceleration; } - CurrentSpeedDifference += accelerationDifference * TimeElapsed; + CurrentSpeedDifference += accelerationDifference * timeElapsed; double acceleration = 0.10 + 0.35 * Math.Abs(CurrentSpeedDifference); - double speedQuanta = acceleration * TimeElapsed; + double speedQuanta = acceleration * timeElapsed; if (Math.Abs(CurrentSpeedDifference) < speedQuanta) { CurrentSpeedDifference = 0.0; diff --git a/source/TrainManager/Handles/AbstractHandle.cs b/source/TrainManager/Handles/AbstractHandle.cs index 4d2c50064..1b4481ec1 100644 --- a/source/TrainManager/Handles/AbstractHandle.cs +++ b/source/TrainManager/Handles/AbstractHandle.cs @@ -12,10 +12,10 @@ public abstract class AbstractHandle public int Driver; /// The notch set by the safety sytem - public int Safety => safetyState; + public int Safety => SafetyState; /// Backing property for the safety state - protected int safetyState; + protected int SafetyState; /// The actual notch, as used by the physics system etc. public int Actual; @@ -66,7 +66,7 @@ public abstract class AbstractHandle internal double SpringTimer; - internal readonly TrainBase baseTrain; + internal readonly TrainBase BaseTrain; public abstract void Update(); @@ -86,13 +86,13 @@ public virtual void ResetSpring() { if (SpringType > SpringType.AnyHandle) { - SpringTime = TrainManagerBase.currentHost.InGameTime; + SpringTime = TrainManagerBase.CurrentHost.InGameTime; } } - protected AbstractHandle(TrainBase Train) + protected AbstractHandle(TrainBase train) { - baseTrain = Train; + BaseTrain = train; Increase = new CarSound(); IncreaseFast = new CarSound(); Decrease = new CarSound(); @@ -131,36 +131,36 @@ internal NotchedHandle(TrainBase train) : base(train) } /// Adds a delayed handle state change - /// The value to add or subtract - /// The delay in seconds - internal void AddChange(int Value, double Delay) + /// The value to add or subtract + /// The delay in seconds + internal void AddChange(int value, double delay) { int n = DelayedChanges.Length; Array.Resize(ref DelayedChanges, n + 1); - DelayedChanges[n].Value = Value; - DelayedChanges[n].Time = TrainManagerBase.currentHost.InGameTime + Delay; + DelayedChanges[n].Value = value; + DelayedChanges[n].Time = TrainManagerBase.CurrentHost.InGameTime + delay; } /// Removes a specified number of delayed changes - /// The number of changes to remove - internal void RemoveChanges(int Count) + /// The number of changes to remove + internal void RemoveChanges(int count) { int n = DelayedChanges.Length; - for (int i = 0; i < n - Count; i++) + for (int i = 0; i < n - count; i++) { - DelayedChanges[i] = DelayedChanges[i + Count]; + DelayedChanges[i] = DelayedChanges[i + count]; } - Array.Resize(ref DelayedChanges, n - Count); + Array.Resize(ref DelayedChanges, n - count); } /// Gets the delay value for this handle - /// Whether this is an increase or a decrease + /// Whether this is an increase or a decrease /// The delay value to apply - internal double GetDelay(bool ShouldIncrease) + internal double GetDelay(bool shouldIncrease) { - if (ShouldIncrease) + if (shouldIncrease) { if (DelayUp == null || DelayUp.Length == 0) { diff --git a/source/TrainManager/Handles/Handles.AirBrake.cs b/source/TrainManager/Handles/Handles.AirBrake.cs index 9a7e666f7..94ec27a05 100644 --- a/source/TrainManager/Handles/Handles.AirBrake.cs +++ b/source/TrainManager/Handles/Handles.AirBrake.cs @@ -23,7 +23,7 @@ public override void Update() { if (DelayedValue != AirBrakeHandleState.Invalid) { - if (DelayedTime <= TrainManagerBase.currentHost.InGameTime) + if (DelayedTime <= TrainManagerBase.CurrentHost.InGameTime) { Actual = (int)DelayedValue; DelayedValue = AirBrakeHandleState.Invalid; @@ -34,12 +34,12 @@ public override void Update() if (Safety == (int)AirBrakeHandleState.Release & Actual != (int)AirBrakeHandleState.Release) { DelayedValue = AirBrakeHandleState.Release; - DelayedTime = TrainManagerBase.currentHost.InGameTime; + DelayedTime = TrainManagerBase.CurrentHost.InGameTime; } else if (Safety == (int)AirBrakeHandleState.Service & Actual != (int)AirBrakeHandleState.Service) { DelayedValue = AirBrakeHandleState.Service; - DelayedTime = TrainManagerBase.currentHost.InGameTime; + DelayedTime = TrainManagerBase.CurrentHost.InGameTime; } else if (Safety == (int)AirBrakeHandleState.Lap) { @@ -55,7 +55,7 @@ public override void ApplyState(AirBrakeHandleState newState) // sound when moved to service if (newState == AirBrakeHandleState.Service) { - baseTrain.Cars[baseTrain.DriverCar].CarBrake.Release.Play(baseTrain.Cars[baseTrain.DriverCar], false); + BaseTrain.Cars[BaseTrain.DriverCar].CarBrake.Release.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } // sound @@ -67,17 +67,17 @@ public override void ApplyState(AirBrakeHandleState newState) // brake release (not min) if (Driver - (int)newState > 2 | ContinuousMovement && DecreaseFast.Buffer != null) { - DecreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + DecreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - Decrease.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Decrease.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else { // brake min - Min.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Min.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else if ((int)newState > Driver) @@ -85,31 +85,31 @@ public override void ApplyState(AirBrakeHandleState newState) // brake if ((int)newState - Driver > 2 | ContinuousMovement && IncreaseFast.Buffer != null) { - IncreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + IncreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - Increase.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Increase.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } Driver = (int)newState; - TrainManagerBase.currentHost.AddBlackBoxEntry(); + TrainManagerBase.CurrentHost.AddBlackBoxEntry(); // plugin - if (baseTrain.Plugin != null) + if (BaseTrain.Plugin != null) { - baseTrain.Plugin.UpdatePower(); - baseTrain.Plugin.UpdateBrake(); + BaseTrain.Plugin.UpdatePower(); + BaseTrain.Plugin.UpdateBrake(); } if (!TrainManagerBase.CurrentOptions.Accessibility) return; - TrainManagerBase.currentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); } } public override void ApplySafetyState(int newState) { - safetyState = newState; + SafetyState = newState; } public override string GetNotchDescription(out MessageColor color) @@ -117,7 +117,7 @@ public override string GetNotchDescription(out MessageColor color) color = MessageColor.Gray; if (NotchDescriptions == null || Driver >= NotchDescriptions.Length) { - if (baseTrain.Handles.EmergencyBrake.Driver) + if (BaseTrain.Handles.EmergencyBrake.Driver) { color = MessageColor.Red; return Translations.QuickReferences.HandleEmergency; @@ -138,7 +138,7 @@ public override string GetNotchDescription(out MessageColor color) } else { - if (baseTrain.Handles.EmergencyBrake.Driver) + if (BaseTrain.Handles.EmergencyBrake.Driver) { color = MessageColor.Red; return NotchDescriptions[0]; diff --git a/source/TrainManager/Handles/Handles.Brake.cs b/source/TrainManager/Handles/Handles.Brake.cs index 7f90659e4..118f69349 100644 --- a/source/TrainManager/Handles/Handles.Brake.cs +++ b/source/TrainManager/Handles/Handles.Brake.cs @@ -11,7 +11,7 @@ namespace TrainManager.Handles /// A brake handle public class BrakeHandle : NotchedHandle { - public BrakeHandle(int max, int driverMax, EmergencyHandle eb, double[] delayUp, double[] delayDown, TrainBase Train) : base(Train) + public BrakeHandle(int max, int driverMax, EmergencyHandle eb, double[] delayUp, double[] delayDown, TrainBase train) : base(train) { MaximumNotch = max; MaximumDriverNotch = driverMax; @@ -52,7 +52,7 @@ public override void Update() } if (DelayedChanges.Length >= 1) { - if (DelayedChanges[0].Time <= TrainManagerBase.currentHost.InGameTime) + if (DelayedChanges[0].Time <= TrainManagerBase.CurrentHost.InGameTime) { Actual = DelayedChanges[0].Value; RemoveChanges(1); @@ -62,22 +62,22 @@ public override void Update() // Spring increase if (SpringType != SpringType.Unsprung && SpringTime > 0) { - if (TrainManagerBase.currentHost.InGameTime > SpringTimer) + if (TrainManagerBase.CurrentHost.InGameTime > SpringTimer) { ApplyState(1, true); } } } - public override void ApplyState(int BrakeValue, bool BrakeRelative, bool IsOverMaxDriverNotch = false) + public override void ApplyState(int brakeValue, bool brakeRelative, bool isOverMaxDriverNotch = false) { int previousDriver = Driver; - if (baseTrain.Handles.Power.SpringType > SpringType.Single) + if (BaseTrain.Handles.Power.SpringType > SpringType.Single) { - baseTrain.Handles.Power.SpringTimer = TrainManagerBase.currentHost.InGameTime + SpringTime; + BaseTrain.Handles.Power.SpringTimer = TrainManagerBase.CurrentHost.InGameTime + SpringTime; } - SpringTimer = TrainManagerBase.currentHost.InGameTime + SpringTime; - int b = BrakeRelative ? BrakeValue + Driver : BrakeValue; + SpringTimer = TrainManagerBase.CurrentHost.InGameTime + SpringTime; + int b = brakeRelative ? brakeValue + Driver : brakeValue; if (b < 0) { b = 0; @@ -86,7 +86,7 @@ public override void ApplyState(int BrakeValue, bool BrakeRelative, bool IsOverM { b = MaximumNotch; } - if (!IsOverMaxDriverNotch && b > MaximumDriverNotch) + if (!isOverMaxDriverNotch && b > MaximumDriverNotch) { b = MaximumDriverNotch; } @@ -95,24 +95,24 @@ public override void ApplyState(int BrakeValue, bool BrakeRelative, bool IsOverM if (b < Driver) { // brake release - baseTrain.Cars[baseTrain.DriverCar].CarBrake.Release.Play(baseTrain.Cars[baseTrain.DriverCar], false); + BaseTrain.Cars[BaseTrain.DriverCar].CarBrake.Release.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); if (b > 0) { // brake release (not min) if (Driver - b > 2 | ContinuousMovement && DecreaseFast.Buffer != null) { - DecreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + DecreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - Decrease.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Decrease.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else { // brake min - Min.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Min.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else if (b > Driver) @@ -120,51 +120,51 @@ public override void ApplyState(int BrakeValue, bool BrakeRelative, bool IsOverM // brake if (b - Driver > 2 | ContinuousMovement && IncreaseFast.Buffer != null) { - IncreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + IncreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - Increase.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Increase.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } Driver = b; // plugin - if (baseTrain.Plugin != null) + if (BaseTrain.Plugin != null) { - baseTrain.Plugin.UpdatePower(); - baseTrain.Plugin.UpdateBrake(); + BaseTrain.Plugin.UpdatePower(); + BaseTrain.Plugin.UpdateBrake(); } if (previousDriver == Driver) { return; } - TrainManagerBase.currentHost.AddBlackBoxEntry(); + TrainManagerBase.CurrentHost.AddBlackBoxEntry(); if (!TrainManagerBase.CurrentOptions.Accessibility) return; - TrainManagerBase.currentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); } public override void ApplySafetyState(int newState) { - safetyState = newState; + SafetyState = newState; } public override string GetNotchDescription(out MessageColor color) { color = MessageColor.Gray; - int offset = baseTrain.Handles.HasHoldBrake ? 2 : 1; + int offset = BaseTrain.Handles.HasHoldBrake ? 2 : 1; if (NotchDescriptions == null || offset + Driver >= NotchDescriptions.Length) { - if (baseTrain.Handles.EmergencyBrake.Driver) + if (BaseTrain.Handles.EmergencyBrake.Driver) { color = MessageColor.Red; return Translations.QuickReferences.HandleEmergency; } - if (baseTrain.Handles.HasHoldBrake && baseTrain.Handles.HoldBrake.Driver) + if (BaseTrain.Handles.HasHoldBrake && BaseTrain.Handles.HoldBrake.Driver) { color = MessageColor.Green; return Translations.QuickReferences.HandleHoldBrake; @@ -180,13 +180,13 @@ public override string GetNotchDescription(out MessageColor color) } else { - if (baseTrain.Handles.EmergencyBrake.Driver) + if (BaseTrain.Handles.EmergencyBrake.Driver) { color = MessageColor.Red; return NotchDescriptions[0]; } - if (baseTrain.Handles.HasHoldBrake && baseTrain.Handles.HoldBrake.Driver) { + if (BaseTrain.Handles.HasHoldBrake && BaseTrain.Handles.HoldBrake.Driver) { color = MessageColor.Green; return NotchDescriptions[1]; } diff --git a/source/TrainManager/Handles/Handles.EmergencyBrake.cs b/source/TrainManager/Handles/Handles.EmergencyBrake.cs index a67d2a5f7..0387c5ba7 100644 --- a/source/TrainManager/Handles/Handles.EmergencyBrake.cs +++ b/source/TrainManager/Handles/Handles.EmergencyBrake.cs @@ -40,8 +40,8 @@ public void Update() { if (Safety & !Actual) { - if (TrainManagerBase.currentHost.InGameTime < ApplicationTime) ApplicationTime = TrainManagerBase.currentHost.InGameTime; - if (ApplicationTime <= TrainManagerBase.currentHost.InGameTime) + if (TrainManagerBase.CurrentHost.InGameTime < ApplicationTime) ApplicationTime = TrainManagerBase.CurrentHost.InGameTime; + if (ApplicationTime <= TrainManagerBase.CurrentHost.InGameTime) { Actual = true; ApplicationTime = double.MaxValue; @@ -102,7 +102,7 @@ public void Apply() if (!TrainManagerBase.CurrentOptions.Accessibility) return; if (Driver) { - TrainManagerBase.currentHost.AddMessage(Translations.QuickReferences.HandleEmergency, MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.QuickReferences.HandleEmergency, MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); } } diff --git a/source/TrainManager/Handles/Handles.HoldBrake.cs b/source/TrainManager/Handles/Handles.HoldBrake.cs index 96e7cb828..e9bc9a760 100644 --- a/source/TrainManager/Handles/Handles.HoldBrake.cs +++ b/source/TrainManager/Handles/Handles.HoldBrake.cs @@ -17,9 +17,9 @@ public HoldBrakeHandle(TrainBase train) baseTrain = train; } - public void ApplyState(bool Value) + public void ApplyState(bool value) { - Driver = Value; + Driver = value; if (baseTrain.Plugin == null) return; baseTrain.Plugin.UpdatePower(); baseTrain.Plugin.UpdateBrake(); diff --git a/source/TrainManager/Handles/Handles.LocoBrake.cs b/source/TrainManager/Handles/Handles.LocoBrake.cs index bd97843ea..f68d6fa4b 100644 --- a/source/TrainManager/Handles/Handles.LocoBrake.cs +++ b/source/TrainManager/Handles/Handles.LocoBrake.cs @@ -11,7 +11,7 @@ namespace TrainManager.Handles /// A locomotive brake handle public class LocoBrakeHandle : NotchedHandle { - public LocoBrakeHandle(int max, EmergencyHandle eb, double[] delayUp, double[] delayDown, TrainBase Train) : base (Train) + public LocoBrakeHandle(int max, EmergencyHandle eb, double[] delayUp, double[] delayDown, TrainBase train) : base (train) { this.MaximumNotch = max; this.EmergencyBrake = eb; @@ -51,7 +51,7 @@ public override void Update() if (DelayedChanges.Length >= 1) { - if (DelayedChanges[0].Time <= TrainManagerBase.currentHost.InGameTime) + if (DelayedChanges[0].Time <= TrainManagerBase.CurrentHost.InGameTime) { Actual = DelayedChanges[0].Value; RemoveChanges(1); @@ -59,9 +59,9 @@ public override void Update() } } - public override void ApplyState(int NotchValue, bool Relative, bool isOverMaxDriverNotch = false) + public override void ApplyState(int notchValue, bool relative, bool isOverMaxDriverNotch = false) { - int b = Relative ? NotchValue + Driver : NotchValue; + int b = relative ? notchValue + Driver : notchValue; if (b < 0) { b = 0; @@ -75,50 +75,50 @@ public override void ApplyState(int NotchValue, bool Relative, bool isOverMaxDri if (b < Driver) { // brake release - baseTrain.Cars[baseTrain.DriverCar].CarBrake.Release.Play(baseTrain.Cars[baseTrain.DriverCar], false); + BaseTrain.Cars[BaseTrain.DriverCar].CarBrake.Release.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); if (b > 0) { // brake release (not min) if (Driver - b > 2 | ContinuousMovement && DecreaseFast.Buffer != null) { - baseTrain.Handles.Brake.DecreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + BaseTrain.Handles.Brake.DecreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - baseTrain.Handles.Brake.Decrease.Play(baseTrain.Cars[baseTrain.DriverCar], false); + BaseTrain.Handles.Brake.Decrease.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else { // brake min - baseTrain.Handles.Brake.Min.Play(baseTrain.Cars[baseTrain.DriverCar], false); + BaseTrain.Handles.Brake.Min.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else if (b > Driver) { // brake - if (b - Driver > 2 | ContinuousMovement && baseTrain.Handles.Brake.IncreaseFast.Buffer != null) + if (b - Driver > 2 | ContinuousMovement && BaseTrain.Handles.Brake.IncreaseFast.Buffer != null) { - baseTrain.Handles.Brake.IncreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + BaseTrain.Handles.Brake.IncreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - baseTrain.Handles.Brake.Increase.Play(baseTrain.Cars[baseTrain.DriverCar], false); + BaseTrain.Handles.Brake.Increase.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } Driver = b; Actual = b; //TODO: FIXME - TrainManagerBase.currentHost.AddBlackBoxEntry(); + TrainManagerBase.CurrentHost.AddBlackBoxEntry(); if (!TrainManagerBase.CurrentOptions.Accessibility) return; - TrainManagerBase.currentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); } public override void ApplySafetyState(int newState) { - safetyState = newState; + SafetyState = newState; } } @@ -137,7 +137,7 @@ public override void Update() { if (DelayedValue != AirBrakeHandleState.Invalid) { - if (DelayedTime <= TrainManagerBase.currentHost.InGameTime) + if (DelayedTime <= TrainManagerBase.CurrentHost.InGameTime) { Actual = (int) DelayedValue; DelayedValue = AirBrakeHandleState.Invalid; @@ -148,12 +148,12 @@ public override void Update() if (Safety == (int) AirBrakeHandleState.Release & Actual != (int) AirBrakeHandleState.Release) { DelayedValue = AirBrakeHandleState.Release; - DelayedTime = TrainManagerBase.currentHost.InGameTime; + DelayedTime = TrainManagerBase.CurrentHost.InGameTime; } else if (Safety == (int) AirBrakeHandleState.Service & Actual != (int) AirBrakeHandleState.Service) { DelayedValue = AirBrakeHandleState.Service; - DelayedTime = TrainManagerBase.currentHost.InGameTime; + DelayedTime = TrainManagerBase.CurrentHost.InGameTime; } else if (Safety == (int) AirBrakeHandleState.Lap) { @@ -169,7 +169,7 @@ public override void ApplyState(AirBrakeHandleState newState) // sound when moved to service if (newState == AirBrakeHandleState.Service) { - baseTrain.Cars[baseTrain.DriverCar].CarBrake.Release.Play(baseTrain.Cars[baseTrain.DriverCar], false); + BaseTrain.Cars[BaseTrain.DriverCar].CarBrake.Release.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } // sound @@ -181,17 +181,17 @@ public override void ApplyState(AirBrakeHandleState newState) // brake release (not min) if (Driver - (int)newState > 2 | ContinuousMovement && DecreaseFast.Buffer != null) { - DecreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + DecreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - Decrease.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Decrease.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else { // brake min - Min.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Min.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else if ((int) newState > Driver) @@ -199,22 +199,22 @@ public override void ApplyState(AirBrakeHandleState newState) // brake if ((int)newState - Driver > 2 | ContinuousMovement && IncreaseFast.Buffer != null) { - IncreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + IncreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - Increase.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Increase.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } Driver = (int) newState; Actual = (int) newState; //TODO: FIXME - TrainManagerBase.currentHost.AddBlackBoxEntry(); + TrainManagerBase.CurrentHost.AddBlackBoxEntry(); } } public override void ApplySafetyState(int newState) { - safetyState = Math.Max(safetyState, newState); + SafetyState = Math.Max(SafetyState, newState); } public override string GetNotchDescription(out MessageColor color) @@ -222,7 +222,7 @@ public override string GetNotchDescription(out MessageColor color) color = MessageColor.Gray; if (NotchDescriptions == null || Driver >= NotchDescriptions.Length) { - if (baseTrain.Handles.EmergencyBrake.Driver) + if (BaseTrain.Handles.EmergencyBrake.Driver) { color = MessageColor.Red; return Translations.QuickReferences.HandleEmergency; @@ -238,7 +238,7 @@ public override string GetNotchDescription(out MessageColor color) } else { - if (baseTrain.Handles.EmergencyBrake.Driver) + if (BaseTrain.Handles.EmergencyBrake.Driver) { color = MessageColor.Red; return NotchDescriptions[0]; diff --git a/source/TrainManager/Handles/Handles.Power.cs b/source/TrainManager/Handles/Handles.Power.cs index 406992be8..01212971a 100644 --- a/source/TrainManager/Handles/Handles.Power.cs +++ b/source/TrainManager/Handles/Handles.Power.cs @@ -11,7 +11,7 @@ namespace TrainManager.Handles /// A power handle public class PowerHandle : NotchedHandle { - public PowerHandle(int max, int driverMax, double[] delayUp, double[] delayDown, TrainBase Train) : base(Train) + public PowerHandle(int max, int driverMax, double[] delayUp, double[] delayDown, TrainBase train) : base(train) { MaximumNotch = max; MaximumDriverNotch = driverMax; @@ -54,7 +54,7 @@ public override void Update() } if (DelayedChanges.Length >= 1) { - if (DelayedChanges[0].Time <= TrainManagerBase.currentHost.InGameTime) + if (DelayedChanges[0].Time <= TrainManagerBase.CurrentHost.InGameTime) { Actual = DelayedChanges[0].Value; RemoveChanges(1); @@ -64,7 +64,7 @@ public override void Update() // Spring return if (SpringType != SpringType.Unsprung && SpringTime > 0) { - if (TrainManagerBase.currentHost.InGameTime > SpringTimer) + if (TrainManagerBase.CurrentHost.InGameTime > SpringTimer) { ApplyState(-1, true); } @@ -74,11 +74,11 @@ public override void Update() public override void ApplyState(int newState, bool relativeChange, bool isOverMaxDriverNotch = false) { int previousDriver = Driver; - if (baseTrain.Handles.Brake.SpringType > SpringType.Single) + if (BaseTrain.Handles.Brake.SpringType > SpringType.Single) { - baseTrain.Handles.Brake.SpringTimer = TrainManagerBase.currentHost.InGameTime + SpringTime; + BaseTrain.Handles.Brake.SpringTimer = TrainManagerBase.CurrentHost.InGameTime + SpringTime; } - SpringTimer = TrainManagerBase.currentHost.InGameTime + SpringTime; + SpringTimer = TrainManagerBase.CurrentHost.InGameTime + SpringTime; // determine notch int p = relativeChange ? newState + Driver : newState; if (p < 0) @@ -102,17 +102,17 @@ public override void ApplyState(int newState, bool relativeChange, bool isOverMa // down (not min) if (Driver - p > 2 | ContinuousMovement && DecreaseFast.Buffer != null) { - DecreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + DecreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - Decrease.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Decrease.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else { // min - Min.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Min.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else if (p > Driver) @@ -122,31 +122,31 @@ public override void ApplyState(int newState, bool relativeChange, bool isOverMa // up (not max) if (Driver - p > 2 | ContinuousMovement && IncreaseFast.Buffer != null) { - IncreaseFast.Play(baseTrain.Cars[baseTrain.DriverCar], false); + IncreaseFast.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } else { - Increase.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Increase.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } else { // max - Max.Play(baseTrain.Cars[baseTrain.DriverCar], false); + Max.Play(BaseTrain.Cars[BaseTrain.DriverCar], false); } } - if (baseTrain.Handles.HandleType != HandleType.TwinHandle && baseTrain.Handles.Brake.Driver != 0) + if (BaseTrain.Handles.HandleType != HandleType.TwinHandle && BaseTrain.Handles.Brake.Driver != 0) { p = 0; } Driver = p; // plugin - if (baseTrain.Plugin != null) + if (BaseTrain.Plugin != null) { - baseTrain.Plugin.UpdatePower(); - baseTrain.Plugin.UpdateBrake(); + BaseTrain.Plugin.UpdatePower(); + BaseTrain.Plugin.UpdateBrake(); } if (previousDriver == Driver) @@ -154,25 +154,25 @@ public override void ApplyState(int newState, bool relativeChange, bool isOverMa return; } - TrainManagerBase.currentHost.AddBlackBoxEntry(); + TrainManagerBase.CurrentHost.AddBlackBoxEntry(); if (!TrainManagerBase.CurrentOptions.Accessibility) return; - TrainManagerBase.currentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); } public override void ApplySafetyState(int newState) { - safetyState = newState; + SafetyState = newState; } public override string GetNotchDescription(out MessageColor color) { color = MessageColor.Gray; - if (baseTrain.Handles.HandleType == HandleType.SingleHandle && (baseTrain.Handles.Brake.Driver != 0 || baseTrain.Handles.EmergencyBrake.Driver)) + if (BaseTrain.Handles.HandleType == HandleType.SingleHandle && (BaseTrain.Handles.Brake.Driver != 0 || BaseTrain.Handles.EmergencyBrake.Driver)) { - return baseTrain.Handles.Brake.GetNotchDescription(out color); + return BaseTrain.Handles.Brake.GetNotchDescription(out color); } if (Driver > 0) diff --git a/source/TrainManager/Handles/Handles.Reverser.cs b/source/TrainManager/Handles/Handles.Reverser.cs index 2ccefe3f2..7b0d2f93a 100644 --- a/source/TrainManager/Handles/Handles.Reverser.cs +++ b/source/TrainManager/Handles/Handles.Reverser.cs @@ -35,19 +35,19 @@ public ReverserHandle(TrainBase train) baseTrain = train; } - public void ApplyState(ReverserPosition Value) + public void ApplyState(ReverserPosition value) { - ApplyState((int)Value, false); + ApplyState((int)value, false); } - public void ApplyState(int Value, bool Relative) + public void ApplyState(int value, bool relative) { if (baseTrain.Handles.HandleType == HandleType.InterlockedReverserHandle && baseTrain.Handles.Power.Driver != 0) { return; } int a = (int)Driver; - int r = Relative ? a + Value : Value; + int r = relative ? a + value : value; if (r < -1) r = -1; if (r > 1) r = 1; if (baseTrain.CurrentDirection == TrackDirection.Reverse) @@ -61,7 +61,7 @@ public void ApplyState(int Value, bool Relative) { baseTrain.Plugin.UpdateReverser(); } - TrainManagerBase.currentHost.AddBlackBoxEntry(); + TrainManagerBase.CurrentHost.AddBlackBoxEntry(); // sound if (a == 0 & r != 0) { @@ -76,7 +76,7 @@ public void ApplyState(int Value, bool Relative) if (a == (int)Driver) return; if (!TrainManagerBase.CurrentOptions.Accessibility) return; - TrainManagerBase.currentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(GetNotchDescription(out _), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); } /// Gets the description string for this notch diff --git a/source/TrainManager/Motor/AbstractMotorSound.cs b/source/TrainManager/Motor/AbstractMotorSound.cs index 9db3244f3..933c717d0 100644 --- a/source/TrainManager/Motor/AbstractMotorSound.cs +++ b/source/TrainManager/Motor/AbstractMotorSound.cs @@ -17,7 +17,7 @@ protected AbstractMotorSound(CarBase car) } /// Updates the motor sounds - public virtual void Update(double TimeElapsed) + public virtual void Update(double timeElapsed) { } diff --git a/source/TrainManager/Motor/BVE4/MotorSound.cs b/source/TrainManager/Motor/BVE4/MotorSound.cs index 8282f5e59..22a319b08 100644 --- a/source/TrainManager/Motor/BVE4/MotorSound.cs +++ b/source/TrainManager/Motor/BVE4/MotorSound.cs @@ -50,7 +50,7 @@ public BVEMotorSound(CarBase car, double speedConversionFactor, BVEMotorSoundTab } } - public override void Update(double TimeElapsed) + public override void Update(double timeElapsed) { if (!Car.Specs.IsMotorCar) { @@ -68,7 +68,7 @@ public override void Update(double TimeElapsed) { if (j < Tables.Length) { - TrainManagerBase.currentHost.StopSound(Tables[j].Source); + TrainManagerBase.CurrentHost.StopSound(Tables[j].Source); Tables[j].Source = null; Tables[j].Buffer = null; } @@ -77,7 +77,7 @@ public override void Update(double TimeElapsed) { if (k < Tables.Length) { - TrainManagerBase.currentHost.StopSound(Tables[k].Source); + TrainManagerBase.CurrentHost.StopSound(Tables[k].Source); Tables[k].Source = null; Tables[k].Buffer = null; } @@ -94,7 +94,7 @@ public override void Update(double TimeElapsed) idx2 = Tables[j].Entries.Length - 1; } - if (TrainManagerBase.currentHost.Application != HostApplication.OpenBve && ((!PlayFirstTrack && h == 0) || (!PlaySecondTrack && h == 1))) + if (TrainManagerBase.CurrentHost.Application != HostApplication.OpenBve && ((!PlayFirstTrack && h == 0) || (!PlaySecondTrack && h == 1))) { // Used in TrainEditor2 to play a single track whilst editing idx2 = -1; @@ -121,10 +121,10 @@ public override void Update(double TimeElapsed) { // brake double max = -Car.Specs.MotorAcceleration; - if (Car.baseTrain != null) + if (Car.BaseTrain != null) { // train / brake system not simulated in TrainEditor2 - max = Car.CarBrake.DecelerationAtServiceMaximumPressure(Car.baseTrain.Handles.Brake.Actual, Car.CurrentSpeed); + max = Car.CarBrake.DecelerationAtServiceMaximumPressure(Car.BaseTrain.Handles.Brake.Actual, Car.CurrentSpeed); } if (max != 0.0) { @@ -136,10 +136,10 @@ public override void Update(double TimeElapsed) if (obuf != nbuf) { - TrainManagerBase.currentHost.StopSound(Tables[j].Source); + TrainManagerBase.CurrentHost.StopSound(Tables[j].Source); if (nbuf != null) { - Tables[j].Source = (SoundSource) TrainManagerBase.currentHost.PlaySound(nbuf, pitch, gain, Position, Car, true); + Tables[j].Source = (SoundSource) TrainManagerBase.CurrentHost.PlaySound(nbuf, pitch, gain, Position, Car, true); Tables[j].Buffer = nbuf; } else @@ -158,14 +158,14 @@ public override void Update(double TimeElapsed) } else { - TrainManagerBase.currentHost.StopSound(Tables[j].Source); + TrainManagerBase.CurrentHost.StopSound(Tables[j].Source); Tables[j].Source = null; Tables[j].Buffer = null; } } else { - TrainManagerBase.currentHost.StopSound(Tables[j].Source); + TrainManagerBase.CurrentHost.StopSound(Tables[j].Source); Tables[j].Source = null; Tables[j].Buffer = null; } diff --git a/source/TrainManager/Motor/BVE5/AITrainSound.cs b/source/TrainManager/Motor/BVE5/AITrainSound.cs index 826fde0f1..a1dc727ac 100644 --- a/source/TrainManager/Motor/BVE5/AITrainSound.cs +++ b/source/TrainManager/Motor/BVE5/AITrainSound.cs @@ -45,9 +45,9 @@ public BVE5AITrainSounds(CarBase car, BVE5AISoundEntry[] entries) : base(car) private BVE5AISoundControl lastState; private double timer; - public override void Update(double TimeElapsed) + public override void Update(double timeElapsed) { - timer += TimeElapsed; + timer += timeElapsed; if (SoundEntries.Length == 0 || timer < 1) { // no need to update @@ -83,7 +83,7 @@ public override void Update(double TimeElapsed) { if (SoundEntries[i].Controller == currentState) { - SoundEntries[i].Source = TrainManagerBase.currentHost.PlaySound(SoundEntries[i].Sound, 1.0, 1.0, Vector3.Zero, Car, true) as SoundSource; + SoundEntries[i].Source = TrainManagerBase.CurrentHost.PlaySound(SoundEntries[i].Sound, 1.0, 1.0, Vector3.Zero, Car, true) as SoundSource; } else { diff --git a/source/TrainManager/Motor/BVE5/MotorSound.cs b/source/TrainManager/Motor/BVE5/MotorSound.cs index 613828ac4..7c8f4c1cb 100644 --- a/source/TrainManager/Motor/BVE5/MotorSound.cs +++ b/source/TrainManager/Motor/BVE5/MotorSound.cs @@ -22,7 +22,7 @@ public BVE5MotorSound(CarBase car) : base(car) SoundSources = new SoundSource[0]; } - public override void Update(double TimeElapsed) + public override void Update(double timeElapsed) { if (!Car.Specs.IsMotorCar) { @@ -53,7 +53,7 @@ public override void Update(double TimeElapsed) { if (i >= entry.Sounds.Length || i < SoundSources.Length && (entry.Sounds[i].Pitch == 0 || entry.Sounds[i].Gain == 0)) { - TrainManagerBase.currentHost.StopSound(SoundSources[i]); + TrainManagerBase.CurrentHost.StopSound(SoundSources[i]); } else { @@ -69,7 +69,7 @@ public override void Update(double TimeElapsed) if (pitch <= 0 || gain <= 0) { - TrainManagerBase.currentHost.StopSound(SoundSources[i]); + TrainManagerBase.CurrentHost.StopSound(SoundSources[i]); continue; } /* @@ -93,7 +93,7 @@ public override void Update(double TimeElapsed) } else { - SoundSources[i] = TrainManagerBase.currentHost.PlaySound(SoundBuffers[i], pitch, gain, Position, Car, true) as SoundSource; + SoundSources[i] = TrainManagerBase.CurrentHost.PlaySound(SoundBuffers[i], pitch, gain, Position, Car, true) as SoundSource; } } } @@ -121,7 +121,7 @@ public override void Update(double TimeElapsed) { if (i >= entry.Sounds.Length || i < SoundSources.Length && (entry.Sounds[i].Pitch == 0 || entry.Sounds[i].Gain == 0)) { - TrainManagerBase.currentHost.StopSound(SoundSources[i]); + TrainManagerBase.CurrentHost.StopSound(SoundSources[i]); } else { @@ -137,7 +137,7 @@ public override void Update(double TimeElapsed) if (pitch <= 0 || gain <= 0) { - TrainManagerBase.currentHost.StopSound(SoundSources[i]); + TrainManagerBase.CurrentHost.StopSound(SoundSources[i]); continue; } /* @@ -160,7 +160,7 @@ public override void Update(double TimeElapsed) } else { - SoundSources[i] = TrainManagerBase.currentHost.PlaySound(SoundBuffers[i], pitch, gain, Position, Car, true) as SoundSource; + SoundSources[i] = TrainManagerBase.CurrentHost.PlaySound(SoundBuffers[i], pitch, gain, Position, Car, true) as SoundSource; } } } diff --git a/source/TrainManager/Power/AccelerationCurve.cs b/source/TrainManager/Power/AccelerationCurve.cs index b3332a6c8..15eed207b 100644 --- a/source/TrainManager/Power/AccelerationCurve.cs +++ b/source/TrainManager/Power/AccelerationCurve.cs @@ -6,10 +6,10 @@ namespace TrainManager.Power public abstract class AccelerationCurve { /// Gets the acceleration output for this curve - /// The current speed - /// A double between 0 (Unloaded) and 1.0 (Loaded) representing the load factor + /// The current speed + /// A double between 0 (Unloaded) and 1.0 (Loaded) representing the load factor /// The acceleration output - public abstract double GetAccelerationOutput(double Speed, double Loading); + public abstract double GetAccelerationOutput(double speed, double loading); /// Gets the maximum possible acceleration output for this curve // ReSharper disable once UnusedMemberInSuper.Global @@ -29,25 +29,25 @@ public class BveAccelerationCurve : AccelerationCurve public double StageTwoExponent; private readonly double Multiplier; - public override double GetAccelerationOutput(double Speed, double Loading) + public override double GetAccelerationOutput(double speed, double loading) { - if (Speed <= 0.0) + if (speed <= 0.0) { return Multiplier * this.StageZeroAcceleration; } - if (Speed < this.StageOneSpeed) + if (speed < this.StageOneSpeed) { - double t = Speed / this.StageOneSpeed; + double t = speed / this.StageOneSpeed; return Multiplier * (this.StageZeroAcceleration * (1.0 - t) + this.StageOneAcceleration * t); } - if (Speed < this.StageTwoSpeed) + if (speed < this.StageTwoSpeed) { - return Multiplier * this.StageOneSpeed * this.StageOneAcceleration / Speed; + return Multiplier * this.StageOneSpeed * this.StageOneAcceleration / speed; } - return Multiplier * this.StageOneSpeed * this.StageOneAcceleration * Math.Pow(this.StageTwoSpeed, this.StageTwoExponent - 1.0) * Math.Pow(Speed, -this.StageTwoExponent); + return Multiplier * this.StageOneSpeed * this.StageOneAcceleration * Math.Pow(this.StageTwoSpeed, this.StageTwoExponent - 1.0) * Math.Pow(speed, -this.StageTwoExponent); } public override double MaximumAcceleration => Math.Max(StageZeroAcceleration, StageOneAcceleration); @@ -77,16 +77,16 @@ public class BveDecelerationCurve : AccelerationCurve { private readonly double MaxDecelerationOutput; - public override double GetAccelerationOutput(double Speed, double Loading) + public override double GetAccelerationOutput(double speed, double loading) { return this.MaxDecelerationOutput; } public override double MaximumAcceleration => MaxDecelerationOutput; - public BveDecelerationCurve(double Deceleration) + public BveDecelerationCurve(double deceleration) { - this.MaxDecelerationOutput = Deceleration; + this.MaxDecelerationOutput = deceleration; } } } diff --git a/source/TrainManager/Power/Breaker.cs b/source/TrainManager/Power/Breaker.cs index 5dd67c15a..485afe6e1 100644 --- a/source/TrainManager/Power/Breaker.cs +++ b/source/TrainManager/Power/Breaker.cs @@ -28,17 +28,17 @@ public Breaker(AbstractCar car) } /// Updates the breaker - /// Whether the breaker is currently active - public void Update(bool BreakerActive) + /// Whether the breaker is currently active + public void Update(bool breakerActive) { - if (BreakerActive & !Resumed) + if (breakerActive & !Resumed) { // resume Resume.Play(Car, false); ResumeOrInterrupt.Play(Car, false); Resumed = true; } - else if (!BreakerActive & Resumed) + else if (!breakerActive & Resumed) { // interrupt ResumeOrInterrupt.Play(Car, false); diff --git a/source/TrainManager/SafetySystems/DSD/DriverSupervisionDevice.cs b/source/TrainManager/SafetySystems/DSD/DriverSupervisionDevice.cs index 619b94f34..c9f0a0915 100644 --- a/source/TrainManager/SafetySystems/DSD/DriverSupervisionDevice.cs +++ b/source/TrainManager/SafetySystems/DSD/DriverSupervisionDevice.cs @@ -32,9 +32,9 @@ public class DriverSupervisionDevice private double StopTimer; - public DriverSupervisionDevice(CarBase Car, DriverSupervisionDeviceTypes type, DriverSupervisionDeviceMode mode, DriverSupervisionDeviceTriggerMode triggerMode, double interventionTime, double requiredStopTime, bool loopingAlarm) + public DriverSupervisionDevice(CarBase car, DriverSupervisionDeviceTypes type, DriverSupervisionDeviceMode mode, DriverSupervisionDeviceTriggerMode triggerMode, double interventionTime, double requiredStopTime, bool loopingAlarm) { - baseCar = Car; + baseCar = car; Type = type; Mode = mode; TriggerMode = triggerMode; @@ -45,13 +45,13 @@ public DriverSupervisionDevice(CarBase Car, DriverSupervisionDeviceTypes type, D LoopingAlarm = loopingAlarm; } - public void Update(double TimeElapsed) + public void Update(double timeElapsed) { if (Type == DriverSupervisionDeviceTypes.None) { return; } - Timer += TimeElapsed; + Timer += timeElapsed; if (Timer > InterventionTime && !Triggered) { Triggered = true; @@ -72,7 +72,7 @@ public void Update(double TimeElapsed) } break; case DriverSupervisionDeviceTriggerMode.DirectionSet: - if (baseCar.baseTrain.Handles.Reverser.Actual == 0 && baseCar.CurrentSpeed == 0) + if (baseCar.BaseTrain.Handles.Reverser.Actual == 0 && baseCar.CurrentSpeed == 0) { // no direction set, not moving Timer = 0; @@ -86,21 +86,21 @@ public void Update(double TimeElapsed) switch (Type) { case DriverSupervisionDeviceTypes.CutsPower: - baseCar.baseTrain.Handles.Power.ApplySafetyState(0); + baseCar.BaseTrain.Handles.Power.ApplySafetyState(0); break; case DriverSupervisionDeviceTypes.ApplyBrake: - baseCar.baseTrain.Handles.Power.ApplySafetyState(0); - baseCar.baseTrain.Handles.Brake.ApplySafetyState(baseCar.baseTrain.Handles.Brake.MaximumNotch); + baseCar.BaseTrain.Handles.Power.ApplySafetyState(0); + baseCar.BaseTrain.Handles.Brake.ApplySafetyState(baseCar.BaseTrain.Handles.Brake.MaximumNotch); break; case DriverSupervisionDeviceTypes.ApplyEmergencyBrake: - baseCar.baseTrain.Handles.Power.ApplySafetyState(0); - baseCar.baseTrain.Handles.Brake.ApplySafetyState(baseCar.baseTrain.Handles.Brake.MaximumNotch + 1); + baseCar.BaseTrain.Handles.Power.ApplySafetyState(0); + baseCar.BaseTrain.Handles.Brake.ApplySafetyState(baseCar.BaseTrain.Handles.Brake.MaximumNotch + 1); break; } if (RequiredStopTime != 0 && baseCar.Specs.PerceivedSpeed == 0) { - StopTimer += TimeElapsed; + StopTimer += timeElapsed; } } } @@ -118,31 +118,31 @@ private void AttemptReset() } } - public void ControlDown(Translations.Command Control) + public void ControlDown(Translations.Command control) { switch (Mode) { case DriverSupervisionDeviceMode.Power: - if (Control >= Translations.Command.PowerIncrease && Control <= Translations.Command.PowerFullAxis) + if (control >= Translations.Command.PowerIncrease && control <= Translations.Command.PowerFullAxis) { AttemptReset(); } break; case DriverSupervisionDeviceMode.Brake: - if (Control >= Translations.Command.BrakeIncrease && Control <= Translations.Command.BrakeFullAxis) + if (control >= Translations.Command.BrakeIncrease && control <= Translations.Command.BrakeFullAxis) { AttemptReset(); } break; case DriverSupervisionDeviceMode.AnyHandle: - if ((Control >= Translations.Command.PowerIncrease && Control <= Translations.Command.PowerFullAxis) || (Control >= Translations.Command.BrakeIncrease && Control <= Translations.Command.BrakeFullAxis)) + if ((control >= Translations.Command.PowerIncrease && control <= Translations.Command.PowerFullAxis) || (control >= Translations.Command.BrakeIncrease && control <= Translations.Command.BrakeFullAxis)) { AttemptReset(); } break; case DriverSupervisionDeviceMode.HeldKey: case DriverSupervisionDeviceMode.Independant: - if (Control == Translations.Command.DriverSupervisionDevice) + if (control == Translations.Command.DriverSupervisionDevice) { AttemptReset(); } @@ -150,30 +150,30 @@ public void ControlDown(Translations.Command Control) } } - public void ControlUp(Translations.Command Control) + public void ControlUp(Translations.Command control) { switch (Mode) { case DriverSupervisionDeviceMode.Power: - if (Control >= Translations.Command.PowerIncrease && Control <= Translations.Command.PowerFullAxis) + if (control >= Translations.Command.PowerIncrease && control <= Translations.Command.PowerFullAxis) { AttemptReset(); } break; case DriverSupervisionDeviceMode.Brake: - if (Control >= Translations.Command.BrakeIncrease && Control <= Translations.Command.BrakeFullAxis) + if (control >= Translations.Command.BrakeIncrease && control <= Translations.Command.BrakeFullAxis) { AttemptReset(); } break; case DriverSupervisionDeviceMode.AnyHandle: - if ((Control >= Translations.Command.PowerIncrease && Control <= Translations.Command.PowerFullAxis) || (Control >= Translations.Command.BrakeIncrease && Control <= Translations.Command.BrakeFullAxis)) + if ((control >= Translations.Command.PowerIncrease && control <= Translations.Command.PowerFullAxis) || (control >= Translations.Command.BrakeIncrease && control <= Translations.Command.BrakeFullAxis)) { AttemptReset(); } break; case DriverSupervisionDeviceMode.Independant: - if (Control == Translations.Command.DriverSupervisionDevice) + if (control == Translations.Command.DriverSupervisionDevice) { AttemptReset(); } diff --git a/source/TrainManager/SafetySystems/Overspeed.cs b/source/TrainManager/SafetySystems/Overspeed.cs index 81dffdd85..f13e7d4d5 100644 --- a/source/TrainManager/SafetySystems/Overspeed.cs +++ b/source/TrainManager/SafetySystems/Overspeed.cs @@ -31,7 +31,7 @@ public void Update() * HACK: If the limit has changed, or we are in arcade mode, notify the player * This conforms to the original behaviour, but doesn't need to raise the message from the event. */ - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","route_overspeed"}), MessageDependency.RouteLimit, GameMode.Normal, MessageColor.Orange, double.PositiveInfinity, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","route_overspeed"}), MessageDependency.RouteLimit, GameMode.Normal, MessageColor.Orange, double.PositiveInfinity, null); } currentlyOverspeed = true; } @@ -45,7 +45,7 @@ public void Update() if (previousRouteLimit != baseTrain.CurrentRouteLimit) { //Show for 10s and announce the current speed limit if screen reader present - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","route_newlimit"}), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","route_newlimit"}), MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); } } diff --git a/source/TrainManager/SafetySystems/PassAlarm.cs b/source/TrainManager/SafetySystems/PassAlarm.cs index 6e1035ae0..a4247d292 100644 --- a/source/TrainManager/SafetySystems/PassAlarm.cs +++ b/source/TrainManager/SafetySystems/PassAlarm.cs @@ -16,10 +16,10 @@ public class PassAlarm /// Creates a new PassAlarm /// The type of PassAlarm - /// A reference to the base car - public PassAlarm(PassAlarmType type, AbstractCar Car) + /// A reference to the base car + public PassAlarm(PassAlarmType type, AbstractCar car) { - this.baseCar = Car; + this.baseCar = car; this.Type = type; this.Sound = new CarSound(); this.Lit = false; @@ -29,7 +29,7 @@ public PassAlarm(PassAlarmType type, AbstractCar Car) public void Trigger() { Lit = true; - if (TrainManagerBase.currentHost.SoundIsPlaying(Sound.Source)) + if (TrainManagerBase.CurrentHost.SoundIsPlaying(Sound.Source)) { return; } diff --git a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.HeiAts.cs b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.HeiAts.cs index d64e830e6..06070b84c 100644 --- a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.HeiAts.cs +++ b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.HeiAts.cs @@ -33,8 +33,8 @@ class HeiAtsAI : PluginAI internal HeiAtsAI(Plugin plugin) { Plugin = plugin; - currentStep = 2; - nextPluginAction = 0; + CurrentStep = 2; + NextPluginAction = 0; } /// Used to store the current state of the wipers private int wiperState; @@ -42,67 +42,67 @@ internal override void Perform(AIData data) { if (Plugin.Panel[17] == 0) { - currentStep = 0; + CurrentStep = 0; } - switch (currentStep) + switch (CurrentStep) { case 0: Plugin.KeyDown(VirtualKeys.H); data.Response = AIResponse.Short; - currentStep++; + CurrentStep++; break; case 1: Plugin.KeyUp(VirtualKeys.H); data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; break; case 2: Plugin.KeyDown(VirtualKeys.S); data.Response = AIResponse.Short; - currentStep++; + CurrentStep++; break; case 3: Plugin.KeyUp(VirtualKeys.S); data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; break; case 4: if (Plugin.Train.Cars[Plugin.Train.DriverCar].Sounds.Plugin[0].IsPlaying && Plugin.Train.CurrentSpeed == 0) { data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; } break; case 5: data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; break; case 6: Plugin.KeyDown(VirtualKeys.S); data.Response = AIResponse.Short; - currentStep++; + CurrentStep++; break; case 7: Plugin.KeyUp(VirtualKeys.S); data.Response = AIResponse.Short; - currentStep = 4; + CurrentStep = 4; break; case 100: case 101: //Decent pause before resetting the safety system data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; break; case 102: Plugin.KeyDown(VirtualKeys.S); data.Response = AIResponse.Short; - currentStep++; + CurrentStep++; break; case 103: Plugin.KeyUp(VirtualKeys.S); data.Response = AIResponse.Short; - currentStep = 4; + CurrentStep = 4; break; } @@ -110,7 +110,7 @@ internal override void Perform(AIData data) switch (wiperState) { case 0: - if (currentRainIntensity > 30) + if (CurrentRainIntensity > 30) { Plugin.KeyDown(VirtualKeys.D); Plugin.KeyUp(VirtualKeys.D); @@ -119,14 +119,14 @@ internal override void Perform(AIData data) } return; case 1: - if (currentRainIntensity > 60) + if (CurrentRainIntensity > 60) { Plugin.KeyDown(VirtualKeys.D); Plugin.KeyUp(VirtualKeys.D); data.Response = AIResponse.Short; wiperState++; } - else if(currentRainIntensity < 30) + else if(CurrentRainIntensity < 30) { Plugin.KeyDown(VirtualKeys.E); Plugin.KeyUp(VirtualKeys.E); @@ -135,7 +135,7 @@ internal override void Perform(AIData data) } return; case 2: - if (currentRainIntensity < 60) + if (CurrentRainIntensity < 60) { Plugin.KeyDown(VirtualKeys.E); Plugin.KeyUp(VirtualKeys.E); @@ -148,7 +148,7 @@ internal override void Perform(AIData data) public override void BeginJump(InitializationModes mode) { - currentStep = 100; + CurrentStep = 100; } public override void EndJump() @@ -159,7 +159,7 @@ public override void SetBeacon(BeaconData beacon) { if (beacon.Type == 21) { - currentRainIntensity = beacon.Optional; + CurrentRainIntensity = beacon.Optional; } } } diff --git a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.MTRAuto.cs b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.MTRAuto.cs index b6bdce38b..9baf1672f 100644 --- a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.MTRAuto.cs +++ b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.MTRAuto.cs @@ -34,20 +34,20 @@ class MTRAutoAI : PluginAI internal MTRAutoAI(Plugin plugin) { Plugin = plugin; - currentStep = 0; + CurrentStep = 0; } internal override void Perform(AIData data) { - switch (currentStep) + switch (CurrentStep) { case 0: // start in N + EB data.Handles.Reverser = 0; data.Handles.BrakeNotch = Plugin.Train.Handles.Brake.MaximumNotch + 1; data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; break; case 1: // enable system @@ -55,14 +55,14 @@ internal override void Perform(AIData data) data.Handles.BrakeNotch = Plugin.Train.Handles.Brake.MaximumNotch + 1; Plugin.KeyDown(VirtualKeys.J); data.Response = AIResponse.Short; - currentStep++; + CurrentStep++; break; case 2: data.Handles.Reverser = 0; data.Handles.BrakeNotch = Plugin.Train.Handles.Brake.MaximumNotch + 1; Plugin.KeyUp(VirtualKeys.J); data.Response = AIResponse.Short; - currentStep++; + CurrentStep++; break; case 3: // set train to drive mode @@ -70,7 +70,7 @@ internal override void Perform(AIData data) data.Handles.PowerNotch = 0; data.Handles.BrakeNotch = 0; data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; break; case 4: data.Handles.PowerNotch = 0; @@ -79,7 +79,7 @@ internal override void Perform(AIData data) { Plugin.KeyDown(VirtualKeys.A1); Plugin.KeyDown(VirtualKeys.A2); - currentStep++; + CurrentStep++; } break; case 5: @@ -89,7 +89,7 @@ internal override void Perform(AIData data) { Plugin.KeyUp(VirtualKeys.A1); Plugin.KeyUp(VirtualKeys.A2); - currentStep--; + CurrentStep--; } break; } @@ -103,7 +103,7 @@ public override void BeginJump(InitializationModes mode) public override void EndJump() { - currentStep = 0; + CurrentStep = 0; } public override void SetBeacon(BeaconData beacon) diff --git a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKDt.cs b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKDt.cs index 0f4a2d099..2c09c9525 100644 --- a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKDt.cs +++ b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKDt.cs @@ -42,43 +42,43 @@ internal class UKDtAI : PluginAI internal UKDtAI(Plugin plugin) { Plugin = plugin; - currentStep = 0; - nextPluginAction = 0; + CurrentStep = 0; + NextPluginAction = 0; vigilanceTimer = 0; } internal override void Perform(AIData data) { - if (Plugin.Train.CurrentSpeed != 0 && currentStep == 0) + if (Plugin.Train.CurrentSpeed != 0 && CurrentStep == 0) { // ai asked to take over at speed, skip startup sequence - currentStep = 100; + CurrentStep = 100; } - switch (currentStep) + switch (CurrentStep) { case 0: // start of startup sequence- start by bringing up TPWS / AWS data.Handles.Reverser = 1; data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; return; case 1: data.Handles.Reverser = 0; data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; return; case 2: if (Plugin.Sound[2] == 0 || Plugin.Sound[2] == -1000) { data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; } return; case 3: Plugin.KeyDown(VirtualKeys.A1); data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; case 4: Plugin.KeyUp(VirtualKeys.A1); @@ -87,33 +87,33 @@ internal override void Perform(AIData data) if (Plugin.Panel[5] == 2) { // engine stopped, continue with startup - currentStep++; + CurrentStep++; } else { // startup test complete - currentStep = 100; + CurrentStep = 100; } return; case 5: Plugin.KeyDown(VirtualKeys.D); data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; return; case 6: - currentStep++; + CurrentStep++; return; case 7: Plugin.KeyUp(VirtualKeys.D); data.Response = AIResponse.Medium; - currentStep = 100; + CurrentStep = 100; return; } if (Plugin.Panel[5] == 3) { // engine either stalled on start, or has been stopped by user - currentStep = 5; + CurrentStep = 5; } if (Plugin.Panel[51] == 1) @@ -155,16 +155,16 @@ internal override void Perform(AIData data) if (Plugin.Sound[2] == 0) { //AWS horn active, so wait a sec before triggering cancel - switch (currentStep) + switch (CurrentStep) { case 100: data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; case 101: Plugin.KeyDown(VirtualKeys.A1); data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; } } @@ -191,26 +191,26 @@ internal override void Perform(AIData data) return; } //Reset alarm - switch (currentStep) + switch (CurrentStep) { case 100: data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; case 101: Plugin.KeyDown(VirtualKeys.A2); data.Response = AIResponse.Medium; - currentStep+= 2; + CurrentStep+= 2; return; } } - if (currentStep == 102 || currentStep == 103) + if (CurrentStep == 102 || CurrentStep == 103) { //Raise the cancel key - Plugin.KeyUp(currentStep == 102 ? VirtualKeys.A1 : VirtualKeys.A2); + Plugin.KeyUp(CurrentStep == 102 ? VirtualKeys.A1 : VirtualKeys.A2); data.Response = AIResponse.Medium; - currentStep = 100; + CurrentStep = 100; return; } @@ -218,7 +218,7 @@ internal override void Perform(AIData data) * Assume that with a brightness value below 180 we want night headlights * Further assume that the driver only sets these at the initial station once */ - if (!lightsSet) + if (!LightsSet) { float currentBrightness = Plugin.Train.Cars[Plugin.Train.DriverCar].Brightness.CurrentBrightness(TrainManagerBase.Renderer.Lighting.DynamicCabBrightness, 0.0); switch (Plugin.Panel[20]) @@ -239,7 +239,7 @@ internal override void Perform(AIData data) } else { - lightsSet = true; + LightsSet = true; } return; case 2: @@ -258,7 +258,7 @@ internal override void Perform(AIData data) } else { - lightsSet = true; + LightsSet = true; } return; } @@ -286,7 +286,7 @@ internal override void Perform(AIData data) } //UKDT fitted trains generally use the tail lights toggle for something else dummy (ETS etc.) which isn't directly relevant to the AI or the external appearance, so do nothing here - if (TrainManagerBase.currentHost.InGameTime > nextPluginAction) + if (TrainManagerBase.CurrentHost.InGameTime > NextPluginAction) { //If nothing else has happened recently, blip power / brake (some trains don't like using the vigilance reset key to keep going) if (data.Handles.BrakeNotch == 0) @@ -313,7 +313,7 @@ internal override void Perform(AIData data) } } data.Response = AIResponse.Short; - nextPluginAction = TrainManagerBase.currentHost.InGameTime + 20.0; + NextPluginAction = TrainManagerBase.CurrentHost.InGameTime + 20.0; return; } @@ -332,7 +332,7 @@ internal override void Perform(AIData data) switch (Plugin.Panel[198]) { case 0: - if (currentRainIntensity > 30 || shouldWipe) + if (CurrentRainIntensity > 30 || shouldWipe) { Plugin.KeyDown(VirtualKeys.B1); Plugin.KeyUp(VirtualKeys.B1); @@ -340,7 +340,7 @@ internal override void Perform(AIData data) } return; case 1: - if (currentRainIntensity > 45) + if (CurrentRainIntensity > 45) { Plugin.KeyDown(VirtualKeys.B1); Plugin.KeyUp(VirtualKeys.B1); @@ -354,7 +354,7 @@ internal override void Perform(AIData data) } return; case 2: - if (currentRainIntensity < 60) + if (CurrentRainIntensity < 60) { Plugin.KeyDown(VirtualKeys.B2); Plugin.KeyUp(VirtualKeys.B2); @@ -403,7 +403,7 @@ internal override void Perform(AIData data) public override void BeginJump(InitializationModes mode) { overCurrentTrip = false; - currentStep = mode == InitializationModes.OffEmergency ? 0 : 100; + CurrentStep = mode == InitializationModes.OffEmergency ? 0 : 100; } public override void EndJump() @@ -415,7 +415,7 @@ public override void SetBeacon(BeaconData beacon) { if (beacon.Type == 21) { - currentRainIntensity = beacon.Optional; + CurrentRainIntensity = beacon.Optional; } } } diff --git a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKMUt.cs b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKMUt.cs index 9f977da0c..6baf029b8 100644 --- a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKMUt.cs +++ b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKMUt.cs @@ -40,43 +40,43 @@ internal class UKMUtAI : PluginAI internal UKMUtAI(Plugin plugin) { Plugin = plugin; - currentStep = 0; - nextPluginAction = 0; + CurrentStep = 0; + NextPluginAction = 0; vigilanceTimer = 0; } internal override void Perform(AIData data) { - if (Plugin.Train.CurrentSpeed != 0 && currentStep == 0) + if (Plugin.Train.CurrentSpeed != 0 && CurrentStep == 0) { // ai asked to take over at speed, skip startup sequence - currentStep = 100; + CurrentStep = 100; } - switch (currentStep) + switch (CurrentStep) { case 0: // start of startup sequence- start by bringing up TPWS / AWS data.Handles.Reverser = 1; data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; return; case 1: data.Handles.Reverser = 0; data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; return; case 2: if (Plugin.Sound[2] == 0 || Plugin.Sound[2] == -1000) { data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; } return; case 3: Plugin.KeyDown(VirtualKeys.A1); data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; case 4: Plugin.KeyUp(VirtualKeys.A1); @@ -84,26 +84,26 @@ internal override void Perform(AIData data) if (Plugin.Panel[31] == 0) { // need to raise the pantograph - currentStep++; + CurrentStep++; } else { // startup test complete - currentStep = 100; + CurrentStep = 100; } return; case 5: Plugin.KeyDown(VirtualKeys.D); data.Response = AIResponse.Short; - currentStep++; + CurrentStep++; return; case 6: - currentStep++; + CurrentStep++; return; case 7: Plugin.KeyUp(VirtualKeys.D); data.Response = AIResponse.Short; - currentStep = 100; + CurrentStep = 100; return; } @@ -127,31 +127,31 @@ internal override void Perform(AIData data) //DRA is enabled, so toggle off Plugin.KeyDown(VirtualKeys.S); data.Response = AIResponse.Medium; - currentStep = 99; + CurrentStep = 99; return; } - if (currentStep == 99) + if (CurrentStep == 99) { Plugin.KeyUp(VirtualKeys.S); data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; } if (Plugin.Sound[2] == 0) { //AWS horn active, so wait a sec before triggering cancel - switch (currentStep) + switch (CurrentStep) { case 100: data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; case 101: Plugin.KeyDown(VirtualKeys.A1); data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; } } @@ -178,26 +178,26 @@ internal override void Perform(AIData data) return; } //Reset alarm - switch (currentStep) + switch (CurrentStep) { case 100: data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; case 101: Plugin.KeyDown(VirtualKeys.A2); data.Response = AIResponse.Medium; - currentStep+= 2; + CurrentStep+= 2; return; } } - if (currentStep == 102 || currentStep == 103) + if (CurrentStep == 102 || CurrentStep == 103) { //Raise the cancel key - Plugin.KeyUp(currentStep == 102 ? VirtualKeys.A1 : VirtualKeys.A2); + Plugin.KeyUp(CurrentStep == 102 ? VirtualKeys.A1 : VirtualKeys.A2); data.Response = AIResponse.Medium; - currentStep = 100; + CurrentStep = 100; return; } @@ -205,7 +205,7 @@ internal override void Perform(AIData data) * Assume that with a brightness value below 180 we want night headlights * Further assume that the driver only sets these at the initial station once */ - if (!lightsSet) + if (!LightsSet) { float currentBrightness = Plugin.Train.Cars[Plugin.Train.DriverCar].Brightness.CurrentBrightness(TrainManagerBase.Renderer.Lighting.DynamicCabBrightness, 0.0); switch (Plugin.Panel[20]) @@ -226,7 +226,7 @@ internal override void Perform(AIData data) } else { - lightsSet = true; + LightsSet = true; } return; case 2: @@ -245,7 +245,7 @@ internal override void Perform(AIData data) } else { - lightsSet = true; + LightsSet = true; } return; } @@ -280,13 +280,13 @@ internal override void Perform(AIData data) return; } - if (TrainManagerBase.currentHost.InGameTime > nextPluginAction) + if (TrainManagerBase.CurrentHost.InGameTime > NextPluginAction) { //If nothing else has happened recently, hit the vigilance reset key Plugin.KeyDown(VirtualKeys.A2); Plugin.KeyUp(VirtualKeys.A2); data.Response = AIResponse.Short; - nextPluginAction = TrainManagerBase.currentHost.InGameTime + 20.0; + NextPluginAction = TrainManagerBase.CurrentHost.InGameTime + 20.0; return; } @@ -305,7 +305,7 @@ internal override void Perform(AIData data) switch (Plugin.Panel[198]) { case 0: - if (currentRainIntensity > 30 || shouldWipe) + if (CurrentRainIntensity > 30 || shouldWipe) { Plugin.KeyDown(VirtualKeys.B1); Plugin.KeyUp(VirtualKeys.B1); @@ -313,7 +313,7 @@ internal override void Perform(AIData data) } return; case 1: - if (currentRainIntensity > 45) + if (CurrentRainIntensity > 45) { Plugin.KeyDown(VirtualKeys.B1); Plugin.KeyUp(VirtualKeys.B1); @@ -327,7 +327,7 @@ internal override void Perform(AIData data) } return; case 2: - if (currentRainIntensity < 60) + if (CurrentRainIntensity < 60) { Plugin.KeyDown(VirtualKeys.B2); Plugin.KeyUp(VirtualKeys.B2); @@ -376,7 +376,7 @@ internal override void Perform(AIData data) public override void BeginJump(InitializationModes mode) { - currentStep = mode == InitializationModes.OffEmergency ? 0 : 100; + CurrentStep = mode == InitializationModes.OffEmergency ? 0 : 100; } public override void EndJump() @@ -388,7 +388,7 @@ public override void SetBeacon(BeaconData beacon) { if (beacon.Type == 21) { - currentRainIntensity = beacon.Optional; + CurrentRainIntensity = beacon.Optional; } } } diff --git a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKSpt.cs b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKSpt.cs index 31d69e83b..d419b451a 100644 --- a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKSpt.cs +++ b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.UKSpt.cs @@ -40,43 +40,43 @@ internal class UKSptAI : PluginAI internal UKSptAI(Plugin plugin) { Plugin = plugin; - currentStep = 0; - nextPluginAction = 0; + CurrentStep = 0; + NextPluginAction = 0; vigilanceTimer = 0; } internal override void Perform(AIData data) { - if (Plugin.Train.CurrentSpeed != 0 && currentStep == 0) + if (Plugin.Train.CurrentSpeed != 0 && CurrentStep == 0) { // ai asked to take over at speed, skip startup sequence - currentStep = 100; + CurrentStep = 100; } - switch (currentStep) + switch (CurrentStep) { case 0: // start of startup sequence- start by bringing up TPWS / AWS data.Handles.Reverser = 1; data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; return; case 1: data.Handles.Reverser = 0; data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; return; case 2: if (Plugin.Sound[2] == 0 || Plugin.Sound[2] == -1000) { data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; } return; case 3: Plugin.KeyDown(VirtualKeys.A1); data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; case 4: Plugin.KeyUp(VirtualKeys.A1); @@ -85,33 +85,33 @@ internal override void Perform(AIData data) if (Plugin.Panel[5] == 2) { // engine stopped, continue with startup - currentStep++; + CurrentStep++; } else { // startup test complete - currentStep = 100; + CurrentStep = 100; } return; case 5: Plugin.KeyDown(VirtualKeys.D); data.Response = AIResponse.Long; - currentStep++; + CurrentStep++; return; case 6: - currentStep++; + CurrentStep++; return; case 7: Plugin.KeyUp(VirtualKeys.D); data.Response = AIResponse.Medium; - currentStep = 100; + CurrentStep = 100; return; } if (Plugin.Panel[5] == 3) { // engine either stalled on start, or has been stopped by user - currentStep = 5; + CurrentStep = 5; } if (!doorStart) @@ -134,31 +134,31 @@ internal override void Perform(AIData data) //DRA is enabled, so toggle off Plugin.KeyDown(VirtualKeys.S); data.Response = AIResponse.Medium; - currentStep = 99; + CurrentStep = 99; return; } - if (currentStep == 99) + if (CurrentStep == 99) { Plugin.KeyUp(VirtualKeys.S); data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; } if (Plugin.Sound[2] == 0) { //AWS horn active, so wait a sec before triggering cancel - switch (currentStep) + switch (CurrentStep) { case 100: data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; case 101: Plugin.KeyDown(VirtualKeys.A1); data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; } } @@ -185,26 +185,26 @@ internal override void Perform(AIData data) return; } //Reset alarm - switch (currentStep) + switch (CurrentStep) { case 100: data.Response = AIResponse.Medium; - currentStep++; + CurrentStep++; return; case 101: Plugin.KeyDown(VirtualKeys.A2); data.Response = AIResponse.Medium; - currentStep+= 2; + CurrentStep+= 2; return; } } - if (currentStep == 102 || currentStep == 103) + if (CurrentStep == 102 || CurrentStep == 103) { //Raise the cancel key - Plugin.KeyUp(currentStep == 102 ? VirtualKeys.A1 : VirtualKeys.A2); + Plugin.KeyUp(CurrentStep == 102 ? VirtualKeys.A1 : VirtualKeys.A2); data.Response = AIResponse.Medium; - currentStep = 100; + CurrentStep = 100; return; } //Handle DRA @@ -232,7 +232,7 @@ internal override void Perform(AIData data) * Assume that with a brightness value below 180 we want night headlights * Further assume that the driver only sets these at the initial station once */ - if (!lightsSet) + if (!LightsSet) { float currentBrightness = Plugin.Train.Cars[Plugin.Train.DriverCar].Brightness.CurrentBrightness(TrainManagerBase.Renderer.Lighting.DynamicCabBrightness, 0.0); switch (Plugin.Panel[20]) @@ -253,7 +253,7 @@ internal override void Perform(AIData data) } else { - lightsSet = true; + LightsSet = true; } return; case 2: @@ -272,7 +272,7 @@ internal override void Perform(AIData data) } else { - lightsSet = true; + LightsSet = true; } return; } @@ -286,13 +286,13 @@ internal override void Perform(AIData data) return; } - if (TrainManagerBase.currentHost.InGameTime > nextPluginAction) + if (TrainManagerBase.CurrentHost.InGameTime > NextPluginAction) { //If nothing else has happened recently, hit the AWS reset key to ensure vigilance doesn't trigger Plugin.KeyDown(VirtualKeys.A1); Plugin.KeyUp(VirtualKeys.A1); data.Response = AIResponse.Short; - nextPluginAction = TrainManagerBase.currentHost.InGameTime + 20.0; + NextPluginAction = TrainManagerBase.CurrentHost.InGameTime + 20.0; return; } @@ -311,7 +311,7 @@ internal override void Perform(AIData data) switch (Plugin.Panel[198]) { case 0: - if (currentRainIntensity > 30 || shouldWipe) + if (CurrentRainIntensity > 30 || shouldWipe) { Plugin.KeyDown(VirtualKeys.B1); Plugin.KeyUp(VirtualKeys.B1); @@ -319,7 +319,7 @@ internal override void Perform(AIData data) } return; case 1: - if (currentRainIntensity > 45) + if (CurrentRainIntensity > 45) { Plugin.KeyDown(VirtualKeys.B1); Plugin.KeyUp(VirtualKeys.B1); @@ -333,7 +333,7 @@ internal override void Perform(AIData data) } return; case 2: - if (currentRainIntensity < 60) + if (CurrentRainIntensity < 60) { Plugin.KeyDown(VirtualKeys.B2); Plugin.KeyUp(VirtualKeys.B2); @@ -384,12 +384,12 @@ public override void BeginJump(InitializationModes mode) { if (mode == InitializationModes.OffEmergency) { - currentStep = 0; + CurrentStep = 0; doorStart = false; } else { - currentStep = 100; + CurrentStep = 100; } } @@ -402,7 +402,7 @@ public override void SetBeacon(BeaconData beacon) { if (beacon.Type == 21) { - currentRainIntensity = beacon.Optional; + CurrentRainIntensity = beacon.Optional; } } } diff --git a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.cs b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.cs index 31ad2d92b..8f1a7608a 100644 --- a/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.cs +++ b/source/TrainManager/SafetySystems/Plugin/AI/PluginAI.cs @@ -9,13 +9,13 @@ internal abstract class PluginAI /// The plugin internal Plugin Plugin; /// Control variable used to determine next AI step - internal int currentStep; + internal int CurrentStep; /// Timer variable controlling the next plugin action - internal double nextPluginAction; + internal double NextPluginAction; /// Stores the current rain intensity - internal int currentRainIntensity; + internal int CurrentRainIntensity; /// Whether the plugin has set the lights - internal bool lightsSet; + internal bool LightsSet; /// Called once a frame to perform any AI specific tasks /// The AI Data internal abstract void Perform(AIData data); diff --git a/source/TrainManager/SafetySystems/Plugin/LegacyPlugin.cs b/source/TrainManager/SafetySystems/Plugin/LegacyPlugin.cs index c09f75917..7d979d60b 100644 --- a/source/TrainManager/SafetySystems/Plugin/LegacyPlugin.cs +++ b/source/TrainManager/SafetySystems/Plugin/LegacyPlugin.cs @@ -16,7 +16,7 @@ internal class Win32Plugin : Plugin // --- win32 proxy calls --- [DllImport("AtsPluginProxy.dll", EntryPoint = "LoadDLL", ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)] - private static extern int Win32LoadDLL([MarshalAs(UnmanagedType.LPWStr)] string UnicodeFileName, [MarshalAs(UnmanagedType.LPStr)] string AnsiFileName); + private static extern int Win32LoadDLL([MarshalAs(UnmanagedType.LPWStr)] string unicodeFileName, [MarshalAs(UnmanagedType.LPStr)] string ansiFileName); [DllImport("AtsPluginProxy.dll", EntryPoint = "UnloadDLL", ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] private static extern int Win32UnloadDLL(); @@ -207,7 +207,7 @@ public override bool Load(VehicleSpecs specs, InitializationModes mode) int errorCode = Marshal.GetLastWin32Error(); string errorMessage = new Win32Exception(errorCode).Message; - TrainManagerBase.currentHost.AddMessage(MessageType.Error, true,$"Error loading Win32 plugin: {errorMessage} (0x{errorCode:x})"); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, true,$"Error loading Win32 plugin: {errorMessage} (0x{errorCode:x})"); return false; } @@ -234,7 +234,7 @@ public override bool Load(VehicleSpecs specs, InitializationModes mode) if (version == 0 && System.IO.Path.GetFileName(PluginFile).ToLowerInvariant() != "ats2.dll" || version != 131072) { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + PluginTitle + " is of an unsupported version."); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + PluginTitle + " is of an unsupported version."); try { Win32Dispose(); diff --git a/source/TrainManager/SafetySystems/Plugin/NetPlugin.cs b/source/TrainManager/SafetySystems/Plugin/NetPlugin.cs index a4529d294..1bbe90da7 100644 --- a/source/TrainManager/SafetySystems/Plugin/NetPlugin.cs +++ b/source/TrainManager/SafetySystems/Plugin/NetPlugin.cs @@ -150,10 +150,10 @@ public override bool Load(VehicleSpecs specs, InitializationModes mode) if (properties.FailureReason != null) { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + PluginTitle + " failed to load for the following reason: " + properties.FailureReason); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + PluginTitle + " failed to load for the following reason: " + properties.FailureReason); return false; } - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + PluginTitle + " failed to load for an unspecified reason."); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + PluginTitle + " failed to load for an unspecified reason."); return false; } @@ -413,22 +413,22 @@ public override void RawKeyUp(Key key) } /// May be called from a .Net plugin, in order to add a message to the in-game display - /// The message to display - /// The color in which to display the message - /// The time in seconds for which to display the message - internal void AddInterfaceMessage(string Message, MessageColor Color, double Time) + /// The message to display + /// The color in which to display the message + /// The time in seconds for which to display the message + internal void AddInterfaceMessage(string message, MessageColor color, double time) { - TrainManagerBase.currentHost.AddMessage(Message, MessageDependency.Plugin, GameMode.Expert, Color, TrainManagerBase.currentHost.InGameTime + Time, null); + TrainManagerBase.CurrentHost.AddMessage(message, MessageDependency.Plugin, GameMode.Expert, color, TrainManagerBase.CurrentHost.InGameTime + time, null); } /// May be called from a .Net plugin, in order to add a score to the post-game log - /// The score to add - /// The message to display in the post-game log - /// The color of the in-game message - /// The time in seconds for which to display the in-game message - internal void AddScore(int Score, string Message, MessageColor Color, double Timeout) + /// The score to add + /// The message to display in the post-game log + /// The color of the in-game message + /// The time in seconds for which to display the in-game message + internal void AddScore(int score, string message, MessageColor color, double timeout) { - TrainManagerBase.currentHost.AddScore(Score, Message, Color, Timeout); + TrainManagerBase.CurrentHost.AddScore(score, message, color, timeout); } /// May be called from a .Net plugin to open the train doors @@ -472,11 +472,11 @@ internal SoundHandleEx PlayMultiCarSound(int index, double volume, double pitch, /// The volume of the sound- A volume of 1.0 represents nominal volume /// The pitch of the sound- A pitch of 1.0 represents nominal pitch /// Whether the sound is looped - /// The index of the car which is to emit the sound + /// The index of the car which is to emit the sound /// The sound handle, or null if not successful - internal SoundHandleEx PlayCarSound(int index, double volume, double pitch, bool looped, int CarIndex) + internal SoundHandleEx PlayCarSound(int index, double volume, double pitch, bool looped, int carIndex) { - if (CarIndex < 0 || CarIndex >= Train.Cars.Length) + if (carIndex < 0 || carIndex >= Train.Cars.Length) { // Not a valid car return null; @@ -496,21 +496,21 @@ internal SoundHandleEx PlayCarSound(int index, double volume, double pitch, bool * If a separate soundset has been loaded via XML for the car, this may produce different sounds, but is unavoidable */ - if (!Train.Cars[CarIndex].Sounds.Plugin.ContainsKey(index)) + if (!Train.Cars[carIndex].Sounds.Plugin.ContainsKey(index)) { if (Train.Cars[Train.DriverCar].Sounds.Plugin.ContainsKey(index)) { - Train.Cars[CarIndex].Sounds.Plugin.Add(index, Train.Cars[Train.DriverCar].Sounds.Plugin[index].Clone()); + Train.Cars[carIndex].Sounds.Plugin.Add(index, Train.Cars[Train.DriverCar].Sounds.Plugin[index].Clone()); } } - Train.Cars[CarIndex].Sounds.Plugin[index].Play(pitch, volume, Train.Cars[CarIndex], looped); + Train.Cars[carIndex].Sounds.Plugin[index].Play(pitch, volume, Train.Cars[carIndex], looped); if (SoundHandlesCount == SoundHandles.Length) { Array.Resize(ref SoundHandles, SoundHandles.Length << 1); } - SoundHandles[SoundHandlesCount] = new SoundHandleEx(volume, pitch, Train.Cars[CarIndex].Sounds.Plugin[index].Source); + SoundHandles[SoundHandlesCount] = new SoundHandleEx(volume, pitch, Train.Cars[carIndex].Sounds.Plugin[index].Source); SoundHandlesCount++; return SoundHandles[SoundHandlesCount - 1]; } @@ -520,14 +520,14 @@ internal SoundHandleEx PlayCarSound(int index, double volume, double pitch, bool /// The volume of the sound- A volume of 1.0 represents nominal volume /// The pitch of the sound- A pitch of 1.0 represents nominal pitch /// Whether the sound is looped - /// The index of the cars which are to emit the sound + /// The index of the cars which are to emit the sound /// The sound handle, or null if not successful - internal SoundHandleEx[] PlayMultiCarSound(int index, double volume, double pitch, bool looped, int[] CarIndicies) + internal SoundHandleEx[] PlayMultiCarSound(int index, double volume, double pitch, bool looped, int[] carIndicies) { - SoundHandleEx[] soundHandles = new SoundHandleEx[CarIndicies.Length]; - for (int i = 0; i < CarIndicies.Length; i++) + SoundHandleEx[] soundHandles = new SoundHandleEx[carIndicies.Length]; + for (int i = 0; i < carIndicies.Length; i++) { - soundHandles[i] = PlayCarSound(index, volume, pitch, looped, CarIndicies[i]); + soundHandles[i] = PlayCarSound(index, volume, pitch, looped, carIndicies[i]); } return soundHandles; } diff --git a/source/TrainManager/SafetySystems/Plugin/Plugin.Functions.cs b/source/TrainManager/SafetySystems/Plugin/Plugin.Functions.cs index 726099c43..f82c99a51 100644 --- a/source/TrainManager/SafetySystems/Plugin/Plugin.Functions.cs +++ b/source/TrainManager/SafetySystems/Plugin/Plugin.Functions.cs @@ -22,9 +22,9 @@ public bool LoadCustomPlugin(string trainFolder, System.Text.Encoding encoding) return false; } - string Text = System.IO.File.ReadAllText(config, encoding); - Text = Text.Replace("\r", "").Replace("\n", ""); - if (Text.Length > 260) + string text = System.IO.File.ReadAllText(config, encoding); + text = text.Replace("\r", "").Replace("\n", ""); + if (text.Length > 260) { /* * String length is over max Windows path length, so @@ -43,7 +43,7 @@ public bool LoadCustomPlugin(string trainFolder, System.Text.Encoding encoding) fileLines[i] = fileLines[i].Trim(); if (fileLines[i].Length != 0) { - Text = fileLines[i]; + text = fileLines[i]; break; } } @@ -52,34 +52,34 @@ public bool LoadCustomPlugin(string trainFolder, System.Text.Encoding encoding) string file; try { - file = OpenBveApi.Path.CombineFile(trainFolder, Text); + file = OpenBveApi.Path.CombineFile(trainFolder, text); } catch { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, true, "The train plugin path was malformed in " + config); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, true, "The train plugin path was malformed in " + config); return false; } string title = System.IO.Path.GetFileName(file); if (!System.IO.File.Exists(file)) { - if (Text.EndsWith(".dll") && encoding.Equals(System.Text.Encoding.Unicode)) + if (text.EndsWith(".dll") && encoding.Equals(System.Text.Encoding.Unicode)) { // Our filename ends with .dll so probably is not mangled Unicode - TrainManagerBase.currentHost.AddMessage(MessageType.Error, true, "The train plugin " + title + " could not be found in " + config); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, true, "The train plugin " + title + " could not be found in " + config); return false; } // Try again with ASCII encoding - Text = System.IO.File.ReadAllText(config, System.Text.Encoding.GetEncoding(1252)); - Text = Text.Replace("\r", "").Replace("\n", ""); + text = System.IO.File.ReadAllText(config, System.Text.Encoding.GetEncoding(1252)); + text = text.Replace("\r", "").Replace("\n", ""); try { - file = OpenBveApi.Path.CombineFile(trainFolder, Text); + file = OpenBveApi.Path.CombineFile(trainFolder, text); } catch { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, true, "The train plugin path was malformed in " + config); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, true, "The train plugin path was malformed in " + config); return false; } @@ -87,13 +87,13 @@ public bool LoadCustomPlugin(string trainFolder, System.Text.Encoding encoding) if (!System.IO.File.Exists(file)) { // Nope, still not found - TrainManagerBase.currentHost.AddMessage(MessageType.Error, true, "The train plugin " + title + " could not be found in " + config); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, true, "The train plugin " + title + " could not be found in " + config); return false; } } - TrainManagerBase.currentHost.AddMessage(MessageType.Information, false, "Loading train plugin: " + file); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Information, false, "Loading train plugin: " + file); bool success = LoadPlugin(file, trainFolder); if (success == false) { @@ -101,7 +101,7 @@ public bool LoadCustomPlugin(string trainFolder, System.Text.Encoding encoding) } else { - TrainManagerBase.currentHost.AddMessage(MessageType.Information, false, "Train plugin loaded successfully."); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Information, false, "Train plugin loaded successfully."); } return success; @@ -154,7 +154,7 @@ public bool LoadPlugin(string pluginFile, string trainFolder) string pluginTitle = System.IO.Path.GetFileName(pluginFile); if (!System.IO.File.Exists(pluginFile)) { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, true, "The train plugin " + pluginTitle + " could not be found."); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, true, "The train plugin " + pluginTitle + " could not be found."); return false; } @@ -187,7 +187,7 @@ public bool LoadPlugin(string pluginFile, string trainFolder) AssemblyName myAssembly = AssemblyName.GetAssemblyName(pluginFile); if (IntPtr.Size != 4 && myAssembly.ProcessorArchitecture == ProcessorArchitecture.X86) { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " can only be used with the 32-bit version of " + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"program","title"})); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " can only be used with the 32-bit version of " + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"program","title"})); return false; } } @@ -199,7 +199,7 @@ public bool LoadPlugin(string pluginFile, string trainFolder) } catch (Exception ex) { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be loaded due to the following exception: " + ex.Message); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be loaded due to the following exception: " + ex.Message); return false; } @@ -214,7 +214,7 @@ public bool LoadPlugin(string pluginFile, string trainFolder) { foreach (Exception e in ex.LoaderExceptions) { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " raised an exception on loading: " + e.Message); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " raised an exception on loading: " + e.Message); } return false; @@ -257,7 +257,7 @@ public bool LoadPlugin(string pluginFile, string trainFolder) } } - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with" + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"program","title"})); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with" + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"program","title"})); return false; } @@ -269,22 +269,22 @@ public bool LoadPlugin(string pluginFile, string trainFolder) { if (!Win32Plugin.CheckHeader(pluginFile)) { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " is of an unsupported binary format and therefore cannot be used with " + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"program","title"})); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " is of an unsupported binary format and therefore cannot be used with " + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"program","title"})); return false; } } catch (Exception ex) { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be read due to the following reason: " + ex.Message); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be read due to the following reason: " + ex.Message); return false; } - switch (TrainManagerBase.currentHost.Platform) + switch (TrainManagerBase.CurrentHost.Platform) { case HostPlatform.WINE: if (IntPtr.Size != 4) { - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "WINE does not support the WCF plugin proxy- Please use the 32-bit version of OpenBVE to load this train plugin."); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "WINE does not support the WCF plugin proxy- Please use the 32-bit version of OpenBVE to load this train plugin."); return false; } break; @@ -299,18 +299,18 @@ public bool LoadPlugin(string pluginFile, string trainFolder) } Plugin = null; - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " failed to load."); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " failed to load."); return false; } break; default: - TrainManagerBase.currentHost.AddMessage(MessageType.Warning, false, "Legacy Win32 train plugins " + pluginTitle + " can only be used on Microsoft Windows or compatible."); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Warning, false, "Legacy Win32 train plugins " + pluginTitle + " can only be used on Microsoft Windows or compatible."); return false; } - if (TrainManagerBase.currentHost.Platform == HostPlatform.MicrosoftWindows && !System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\AtsPluginProxy.dll")) + if (TrainManagerBase.CurrentHost.Platform == HostPlatform.MicrosoftWindows && !System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\AtsPluginProxy.dll")) { - TrainManagerBase.currentHost.AddMessage(MessageType.Warning, false, "AtsPluginProxy.dll is missing or corrupt- Please reinstall."); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Warning, false, "AtsPluginProxy.dll is missing or corrupt- Please reinstall."); return false; } @@ -321,7 +321,7 @@ public bool LoadPlugin(string pluginFile, string trainFolder) } Plugin = null; - TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with" + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"program","title"})); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with" + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"program","title"})); return false; } diff --git a/source/TrainManager/SafetySystems/Plugin/Plugin.cs b/source/TrainManager/SafetySystems/Plugin/Plugin.cs index 1539dd399..98836daac 100644 --- a/source/TrainManager/SafetySystems/Plugin/Plugin.cs +++ b/source/TrainManager/SafetySystems/Plugin/Plugin.cs @@ -129,11 +129,11 @@ public void UpdatePlugin() //End of additions double speed = this.Train.Cars[this.Train.DriverCar].Specs.PerceivedSpeed; - double bcPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.brakeCylinder.CurrentPressure; - double mrPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.mainReservoir.CurrentPressure; - double erPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.equalizingReservoir.CurrentPressure; - double bpPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.brakePipe.CurrentPressure; - double sapPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.straightAirPipe.CurrentPressure; + double bcPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.BrakeCylinder.CurrentPressure; + double mrPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.MainReservoir.CurrentPressure; + double erPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.EqualizingReservoir.CurrentPressure; + double bpPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.BrakePipe.CurrentPressure; + double sapPressure = this.Train.Cars[this.Train.DriverCar].CarBrake.StraightAirPipe.CurrentPressure; bool wheelSlip = false; for (int i = 0; i < this.Train.Cars.Length; i++) { @@ -157,7 +157,7 @@ public void UpdatePlugin() PrecedingVehicleState precedingVehicle; try { - AbstractTrain closestTrain = TrainManagerBase.currentHost.ClosestTrain(this.Train); + AbstractTrain closestTrain = TrainManagerBase.CurrentHost.ClosestTrain(this.Train); precedingVehicle = closestTrain != null ? new PrecedingVehicleState(closestTrain.RearCarTrackPosition, closestTrain.RearCarTrackPosition - location, new Speed(closestTrain.CurrentSpeed)) : new PrecedingVehicleState(Double.MaxValue, Double.MaxValue - location, new Speed(0.0)); } catch @@ -172,12 +172,12 @@ public void UpdatePlugin() /* * Update the plugin. * */ - double totalTime = TrainManagerBase.currentHost.InGameTime; - double elapsedTime = TrainManagerBase.currentHost.InGameTime - LastTime; + double totalTime = TrainManagerBase.CurrentHost.InGameTime; + double elapsedTime = TrainManagerBase.CurrentHost.InGameTime - LastTime; ElapseData data = new ElapseData(vehicle, precedingVehicle, handles, this.Train.SafetySystems.DoorInterlockState, this.Train.SafetySystems.Headlights.CurrentState, new Time(totalTime), new Time(elapsedTime), currentRouteStations, TrainManagerBase.Renderer.Camera.CurrentMode, Translations.CurrentLanguageCode, this.Train.Destination); ElapseData inputDevicePluginData = data; - LastTime = TrainManagerBase.currentHost.InGameTime; + LastTime = TrainManagerBase.CurrentHost.InGameTime; Elapse(ref data); this.PluginMessage = data.DebugMessage; this.Train.SafetySystems.DoorInterlockState = data.DoorInterlockState; diff --git a/source/TrainManager/SafetySystems/Plugin/ProxyPlugin.cs b/source/TrainManager/SafetySystems/Plugin/ProxyPlugin.cs index 2ed66b595..090463db4 100644 --- a/source/TrainManager/SafetySystems/Plugin/ProxyPlugin.cs +++ b/source/TrainManager/SafetySystems/Plugin/ProxyPlugin.cs @@ -287,10 +287,10 @@ protected override void PerformAI(AIData data) } } - public void ReportError(string Error, bool Critical = false) + public void ReportError(string error, bool critical = false) { - lastError = Error; - if (Critical) + lastError = error; + if (critical) { externalCrashed = true; } diff --git a/source/TrainManager/SafetySystems/StationAdjustAlarm.cs b/source/TrainManager/SafetySystems/StationAdjustAlarm.cs index ef22ad74f..c2b96917c 100644 --- a/source/TrainManager/SafetySystems/StationAdjustAlarm.cs +++ b/source/TrainManager/SafetySystems/StationAdjustAlarm.cs @@ -34,7 +34,7 @@ public void Update(double tb, double tf) AdjustAlarm.Play(baseTrain.Cars[baseTrain.DriverCar], false); if (baseTrain.IsPlayerTrain) { - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"message","station_correct"}), MessageDependency.None, GameMode.Normal, MessageColor.Orange, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 5.0, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"message","station_correct"}), MessageDependency.None, GameMode.Normal, MessageColor.Orange, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 5.0, null); } Lit = true; } diff --git a/source/TrainManager/TrackFollowingObject/AI/TrackFollowingObject.AI.cs b/source/TrainManager/TrackFollowingObject/AI/TrackFollowingObject.AI.cs index ee435ab93..3c033c631 100644 --- a/source/TrainManager/TrackFollowingObject/AI/TrackFollowingObject.AI.cs +++ b/source/TrainManager/TrackFollowingObject/AI/TrackFollowingObject.AI.cs @@ -44,9 +44,9 @@ public TrackFollowingObjectAI(ScriptedTrain train, TravelData[] data) CheckTravelData(); } - public override void Trigger(double TimeElapsed) + public override void Trigger(double timeElapsed) { - if (TrainManagerBase.currentHost.InGameTime == TimeLastProcessed) + if (TrainManagerBase.CurrentHost.InGameTime == TimeLastProcessed) { return; } @@ -54,46 +54,46 @@ public override void Trigger(double TimeElapsed) // Initialize if (TimeLastProcessed == 0.0) { - AppearanceTime = TrainManagerBase.currentHost.InGameTime; + AppearanceTime = TrainManagerBase.CurrentHost.InGameTime; LeaveTime = AppearanceTime + Train.LeaveTime; CurrentPosition = Data[0].Position; } - TimeLastProcessed = TrainManagerBase.currentHost.InGameTime; + TimeLastProcessed = TrainManagerBase.CurrentHost.InGameTime; // Dispose the train if it is past the leave time of the train - if (LeaveTime > AppearanceTime && TrainManagerBase.currentHost.InGameTime >= LeaveTime) + if (LeaveTime > AppearanceTime && TrainManagerBase.CurrentHost.InGameTime >= LeaveTime) { Train.Dispose(); return; } // Calculate the position where the train is at the present time. - GetNewState(TrainManagerBase.currentHost.InGameTime - AppearanceTime, out double NewMileage, out double NewPosition, out TravelDirection NewDirection, out bool OpenLeftDoors, out bool OpenRightDoors); + GetNewState(TrainManagerBase.CurrentHost.InGameTime - AppearanceTime, out double newMileage, out double newPosition, out TravelDirection newDirection, out bool openLeftDoors, out bool openRightDoors); // Calculate the travel distance of the train. - double DeltaPosition = NewPosition - CurrentPosition; + double deltaPosition = newPosition - CurrentPosition; // Set the state quantity of the train. - if (DeltaPosition < 0) + if (deltaPosition < 0) { Train.Handles.Reverser.Driver = ReverserPosition.Reverse; } - else if (DeltaPosition > 0) + else if (deltaPosition > 0) { Train.Handles.Reverser.Driver = ReverserPosition.Forwards; } Train.Handles.Reverser.Actual = Train.Handles.Reverser.Driver; - Train.OpenDoors(OpenLeftDoors, OpenRightDoors); - Train.CloseDoors(!OpenLeftDoors, !OpenRightDoors); + Train.OpenDoors(openLeftDoors, openRightDoors); + Train.CloseDoors(!openLeftDoors, !openRightDoors); - if (TimeElapsed != 0.0) + if (timeElapsed != 0.0) { double oldSpeed = Train.CurrentSpeed; - Train.CurrentSpeed = DeltaPosition / TimeElapsed; - Train.Specs.CurrentAverageAcceleration = (int)NewDirection * (Train.CurrentSpeed - oldSpeed) / TimeElapsed; + Train.CurrentSpeed = deltaPosition / timeElapsed; + Train.Specs.CurrentAverageAcceleration = (int)newDirection * (Train.CurrentSpeed - oldSpeed) / timeElapsed; } else { @@ -101,143 +101,143 @@ public override void Trigger(double TimeElapsed) Train.Specs.CurrentAverageAcceleration = 0.0; } - foreach (var Car in Train.Cars) + foreach (var car in Train.Cars) { - SetRailIndex(NewMileage, NewDirection, Car.FrontAxle.Follower); - SetRailIndex(NewMileage, NewDirection, Car.RearAxle.Follower); - SetRailIndex(NewMileage, NewDirection, Car.FrontBogie.FrontAxle.Follower); - SetRailIndex(NewMileage, NewDirection, Car.FrontBogie.RearAxle.Follower); - SetRailIndex(NewMileage, NewDirection, Car.RearBogie.FrontAxle.Follower); - SetRailIndex(NewMileage, NewDirection, Car.RearBogie.RearAxle.Follower); - - Car.Move(DeltaPosition); - - Car.CurrentSpeed = Train.CurrentSpeed; - Car.Specs.PerceivedSpeed = Train.CurrentSpeed; - Car.Specs.Acceleration = Train.Specs.CurrentAverageAcceleration; - Car.Specs.MotorAcceleration = Train.Specs.CurrentAverageAcceleration; + SetRailIndex(newMileage, newDirection, car.FrontAxle.Follower); + SetRailIndex(newMileage, newDirection, car.RearAxle.Follower); + SetRailIndex(newMileage, newDirection, car.FrontBogie.FrontAxle.Follower); + SetRailIndex(newMileage, newDirection, car.FrontBogie.RearAxle.Follower); + SetRailIndex(newMileage, newDirection, car.RearBogie.FrontAxle.Follower); + SetRailIndex(newMileage, newDirection, car.RearBogie.RearAxle.Follower); + + car.Move(deltaPosition); + + car.CurrentSpeed = Train.CurrentSpeed; + car.Specs.PerceivedSpeed = Train.CurrentSpeed; + car.Specs.Acceleration = Train.Specs.CurrentAverageAcceleration; + car.Specs.MotorAcceleration = Train.Specs.CurrentAverageAcceleration; } - CurrentPosition = NewPosition; + CurrentPosition = newPosition; } /// Create a train operation plan. internal void SetupTravelData() { // The first point must be TravelStopData. - TravelStopData FirstData = (TravelStopData)Data[0]; + TravelStopData firstData = (TravelStopData)Data[0]; // Calculate the end point of acceleration and the start point of deceleration. { - TravelDirection LastDirection; - double DeltaPosition; + TravelDirection lastDirection; + double deltaPosition; // The start point does not slow down. Acceleration only. { - FirstData.Mileage = 0.0; - LastDirection = FirstData.Direction; - DeltaPosition = 0.0; - if (FirstData.Accelerate != 0.0) + firstData.Mileage = 0.0; + lastDirection = firstData.Direction; + deltaPosition = 0.0; + if (firstData.Accelerate != 0.0) { - DeltaPosition = Math.Pow(FirstData.TargetSpeed, 2.0) / (2.0 * FirstData.Accelerate); + deltaPosition = Math.Pow(firstData.TargetSpeed, 2.0) / (2.0 * firstData.Accelerate); } - FirstData.AccelerationEndPosition = FirstData.Position + (int)LastDirection * DeltaPosition; + firstData.AccelerationEndPosition = firstData.Position + (int)lastDirection * deltaPosition; } for (int i = 1; i < Data.Length; i++) { - DeltaPosition = 0.0; + deltaPosition = 0.0; if (Data[i].Decelerate != 0.0) { - DeltaPosition = (Math.Pow(Data[i].PassingSpeed, 2.0) - Math.Pow(Data[i - 1].TargetSpeed, 2.0)) / (2.0 * Data[i].Decelerate); + deltaPosition = (Math.Pow(Data[i].PassingSpeed, 2.0) - Math.Pow(Data[i - 1].TargetSpeed, 2.0)) / (2.0 * Data[i].Decelerate); } - Data[i].DecelerationStartPosition = Data[i].Position - (int)LastDirection * DeltaPosition; + Data[i].DecelerationStartPosition = Data[i].Position - (int)lastDirection * deltaPosition; Data[i].Mileage = Data[i - 1].Mileage + Math.Abs(Data[i].Position - Data[i - 1].Position); - LastDirection = (Data[i] as TravelStopData)?.Direction ?? LastDirection; - DeltaPosition = 0.0; + lastDirection = (Data[i] as TravelStopData)?.Direction ?? lastDirection; + deltaPosition = 0.0; if (Data[i].Accelerate != 0.0) { - DeltaPosition = (Math.Pow(Data[i].TargetSpeed, 2.0) - Math.Pow(Data[i].PassingSpeed, 2.0)) / (2.0 * Data[i].Accelerate); + deltaPosition = (Math.Pow(Data[i].TargetSpeed, 2.0) - Math.Pow(Data[i].PassingSpeed, 2.0)) / (2.0 * Data[i].Accelerate); } - Data[i].AccelerationEndPosition = Data[i].Position + (int)LastDirection * DeltaPosition; + Data[i].AccelerationEndPosition = Data[i].Position + (int)lastDirection * deltaPosition; } } // Reflect the delay until the TFO becomes effective at the first point. { - if (FirstData.OpenLeftDoors || FirstData.OpenRightDoors) + if (firstData.OpenLeftDoors || firstData.OpenRightDoors) { - FirstData.OpeningDoorsEndTime += OpeningDoorsTime; + firstData.OpeningDoorsEndTime += OpeningDoorsTime; } - FirstData.ClosingDoorsStartTime = FirstData.OpeningDoorsEndTime + FirstData.StopTime; - FirstData.DepartureTime = FirstData.ClosingDoorsStartTime; - if (FirstData.OpenLeftDoors || FirstData.OpenRightDoors) + firstData.ClosingDoorsStartTime = firstData.OpeningDoorsEndTime + firstData.StopTime; + firstData.DepartureTime = firstData.ClosingDoorsStartTime; + if (firstData.OpenLeftDoors || firstData.OpenRightDoors) { - FirstData.DepartureTime += ClosingDoorsTime; + firstData.DepartureTime += ClosingDoorsTime; } } // Calculate the time of each point. { - double DeltaT; + double deltaT; // The start point does not slow down. Acceleration only. { - DeltaT = 0.0; - if (FirstData.Accelerate != 0.0) + deltaT = 0.0; + if (firstData.Accelerate != 0.0) { - DeltaT = FirstData.TargetSpeed / FirstData.Accelerate; + deltaT = firstData.TargetSpeed / firstData.Accelerate; } - FirstData.AccelerationEndTime = FirstData.DepartureTime + DeltaT; + firstData.AccelerationEndTime = firstData.DepartureTime + deltaT; } for (int i = 1; i < Data.Length; i++) { - DeltaT = 0.0; + deltaT = 0.0; if (Data[i - 1].TargetSpeed != 0.0) { - DeltaT = Math.Abs(Data[i].DecelerationStartPosition - Data[i - 1].AccelerationEndPosition) / Data[i - 1].TargetSpeed; + deltaT = Math.Abs(Data[i].DecelerationStartPosition - Data[i - 1].AccelerationEndPosition) / Data[i - 1].TargetSpeed; } - Data[i].DecelerationStartTime = Data[i - 1].AccelerationEndTime + DeltaT; + Data[i].DecelerationStartTime = Data[i - 1].AccelerationEndTime + deltaT; - DeltaT = 0.0; + deltaT = 0.0; if (Data[i].Decelerate != 0.0) { - DeltaT = (Data[i].PassingSpeed - Data[i - 1].TargetSpeed) / Data[i].Decelerate; + deltaT = (Data[i].PassingSpeed - Data[i - 1].TargetSpeed) / Data[i].Decelerate; } - Data[i].ArrivalTime = Data[i].DecelerationStartTime + DeltaT; + Data[i].ArrivalTime = Data[i].DecelerationStartTime + deltaT; - if (Data[i] is TravelStopData StopData) + if (Data[i] is TravelStopData stopData) { - StopData.OpeningDoorsEndTime = StopData.ArrivalTime; - if (StopData.OpenLeftDoors || StopData.OpenRightDoors) + stopData.OpeningDoorsEndTime = stopData.ArrivalTime; + if (stopData.OpenLeftDoors || stopData.OpenRightDoors) { - StopData.OpeningDoorsEndTime += OpeningDoorsTime; + stopData.OpeningDoorsEndTime += OpeningDoorsTime; } - StopData.ClosingDoorsStartTime = StopData.OpeningDoorsEndTime + StopData.StopTime; - StopData.DepartureTime = StopData.ClosingDoorsStartTime; - if (StopData.OpenLeftDoors || StopData.OpenRightDoors) + stopData.ClosingDoorsStartTime = stopData.OpeningDoorsEndTime + stopData.StopTime; + stopData.DepartureTime = stopData.ClosingDoorsStartTime; + if (stopData.OpenLeftDoors || stopData.OpenRightDoors) { - StopData.DepartureTime += ClosingDoorsTime; + stopData.DepartureTime += ClosingDoorsTime; } } - DeltaT = 0.0; + deltaT = 0.0; if (Data[i].Accelerate != 0.0) { - DeltaT = (Data[i].TargetSpeed - Data[i].PassingSpeed) / Data[i].Accelerate; + deltaT = (Data[i].TargetSpeed - Data[i].PassingSpeed) / Data[i].Accelerate; } - Data[i].AccelerationEndTime = Data[i].DepartureTime + DeltaT; + Data[i].AccelerationEndTime = Data[i].DepartureTime + deltaT; } } } @@ -245,139 +245,139 @@ internal void SetupTravelData() /// Check whether the travel plan of the train is valid. private void CheckTravelData() { - bool Recalculation = false; - TravelDirection LastDirection = ((TravelStopData)Data[0]).Direction; + bool recalculation = false; + TravelDirection lastDirection = ((TravelStopData)Data[0]).Direction; for (int i = 1; i < Data.Length; i++) { // The deceleration start point must appear after the acceleration end point. - if ((Data[i - 1].AccelerationEndPosition - Data[i].DecelerationStartPosition) * (int)LastDirection > 0) + if ((Data[i - 1].AccelerationEndPosition - Data[i].DecelerationStartPosition) * (int)lastDirection > 0) { // Reset acceleration and deceleration. - double Delta = Math.Abs(Data[i].Position - Data[i - 1].Position); - if (Delta != 0.0) + double delta = Math.Abs(Data[i].Position - Data[i - 1].Position); + if (delta != 0.0) { - Data[i - 1].Accelerate = (Math.Pow(Data[i - 1].TargetSpeed, 2.0) - Math.Pow(Data[i - 1].PassingSpeed, 2.0)) / Delta; - Data[i].Decelerate = (Math.Pow(Data[i].PassingSpeed, 2.0) - Math.Pow(Data[i - 1].TargetSpeed, 2.0)) / Delta; - Recalculation = true; + Data[i - 1].Accelerate = (Math.Pow(Data[i - 1].TargetSpeed, 2.0) - Math.Pow(Data[i - 1].PassingSpeed, 2.0)) / delta; + Data[i].Decelerate = (Math.Pow(Data[i].PassingSpeed, 2.0) - Math.Pow(Data[i - 1].TargetSpeed, 2.0)) / delta; + recalculation = true; } } - LastDirection = (Data[i] as TravelStopData)?.Direction ?? LastDirection; + lastDirection = (Data[i] as TravelStopData)?.Direction ?? lastDirection; } // Recreate the operation plan of the train. - if (Recalculation) + if (recalculation) { SetupTravelData(); } } - private void GetNewState(double Time, out double NewMileage, out double NewPosition, out TravelDirection NewDirection, out bool OpenLeftDoors, out bool OpenRightDoors) + private void GetNewState(double time, out double newMileage, out double newPosition, out TravelDirection newDirection, out bool openLeftDoors, out bool openRightDoors) { - double DeltaT; - double DeltaPosition; - OpenLeftDoors = false; - OpenRightDoors = false; + double deltaT; + double deltaPosition; + openLeftDoors = false; + openRightDoors = false; { // The first point must be TravelStopData. - TravelStopData FirstData = (TravelStopData)Data[0]; + TravelStopData firstData = (TravelStopData)Data[0]; - NewMileage = FirstData.Mileage; - NewPosition = FirstData.Position; - NewDirection = FirstData.Direction; + newMileage = firstData.Mileage; + newPosition = firstData.Position; + newDirection = firstData.Direction; - if (Time <= FirstData.ArrivalTime) + if (time <= firstData.ArrivalTime) { return; } - if (Time <= FirstData.ClosingDoorsStartTime) + if (time <= firstData.ClosingDoorsStartTime) { - OpenLeftDoors = FirstData.OpenLeftDoors; - OpenRightDoors = FirstData.OpenRightDoors; + openLeftDoors = firstData.OpenLeftDoors; + openRightDoors = firstData.OpenRightDoors; return; } - if (Time <= FirstData.DepartureTime) + if (time <= firstData.DepartureTime) { return; } // The start point does not slow down. Acceleration only. - if (Time <= FirstData.AccelerationEndTime) + if (time <= firstData.AccelerationEndTime) { - DeltaT = Time - FirstData.DepartureTime; - DeltaPosition = 0.5 * FirstData.Accelerate * Math.Pow(DeltaT, 2.0); - NewMileage += DeltaPosition; - NewPosition += (int)NewDirection * DeltaPosition; + deltaT = time - firstData.DepartureTime; + deltaPosition = 0.5 * firstData.Accelerate * Math.Pow(deltaT, 2.0); + newMileage += deltaPosition; + newPosition += (int)newDirection * deltaPosition; return; } - NewMileage += Math.Abs(FirstData.AccelerationEndPosition - NewPosition); - NewPosition = FirstData.AccelerationEndPosition; + newMileage += Math.Abs(firstData.AccelerationEndPosition - newPosition); + newPosition = firstData.AccelerationEndPosition; } for (int i = 1; i < Data.Length; i++) { - if (Time <= Data[i].DecelerationStartTime) + if (time <= Data[i].DecelerationStartTime) { - DeltaT = Time - Data[i - 1].AccelerationEndTime; - DeltaPosition = Data[i - 1].TargetSpeed * DeltaT; - NewMileage += DeltaPosition; - NewPosition += (int)NewDirection * DeltaPosition; + deltaT = time - Data[i - 1].AccelerationEndTime; + deltaPosition = Data[i - 1].TargetSpeed * deltaT; + newMileage += deltaPosition; + newPosition += (int)newDirection * deltaPosition; return; } - NewMileage += Math.Abs(Data[i].DecelerationStartPosition - NewPosition); - NewPosition = Data[i].DecelerationStartPosition; + newMileage += Math.Abs(Data[i].DecelerationStartPosition - newPosition); + newPosition = Data[i].DecelerationStartPosition; - if (Time <= Data[i].ArrivalTime) + if (time <= Data[i].ArrivalTime) { - DeltaT = Time - Data[i].DecelerationStartTime; - DeltaPosition = Data[i - 1].TargetSpeed * DeltaT + 0.5 * Data[i].Decelerate * Math.Pow(DeltaT, 2.0); - NewMileage += DeltaPosition; - NewPosition += (int)NewDirection * DeltaPosition; + deltaT = time - Data[i].DecelerationStartTime; + deltaPosition = Data[i - 1].TargetSpeed * deltaT + 0.5 * Data[i].Decelerate * Math.Pow(deltaT, 2.0); + newMileage += deltaPosition; + newPosition += (int)newDirection * deltaPosition; return; } - TravelStopData StopData = Data[i] as TravelStopData; + TravelStopData stopData = Data[i] as TravelStopData; - NewMileage = Data[i].Mileage; - NewPosition = Data[i].Position; - NewDirection = StopData?.Direction ?? NewDirection; + newMileage = Data[i].Mileage; + newPosition = Data[i].Position; + newDirection = stopData?.Direction ?? newDirection; - if (Time <= StopData?.ClosingDoorsStartTime) + if (time <= stopData?.ClosingDoorsStartTime) { - OpenLeftDoors = StopData.OpenLeftDoors; - OpenRightDoors = StopData.OpenRightDoors; + openLeftDoors = stopData.OpenLeftDoors; + openRightDoors = stopData.OpenRightDoors; return; } // The end point does not accelerate. - if (Time <= Data[i].DepartureTime || i == Data.Length - 1) + if (time <= Data[i].DepartureTime || i == Data.Length - 1) { return; } - if (Time <= Data[i].AccelerationEndTime) + if (time <= Data[i].AccelerationEndTime) { - DeltaT = Time - Data[i].DepartureTime; - DeltaPosition = Data[i].PassingSpeed * DeltaT + 0.5 * Data[i].Accelerate * Math.Pow(DeltaT, 2.0); - NewMileage += DeltaPosition; - NewPosition += (int)NewDirection * DeltaPosition; + deltaT = time - Data[i].DepartureTime; + deltaPosition = Data[i].PassingSpeed * deltaT + 0.5 * Data[i].Accelerate * Math.Pow(deltaT, 2.0); + newMileage += deltaPosition; + newPosition += (int)newDirection * deltaPosition; return; } - NewMileage += Math.Abs(Data[i].AccelerationEndPosition - NewPosition); - NewPosition = Data[i].AccelerationEndPosition; + newMileage += Math.Abs(Data[i].AccelerationEndPosition - newPosition); + newPosition = Data[i].AccelerationEndPosition; } } - private void SetRailIndex(double Mileage, TravelDirection Direction, TrackFollower TrackFollower) + private void SetRailIndex(double mileage, TravelDirection direction, TrackFollower trackFollower) { - TrackFollower.TrackIndex = Data.LastOrDefault(x => x.Mileage <= Mileage + (int)Direction * (TrackFollower.TrackPosition - CurrentPosition))?.RailIndex ?? Data[0].RailIndex; + trackFollower.TrackIndex = Data.LastOrDefault(x => x.Mileage <= mileage + (int)direction * (trackFollower.TrackPosition - CurrentPosition))?.RailIndex ?? Data[0].RailIndex; } } } diff --git a/source/TrainManager/TrackFollowingObject/ScriptedTrain.cs b/source/TrainManager/TrackFollowingObject/ScriptedTrain.cs index 28bc9159b..0793f3323 100644 --- a/source/TrainManager/TrackFollowingObject/ScriptedTrain.cs +++ b/source/TrainManager/TrackFollowingObject/ScriptedTrain.cs @@ -34,20 +34,20 @@ public override void Dispose() Cars[i].RearBogie.ChangeSection(-1); Cars[i].Coupler.ChangeSection(-1); } - TrainManagerBase.currentHost.StopAllSounds(this); + TrainManagerBase.CurrentHost.StopAllSounds(this); } /// Call this method to update the train - /// The elapsed time this frame - public override void Update(double TimeElapsed) + /// The elapsed time this frame + public override void Update(double timeElapsed) { if (State == TrainState.Pending) { // pending train - if (TrainManagerBase.currentHost.InGameTime >= AppearanceTime) + if (TrainManagerBase.CurrentHost.InGameTime >= AppearanceTime) { - double PlayerTrainTrackPosition = TrainManagerBase.PlayerTrain.Cars[0].FrontAxle.Follower.TrackPosition + 0.5 * TrainManagerBase.PlayerTrain.Cars[0].Length - TrainManagerBase.PlayerTrain.Cars[0].FrontAxle.Position; - if (PlayerTrainTrackPosition < AppearanceStartPosition || (PlayerTrainTrackPosition > AppearanceEndPosition && AppearanceEndPosition > AppearanceStartPosition)) + double playerTrainTrackPosition = TrainManagerBase.PlayerTrain.Cars[0].FrontAxle.Follower.TrackPosition + 0.5 * TrainManagerBase.PlayerTrain.Cars[0].Length - TrainManagerBase.PlayerTrain.Cars[0].FrontAxle.Position; + if (playerTrainTrackPosition < AppearanceStartPosition || (playerTrainTrackPosition > AppearanceEndPosition && AppearanceEndPosition > AppearanceStartPosition)) { return; } @@ -74,7 +74,7 @@ public override void Update(double TimeElapsed) else if (State == TrainState.Available) { // available train - UpdatePhysicsAndControls(TimeElapsed); + UpdatePhysicsAndControls(timeElapsed); for (int i = 0; i < Cars.Length; i++) { byte dnb; @@ -116,21 +116,21 @@ public override void Update(double TimeElapsed) } } - AI?.Trigger(TimeElapsed); + AI?.Trigger(timeElapsed); } } else if (State == TrainState.Bogus) { // bogus train - AI?.Trigger(TimeElapsed); + AI?.Trigger(timeElapsed); } } /// Updates the physics and controls for this train - /// The time elapsed - private void UpdatePhysicsAndControls(double TimeElapsed) + /// The time elapsed + private void UpdatePhysicsAndControls(double timeElapsed) { - if (TimeElapsed == 0.0 || TimeElapsed > 1000) + if (timeElapsed == 0.0 || timeElapsed > 1000) { //HACK: The physics engine really does not like update times above 1000ms //This works around a bug experienced when jumping to a station on a steep hill @@ -139,18 +139,18 @@ private void UpdatePhysicsAndControls(double TimeElapsed) } // update station and doors - UpdateDoors(TimeElapsed); + UpdateDoors(timeElapsed); // Update Run and Motor sounds - foreach (var Car in Cars) + foreach (var car in Cars) { - Car.Run.Update(TimeElapsed); - Car.Sounds.Motor?.Update(TimeElapsed); + car.Run.Update(timeElapsed); + car.Sounds.Motor?.Update(timeElapsed); } // infrequent updates - InternalTimerTimeElapsed += TimeElapsed; + InternalTimerTimeElapsed += timeElapsed; if (InternalTimerTimeElapsed > 10.0) { InternalTimerTimeElapsed -= 10.0; @@ -162,7 +162,7 @@ public override void Jump(int stationIndex, int trackIndex) { Dispose(); State = TrainState.Pending; - TrainManagerBase.currentHost.ProcessJump(this, stationIndex, 0); + TrainManagerBase.CurrentHost.ProcessJump(this, stationIndex, 0); } } } diff --git a/source/TrainManager/Train/BrakeSystem.cs b/source/TrainManager/Train/BrakeSystem.cs index b4b30bdec..d203a1215 100644 --- a/source/TrainManager/Train/BrakeSystem.cs +++ b/source/TrainManager/Train/BrakeSystem.cs @@ -7,31 +7,31 @@ namespace TrainManager.Trains public partial class TrainBase { /// Updates the brake system for the entire train - /// The frame time elapsed - /// An array containing the deceleration figures generated by the brake system of each car in the train - /// An array containing the deceleration figures generated by the motor of each car in the train (If it is a motor car) - public void UpdateBrakeSystem(double TimeElapsed, out double[] DecelerationDueToBrake, out double[] DecelerationDueToMotor) + /// The frame time elapsed + /// An array containing the deceleration figures generated by the brake system of each car in the train + /// An array containing the deceleration figures generated by the motor of each car in the train (If it is a motor car) + public void UpdateBrakeSystem(double timeElapsed, out double[] decelerationDueToBrake, out double[] decelerationDueToMotor) { // individual brake systems - DecelerationDueToBrake = new double[Cars.Length]; - DecelerationDueToMotor = new double[Cars.Length]; + decelerationDueToBrake = new double[Cars.Length]; + decelerationDueToMotor = new double[Cars.Length]; for (int i = 0; i < Cars.Length; i++) { - UpdateBrakeSystem(i, TimeElapsed, out DecelerationDueToBrake[i], out DecelerationDueToMotor[i]); + UpdateBrakeSystem(i, timeElapsed, out decelerationDueToBrake[i], out decelerationDueToMotor[i]); } if (Specs.AveragesPressureDistribution) { // brake pipe pressure distribution dummy (just averages) - double TotalPressure = 0.0; + double totalPressure = 0.0; for (int i = 0; i < Cars.Length; i++) { if (i > 0) { if (Cars[i - 1].Derailed | Cars[i].Derailed) { - Cars[i].CarBrake.brakePipe.CurrentPressure -= Cars[i].CarBrake.brakePipe.LeakRate * TimeElapsed; - if (Cars[i].CarBrake.brakePipe.CurrentPressure < 0.0) Cars[i].CarBrake.brakePipe.CurrentPressure = 0.0; + Cars[i].CarBrake.BrakePipe.CurrentPressure -= Cars[i].CarBrake.BrakePipe.LeakRate * timeElapsed; + if (Cars[i].CarBrake.BrakePipe.CurrentPressure < 0.0) Cars[i].CarBrake.BrakePipe.CurrentPressure = 0.0; } } @@ -39,18 +39,18 @@ public void UpdateBrakeSystem(double TimeElapsed, out double[] DecelerationDueTo { if (Cars[i].Derailed | Cars[i + 1].Derailed) { - Cars[i].CarBrake.brakePipe.CurrentPressure -= Cars[i].CarBrake.brakePipe.LeakRate * TimeElapsed; - if (Cars[i].CarBrake.brakePipe.CurrentPressure < 0.0) Cars[i].CarBrake.brakePipe.CurrentPressure = 0.0; + Cars[i].CarBrake.BrakePipe.CurrentPressure -= Cars[i].CarBrake.BrakePipe.LeakRate * timeElapsed; + if (Cars[i].CarBrake.BrakePipe.CurrentPressure < 0.0) Cars[i].CarBrake.BrakePipe.CurrentPressure = 0.0; } } - TotalPressure += Cars[i].CarBrake.brakePipe.CurrentPressure; + totalPressure += Cars[i].CarBrake.BrakePipe.CurrentPressure; } - double averagePressure = TotalPressure / Cars.Length; + double averagePressure = totalPressure / Cars.Length; for (int i = 0; i < Cars.Length; i++) { - Cars[i].CarBrake.brakePipe.CurrentPressure = averagePressure; + Cars[i].CarBrake.BrakePipe.CurrentPressure = averagePressure; } } else @@ -69,31 +69,31 @@ public void UpdateBrakeSystem(double TimeElapsed, out double[] DecelerationDueTo int lastMainBrake = 0; for (int i = 0; i < Cars.Length; i++) { - Cars[i].CarBrake.brakePipe.CurrentPressure -= Cars[i].CarBrake.brakePipe.LeakRate * TimeElapsed; - if (Cars[i].CarBrake.brakePipe.CurrentPressure < 0.0) Cars[i].CarBrake.brakePipe.CurrentPressure = 0.0; - if (Cars[i].CarBrake.brakeType == BrakeType.Main) + Cars[i].CarBrake.BrakePipe.CurrentPressure -= Cars[i].CarBrake.BrakePipe.LeakRate * timeElapsed; + if (Cars[i].CarBrake.BrakePipe.CurrentPressure < 0.0) Cars[i].CarBrake.BrakePipe.CurrentPressure = 0.0; + if (Cars[i].CarBrake.BrakeType == BrakeType.Main) { // If at the end of the train or a compressor we don't need to flow into it - bool nextCarIsMainBrake = i == Cars.Length - 1 || Cars[i + 1].CarBrake.brakeType == BrakeType.Main; + bool nextCarIsMainBrake = i == Cars.Length - 1 || Cars[i + 1].CarBrake.BrakeType == BrakeType.Main; if (i > 0) { // Back flow for (int j = i; j > lastMainBrake; j--) { - double pressureChange = Math.Min(Cars[j].CarBrake.brakePipe.NormalPressure - Cars[j].CarBrake.brakePipe.CurrentPressure, Cars[j].CarBrake.brakePipe.ChargeRate / 2) * TimeElapsed; - double pressureDiff = Math.Min(pressureChange, Cars[j].CarBrake.brakePipe.CurrentPressure) * TimeElapsed; - Cars[i].CarBrake.brakePipe.CurrentPressure -= pressureDiff; - Cars[j].CarBrake.brakePipe.CurrentPressure += pressureDiff; + double pressureChange = Math.Min(Cars[j].CarBrake.BrakePipe.NormalPressure - Cars[j].CarBrake.BrakePipe.CurrentPressure, Cars[j].CarBrake.BrakePipe.ChargeRate / 2) * timeElapsed; + double pressureDiff = Math.Min(pressureChange, Cars[j].CarBrake.BrakePipe.CurrentPressure) * timeElapsed; + Cars[i].CarBrake.BrakePipe.CurrentPressure -= pressureDiff; + Cars[j].CarBrake.BrakePipe.CurrentPressure += pressureDiff; } } // Forwards flow for (int j = i; j < Cars.Length; j++) { - double pressureChange = Math.Min(Cars[j].CarBrake.brakePipe.NormalPressure - Cars[j].CarBrake.brakePipe.CurrentPressure, Cars[j].CarBrake.brakePipe.ChargeRate / 2) * TimeElapsed; - double pressureDiff = Math.Min(pressureChange, Cars[j].CarBrake.brakePipe.CurrentPressure) * TimeElapsed; - Cars[i].CarBrake.brakePipe.CurrentPressure -= pressureDiff; - Cars[j].CarBrake.brakePipe.CurrentPressure += pressureDiff; + double pressureChange = Math.Min(Cars[j].CarBrake.BrakePipe.NormalPressure - Cars[j].CarBrake.BrakePipe.CurrentPressure, Cars[j].CarBrake.BrakePipe.ChargeRate / 2) * timeElapsed; + double pressureDiff = Math.Min(pressureChange, Cars[j].CarBrake.BrakePipe.CurrentPressure) * timeElapsed; + Cars[i].CarBrake.BrakePipe.CurrentPressure -= pressureDiff; + Cars[j].CarBrake.BrakePipe.CurrentPressure += pressureDiff; if (nextCarIsMainBrake) { break; @@ -107,27 +107,27 @@ public void UpdateBrakeSystem(double TimeElapsed, out double[] DecelerationDueTo /// Updates the brake system for a car within this train /// This must remain a property of the train, for easy access to various base properties - /// The individual car - /// The frame time elapsed - /// The total brake deceleration this car provides - /// The total motor deceleration this car provides - public void UpdateBrakeSystem(int CarIndex, double TimeElapsed, out double DecelerationDueToBrake, out double DecelerationDueToMotor) + /// The individual car + /// The frame time elapsed + /// The total brake deceleration this car provides + /// The total motor deceleration this car provides + public void UpdateBrakeSystem(int carIndex, double timeElapsed, out double decelerationDueToBrake, out double decelerationDueToMotor) { - DecelerationDueToBrake = 0.0; - DecelerationDueToMotor = 0.0; + decelerationDueToBrake = 0.0; + decelerationDueToMotor = 0.0; // air compressor - if (Cars[CarIndex].CarBrake.brakeType == BrakeType.Main) + if (Cars[carIndex].CarBrake.BrakeType == BrakeType.Main) { - Cars[CarIndex].CarBrake.airCompressor.Update(TimeElapsed); + Cars[carIndex].CarBrake.AirCompressor.Update(timeElapsed); } - if (CarIndex == DriverCar && Handles.HasLocoBrake) + if (carIndex == DriverCar && Handles.HasLocoBrake) { switch (Handles.LocoBrakeType) { case LocoBrakeType.Independant: //With an independant Loco brake, we always want to use this handle - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out decelerationDueToBrake); break; case LocoBrakeType.Combined: if (Handles.LocoBrake is LocoBrakeHandle && Handles.Brake is NotchedHandle) @@ -138,11 +138,11 @@ public void UpdateBrakeSystem(int CarIndex, double TimeElapsed, out double Decel //Identical number of notches, so return the handle with the higher setting if (Handles.LocoBrake.Actual >= Handles.Brake.Actual) { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out decelerationDueToBrake); } else { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out decelerationDueToBrake); } } else if (Handles.Brake.MaximumNotch > Handles.LocoBrake.MaximumNotch) @@ -150,11 +150,11 @@ public void UpdateBrakeSystem(int CarIndex, double TimeElapsed, out double Decel double nc = ((double) Handles.LocoBrake.Actual / Handles.LocoBrake.MaximumNotch) * Handles.Brake.MaximumNotch; if (nc > Handles.Brake.Actual) { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out decelerationDueToBrake); } else { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out decelerationDueToBrake); } } else @@ -162,11 +162,11 @@ public void UpdateBrakeSystem(int CarIndex, double TimeElapsed, out double Decel double nc = ((double) Handles.Brake.Actual / Handles.Brake.MaximumNotch) * Handles.LocoBrake.MaximumNotch; if (nc > Handles.LocoBrake.Actual) { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out decelerationDueToBrake); } else { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out decelerationDueToBrake); } } } @@ -174,11 +174,11 @@ public void UpdateBrakeSystem(int CarIndex, double TimeElapsed, out double Decel { if (Handles.LocoBrake.Actual < Handles.Brake.Actual) { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out decelerationDueToBrake); } else { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out decelerationDueToBrake); } } else @@ -188,23 +188,23 @@ public void UpdateBrakeSystem(int CarIndex, double TimeElapsed, out double Decel if (Handles.LocoBrake is LocoAirBrakeHandle) { //Air brake handle - p = Cars[CarIndex].CarBrake.brakeCylinder.CurrentPressure / Cars[CarIndex].CarBrake.brakeCylinder.ServiceMaximumPressure; - tp = (Cars[CarIndex].CarBrake.brakeCylinder.ServiceMaximumPressure / Handles.Brake.MaximumNotch) * Handles.Brake.Actual; + p = Cars[carIndex].CarBrake.BrakeCylinder.CurrentPressure / Cars[carIndex].CarBrake.BrakeCylinder.ServiceMaximumPressure; + tp = (Cars[carIndex].CarBrake.BrakeCylinder.ServiceMaximumPressure / Handles.Brake.MaximumNotch) * Handles.Brake.Actual; } else { //Notched handle - p = Cars[CarIndex].CarBrake.brakeCylinder.CurrentPressure / Cars[CarIndex].CarBrake.brakeCylinder.ServiceMaximumPressure; - tp = (Cars[CarIndex].CarBrake.brakeCylinder.ServiceMaximumPressure / Handles.LocoBrake.MaximumNotch) * Handles.LocoBrake.Actual; + p = Cars[carIndex].CarBrake.BrakeCylinder.CurrentPressure / Cars[carIndex].CarBrake.BrakeCylinder.ServiceMaximumPressure; + tp = (Cars[carIndex].CarBrake.BrakeCylinder.ServiceMaximumPressure / Handles.LocoBrake.MaximumNotch) * Handles.LocoBrake.Actual; } if (p < tp) { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out decelerationDueToBrake); } else { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out decelerationDueToBrake); } } @@ -212,11 +212,11 @@ public void UpdateBrakeSystem(int CarIndex, double TimeElapsed, out double Decel case LocoBrakeType.Blocking: if (Handles.LocoBrake.Actual != 0) { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.LocoBrake, out decelerationDueToBrake); } else { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out decelerationDueToBrake); } break; @@ -225,36 +225,36 @@ public void UpdateBrakeSystem(int CarIndex, double TimeElapsed, out double Decel } else { - Cars[CarIndex].CarBrake.Update(TimeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out DecelerationDueToBrake); + Cars[carIndex].CarBrake.Update(timeElapsed, Cars[DriverCar].CurrentSpeed, Handles.Brake, out decelerationDueToBrake); } - if (Cars[CarIndex].CarBrake.airSound != null) + if (Cars[carIndex].CarBrake.AirSound != null) { - Cars[CarIndex].CarBrake.airSound.Play(Cars[CarIndex], false); + Cars[carIndex].CarBrake.AirSound.Play(Cars[carIndex], false); } // deceleration provided by motor - if (!(Cars[CarIndex].CarBrake is AutomaticAirBrake) && Math.Abs(Cars[CarIndex].CurrentSpeed) >= Cars[CarIndex].CarBrake.brakeControlSpeed & Handles.Reverser.Actual != 0 & !Handles.EmergencyBrake.Actual) + if (!(Cars[carIndex].CarBrake is AutomaticAirBrake) && Math.Abs(Cars[carIndex].CurrentSpeed) >= Cars[carIndex].CarBrake.BrakeControlSpeed & Handles.Reverser.Actual != 0 & !Handles.EmergencyBrake.Actual) { - if (Handles.LocoBrake.Actual != 0 && CarIndex == DriverCar) + if (Handles.LocoBrake.Actual != 0 && carIndex == DriverCar) { - DecelerationDueToMotor = Cars[CarIndex].CarBrake.CurrentMotorDeceleration(TimeElapsed, Handles.LocoBrake); + decelerationDueToMotor = Cars[carIndex].CarBrake.CurrentMotorDeceleration(timeElapsed, Handles.LocoBrake); } else { - DecelerationDueToMotor = Cars[CarIndex].CarBrake.CurrentMotorDeceleration(TimeElapsed, Handles.Brake); + decelerationDueToMotor = Cars[carIndex].CarBrake.CurrentMotorDeceleration(timeElapsed, Handles.Brake); } } // hold brake - Cars[CarIndex].HoldBrake.Update(ref DecelerationDueToMotor, Handles.HoldBrake.Actual); - if(Cars[CarIndex].CarBrake.brakeType != BrakeType.None) + Cars[carIndex].HoldBrake.Update(ref decelerationDueToMotor, Handles.HoldBrake.Actual); + if(Cars[carIndex].CarBrake.BrakeType != BrakeType.None) { // brake shoe rub sound - double spd = Math.Abs(Cars[CarIndex].CurrentSpeed); + double spd = Math.Abs(Cars[carIndex].CurrentSpeed); double pitch = 1.0 / (spd + 1.0) + 1.0; - double gain = Cars[CarIndex].Derailed ? 0.0 : Cars[CarIndex].CarBrake.brakeCylinder.CurrentPressure / Cars[CarIndex].CarBrake.brakeCylinder.ServiceMaximumPressure; + double gain = Cars[carIndex].Derailed ? 0.0 : Cars[carIndex].CarBrake.BrakeCylinder.CurrentPressure / Cars[carIndex].CarBrake.BrakeCylinder.ServiceMaximumPressure; if (spd < 1.38888888888889) { double t = spd * spd; @@ -267,21 +267,21 @@ public void UpdateBrakeSystem(int CarIndex, double TimeElapsed, out double Decel gain *= 1.0 / (fadefactor * t * t + 1.0); } - if (Cars[CarIndex].CarBrake.Rub.IsPlaying) + if (Cars[carIndex].CarBrake.Rub.IsPlaying) { if (pitch > 0.01 & gain > 0.001) { - Cars[CarIndex].CarBrake.Rub.Source.Pitch = pitch; - Cars[CarIndex].CarBrake.Rub.Source.Volume = gain; + Cars[carIndex].CarBrake.Rub.Source.Pitch = pitch; + Cars[carIndex].CarBrake.Rub.Source.Volume = gain; } else { - Cars[CarIndex].CarBrake.Rub.Stop(); + Cars[carIndex].CarBrake.Rub.Stop(); } } else if (pitch > 0.02 & gain > 0.01) { - Cars[CarIndex].CarBrake.Rub.Play(pitch, gain, Cars[CarIndex], true); + Cars[carIndex].CarBrake.Rub.Play(pitch, gain, Cars[carIndex], true); } } } diff --git a/source/TrainManager/Train/Doors.cs b/source/TrainManager/Train/Doors.cs index d7803961e..e349a26cb 100644 --- a/source/TrainManager/Train/Doors.cs +++ b/source/TrainManager/Train/Doors.cs @@ -7,18 +7,18 @@ namespace TrainManager.Trains public partial class TrainBase { /// - public override void OpenDoors(bool Left, bool Right) + public override void OpenDoors(bool left, bool right) { bool sl = false, sr = false; for (int i = 0; i < Cars.Length; i++) { - if (Left & !Cars[i].Doors[0].AnticipatedOpen & (SafetySystems.DoorInterlockState == DoorInterlockStates.Left | SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) + if (left & !Cars[i].Doors[0].AnticipatedOpen & (SafetySystems.DoorInterlockState == DoorInterlockStates.Left | SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) { Cars[i].Doors[0].AnticipatedOpen = true; sl = true; } - if (Right & !Cars[i].Doors[1].AnticipatedOpen & (SafetySystems.DoorInterlockState == DoorInterlockStates.Right | SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) + if (right & !Cars[i].Doors[1].AnticipatedOpen & (SafetySystems.DoorInterlockState == DoorInterlockStates.Right | SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) { Cars[i].Doors[1].AnticipatedOpen = true; sr = true; @@ -57,18 +57,18 @@ public override void OpenDoors(bool Left, bool Right) } /// - public override void CloseDoors(bool Left, bool Right) + public override void CloseDoors(bool left, bool right) { bool sl = false, sr = false; for (int i = 0; i < Cars.Length; i++) { - if (Left & Cars[i].Doors[0].AnticipatedOpen & (SafetySystems.DoorInterlockState == DoorInterlockStates.Left | SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) + if (left & Cars[i].Doors[0].AnticipatedOpen & (SafetySystems.DoorInterlockState == DoorInterlockStates.Left | SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) { Cars[i].Doors[0].AnticipatedOpen = false; sl = true; } - if (Right & Cars[i].Doors[1].AnticipatedOpen & (SafetySystems.DoorInterlockState == DoorInterlockStates.Right | SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) + if (right & Cars[i].Doors[1].AnticipatedOpen & (SafetySystems.DoorInterlockState == DoorInterlockStates.Right | SafetySystems.DoorInterlockState == DoorInterlockStates.Unlocked)) { Cars[i].Doors[1].AnticipatedOpen = false; sr = true; @@ -93,17 +93,17 @@ public override void CloseDoors(bool Left, bool Right) } /// Returns the combination of door states encountered in a - /// Whether to include left doors. - /// Whether to include right doors. + /// Whether to include left doors. + /// Whether to include right doors. /// A bit mask combining encountered door states. - public TrainDoorState GetDoorsState(bool Left, bool Right) + public TrainDoorState GetDoorsState(bool left, bool right) { bool opened = false, closed = false, mixed = false; for (int i = 0; i < Cars.Length; i++) { for (int j = 0; j < Cars[i].Doors.Length; j++) { - if (Left & Cars[i].Doors[j].Direction == -1 | Right & Cars[i].Doors[j].Direction == 1) + if (left & Cars[i].Doors[j].Direction == -1 | right & Cars[i].Doors[j].Direction == 1) { if (Cars[i].Doors[j].State == 0.0) { @@ -121,27 +121,27 @@ public TrainDoorState GetDoorsState(bool Left, bool Right) } } - TrainDoorState Result = TrainDoorState.None; - if (opened) Result |= TrainDoorState.Opened; - if (closed) Result |= TrainDoorState.Closed; - if (mixed) Result |= TrainDoorState.Mixed; - if (opened & !closed & !mixed) Result |= TrainDoorState.AllOpened; - if (!opened & closed & !mixed) Result |= TrainDoorState.AllClosed; - if (!opened & !closed & mixed) Result |= TrainDoorState.AllMixed; - return Result; + TrainDoorState result = TrainDoorState.None; + if (opened) result |= TrainDoorState.Opened; + if (closed) result |= TrainDoorState.Closed; + if (mixed) result |= TrainDoorState.Mixed; + if (opened & !closed & !mixed) result |= TrainDoorState.AllOpened; + if (!opened & closed & !mixed) result |= TrainDoorState.AllClosed; + if (!opened & !closed & mixed) result |= TrainDoorState.AllMixed; + return result; } /// Called once a frame for each train when arriving at a station, in order to update the automatic doors - /// The train's next station - /// The backwards tolerance for this stop point - /// The forwards tolerance for this stop point - public void AttemptToOpenDoors(Station NextStation, double BackwardsTolerance, double ForwardsTolerance) + /// The train's next station + /// The backwards tolerance for this stop point + /// The forwards tolerance for this stop point + public void AttemptToOpenDoors(Station nextStation, double backwardsTolerance, double forwardsTolerance) { - if ((GetDoorsState(NextStation.OpenLeftDoors, NextStation.OpenRightDoors) & TrainDoorState.AllOpened) == 0) + if ((GetDoorsState(nextStation.OpenLeftDoors, nextStation.OpenRightDoors) & TrainDoorState.AllOpened) == 0) { - if (StationDistanceToStopPoint < BackwardsTolerance & -StationDistanceToStopPoint < ForwardsTolerance) + if (StationDistanceToStopPoint < backwardsTolerance & -StationDistanceToStopPoint < forwardsTolerance) { - OpenDoors(NextStation.OpenLeftDoors, NextStation.OpenRightDoors); + OpenDoors(nextStation.OpenLeftDoors, nextStation.OpenRightDoors); } } @@ -150,7 +150,7 @@ public void AttemptToOpenDoors(Station NextStation, double BackwardsTolerance, d /// Called once a frame for each train whilst stopped at a station with the doors open, in order to update the automatic doors public void AttemptToCloseDoors() { - if (TrainManagerBase.currentHost.InGameTime >= StationDepartureTime - 1.0 / Cars[DriverCar].Specs.DoorCloseFrequency) + if (TrainManagerBase.CurrentHost.InGameTime >= StationDepartureTime - 1.0 / Cars[DriverCar].Specs.DoorCloseFrequency) { if ((GetDoorsState(true, true) & TrainDoorState.AllClosed) == 0) { @@ -161,8 +161,8 @@ public void AttemptToCloseDoors() } /// Is called once a frame, to update the door states of the train - /// The frame time elapsed - public void UpdateDoors(double TimeElapsed) + /// The frame time elapsed + public void UpdateDoors(double timeElapsed) { DoorStates oldState = DoorStates.None; DoorStates newState = DoorStates.None; @@ -193,7 +193,7 @@ public void UpdateDoors(double TimeElapsed) if (shouldBeOpen) { // open - Cars[i].Doors[j].State += os * TimeElapsed; + Cars[i].Doors[j].State += os * timeElapsed; if (Cars[i].Doors[j].State > 1.0) { Cars[i].Doors[j].State = 1.0; @@ -206,7 +206,7 @@ public void UpdateDoors(double TimeElapsed) { if (Cars[i].Doors[j].State > Cars[i].Doors[j].DoorLockState) { - Cars[i].Doors[j].State -= cs * TimeElapsed; + Cars[i].Doors[j].State -= cs * timeElapsed; } if (Cars[i].Doors[j].State < Cars[i].Doors[j].DoorLockState) @@ -214,7 +214,7 @@ public void UpdateDoors(double TimeElapsed) Cars[i].Doors[j].State = Cars[i].Doors[j].DoorLockState; } - Cars[i].Doors[j].DoorLockDuration -= TimeElapsed; + Cars[i].Doors[j].DoorLockDuration -= timeElapsed; if (Cars[i].Doors[j].DoorLockDuration < 0.0) { Cars[i].Doors[j].DoorLockDuration = 0.0; @@ -222,7 +222,7 @@ public void UpdateDoors(double TimeElapsed) } else { - Cars[i].Doors[j].State -= cs * TimeElapsed; + Cars[i].Doors[j].State -= cs * timeElapsed; } if (Cars[i].Doors[j].AnticipatedReopen && Cars[i].Doors[j].State < Cars[i].Doors[j].InterferingObjectRate) diff --git a/source/TrainManager/Train/DriverBody.cs b/source/TrainManager/Train/DriverBody.cs index af99a692e..a303ec78f 100644 --- a/source/TrainManager/Train/DriverBody.cs +++ b/source/TrainManager/Train/DriverBody.cs @@ -30,7 +30,7 @@ public DriverBody(TrainBase train) RollDamping = new Damping(6.0, 0.3); } - public void Update(double TimeElapsed) + public void Update(double timeElapsed) { if (TrainManagerBase.Renderer.Camera.CurrentRestriction == CameraRestrictionMode.NotAvailable) { @@ -41,7 +41,7 @@ public void Update(double TimeElapsed) const double accelerationFast = 2.0; if (Slow.Y < targetY) { - Slow.Y += accelerationSlow * TimeElapsed; + Slow.Y += accelerationSlow * timeElapsed; if (Slow.Y > targetY) { Slow.Y = targetY; @@ -49,7 +49,7 @@ public void Update(double TimeElapsed) } else if (Slow.Y > targetY) { - Slow.Y -= accelerationSlow * TimeElapsed; + Slow.Y -= accelerationSlow * timeElapsed; if (Slow.Y < targetY) { Slow.Y = targetY; @@ -58,7 +58,7 @@ public void Update(double TimeElapsed) if (Fast.Y < targetY) { - Fast.Y += accelerationFast * TimeElapsed; + Fast.Y += accelerationFast * timeElapsed; if (Fast.Y > targetY) { Fast.Y = targetY; @@ -66,7 +66,7 @@ public void Update(double TimeElapsed) } else if (Fast.Y > targetY) { - Fast.Y -= accelerationFast * TimeElapsed; + Fast.Y -= accelerationFast * timeElapsed; if (Fast.Y < targetY) { Fast.Y = targetY; @@ -80,7 +80,7 @@ public void Update(double TimeElapsed) { Pitch = 0.1; } - PitchDamping.Update(TimeElapsed, ref Pitch, true); + PitchDamping.Update(timeElapsed, ref Pitch, true); } { // roll @@ -127,7 +127,7 @@ public void Update(double TimeElapsed) const double accelerationFast = 10.0; if (Slow.X < targetX) { - Slow.X += accelerationSlow * TimeElapsed; + Slow.X += accelerationSlow * timeElapsed; if (Slow.X > targetX) { Slow.X = targetX; @@ -135,7 +135,7 @@ public void Update(double TimeElapsed) } else if (Slow.X > targetX) { - Slow.X -= accelerationSlow * TimeElapsed; + Slow.X -= accelerationSlow * timeElapsed; if (Slow.X < targetX) { Slow.X = targetX; @@ -144,7 +144,7 @@ public void Update(double TimeElapsed) if (Fast.X < targetX) { - Fast.X += accelerationFast * TimeElapsed; + Fast.X += accelerationFast * timeElapsed; if (Fast.X > targetX) { Fast.X = targetX; @@ -152,7 +152,7 @@ public void Update(double TimeElapsed) } else if (Fast.X > targetX) { - Fast.X -= accelerationFast * TimeElapsed; + Fast.X -= accelerationFast * timeElapsed; if (Fast.X < targetX) { Fast.X = targetX; @@ -162,7 +162,7 @@ public void Update(double TimeElapsed) double diffX = Slow.X - Fast.X; diffX = Math.Sign(diffX) * diffX * diffX; Roll = 0.5 * Math.Atan(0.3 * diffX); - RollDamping.Update(TimeElapsed, ref Roll, true); + RollDamping.Update(timeElapsed, ref Roll, true); } } } diff --git a/source/TrainManager/Train/Horn.cs b/source/TrainManager/Train/Horn.cs index da3864c94..b67376af8 100644 --- a/source/TrainManager/Train/Horn.cs +++ b/source/TrainManager/Train/Horn.cs @@ -25,7 +25,7 @@ public class Horn /// Stores the loop state private bool LoopStarted; /// Holds a reference to the base car - public readonly CarBase baseCar; + public readonly CarBase BaseCar; /// The default constructor public Horn(CarBase car) @@ -34,7 +34,7 @@ public Horn(CarBase car) this.LoopSound = null; this.EndSound = null; this.Loop = false; - this.baseCar = car; + this.BaseCar = car; } public Horn(SoundBuffer startSound, SoundBuffer loopSound, SoundBuffer endSound, bool loop, CarBase car) @@ -47,13 +47,13 @@ public Horn(SoundBuffer startSound, SoundBuffer loopSound, SoundBuffer endSound, this.StartEndSounds = false; this.LoopStarted = false; this.SoundPosition = new Vector3(); - this.baseCar = car; + this.BaseCar = car; } /// Called by the controls loop to start playback of this horn public void Play() { - if (TrainManagerBase.currentHost.SimulationState == SimulationState.MinimalisticSimulation) + if (TrainManagerBase.CurrentHost.SimulationState == SimulationState.MinimalisticSimulation) { return; } @@ -63,12 +63,12 @@ public void Play() //New style three-part sounds if (LoopStarted == false) { - if (!TrainManagerBase.currentHost.SoundIsPlaying(Source)) + if (!TrainManagerBase.CurrentHost.SoundIsPlaying(Source)) { if (StartSound != null) { //The start sound is not currently playing, so start it - Source = (SoundSource)TrainManagerBase.currentHost.PlaySound(StartSound, 1.0, 1.0, SoundPosition, baseCar, false); + Source = (SoundSource)TrainManagerBase.CurrentHost.PlaySound(StartSound, 1.0, 1.0, SoundPosition, BaseCar, false); //Set the loop control variable to started LoopStarted = true; @@ -77,17 +77,17 @@ public void Play() { if (LoopSound != null) { - Source = (SoundSource)TrainManagerBase.currentHost.PlaySound(LoopSound, 1.0, 1.0, SoundPosition, baseCar, true); + Source = (SoundSource)TrainManagerBase.CurrentHost.PlaySound(LoopSound, 1.0, 1.0, SoundPosition, BaseCar, true); } } } } else { - if (!TrainManagerBase.currentHost.SoundIsPlaying(Source) && LoopSound != null) + if (!TrainManagerBase.CurrentHost.SoundIsPlaying(Source) && LoopSound != null) { //Start our loop sound playing if the start sound is finished - Source = (SoundSource)TrainManagerBase.currentHost.PlaySound(LoopSound, 1.0, 1.0, SoundPosition, baseCar, true); + Source = (SoundSource)TrainManagerBase.CurrentHost.PlaySound(LoopSound, 1.0, 1.0, SoundPosition, BaseCar, true); } } } @@ -99,11 +99,11 @@ public void Play() //Loop is ONLY true if this is a Music Horn if (Loop) { - if (!TrainManagerBase.currentHost.SoundIsPlaying(Source) && !LoopStarted) + if (!TrainManagerBase.CurrentHost.SoundIsPlaying(Source) && !LoopStarted) { //On the first keydown event, start the sound source playing and trigger the loop control variable - Source = (SoundSource)TrainManagerBase.currentHost.PlaySound(LoopSound, 1.0, 1.0, SoundPosition, - baseCar, true); + Source = (SoundSource)TrainManagerBase.CurrentHost.PlaySound(LoopSound, 1.0, 1.0, SoundPosition, + BaseCar, true); LoopStarted = true; } else @@ -112,7 +112,7 @@ public void Play() { //Our loop control variable is reset by the keyup event so this code will only trigger on the //second keydown meaning our horn toggles - TrainManagerBase.currentHost.StopSound(Source); + TrainManagerBase.CurrentHost.StopSound(Source); LoopStarted = true; } } @@ -121,7 +121,7 @@ public void Play() { if (!LoopStarted) { - Source = (SoundSource)TrainManagerBase.currentHost.PlaySound(LoopSound, 1.0, 1.0, SoundPosition, baseCar, false); + Source = (SoundSource)TrainManagerBase.CurrentHost.PlaySound(LoopSound, 1.0, 1.0, SoundPosition, BaseCar, false); } LoopStarted = true; @@ -148,16 +148,16 @@ public void Stop() return; } - if (TrainManagerBase.currentHost.SoundIsPlaying(Source)) + if (TrainManagerBase.CurrentHost.SoundIsPlaying(Source)) { //Stop the loop sound playing - TrainManagerBase.currentHost.StopSound(Source); + TrainManagerBase.CurrentHost.StopSound(Source); } - if (StartEndSounds && !TrainManagerBase.currentHost.SoundIsPlaying(Source) && EndSound != null) + if (StartEndSounds && !TrainManagerBase.CurrentHost.SoundIsPlaying(Source) && EndSound != null) { //If our end sound is defined and in use, play once - Source =(SoundSource)TrainManagerBase.currentHost.PlaySound(EndSound, 1.0, 1.0, SoundPosition, baseCar, false); + Source =(SoundSource)TrainManagerBase.CurrentHost.PlaySound(EndSound, 1.0, 1.0, SoundPosition, BaseCar, false); } } } diff --git a/source/TrainManager/Train/RequestStop.cs b/source/TrainManager/Train/RequestStop.cs index b382fd8c5..9dbe3797f 100644 --- a/source/TrainManager/Train/RequestStop.cs +++ b/source/TrainManager/Train/RequestStop.cs @@ -41,7 +41,7 @@ public override void RequestStop(RequestStop stopRequest) //If message is not empty, add it if (!string.IsNullOrEmpty(stopRequest.PassMessage) && IsPlayerTrain) { - TrainManagerBase.currentHost.AddMessage(stopRequest.PassMessage, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(stopRequest.PassMessage, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null); } return; @@ -52,7 +52,7 @@ public override void RequestStop(RequestStop stopRequest) //If message is not empty, add it if (!string.IsNullOrEmpty(stopRequest.StopMessage) && IsPlayerTrain) { - TrainManagerBase.currentHost.AddMessage(stopRequest.StopMessage, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(stopRequest.StopMessage, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null); } } else @@ -66,7 +66,7 @@ public override void RequestStop(RequestStop stopRequest) //If message is not empty, add it if (!string.IsNullOrEmpty(stopRequest.PassMessage) && IsPlayerTrain) { - TrainManagerBase.currentHost.AddMessage(stopRequest.PassMessage, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(stopRequest.PassMessage, MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null); } } } diff --git a/source/TrainManager/Train/Station.cs b/source/TrainManager/Train/Station.cs index a32e08df1..d5331aef4 100644 --- a/source/TrainManager/Train/Station.cs +++ b/source/TrainManager/Train/Station.cs @@ -20,7 +20,7 @@ public override void EnterStation(int stationIndex, int direction) { if (direction < 0) { - if (Handles.Reverser.Actual == ReverserPosition.Forwards && Handles.Power.Driver != 0 && TrainManagerBase.currentHost.SimulationState != SimulationState.MinimalisticSimulation && stationIndex == Station) + if (Handles.Reverser.Actual == ReverserPosition.Forwards && Handles.Power.Driver != 0 && TrainManagerBase.CurrentHost.SimulationState != SimulationState.MinimalisticSimulation && stationIndex == Station) { //Our reverser and power are in F, but we are rolling backwards //Leave the station index alone, and we won't trigger again when we actually move forwards @@ -69,13 +69,13 @@ public override void LeaveStation(int stationIndex, int direction) { string s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_passed"}); s = s.Replace("[name]", TrainManagerBase.CurrentRoute.Stations[stationIndex].Name); - TrainManagerBase.currentHost.AddMessage(s, MessageDependency.None, GameMode.Normal, MessageColor.Orange, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(s, MessageDependency.None, GameMode.Normal, MessageColor.Orange, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); } else if (TrainManagerBase.CurrentRoute.Stations[stationIndex].PlayerStops() & StationState == TrainStopState.Boarding) { string s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message","station_passed_boarding"}); s = s.Replace("[name]", TrainManagerBase.CurrentRoute.Stations[stationIndex].Name); - TrainManagerBase.currentHost.AddMessage(s, MessageDependency.None, GameMode.Normal, MessageColor.Red, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(s, MessageDependency.None, GameMode.Normal, MessageColor.Red, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); } } @@ -91,8 +91,8 @@ public override void LeaveStation(int stationIndex, int direction) } /// Is called once a frame to update the station state for the train - /// The frame time elapsed - private void UpdateStation(double TimeElapsed) + /// The frame time elapsed + private void UpdateStation(double timeElapsed) { if (Station >= 0) { @@ -182,7 +182,7 @@ private void UpdateStation(double TimeElapsed) if (buffer != null) { OpenBveApi.Math.Vector3 pos = TrainManagerBase.CurrentRoute.Stations[i].SoundOrigin; - TrainManagerBase.currentHost.PlaySound(buffer, 1.0, 1.0, pos, null, false); + TrainManagerBase.CurrentHost.PlaySound(buffer, 1.0, 1.0, pos, null, false); } StationArrivalTime = TrainManagerBase.CurrentRoute.SecondsSinceMidnight; @@ -218,9 +218,9 @@ private void UpdateStation(double TimeElapsed) s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_arrival"}); } - System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; + System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.InvariantCulture; TimeSpan a = TimeSpan.FromSeconds(Math.Abs(early)); - string b = a.Hours.ToString("00", Culture) + ":" + a.Minutes.ToString("00", Culture) + ":" + a.Seconds.ToString("00", Culture); + string b = a.Hours.ToString("00", culture) + ":" + a.Minutes.ToString("00", culture) + ":" + a.Seconds.ToString("00", culture); if (StationDistanceToStopPoint < -0.1) { s += Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","delimiter"}) + Translations.GetInterfaceString(HostApplication.OpenBve, CurrentDirection == TrackDirection.Forwards ? new[] {"message","station_overrun"} : new[] {"message","station_underrun"}); @@ -231,7 +231,7 @@ private void UpdateStation(double TimeElapsed) } double d = Math.Abs(StationDistanceToStopPoint); - string c = d.ToString("0.0", Culture); + string c = d.ToString("0.0", culture); if (TrainManagerBase.CurrentRoute.Stations[i].Type == StationType.Terminal) { s += Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","delimiter"}) + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_terminal"}); @@ -240,14 +240,14 @@ private void UpdateStation(double TimeElapsed) s = s.Replace("[name]", TrainManagerBase.CurrentRoute.Stations[i].Name); s = s.Replace("[time]", b); s = s.Replace("[difference]", c); - TrainManagerBase.currentHost.AddMessage(s, MessageDependency.StationArrival, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(s, MessageDependency.StationArrival, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 10.0, null); if (TrainManagerBase.CurrentRoute.Stations[i].Type == StationType.Normal) { s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_deadline"}); - TrainManagerBase.currentHost.AddMessage(s, MessageDependency.StationDeparture, GameMode.Normal, MessageColor.White, double.PositiveInfinity, null); + TrainManagerBase.CurrentHost.AddMessage(s, MessageDependency.StationDeparture, GameMode.Normal, MessageColor.White, double.PositiveInfinity, null); } - TrainManagerBase.currentHost.UpdateCustomTimetable(TrainManagerBase.CurrentRoute.Stations[i].TimetableDaytimeTexture, TrainManagerBase.CurrentRoute.Stations[i].TimetableNighttimeTexture); + TrainManagerBase.CurrentHost.UpdateCustomTimetable(TrainManagerBase.CurrentRoute.Stations[i].TimetableDaytimeTexture, TrainManagerBase.CurrentRoute.Stations[i].TimetableNighttimeTexture); } // schedule door locks (passengers stuck between the doors) @@ -388,9 +388,9 @@ private void UpdateStation(double TimeElapsed) { if (TrainManagerBase.CurrentRoute.SecondsSinceMidnight >= StationDepartureTime - buffer.Duration) { - if (TrainManagerBase.currentHost.SimulationState == SimulationState.Running) + if (TrainManagerBase.CurrentHost.SimulationState == SimulationState.Running) { - TrainManagerBase.currentHost.PlaySound(buffer, 1.0, 1.0, TrainManagerBase.CurrentRoute.Stations[i].SoundOrigin, null, false); + TrainManagerBase.CurrentHost.PlaySound(buffer, 1.0, 1.0, TrainManagerBase.CurrentRoute.Stations[i].SoundOrigin, null, false); StationDepartureSoundPlayed = true; } } @@ -452,7 +452,7 @@ private void UpdateStation(double TimeElapsed) for (int j = 0; j < Cars.Length; j++) { if (!Cars[j].EnableLoadingSway) continue; - double r = 2.0 * TrainManagerBase.CurrentRoute.Stations[i].PassengerRatio * TimeElapsed; + double r = 2.0 * TrainManagerBase.CurrentRoute.Stations[i].PassengerRatio * timeElapsed; if (r >= TrainManagerBase.RandomNumberGenerator.NextDouble()) { int d = @@ -481,11 +481,11 @@ private void UpdateStation(double TimeElapsed) break; // Only trigger messages for the player train if (!TrainManagerBase.CurrentRoute.Stations[i].OpenLeftDoors & !TrainManagerBase.CurrentRoute.Stations[i].OpenRightDoors | Specs.DoorCloseMode != DoorMode.Manual) { - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_depart"}), MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 5.0, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_depart"}), MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 5.0, null); } else { - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_depart_closedoors"}), MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 5.0, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_depart_closedoors"}), MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 5.0, null); } break; @@ -505,7 +505,7 @@ private void UpdateStation(double TimeElapsed) StationState = TrainStopState.Completed; if (IsPlayerTrain & TrainManagerBase.CurrentRoute.Stations[i].Type == StationType.Normal) { - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_depart"}), MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 5.0, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","station_depart"}), MessageDependency.None, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 5.0, null); } } } diff --git a/source/TrainManager/Train/TrainBase.cs b/source/TrainManager/Train/TrainBase.cs index 091448211..d4785fa62 100644 --- a/source/TrainManager/Train/TrainBase.cs +++ b/source/TrainManager/Train/TrainBase.cs @@ -58,7 +58,7 @@ public partial class TrainBase : AbstractTrain /// public override bool IsPlayerTrain => this == TrainManagerBase.PlayerTrain; /// The lock to be held whilst operations potentially affecting the makeup of the train are performed - internal object updateLock = new object(); + internal object UpdateLock = new object(); /// public override int NumberOfCars => this.Cars.Length; @@ -134,23 +134,23 @@ public void Synchronize() } /// Updates the objects for all cars in this train - /// The time elapsed - /// Whether this is a forced update - public void UpdateObjects(double TimeElapsed, bool ForceUpdate) + /// The time elapsed + /// Whether this is a forced update + public void UpdateObjects(double timeElapsed, bool forceUpdate) { - if (TrainManagerBase.currentHost.SimulationState == SimulationState.Running) + if (TrainManagerBase.CurrentHost.SimulationState == SimulationState.Running) { for (int i = 0; i < Cars.Length; i++) { - Cars[i].UpdateObjects(TimeElapsed, ForceUpdate, true); - Cars[i].FrontBogie.UpdateObjects(TimeElapsed, ForceUpdate); - Cars[i].RearBogie.UpdateObjects(TimeElapsed, ForceUpdate); + Cars[i].UpdateObjects(timeElapsed, forceUpdate, true); + Cars[i].FrontBogie.UpdateObjects(timeElapsed, forceUpdate); + Cars[i].RearBogie.UpdateObjects(timeElapsed, forceUpdate); if (i == DriverCar && Cars[i].Windscreen != null) { - Cars[i].Windscreen.Update(TimeElapsed); + Cars[i].Windscreen.Update(timeElapsed); } - Cars[i].Coupler.UpdateObjects(TimeElapsed, ForceUpdate); + Cars[i].Coupler.UpdateObjects(timeElapsed, forceUpdate); } } } @@ -178,27 +178,27 @@ public void PreloadTextures() } /// Places the cars - /// The track position of the front car - public void PlaceCars(double TrackPosition) + /// The track position of the front car + public void PlaceCars(double trackPosition) { for (int i = 0; i < Cars.Length; i++) { //Front axle track position - Cars[i].FrontAxle.Follower.TrackPosition = TrackPosition - 0.5 * Cars[i].Length + Cars[i].FrontAxle.Position; + Cars[i].FrontAxle.Follower.TrackPosition = trackPosition - 0.5 * Cars[i].Length + Cars[i].FrontAxle.Position; //Bogie for front axle Cars[i].FrontBogie.FrontAxle.Follower.TrackPosition = Cars[i].FrontAxle.Follower.TrackPosition - 0.5 * Cars[i].FrontBogie.Length + Cars[i].FrontBogie.FrontAxle.Position; Cars[i].FrontBogie.RearAxle.Follower.TrackPosition = Cars[i].FrontAxle.Follower.TrackPosition - 0.5 * Cars[i].FrontBogie.Length + Cars[i].FrontBogie.RearAxle.Position; //Rear axle track position - Cars[i].RearAxle.Follower.TrackPosition = TrackPosition - 0.5 * Cars[i].Length + Cars[i].RearAxle.Position; + Cars[i].RearAxle.Follower.TrackPosition = trackPosition - 0.5 * Cars[i].Length + Cars[i].RearAxle.Position; //Bogie for rear axle Cars[i].RearBogie.FrontAxle.Follower.TrackPosition = Cars[i].RearAxle.Follower.TrackPosition - 0.5 * Cars[i].RearBogie.Length + Cars[i].RearBogie.FrontAxle.Position; Cars[i].RearBogie.RearAxle.Follower.TrackPosition = Cars[i].RearAxle.Follower.TrackPosition - 0.5 * Cars[i].RearBogie.Length + Cars[i].RearBogie.RearAxle.Position; //Beacon reciever (AWS, ATC etc.) - Cars[i].BeaconReceiver.TrackPosition = TrackPosition - 0.5 * Cars[i].Length + Cars[i].BeaconReceiverPosition; - TrackPosition -= Cars[i].Length; + Cars[i].BeaconReceiver.TrackPosition = trackPosition - 0.5 * Cars[i].Length + Cars[i].BeaconReceiverPosition; + trackPosition -= Cars[i].Length; if (i < Cars.Length - 1) { - TrackPosition -= 0.5 * (Cars[i].Coupler.MinimumDistanceBetweenCars + Cars[i].Coupler.MaximumDistanceBetweenCars); + trackPosition -= 0.5 * (Cars[i].Coupler.MinimumDistanceBetweenCars + Cars[i].Coupler.MaximumDistanceBetweenCars); } } } @@ -215,7 +215,7 @@ public override void Dispose() Cars[i].Coupler.ChangeSection(-1); } - TrainManagerBase.currentHost.StopAllSounds(this); + TrainManagerBase.CurrentHost.StopAllSounds(this); for (int i = 0; i < TrainManagerBase.CurrentRoute.Sections.Length; i++) { @@ -235,14 +235,14 @@ public override void UpdateBeacon(int transponderType, int sectionIndex, int opt } /// - public override void Update(double TimeElapsed) + public override void Update(double timeElapsed) { - lock (updateLock) + lock (UpdateLock) { if (State == TrainState.Pending) { // pending train - bool forceIntroduction = !IsPlayerTrain && TrainManagerBase.currentHost.SimulationState != SimulationState.MinimalisticSimulation; + bool forceIntroduction = !IsPlayerTrain && TrainManagerBase.CurrentHost.SimulationState != SimulationState.MinimalisticSimulation; double time = 0.0; if (!forceIntroduction) { @@ -280,7 +280,7 @@ public override void Update(double TimeElapsed) } } - if (this == TrainManagerBase.PlayerTrain && TrainManagerBase.currentHost.SimulationState != SimulationState.Loading) + if (this == TrainManagerBase.PlayerTrain && TrainManagerBase.CurrentHost.SimulationState != SimulationState.Loading) { /* Loading has finished, but we still have an AI train in the current section * This may be caused by an iffy RunInterval value, or simply by having no sections * @@ -338,7 +338,7 @@ public override void Update(double TimeElapsed) else if (State == TrainState.Available) { // available train - UpdatePhysicsAndControls(TimeElapsed); + UpdatePhysicsAndControls(timeElapsed); SafetySystems.OverspeedDevice?.Update(); if (TrainManagerBase.CurrentOptions.Accessibility) @@ -352,7 +352,7 @@ public override void Update(double TimeElapsed) if (!nextSection.AccessibilityAnnounced && tPos < 500) { string s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message", "route_nextsection" }).Replace("[distance]", $"{tPos:0.0}") + "m"; - TrainManagerBase.currentHost.AddMessage(s, MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(s, MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); nextSection.AccessibilityAnnounced = true; } } @@ -366,7 +366,7 @@ public override void Update(double TimeElapsed) if (!nextStation.AccessibilityAnnounced && tPos < 500) { string s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message", "route_nextstation" }).Replace("[distance]", $"{tPos:0.0}") + "m".Replace("[name]", nextStation.Name); - TrainManagerBase.currentHost.AddMessage(s, MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.currentHost.InGameTime + 10.0, null); + TrainManagerBase.CurrentHost.AddMessage(s, MessageDependency.AccessibilityHelper, GameMode.Normal, MessageColor.White, TrainManagerBase.CurrentHost.InGameTime + 10.0, null); nextStation.AccessibilityAnnounced = true; } } @@ -376,20 +376,20 @@ public override void Update(double TimeElapsed) { if (CurrentSectionLimit == 0.0) { - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message", "signal_stop" }), MessageDependency.PassedRedSignal, GameMode.Normal, MessageColor.Red, double.PositiveInfinity, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message", "signal_stop" }), MessageDependency.PassedRedSignal, GameMode.Normal, MessageColor.Red, double.PositiveInfinity, null); } else if (CurrentSpeed > CurrentSectionLimit) { - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message", "signal_overspeed" }), MessageDependency.SectionLimit, GameMode.Normal, MessageColor.Orange, double.PositiveInfinity, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] { "message", "signal_overspeed" }), MessageDependency.SectionLimit, GameMode.Normal, MessageColor.Orange, double.PositiveInfinity, null); } } - AI?.Trigger(TimeElapsed); + AI?.Trigger(timeElapsed); } else if (State == TrainState.Bogus) { // bogus train - AI?.Trigger(TimeElapsed); + AI?.Trigger(timeElapsed); } //Trigger point sounds if appropriate @@ -435,10 +435,10 @@ public override void Update(double TimeElapsed) } /// Updates the physics and controls for this train - /// The time elapsed - private void UpdatePhysicsAndControls(double TimeElapsed) + /// The time elapsed + private void UpdatePhysicsAndControls(double timeElapsed) { - if (TimeElapsed == 0.0 || TimeElapsed > 1000) + if (timeElapsed == 0.0 || timeElapsed > 1000) { //HACK: The physics engine really does not like update times above 1000ms //This works around a bug experienced when jumping to a station on a steep hill @@ -450,18 +450,18 @@ private void UpdatePhysicsAndControls(double TimeElapsed) for (int i = 0; i < Cars.Length; i++) { // move cars - Cars[i].Move(Cars[i].CurrentSpeed * TimeElapsed); + Cars[i].Move(Cars[i].CurrentSpeed * timeElapsed); if (State == TrainState.Disposed) { return; } // update cargo and related score - Cars[i].Cargo.Update(Specs.CurrentAverageAcceleration, TimeElapsed); + Cars[i].Cargo.Update(Specs.CurrentAverageAcceleration, timeElapsed); } // update station and doors - UpdateStation(TimeElapsed); - UpdateDoors(TimeElapsed); + UpdateStation(timeElapsed); + UpdateDoors(timeElapsed); // delayed handles if (Plugin == null) { @@ -475,21 +475,21 @@ private void UpdatePhysicsAndControls(double TimeElapsed) Handles.Brake.Update(); Handles.EmergencyBrake.Update(); Handles.HoldBrake.Actual = Handles.HoldBrake.Driver; - Cars[DriverCar].DSD?.Update(TimeElapsed); + Cars[DriverCar].DSD?.Update(timeElapsed); // update speeds - UpdateSpeeds(TimeElapsed); + UpdateSpeeds(timeElapsed); // Update Run and Motor sounds for (int i = 0; i < Cars.Length; i++) { - Cars[i].Run.Update(TimeElapsed); + Cars[i].Run.Update(timeElapsed); if (Cars[i].Sounds.Motor != null) { - Cars[i].Sounds.Motor.Update(TimeElapsed); + Cars[i].Sounds.Motor.Update(timeElapsed); } } // safety system - if (TrainManagerBase.currentHost.SimulationState != SimulationState.MinimalisticSimulation | !IsPlayerTrain) + if (TrainManagerBase.CurrentHost.SimulationState != SimulationState.MinimalisticSimulation | !IsPlayerTrain) { UpdateSafetySystem(); } @@ -519,13 +519,13 @@ private void UpdatePhysicsAndControls(double TimeElapsed) double a = (3.6 * CurrentSectionLimit) * TrainManagerBase.CurrentOptions.SpeedConversionFactor; s = s.Replace("[speed]", a.ToString("0", CultureInfo.InvariantCulture)); s = s.Replace("[unit]", TrainManagerBase.CurrentOptions.UnitOfSpeed); - TrainManagerBase.currentHost.AddMessage(s, MessageDependency.None, GameMode.Normal, MessageColor.Red, TrainManagerBase.currentHost.InGameTime + 5.0, null); + TrainManagerBase.CurrentHost.AddMessage(s, MessageDependency.None, GameMode.Normal, MessageColor.Red, TrainManagerBase.CurrentHost.InGameTime + 5.0, null); } } } // infrequent updates - InternalTimerTimeElapsed += TimeElapsed; + InternalTimerTimeElapsed += timeElapsed; if (InternalTimerTimeElapsed > 10.0) { InternalTimerTimeElapsed -= 10.0; @@ -533,9 +533,9 @@ private void UpdatePhysicsAndControls(double TimeElapsed) } } - private void UpdateSpeeds(double TimeElapsed) + private void UpdateSpeeds(double timeElapsed) { - if (TrainManagerBase.currentHost.SimulationState == SimulationState.MinimalisticSimulation & IsPlayerTrain) + if (TrainManagerBase.CurrentHost.SimulationState == SimulationState.MinimalisticSimulation & IsPlayerTrain) { // hold the position of the player's train during startup for (int i = 0; i < Cars.Length; i++) @@ -548,30 +548,30 @@ private void UpdateSpeeds(double TimeElapsed) } // update brake system - UpdateBrakeSystem(TimeElapsed, out var DecelerationDueToBrake, out var DecelerationDueToMotor); + UpdateBrakeSystem(timeElapsed, out var decelerationDueToBrake, out var decelerationDueToMotor); // calculate new car speeds - double[] NewSpeeds = new double[Cars.Length]; + double[] newSpeeds = new double[Cars.Length]; for (int i = 0; i < Cars.Length; i++) { - Cars[i].UpdateSpeed(TimeElapsed, DecelerationDueToMotor[i], DecelerationDueToBrake[i], out NewSpeeds[i]); + Cars[i].UpdateSpeed(timeElapsed, decelerationDueToMotor[i], decelerationDueToBrake[i], out newSpeeds[i]); } // calculate center of mass position - double[] CenterOfCarPositions = new double[Cars.Length]; - double CenterOfMassPosition = 0.0; - double TrainMass = 0.0; + double[] centerOfCarPositions = new double[Cars.Length]; + double centerOfMassPosition = 0.0; + double trainMass = 0.0; for (int i = 0; i < Cars.Length; i++) { double pr = Cars[i].RearAxle.Follower.TrackPosition - Cars[i].RearAxle.Position; double pf = Cars[i].FrontAxle.Follower.TrackPosition - Cars[i].FrontAxle.Position; - CenterOfCarPositions[i] = 0.5 * (pr + pf); - CenterOfMassPosition += CenterOfCarPositions[i] * Cars[i].CurrentMass; - TrainMass += Cars[i].CurrentMass; + centerOfCarPositions[i] = 0.5 * (pr + pf); + centerOfMassPosition += centerOfCarPositions[i] * Cars[i].CurrentMass; + trainMass += Cars[i].CurrentMass; } - if (TrainMass != 0.0) + if (trainMass != 0.0) { - CenterOfMassPosition /= TrainMass; + centerOfMassPosition /= trainMass; } { @@ -580,38 +580,38 @@ private void UpdateSpeeds(double TimeElapsed) int p = -1; // primary car index int s = -1; // secondary car index { - double PrimaryDistance = double.MaxValue; + double primaryDistance = double.MaxValue; for (int i = 0; i < Cars.Length; i++) { - double d = Math.Abs(CenterOfCarPositions[i] - CenterOfMassPosition); - if (d < PrimaryDistance) + double d = Math.Abs(centerOfCarPositions[i] - centerOfMassPosition); + if (d < primaryDistance) { - PrimaryDistance = d; + primaryDistance = d; p = i; } } - double SecondDistance = Double.MaxValue; + double secondDistance = Double.MaxValue; for (int i = p - 1; i <= p + 1; i++) { if (i >= 0 & i < Cars.Length & i != p) { - double d = Math.Abs(CenterOfCarPositions[i] - CenterOfMassPosition); - if (d < SecondDistance) + double d = Math.Abs(centerOfCarPositions[i] - centerOfMassPosition); + if (d < secondDistance) { - SecondDistance = d; + secondDistance = d; s = i; } } } - if (s >= 0 && PrimaryDistance <= 0.25 * (PrimaryDistance + SecondDistance)) + if (s >= 0 && primaryDistance <= 0.25 * (primaryDistance + secondDistance)) { s = -1; } } // coupler - bool[] CouplerCollision = new bool[Cars.Length - 1]; + bool[] couplerCollision = new bool[Cars.Length - 1]; int cf, cr; if (s >= 0) { @@ -625,7 +625,7 @@ private void UpdateSpeeds(double TimeElapsed) double min = Cars[p].Coupler.MinimumDistanceBetweenCars; double max = Cars[p].Coupler.MaximumDistanceBetweenCars; - double d = CenterOfCarPositions[p] - CenterOfCarPositions[s] - 0.5 * (Cars[p].Length + Cars[s].Length); + double d = centerOfCarPositions[p] - centerOfCarPositions[s] - 0.5 * (Cars[p].Length + Cars[s].Length); if (d < min) { double t = (min - d) / (Cars[p].CurrentMass + Cars[s].CurrentMass); @@ -633,9 +633,9 @@ private void UpdateSpeeds(double TimeElapsed) double ts = t * Cars[p].CurrentMass; Cars[p].UpdateTrackFollowers(tp, false, false); Cars[s].UpdateTrackFollowers(-ts, false, false); - CenterOfCarPositions[p] += tp; - CenterOfCarPositions[s] -= ts; - CouplerCollision[p] = true; + centerOfCarPositions[p] += tp; + centerOfCarPositions[s] -= ts; + couplerCollision[p] = true; } else if (d > max & !Cars[p].Derailed & !Cars[s].Derailed) { @@ -645,9 +645,9 @@ private void UpdateSpeeds(double TimeElapsed) Cars[p].UpdateTrackFollowers(-tp, false, false); Cars[s].UpdateTrackFollowers(ts, false, false); - CenterOfCarPositions[p] -= tp; - CenterOfCarPositions[s] += ts; - CouplerCollision[p] = true; + centerOfCarPositions[p] -= tp; + centerOfCarPositions[s] += ts; + couplerCollision[p] = true; } cf = p; @@ -665,20 +665,20 @@ private void UpdateSpeeds(double TimeElapsed) { double min = Cars[i].Coupler.MinimumDistanceBetweenCars; double max = Cars[i].Coupler.MaximumDistanceBetweenCars; - double d = CenterOfCarPositions[i] - CenterOfCarPositions[i + 1] - 0.5 * (Cars[i].Length + Cars[i + 1].Length); + double d = centerOfCarPositions[i] - centerOfCarPositions[i + 1] - 0.5 * (Cars[i].Length + Cars[i + 1].Length); if (d < min) { double t = min - d + 0.0001; Cars[i].UpdateTrackFollowers(t, false, false); - CenterOfCarPositions[i] += t; - CouplerCollision[i] = true; + centerOfCarPositions[i] += t; + couplerCollision[i] = true; } else if (d > max & !Cars[i].Derailed & !Cars[i + 1].Derailed) { double t = d - max + 0.0001; Cars[i].UpdateTrackFollowers(-t, false, false); - CenterOfCarPositions[i] -= t; - CouplerCollision[i] = true; + centerOfCarPositions[i] -= t; + couplerCollision[i] = true; } } @@ -687,33 +687,33 @@ private void UpdateSpeeds(double TimeElapsed) { double min = Cars[i - 1].Coupler.MinimumDistanceBetweenCars; double max = Cars[i - 1].Coupler.MaximumDistanceBetweenCars; - double d = CenterOfCarPositions[i - 1] - CenterOfCarPositions[i] - 0.5 * (Cars[i].Length + Cars[i - 1].Length); + double d = centerOfCarPositions[i - 1] - centerOfCarPositions[i] - 0.5 * (Cars[i].Length + Cars[i - 1].Length); if (d < min) { double t = min - d + 0.0001; Cars[i].UpdateTrackFollowers(-t, false, false); - CenterOfCarPositions[i] -= t; - CouplerCollision[i - 1] = true; + centerOfCarPositions[i] -= t; + couplerCollision[i - 1] = true; } else if (d > max & !Cars[i].Derailed & !Cars[i - 1].Derailed) { double t = d - max + 0.0001; Cars[i].UpdateTrackFollowers(t, false, false); - CenterOfCarPositions[i] += t; - CouplerCollision[i - 1] = true; + centerOfCarPositions[i] += t; + couplerCollision[i - 1] = true; } } // update speeds for (int i = 0; i < Cars.Length - 1; i++) { - if (CouplerCollision[i]) + if (couplerCollision[i]) { int j; for (j = i + 1; j < Cars.Length - 1; j++) { - if (!CouplerCollision[j]) + if (!couplerCollision[j]) { break; } @@ -723,7 +723,7 @@ private void UpdateSpeeds(double TimeElapsed) double m = 0.0; for (int k = i; k <= j; k++) { - v += NewSpeeds[k] * Cars[k].CurrentMass; + v += newSpeeds[k] * Cars[k].CurrentMass; m += Cars[k].CurrentMass; } @@ -734,12 +734,12 @@ private void UpdateSpeeds(double TimeElapsed) for (int k = i; k <= j; k++) { - if (TrainManagerBase.CurrentOptions.Derailments && Math.Abs(v - NewSpeeds[k]) > 0.5 * CriticalCollisionSpeedDifference) + if (TrainManagerBase.CurrentOptions.Derailments && Math.Abs(v - newSpeeds[k]) > 0.5 * CriticalCollisionSpeedDifference) { - Derail(k, TimeElapsed); + Derail(k, timeElapsed); } - NewSpeeds[k] = v; + newSpeeds[k] = v; } i = j - 1; @@ -749,12 +749,12 @@ private void UpdateSpeeds(double TimeElapsed) // update average data CurrentSpeed = 0.0; Specs.CurrentAverageAcceleration = 0.0; - double invtime = TimeElapsed != 0.0 ? 1.0 / TimeElapsed : 1.0; + double invtime = timeElapsed != 0.0 ? 1.0 / timeElapsed : 1.0; for (int i = 0; i < Cars.Length; i++) { - Cars[i].Specs.Acceleration = (NewSpeeds[i] - Cars[i].CurrentSpeed) * invtime; - Cars[i].CurrentSpeed = NewSpeeds[i]; - CurrentSpeed += NewSpeeds[i]; + Cars[i].Specs.Acceleration = (newSpeeds[i] - Cars[i].CurrentSpeed) * invtime; + Cars[i].CurrentSpeed = newSpeeds[i]; + CurrentSpeed += newSpeeds[i]; Specs.CurrentAverageAcceleration += Cars[i].Specs.Acceleration; } @@ -796,41 +796,41 @@ internal void UpdateSafetySystem() /// Call this method to derail a car - /// The car index to derail - /// The elapsed time for this frame (Used for logging) - public override void Derail(int CarIndex, double ElapsedTime) + /// The car index to derail + /// The elapsed time for this frame (Used for logging) + public override void Derail(int carIndex, double elapsedTime) { - this.Cars[CarIndex].Derailed = true; + this.Cars[carIndex].Derailed = true; this.Derailed = true; - if (Cars[CarIndex].Sounds.Loop != null) + if (Cars[carIndex].Sounds.Loop != null) { - TrainManagerBase.currentHost.StopSound(Cars[CarIndex].Sounds.Loop.Source); + TrainManagerBase.CurrentHost.StopSound(Cars[carIndex].Sounds.Loop.Source); } - Cars[CarIndex].Run.Stop(); + Cars[carIndex].Run.Stop(); if (TrainManagerBase.CurrentOptions.GenerateDebugLogging) { - TrainManagerBase.currentHost.AddMessage(MessageType.Information, false, "Car " + CarIndex + " derailed. Current simulation time: " + TrainManagerBase.CurrentRoute.SecondsSinceMidnight + " Current frame time: " + ElapsedTime); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Information, false, "Car " + carIndex + " derailed. Current simulation time: " + TrainManagerBase.CurrentRoute.SecondsSinceMidnight + " Current frame time: " + elapsedTime); } } /// - public override void Derail(AbstractCar Car, double ElapsedTime) + public override void Derail(AbstractCar car, double elapsedTime) { - if (this.Cars.Contains(Car)) + if (this.Cars.Contains(car)) { - var c = Car as CarBase; + var c = car as CarBase; // ReSharper disable once PossibleNullReferenceException if (c.Sounds.Loop != null) { - TrainManagerBase.currentHost.StopSound(c.Sounds.Loop.Source); + TrainManagerBase.CurrentHost.StopSound(c.Sounds.Loop.Source); } c.Run.Stop(); c.Derailed = true; this.Derailed = true; if (TrainManagerBase.CurrentOptions.GenerateDebugLogging) { - TrainManagerBase.currentHost.AddMessage(MessageType.Information, false, "Car " + c.Index + " derailed. Current simulation time: " + TrainManagerBase.CurrentRoute.SecondsSinceMidnight + " Current frame time: " + ElapsedTime); + TrainManagerBase.CurrentHost.AddMessage(MessageType.Information, false, "Car " + c.Index + " derailed. Current simulation time: " + TrainManagerBase.CurrentRoute.SecondsSinceMidnight + " Current frame time: " + elapsedTime); } } } @@ -838,7 +838,7 @@ public override void Derail(AbstractCar Car, double ElapsedTime) /// public override void Reverse(bool flipInterior = false, bool flipDriver = false) { - lock (updateLock) + lock (UpdateLock) { double trackPosition = Cars[0].TrackPosition; Cars = Cars.Reverse().ToArray(); @@ -894,13 +894,13 @@ public override double RearCarTrackPosition /// public override void SectionChange() { - if (CurrentSectionLimit == 0.0 && TrainManagerBase.currentHost.SimulationState != SimulationState.MinimalisticSimulation) + if (CurrentSectionLimit == 0.0 && TrainManagerBase.CurrentHost.SimulationState != SimulationState.MinimalisticSimulation) { - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"message","signal_stop"}), MessageDependency.PassedRedSignal, GameMode.Normal, MessageColor.Red, double.PositiveInfinity, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"message","signal_stop"}), MessageDependency.PassedRedSignal, GameMode.Normal, MessageColor.Red, double.PositiveInfinity, null); } else if (CurrentSpeed > CurrentSectionLimit) { - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"message","signal_overspeed"}), MessageDependency.SectionLimit, GameMode.Normal, MessageColor.Orange, double.PositiveInfinity, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"message","signal_overspeed"}), MessageDependency.SectionLimit, GameMode.Normal, MessageColor.Orange, double.PositiveInfinity, null); } } @@ -1034,14 +1034,14 @@ public override void Jump(int stationIndex, int trackKey) { for (int i = newTrackElement; i < currentTrackElement; i++) { - for (int j = 0; j < TrainManagerBase.currentHost.Tracks[0].Elements[i].Events.Count; j++) + for (int j = 0; j < TrainManagerBase.CurrentHost.Tracks[0].Elements[i].Events.Count; j++) { - TrainManagerBase.currentHost.Tracks[0].Elements[i].Events[j].Reset(); + TrainManagerBase.CurrentHost.Tracks[0].Elements[i].Events[j].Reset(); } } } - TrainManagerBase.currentHost.ProcessJump(this, stationIndex, 0); + TrainManagerBase.CurrentHost.ProcessJump(this, stationIndex, 0); } } @@ -1060,7 +1060,7 @@ public void ChangeCameraCar(bool shouldIncrement) if (CameraCar < Cars.Length - 1) { CameraCar++; - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"notification","exterior"}) + " " + (CurrentDirection == TrackDirection.Reverse ? Cars.Length - CameraCar : CameraCar + 1), MessageDependency.CameraView, GameMode.Expert, + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"notification","exterior"}) + " " + (CurrentDirection == TrackDirection.Reverse ? Cars.Length - CameraCar : CameraCar + 1), MessageDependency.CameraView, GameMode.Expert, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 2.0, null); } } @@ -1069,7 +1069,7 @@ public void ChangeCameraCar(bool shouldIncrement) if (CameraCar > 0) { CameraCar--; - TrainManagerBase.currentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"notification","exterior"}) + " " + (CurrentDirection == TrackDirection.Reverse ? Cars.Length - CameraCar : CameraCar + 1), MessageDependency.CameraView, GameMode.Expert, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 2.0, null); + TrainManagerBase.CurrentHost.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"notification","exterior"}) + " " + (CurrentDirection == TrackDirection.Reverse ? Cars.Length - CameraCar : CameraCar + 1), MessageDependency.CameraView, GameMode.Expert, MessageColor.White, TrainManagerBase.CurrentRoute.SecondsSinceMidnight + 2.0, null); } } diff --git a/source/TrainManager/TrainManager.cs b/source/TrainManager/TrainManager.cs index f8a2b4dbf..ce7a07de3 100644 --- a/source/TrainManager/TrainManager.cs +++ b/source/TrainManager/TrainManager.cs @@ -13,7 +13,7 @@ namespace TrainManager /// The base train manager class public abstract class TrainManagerBase { - internal static HostInterface currentHost; + internal static HostInterface CurrentHost; internal static BaseRenderer Renderer; public static CurrentRoute CurrentRoute; internal static FileSystem FileSystem; @@ -32,11 +32,11 @@ public abstract class TrainManagerBase /// Stores the plugin error message string, or a null reference if no error encountered public static string PluginError; - protected TrainManagerBase(HostInterface host, BaseRenderer renderer, BaseOptions Options, FileSystem fileSystem) + protected TrainManagerBase(HostInterface host, BaseRenderer renderer, BaseOptions options, FileSystem fileSystem) { - currentHost = host; + CurrentHost = host; Renderer = renderer; - CurrentOptions = Options; + CurrentOptions = options; FileSystem = fileSystem; } @@ -67,19 +67,19 @@ public static void UnderailTrain(TrainBase Train) } /// Updates the objects for all trains within the simulation world - /// The time elapsed - /// Whether this is a forced update - public void UpdateTrainObjects(double TimeElapsed, bool ForceUpdate) + /// The time elapsed + /// Whether this is a forced update + public void UpdateTrainObjects(double timeElapsed, bool forceUpdate) { for (int i = 0; i < Trains.Length; i++) { - Trains[i].UpdateObjects(TimeElapsed, ForceUpdate); + Trains[i].UpdateObjects(timeElapsed, forceUpdate); } // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop - foreach (ScriptedTrain 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); + train.UpdateObjects(timeElapsed, forceUpdate); } } @@ -87,9 +87,9 @@ public void UpdateTrainObjects(double TimeElapsed, bool ForceUpdate) public void JumpTFO() { // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop - foreach (ScriptedTrain 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); + train.Jump(-1, 0); } } } From 61d7c56001202923795750cc1e67d173d08d1d47 Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Mon, 11 Nov 2024 17:12:16 +0000 Subject: [PATCH 2/7] Change: Enforce lowerCamelCase for parameter names (P2) Route Viewer --- source/OpenBVE/Audio/Sounds.Update.cs | 2 +- source/RouteViewer/FunctionScripts.cs | 964 ++++++++++++------------ source/RouteViewer/Game/Menu.cs | 2 +- source/RouteViewer/GameR.cs | 10 +- source/RouteViewer/InterfaceR.cs | 4 +- source/RouteViewer/LoadingR.cs | 40 +- source/RouteViewer/NewRendererR.cs | 55 +- source/RouteViewer/ObjectManager.cs | 6 +- source/RouteViewer/ProgramR.cs | 102 ++- source/RouteViewer/System/Gamewindow.cs | 14 +- source/RouteViewer/WorldR.cs | 16 +- source/RouteViewer/formOptions.cs | 6 +- source/RouteViewer/formRailPaths.cs | 2 +- source/SoundManager/Sounds.CarSound.cs | 24 +- source/SoundManager/Sounds.cs | 22 +- 15 files changed, 634 insertions(+), 635 deletions(-) diff --git a/source/OpenBVE/Audio/Sounds.Update.cs b/source/OpenBVE/Audio/Sounds.Update.cs index 3901ebf9f..4c6ac3578 100644 --- a/source/OpenBVE/Audio/Sounds.Update.cs +++ b/source/OpenBVE/Audio/Sounds.Update.cs @@ -211,7 +211,7 @@ protected override void UpdateInverseModel(double timeElapsed) toBePlayed[i].Gain += clampFactor * toBePlayed[i].Distance * toBePlayed[i].Distance; } double desiredLogClampFactor; - int index = Math.Min(systemMaxSounds, Interface.CurrentOptions.SoundNumber); + int index = Math.Min(SystemMaxSounds, Interface.CurrentOptions.SoundNumber); if (toBePlayed.Count <= index) { desiredLogClampFactor = MinLogClampFactor; } else { diff --git a/source/RouteViewer/FunctionScripts.cs b/source/RouteViewer/FunctionScripts.cs index d8f41c11a..2b1ecf048 100644 --- a/source/RouteViewer/FunctionScripts.cs +++ b/source/RouteViewer/FunctionScripts.cs @@ -11,1021 +11,1021 @@ namespace RouteViewer { internal static class FunctionScripts { // execute function script - internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager.Train Train, int CarIndex, Vector3 Position, double TrackPosition, int SectionIndex, bool IsPartOfTrain, double TimeElapsed, int CurrentState) { + internal static void ExecuteFunctionScript(FunctionScript function, TrainManager.Train train, int carIndex, Vector3 position, double trackPosition, int sectionIndex, bool isPartOfTrain, double timeElapsed, int currentState) { int s = 0, c = 0; - for (int i = 0; i < Function.InstructionSet.Length; i++) { - switch (Function.InstructionSet[i]) { + for (int i = 0; i < function.InstructionSet.Length; i++) { + switch (function.InstructionSet[i]) { // system case Instructions.SystemHalt: - i = Function.InstructionSet.Length; + i = function.InstructionSet.Length; break; case Instructions.SystemConstant: - Function.Stack[s] = Function.Constants[c]; + function.Stack[s] = function.Constants[c]; s++; c++; break; case Instructions.SystemConstantArray: { - int n = (int)Function.InstructionSet[i + 1]; + int n = (int)function.InstructionSet[i + 1]; for (int j = 0; j < n; j++) { - Function.Stack[s + j] = Function.Constants[c + j]; + function.Stack[s + j] = function.Constants[c + j]; } s += n; c += n; i++; } break; case Instructions.SystemValue: - Function.Stack[s] = Function.LastResult; + function.Stack[s] = function.LastResult; s++; break; case Instructions.SystemDelta: - Function.Stack[s] = TimeElapsed; + function.Stack[s] = timeElapsed; s++; break; // stack case Instructions.StackCopy: - Function.Stack[s] = Function.Stack[s - 1]; + function.Stack[s] = function.Stack[s - 1]; s++; break; case Instructions.StackSwap: - (Function.Stack[s - 1], Function.Stack[s - 2]) = (Function.Stack[s - 2], Function.Stack[s - 1]); + (function.Stack[s - 1], function.Stack[s - 2]) = (function.Stack[s - 2], function.Stack[s - 1]); break; // math case Instructions.MathPlus: - Function.Stack[s - 2] += Function.Stack[s - 1]; + function.Stack[s - 2] += function.Stack[s - 1]; s--; break; case Instructions.MathSubtract: - Function.Stack[s - 2] -= Function.Stack[s - 1]; + function.Stack[s - 2] -= function.Stack[s - 1]; s--; break; case Instructions.MathMinus: - Function.Stack[s - 1] = -Function.Stack[s - 1]; + function.Stack[s - 1] = -function.Stack[s - 1]; break; case Instructions.MathTimes: - Function.Stack[s - 2] *= Function.Stack[s - 1]; + function.Stack[s - 2] *= function.Stack[s - 1]; s--; break; case Instructions.MathDivide: - Function.Stack[s - 2] = Function.Stack[s - 1] == 0.0 ? 0.0 : Function.Stack[s - 2] / Function.Stack[s - 1]; + function.Stack[s - 2] = function.Stack[s - 1] == 0.0 ? 0.0 : function.Stack[s - 2] / function.Stack[s - 1]; s--; break; case Instructions.MathReciprocal: - Function.Stack[s - 1] = Function.Stack[s - 1] == 0.0 ? 0.0 : 1.0 / Function.Stack[s - 1]; + function.Stack[s - 1] = function.Stack[s - 1] == 0.0 ? 0.0 : 1.0 / function.Stack[s - 1]; break; case Instructions.MathPower: { - double a = Function.Stack[s - 2]; - double b = Function.Stack[s - 1]; + double a = function.Stack[s - 2]; + double b = function.Stack[s - 1]; if (b == 2.0) { - Function.Stack[s - 2] = a * a; + function.Stack[s - 2] = a * a; } else if (b == 3.0) { - Function.Stack[s - 2] = a * a * a; + function.Stack[s - 2] = a * a * a; } else if (b == 4.0) { double t = a * a; - Function.Stack[s - 2] = t * t; + function.Stack[s - 2] = t * t; } else if (b == 5.0) { double t = a * a; - Function.Stack[s - 2] = t * t * a; + function.Stack[s - 2] = t * t * a; } else if (b == 6.0) { double t = a * a * a; - Function.Stack[s - 2] = t * t; + function.Stack[s - 2] = t * t; } else if (b == 7.0) { double t = a * a * a; - Function.Stack[s - 2] = t * t * a; + function.Stack[s - 2] = t * t * a; } else if (b == 8.0) { double t = a * a; t *= t; - Function.Stack[s - 2] = t * t; + function.Stack[s - 2] = t * t; } else if (b == 0.0) { - Function.Stack[s - 2] = 1.0; + function.Stack[s - 2] = 1.0; } else if (b < 0.0) { - Function.Stack[s - 2] = 0.0; + function.Stack[s - 2] = 0.0; } else { - Function.Stack[s - 2] = Math.Pow(a, b); + function.Stack[s - 2] = Math.Pow(a, b); } s--; break; } case Instructions.MathRandom: { //Generates a random number between two given doubles - double min = Function.Stack[s - 2]; - double max = Function.Stack[s - 1]; + double min = function.Stack[s - 2]; + double max = function.Stack[s - 1]; var randomGenerator = new Random(); - Function.Stack[s - 2] = min + randomGenerator.NextDouble() * (max - min); + function.Stack[s - 2] = min + randomGenerator.NextDouble() * (max - min); s--; } break; case Instructions.MathRandomInt: { //Generates a random number between two given doubles - int min = (int)Function.Stack[s - 2]; - int max = (int)Function.Stack[s - 1]; + int min = (int)function.Stack[s - 2]; + int max = (int)function.Stack[s - 1]; var randomGenerator = new Random(); - Function.Stack[s - 2] = randomGenerator.Next(min, max); + function.Stack[s - 2] = randomGenerator.Next(min, max); s--; } break; case Instructions.MathIncrement: - Function.Stack[s - 1] += 1.0; + function.Stack[s - 1] += 1.0; break; case Instructions.MathDecrement: - Function.Stack[s - 1] -= 1.0; + function.Stack[s - 1] -= 1.0; break; case Instructions.MathFusedMultiplyAdd: - Function.Stack[s - 3] = Function.Stack[s - 3] * Function.Stack[s - 2] + Function.Stack[s - 1]; + function.Stack[s - 3] = function.Stack[s - 3] * function.Stack[s - 2] + function.Stack[s - 1]; s -= 2; break; case Instructions.MathQuotient: - Function.Stack[s - 2] = Function.Stack[s - 1] == 0.0 ? 0.0 : Math.Floor(Function.Stack[s - 2] / Function.Stack[s - 1]); + function.Stack[s - 2] = function.Stack[s - 1] == 0.0 ? 0.0 : Math.Floor(function.Stack[s - 2] / function.Stack[s - 1]); s--; break; case Instructions.MathMod: - Function.Stack[s - 2] = Function.Stack[s - 1] == 0.0 ? 0.0 : Function.Stack[s - 2] - Function.Stack[s - 1] * Math.Floor(Function.Stack[s - 2] / Function.Stack[s - 1]); + function.Stack[s - 2] = function.Stack[s - 1] == 0.0 ? 0.0 : function.Stack[s - 2] - function.Stack[s - 1] * Math.Floor(function.Stack[s - 2] / function.Stack[s - 1]); s--; break; case Instructions.MathFloor: - Function.Stack[s - 1] = Math.Floor(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Floor(function.Stack[s - 1]); break; case Instructions.MathCeiling: - Function.Stack[s - 1] = Math.Ceiling(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Ceiling(function.Stack[s - 1]); break; case Instructions.MathRound: - Function.Stack[s - 1] = Math.Round(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Round(function.Stack[s - 1]); break; case Instructions.MathMin: - Function.Stack[s - 2] = Function.Stack[s - 2] < Function.Stack[s - 1] ? Function.Stack[s - 2] : Function.Stack[s - 1]; + function.Stack[s - 2] = function.Stack[s - 2] < function.Stack[s - 1] ? function.Stack[s - 2] : function.Stack[s - 1]; s--; break; case Instructions.MathMax: - Function.Stack[s - 2] = Function.Stack[s - 2] > Function.Stack[s - 1] ? Function.Stack[s - 2] : Function.Stack[s - 1]; + function.Stack[s - 2] = function.Stack[s - 2] > function.Stack[s - 1] ? function.Stack[s - 2] : function.Stack[s - 1]; s--; break; case Instructions.MathAbs: - Function.Stack[s - 1] = Math.Abs(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Abs(function.Stack[s - 1]); break; case Instructions.MathSign: - Function.Stack[s - 1] = Math.Sign(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Sign(function.Stack[s - 1]); break; case Instructions.MathExp: - Function.Stack[s - 1] = Math.Exp(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Exp(function.Stack[s - 1]); break; case Instructions.MathLog: - Function.Stack[s - 1] = Log(Function.Stack[s - 1]); + function.Stack[s - 1] = Log(function.Stack[s - 1]); break; case Instructions.MathSqrt: - Function.Stack[s - 1] = Sqrt(Function.Stack[s - 1]); + function.Stack[s - 1] = Sqrt(function.Stack[s - 1]); break; case Instructions.MathSin: - Function.Stack[s - 1] = Math.Sin(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Sin(function.Stack[s - 1]); break; case Instructions.MathCos: - Function.Stack[s - 1] = Math.Cos(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Cos(function.Stack[s - 1]); break; case Instructions.MathTan: - Function.Stack[s - 1] = Tan(Function.Stack[s - 1]); + function.Stack[s - 1] = Tan(function.Stack[s - 1]); break; case Instructions.MathArcTan: - Function.Stack[s - 1] = Math.Atan(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Atan(function.Stack[s - 1]); break; case Instructions.MathPi: - Function.Stack[s] = Math.PI; + function.Stack[s] = Math.PI; s++; break; // comparisons case Instructions.CompareEqual: - Function.Stack[s - 2] = Function.Stack[s - 2] == Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] == function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareUnequal: - Function.Stack[s - 2] = Function.Stack[s - 2] != Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareLess: - Function.Stack[s - 2] = Function.Stack[s - 2] < Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] < function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareGreater: - Function.Stack[s - 2] = Function.Stack[s - 2] > Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] > function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareLessEqual: - Function.Stack[s - 2] = Function.Stack[s - 2] <= Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] <= function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareGreaterEqual: - Function.Stack[s - 2] = Function.Stack[s - 2] >= Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] >= function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareConditional: - Function.Stack[s - 3] = Function.Stack[s - 3] != 0.0 ? Function.Stack[s - 2] : Function.Stack[s - 1]; + function.Stack[s - 3] = function.Stack[s - 3] != 0.0 ? function.Stack[s - 2] : function.Stack[s - 1]; s -= 2; break; // logical case Instructions.LogicalNot: - Function.Stack[s - 1] = Function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; + function.Stack[s - 1] = function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; break; case Instructions.LogicalAnd: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 & Function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 & function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; s--; break; case Instructions.LogicalOr: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 | Function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 | function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; s--; break; case Instructions.LogicalNand: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 & Function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 & function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; s--; break; case Instructions.LogicalNor: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 | Function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 | function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; s--; break; case Instructions.LogicalXor: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 ^ Function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 ^ function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; s--; break; case Instructions.CurrentObjectState: - Function.Stack[s] = CurrentState; + function.Stack[s] = currentState; s++; break; // time/camera case Instructions.TimeSecondsSinceMidnight: - Function.Stack[s] = Game.SecondsSinceMidnight; + function.Stack[s] = Game.SecondsSinceMidnight; s++; break; case Instructions.TimeHourDigit: - Function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight / 3600.0); + function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight / 3600.0); s++; break; case Instructions.TimeMinuteDigit: - Function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight / 60 % 60); + function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight / 60 % 60); s++; break; case Instructions.TimeSecondDigit: - Function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight % 60); + function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight % 60); s++; break; case Instructions.CameraDistance: { - double dx = Program.Renderer.Camera.AbsolutePosition.X - Position.X; - double dy = Program.Renderer.Camera.AbsolutePosition.Y - Position.Y; - double dz = Program.Renderer.Camera.AbsolutePosition.Z - Position.Z; - Function.Stack[s] = Math.Sqrt(dx * dx + dy * dy + dz * dz); + double dx = Program.Renderer.Camera.AbsolutePosition.X - position.X; + double dy = Program.Renderer.Camera.AbsolutePosition.Y - position.Y; + double dz = Program.Renderer.Camera.AbsolutePosition.Z - position.Z; + function.Stack[s] = Math.Sqrt(dx * dx + dy * dy + dz * dz); s++; } break; case Instructions.CameraXDistance: { - Function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.X - Position.X; + function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.X - position.X; s++; } break; case Instructions.CameraYDistance: { - Function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Y - Position.Y; + function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Y - position.Y; s++; } break; case Instructions.CameraZDistance: { - Function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Z - Position.Z; + function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Z - position.Z; s++; } break; case Instructions.BillboardX: { - Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - Position; - Function.Stack[s] = Math.Atan2(toCamera.Y, -toCamera.Z); + Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - position; + function.Stack[s] = Math.Atan2(toCamera.Y, -toCamera.Z); s++; } break; case Instructions.BillboardY: { - Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - Position; - Function.Stack[s] = Math.Atan2(-toCamera.Z, toCamera.X); + Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - position; + function.Stack[s] = Math.Atan2(-toCamera.Z, toCamera.X); s++; } break; case Instructions.CameraView: //Returns whether the camera is in interior or exterior mode if (Program.Renderer.Camera.CurrentMode == CameraViewMode.Interior) { - Function.Stack[s] = 0; + function.Stack[s] = 0; } else { - Function.Stack[s] = 1; + function.Stack[s] = 1; } s++; break; // train case Instructions.PlayerTrain: - if (IsPartOfTrain && Train != null) + if (isPartOfTrain && train != null) { - Function.Stack[s] = Train.IsPlayerTrain ? 1.0 : 0.0; + function.Stack[s] = train.IsPlayerTrain ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainCars: - if (Train != null) { - Function.Stack[s] = (double)Train.Cars.Length; + if (train != null) { + function.Stack[s] = train.Cars.Length; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainDestination: - if (Train != null) { - Function.Stack[s] = (double)Train.Destination; + if (train != null) { + function.Stack[s] = train.Destination; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainLength: - if (Train != null) { - Function.Stack[s] = Train.Length; + if (train != null) { + function.Stack[s] = train.Length; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainSpeed: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CurrentSpeed; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CurrentSpeed; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainSpeedOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CurrentSpeed; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CurrentSpeed; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.TrainSpeedometer: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].Specs.PerceivedSpeed; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].Specs.PerceivedSpeed; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainSpeedometerOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].Specs.PerceivedSpeed; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].Specs.PerceivedSpeed; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.TrainAcceleration: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].Specs.Acceleration; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].Specs.Acceleration; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainAccelerationOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].Specs.Acceleration; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].Specs.Acceleration; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.TrainAccelerationMotor: - if (Train != null) { - Function.Stack[s] = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - if (Train.Cars[j].Specs.IsMotorCar) { + if (train != null) { + function.Stack[s] = 0.0; + for (int j = 0; j < train.Cars.Length; j++) { + if (train.Cars[j].Specs.IsMotorCar) { // hack: MotorAcceleration does not distinguish between forward/backward - if (Train.Cars[j].Specs.MotorAcceleration < 0.0) { - Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * (double)Math.Sign(Train.Cars[j].CurrentSpeed); - } else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) { - Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual; + if (train.Cars[j].Specs.MotorAcceleration < 0.0) { + function.Stack[s] = train.Cars[j].Specs.MotorAcceleration * Math.Sign(train.Cars[j].CurrentSpeed); + } else if (train.Cars[j].Specs.MotorAcceleration > 0.0) { + function.Stack[s] = train.Cars[j].Specs.MotorAcceleration * (double)train.Handles.Reverser.Actual; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } break; } } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainAccelerationMotorOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { // hack: MotorAcceleration does not distinguish between forward/backward - if (Train.Cars[j].Specs.MotorAcceleration < 0.0) { - Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * (double)Math.Sign(Train.Cars[j].CurrentSpeed); - } else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) { - Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual; + if (train.Cars[j].Specs.MotorAcceleration < 0.0) { + function.Stack[s - 1] = train.Cars[j].Specs.MotorAcceleration * Math.Sign(train.Cars[j].CurrentSpeed); + } else if (train.Cars[j].Specs.MotorAcceleration > 0.0) { + function.Stack[s - 1] = train.Cars[j].Specs.MotorAcceleration * (double)train.Handles.Reverser.Actual; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } 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 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 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); + function.Stack[s] = Math.Sqrt(playerDist); s++; break; case Instructions.TrainDistance: - if (Train != null) { + if (train != null) { double dist = double.MaxValue; - for (int j = 0; j < Train.Cars.Length; j++) { - double fx = Train.Cars[j].FrontAxle.Follower.WorldPosition.X - Position.X; - double fy = Train.Cars[j].FrontAxle.Follower.WorldPosition.Y - Position.Y; - double fz = Train.Cars[j].FrontAxle.Follower.WorldPosition.Z - Position.Z; + for (int j = 0; j < train.Cars.Length; j++) { + double fx = train.Cars[j].FrontAxle.Follower.WorldPosition.X - position.X; + double fy = train.Cars[j].FrontAxle.Follower.WorldPosition.Y - position.Y; + double fz = train.Cars[j].FrontAxle.Follower.WorldPosition.Z - position.Z; double f = fx * fx + fy * fy + fz * fz; if (f < dist) dist = f; - double rx = Train.Cars[j].RearAxle.Follower.WorldPosition.X - Position.X; - double ry = Train.Cars[j].RearAxle.Follower.WorldPosition.Y - Position.Y; - double rz = Train.Cars[j].RearAxle.Follower.WorldPosition.Z - Position.Z; + double rx = train.Cars[j].RearAxle.Follower.WorldPosition.X - position.X; + double ry = train.Cars[j].RearAxle.Follower.WorldPosition.Y - position.Y; + double rz = train.Cars[j].RearAxle.Follower.WorldPosition.Z - position.Z; double r = rx * rx + ry * ry + rz * rz; if (r < dist) dist = r; } - Function.Stack[s] = Math.Sqrt(dist); + function.Stack[s] = Math.Sqrt(dist); } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainDistanceToCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - double x = 0.5 * (Train.Cars[j].FrontAxle.Follower.WorldPosition.X + Train.Cars[j].RearAxle.Follower.WorldPosition.X) - Position.X; - double y = 0.5 * (Train.Cars[j].FrontAxle.Follower.WorldPosition.Y + Train.Cars[j].RearAxle.Follower.WorldPosition.Y) - Position.Y; - double z = 0.5 * (Train.Cars[j].FrontAxle.Follower.WorldPosition.Z + Train.Cars[j].RearAxle.Follower.WorldPosition.Z) - Position.Z; - Function.Stack[s - 1] = Math.Sqrt(x * x + y * y + z * z); + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + double x = 0.5 * (train.Cars[j].FrontAxle.Follower.WorldPosition.X + train.Cars[j].RearAxle.Follower.WorldPosition.X) - position.X; + double y = 0.5 * (train.Cars[j].FrontAxle.Follower.WorldPosition.Y + train.Cars[j].RearAxle.Follower.WorldPosition.Y) - position.Y; + double z = 0.5 * (train.Cars[j].FrontAxle.Follower.WorldPosition.Z + train.Cars[j].RearAxle.Follower.WorldPosition.Z) - position.Z; + function.Stack[s - 1] = Math.Sqrt(x * x + y * y + z * z); } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } 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; + function.Stack[s] = trackPosition > pt0 ? trackPosition - pt0 : trackPosition < pt1 ? trackPosition - pt1 : 0.0; s++; break; case Instructions.TrainTrackDistance: - if (Train != null) { - double t0 = Train.FrontCarTrackPosition; - double t1 = Train.RearCarTrackPosition; - Function.Stack[s] = TrackPosition > t0 ? TrackPosition - t0 : TrackPosition < t1 ? TrackPosition - t1 : 0.0; + if (train != null) { + double t0 = train.FrontCarTrackPosition; + double t1 = train.RearCarTrackPosition; + function.Stack[s] = trackPosition > t0 ? trackPosition - t0 : trackPosition < t1 ? trackPosition - t1 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.CurveRadius: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.CurveRadiusOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = (Train.Cars[j].FrontAxle.Follower.CurveRadius + Train.Cars[j].RearAxle.Follower.CurveRadius) / 2; + function.Stack[s - 1] = (train.Cars[j].FrontAxle.Follower.CurveRadius + train.Cars[j].RearAxle.Follower.CurveRadius) / 2; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.FrontAxleCurveRadius: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.FrontAxleCurveRadiusOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.CurveRadius; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.CurveRadius; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.RearAxleCurveRadius: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.RearAxleCurveRadiusOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].RearAxle.Follower.CurveRadius; + function.Stack[s - 1] = train.Cars[j].RearAxle.Follower.CurveRadius; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.CurveCant: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.CurveCantOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.CurveCant; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.CurveCant; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.Pitch: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.PitchOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.Pitch; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.Pitch; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.Odometer: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.OdometerOfCar: - Function.Stack[s -1] = 0.0; + function.Stack[s -1] = 0.0; break; case Instructions.TrainTrackDistanceToCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - double p = 0.5 * (Train.Cars[j].FrontAxle.Follower.TrackPosition + Train.Cars[j].RearAxle.Follower.TrackPosition); - Function.Stack[s - 1] = TrackPosition - p; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + double p = 0.5 * (train.Cars[j].FrontAxle.Follower.TrackPosition + train.Cars[j].RearAxle.Follower.TrackPosition); + function.Stack[s - 1] = trackPosition - p; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; // door case Instructions.Doors: - if (Train != null) { + if (train != null) { double a = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + for (int j = 0; j < train.Cars.Length; j++) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s] = a; + function.Stack[s] = a; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.DoorsIndex: - if (Train != null) { + if (train != null) { double a = 0.0; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s - 1] = a; + function.Stack[s - 1] = a; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.LeftDoors: - if (Train != null) { + if (train != null) { double a = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == -1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + for (int j = 0; j < train.Cars.Length; j++) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == -1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s] = a; + function.Stack[s] = a; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LeftDoorsIndex: - if (Train != null) { + if (train != null) { double a = 0.0; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == -1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == -1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s - 1] = a; + function.Stack[s - 1] = a; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.RightDoors: - if (Train != null) { + if (train != null) { double a = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == 1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + for (int j = 0; j < train.Cars.Length; j++) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == 1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s] = a; + function.Stack[s] = a; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.RightDoorsIndex: - if (Train != null) { + if (train != null) { double a = 0.0; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == 1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == 1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s - 1] = a; + function.Stack[s - 1] = a; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.LeftDoorsTarget: - if (Train != null) { + if (train != null) { bool q = false; - for (int j = 0; j < Train.Cars.Length; j++) { - if (Train.Cars[j].Doors[0].AnticipatedOpen) { + for (int j = 0; j < train.Cars.Length; j++) { + if (train.Cars[j].Doors[0].AnticipatedOpen) { q = true; break; } } - Function.Stack[s] = q ? 1.0 : 0.0; + function.Stack[s] = q ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LeftDoorsTargetIndex: - if (Train != null) { + if (train != null) { bool q = false; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[0].AnticipatedOpen) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[0].AnticipatedOpen) { q = true; break; } } } - Function.Stack[s - 1] = q ? 1.0 : 0.0; + function.Stack[s - 1] = q ? 1.0 : 0.0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.RightDoorsTarget: - if (Train != null) { + if (train != null) { bool q = false; - for (int j = 0; j < Train.Cars.Length; j++) { - if (Train.Cars[j].Doors[1].AnticipatedOpen) { + for (int j = 0; j < train.Cars.Length; j++) { + if (train.Cars[j].Doors[1].AnticipatedOpen) { q = true; break; } } - Function.Stack[s] = q ? 1.0 : 0.0; + function.Stack[s] = q ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.RightDoorsTargetIndex: - if (Train != null) { + if (train != null) { bool q = false; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[1].AnticipatedOpen) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[1].AnticipatedOpen) { q = true; break; } } } - Function.Stack[s - 1] = q ? 1.0 : 0.0; + function.Stack[s - 1] = q ? 1.0 : 0.0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.PilotLamp: //Not currently supported in viewers - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.PassAlarm: //Not currently supported in viewers - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.StationAdjustAlarm: //Not currently supported in viewers - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.Headlights: - if (Train != null) + if (train != null) { - Function.Stack[s] = Train.SafetySystems.Headlights.CurrentState; + function.Stack[s] = train.SafetySystems.Headlights.CurrentState; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; // handles case Instructions.ReverserNotch: - if (Train != null) { - Function.Stack[s] = (double)Train.Handles.Reverser.Driver; + if (train != null) { + function.Stack[s] = (double)train.Handles.Reverser.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PowerNotch: - if (Train != null) { - Function.Stack[s] = (double)Train.Handles.Power.Driver; + if (train != null) { + function.Stack[s] = train.Handles.Power.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PowerNotches: - if (Train != null) { - Function.Stack[s] = (double)Train.Handles.Power.MaximumNotch; + if (train != null) { + function.Stack[s] = train.Handles.Power.MaximumNotch; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotch: - if (Train != null) { - Function.Stack[s] = (double)Train.Handles.Brake.Driver; + if (train != null) { + function.Stack[s] = train.Handles.Brake.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotches: - if (Train != null) { - if (Train.Handles.Brake is AirBrakeHandle) { - Function.Stack[s] = 2.0; + if (train != null) { + if (train.Handles.Brake is AirBrakeHandle) { + function.Stack[s] = 2.0; } else { - Function.Stack[s] = (double)Train.Handles.Brake.MaximumNotch; + function.Stack[s] = train.Handles.Brake.MaximumNotch; } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotchLinear: - if (Train != null) { - if (Train.Handles.Brake is AirBrakeHandle) { - if (Train.Handles.EmergencyBrake.Driver) { - Function.Stack[s] = 3.0; + if (train != null) { + if (train.Handles.Brake is AirBrakeHandle) { + if (train.Handles.EmergencyBrake.Driver) { + function.Stack[s] = 3.0; } else { - Function.Stack[s] = (double)Train.Handles.Brake.Driver; + function.Stack[s] = train.Handles.Brake.Driver; } - } else if (Train.Handles.HasHoldBrake) { - if (Train.Handles.EmergencyBrake.Driver) { - Function.Stack[s] = (double)Train.Handles.Brake.MaximumNotch + 2.0; - } else if (Train.Handles.Brake.Driver > 0) { - Function.Stack[s] = (double)Train.Handles.Brake.Driver + 1.0; + } else if (train.Handles.HasHoldBrake) { + if (train.Handles.EmergencyBrake.Driver) { + function.Stack[s] = train.Handles.Brake.MaximumNotch + 2.0; + } else if (train.Handles.Brake.Driver > 0) { + function.Stack[s] = train.Handles.Brake.Driver + 1.0; } else { - Function.Stack[s] = Train.Handles.HoldBrake.Driver ? 1.0 : 0.0; + function.Stack[s] = train.Handles.HoldBrake.Driver ? 1.0 : 0.0; } } else { - if (Train.Handles.EmergencyBrake.Driver) { - Function.Stack[s] = (double)Train.Handles.Brake.MaximumNotch + 1.0; + if (train.Handles.EmergencyBrake.Driver) { + function.Stack[s] = train.Handles.Brake.MaximumNotch + 1.0; } else { - Function.Stack[s] = (double)Train.Handles.Brake.Driver; + function.Stack[s] = train.Handles.Brake.Driver; } } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotchesLinear: - if (Train != null) { - if (Train.Handles.Brake is AirBrakeHandle) { - Function.Stack[s] = 3.0; - } else if (Train.Handles.HasHoldBrake) { - Function.Stack[s] = Train.Handles.Brake.MaximumNotch + 2.0; + if (train != null) { + if (train.Handles.Brake is AirBrakeHandle) { + function.Stack[s] = 3.0; + } else if (train.Handles.HasHoldBrake) { + function.Stack[s] = train.Handles.Brake.MaximumNotch + 2.0; } else { - Function.Stack[s] = Train.Handles.Brake.MaximumNotch + 1.0; + function.Stack[s] = train.Handles.Brake.MaximumNotch + 1.0; } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.EmergencyBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.EmergencyBrake.Driver ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.EmergencyBrake.Driver ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } 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; + function.Stack[s] = 0.0; s++; break; case Instructions.HasAirBrake: - if (Train != null) { - Function.Stack[s] = Train.Cars[Train.DriverCar].CarBrake is AutomaticAirBrake ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Cars[train.DriverCar].CarBrake is AutomaticAirBrake ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.HoldBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.HoldBrake.Driver ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.HoldBrake.Driver ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.HasHoldBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.HasHoldBrake ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.HasHoldBrake ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.ConstSpeed: - if (Train != null) { - Function.Stack[s] = Train.Specs.CurrentConstSpeed ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Specs.CurrentConstSpeed ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.HasConstSpeed: - if (Train != null) { - Function.Stack[s] = Train.Specs.HasConstSpeed ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Specs.HasConstSpeed ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; // brake case Instructions.BrakeMainReservoir: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.MainReservoir.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.MainReservoir.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeMainReservoirOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.MainReservoir.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.MainReservoir.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeEqualizingReservoir: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.EqualizingReservoir.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.EqualizingReservoir.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeEqualizingReservoirOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.EqualizingReservoir.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.EqualizingReservoir.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeBrakePipe: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakePipe.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.BrakePipe.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeBrakePipeOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakePipe.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.BrakePipe.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeBrakeCylinder: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakeCylinder.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.BrakeCylinder.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeBrakeCylinderOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakeCylinder.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.BrakeCylinder.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeStraightAirPipe: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.StraightAirPipe.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.StraightAirPipe.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeStraightAirPipeOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.StraightAirPipe.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.StraightAirPipe.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; // safety case Instructions.SafetyPluginAvailable: //Not supported by Route Viewer - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.SafetyPluginState: //Not supported by Route Viewer - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; break; // timetable case Instructions.TimetableVisible: @@ -1033,10 +1033,10 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager { case DisplayedTimetable.Custom: case DisplayedTimetable.Default: - Function.Stack[s] = 1.0; + function.Stack[s] = 1.0; break; case DisplayedTimetable.None: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; break; } s++; break; @@ -1046,7 +1046,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager case Instructions.NextStation: case Instructions.NextStationStop: case Instructions.RouteLimit: - Function.Stack[s] = 0.0; //Unsupported in viewers + function.Stack[s] = 0.0; //Unsupported in viewers s++; break; case Instructions.TerminalStation: int idx = Program.CurrentRoute.Stations.Length; @@ -1058,158 +1058,160 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager break; } } - Function.Stack[s] = idx; + function.Stack[s] = idx; s++; break; case Instructions.DistanceStation: case Instructions.StopsStation: - Function.Stack[s - 1] = 0.0; //Unsupported in viewers + function.Stack[s - 1] = 0.0; //Unsupported in viewers break; // sections case Instructions.SectionAspectNumber: - if (IsPartOfTrain) { - int nextSectionIndex = Train.CurrentSectionIndex + 1; + if (isPartOfTrain) { + int nextSectionIndex = train.CurrentSectionIndex + 1; if (nextSectionIndex >= 0 & nextSectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[nextSectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[nextSectionIndex].Aspects.Length) { - Function.Stack[s] = (double)Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; + function.Stack[s] = Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; } else { - Function.Stack[s] = 0; + function.Stack[s] = 0; } } - } else if (SectionIndex >= 0 & SectionIndex < Program.CurrentRoute.Sections.Length) { - int a = Program.CurrentRoute.Sections[SectionIndex].CurrentAspect; - if (a >= 0 & a < Program.CurrentRoute.Sections[SectionIndex].Aspects.Length) { - Function.Stack[s] = (double)Program.CurrentRoute.Sections[SectionIndex].Aspects[a].Number; + } else if (sectionIndex >= 0 & sectionIndex < Program.CurrentRoute.Sections.Length) { + int a = Program.CurrentRoute.Sections[sectionIndex].CurrentAspect; + if (a >= 0 & a < Program.CurrentRoute.Sections[sectionIndex].Aspects.Length) { + function.Stack[s] = Program.CurrentRoute.Sections[sectionIndex].Aspects[a].Number; } else { - Function.Stack[s] = 0; + function.Stack[s] = 0; } } else { - Function.Stack[s] = 0; + function.Stack[s] = 0; } s++; break; case Instructions.Panel2Timetable: - throw new InvalidOperationException("The instruction " + Function.InstructionSet[i].ToString() + " is for internal use only, and should not be added to objects."); + throw new InvalidOperationException("The instruction " + function.InstructionSet[i].ToString() + " is for internal use only, and should not be added to objects."); case Instructions.TrainCarNumber: - if (!IsPartOfTrain) + if (!isPartOfTrain) { - Function.Stack[s] = -1; + function.Stack[s] = -1; } else { - Function.Stack[s] = CarIndex; + function.Stack[s] = carIndex; } s++; break; case Instructions.WheelSlip: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].FrontAxle.CurrentWheelSlip ? 1 : 0; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].FrontAxle.CurrentWheelSlip ? 1 : 0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.WheelSlipCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.CurrentWheelSlip ? 1 : 0; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].FrontAxle.CurrentWheelSlip ? 1 : 0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.Sanders: { - if (Train != null && Train.Cars[CarIndex].ReAdhesionDevice is Sanders sanders) { - Function.Stack[s] = sanders.Active ? 1 : 0; + if (train != null && train.Cars[carIndex].ReAdhesionDevice is Sanders sanders) { + function.Stack[s] = sanders.Active ? 1 : 0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.SandLevel: { - if (Train != null && Train.Cars[CarIndex].ReAdhesionDevice is Sanders sanders) { - Function.Stack[s] = sanders.SandLevel; + if (train != null && train.Cars[carIndex].ReAdhesionDevice is Sanders sanders) { + function.Stack[s] = sanders.SandLevel; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.SandShots: { - if (Train != null && Train.Cars[CarIndex].ReAdhesionDevice is Sanders sanders) { - Function.Stack[s] = sanders.NumberOfShots; + if (train != null && train.Cars[carIndex].ReAdhesionDevice is Sanders sanders) { + function.Stack[s] = sanders.NumberOfShots; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.DSD: { - if (Train != null && Train.Cars[Train.DriverCar].DSD != null) + if (train != null && train.Cars[train.DriverCar].DSD != null) { - Function.Stack[s] = Train.Cars[Train.DriverCar].DSD.Triggered ? 1 : 0; + function.Stack[s] = train.Cars[train.DriverCar].DSD.Triggered ? 1 : 0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.AmbientTemperature: { - if (Train != null) + if (train != null) { - Function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(Train.Cars[CarIndex].FrontAxle.Follower.WorldPosition.Y + Program.CurrentRoute.Atmosphere.InitialElevation); + function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(train.Cars[carIndex].FrontAxle.Follower.WorldPosition.Y + Program.CurrentRoute.Atmosphere.InitialElevation); } else { - Function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(Position.Y + Program.CurrentRoute.Atmosphere.InitialElevation); + function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(position.Y + Program.CurrentRoute.Atmosphere.InitialElevation); } } s++; break; case Instructions.RainDrop: case Instructions.SnowFlake: // Only shown on the player train, so not helpful here - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; break; case Instructions.WiperPosition: - Function.Stack[s] = 1.0; + function.Stack[s] = 1.0; s++; break; default: - throw new InvalidOperationException("The unknown instruction " + Function.InstructionSet[i].ToString() + " was encountered in ExecuteFunctionScript."); + throw new InvalidOperationException("The unknown instruction " + function.InstructionSet[i].ToString() + " was encountered in ExecuteFunctionScript."); } } - Function.LastResult = Function.Stack[s - 1]; + function.LastResult = function.Stack[s - 1]; } // mathematical functions - private static double Log(double X) { - if (X <= 0.0) { + private static double Log(double X) + { + if (X <= 0.0) + { return 0.0; // ComplexInfinity or NonReal - } else { - return Math.Log(X); } + return Math.Log(X); } - private static double Sqrt(double X) { - if (X < 0.0) { + private static double Sqrt(double X) + { + if (X < 0.0) + { return 0.0; // NonReal - } else { - return Math.Sqrt(X); } + return Math.Sqrt(X); } private static double Tan(double X) { double c = X / Math.PI; double d = c - Math.Floor(c) - 0.5; double e = Math.Floor(X >= 0.0 ? X : -X) * 1.38462643383279E-16; - if (d >= -e & d <= e) { + if (d >= -e & d <= e) + { return 0.0; // ComplexInfinity - } else { - return Math.Tan(X); } + return Math.Tan(X); } } diff --git a/source/RouteViewer/Game/Menu.cs b/source/RouteViewer/Game/Menu.cs index 5169f315c..879dc452a 100644 --- a/source/RouteViewer/Game/Menu.cs +++ b/source/RouteViewer/Game/Menu.cs @@ -243,7 +243,7 @@ public override void ProcessCommand(Translations.Command cmd, double timeElapsed public override bool ProcessMouseMove(int x, int y) { - Program.currentGameWindow.CursorVisible = true; + Program.CurrentGameWindow.CursorVisible = true; if (CurrMenu < 0) { return false; diff --git a/source/RouteViewer/GameR.cs b/source/RouteViewer/GameR.cs index 49e83eacd..b0e0ecdaa 100644 --- a/source/RouteViewer/GameR.cs +++ b/source/RouteViewer/GameR.cs @@ -76,12 +76,12 @@ internal static void Reset(bool resetRenderer = true) { // ================================ - internal static bool ApplyPointOfInterest(int Value, bool Relative) { + internal static bool ApplyPointOfInterest(int newValue, bool newValueIsRelative) { double t = 0.0; int j = -1; - if (Relative) { + if (newValueIsRelative) { // relative - if (Value < 0) { + if (newValue < 0) { // previous poi t = double.NegativeInfinity; for (int i = 0; i < Program.CurrentRoute.PointsOfInterest.Length; i++) { @@ -92,7 +92,7 @@ internal static bool ApplyPointOfInterest(int Value, bool Relative) { } } } - } else if (Value > 0) { + } else if (newValue > 0) { // next poi t = double.PositiveInfinity; for (int i = 0; i < Program.CurrentRoute.PointsOfInterest.Length; i++) { @@ -106,7 +106,7 @@ internal static bool ApplyPointOfInterest(int Value, bool Relative) { } } else { // absolute - j = Value >= 0 & Value < Program.CurrentRoute.PointsOfInterest.Length ? Value : -1; + j = newValue >= 0 & newValue < Program.CurrentRoute.PointsOfInterest.Length ? newValue : -1; } // process poi if (j >= 0) { diff --git a/source/RouteViewer/InterfaceR.cs b/source/RouteViewer/InterfaceR.cs index 4c3a25173..f110f5559 100644 --- a/source/RouteViewer/InterfaceR.cs +++ b/source/RouteViewer/InterfaceR.cs @@ -16,8 +16,8 @@ internal static class Interface { internal static Options CurrentOptions; internal static readonly List LogMessages = new List(); - internal static void AddMessage(MessageType Type, bool FileNotFound, string Text) { - LogMessages.Add(new LogMessage(Type, FileNotFound, Text)); + internal static void AddMessage(MessageType type, bool fileNotFound, string text) { + LogMessages.Add(new LogMessage(type, fileNotFound, text)); } } } diff --git a/source/RouteViewer/LoadingR.cs b/source/RouteViewer/LoadingR.cs index 7c515c178..058860e0c 100644 --- a/source/RouteViewer/LoadingR.cs +++ b/source/RouteViewer/LoadingR.cs @@ -54,9 +54,9 @@ internal static bool Cancel internal static bool JobAvailable; // load - internal static void Load(string RouteFile, Encoding RouteEncoding, byte[] textureBytes) + internal static void Load(string routeFile, Encoding routeEncoding, byte[] textureBytes) { - Program.currentGameWindow.TargetRenderFrequency = 0; + Program.CurrentGameWindow.TargetRenderFrequency = 0; // reset Game.Reset(); Program.Renderer.Loading.InitLoading(Program.FileSystem.GetDataFolder("In-game"), typeof(NewRenderer).Assembly.GetName().Version.ToString(), Interface.CurrentOptions.LoadingLogo, Interface.CurrentOptions.LoadingProgressBar); @@ -68,8 +68,8 @@ internal static void Load(string RouteFile, Encoding RouteEncoding, byte[] textu // members Cancel = false; Complete = false; - CurrentRouteFile = RouteFile; - CurrentRouteEncoding = RouteEncoding; + CurrentRouteFile = routeFile; + CurrentRouteEncoding = routeEncoding; // thread Loading.LoadAsynchronously(CurrentRouteFile, CurrentRouteEncoding); RouteViewer.LoadingScreenLoop(); @@ -77,10 +77,10 @@ internal static void Load(string RouteFile, Encoding RouteEncoding, byte[] textu /// Gets the absolute Railway folder for a given route file /// The absolute on-disk path of the railway folder - internal static string GetRailwayFolder(string RouteFile) { + internal static string GetRailwayFolder(string routeFile) { try { - string Folder = Path.GetDirectoryName(RouteFile); + string Folder = Path.GetDirectoryName(routeFile); while (true) { @@ -109,7 +109,7 @@ internal static string GetRailwayFolder(string RouteFile) { //If the Route, Object and Sound folders exist, but are not in a railway folder..... try { - string Folder = Path.GetDirectoryName(RouteFile); + string Folder = Path.GetDirectoryName(routeFile); if (Folder == null) { // Unlikely to work, but attempt to make the best of it @@ -164,13 +164,13 @@ private static async Task LoadThreaded() } } - internal static void LoadAsynchronously(string RouteFile, Encoding RouteEncoding) + internal static void LoadAsynchronously(string routeFile, Encoding routeEncoding) { // members Cancel = false; Complete = false; - CurrentRouteFile = RouteFile; - CurrentRouteEncoding = RouteEncoding; + CurrentRouteFile = routeFile; + CurrentRouteEncoding = routeEncoding; //Set the route and train folders in the info class // ReSharper disable once UnusedVariable @@ -181,9 +181,9 @@ internal static void LoadAsynchronously(string RouteFile, Encoding RouteEncoding } private static void LoadEverythingThreaded() { - string RailwayFolder = GetRailwayFolder(CurrentRouteFile); - string ObjectFolder = Path.CombineDirectory(RailwayFolder, "Object"); - string SoundFolder = Path.CombineDirectory(RailwayFolder, "Sound"); + string railwayFolder = GetRailwayFolder(CurrentRouteFile); + string objectFolder = Path.CombineDirectory(railwayFolder, "Object"); + string soundFolder = Path.CombineDirectory(railwayFolder, "Sound"); Program.Renderer.Camera.CurrentMode = CameraViewMode.Track; // load route bool loaded = false; @@ -191,10 +191,10 @@ private static void LoadEverythingThreaded() { { if (Program.CurrentHost.Plugins[i].Route != null && Program.CurrentHost.Plugins[i].Route.CanLoadRoute(CurrentRouteFile)) { - object Route = (object)Program.CurrentRoute; //must cast to allow us to use the ref keyword. - if (Program.CurrentHost.Plugins[i].Route.LoadRoute(CurrentRouteFile, CurrentRouteEncoding, null, ObjectFolder, SoundFolder, false, ref Route)) + object currentRoute = (object)Program.CurrentRoute; //must cast to allow us to use the ref keyword. + if (Program.CurrentHost.Plugins[i].Route.LoadRoute(CurrentRouteFile, CurrentRouteEncoding, null, objectFolder, soundFolder, false, ref currentRoute)) { - Program.CurrentRoute = (CurrentRoute) Route; + Program.CurrentRoute = (CurrentRoute) currentRoute; Program.CurrentRoute.UpdateLighting(); loaded = true; break; @@ -224,10 +224,10 @@ private static void LoadEverythingThreaded() { Program.CurrentRoute.UpdateAllSections(); // starting track position System.Threading.Thread.Sleep(1); if (Cancel) return; - double FirstStationPosition = 0.0; + double firstStationPosition = 0.0; for (int i = 0; i < Program.CurrentRoute.Stations.Length; i++) { if (Program.CurrentRoute.Stations[i].Stops.Length != 0) { - FirstStationPosition = Program.CurrentRoute.Stations[i].Stops[Program.CurrentRoute.Stations[i].Stops.Length - 1].TrackPosition; + firstStationPosition = Program.CurrentRoute.Stations[i].Stops[Program.CurrentRoute.Stations[i].Stops.Length - 1].TrackPosition; if (Program.CurrentRoute.Stations[i].ArrivalTime < 0.0) { if (Program.CurrentRoute.Stations[i].DepartureTime < 0.0) { Game.SecondsSinceMidnight = 0.0; @@ -242,8 +242,8 @@ private static void LoadEverythingThreaded() { } // initialize camera Program.Renderer.CameraTrackFollower.UpdateAbsolute(-1.0, true, false); - Program.Renderer.CameraTrackFollower.UpdateAbsolute(FirstStationPosition, true, false); - Program.Renderer.Camera.Alignment = new CameraAlignment(new Vector3(0.0, 2.5, 0.0), 0.0, 0.0, 0.0, FirstStationPosition, 1.0); + Program.Renderer.CameraTrackFollower.UpdateAbsolute(firstStationPosition, true, false); + Program.Renderer.Camera.Alignment = new CameraAlignment(new Vector3(0.0, 2.5, 0.0), 0.0, 0.0, 0.0, firstStationPosition, 1.0); World.UpdateAbsoluteCamera(0.0); Complete = true; } diff --git a/source/RouteViewer/NewRendererR.cs b/source/RouteViewer/NewRendererR.cs index 64f8b02c1..b47dda0e2 100644 --- a/source/RouteViewer/NewRendererR.cs +++ b/source/RouteViewer/NewRendererR.cs @@ -17,7 +17,6 @@ using OpenBveApi.Routes; using OpenBveApi.Runtime; using OpenBveApi.Textures; -using OpenTK; using OpenTK.Graphics.OpenGL; using RouteManager2.Events; using RouteManager2.Tracks; @@ -56,21 +55,21 @@ public override void Initialize() { base.Initialize(); - string Folder = Path.CombineDirectory(Program.FileSystem.GetDataFolder(), "RouteViewer"); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "background.png"), out BackgroundChangeTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "brightness.png"), out BrightnessChangeTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "transponder.png"), out TransponderTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "section.png"), out SectionTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "limit.png"), out LimitTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "station_start.png"), out StationStartTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "station_end.png"), out StationEndTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "stop.png"), out StopTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "buffer.png"), out BufferTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "sound.png"), out SoundTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "switchsound.png"), out PointSoundTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "runsound.png"), out RunSoundTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "lighting.png"), out LightingEventTexture); - TextureManager.RegisterTexture(Path.CombineFile(Folder, "weather.png"), out WeatherEventTexture); + string dataFolder = Path.CombineDirectory(Program.FileSystem.GetDataFolder(), "RouteViewer"); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "background.png"), out BackgroundChangeTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "brightness.png"), out BrightnessChangeTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "transponder.png"), out TransponderTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "section.png"), out SectionTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "limit.png"), out LimitTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "station_start.png"), out StationStartTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "station_end.png"), out StationEndTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "stop.png"), out StopTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "buffer.png"), out BufferTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "sound.png"), out SoundTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "switchsound.png"), out PointSoundTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "runsound.png"), out RunSoundTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "lighting.png"), out LightingEventTexture); + TextureManager.RegisterTexture(Path.CombineFile(dataFolder, "weather.png"), out WeatherEventTexture); } // render scene @@ -799,35 +798,35 @@ private void RenderOverlays(double timeElapsed) PopMatrix(MatrixMode.Modelview); } - private static string GetTime(double Time) + private static string GetTime(double currentTime) { - int h = (int)Math.Floor(Time / 3600.0); - Time -= h * 3600.0; - int m = (int)Math.Floor(Time / 60.0); - Time -= m * 60.0; - int s = (int)Math.Floor(Time); + int h = (int)Math.Floor(currentTime / 3600.0); + currentTime -= h * 3600.0; + int m = (int)Math.Floor(currentTime / 60.0); + currentTime -= m * 60.0; + int s = (int)Math.Floor(currentTime); return $"{h:00}:{m:00}:{s:00}"; } // get length string - private static string GetLengthString(double Value) + private static string GetLengthString(double lengthValue) { CultureInfo culture = CultureInfo.InvariantCulture; if (Program.CurrentRoute.UnitOfLength.Length == 1 && Program.CurrentRoute.UnitOfLength[0] == 1.0) { - return Value.ToString("0.00", culture); + return lengthValue.ToString("0.00", culture); } double[] values = new double[Program.CurrentRoute.UnitOfLength.Length]; for (int i = 0; i < Program.CurrentRoute.UnitOfLength.Length - 1; i++) { - values[i] = Math.Floor(Value / Program.CurrentRoute.UnitOfLength[i]); - Value -= values[i] * Program.CurrentRoute.UnitOfLength[i]; + values[i] = Math.Floor(lengthValue / Program.CurrentRoute.UnitOfLength[i]); + lengthValue -= values[i] * Program.CurrentRoute.UnitOfLength[i]; } - values[Program.CurrentRoute.UnitOfLength.Length - 1] = Value / Program.CurrentRoute.UnitOfLength[Program.CurrentRoute.UnitOfLength.Length - 1]; + values[Program.CurrentRoute.UnitOfLength.Length - 1] = lengthValue / Program.CurrentRoute.UnitOfLength[Program.CurrentRoute.UnitOfLength.Length - 1]; string s = string.Empty; for (int i = 0; i < values.Length - 1; i++) @@ -839,7 +838,7 @@ private static string GetLengthString(double Value) return s; } - public NewRenderer(HostInterface CurrentHost, BaseOptions CurrentOptions, FileSystem FileSystem) : base(CurrentHost, CurrentOptions, FileSystem) + public NewRenderer(HostInterface currentHost, BaseOptions currentOptions, FileSystem fileSystem) : base(currentHost, currentOptions, fileSystem) { Screen.Width = Interface.CurrentOptions.WindowWidth; Screen.Height = Interface.CurrentOptions.WindowHeight; diff --git a/source/RouteViewer/ObjectManager.cs b/source/RouteViewer/ObjectManager.cs index fa9226fa6..e7688c1b0 100644 --- a/source/RouteViewer/ObjectManager.cs +++ b/source/RouteViewer/ObjectManager.cs @@ -8,18 +8,18 @@ internal static class ObjectManager { internal static WorldObject[] AnimatedWorldObjects = new WorldObject[4]; internal static int AnimatedWorldObjectsUsed = 0; - internal static void UpdateAnimatedWorldObjects(double TimeElapsed, bool ForceUpdate) { + internal static void UpdateAnimatedWorldObjects(double timeElapsed, bool forceUpdate) { for (int i = 0; i < AnimatedWorldObjectsUsed; i++) { AbstractTrain train = null; Vector3 cameraPos = Program.Renderer.Camera.Alignment.Position; cameraPos.Z += Program.Renderer.CameraTrackFollower.TrackPosition; bool visible = AnimatedWorldObjects[i].IsVisible(cameraPos, Program.CurrentRoute.CurrentBackground.BackgroundImageDistance, Program.Renderer.Camera.ExtraViewingDistance); - if (visible | ForceUpdate) + if (visible | forceUpdate) { train = Program.CurrentHost.ClosestTrain(AnimatedWorldObjects[i].RelativeTrackPosition); } - AnimatedWorldObjects[i].Update(train, TimeElapsed, ForceUpdate, visible); + AnimatedWorldObjects[i].Update(train, timeElapsed, forceUpdate, visible); } } } diff --git a/source/RouteViewer/ProgramR.cs b/source/RouteViewer/ProgramR.cs index 61dcac912..ff0af4b6e 100644 --- a/source/RouteViewer/ProgramR.cs +++ b/source/RouteViewer/ProgramR.cs @@ -16,8 +16,6 @@ using OpenTK.Input; using RouteManager2; using System; -using System.Drawing; -using System.Drawing.Imaging; using System.Globalization; using System.Linq; using System.Runtime; @@ -43,15 +41,15 @@ internal static class Program { internal static bool JumpToPositionEnabled = false; internal static string JumpToPositionValue = ""; internal static double MinimumJumpToPositionValue = 0; - internal static bool processCommandLineArgs; + internal static bool ProcessCommandLineArgs; // keys private static bool ShiftPressed = false; private static bool ControlPressed = false; private static bool AltPressed = false; - internal static GameWindow currentGameWindow; - internal static GraphicsMode currentGraphicsMode; + internal static GameWindow CurrentGameWindow; + internal static GraphicsMode CurrentGraphicsMode; // mouse private static int MouseButton; @@ -67,7 +65,7 @@ internal static class Program { internal static TrainManager TrainManager; - internal static formRailPaths pathForm; + internal static formRailPaths PathForm; [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern bool SetProcessDPIAware(); @@ -114,7 +112,7 @@ internal static void Main(string[] args) if (string.IsNullOrEmpty(CurrentRouteFile)) { CurrentRouteFile = args[i]; - processCommandLineArgs = true; + ProcessCommandLineArgs = true; } } } @@ -143,10 +141,10 @@ internal static void Main(string[] args) if (objectsToLoad.Length != 0) { - string File = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe"); - if (System.IO.File.Exists(File)) + string objectViewerExecutable = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe"); + if (System.IO.File.Exists(objectViewerExecutable)) { - System.Diagnostics.Process.Start(File, objectsToLoad); + System.Diagnostics.Process.Start(objectViewerExecutable, objectsToLoad); if (string.IsNullOrEmpty(CurrentRouteFile)) { //We only supplied objects, so launch Object Viewer instead @@ -169,7 +167,7 @@ internal static void Main(string[] args) Interface.CurrentOptions.ObjectOptimizationBasicThreshold = 1000; Interface.CurrentOptions.ObjectOptimizationFullThreshold = 250; // application - currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel); + CurrentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel); if (Renderer.Screen.Width == 0 || Renderer.Screen.Height == 0) { //Duff values saved, so reset to something sensible else we crash @@ -177,13 +175,13 @@ internal static void Main(string[] args) Renderer.Screen.Height = 768; } Renderer.CameraTrackFollower = new TrackFollower(Program.CurrentHost); - currentGameWindow = new RouteViewer(Renderer.Screen.Width, Renderer.Screen.Height, currentGraphicsMode, "Route Viewer", GameWindowFlags.Default); - currentGameWindow.Visible = true; - currentGameWindow.TargetUpdateFrequency = 0; - currentGameWindow.TargetRenderFrequency = 0; - currentGameWindow.Title = "Route Viewer"; - processCommandLineArgs = true; - currentGameWindow.Run(); + CurrentGameWindow = new RouteViewer(Renderer.Screen.Width, Renderer.Screen.Height, CurrentGraphicsMode, "Route Viewer", GameWindowFlags.Default); + CurrentGameWindow.Visible = true; + CurrentGameWindow.TargetUpdateFrequency = 0; + CurrentGameWindow.TargetRenderFrequency = 0; + CurrentGameWindow.Title = "Route Viewer"; + ProcessCommandLineArgs = true; + CurrentGameWindow.Run(); //Unload Sounds.DeInitialize(); } @@ -248,12 +246,12 @@ internal static bool LoadRoute(byte[] textureBytes = null) { } // jump to station - private static void JumpToStation(int Direction) { + private static void JumpToStation(int directionOfTravel) { if (Program.CurrentRoute.Tracks[0].Direction == TrackDirection.Reverse) { - Direction = -Direction; + directionOfTravel = -directionOfTravel; } - if (Direction < 0) { + if (directionOfTravel < 0) { for (int i = CurrentRoute.Stations.Length - 1; i >= 0; i--) { if (CurrentRoute.Stations[i].Stops.Length != 0) { double p = CurrentRoute.Stations[i].Stops[CurrentRoute.Stations[i].Stops.Length - 1].TrackPosition; @@ -265,7 +263,7 @@ private static void JumpToStation(int Direction) { } } } - } else if (Direction > 0) { + } else if (directionOfTravel > 0) { for (int i = 0; i < CurrentRoute.Stations.Length; i++) { if (CurrentRoute.Stations[i].Stops.Length != 0) { double p = CurrentRoute.Stations[i].Stops[CurrentRoute.Stations[i].Stops.Length - 1].TrackPosition; @@ -288,7 +286,7 @@ internal static void UpdateGraphicsSettings() { Program.CurrentlyLoading = true; Renderer.RenderScene(0.0); - Program.currentGameWindow.SwapBuffers(); + Program.CurrentGameWindow.SwapBuffers(); CameraAlignment a = Renderer.Camera.Alignment; if (Program.LoadRoute()) { @@ -351,7 +349,7 @@ internal static void MouseEvent(object sender, MouseButtonEventArgs e) { MouseButton = e.Mouse.RightButton == ButtonState.Pressed ? 3 : 0; } - previousMouseState = Mouse.GetState(); + PreviousMouseState = Mouse.GetState(); if (MouseButton == 0) { Renderer.Camera.AlignmentDirection.Yaw = 0.0; @@ -364,15 +362,15 @@ internal static void MouseEvent(object sender, MouseButtonEventArgs e) } - internal static MouseState currentMouseState; - internal static MouseState previousMouseState; + internal static MouseState CurrentMouseState; + internal static MouseState PreviousMouseState; internal static void MouseMovement() { if (MouseButton == 0 || Program.Renderer.CurrentInterface != InterfaceType.Normal) return; - currentMouseState = Mouse.GetState(); - if (currentMouseState != previousMouseState) + CurrentMouseState = Mouse.GetState(); + if (CurrentMouseState != PreviousMouseState) { Renderer.Camera.AlignmentDirection.Yaw = 0.0; Renderer.Camera.AlignmentDirection.Pitch = 0.0; @@ -380,13 +378,13 @@ internal static void MouseMovement() Renderer.Camera.AlignmentDirection.Position.Y = 0.0; if (MouseButton == 1) { - Renderer.Camera.AlignmentDirection.Yaw = 0.025 * (previousMouseState.X - currentMouseState.X); - Renderer.Camera.AlignmentDirection.Pitch = 0.025 * (previousMouseState.Y - currentMouseState.Y); + Renderer.Camera.AlignmentDirection.Yaw = 0.025 * (PreviousMouseState.X - CurrentMouseState.X); + Renderer.Camera.AlignmentDirection.Pitch = 0.025 * (PreviousMouseState.Y - CurrentMouseState.Y); } else if (MouseButton == 2) { - Renderer.Camera.AlignmentDirection.Position.X = 0.1 * (previousMouseState.X - currentMouseState.X); - Renderer.Camera.AlignmentDirection.Position.Y = 0.1 * (previousMouseState.Y - currentMouseState.Y); + Renderer.Camera.AlignmentDirection.Position.X = 0.1 * (PreviousMouseState.X - CurrentMouseState.X); + Renderer.Camera.AlignmentDirection.Position.Y = 0.1 * (PreviousMouseState.Y - CurrentMouseState.Y); } } @@ -406,7 +404,7 @@ internal static void FileDrop(object sender, FileDropEventArgs e) UpdateCaption(); } - internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) + internal static void KeyDownEvent(object sender, KeyboardKeyEventArgs e) { double speedModified = (ShiftPressed ? 2.0 : 1.0) * (ControlPressed ? 4.0 : 1.0) * (AltPressed ? 8.0 : 1.0); switch (e.Key) @@ -436,7 +434,7 @@ internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) if (!Interface.CurrentOptions.LoadingBackground) { Renderer.RenderScene(0.0); - currentGameWindow.SwapBuffers(); + CurrentGameWindow.SwapBuffers(); textureBytes = new byte[Renderer.Screen.Width * Renderer.Screen.Height * 4]; GL.ReadPixels(0, 0, Renderer.Screen.Width, Renderer.Screen.Height, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, textureBytes); // GL.ReadPixels is reversed for what it wants as a texture, so we've got to flip it @@ -486,14 +484,14 @@ internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) { break; } - OpenFileDialog Dialog = new OpenFileDialog(); - Dialog.CheckFileExists = true; - Dialog.Filter = @"All Supported Routes|*.csv;*.rw;*.dat;*.txt|CSV/RW files|*.csv;*.rw|Mechanik Routes|*.dat|BVE5 Routes|*.txt|All files|*"; - if (Dialog.ShowDialog() == DialogResult.OK) + OpenFileDialog dialog = new OpenFileDialog(); + dialog.CheckFileExists = true; + dialog.Filter = @"All Supported Routes|*.csv;*.rw;*.dat;*.txt|CSV/RW files|*.csv;*.rw|Mechanik Routes|*.dat|BVE5 Routes|*.txt|All files|*"; + if (dialog.ShowDialog() == DialogResult.OK) { Application.DoEvents(); CurrentlyLoading = true; - CurrentRouteFile = Dialog.FileName; + CurrentRouteFile = dialog.FileName; UpdateCaption(); bool canLoad = false; for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) @@ -527,10 +525,10 @@ internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) if (isObject) { // oops, that's actually an object- Let's show Object Viewer - string File = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe"); - if (System.IO.File.Exists(File)) + string objectViewerExecutable = System.IO.Path.Combine(Application.StartupPath, "ObjectViewer.exe"); + if (System.IO.File.Exists(objectViewerExecutable)) { - System.Diagnostics.Process.Start(File, CurrentRouteFile); + System.Diagnostics.Process.Start(objectViewerExecutable, CurrentRouteFile); } } else @@ -556,7 +554,7 @@ internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) Application.DoEvents(); } } - Dialog.Dispose(); + dialog.Dispose(); break; case Key.F8: if (Program.CurrentHost.Platform == HostPlatform.AppleOSX && IntPtr.Size != 4) @@ -795,7 +793,7 @@ internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) { if (Program.CurrentHost.Platform == HostPlatform.AppleOSX && IntPtr.Size != 4) { - Program.currentGameWindow.TargetRenderFrequency = 0; + Program.CurrentGameWindow.TargetRenderFrequency = 0; Program.Renderer.CurrentInterface = InterfaceType.Menu; Game.Menu.PushMenu(MenuType.GameStart); } @@ -812,22 +810,22 @@ internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) } if (CurrentRouteFile != null && CurrentlyLoading == false) { - if (pathForm == null || pathForm.IsDisposed) + if (PathForm == null || PathForm.IsDisposed) { - pathForm = new formRailPaths(); + PathForm = new formRailPaths(); } // Must be shown as a dialog box on Linux for paint events to work.... if (CurrentHost.Platform == HostPlatform.MicrosoftWindows) { - if (!pathForm.Visible) + if (!PathForm.Visible) { - pathForm.Show(); + PathForm.Show(); } } else { - pathForm.ShowDialog(); + PathForm.ShowDialog(); Application.DoEvents(); } @@ -838,7 +836,7 @@ internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) } } - internal static void keyUpEvent(object sender, KeyboardKeyEventArgs e) + internal static void KeyUpEvent(object sender, KeyboardKeyEventArgs e) { switch (e.Key) { @@ -893,10 +891,10 @@ internal static void keyUpEvent(object sender, KeyboardKeyEventArgs e) internal static void UpdateCaption() { if (CurrentRouteFile != null) { - currentGameWindow.Title = Program.CurrentlyLoading ? @"Loading: " + System.IO.Path.GetFileName(CurrentRouteFile) + " - " + Application.ProductName : System.IO.Path.GetFileName(CurrentRouteFile) + " - " + Application.ProductName; + CurrentGameWindow.Title = Program.CurrentlyLoading ? @"Loading: " + System.IO.Path.GetFileName(CurrentRouteFile) + " - " + Application.ProductName : System.IO.Path.GetFileName(CurrentRouteFile) + " - " + Application.ProductName; } else { - currentGameWindow.Title = Application.ProductName; + CurrentGameWindow.Title = Application.ProductName; } } } diff --git a/source/RouteViewer/System/Gamewindow.cs b/source/RouteViewer/System/Gamewindow.cs index 5e4f5c8fc..d9ba8174c 100644 --- a/source/RouteViewer/System/Gamewindow.cs +++ b/source/RouteViewer/System/Gamewindow.cs @@ -89,8 +89,8 @@ protected override void OnResize(EventArgs e) protected override void OnLoad(EventArgs e) { - KeyDown += Program.keyDownEvent; - KeyUp += Program.keyUpEvent; + KeyDown += Program.KeyDownEvent; + KeyUp += Program.KeyUpEvent; MouseDown += Program.MouseEvent; MouseUp += Program.MouseEvent; FileDrop += Program.FileDrop; @@ -106,9 +106,9 @@ protected override void OnLoad(EventArgs e) Program.Renderer.Lighting.Initialize(); Program.Sounds.Initialize(SoundRange.Low); Program.Renderer.UpdateViewport(); - if (Program.processCommandLineArgs) + if (Program.ProcessCommandLineArgs) { - Program.processCommandLineArgs = false; + Program.ProcessCommandLineArgs = false; Program.UpdateCaption(); Program.LoadRoute(); Program.UpdateCaption(); @@ -145,8 +145,8 @@ public static void LoadingScreenLoop() while (!Loading.Complete && !Loading.Cancel) { CPreciseTimer.GetElapsedTime(); - Program.currentGameWindow.ProcessEvents(); - if (Program.currentGameWindow.IsExiting) + Program.CurrentGameWindow.ProcessEvents(); + if (Program.CurrentGameWindow.IsExiting) Loading.Cancel = true; double routeProgress = 1.0; for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) @@ -157,7 +157,7 @@ public static void LoadingScreenLoop() } } Program.Renderer.Loading.DrawLoadingScreen(Program.Renderer.Fonts.SmallFont, routeProgress); - Program.currentGameWindow.SwapBuffers(); + Program.CurrentGameWindow.SwapBuffers(); if (Loading.JobAvailable) { diff --git a/source/RouteViewer/WorldR.cs b/source/RouteViewer/WorldR.cs index 0f1f08cbb..a98968ed4 100644 --- a/source/RouteViewer/WorldR.cs +++ b/source/RouteViewer/WorldR.cs @@ -11,22 +11,22 @@ namespace RouteViewer { public static class World { // update absolute camera - internal static void UpdateAbsoluteCamera(double TimeElapsed) { + internal static void UpdateAbsoluteCamera(double timeElapsed) { // zoom double zm = Program.Renderer.Camera.Alignment.Zoom; - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Zoom, Program.Renderer.Camera.AlignmentDirection.Zoom, ref Program.Renderer.Camera.AlignmentSpeed.Zoom, TimeElapsed, true); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Zoom, Program.Renderer.Camera.AlignmentDirection.Zoom, ref Program.Renderer.Camera.AlignmentSpeed.Zoom, timeElapsed, true); if (zm != Program.Renderer.Camera.Alignment.Zoom) { Program.Renderer.Camera.ApplyZoom(); } // current alignment - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.X, Program.Renderer.Camera.AlignmentDirection.Position.X, ref Program.Renderer.Camera.AlignmentSpeed.Position.X, TimeElapsed); - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.Y, Program.Renderer.Camera.AlignmentDirection.Position.Y, ref Program.Renderer.Camera.AlignmentSpeed.Position.Y, TimeElapsed); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.X, Program.Renderer.Camera.AlignmentDirection.Position.X, ref Program.Renderer.Camera.AlignmentSpeed.Position.X, timeElapsed); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.Y, Program.Renderer.Camera.AlignmentDirection.Position.Y, ref Program.Renderer.Camera.AlignmentSpeed.Position.Y, timeElapsed); bool q = Program.Renderer.Camera.AlignmentSpeed.Yaw != 0.0 | Program.Renderer.Camera.AlignmentSpeed.Pitch != 0.0 | Program.Renderer.Camera.AlignmentSpeed.Roll != 0.0; - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Yaw, Program.Renderer.Camera.AlignmentDirection.Yaw, ref Program.Renderer.Camera.AlignmentSpeed.Yaw, TimeElapsed); - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Pitch, Program.Renderer.Camera.AlignmentDirection.Pitch, ref Program.Renderer.Camera.AlignmentSpeed.Pitch, TimeElapsed); - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Roll, Program.Renderer.Camera.AlignmentDirection.Roll, ref Program.Renderer.Camera.AlignmentSpeed.Roll, TimeElapsed); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Yaw, Program.Renderer.Camera.AlignmentDirection.Yaw, ref Program.Renderer.Camera.AlignmentSpeed.Yaw, timeElapsed); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Pitch, Program.Renderer.Camera.AlignmentDirection.Pitch, ref Program.Renderer.Camera.AlignmentSpeed.Pitch, timeElapsed); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Roll, Program.Renderer.Camera.AlignmentDirection.Roll, ref Program.Renderer.Camera.AlignmentSpeed.Roll, timeElapsed); double tr = Program.Renderer.Camera.Alignment.TrackPosition; - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.TrackPosition, Program.Renderer.Camera.AlignmentDirection.TrackPosition, ref Program.Renderer.Camera.AlignmentSpeed.TrackPosition, TimeElapsed); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.TrackPosition, Program.Renderer.Camera.AlignmentDirection.TrackPosition, ref Program.Renderer.Camera.AlignmentSpeed.TrackPosition, timeElapsed); if (tr != Program.Renderer.Camera.Alignment.TrackPosition) { Program.Renderer.CameraTrackFollower.UpdateAbsolute(Program.Renderer.Camera.Alignment.TrackPosition, true, false); q = true; diff --git a/source/RouteViewer/formOptions.cs b/source/RouteViewer/formOptions.cs index 3450c6338..18aa0340a 100644 --- a/source/RouteViewer/formOptions.cs +++ b/source/RouteViewer/formOptions.cs @@ -83,7 +83,7 @@ private void button1_Click(object sender, EventArgs e) Interface.CurrentOptions.AntiAliasingLevel = (int)AntialiasingLevel.Value; if (Interface.CurrentOptions.AntiAliasingLevel != previousAntialasingLevel) { - Program.currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel); + Program.CurrentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel); GraphicsModeChanged = true; } //Transparency quality @@ -102,12 +102,12 @@ private void button1_Click(object sender, EventArgs e) if (width.Value >= 300) { Program.Renderer.Screen.Width = (int) width.Value; - Program.currentGameWindow.Width = (int)width.Value; + Program.CurrentGameWindow.Width = (int)width.Value; } if (height.Value >= 300) { Program.Renderer.Screen.Height = (int) height.Value; - Program.currentGameWindow.Height = (int)height.Value; + Program.CurrentGameWindow.Height = (int)height.Value; } Program.Renderer.UpdateViewport(); } diff --git a/source/RouteViewer/formRailPaths.cs b/source/RouteViewer/formRailPaths.cs index e3cea91c7..6d2b8e583 100644 --- a/source/RouteViewer/formRailPaths.cs +++ b/source/RouteViewer/formRailPaths.cs @@ -60,7 +60,7 @@ private void buttonClose_Click(object sender, EventArgs e) Program.Renderer.trackColors[(int)dataGridViewPaths.Rows[i].Cells[keyColumn].Value].Display = (bool)dataGridViewPaths.Rows[i].Cells[4].Value; } } - Program.pathForm = null; + Program.PathForm = null; this.Close(); } diff --git a/source/SoundManager/Sounds.CarSound.cs b/source/SoundManager/Sounds.CarSound.cs index 2a2657318..12fa2f00c 100644 --- a/source/SoundManager/Sounds.CarSound.cs +++ b/source/SoundManager/Sounds.CarSound.cs @@ -59,22 +59,22 @@ public CarSound(HostInterface currentHost, string soundFile, double radius, Vect /// Creates a new car sound /// The API handle to the sound buffer - /// The position that the sound is emitted from within the car + /// The position that the sound is emitted from within the car /// The new car sound - public CarSound(SoundHandle handle, Vector3 Position) + public CarSound(SoundHandle handle, Vector3 position) { this.Buffer = handle as SoundBuffer; - this.Position = Position; + this.Position = position; this.Source = null; } /// Creates a new car sound /// The sound buffer - /// The position that the sound is emitted from within the car + /// The position that the sound is emitted from within the car /// The new car sound - public CarSound(SoundBuffer buffer, Vector3 Position) + public CarSound(SoundBuffer buffer, Vector3 position) { - this.Position = Position; + this.Position = position; this.Source = null; this.Buffer = buffer; } @@ -93,19 +93,19 @@ public CarSound Clone() } /// Plays the sound at the original pitch and volume - /// The parent car + /// The parent car /// Whether the sound is to be played looped - public void Play(AbstractCar Car, bool looped) + public void Play(AbstractCar parentCar, bool looped) { - Play(1.0, 1.0, Car, looped); + Play(1.0, 1.0, parentCar, looped); } /// Plays the sound at the specified pitch and volume /// The pitch /// The volume - /// The parent car + /// The parent car /// Whether the sound is to be played looped - public void Play(double pitch, double volume, AbstractCar Car, bool looped) + public void Play(double pitch, double volume, AbstractCar parentCar, bool looped) { if (looped && IsPaused) { @@ -126,7 +126,7 @@ public void Play(double pitch, double volume, AbstractCar Car, bool looped) { Array.Resize(ref SoundsBase.Sources, SoundsBase.Sources.Length << 1); } - SoundsBase.Sources[SoundsBase.SourceCount] = new SoundSource(Buffer, Buffer.Radius, pitch, volume, Position, Car, looped); + SoundsBase.Sources[SoundsBase.SourceCount] = new SoundSource(Buffer, Buffer.Radius, pitch, volume, Position, parentCar, looped); this.Source = SoundsBase.Sources[SoundsBase.SourceCount]; SoundsBase.SourceCount++; } diff --git a/source/SoundManager/Sounds.cs b/source/SoundManager/Sounds.cs index 6b4a304b7..d4457ec99 100644 --- a/source/SoundManager/Sounds.cs +++ b/source/SoundManager/Sounds.cs @@ -66,7 +66,7 @@ public abstract partial class SoundsBase /// Whether sound events are currently suppressed public static bool SuppressSoundEvents = false; - protected internal int systemMaxSounds = int.MaxValue; + protected internal int SystemMaxSounds = int.MaxValue; // --- linear distance clamp model --- /// The factor by which the inner radius is multiplied to give the outer radius. @@ -145,7 +145,7 @@ public void Initialize(SoundRange range) * Further note that the current version of OpenAL Soft (1.20.0 at the time of writing) does not like OpenTK * The version in use is 1.17.0 found here: https://openal-soft.org/openal-binaries/ */ - systemMaxSounds = 16; + SystemMaxSounds = 16; } try { @@ -293,18 +293,18 @@ public SoundBuffer RegisterBuffer(Sound data, double radius) } /// Attempts to load a new sound buffer - /// The on-disk path to the sound + /// The on-disk path to the sound /// The radius of the sound /// The new sound buffer OR null if the call does not succeed - public SoundBuffer TryToLoad(string FileName, double radius) + public SoundBuffer TryToLoad(string fileName, double radius) { - if (FileName != null) + if (fileName != null) { - if (File.Exists(FileName)) + if (File.Exists(fileName)) { try { - return RegisterBuffer(FileName, radius); + return RegisterBuffer(fileName, radius); } catch { @@ -522,13 +522,13 @@ public virtual void StopAllSounds(object train) // --- tests --- /// Checks whether the specified sound is playing or supposed to be playing. - /// The sound source, or a null reference. + /// The sound source, or a null reference. /// Whether the sound is playing or supposed to be playing. - public bool IsPlaying(object Source) + public bool IsPlaying(object source) { - if (Source is SoundSource source) + if (source is SoundSource soundSource) { - if (source.State == SoundSourceState.PlayPending | source.State == SoundSourceState.Playing) + if (soundSource.State == SoundSourceState.PlayPending | soundSource.State == SoundSourceState.Playing) { return true; } From 197fc4707013b17b3272a698c7ffa54e3443e07c Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Mon, 11 Nov 2024 17:25:06 +0000 Subject: [PATCH 3/7] Change: Enforce lowerCamelCase for parameter names (P3) --- source/ObjectViewer/FunctionScripts.cs | 4 +- .../AnimatedObjects/FunctionScripts.cs | 4 +- source/OpenBVE/System/Scripting.cs | 4 +- .../Plugins/Route.Bve5/Structures/Section.cs | 2 +- .../Route.CsvRw/Structures/Signals/Section.cs | 2 +- source/RouteManager2/CurrentRoute.cs | 98 +++++++++---------- source/RouteManager2/Events/Transponder.cs | 2 +- .../RouteManager2/Illustrations/RouteMap.cs | 2 - .../MessageTypes/MarkerImage.cs | 6 +- .../MessageManager/MessageTypes/MarkerText.cs | 6 +- .../MessageTypes/TextureMessage.cs | 4 +- .../SignalManager/SafetySystems.cs | 2 - source/RouteManager2/SignalManager/Section.cs | 26 ++--- .../SignalManager/SectionAspect.cs | 11 +-- .../SignalManager/SectionTypes.cs | 1 - .../SignalObject.Compatability.cs | 28 +++--- .../SignalManager/SignalObject.cs | 2 +- source/RouteManager2/Stations/RouteStation.cs | 12 +-- source/RouteViewer/Audio/Sounds.Update.cs | 15 ++- source/RouteViewer/Game/Menu.SingleMenu.cs | 9 +- source/RouteViewer/Game/Menu.cs | 34 +++---- source/RouteViewer/System/Gamewindow.cs | 10 +- source/RouteViewer/System/Host.cs | 72 +++++++------- 23 files changed, 173 insertions(+), 183 deletions(-) diff --git a/source/ObjectViewer/FunctionScripts.cs b/source/ObjectViewer/FunctionScripts.cs index 1b7bed6e4..c6ffdd127 100644 --- a/source/ObjectViewer/FunctionScripts.cs +++ b/source/ObjectViewer/FunctionScripts.cs @@ -1094,7 +1094,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr if (nextSectionIndex >= 0 & nextSectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[nextSectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[nextSectionIndex].Aspects.Length) { - Function.Stack[s] = (double)Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; + Function.Stack[s] = (double)Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].AspectNumber; } else { Function.Stack[s] = 0; } @@ -1102,7 +1102,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr } else if (SectionIndex >= 0 & SectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[SectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[SectionIndex].Aspects.Length) { - Function.Stack[s] = (double)Program.CurrentRoute.Sections[SectionIndex].Aspects[a].Number; + Function.Stack[s] = (double)Program.CurrentRoute.Sections[SectionIndex].Aspects[a].AspectNumber; } else { Function.Stack[s] = 0; } diff --git a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs index f3aca3f2c..ac51c9295 100644 --- a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs +++ b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs @@ -1452,7 +1452,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr if (nextSectionIndex >= 0 & nextSectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[nextSectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[nextSectionIndex].Aspects.Length) { - Function.Stack[s] = Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; + Function.Stack[s] = Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].AspectNumber; } else { Function.Stack[s] = 0; } @@ -1460,7 +1460,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr } else if (SectionIndex >= 0 & SectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[SectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[SectionIndex].Aspects.Length) { - Function.Stack[s] = Program.CurrentRoute.Sections[SectionIndex].Aspects[a].Number; + Function.Stack[s] = Program.CurrentRoute.Sections[SectionIndex].Aspects[a].AspectNumber; } else { Function.Stack[s] = 0; } diff --git a/source/OpenBVE/System/Scripting.cs b/source/OpenBVE/System/Scripting.cs index 4c9943fa8..5a6b2bad8 100644 --- a/source/OpenBVE/System/Scripting.cs +++ b/source/OpenBVE/System/Scripting.cs @@ -33,7 +33,7 @@ public static int CurrentAspect(TrainBase Train, int SectionIndex, bool IsPartOf int a = Program.CurrentRoute.Sections[nextSectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[nextSectionIndex].Aspects.Length) { - return Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; + return Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].AspectNumber; } return 0; } @@ -43,7 +43,7 @@ public static int CurrentAspect(TrainBase Train, int SectionIndex, bool IsPartOf int a = Program.CurrentRoute.Sections[SectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[SectionIndex].Aspects.Length) { - return Program.CurrentRoute.Sections[SectionIndex].Aspects[a].Number; + return Program.CurrentRoute.Sections[SectionIndex].Aspects[a].AspectNumber; } } return 0; diff --git a/source/Plugins/Route.Bve5/Structures/Section.cs b/source/Plugins/Route.Bve5/Structures/Section.cs index fbfa2200a..c667f6e82 100644 --- a/source/Plugins/Route.Bve5/Structures/Section.cs +++ b/source/Plugins/Route.Bve5/Structures/Section.cs @@ -64,7 +64,7 @@ internal void Create(RouteData Data, int currentElement, double startingDistance for (int l = 0; l < Aspects.Length; l++) { - Plugin.CurrentRoute.Sections[m].Aspects[l].Number = Aspects[l]; + Plugin.CurrentRoute.Sections[m].Aspects[l].AspectNumber = Aspects[l]; if (Aspects[l] >= 0 & Aspects[l] < Data.SignalSpeeds.Length) { Plugin.CurrentRoute.Sections[m].Aspects[l].Speed = Data.SignalSpeeds[Aspects[l]]; diff --git a/source/Plugins/Route.CsvRw/Structures/Signals/Section.cs b/source/Plugins/Route.CsvRw/Structures/Signals/Section.cs index 22866b3d1..d93a59f78 100644 --- a/source/Plugins/Route.CsvRw/Structures/Signals/Section.cs +++ b/source/Plugins/Route.CsvRw/Structures/Signals/Section.cs @@ -53,7 +53,7 @@ internal void Create(CurrentRoute CurrentRoute, List Blocks, int CurrentB SectionAspect[] newAspects = new SectionAspect[Aspects.Length]; for (int l = 0; l < Aspects.Length; l++) { - newAspects[l].Number = Aspects[l]; + newAspects[l].AspectNumber = Aspects[l]; if (Aspects[l] >= 0 & Aspects[l] < SignalSpeeds.Length) { newAspects[l].Speed = SignalSpeeds[Aspects[l]]; diff --git a/source/RouteManager2/CurrentRoute.cs b/source/RouteManager2/CurrentRoute.cs index a4ec20351..bae308d4e 100644 --- a/source/RouteManager2/CurrentRoute.cs +++ b/source/RouteManager2/CurrentRoute.cs @@ -142,10 +142,10 @@ public void UpdateAllSections() } /// Updates the specified signal section - /// - public void UpdateSection(int SectionIndex) + /// + public void UpdateSection(int sectionIndex) { - UpdateSection(Sections[SectionIndex], out Section nextSectionToUpdate); + UpdateSection(Sections[sectionIndex], out Section nextSectionToUpdate); while (nextSectionToUpdate != null) { UpdateSection(nextSectionToUpdate, out nextSectionToUpdate); @@ -153,31 +153,31 @@ public void UpdateSection(int SectionIndex) } /// Updates the specified signal section - /// - /// - public void UpdateSection(Section Section, out Section PreviousSection) + /// + /// + public void UpdateSection(Section section, out Section previousSection) { - if (Section == null) + if (section == null) { - PreviousSection = null; + previousSection = null; return; } - double timeElapsed = SecondsSinceMidnight - Section.LastUpdate; - Section.LastUpdate = SecondsSinceMidnight; + double timeElapsed = SecondsSinceMidnight - section.LastUpdate; + section.LastUpdate = SecondsSinceMidnight; // preparations int zeroAspect = 0; bool setToRed = false; - if (Section.Type == SectionType.ValueBased) + if (section.Type == SectionType.ValueBased) { // value-based zeroAspect = 0; - for (int i = 1; i < Section.Aspects.Length; i++) + for (int i = 1; i < section.Aspects.Length; i++) { - if (Section.Aspects[i].Number < Section.Aspects[zeroAspect].Number) + if (section.Aspects[i].Number < section.Aspects[zeroAspect].Number) { zeroAspect = i; } @@ -185,12 +185,12 @@ public void UpdateSection(Section Section, out Section PreviousSection) } // hold station departure signal at red - int d = Section.StationIndex; + int d = section.StationIndex; if (d >= 0) { // look for train in previous blocks - Section l = Section.PreviousSection; + Section l = section.PreviousSection; AbstractTrain train = null; while (true) @@ -232,7 +232,7 @@ public void UpdateSection(Section Section, out Section PreviousSection) // set to red where applicable if (train != null) { - if (!Section.TrainReachedStopPoint) + if (!section.TrainReachedStopPoint) { if (train.Station == d) { @@ -245,12 +245,12 @@ public void UpdateSection(Section Section, out Section PreviousSection) if (p0 >= p1) { - Section.TrainReachedStopPoint = true; + section.TrainReachedStopPoint = true; } } else { - Section.TrainReachedStopPoint = true; + section.TrainReachedStopPoint = true; } } } @@ -270,20 +270,20 @@ public void UpdateSection(Section Section, out Section PreviousSection) { if (train.LastStation == d - 1 || train.Station == d) { - if (Section.RedTimer == -1) + if (section.RedTimer == -1) { - Section.RedTimer = 30; + section.RedTimer = 30; } else { - Section.RedTimer -= timeElapsed; + section.RedTimer -= timeElapsed; } - setToRed = !(Section.RedTimer <= 0); + setToRed = !(section.RedTimer <= 0); } else { - Section.RedTimer = -1; + section.RedTimer = -1; } } @@ -295,7 +295,7 @@ public void UpdateSection(Section Section, out Section PreviousSection) { setToRed = true; } - else if (!Section.TrainReachedStopPoint) + else if (!section.TrainReachedStopPoint) { setToRed = true; } @@ -307,7 +307,7 @@ public void UpdateSection(Section Section, out Section PreviousSection) } // train in block - if (!Section.IsFree()) + if (!section.IsFree()) { setToRed = true; } @@ -317,38 +317,38 @@ public void UpdateSection(Section Section, out Section PreviousSection) if (setToRed) { - Section.FreeSections = 0; + section.FreeSections = 0; newAspect = zeroAspect; } else { - Section n = Section.NextSection; + Section n = section.NextSection; if (n != null) { if (n.FreeSections == -1) { - Section.FreeSections = -1; + section.FreeSections = -1; } else { - Section.FreeSections = n.FreeSections + 1; + section.FreeSections = n.FreeSections + 1; } } else { - Section.FreeSections = -1; + section.FreeSections = -1; } } // change aspect if (newAspect == -1) { - if (Section.Type == SectionType.ValueBased) + if (section.Type == SectionType.ValueBased) { // value-based - Section n = Section.NextSection; - int a = Section.Aspects.Last().Number; + Section n = section.NextSection; + int a = section.Aspects.Last().Number; if (n != null && n.CurrentAspect >= 0) { @@ -356,9 +356,9 @@ public void UpdateSection(Section Section, out Section PreviousSection) a = n.Aspects[n.CurrentAspect].Number; } - for (int i = Section.Aspects.Length - 1; i >= 0; i--) + for (int i = section.Aspects.Length - 1; i >= 0; i--) { - if (Section.Aspects[i].Number > a) + if (section.Aspects[i].Number > a) { newAspect = i; } @@ -366,28 +366,28 @@ public void UpdateSection(Section Section, out Section PreviousSection) if (newAspect == -1) { - newAspect = Section.Aspects.Length - 1; + newAspect = section.Aspects.Length - 1; } } else { // index-based - if (Section.FreeSections >= 0 & Section.FreeSections < Section.Aspects.Length) + if (section.FreeSections >= 0 & section.FreeSections < section.Aspects.Length) { - newAspect = Section.FreeSections; + newAspect = section.FreeSections; } else { - newAspect = Section.Aspects.Length - 1; + newAspect = section.Aspects.Length - 1; } } } // apply new aspect - Section.CurrentAspect = newAspect; + section.CurrentAspect = newAspect; // update previous section - PreviousSection = Section.PreviousSection; + previousSection = section.PreviousSection; } /// Gets the next section from the specified track position @@ -427,14 +427,14 @@ public RouteStation NextStation(double trackPosition) } /// Updates the currently displayed background - /// The time elapsed since the previous call to this function - /// Whether the game is currently paused - public void UpdateBackground(double TimeElapsed, bool GamePaused) + /// The time elapsed since the previous call to this function + /// Whether the game is currently paused + public void UpdateBackground(double timeElapsed, bool gamePaused) { - if (GamePaused) + if (gamePaused) { //Don't update the transition whilst paused - TimeElapsed = 0.0; + timeElapsed = 0.0; } const float scale = 0.5f; @@ -463,7 +463,7 @@ public void UpdateBackground(double TimeElapsed, bool GamePaused) } //Update the currently displayed background - CurrentBackground.UpdateBackground(SecondsSinceMidnight, TimeElapsed, false); + CurrentBackground.UpdateBackground(SecondsSinceMidnight, timeElapsed, false); if (TargetBackground == null || TargetBackground == CurrentBackground) { @@ -475,10 +475,10 @@ public void UpdateBackground(double TimeElapsed, bool GamePaused) //Update the target background if (TargetBackground is StaticBackground) { - TargetBackground.Countdown += TimeElapsed; + TargetBackground.Countdown += timeElapsed; } - TargetBackground.UpdateBackground(SecondsSinceMidnight, TimeElapsed, true); + TargetBackground.UpdateBackground(SecondsSinceMidnight, timeElapsed, true); switch (TargetBackground.Mode) { diff --git a/source/RouteManager2/Events/Transponder.cs b/source/RouteManager2/Events/Transponder.cs index 09074433b..bfc991b9b 100644 --- a/source/RouteManager2/Events/Transponder.cs +++ b/source/RouteManager2/Events/Transponder.cs @@ -58,7 +58,7 @@ public override void Trigger(int direction, TrackFollower trackFollower) if (a >= 0) { - if (currentRoute.Sections[s].Aspects[a].Number == 0) + if (currentRoute.Sections[s].Aspects[a].AspectNumber == 0) { break; } diff --git a/source/RouteManager2/Illustrations/RouteMap.cs b/source/RouteManager2/Illustrations/RouteMap.cs index 52e324c24..3b6c3ccfd 100644 --- a/source/RouteManager2/Illustrations/RouteMap.cs +++ b/source/RouteManager2/Illustrations/RouteMap.cs @@ -6,13 +6,11 @@ using System.Linq; using OpenBveApi; using OpenBveApi.Hosts; -using OpenBveApi.Input; using OpenBveApi.Interface; using OpenBveApi.Math; using OpenBveApi.Routes; using RouteManager2.Events; using RouteManager2.SignalManager; -using RouteManager2.Tracks; namespace RouteManager2 { diff --git a/source/RouteManager2/MessageManager/MessageTypes/MarkerImage.cs b/source/RouteManager2/MessageManager/MessageTypes/MarkerImage.cs index 63c9d290b..394995f4b 100644 --- a/source/RouteManager2/MessageManager/MessageTypes/MarkerImage.cs +++ b/source/RouteManager2/MessageManager/MessageTypes/MarkerImage.cs @@ -12,10 +12,10 @@ public class MarkerImage : AbstractMessage /// The texture to be displayed private readonly Texture texture; - public MarkerImage(HostInterface Host, Texture Texture) + public MarkerImage(HostInterface host, Texture texture) { - currentHost = Host; - texture = Texture; + currentHost = host; + this.texture = texture; } public override void AddMessage(double currentTime) diff --git a/source/RouteManager2/MessageManager/MessageTypes/MarkerText.cs b/source/RouteManager2/MessageManager/MessageTypes/MarkerText.cs index 021332d9b..853a96b0e 100644 --- a/source/RouteManager2/MessageManager/MessageTypes/MarkerText.cs +++ b/source/RouteManager2/MessageManager/MessageTypes/MarkerText.cs @@ -23,14 +23,14 @@ public MarkerText(string text) /// Creates a marker text /// The text to be displayed - /// The color of the text - public MarkerText(string text, MessageColor Color) + /// The color of the text + public MarkerText(string text, MessageColor color) { MessageToDisplay = text; Timeout = double.PositiveInfinity; TriggerOnce = false; Direction = MessageDirection.Both; - this.Color = Color; + Color = color; RendererAlpha = 1.0; } diff --git a/source/RouteManager2/MessageManager/MessageTypes/TextureMessage.cs b/source/RouteManager2/MessageManager/MessageTypes/TextureMessage.cs index 9353ec27d..ca935a2d6 100644 --- a/source/RouteManager2/MessageManager/MessageTypes/TextureMessage.cs +++ b/source/RouteManager2/MessageManager/MessageTypes/TextureMessage.cs @@ -29,9 +29,9 @@ public class TextureMessage : AbstractMessage /// The size public Vector2 Size = Vector2.Null; - public TextureMessage(HostInterface Host) + public TextureMessage(HostInterface host) { - currentHost = Host; + currentHost = host; Timeout = 10000; TriggerOnce = true; Direction = MessageDirection.Forwards; diff --git a/source/RouteManager2/SignalManager/SafetySystems.cs b/source/RouteManager2/SignalManager/SafetySystems.cs index 02d835210..e3d31b096 100644 --- a/source/RouteManager2/SignalManager/SafetySystems.cs +++ b/source/RouteManager2/SignalManager/SafetySystems.cs @@ -6,10 +6,8 @@ public enum SafetySystem { /// Any available safety system should be used (Either that from the previous station if defined or NONE) Any = -1, - /// ATS should be used- The track is NOT fitted with ATC Ats = 0, - /// ATC should be used Atc = 1 } diff --git a/source/RouteManager2/SignalManager/Section.cs b/source/RouteManager2/SignalManager/Section.cs index 53a4209c2..9a2ff4c7b 100644 --- a/source/RouteManager2/SignalManager/Section.cs +++ b/source/RouteManager2/SignalManager/Section.cs @@ -62,32 +62,32 @@ public Section(double trackPosition, SectionAspect[] aspects, SectionType type, } /// Called when a train enters the section - /// The train - public void Enter(AbstractTrain Train) + /// The train + public void Enter(AbstractTrain train) { int n = Trains.Length; for (int i = 0; i < n; i++) { - if (Trains[i] == Train) + if (Trains[i] == train) { return; } } Array.Resize(ref Trains, n + 1); - Trains[n] = Train; + Trains[n] = train; } /// Called when a train leaves the section - /// The train - public void Leave(AbstractTrain Train) + /// The train + public void Leave(AbstractTrain train) { int n = Trains.Length; for (int i = 0; i < n; i++) { - if (Trains[i] == Train) + if (Trains[i] == train) { for (int j = i; j < n - 1; j++) { @@ -101,11 +101,11 @@ public void Leave(AbstractTrain Train) } /// Checks whether a train is currently within the section - /// The train + /// The train /// True if the train is within the section, false otherwise - public bool Exists(AbstractTrain Train) + public bool Exists(AbstractTrain train) { - return Trains.Any(t => t == Train); + return Trains.Any(t => t == train); } /// Checks whether the section is free, disregarding the specified train. @@ -124,9 +124,9 @@ public bool IsFree() } /// Gets the first train within the section - /// Whether bogus trains are to be allowed + /// Whether bogus trains are to be allowed /// The first train within the section, or null if no trains are found - public AbstractTrain GetFirstTrain(bool AllowBogusTrain) + public AbstractTrain GetFirstTrain(bool allowBogusTrain) { for (int i = 0; i < Trains.Length; i++) { @@ -135,7 +135,7 @@ public AbstractTrain GetFirstTrain(bool AllowBogusTrain) return Trains[i]; } - if (AllowBogusTrain & Trains[i].State == TrainState.Bogus) + if (allowBogusTrain & Trains[i].State == TrainState.Bogus) { return Trains[i]; } diff --git a/source/RouteManager2/SignalManager/SectionAspect.cs b/source/RouteManager2/SignalManager/SectionAspect.cs index ddadbc379..6add74209 100644 --- a/source/RouteManager2/SignalManager/SectionAspect.cs +++ b/source/RouteManager2/SignalManager/SectionAspect.cs @@ -5,17 +5,16 @@ public struct SectionAspect { /// The aspect number public int Number; - /// The speed limit associated with this aspect number public double Speed; /// Creates a new signalling aspect - /// The aspect number - /// The speed limit - public SectionAspect(int Number, double Speed) + /// The aspect number + /// The speed limit + public SectionAspect(int aspectNumber, double speedLimit) { - this.Number = Number; - this.Speed = Speed; + this.Number = aspectNumber; + this.Speed = speedLimit; } } } diff --git a/source/RouteManager2/SignalManager/SectionTypes.cs b/source/RouteManager2/SignalManager/SectionTypes.cs index 68187f904..95a5251ee 100644 --- a/source/RouteManager2/SignalManager/SectionTypes.cs +++ b/source/RouteManager2/SignalManager/SectionTypes.cs @@ -5,7 +5,6 @@ public enum SectionType { /// A section aspect may have any value ValueBased, - /// Section aspect count upwards from zero (0,1,2,3....) IndexBased } diff --git a/source/RouteManager2/SignalManager/SignalObject.Compatability.cs b/source/RouteManager2/SignalManager/SignalObject.Compatability.cs index b21f2cfb0..9d1d60cd1 100644 --- a/source/RouteManager2/SignalManager/SignalObject.Compatability.cs +++ b/source/RouteManager2/SignalManager/SignalObject.Compatability.cs @@ -20,14 +20,14 @@ public class CompatibilitySignalObject : SignalObject /// The aspect numbers associated with each state public readonly int[] AspectNumbers; /// The object states - public readonly StaticObject[] Objects; + public readonly StaticObject[] AspectObjects; private readonly HostInterface currentHost; - public CompatibilitySignalObject(int[] aspectNumbers, StaticObject[] Objects, HostInterface Host) + public CompatibilitySignalObject(int[] aspectNumbers, StaticObject[] aspectObjects, HostInterface currentHost) { this.AspectNumbers = aspectNumbers; - this.Objects = Objects; - this.currentHost = Host; + this.AspectObjects = aspectObjects; + this.currentHost = currentHost; } public override void Create(Vector3 wpos, Transformation railTransformation, Transformation localTransformation, int sectionIndex, double startingDistance, double endingDistance, double trackPosition, double brightness) @@ -44,15 +44,15 @@ public override void Create(Vector3 wpos, Transformation railTransformation, Tra aoc.Objects[0].States = new ObjectState[AspectNumbers.Length]; for (int l = 0; l < AspectNumbers.Length; l++) { - aoc.Objects[0].States[l] = new ObjectState((StaticObject)Objects[l].Clone()); + aoc.Objects[0].States[l] = new ObjectState((StaticObject)AspectObjects[l].Clone()); } - CultureInfo Culture = CultureInfo.InvariantCulture; + CultureInfo culture = CultureInfo.InvariantCulture; string expr = ""; for (int l = 0; l < AspectNumbers.Length - 1; l++) { - expr += "section " + AspectNumbers[l].ToString(Culture) + " <= " + l.ToString(Culture) + " "; + expr += "section " + AspectNumbers[l].ToString(culture) + " <= " + l.ToString(culture) + " "; } - expr += (AspectNumbers.Length - 1).ToString(Culture); + expr += (AspectNumbers.Length - 1).ToString(culture); for (int l = 0; l < AspectNumbers.Length - 1; l++) { expr += " ?"; @@ -86,11 +86,11 @@ public static void ReadCompatibilitySignalXML(HostInterface currentHost, string { currentHost.AddMessage(MessageType.Information, false, "INFO: Using the " + node.InnerText + " compatibility signal set."); } - XmlNodeList DocumentNodes = currentXML.DocumentElement.SelectNodes("/openBVE/CompatibilitySignals/Signal"); - if (DocumentNodes != null) + XmlNodeList documentNodes = currentXML.DocumentElement.SelectNodes("/openBVE/CompatibilitySignals/Signal"); + if (documentNodes != null) { int index = 0; - foreach (XmlNode nn in DocumentNodes) + foreach (XmlNode nn in documentNodes) { List objectList = new List(); List aspectList = new List(); @@ -158,10 +158,10 @@ public static void ReadCompatibilitySignalXML(HostInterface currentHost, string currentHost.AddMessage(MessageType.Error, true, "An unexpected error was encountered whilst processing the compatability signal file " + fileName); } - DocumentNodes = currentXML.DocumentElement.SelectNodes("/openBVE/CompatibilitySignals/SpeedLimits"); - if (DocumentNodes != null) + documentNodes = currentXML.DocumentElement.SelectNodes("/openBVE/CompatibilitySignals/SpeedLimits"); + if (documentNodes != null) { - foreach (XmlNode nn in DocumentNodes) + foreach (XmlNode nn in documentNodes) { try { diff --git a/source/RouteManager2/SignalManager/SignalObject.cs b/source/RouteManager2/SignalManager/SignalObject.cs index 3e57f4273..52bed4d2c 100644 --- a/source/RouteManager2/SignalManager/SignalObject.cs +++ b/source/RouteManager2/SignalManager/SignalObject.cs @@ -6,7 +6,7 @@ namespace RouteManager2.SignalManager /// An abstract signal object - All signals must inherit from this class public abstract class SignalObject { - public virtual void Create(Vector3 wpos, Transformation RailTransformation, Transformation LocalTransformation, int SectionIndex, double StartingDistance, double EndingDistance, double TrackPosition, double Brightness) + public virtual void Create(Vector3 wpos, Transformation railTransformation, Transformation localTransformation, int sectionIndex, double startingDistance, double endingDistance, double trackPosition, double brightness) {} } } diff --git a/source/RouteManager2/Stations/RouteStation.cs b/source/RouteManager2/Stations/RouteStation.cs index 92bfe91cf..7aeab80a9 100644 --- a/source/RouteManager2/Stations/RouteStation.cs +++ b/source/RouteManager2/Stations/RouteStation.cs @@ -44,14 +44,14 @@ public class RouteStation : Station public readonly string Key; /// Gets the index of the stop corresponding to the train's number of cars - /// The number of cars the train has - public int GetStopIndex(int Cars) + /// The number of cars the train has + public int GetStopIndex(int numberOfCars) { int j = -1; int allCars = -1; for (int i = Stops.Length - 1; i >= 0; i--) { - if (Cars == Stops[i].Cars) + if (numberOfCars == Stops[i].Cars) { // If we have found the specified number of cars, stop searching return i; @@ -60,7 +60,7 @@ public int GetStopIndex(int Cars) { allCars = j; } - if (Stops[i].Cars != 0 && Cars < Stops[i].Cars) + if (Stops[i].Cars != 0 && numberOfCars < Stops[i].Cars) { /* * The stop has greater than the specified number of cars (hence all cars will be platformed) @@ -90,9 +90,9 @@ public int GetStopIndex(int Cars) } /// Indicates whether the specified train stops at this station. - public bool StopsHere(AbstractTrain Train) + public bool StopsHere(AbstractTrain train) { - if (Train.IsPlayerTrain) + if (train.IsPlayerTrain) { return StopMode == StationStopMode.AllStop | StopMode == StationStopMode.PlayerStop | StopMode == StationStopMode.PlayerRequestStop | StopMode == StationStopMode.AllRequestStop; } diff --git a/source/RouteViewer/Audio/Sounds.Update.cs b/source/RouteViewer/Audio/Sounds.Update.cs index 83170f922..d7ba8528a 100644 --- a/source/RouteViewer/Audio/Sounds.Update.cs +++ b/source/RouteViewer/Audio/Sounds.Update.cs @@ -37,8 +37,8 @@ protected override void UpdateInverseModel(double timeElapsed) } AL.Listener(ALListener3f.Position, 0.0f, 0.0f, 0.0f); AL.Listener(ALListener3f.Velocity, (float)listenerVelocity.X, (float)listenerVelocity.Y, (float)listenerVelocity.Z); - var Orientation = new[]{(float) listenerOrientation.Z.X, (float) listenerOrientation.Z.Y, (float) listenerOrientation.Z.Z,-(float) listenerOrientation.Y.X, -(float) listenerOrientation.Y.Y, -(float) listenerOrientation.Y.Z}; - AL.Listener(ALListenerfv.Orientation, ref Orientation); + var orientation = new[]{(float) listenerOrientation.Z.X, (float) listenerOrientation.Z.Y, (float) listenerOrientation.Z.Z,-(float) listenerOrientation.Y.X, -(float) listenerOrientation.Y.Y, -(float) listenerOrientation.Y.Z}; + AL.Listener(ALListenerfv.Orientation, ref orientation); /* * Set up the atmospheric attributes. * */ @@ -142,8 +142,8 @@ protected override void UpdateInverseModel(double timeElapsed) switch (Sources[i].Type) { case SoundType.TrainCar: - var Car = (AbstractCar)Sources[i].Parent; - Car.CreateWorldCoordinates(Sources[i].Position, out position, out _); + var parentCar = (AbstractCar)Sources[i].Parent; + parentCar.CreateWorldCoordinates(Sources[i].Position, out position, out _); break; default: position = Sources[i].Position; @@ -285,10 +285,9 @@ protected override void UpdateInverseModel(double timeElapsed) switch (source.Type) { case SoundType.TrainCar: - Vector3 direction; - var Car = (AbstractCar)Sources[i].Parent; - Car.CreateWorldCoordinates(source.Position, out position, out direction); - velocity = Car.CurrentSpeed * direction; + var parentCar = (AbstractCar)Sources[i].Parent; + parentCar.CreateWorldCoordinates(source.Position, out position, out Vector3 direction); + velocity = parentCar.CurrentSpeed * direction; break; default: position = source.Position; diff --git a/source/RouteViewer/Game/Menu.SingleMenu.cs b/source/RouteViewer/Game/Menu.SingleMenu.cs index 3a45496ef..2519f9a43 100644 --- a/source/RouteViewer/Game/Menu.SingleMenu.cs +++ b/source/RouteViewer/Game/Menu.SingleMenu.cs @@ -5,10 +5,7 @@ using OpenBveApi.Textures; using System; using System.IO; -using OpenBveApi.Math; using Path = OpenBveApi.Path; -using RouteViewer; -using OpenBveApi.Packages; using System.ComponentModel; namespace RouteViewer @@ -18,9 +15,9 @@ public sealed partial class GameMenu /// Provides implementation for a single menu of the menu stack. /// The class is private to Menu, but all its fields are public to allow 'quick-and-dirty' /// access from Menu itself. - private class SingleMenu : MenuBase + private sealed class SingleMenu : MenuBase { - public SingleMenu(AbstractMenu menu, MenuType menuType, int data = 0, double MaxWidth = 0) : base(menuType) + public SingleMenu(AbstractMenu menu, MenuType menuType, int data = 0, double maxWidth = 0) : base(menuType) { //Vector2 size; Align = TextAlignment.TopMiddle; @@ -162,7 +159,7 @@ public SingleMenu(AbstractMenu menu, MenuType menuType, int data = 0, double Max break; } - ComputeExtent(menuType, Game.Menu.MenuFont, MaxWidth); + ComputeExtent(menuType, Game.Menu.MenuFont, maxWidth); Height = Items.Length * Game.Menu.lineHeight; TopItem = 0; diff --git a/source/RouteViewer/Game/Menu.cs b/source/RouteViewer/Game/Menu.cs index 879dc452a..dbfaf36e2 100644 --- a/source/RouteViewer/Game/Menu.cs +++ b/source/RouteViewer/Game/Menu.cs @@ -89,12 +89,12 @@ public override void PushMenu(MenuType type, int data = 0, bool replace = false) if (Menus.Length <= CurrMenu) Array.Resize(ref Menus, CurrMenu + 1); - int MaxWidth = 0; + int maxWidth = 0; if ((int)type >= 100) { - MaxWidth = Renderer.Screen.Width / 2; + maxWidth = Renderer.Screen.Width / 2; } - Menus[CurrMenu] = new SingleMenu(this, type, data, MaxWidth); + Menus[CurrMenu] = new SingleMenu(this, type, data, maxWidth); if (replace) { Menus[CurrMenu].Selection = 1; @@ -290,10 +290,10 @@ public override bool ProcessMouseMove(int x, int y) return false; } - public override void Draw(double RealTimeElapsed) + public override void Draw(double realTimeElapsed) { - double TimeElapsed = RealTimeElapsed - lastTimeElapsed; - lastTimeElapsed = RealTimeElapsed; + double timeElapsed = realTimeElapsed - lastTimeElapsed; + lastTimeElapsed = realTimeElapsed; int i; if (CurrMenu < 0 || CurrMenu >= Menus.Length) @@ -382,14 +382,14 @@ public override void Draw(double RealTimeElapsed) } // draw the text - Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(TimeElapsed), new Vector2(itemX, itemY), + Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(timeElapsed), new Vector2(itemX, itemY), menu.Align, ColourHighlight, false); } else if (menu.Items[i] is MenuCaption) - Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(TimeElapsed), new Vector2(itemX, itemY), + Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(timeElapsed), new Vector2(itemX, itemY), menu.Align, ColourCaption, false); else - Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(TimeElapsed), new Vector2(itemX, itemY), + Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(timeElapsed), new Vector2(itemX, itemY), menu.Align, ColourNormal, false); if (menu.Items[i] is MenuOption opt) { @@ -451,13 +451,13 @@ private static void routeWorkerThread_doWork(object sender, DoWorkEventArgs e) if (Program.CurrentHost.Plugins[i].Route != null && Program.CurrentHost.Plugins[i].Route.CanLoadRoute(currentFile)) { // ReSharper disable once RedundantCast - object Route = (object)Program.CurrentRoute; // must cast to allow us to use the ref keyword correctly. - string RailwayFolder = Loading.GetRailwayFolder(currentFile); - string ObjectFolder = Path.CombineDirectory(RailwayFolder, "Object"); - string SoundFolder = Path.CombineDirectory(RailwayFolder, "Sound"); - if (Program.CurrentHost.Plugins[i].Route.LoadRoute(currentFile, RouteEncoding, null, ObjectFolder, SoundFolder, true, ref Route)) + object route = (object)Program.CurrentRoute; // must cast to allow us to use the ref keyword correctly. + string railwayFolder = Loading.GetRailwayFolder(currentFile); + string objectFolder = Path.CombineDirectory(railwayFolder, "Object"); + string soundFolder = Path.CombineDirectory(railwayFolder, "Sound"); + if (Program.CurrentHost.Plugins[i].Route.LoadRoute(currentFile, RouteEncoding, null, objectFolder, soundFolder, true, ref route)) { - Program.CurrentRoute = (CurrentRoute)Route; + Program.CurrentRoute = (CurrentRoute)route; } else { @@ -535,8 +535,8 @@ private static void routeWorkerThread_completed(object sender, RunWorkerComplete } // description - string Description = Program.CurrentRoute.Comment.ConvertNewlinesToCrLf(); - routeDescriptionBox.Text = Description.Length != 0 ? Description : System.IO.Path.GetFileNameWithoutExtension(currentFile); + string description = Program.CurrentRoute.Comment.ConvertNewlinesToCrLf(); + routeDescriptionBox.Text = description.Length != 0 ? description : System.IO.Path.GetFileNameWithoutExtension(currentFile); } catch (Exception ex) { diff --git a/source/RouteViewer/System/Gamewindow.cs b/source/RouteViewer/System/Gamewindow.cs index d9ba8174c..208205736 100644 --- a/source/RouteViewer/System/Gamewindow.cs +++ b/source/RouteViewer/System/Gamewindow.cs @@ -62,19 +62,19 @@ protected override void OnRenderFrame(FrameEventArgs e) return; } ProcessEvents(); - double TimeElapsed = CPreciseTimer.GetElapsedTime(); + double timeElapsed = CPreciseTimer.GetElapsedTime(); if (Program.CurrentRouteFile != null) { DateTime d = DateTime.Now; Game.SecondsSinceMidnight = 3600 * d.Hour + 60 * d.Minute + d.Second + 0.001 * d.Millisecond; - ObjectManager.UpdateAnimatedWorldObjects(TimeElapsed, false); - World.UpdateAbsoluteCamera(TimeElapsed); + ObjectManager.UpdateAnimatedWorldObjects(timeElapsed, false); + World.UpdateAbsoluteCamera(timeElapsed); Program.Renderer.UpdateVisibility(true); - Program.Sounds.Update(TimeElapsed, SoundModels.Linear); + Program.Sounds.Update(timeElapsed, SoundModels.Linear); } Program.Renderer.Lighting.UpdateLighting(Program.CurrentRoute.SecondsSinceMidnight, Program.CurrentRoute.LightDefinitions); - Program.Renderer.RenderScene(TimeElapsed); + Program.Renderer.RenderScene(timeElapsed); MessageManager.UpdateMessages(); SwapBuffers(); diff --git a/source/RouteViewer/System/Host.cs b/source/RouteViewer/System/Host.cs index 0cdeca24f..86d898b6d 100644 --- a/source/RouteViewer/System/Host.cs +++ b/source/RouteViewer/System/Host.cs @@ -41,14 +41,14 @@ public override void ReportProblem(ProblemType type, string text) { } } - public override void AddMessage(MessageType type, bool FileNotFound, string text) + public override void AddMessage(MessageType type, bool fileNotFound, string text) { - Interface.AddMessage(type, FileNotFound, text); + Interface.AddMessage(type, fileNotFound, text); } - public override void AddMessage(object Message) + public override void AddMessage(object message) { - MessageManager.AddMessage((AbstractMessage)Message); + MessageManager.AddMessage((AbstractMessage)message); } // --- texture --- @@ -186,9 +186,9 @@ public override bool LoadTexture(string path, TextureParameters parameters, out return false; } - public override bool LoadTexture(ref Texture Texture, OpenGlTextureWrapMode wrapMode) + public override bool LoadTexture(ref Texture texture, OpenGlTextureWrapMode wrapMode) { - return Program.Renderer.TextureManager.LoadTexture(ref Texture, wrapMode, CPreciseTimer.GetClockTicks(), Interface.CurrentOptions.Interpolation, Interface.CurrentOptions.AnisotropicFilteringLevel); + return Program.Renderer.TextureManager.LoadTexture(ref texture, wrapMode, CPreciseTimer.GetClockTicks(), Interface.CurrentOptions.Interpolation, Interface.CurrentOptions.AnisotropicFilteringLevel); } public override bool RegisterTexture(string path, TextureParameters parameters, out Texture handle, bool loadTexture = false, int timeout = 1000) { @@ -319,16 +319,16 @@ public override bool RegisterSound(OpenBveApi.Sounds.Sound sound, out OpenBveApi return true; } - public override bool LoadStaticObject(string path, System.Text.Encoding Encoding, bool PreserveVertices, out StaticObject Object) + public override bool LoadStaticObject(string path, System.Text.Encoding encoding, bool preserveVertices, out StaticObject @object) { - if (base.LoadStaticObject(path, Encoding, PreserveVertices, out Object)) + if (base.LoadStaticObject(path, encoding, preserveVertices, out @object)) { return true; } if (File.Exists(path) || Directory.Exists(path)) { - Encoding = TextEncoding.GetSystemEncodingFromFile(path, Encoding); + encoding = TextEncoding.GetSystemEncodingFromFile(path, encoding); for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) { @@ -340,17 +340,17 @@ public override bool LoadStaticObject(string path, System.Text.Encoding Encoding { try { - if (Program.CurrentHost.Plugins[i].Object.LoadObject(path, Encoding, out var unifiedObject)) + if (Program.CurrentHost.Plugins[i].Object.LoadObject(path, encoding, out var unifiedObject)) { if (unifiedObject is StaticObject staticObject) { - staticObject.OptimizeObject(PreserveVertices, Interface.CurrentOptions.ObjectOptimizationBasicThreshold, true); - Object = staticObject; - StaticObjectCache.Add(ValueTuple.Create(path, PreserveVertices, File.GetLastWriteTime(path)), Object); + staticObject.OptimizeObject(preserveVertices, Interface.CurrentOptions.ObjectOptimizationBasicThreshold, true); + @object = staticObject; + StaticObjectCache.Add(ValueTuple.Create(path, preserveVertices, File.GetLastWriteTime(path)), @object); return true; } - Object = null; + @object = null; // may be trying to load in different places, so leave Interface.AddMessage(MessageType.Error, false, "Attempted to load " + path + " which is an animated object where only static objects are allowed."); } @@ -384,20 +384,20 @@ public override bool LoadStaticObject(string path, System.Text.Encoding Encoding { ReportProblem(ProblemType.PathNotFound, path); } - Object = null; + @object = null; return false; } - public override bool LoadObject(string path, System.Text.Encoding Encoding, out UnifiedObject Object) + public override bool LoadObject(string path, System.Text.Encoding encoding, out UnifiedObject @object) { - if (base.LoadObject(path, Encoding, out Object)) + if (base.LoadObject(path, encoding, out @object)) { return true; } if (File.Exists(path) || Directory.Exists(path)) { - Encoding = TextEncoding.GetSystemEncodingFromFile(path, Encoding); + encoding = TextEncoding.GetSystemEncodingFromFile(path, encoding); for (int i = 0; i < Program.CurrentHost.Plugins.Length; i++) { @@ -409,22 +409,22 @@ public override bool LoadObject(string path, System.Text.Encoding Encoding, out { try { - if (Program.CurrentHost.Plugins[i].Object.LoadObject(path, Encoding, out UnifiedObject obj)) + if (Program.CurrentHost.Plugins[i].Object.LoadObject(path, encoding, out UnifiedObject obj)) { if (obj == null) { continue; } obj.OptimizeObject(false, Interface.CurrentOptions.ObjectOptimizationBasicThreshold, true); - Object = obj; + @object = obj; - if (Object is StaticObject staticObject) + if (@object is StaticObject staticObject) { StaticObjectCache.Add(ValueTuple.Create(path, false, File.GetLastWriteTime(path)), staticObject); return true; } - if (Object is AnimatedObjectCollection aoc) + if (@object is AnimatedObjectCollection aoc) { AnimatedObjectCollectionCache.Add(path, aoc); } @@ -473,23 +473,23 @@ public override bool LoadObject(string path, System.Text.Encoding Encoding, out { ReportProblem(ProblemType.PathNotFound, path); } - Object = null; + @object = null; return false; } - public override void ExecuteFunctionScript(OpenBveApi.FunctionScripting.FunctionScript functionScript, AbstractTrain train, int CarIndex, Vector3 Position, double TrackPosition, int SectionIndex, bool IsPartOfTrain, double TimeElapsed, int CurrentState) + public override void ExecuteFunctionScript(OpenBveApi.FunctionScripting.FunctionScript functionScript, AbstractTrain train, int carIndex, Vector3 position, double trackPosition, int sectionIndex, bool isPartOfTrain, double timeElapsed, int currentState) { - FunctionScripts.ExecuteFunctionScript(functionScript, (TrainManager.Train)train, CarIndex, Position, TrackPosition, SectionIndex, IsPartOfTrain, TimeElapsed, CurrentState); + FunctionScripts.ExecuteFunctionScript(functionScript, (TrainManager.Train)train, carIndex, position, trackPosition, sectionIndex, isPartOfTrain, timeElapsed, currentState); } - public override int CreateStaticObject(StaticObject Prototype, Vector3 Position, Transformation WorldTransformation, Transformation LocalTransformation, double AccurateObjectDisposalZOffset, double StartingDistance, double EndingDistance, double TrackPosition, double Brightness) + public override int CreateStaticObject(StaticObject prototype, Vector3 position, Transformation worldTransformation, Transformation localTransformation, double accurateObjectDisposalZOffset, double startingDistance, double endingDistance, double trackPosition, double brightness) { - return Program.Renderer.CreateStaticObject(Prototype, Position, WorldTransformation, LocalTransformation, Program.CurrentRoute.AccurateObjectDisposal, AccurateObjectDisposalZOffset, StartingDistance, EndingDistance, Program.CurrentRoute.BlockLength, TrackPosition, Brightness); + return Program.Renderer.CreateStaticObject(prototype, position, worldTransformation, localTransformation, Program.CurrentRoute.AccurateObjectDisposal, accurateObjectDisposalZOffset, startingDistance, endingDistance, Program.CurrentRoute.BlockLength, trackPosition, brightness); } - public override int CreateStaticObject(StaticObject Prototype, Vector3 Position, Transformation LocalTransformation, Matrix4D Rotate, Matrix4D Translate, double AccurateObjectDisposalZOffset, double StartingDistance, double EndingDistance, double TrackPosition, double Brightness) + public override int CreateStaticObject(StaticObject prototype, Vector3 position, Transformation localTransformation, Matrix4D rotate, Matrix4D translate, double accurateObjectDisposalZOffset, double startingDistance, double endingDistance, double trackPosition, double brightness) { - return Program.Renderer.CreateStaticObject(Position, Prototype, LocalTransformation, Rotate, Translate, Program.CurrentRoute.AccurateObjectDisposal, AccurateObjectDisposalZOffset, StartingDistance, EndingDistance, Program.CurrentRoute.BlockLength, TrackPosition, Brightness); + return Program.Renderer.CreateStaticObject(position, prototype, localTransformation, rotate, translate, Program.CurrentRoute.AccurateObjectDisposal, accurateObjectDisposalZOffset, startingDistance, endingDistance, Program.CurrentRoute.BlockLength, trackPosition, brightness); } public override void CreateDynamicObject(ref ObjectState internalObject) @@ -547,11 +547,11 @@ public override AbstractTrain ParseTrackFollowingObject(string objectPath, strin // ReSharper disable once CoVariantArrayConversion public override AbstractTrain[] Trains => Program.TrainManager.Trains; - public override AbstractTrain ClosestTrain(AbstractTrain Train) + public override AbstractTrain ClosestTrain(AbstractTrain train) { AbstractTrain closestTrain = null; double bestLocation = double.MaxValue; - if(Train is TrainBase baseTrain) + if(train is TrainBase baseTrain) { for (int i = 0; i < Program.TrainManager.Trains.Length; i++) { @@ -570,7 +570,7 @@ public override AbstractTrain ClosestTrain(AbstractTrain Train) return closestTrain; } - public override AbstractTrain ClosestTrain(double TrackPosition) + public override AbstractTrain ClosestTrain(double trackPosition) { AbstractTrain closestTrain = null; double trainDistance = double.MaxValue; @@ -579,13 +579,13 @@ public override AbstractTrain ClosestTrain(double TrackPosition) if (Program.TrainManager.Trains[j].State == TrainState.Available) { double distance; - if (Program.TrainManager.Trains[j].Cars[0].FrontAxle.Follower.TrackPosition < TrackPosition) + if (Program.TrainManager.Trains[j].Cars[0].FrontAxle.Follower.TrackPosition < trackPosition) { - distance = TrackPosition - Program.TrainManager.Trains[j].Cars[0].TrackPosition; + distance = trackPosition - Program.TrainManager.Trains[j].Cars[0].TrackPosition; } - else if (Program.TrainManager.Trains[j].Cars[Program.TrainManager.Trains[j].Cars.Length - 1].RearAxle.Follower.TrackPosition > TrackPosition) + else if (Program.TrainManager.Trains[j].Cars[Program.TrainManager.Trains[j].Cars.Length - 1].RearAxle.Follower.TrackPosition > trackPosition) { - distance = Program.TrainManager.Trains[j].Cars[Program.TrainManager.Trains[j].Cars.Length - 1].RearAxle.Follower.TrackPosition - TrackPosition; + distance = Program.TrainManager.Trains[j].Cars[Program.TrainManager.Trains[j].Cars.Length - 1].RearAxle.Follower.TrackPosition - trackPosition; } else { From cfc2965eee5fc2f075b6ae8b29b5f3b0fc26a248 Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Mon, 11 Nov 2024 17:32:12 +0000 Subject: [PATCH 4/7] Change: Enforce lowerCamelCase for parameter names (P4) RouteManager --- source/ObjectViewer/FunctionScripts.cs | 4 +- .../AnimatedObjects/FunctionScripts.cs | 4 +- source/OpenBVE/System/Scripting.cs | 4 +- .../Plugins/Route.Bve5/Structures/Section.cs | 2 +- .../Route.CsvRw/Structures/Signals/Section.cs | 2 +- source/RouteManager2/Climate/Atmosphere.cs | 58 +++++++++---------- source/RouteManager2/Climate/Fog.cs | 18 +++--- source/RouteManager2/Events/Transponder.cs | 2 +- 8 files changed, 48 insertions(+), 46 deletions(-) diff --git a/source/ObjectViewer/FunctionScripts.cs b/source/ObjectViewer/FunctionScripts.cs index c6ffdd127..1b7bed6e4 100644 --- a/source/ObjectViewer/FunctionScripts.cs +++ b/source/ObjectViewer/FunctionScripts.cs @@ -1094,7 +1094,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr if (nextSectionIndex >= 0 & nextSectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[nextSectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[nextSectionIndex].Aspects.Length) { - Function.Stack[s] = (double)Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].AspectNumber; + Function.Stack[s] = (double)Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; } else { Function.Stack[s] = 0; } @@ -1102,7 +1102,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr } else if (SectionIndex >= 0 & SectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[SectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[SectionIndex].Aspects.Length) { - Function.Stack[s] = (double)Program.CurrentRoute.Sections[SectionIndex].Aspects[a].AspectNumber; + Function.Stack[s] = (double)Program.CurrentRoute.Sections[SectionIndex].Aspects[a].Number; } else { Function.Stack[s] = 0; } diff --git a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs index ac51c9295..f3aca3f2c 100644 --- a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs +++ b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs @@ -1452,7 +1452,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr if (nextSectionIndex >= 0 & nextSectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[nextSectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[nextSectionIndex].Aspects.Length) { - Function.Stack[s] = Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].AspectNumber; + Function.Stack[s] = Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; } else { Function.Stack[s] = 0; } @@ -1460,7 +1460,7 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr } else if (SectionIndex >= 0 & SectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[SectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[SectionIndex].Aspects.Length) { - Function.Stack[s] = Program.CurrentRoute.Sections[SectionIndex].Aspects[a].AspectNumber; + Function.Stack[s] = Program.CurrentRoute.Sections[SectionIndex].Aspects[a].Number; } else { Function.Stack[s] = 0; } diff --git a/source/OpenBVE/System/Scripting.cs b/source/OpenBVE/System/Scripting.cs index 5a6b2bad8..4c9943fa8 100644 --- a/source/OpenBVE/System/Scripting.cs +++ b/source/OpenBVE/System/Scripting.cs @@ -33,7 +33,7 @@ public static int CurrentAspect(TrainBase Train, int SectionIndex, bool IsPartOf int a = Program.CurrentRoute.Sections[nextSectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[nextSectionIndex].Aspects.Length) { - return Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].AspectNumber; + return Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; } return 0; } @@ -43,7 +43,7 @@ public static int CurrentAspect(TrainBase Train, int SectionIndex, bool IsPartOf int a = Program.CurrentRoute.Sections[SectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[SectionIndex].Aspects.Length) { - return Program.CurrentRoute.Sections[SectionIndex].Aspects[a].AspectNumber; + return Program.CurrentRoute.Sections[SectionIndex].Aspects[a].Number; } } return 0; diff --git a/source/Plugins/Route.Bve5/Structures/Section.cs b/source/Plugins/Route.Bve5/Structures/Section.cs index c667f6e82..fbfa2200a 100644 --- a/source/Plugins/Route.Bve5/Structures/Section.cs +++ b/source/Plugins/Route.Bve5/Structures/Section.cs @@ -64,7 +64,7 @@ internal void Create(RouteData Data, int currentElement, double startingDistance for (int l = 0; l < Aspects.Length; l++) { - Plugin.CurrentRoute.Sections[m].Aspects[l].AspectNumber = Aspects[l]; + Plugin.CurrentRoute.Sections[m].Aspects[l].Number = Aspects[l]; if (Aspects[l] >= 0 & Aspects[l] < Data.SignalSpeeds.Length) { Plugin.CurrentRoute.Sections[m].Aspects[l].Speed = Data.SignalSpeeds[Aspects[l]]; diff --git a/source/Plugins/Route.CsvRw/Structures/Signals/Section.cs b/source/Plugins/Route.CsvRw/Structures/Signals/Section.cs index d93a59f78..22866b3d1 100644 --- a/source/Plugins/Route.CsvRw/Structures/Signals/Section.cs +++ b/source/Plugins/Route.CsvRw/Structures/Signals/Section.cs @@ -53,7 +53,7 @@ internal void Create(CurrentRoute CurrentRoute, List Blocks, int CurrentB SectionAspect[] newAspects = new SectionAspect[Aspects.Length]; for (int l = 0; l < Aspects.Length; l++) { - newAspects[l].AspectNumber = Aspects[l]; + newAspects[l].Number = Aspects[l]; if (Aspects[l] >= 0 & Aspects[l] < SignalSpeeds.Length) { newAspects[l].Speed = SignalSpeeds[Aspects[l]]; diff --git a/source/RouteManager2/Climate/Atmosphere.cs b/source/RouteManager2/Climate/Atmosphere.cs index 1de33c973..0dd8dfc4a 100644 --- a/source/RouteManager2/Climate/Atmosphere.cs +++ b/source/RouteManager2/Climate/Atmosphere.cs @@ -54,11 +54,11 @@ public class Atmosphere public void CalculateSeaLevelConstants() { SeaLevelAirTemperature = InitialAirTemperature - TemperatureLapseRate * InitialElevation; - double Exponent = AccelerationDueToGravity * MolarMass / (UniversalGasConstant * TemperatureLapseRate); - double Base = 1.0 + TemperatureLapseRate * InitialElevation / SeaLevelAirTemperature; - if (Base >= 0.0) + double exponent = AccelerationDueToGravity * MolarMass / (UniversalGasConstant * TemperatureLapseRate); + double baseRate = 1.0 + TemperatureLapseRate * InitialElevation / SeaLevelAirTemperature; + if (baseRate >= 0.0) { - SeaLevelAirPressure = InitialAirPressure * Math.Pow(Base, Exponent); + SeaLevelAirPressure = InitialAirPressure * Math.Pow(baseRate, exponent); if (SeaLevelAirPressure < 0.001) { SeaLevelAirPressure = 0.001; @@ -71,21 +71,21 @@ public void CalculateSeaLevelConstants() } /// Calculates the air temperature for a given elevation - /// The elevation for which to calculate the air temperature + /// The elevation for which to calculate the air temperature /// A temperature in degrees kelvin - public double GetAirTemperature(double Elevation) + public double GetAirTemperature(double elevation) { - double x = SeaLevelAirTemperature + TemperatureLapseRate * Elevation; + double x = SeaLevelAirTemperature + TemperatureLapseRate * elevation; return x >= 1.0 ? x : 1.0; } /// Calculates the air density for a given pressure and temperature - /// The air pressure in Pa - /// The air temperature in degrees kelvin + /// The air pressure in Pa + /// The air temperature in degrees kelvin /// The air density in kg/m³ - public double GetAirDensity(double AirPressure, double AirTemperature) + public double GetAirDensity(double airPressure, double airTemperature) { - double x = AirPressure * MolarMass / (UniversalGasConstant * AirTemperature); + double x = airPressure * MolarMass / (UniversalGasConstant * airTemperature); return x >= 0.001 ? x : 0.001; } @@ -93,45 +93,45 @@ public double GetAirDensity(double AirPressure, double AirTemperature) /// The air density in kg/m³ public double GetAirDensity(double elevation) { - double AirTemperature = GetAirTemperature(elevation); - double AirPressure = GetAirPressure(elevation, AirTemperature); - double x = AirPressure * MolarMass / (UniversalGasConstant * AirTemperature); + double airTemperature = GetAirTemperature(elevation); + double airPressure = GetAirPressure(elevation, airTemperature); + double x = airPressure * MolarMass / (UniversalGasConstant * airTemperature); return x >= 0.001 ? x : 0.001; } /// Calculates the air pressure for a given elevation and temperature - /// The elevation in m - /// The air temperature in degrees kelvin + /// The elevation in m + /// The air temperature in degrees kelvin /// The air pressure in Pa - public double GetAirPressure(double Elevation, double AirTemperature) + public double GetAirPressure(double elevation, double airTemperature) { - double Exponent = -AccelerationDueToGravity * MolarMass / (UniversalGasConstant * TemperatureLapseRate); - double Base = 1.0 + TemperatureLapseRate * Elevation / SeaLevelAirTemperature; - if (!(Base >= 0.0)) + double exponent = -AccelerationDueToGravity * MolarMass / (UniversalGasConstant * TemperatureLapseRate); + double baseRate = 1.0 + TemperatureLapseRate * elevation / SeaLevelAirTemperature; + if (!(baseRate >= 0.0)) { return 0.001; } - double x = SeaLevelAirPressure * Math.Pow(Base, Exponent); + double x = SeaLevelAirPressure * Math.Pow(baseRate, exponent); return x >= 0.001 ? x : 0.001; } /// Calculates the speed of sound for a given air pressure and temperature - /// The air pressure in Pa - /// The air temperature in degrees kelvin + /// The air pressure in Pa + /// The air temperature in degrees kelvin /// The speed of sound in m/s - public double GetSpeedOfSound(double AirPressure, double AirTemperature) + public double GetSpeedOfSound(double airPressure, double airTemperature) { - double AirDensity = GetAirDensity(AirPressure, AirTemperature); - return Math.Sqrt(CoefficientOfStiffness / AirDensity); + double airDensity = GetAirDensity(airPressure, airTemperature); + return Math.Sqrt(CoefficientOfStiffness / airDensity); } /// Calculates the speed of sound for a given air density - /// The air density + /// The air density /// The speed of sound in m/s - public double GetSpeedOfSound(double AirDensity) + public double GetSpeedOfSound(double airDensity) { - return Math.Sqrt(CoefficientOfStiffness / AirDensity); + return Math.Sqrt(CoefficientOfStiffness / airDensity); } } } diff --git a/source/RouteManager2/Climate/Fog.cs b/source/RouteManager2/Climate/Fog.cs index 668020b98..3115e1864 100644 --- a/source/RouteManager2/Climate/Fog.cs +++ b/source/RouteManager2/Climate/Fog.cs @@ -6,9 +6,11 @@ namespace RouteManager2.Climate public struct Fog { /// The offset at which the fog starts + /// Distance from camera public float Start; - + /// The offset at which the fog ends + /// /// Distance from camera public float End; /// The color of the fog @@ -24,14 +26,14 @@ public struct Fog public bool IsLinear; /// Creates a new region of fog - public Fog(float Start, float End, Color24 Color, double TrackPosition, bool IsLinear = true, float Density = 0.0f) + public Fog(float startDistance, float endDistance, Color24 fogColor, double trackPosition, bool isLinear = true, float density = 0.0f) { - this.Start = Start; - this.End = End; - this.Color = Color; - this.TrackPosition = TrackPosition; - this.Density = Density; - this.IsLinear = IsLinear; + Start = startDistance; + End = endDistance; + Color = fogColor; + TrackPosition = trackPosition; + Density = density; + IsLinear = isLinear; } } } diff --git a/source/RouteManager2/Events/Transponder.cs b/source/RouteManager2/Events/Transponder.cs index bfc991b9b..09074433b 100644 --- a/source/RouteManager2/Events/Transponder.cs +++ b/source/RouteManager2/Events/Transponder.cs @@ -58,7 +58,7 @@ public override void Trigger(int direction, TrackFollower trackFollower) if (a >= 0) { - if (currentRoute.Sections[s].Aspects[a].AspectNumber == 0) + if (currentRoute.Sections[s].Aspects[a].Number == 0) { break; } From f8e672c79895488b624d6ddd90dea09dc5c62ed1 Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Mon, 11 Nov 2024 18:08:52 +0000 Subject: [PATCH 5/7] Change: Enforce lowerCamelCase for parameter names (P5) Main program --- source/LibRender2/Menu/AbstractMenu.cs | 6 +- source/OpenBVE/Game/Game.cs | 6 +- source/OpenBVE/Game/Information.cs | 4 +- source/OpenBVE/Game/Menu/Menu.Route.cs | 16 +- source/OpenBVE/Game/Menu/Menu.SingleMenu.cs | 2 +- source/OpenBVE/Game/Menu/Menu.cs | 56 +- source/OpenBVE/Game/MessageManager.cs | 24 +- .../AnimatedObjects/FunctionScripts.cs | 1204 ++++++++--------- .../Game/ObjectManager/ObjectManager.cs | 20 +- source/OpenBVE/Game/PointsOfInterest.cs | 14 +- source/OpenBVE/Game/RouteInfoOverlay.cs | 47 +- .../OpenBVE/Game/Score/Score.ScoreMessage.cs | 2 +- source/OpenBVE/Game/Score/Score.Values.cs | 51 +- source/OpenBVE/Game/Score/Score.cs | 74 +- source/OpenBVE/Game/Timetable.cs | 58 +- source/OpenBVE/Game/TrainManager.cs | 50 +- source/OpenBVE/Game/World.cs | 24 +- source/OpenBVE/Graphics/Renderers/Overlays.cs | 4 +- source/OpenBVE/System/GameWindow.cs | 6 +- .../System/Input/ProcessControls.Digital.cs | 6 +- .../OpenBVE/System/Input/ProcessControls.cs | 2 +- source/OpenBVE/System/MainLoop.cs | 4 +- 22 files changed, 840 insertions(+), 840 deletions(-) diff --git a/source/LibRender2/Menu/AbstractMenu.cs b/source/LibRender2/Menu/AbstractMenu.cs index 5d6c7feb1..a64c98154 100644 --- a/source/LibRender2/Menu/AbstractMenu.cs +++ b/source/LibRender2/Menu/AbstractMenu.cs @@ -160,15 +160,15 @@ public void PopMenu() } /// Processes a scroll wheel event - /// The delta - public virtual void ProcessMouseScroll(int Scroll) + /// The delta + public virtual void ProcessMouseScroll(int scrollDelta) { if (Menus.Length == 0) { return; } // Load the current menu - Menus[CurrMenu].ProcessScroll(Scroll, visibleItems); + Menus[CurrMenu].ProcessScroll(scrollDelta, visibleItems); } /// Processes a mouse move event diff --git a/source/OpenBVE/Game/Game.cs b/source/OpenBVE/Game/Game.cs index 871e7fb9d..e9ebe0c9d 100644 --- a/source/OpenBVE/Game/Game.cs +++ b/source/OpenBVE/Game/Game.cs @@ -25,8 +25,8 @@ internal static partial class Game internal static bool MinimalisticSimulation = false; /// Call this function to reset the game - /// Whether the logs should be reset - internal static void Reset(bool ResetLogs) { + /// Whether the logs should be reset + internal static void Reset(bool resetLogs) { // track manager for (int i = 0; i < Program.CurrentRoute.Tracks.Count; i++) { @@ -59,7 +59,7 @@ internal static void Reset(bool ResetLogs) { Program.CurrentRoute.PreviousFog = new Fog(Program.CurrentRoute.NoFogStart, Program.CurrentRoute.NoFogEnd, Color24.Grey, 0.0); Program.CurrentRoute.CurrentFog = new Fog(Program.CurrentRoute.NoFogStart, Program.CurrentRoute.NoFogEnd, Color24.Grey, 0.5); Program.CurrentRoute.NextFog = new Fog(Program.CurrentRoute.NoFogStart, Program.CurrentRoute.NoFogEnd, Color24.Grey, 1.0); - if (ResetLogs) { + if (resetLogs) { LogRouteName = ""; LogTrainName = ""; LogDateTime = DateTime.Now; diff --git a/source/OpenBVE/Game/Information.cs b/source/OpenBVE/Game/Information.cs index b383dedfd..1ff87a653 100644 --- a/source/OpenBVE/Game/Information.cs +++ b/source/OpenBVE/Game/Information.cs @@ -7,8 +7,8 @@ internal static partial class Game /// The in-game menu system internal static readonly GameMenu Menu = GameMenu.Instance; /// The in-game overlay with route info drawings - internal static readonly RouteInfoOverlay routeInfoOverlay = new RouteInfoOverlay(); + internal static readonly RouteInfoOverlay RouteInfoOverlay = new RouteInfoOverlay(); - internal static readonly SwitchChangeDialog switchChangeDialog = new SwitchChangeDialog(); + internal static readonly SwitchChangeDialog SwitchChangeDialog = new SwitchChangeDialog(); } } diff --git a/source/OpenBVE/Game/Menu/Menu.Route.cs b/source/OpenBVE/Game/Menu/Menu.Route.cs index 4c6fe5715..30f7fc77e 100644 --- a/source/OpenBVE/Game/Menu/Menu.Route.cs +++ b/source/OpenBVE/Game/Menu/Menu.Route.cs @@ -103,13 +103,13 @@ private static void routeWorkerThread_doWork(object sender, DoWorkEventArgs e) if (Program.CurrentHost.Plugins[i].Route != null && Program.CurrentHost.Plugins[i].Route.CanLoadRoute(currentFile)) { // ReSharper disable once RedundantCast - object Route = (object)Program.CurrentRoute; // must cast to allow us to use the ref keyword correctly. - string RailwayFolder = Loading.GetRailwayFolder(currentFile); - string ObjectFolder = Path.CombineDirectory(RailwayFolder, "Object"); - string SoundFolder = Path.CombineDirectory(RailwayFolder, "Sound"); - if (Program.CurrentHost.Plugins[i].Route.LoadRoute(currentFile, RouteEncoding, null, ObjectFolder, SoundFolder, true, ref Route)) + object route = (object)Program.CurrentRoute; // must cast to allow us to use the ref keyword correctly. + string railwayFolder = Loading.GetRailwayFolder(currentFile); + string objectFolder = Path.CombineDirectory(railwayFolder, "Object"); + string soundFolder = Path.CombineDirectory(railwayFolder, "Sound"); + if (Program.CurrentHost.Plugins[i].Route.LoadRoute(currentFile, RouteEncoding, null, objectFolder, soundFolder, true, ref route)) { - Program.CurrentRoute = (CurrentRoute) Route; + Program.CurrentRoute = (CurrentRoute) route; } else { @@ -193,8 +193,8 @@ private static void routeWorkerThread_completed(object sender, RunWorkerComplete routePictureBox.Texture = routeImageTexture; // description - string Description = Program.CurrentRoute.Comment.ConvertNewlinesToCrLf(); - routeDescriptionBox.Text = Description.Length != 0 ? Description : System.IO.Path.GetFileNameWithoutExtension(currentFile); + string routeDescription = Program.CurrentRoute.Comment.ConvertNewlinesToCrLf(); + routeDescriptionBox.Text = routeDescription.Length != 0 ? routeDescription : System.IO.Path.GetFileNameWithoutExtension(currentFile); } catch (Exception ex) { diff --git a/source/OpenBVE/Game/Menu/Menu.SingleMenu.cs b/source/OpenBVE/Game/Menu/Menu.SingleMenu.cs index f17f94fcb..d20aab61b 100644 --- a/source/OpenBVE/Game/Menu/Menu.SingleMenu.cs +++ b/source/OpenBVE/Game/Menu/Menu.SingleMenu.cs @@ -502,7 +502,7 @@ public SingleMenu(AbstractMenu menu, MenuType menuType, int data = 0, double Max case MenuType.Control: //Refresh the joystick list Program.Joysticks.RefreshJoysticks(); - Selection = SelectionNone; + Selection = selectionNone; Items = new MenuEntry[4]; // get code name and description Control loadedControl = Interface.CurrentControls[data]; diff --git a/source/OpenBVE/Game/Menu/Menu.cs b/source/OpenBVE/Game/Menu/Menu.cs index 999db3914..5f02960f5 100644 --- a/source/OpenBVE/Game/Menu/Menu.cs +++ b/source/OpenBVE/Game/Menu/Menu.cs @@ -34,12 +34,11 @@ Implemented as a singleton. /// Implements the in-game menu system; manages addition and removal of individual menus. public sealed partial class GameMenu : AbstractMenu { - private static readonly Picturebox LogoPictureBox = new Picturebox(Program.Renderer); - internal static List nextSwitches = new List(); - internal static List previousSwitches = new List(); - internal static bool switchesFound = false; + private static readonly Picturebox logoPictureBox = new Picturebox(Program.Renderer); + private static readonly List nextSwitches = new List(); + private static readonly List previousSwitches = new List(); - private const int SelectionNone = -1; + private const int selectionNone = -1; private double lastTimeElapsed; private static readonly string currentDatabaseFile = Path.CombineFile(Program.FileSystem.PackageDatabaseFolder, "packages.xml"); @@ -90,7 +89,7 @@ public override void Initialize() menuControls.Add(switchMainPictureBox); menuControls.Add(switchSettingPictureBox); menuControls.Add(switchMapPictureBox); - menuControls.Add(LogoPictureBox); + menuControls.Add(logoPictureBox); menuControls.Add(controlTextBox); menuControls.Add(routeDescriptionBox); menuControls.Add(nextImageButton); @@ -143,9 +142,9 @@ private void OnResize() switchSettingPictureBox.BackgroundColor = Color128.Transparent; switchMapPictureBox.Location = new Vector2(imageLoc / 2.0, 0); switchMapPictureBox.Size = new Vector2(quarterWidth * 2.0, Program.Renderer.Screen.Height); - LogoPictureBox.Location = new Vector2(Program.Renderer.Screen.Width / 2.0, Program.Renderer.Screen.Height / 8.0); - LogoPictureBox.Size = new Vector2(Program.Renderer.Screen.Width / 2.0, Program.Renderer.Screen.Width / 2.0); - LogoPictureBox.Texture = Program.Renderer.ProgramLogo; + logoPictureBox.Location = new Vector2(Program.Renderer.Screen.Width / 2.0, Program.Renderer.Screen.Height / 8.0); + logoPictureBox.Size = new Vector2(Program.Renderer.Screen.Width / 2.0, Program.Renderer.Screen.Width / 2.0); + logoPictureBox.Texture = Program.Renderer.ProgramLogo; controlPictureBox.Location = new Vector2(Program.Renderer.Screen.Width / 2.0, Program.Renderer.Screen.Height / 8.0); controlPictureBox.Size = new Vector2(quarterWidth, quarterWidth); controlPictureBox.BackgroundColor = Color128.Transparent; @@ -183,12 +182,12 @@ public override void PushMenu(MenuType type, int data = 0, bool replace = false if (Menus.Length <= CurrMenu) Array.Resize(ref Menus, CurrMenu + 1); - int MaxWidth = 0; + int maxWidth = 0; if ((int)type >= 100) { - MaxWidth = Program.Renderer.Screen.Width / 2; + maxWidth = Program.Renderer.Screen.Width / 2; } - Menus[CurrMenu] = new SingleMenu(this, type, data, MaxWidth); + Menus[CurrMenu] = new SingleMenu(this, type, data, maxWidth); if (replace) { Menus[CurrMenu].Selection = 1; @@ -239,8 +238,8 @@ internal void SetControlJoyCustomData(Guid device, JoystickComponent component, } /// Processes a scroll wheel event - /// The delta - public override void ProcessMouseScroll(int Scroll) + /// The delta + public override void ProcessMouseScroll(int scrollDelta) { if (Menus.Length == 0) { @@ -252,7 +251,7 @@ public override void ProcessMouseScroll(int Scroll) { if (routeDescriptionBox.CurrentlySelected) { - if (Math.Abs(Scroll) == Scroll) + if (Math.Abs(scrollDelta) == scrollDelta) { routeDescriptionBox.VerticalScroll(-1); } @@ -263,7 +262,7 @@ public override void ProcessMouseScroll(int Scroll) return; } } - base.ProcessMouseScroll(Scroll); + base.ProcessMouseScroll(scrollDelta); } public override void DragFile(object sender, OpenTK.Input.FileDropEventArgs e) @@ -357,7 +356,7 @@ public override void ProcessCommand(Translations.Command cmd, double timeElapsed return; } - if (menu.Selection == SelectionNone) // if menu has no selection, do nothing + if (menu.Selection == selectionNone) // if menu has no selection, do nothing return; if (menu.Selection == int.MaxValue) { @@ -683,8 +682,8 @@ public override void ProcessCommand(Translations.Command cmd, double timeElapsed break; case MenuType.ControlReset: Interface.CurrentControls = null; - var File = Path.CombineFile(Program.FileSystem.GetDataFolder("Controls"), "Default.controls"); - Interface.LoadControls(File, out Interface.CurrentControls); + var controlsFile = Path.CombineFile(Program.FileSystem.GetDataFolder("Controls"), "Default.controls"); + Interface.LoadControls(controlsFile, out Interface.CurrentControls); Instance.PopMenu(); break; } @@ -722,7 +721,6 @@ public override void ProcessCommand(Translations.Command cmd, double timeElapsed } menu.Items[2].Text = "Current Setting: " + Program.CurrentRoute.Switches[switchToToggle].CurrentlySetTrack; - switchesFound = false; // as switch has been toggled, need to recalculate switches along route Instance.PushMenu(Instance.Menus[CurrMenu].Type, 0, true); break; case MenuTag.PreviousSwitch: @@ -786,16 +784,16 @@ public override void ProcessCommand(Translations.Command cmd, double timeElapsed private ControlMethod lastControlMethod; - public override void Draw(double RealTimeElapsed) + public override void Draw(double realTimeElapsed) { - pluginKeepAliveTimer += RealTimeElapsed; + pluginKeepAliveTimer += realTimeElapsed; if (pluginKeepAliveTimer > 100000 && TrainManagerBase.PlayerTrain != null && TrainManagerBase.PlayerTrain.Plugin != null) { TrainManagerBase.PlayerTrain.Plugin.KeepAlive(); pluginKeepAliveTimer = 0; } - double TimeElapsed = RealTimeElapsed - lastTimeElapsed; - lastTimeElapsed = RealTimeElapsed; + double timeElapsed = realTimeElapsed - lastTimeElapsed; + lastTimeElapsed = realTimeElapsed; int i; if (CurrMenu < 0 || CurrMenu >= Menus.Length) @@ -884,14 +882,14 @@ public override void Draw(double RealTimeElapsed) } // draw the text - Program.Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(TimeElapsed), new Vector2(itemX, itemY), + Program.Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(timeElapsed), new Vector2(itemX, itemY), menu.Align, ColourHighlight, false); } else if (menu.Items[i] is MenuCaption) - Program.Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(TimeElapsed), new Vector2(itemX, itemY), + Program.Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(timeElapsed), new Vector2(itemX, itemY), menu.Align, ColourCaption, false); else - Program.Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(TimeElapsed), new Vector2(itemX, itemY), + Program.Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(timeElapsed), new Vector2(itemX, itemY), menu.Align, ColourNormal, false); if (menu.Items[i] is MenuOption opt) { @@ -920,7 +918,7 @@ public override void Draw(double RealTimeElapsed) { case MenuType.GameStart: case MenuType.Packages: - LogoPictureBox.Draw(); + logoPictureBox.Draw(); string currentVersion = @"v" + System.Windows.Forms.Application.ProductVersion + Program.VersionSuffix; if (IntPtr.Size != 4) { @@ -979,7 +977,7 @@ public override void Draw(double RealTimeElapsed) } else { - LogoPictureBox.Draw(); + logoPictureBox.Draw(); } break; case MenuType.UninstallRoute: diff --git a/source/OpenBVE/Game/MessageManager.cs b/source/OpenBVE/Game/MessageManager.cs index dcd8ee9f9..07e242588 100644 --- a/source/OpenBVE/Game/MessageManager.cs +++ b/source/OpenBVE/Game/MessageManager.cs @@ -17,28 +17,28 @@ partial class MessageManager internal static readonly List ImageMessages = new List(); /// Adds a message to the in-game interface render queue - /// The text of the message - /// - /// - /// The color of the message text - /// The time this message will display for + /// The text of the message + /// + /// + /// The color of the message text + /// The time this message will display for /// The textual key identifiying this message - internal static void AddMessage(string Text, MessageDependency Depencency, GameMode Mode, MessageColor Color, double Timeout, string key) + internal static void AddMessage(string text, MessageDependency depencency, GameMode mode, MessageColor color, double timeout, string key) { if (TrainManagerBase.PlayerTrain == null) { - Program.FileSystem.AppendToLogFile(Text); + Program.FileSystem.AppendToLogFile(text); return; } - if (Interface.CurrentOptions.GameMode <= Mode) + if (Interface.CurrentOptions.GameMode <= mode) { GameMessage message = new GameMessage { - InternalText = Text, + InternalText = text, MessageToDisplay = String.Empty, - Depencency = Depencency, - Color = Color, - Timeout = Timeout, + Depencency = depencency, + Color = color, + Timeout = timeout, Key = key }; AddMessage(message); diff --git a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs index f3aca3f2c..deca20aac 100644 --- a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs +++ b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs @@ -11,992 +11,992 @@ namespace OpenBve { internal static class FunctionScripts { // execute function script - internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Train, int CarIndex, Vector3 Position, double TrackPosition, int SectionIndex, bool IsPartOfTrain, double TimeElapsed, int CurrentState) { + internal static void ExecuteFunctionScript(FunctionScript function, TrainBase train, int carIndex, Vector3 position, double trackPosition, int sectionIndex, bool isPartOfTrain, double timeElapsed, int currentState) { int s = 0, c = 0; - for (int i = 0; i < Function.InstructionSet.Length; i++) { - switch (Function.InstructionSet[i]) { + for (int i = 0; i < function.InstructionSet.Length; i++) { + switch (function.InstructionSet[i]) { // system case Instructions.SystemHalt: - i = Function.InstructionSet.Length; + i = function.InstructionSet.Length; break; case Instructions.SystemConstant: - Function.Stack[s] = Function.Constants[c]; + function.Stack[s] = function.Constants[c]; s++; c++; break; case Instructions.SystemConstantArray: { - int n = (int)Function.InstructionSet[i + 1]; + int n = (int)function.InstructionSet[i + 1]; for (int j = 0; j < n; j++) { - Function.Stack[s + j] = Function.Constants[c + j]; + function.Stack[s + j] = function.Constants[c + j]; } s += n; c += n; i++; } break; case Instructions.SystemValue: - Function.Stack[s] = Function.LastResult; + function.Stack[s] = function.LastResult; s++; break; case Instructions.SystemDelta: - Function.Stack[s] = TimeElapsed; + function.Stack[s] = timeElapsed; s++; break; // stack case Instructions.StackCopy: - Function.Stack[s] = Function.Stack[s - 1]; + function.Stack[s] = function.Stack[s - 1]; s++; break; case Instructions.StackSwap: - (Function.Stack[s - 1], Function.Stack[s - 2]) = (Function.Stack[s - 2], Function.Stack[s - 1]); + (function.Stack[s - 1], function.Stack[s - 2]) = (function.Stack[s - 2], function.Stack[s - 1]); break; // math case Instructions.MathPlus: - Function.Stack[s - 2] += Function.Stack[s - 1]; + function.Stack[s - 2] += function.Stack[s - 1]; s--; break; case Instructions.MathSubtract: - Function.Stack[s - 2] -= Function.Stack[s - 1]; + function.Stack[s - 2] -= function.Stack[s - 1]; s--; break; case Instructions.MathMinus: - Function.Stack[s - 1] = -Function.Stack[s - 1]; + function.Stack[s - 1] = -function.Stack[s - 1]; break; case Instructions.MathTimes: - Function.Stack[s - 2] *= Function.Stack[s - 1]; + function.Stack[s - 2] *= function.Stack[s - 1]; s--; break; case Instructions.MathDivide: - Function.Stack[s - 2] = Function.Stack[s - 1] == 0.0 ? 0.0 : Function.Stack[s - 2] / Function.Stack[s - 1]; + function.Stack[s - 2] = function.Stack[s - 1] == 0.0 ? 0.0 : function.Stack[s - 2] / function.Stack[s - 1]; s--; break; case Instructions.MathReciprocal: - Function.Stack[s - 1] = Function.Stack[s - 1] == 0.0 ? 0.0 : 1.0 / Function.Stack[s - 1]; + function.Stack[s - 1] = function.Stack[s - 1] == 0.0 ? 0.0 : 1.0 / function.Stack[s - 1]; break; case Instructions.MathPower: { - double a = Function.Stack[s - 2]; - double b = Function.Stack[s - 1]; + double a = function.Stack[s - 2]; + double b = function.Stack[s - 1]; if (b == 2.0) { - Function.Stack[s - 2] = a * a; + function.Stack[s - 2] = a * a; } else if (b == 3.0) { - Function.Stack[s - 2] = a * a * a; + function.Stack[s - 2] = a * a * a; } else if (b == 4.0) { double t = a * a; - Function.Stack[s - 2] = t * t; + function.Stack[s - 2] = t * t; } else if (b == 5.0) { double t = a * a; - Function.Stack[s - 2] = t * t * a; + function.Stack[s - 2] = t * t * a; } else if (b == 6.0) { double t = a * a * a; - Function.Stack[s - 2] = t * t; + function.Stack[s - 2] = t * t; } else if (b == 7.0) { double t = a * a * a; - Function.Stack[s - 2] = t * t * a; + function.Stack[s - 2] = t * t * a; } else if (b == 8.0) { double t = a * a; t *= t; - Function.Stack[s - 2] = t * t; + function.Stack[s - 2] = t * t; } else if (b == 0.0) { - Function.Stack[s - 2] = 1.0; + function.Stack[s - 2] = 1.0; } else if (b < 0.0) { - Function.Stack[s - 2] = 0.0; + function.Stack[s - 2] = 0.0; } else { - Function.Stack[s - 2] = Math.Pow(a, b); + function.Stack[s - 2] = Math.Pow(a, b); } s--; break; } case Instructions.MathRandom: { //Generates a random number between two given doubles - double min = Function.Stack[s - 2]; - double max = Function.Stack[s - 1]; + double min = function.Stack[s - 2]; + double max = function.Stack[s - 1]; var randomGenerator = new Random(); - Function.Stack[s - 2] = min + randomGenerator.NextDouble() * (max - min); + function.Stack[s - 2] = min + randomGenerator.NextDouble() * (max - min); s--; } break; case Instructions.MathRandomInt: { //Generates a random number between two given doubles - int min = (int)Function.Stack[s - 2]; - int max = (int)Function.Stack[s - 1]; + int min = (int)function.Stack[s - 2]; + int max = (int)function.Stack[s - 1]; var randomGenerator = new Random(); - Function.Stack[s - 2] = randomGenerator.Next(min,max); + function.Stack[s - 2] = randomGenerator.Next(min,max); s--; } break; case Instructions.MathIncrement: - Function.Stack[s - 1] += 1.0; + function.Stack[s - 1] += 1.0; break; case Instructions.MathDecrement: - Function.Stack[s - 1] -= 1.0; + function.Stack[s - 1] -= 1.0; break; case Instructions.MathFusedMultiplyAdd: - Function.Stack[s - 3] = Function.Stack[s - 3] * Function.Stack[s - 2] + Function.Stack[s - 1]; + function.Stack[s - 3] = function.Stack[s - 3] * function.Stack[s - 2] + function.Stack[s - 1]; s -= 2; break; case Instructions.MathQuotient: - Function.Stack[s - 2] = Function.Stack[s - 1] == 0.0 ? 0.0 : Math.Floor(Function.Stack[s - 2] / Function.Stack[s - 1]); + function.Stack[s - 2] = function.Stack[s - 1] == 0.0 ? 0.0 : Math.Floor(function.Stack[s - 2] / function.Stack[s - 1]); s--; break; case Instructions.MathMod: - Function.Stack[s - 2] = Function.Stack[s - 1] == 0.0 ? 0.0 : Function.Stack[s - 2] - Function.Stack[s - 1] * Math.Floor(Function.Stack[s - 2] / Function.Stack[s - 1]); + function.Stack[s - 2] = function.Stack[s - 1] == 0.0 ? 0.0 : function.Stack[s - 2] - function.Stack[s - 1] * Math.Floor(function.Stack[s - 2] / function.Stack[s - 1]); s--; break; case Instructions.MathFloor: - Function.Stack[s - 1] = Math.Floor(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Floor(function.Stack[s - 1]); break; case Instructions.MathCeiling: - Function.Stack[s - 1] = Math.Ceiling(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Ceiling(function.Stack[s - 1]); break; case Instructions.MathRound: - Function.Stack[s - 1] = Math.Round(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Round(function.Stack[s - 1]); break; case Instructions.MathMin: - Function.Stack[s - 2] = Function.Stack[s - 2] < Function.Stack[s - 1] ? Function.Stack[s - 2] : Function.Stack[s - 1]; + function.Stack[s - 2] = function.Stack[s - 2] < function.Stack[s - 1] ? function.Stack[s - 2] : function.Stack[s - 1]; s--; break; case Instructions.MathMax: - Function.Stack[s - 2] = Function.Stack[s - 2] > Function.Stack[s - 1] ? Function.Stack[s - 2] : Function.Stack[s - 1]; + function.Stack[s - 2] = function.Stack[s - 2] > function.Stack[s - 1] ? function.Stack[s - 2] : function.Stack[s - 1]; s--; break; case Instructions.MathAbs: - Function.Stack[s - 1] = Math.Abs(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Abs(function.Stack[s - 1]); break; case Instructions.MathSign: - Function.Stack[s - 1] = Math.Sign(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Sign(function.Stack[s - 1]); break; case Instructions.MathExp: - Function.Stack[s - 1] = Math.Exp(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Exp(function.Stack[s - 1]); break; case Instructions.MathLog: - Function.Stack[s - 1] = Log(Function.Stack[s - 1]); + function.Stack[s - 1] = Log(function.Stack[s - 1]); break; case Instructions.MathSqrt: - Function.Stack[s - 1] = Sqrt(Function.Stack[s - 1]); + function.Stack[s - 1] = Sqrt(function.Stack[s - 1]); break; case Instructions.MathSin: - Function.Stack[s - 1] = Math.Sin(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Sin(function.Stack[s - 1]); break; case Instructions.MathCos: - Function.Stack[s - 1] = Math.Cos(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Cos(function.Stack[s - 1]); break; case Instructions.MathTan: - Function.Stack[s - 1] = Tan(Function.Stack[s - 1]); + function.Stack[s - 1] = Tan(function.Stack[s - 1]); break; case Instructions.MathArcTan: - Function.Stack[s - 1] = Math.Atan(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Atan(function.Stack[s - 1]); break; case Instructions.MathPi: - Function.Stack[s] = Math.PI; + function.Stack[s] = Math.PI; s++; break; // comparisons case Instructions.CompareEqual: - Function.Stack[s - 2] = Function.Stack[s - 2] == Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] == function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareUnequal: - Function.Stack[s - 2] = Function.Stack[s - 2] != Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareLess: - Function.Stack[s - 2] = Function.Stack[s - 2] < Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] < function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareGreater: - Function.Stack[s - 2] = Function.Stack[s - 2] > Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] > function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareLessEqual: - Function.Stack[s - 2] = Function.Stack[s - 2] <= Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] <= function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareGreaterEqual: - Function.Stack[s - 2] = Function.Stack[s - 2] >= Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] >= function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareConditional: - Function.Stack[s - 3] = Function.Stack[s - 3] != 0.0 ? Function.Stack[s - 2] : Function.Stack[s - 1]; + function.Stack[s - 3] = function.Stack[s - 3] != 0.0 ? function.Stack[s - 2] : function.Stack[s - 1]; s -= 2; break; // logical case Instructions.LogicalNot: - Function.Stack[s - 1] = Function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; + function.Stack[s - 1] = function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; break; case Instructions.LogicalAnd: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 & Function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 & function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; s--; break; case Instructions.LogicalOr: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 | Function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 | function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; s--; break; case Instructions.LogicalNand: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 & Function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 & function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; s--; break; case Instructions.LogicalNor: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 | Function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 | function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; s--; break; case Instructions.LogicalXor: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 ^ Function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 ^ function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; s--; break; case Instructions.CurrentObjectState: - Function.Stack[s] = CurrentState; + function.Stack[s] = currentState; s++; break; // time/camera case Instructions.TimeSecondsSinceMidnight: - Function.Stack[s] = Program.CurrentRoute.SecondsSinceMidnight; + function.Stack[s] = Program.CurrentRoute.SecondsSinceMidnight; s++; break; case Instructions.TimeHourDigit: - Function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight / 3600.0); + function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight / 3600.0); s++; break; case Instructions.TimeMinuteDigit: - Function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight / 60 % 60); + function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight / 60 % 60); s++; break; case Instructions.TimeSecondDigit: - Function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight % 60); + function.Stack[s] = Math.Floor(Program.CurrentRoute.SecondsSinceMidnight % 60); s++; break; case Instructions.CameraDistance: { - double dx = Program.Renderer.Camera.AbsolutePosition.X - Position.X; - double dy = Program.Renderer.Camera.AbsolutePosition.Y - Position.Y; - double dz = Program.Renderer.Camera.AbsolutePosition.Z - Position.Z; - Function.Stack[s] = Math.Sqrt(dx * dx + dy * dy + dz * dz); + double dx = Program.Renderer.Camera.AbsolutePosition.X - position.X; + double dy = Program.Renderer.Camera.AbsolutePosition.Y - position.Y; + double dz = Program.Renderer.Camera.AbsolutePosition.Z - position.Z; + function.Stack[s] = Math.Sqrt(dx * dx + dy * dy + dz * dz); s++; } break; case Instructions.CameraXDistance: { - Function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.X - Position.X; + function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.X - position.X; s++; } break; case Instructions.CameraYDistance: { - Function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Y - Position.Y; + function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Y - position.Y; s++; } break; case Instructions.CameraZDistance: { - Function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Z - Position.Z; + function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Z - position.Z; s++; } break; case Instructions.BillboardX: { - Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - Position; - Function.Stack[s] = Math.Atan2(toCamera.Y, -toCamera.Z); + Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - position; + function.Stack[s] = Math.Atan2(toCamera.Y, -toCamera.Z); s++; } break; case Instructions.BillboardY: { - Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - Position; - Function.Stack[s] = Math.Atan2(-toCamera.Z, toCamera.X); + Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - position; + function.Stack[s] = Math.Atan2(-toCamera.Z, toCamera.X); s++; } break; case Instructions.CameraView: //Returns whether the camera is in interior or exterior mode if (Program.Renderer.Camera.CurrentMode == CameraViewMode.Interior || Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead) { - Function.Stack[s] = 0; + function.Stack[s] = 0; } else { - Function.Stack[s] = 1; + function.Stack[s] = 1; } s++; break; // train case Instructions.PlayerTrain: - if (IsPartOfTrain && Train != null) + if (isPartOfTrain && train != null) { - Function.Stack[s] = Train.IsPlayerTrain ? 1.0 : 0.0; + function.Stack[s] = train.IsPlayerTrain ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainCars: - if (Train != null) { - Function.Stack[s] = Train.Cars.Length; + if (train != null) { + function.Stack[s] = train.Cars.Length; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainDestination: - if (Train != null) { - Function.Stack[s] = Train.Destination; + if (train != null) { + function.Stack[s] = train.Destination; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainLength: - if (Train != null) { - Function.Stack[s] = Train.Length; + if (train != null) { + function.Stack[s] = train.Length; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainSpeed: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CurrentSpeed; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CurrentSpeed; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainSpeedOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CurrentSpeed; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CurrentSpeed; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.TrainSpeedometer: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].Specs.PerceivedSpeed; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].Specs.PerceivedSpeed; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainSpeedometerOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].Specs.PerceivedSpeed; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].Specs.PerceivedSpeed; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.TrainAcceleration: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].Specs.Acceleration; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].Specs.Acceleration; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainAccelerationOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].Specs.Acceleration; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].Specs.Acceleration; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.TrainAccelerationMotor: - if (Train != null) { - Function.Stack[s] = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - if (Train.Cars[j].Specs.IsMotorCar) { + if (train != null) { + function.Stack[s] = 0.0; + for (int j = 0; j < train.Cars.Length; j++) { + if (train.Cars[j].Specs.IsMotorCar) { // hack: MotorAcceleration does not distinguish between forward/backward - if (Train.Cars[j].Specs.MotorAcceleration < 0.0) { - Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * Math.Sign(Train.Cars[j].CurrentSpeed); - } else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) { - Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual; + if (train.Cars[j].Specs.MotorAcceleration < 0.0) { + function.Stack[s] = train.Cars[j].Specs.MotorAcceleration * Math.Sign(train.Cars[j].CurrentSpeed); + } else if (train.Cars[j].Specs.MotorAcceleration > 0.0) { + function.Stack[s] = train.Cars[j].Specs.MotorAcceleration * (double)train.Handles.Reverser.Actual; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } break; } } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainAccelerationMotorOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { // hack: MotorAcceleration does not distinguish between forward/backward - if (Train.Cars[j].Specs.MotorAcceleration < 0.0) { - Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * Math.Sign(Train.Cars[j].CurrentSpeed); - } else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) { - Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual; + if (train.Cars[j].Specs.MotorAcceleration < 0.0) { + function.Stack[s - 1] = train.Cars[j].Specs.MotorAcceleration * Math.Sign(train.Cars[j].CurrentSpeed); + } else if (train.Cars[j].Specs.MotorAcceleration > 0.0) { + function.Stack[s - 1] = train.Cars[j].Specs.MotorAcceleration * (double)train.Handles.Reverser.Actual; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } 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 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 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); + function.Stack[s] = Math.Sqrt(playerDist); s++; break; case Instructions.TrainDistance: - if (Train != null) { + if (train != null) { double dist = double.MaxValue; - for (int j = 0; j < Train.Cars.Length; j++) { - double fx = Train.Cars[j].FrontAxle.Follower.WorldPosition.X - Position.X; - double fy = Train.Cars[j].FrontAxle.Follower.WorldPosition.Y - Position.Y; - double fz = Train.Cars[j].FrontAxle.Follower.WorldPosition.Z - Position.Z; + for (int j = 0; j < train.Cars.Length; j++) { + double fx = train.Cars[j].FrontAxle.Follower.WorldPosition.X - position.X; + double fy = train.Cars[j].FrontAxle.Follower.WorldPosition.Y - position.Y; + double fz = train.Cars[j].FrontAxle.Follower.WorldPosition.Z - position.Z; double f = fx * fx + fy * fy + fz * fz; if (f < dist) dist = f; - double rx = Train.Cars[j].RearAxle.Follower.WorldPosition.X - Position.X; - double ry = Train.Cars[j].RearAxle.Follower.WorldPosition.Y - Position.Y; - double rz = Train.Cars[j].RearAxle.Follower.WorldPosition.Z - Position.Z; + double rx = train.Cars[j].RearAxle.Follower.WorldPosition.X - position.X; + double ry = train.Cars[j].RearAxle.Follower.WorldPosition.Y - position.Y; + double rz = train.Cars[j].RearAxle.Follower.WorldPosition.Z - position.Z; double r = rx * rx + ry * ry + rz * rz; if (r < dist) dist = r; } - Function.Stack[s] = Math.Sqrt(dist); + function.Stack[s] = Math.Sqrt(dist); } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainDistanceToCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - double x = 0.5 * (Train.Cars[j].FrontAxle.Follower.WorldPosition.X + Train.Cars[j].RearAxle.Follower.WorldPosition.X) - Position.X; - double y = 0.5 * (Train.Cars[j].FrontAxle.Follower.WorldPosition.Y + Train.Cars[j].RearAxle.Follower.WorldPosition.Y) - Position.Y; - double z = 0.5 * (Train.Cars[j].FrontAxle.Follower.WorldPosition.Z + Train.Cars[j].RearAxle.Follower.WorldPosition.Z) - Position.Z; - Function.Stack[s - 1] = Math.Sqrt(x * x + y * y + z * z); + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + double x = 0.5 * (train.Cars[j].FrontAxle.Follower.WorldPosition.X + train.Cars[j].RearAxle.Follower.WorldPosition.X) - position.X; + double y = 0.5 * (train.Cars[j].FrontAxle.Follower.WorldPosition.Y + train.Cars[j].RearAxle.Follower.WorldPosition.Y) - position.Y; + double z = 0.5 * (train.Cars[j].FrontAxle.Follower.WorldPosition.Z + train.Cars[j].RearAxle.Follower.WorldPosition.Z) - position.Z; + function.Stack[s - 1] = Math.Sqrt(x * x + y * y + z * z); } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } 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; + function.Stack[s] = trackPosition > pt0 ? trackPosition - pt0 : trackPosition < pt1 ? trackPosition - pt1 : 0.0; s++; break; case Instructions.TrainTrackDistance: - if (Train != null) { - double t0 = Train.FrontCarTrackPosition; - double t1 = Train.RearCarTrackPosition; - Function.Stack[s] = TrackPosition > t0 ? TrackPosition - t0 : TrackPosition < t1 ? TrackPosition - t1 : 0.0; + if (train != null) { + double t0 = train.FrontCarTrackPosition; + double t1 = train.RearCarTrackPosition; + function.Stack[s] = trackPosition > t0 ? trackPosition - t0 : trackPosition < t1 ? trackPosition - t1 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.CurveRadius: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } else { - Function.Stack[s - 1] = (Train.Cars[CarIndex].FrontAxle.Follower.CurveRadius + Train.Cars[CarIndex].RearAxle.Follower.CurveRadius) / 2; + function.Stack[s - 1] = (train.Cars[carIndex].FrontAxle.Follower.CurveRadius + train.Cars[carIndex].RearAxle.Follower.CurveRadius) / 2; } break; case Instructions.CurveRadiusOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = (Train.Cars[j].FrontAxle.Follower.CurveRadius + Train.Cars[j].RearAxle.Follower.CurveRadius) / 2; + function.Stack[s - 1] = (train.Cars[j].FrontAxle.Follower.CurveRadius + train.Cars[j].RearAxle.Follower.CurveRadius) / 2; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.FrontAxleCurveRadius: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } else { - Function.Stack[s] = Train.Cars[CarIndex].FrontAxle.Follower.CurveRadius; + function.Stack[s] = train.Cars[carIndex].FrontAxle.Follower.CurveRadius; } break; case Instructions.FrontAxleCurveRadiusOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.CurveRadius; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.CurveRadius; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.RearAxleCurveRadius: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } else { - Function.Stack[s] = Train.Cars[CarIndex].RearAxle.Follower.CurveRadius; + function.Stack[s] = train.Cars[carIndex].RearAxle.Follower.CurveRadius; } break; case Instructions.RearAxleCurveRadiusOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].RearAxle.Follower.CurveRadius; + function.Stack[s - 1] = train.Cars[j].RearAxle.Follower.CurveRadius; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.CurveCant: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } else { - Function.Stack[s] = Train.Cars[CarIndex].FrontAxle.Follower.CurveCant; + function.Stack[s] = train.Cars[carIndex].FrontAxle.Follower.CurveCant; } break; case Instructions.CurveCantOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.CurveCant; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.CurveCant; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.Pitch: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } else { - Function.Stack[s - 1] = Train.Cars[CarIndex].FrontAxle.Follower.Pitch; + function.Stack[s - 1] = train.Cars[carIndex].FrontAxle.Follower.Pitch; } break; case Instructions.PitchOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.Pitch; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.Pitch; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.Odometer: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } else { - Function.Stack[s] = Train.Cars[CarIndex].FrontAxle.Follower.Odometer; + function.Stack[s] = train.Cars[carIndex].FrontAxle.Follower.Odometer; } s++; break; case Instructions.OdometerOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.Odometer; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.Odometer; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.TrainTrackDistanceToCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - double p = 0.5 * (Train.Cars[j].FrontAxle.Follower.TrackPosition + Train.Cars[j].RearAxle.Follower.TrackPosition); - Function.Stack[s - 1] = TrackPosition - p; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + double p = 0.5 * (train.Cars[j].FrontAxle.Follower.TrackPosition + train.Cars[j].RearAxle.Follower.TrackPosition); + function.Stack[s - 1] = trackPosition - p; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; // door case Instructions.Doors: - if (Train != null) { + if (train != null) { double a = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + for (int j = 0; j < train.Cars.Length; j++) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s] = a; + function.Stack[s] = a; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.DoorsIndex: - if (Train != null) { + if (train != null) { double a = 0.0; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s - 1] = a; + function.Stack[s - 1] = a; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.LeftDoors: - if (Train != null) { + if (train != null) { double a = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == -1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + for (int j = 0; j < train.Cars.Length; j++) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == -1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s] = a; + function.Stack[s] = a; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LeftDoorsIndex: - if (Train != null) { + if (train != null) { double a = 0.0; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == -1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == -1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s - 1] = a; + function.Stack[s - 1] = a; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.RightDoors: - if (Train != null) { + if (train != null) { double a = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == 1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + for (int j = 0; j < train.Cars.Length; j++) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == 1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s] = a; + function.Stack[s] = a; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.RightDoorsIndex: - if (Train != null) { + if (train != null) { double a = 0.0; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == 1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == 1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s - 1] = a; + function.Stack[s - 1] = a; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.LeftDoorsTarget: - if (Train != null) { + if (train != null) { bool q = false; - for (int j = 0; j < Train.Cars.Length; j++) { - if (Train.Cars[j].Doors[0].AnticipatedOpen) { + for (int j = 0; j < train.Cars.Length; j++) { + if (train.Cars[j].Doors[0].AnticipatedOpen) { q = true; break; } } - Function.Stack[s] = q ? 1.0 : 0.0; + function.Stack[s] = q ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LeftDoorsTargetIndex: - if (Train != null) { + if (train != null) { bool q = false; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[0].AnticipatedOpen) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[0].AnticipatedOpen) { q = true; break; } } } - Function.Stack[s - 1] = q ? 1.0 : 0.0; + function.Stack[s - 1] = q ? 1.0 : 0.0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.RightDoorsTarget: - if (Train != null) { + if (train != null) { bool q = false; - for (int j = 0; j < Train.Cars.Length; j++) { - if (Train.Cars[j].Doors[1].AnticipatedOpen) { + for (int j = 0; j < train.Cars.Length; j++) { + if (train.Cars[j].Doors[1].AnticipatedOpen) { q = true; break; } } - Function.Stack[s] = q ? 1.0 : 0.0; + function.Stack[s] = q ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.RightDoorsTargetIndex: - if (Train != null) { + if (train != null) { bool q = false; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[1].AnticipatedOpen) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[1].AnticipatedOpen) { q = true; break; } } } - Function.Stack[s - 1] = q ? 1.0 : 0.0; + function.Stack[s - 1] = q ? 1.0 : 0.0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.LeftDoorButton: - if (Train != null) + if (train != null) { - Function.Stack[s] = Train.Cars[Train.DriverCar].Doors[0].ButtonPressed ? 1.0 : 0.0; + function.Stack[s] = train.Cars[train.DriverCar].Doors[0].ButtonPressed ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.RightDoorButton: - if (Train != null) + if (train != null) { - Function.Stack[s] = Train.Cars[Train.DriverCar].Doors[1].ButtonPressed ? 1.0 : 0.0; + function.Stack[s] = train.Cars[train.DriverCar].Doors[1].ButtonPressed ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PilotLamp: - if (Train != null) { - if (Train.SafetySystems.PilotLamp.Lit) + if (train != null) { + if (train.SafetySystems.PilotLamp.Lit) { - Function.Stack[s] = 1.0; + function.Stack[s] = 1.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PassAlarm: - if (Train != null) { - if (Train.SafetySystems.PassAlarm.Lit) + if (train != null) { + if (train.SafetySystems.PassAlarm.Lit) { - Function.Stack[s] = 1.0; + function.Stack[s] = 1.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.StationAdjustAlarm: - if (Train != null) { - if (Train.SafetySystems.StationAdjust.Lit) + if (train != null) { + if (train.SafetySystems.StationAdjust.Lit) { - Function.Stack[s] = 1.0; + function.Stack[s] = 1.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.Headlights: - if (Train != null) + if (train != null) { - Function.Stack[s] = Train.SafetySystems.Headlights.CurrentState; + function.Stack[s] = train.SafetySystems.Headlights.CurrentState; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; // handles case Instructions.ReverserNotch: - if (Train != null) { - Function.Stack[s] = (double)Train.Handles.Reverser.Driver; + if (train != null) { + function.Stack[s] = (double)train.Handles.Reverser.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PowerNotch: - if (Train != null) { - Function.Stack[s] = Train.Handles.Power.Driver; + if (train != null) { + function.Stack[s] = train.Handles.Power.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PowerNotches: - if (Train != null) { - Function.Stack[s] = Train.Handles.Power.MaximumNotch; + if (train != null) { + function.Stack[s] = train.Handles.Power.MaximumNotch; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LocoBrakeNotch: - if (Train != null && Train.Handles.LocoBrake != null) { - Function.Stack[s] = Train.Handles.LocoBrake.Driver; + if (train != null && train.Handles.LocoBrake != null) { + function.Stack[s] = train.Handles.LocoBrake.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LocoBrakeNotches: - if (Train != null) { - Function.Stack[s] = Train.Handles.LocoBrake.MaximumNotch; + if (train != null) { + function.Stack[s] = train.Handles.LocoBrake.MaximumNotch; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotch: - if (Train != null) { - Function.Stack[s] = Train.Handles.Brake.Driver; + if (train != null) { + function.Stack[s] = train.Handles.Brake.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotches: - if (Train != null) { - if (Train.Handles.Brake is AirBrakeHandle) { - Function.Stack[s] = 2.0; + if (train != null) { + if (train.Handles.Brake is AirBrakeHandle) { + function.Stack[s] = 2.0; } else { - Function.Stack[s] = Train.Handles.Brake.MaximumNotch; + function.Stack[s] = train.Handles.Brake.MaximumNotch; } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotchLinear: - if (Train != null) { - if (Train.Handles.Brake is AirBrakeHandle) { - if (Train.Handles.EmergencyBrake.Driver) { - Function.Stack[s] = 3.0; + if (train != null) { + if (train.Handles.Brake is AirBrakeHandle) { + if (train.Handles.EmergencyBrake.Driver) { + function.Stack[s] = 3.0; } else { - Function.Stack[s] = Train.Handles.Brake.Driver; + function.Stack[s] = train.Handles.Brake.Driver; } - } else if (Train.Handles.HasHoldBrake) { - if (Train.Handles.EmergencyBrake.Driver) { - Function.Stack[s] = Train.Handles.Brake.MaximumNotch + 2.0; - } else if (Train.Handles.Brake.Driver > 0) { - Function.Stack[s] = Train.Handles.Brake.Driver + 1.0; + } else if (train.Handles.HasHoldBrake) { + if (train.Handles.EmergencyBrake.Driver) { + function.Stack[s] = train.Handles.Brake.MaximumNotch + 2.0; + } else if (train.Handles.Brake.Driver > 0) { + function.Stack[s] = train.Handles.Brake.Driver + 1.0; } else { - Function.Stack[s] = Train.Handles.HoldBrake.Driver ? 1.0 : 0.0; + function.Stack[s] = train.Handles.HoldBrake.Driver ? 1.0 : 0.0; } } else { - if (Train.Handles.EmergencyBrake.Driver) { - Function.Stack[s] = Train.Handles.Brake.MaximumNotch + 1.0; + if (train.Handles.EmergencyBrake.Driver) { + function.Stack[s] = train.Handles.Brake.MaximumNotch + 1.0; } else { - Function.Stack[s] = Train.Handles.Brake.Driver; + function.Stack[s] = train.Handles.Brake.Driver; } } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotchesLinear: - if (Train != null) { - if (Train.Handles.Brake is AirBrakeHandle) { - Function.Stack[s] = 3.0; - } else if (Train.Handles.HasHoldBrake) { - Function.Stack[s] = Train.Handles.Brake.MaximumNotch + 2.0; + if (train != null) { + if (train.Handles.Brake is AirBrakeHandle) { + function.Stack[s] = 3.0; + } else if (train.Handles.HasHoldBrake) { + function.Stack[s] = train.Handles.Brake.MaximumNotch + 2.0; } else { - Function.Stack[s] = Train.Handles.Brake.MaximumNotch + 1.0; + function.Stack[s] = train.Handles.Brake.MaximumNotch + 1.0; } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.EmergencyBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.EmergencyBrake.Driver ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.EmergencyBrake.Driver ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.Klaxon: - if (Train != null && TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns != null) + 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++) { @@ -1008,203 +1008,203 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr */ if (Program.Sounds.IsPlaying(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns[j].Source)) { - Function.Stack[s] = j + 1; + function.Stack[s] = j + 1; break; } if (j == TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns.Length -1) { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PrimaryKlaxon: - if (Train != null) + if (train != null) { - Function.Stack[s] = Program.Sounds.IsPlaying(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns[0].Source) ? 1.0 : 0.0; + 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; + function.Stack[s] = 0.0; } s++; break; case Instructions.SecondaryKlaxon: - if (Train != null) + if (train != null) { - Function.Stack[s] = Program.Sounds.IsPlaying(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns[1].Source) ? 1.0 : 0.0; + 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; + function.Stack[s] = 0.0; } s++; break; case Instructions.MusicKlaxon: - if (Train != null) + if (train != null) { - Function.Stack[s] = Program.Sounds.IsPlaying(TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Horns[2].Source) ? 1.0 : 0.0; + 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; + function.Stack[s] = 0.0; } s++; break; case Instructions.HasAirBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.Brake is AirBrakeHandle ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.Brake is AirBrakeHandle ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.HoldBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.HoldBrake.Driver ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.HoldBrake.Driver ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.HasHoldBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.HasHoldBrake ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.HasHoldBrake ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.ConstSpeed: - if (Train != null) { - Function.Stack[s] = Train.Specs.CurrentConstSpeed ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Specs.CurrentConstSpeed ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.HasConstSpeed: - if (Train != null) { - Function.Stack[s] = Train.Specs.HasConstSpeed ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Specs.HasConstSpeed ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; // brake case Instructions.BrakeMainReservoir: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.MainReservoir.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.MainReservoir.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeMainReservoirOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.MainReservoir.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.MainReservoir.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeEqualizingReservoir: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.EqualizingReservoir.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.EqualizingReservoir.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeEqualizingReservoirOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.EqualizingReservoir.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.EqualizingReservoir.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeBrakePipe: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakePipe.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.BrakePipe.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeBrakePipeOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakePipe.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.BrakePipe.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeBrakeCylinder: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakeCylinder.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.BrakeCylinder.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeBrakeCylinderOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakeCylinder.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.BrakeCylinder.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeStraightAirPipe: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.StraightAirPipe.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.StraightAirPipe.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeStraightAirPipeOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.StraightAirPipe.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.StraightAirPipe.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; // safety case Instructions.SafetyPluginAvailable: - if (Train != null && Train.IsPlayerTrain && Train.Plugin != null) { - Function.Stack[s] = TrainManager.PlayerTrain.Plugin.IsDefault ? 0.0 : 1.0; + if (train != null && train.IsPlayerTrain && train.Plugin != null) { + function.Stack[s] = TrainManager.PlayerTrain.Plugin.IsDefault ? 0.0 : 1.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.SafetyPluginState: - if (Train == null || Train.Plugin == null) { - Function.Stack[s - 1] = 0.0; + if (train == null || train.Plugin == null) { + function.Stack[s - 1] = 0.0; } else { - int n = (int)Math.Round(Function.Stack[s - 1]); - if (n >= 0 & n < Train.Plugin.Panel.Length) { - Function.Stack[s - 1] = Train.Plugin.Panel[n]; + int n = (int)Math.Round(function.Stack[s - 1]); + if (n >= 0 & n < train.Plugin.Panel.Length) { + function.Stack[s - 1] = train.Plugin.Panel[n]; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; // timetable @@ -1213,10 +1213,10 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr { case DisplayedTimetable.Custom: case DisplayedTimetable.Default: - Function.Stack[s] = 1.0; + function.Stack[s] = 1.0; break; case DisplayedTimetable.None: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; break; } s++; break; @@ -1225,35 +1225,35 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr switch (Program.Renderer.CurrentTimetable) { case DisplayedTimetable.Custom: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; break; default: - Function.Stack[s] = -1.0; + function.Stack[s] = -1.0; break; } s++; break; case Instructions.DistanceNextStation: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant + function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant } else { int stationIdx; - if (Train.Station >= 0 && Train.StationState != TrainStopState.Completed) + if (train.Station >= 0 && train.StationState != TrainStopState.Completed) { - stationIdx = Train.LastStation; + stationIdx = train.LastStation; } else { - stationIdx = Train.LastStation + 1; + stationIdx = train.LastStation + 1; } if (stationIdx > Program.CurrentRoute.Stations.Length - 1) { - stationIdx = Train.LastStation; + stationIdx = train.LastStation; } - int n = Program.CurrentRoute.Stations[stationIdx].GetStopIndex(Train.NumberOfCars); - double p0 = Train.FrontCarTrackPosition; + int n = Program.CurrentRoute.Stations[stationIdx].GetStopIndex(train.NumberOfCars); + double p0 = train.FrontCarTrackPosition; double p1; if (Program.CurrentRoute.Stations[stationIdx].Stops.Length > 0) { @@ -1263,24 +1263,24 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr { p1 = Program.CurrentRoute.Stations[stationIdx].DefaultTrackPosition; } - Function.Stack[s] = p1 - p0; + function.Stack[s] = p1 - p0; } s++; break; case Instructions.DistanceLastStation: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant + function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant } else { int stationIdx; - if (Train.Station >= 0 && Train.StationState != TrainStopState.Completed) + if (train.Station >= 0 && train.StationState != TrainStopState.Completed) { - stationIdx = Train.LastStation; + stationIdx = train.LastStation; } else { - stationIdx = Train.LastStation + 1; + stationIdx = train.LastStation + 1; } stationIdx -= 1; @@ -1290,8 +1290,8 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr stationIdx = 0; } - int n = Program.CurrentRoute.Stations[stationIdx].GetStopIndex(Train.NumberOfCars); - double p0 = Train.FrontCarTrackPosition; + int n = Program.CurrentRoute.Stations[stationIdx].GetStopIndex(train.NumberOfCars); + double p0 = train.FrontCarTrackPosition; double p1; if (Program.CurrentRoute.Stations[stationIdx].Stops.Length > 0) { @@ -1301,47 +1301,47 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr { p1 = Program.CurrentRoute.Stations[stationIdx].DefaultTrackPosition; } - Function.Stack[s] = p1 - p0; + function.Stack[s] = p1 - p0; } s++; break; case Instructions.StopsNextStation: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; //Not part of a train, so we obviously can't stop at a station.... + function.Stack[s] = 0.0; //Not part of a train, so we obviously can't stop at a station.... } else { int stationIdx; - if (Train.Station >= 0 && Train.StationState != TrainStopState.Completed) + if (train.Station >= 0 && train.StationState != TrainStopState.Completed) { - stationIdx = Train.LastStation; + stationIdx = train.LastStation; } else { - stationIdx = Train.LastStation + 1; + stationIdx = train.LastStation + 1; } if (stationIdx > Program.CurrentRoute.Stations.Length - 1) { - Function.Stack[s] = 0.0; //Passed the terminal station, hence cannot stop again + function.Stack[s] = 0.0; //Passed the terminal station, hence cannot stop again } else { - Function.Stack[s] = Program.CurrentRoute.Stations[stationIdx].StopsHere(Train) ? 1.0 : 0.0; + function.Stack[s] = Program.CurrentRoute.Stations[stationIdx].StopsHere(train) ? 1.0 : 0.0; } } s++; break; case Instructions.DistanceStation: - if (Train != null) + if (train != null) { - int stationIdx = (int)Math.Round(Function.Stack[s - 1]); //Station index + int stationIdx = (int)Math.Round(function.Stack[s - 1]); //Station index if (stationIdx > Program.CurrentRoute.Stations.Length - 1) { - Function.Stack[s - 1] = 0.0; //Invalid index + function.Stack[s - 1] = 0.0; //Invalid index } else { - int n = Program.CurrentRoute.Stations[stationIdx].GetStopIndex(Train.NumberOfCars); - double p0 = Train.FrontCarTrackPosition; + int n = Program.CurrentRoute.Stations[stationIdx].GetStopIndex(train.NumberOfCars); + double p0 = train.FrontCarTrackPosition; double p1; if (Program.CurrentRoute.Stations[stationIdx].Stops.Length > 0) { @@ -1351,76 +1351,76 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr { p1 = Program.CurrentRoute.Stations[stationIdx].DefaultTrackPosition; } - Function.Stack[s - 1] = p1 - p0; + function.Stack[s - 1] = p1 - p0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.StopsStation: - if (Train != null) + if (train != null) { - int stationIdx = (int)Math.Round(Function.Stack[s - 1]); //Station index + int stationIdx = (int)Math.Round(function.Stack[s - 1]); //Station index if (stationIdx > Program.CurrentRoute.Stations.Length - 1) { - Function.Stack[s - 1] = 0.0; //Invalid index + function.Stack[s - 1] = 0.0; //Invalid index } else { - Function.Stack[s - 1] = Program.CurrentRoute.Stations[stationIdx].StopsHere(Train) ? 1.0 : 0.0; + function.Stack[s - 1] = Program.CurrentRoute.Stations[stationIdx].StopsHere(train) ? 1.0 : 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.NextStation: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant + function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant } else { - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant + function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant } else { - int stationIdx = Train.LastStation + 1; + int stationIdx = train.LastStation + 1; if (stationIdx > Program.CurrentRoute.Stations.Length - 1) { - stationIdx = Train.LastStation; + stationIdx = train.LastStation; } - Function.Stack[s] = stationIdx; + function.Stack[s] = stationIdx; } } s++; break; case Instructions.NextStationStop: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant + function.Stack[s] = 0.0; //Not part of a train, so distance is irrelevant } else { - int stationIdx = Train.LastStation + 1; + int stationIdx = train.LastStation + 1; if (stationIdx > Program.CurrentRoute.Stations.Length - 1) { - stationIdx = Train.LastStation; + stationIdx = train.LastStation; } while (stationIdx < Program.CurrentRoute.Stations.Length - 1) { - if (Program.CurrentRoute.Stations[stationIdx].StopsHere(Train)) + if (Program.CurrentRoute.Stations[stationIdx].StopsHere(train)) { break; } stationIdx++; } - Function.Stack[s] = stationIdx; + function.Stack[s] = stationIdx; } s++; break; case Instructions.TerminalStation: @@ -1433,175 +1433,175 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr break; } } - Function.Stack[s] = idx; + function.Stack[s] = idx; s++; break; case Instructions.RouteLimit: - if (Train == null) + if (train == null) { - Function.Stack[s] = 0.0; //Not part of a train, so irrelevant + function.Stack[s] = 0.0; //Not part of a train, so irrelevant } else { - Function.Stack[s] = Train.CurrentRouteLimit; + function.Stack[s] = train.CurrentRouteLimit; } s++; break; // sections case Instructions.SectionAspectNumber: - if (IsPartOfTrain) { - int nextSectionIndex = Train.CurrentSectionIndex + 1; + if (isPartOfTrain) { + int nextSectionIndex = train.CurrentSectionIndex + 1; if (nextSectionIndex >= 0 & nextSectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[nextSectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[nextSectionIndex].Aspects.Length) { - Function.Stack[s] = Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; + function.Stack[s] = Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; } else { - Function.Stack[s] = 0; + function.Stack[s] = 0; } } - } else if (SectionIndex >= 0 & SectionIndex < Program.CurrentRoute.Sections.Length) { - int a = Program.CurrentRoute.Sections[SectionIndex].CurrentAspect; - if (a >= 0 & a < Program.CurrentRoute.Sections[SectionIndex].Aspects.Length) { - Function.Stack[s] = Program.CurrentRoute.Sections[SectionIndex].Aspects[a].Number; + } else if (sectionIndex >= 0 & sectionIndex < Program.CurrentRoute.Sections.Length) { + int a = Program.CurrentRoute.Sections[sectionIndex].CurrentAspect; + if (a >= 0 & a < Program.CurrentRoute.Sections[sectionIndex].Aspects.Length) { + function.Stack[s] = Program.CurrentRoute.Sections[sectionIndex].Aspects[a].Number; } else { - Function.Stack[s] = 0; + function.Stack[s] = 0; } } else { - Function.Stack[s] = 0; + function.Stack[s] = 0; } s++; break; case Instructions.RainDrop: // n.b. windscreen may be null if we've changed driver car, or this is used in non XML train - if (Train == null || !Train.IsPlayerTrain && Train.Cars[Train.DriverCar].Windscreen != null) { - Function.Stack[s - 1] = 0.0; + if (train == null || !train.IsPlayerTrain && train.Cars[train.DriverCar].Windscreen != null) { + function.Stack[s - 1] = 0.0; } else { - int n = (int)Math.Round(Function.Stack[s - 1]); - if (n >= 0 & n < Train.Cars[Train.DriverCar].Windscreen.RainDrops.Length) { - Function.Stack[s - 1] = Train.Cars[Train.DriverCar].Windscreen.RainDrops[n].Visible && !Train.Cars[Train.DriverCar].Windscreen.RainDrops[n].IsSnowFlake ? 1.0 : 0.0; + int n = (int)Math.Round(function.Stack[s - 1]); + if (n >= 0 & n < train.Cars[train.DriverCar].Windscreen.RainDrops.Length) { + function.Stack[s - 1] = train.Cars[train.DriverCar].Windscreen.RainDrops[n].Visible && !train.Cars[train.DriverCar].Windscreen.RainDrops[n].IsSnowFlake ? 1.0 : 0.0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.SnowFlake: - if (Train == null || !Train.IsPlayerTrain) { - Function.Stack[s - 1] = 0.0; + if (train == null || !train.IsPlayerTrain) { + function.Stack[s - 1] = 0.0; } else { - int n = (int)Math.Round(Function.Stack[s - 1]); - if (n >= 0 & n < Train.Cars[Train.DriverCar].Windscreen.RainDrops.Length) { - Function.Stack[s - 1] = Train.Cars[Train.DriverCar].Windscreen.RainDrops[n].Visible && Train.Cars[Train.DriverCar].Windscreen.RainDrops[n].IsSnowFlake ? 1.0 : 0.0; + int n = (int)Math.Round(function.Stack[s - 1]); + if (n >= 0 & n < train.Cars[train.DriverCar].Windscreen.RainDrops.Length) { + function.Stack[s - 1] = train.Cars[train.DriverCar].Windscreen.RainDrops[n].Visible && train.Cars[train.DriverCar].Windscreen.RainDrops[n].IsSnowFlake ? 1.0 : 0.0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.WiperPosition: - if (Train == null || !Train.IsPlayerTrain) + if (train == null || !train.IsPlayerTrain) { - Function.Stack[s] = 0.0; //Not part of player train, so irrelevant + function.Stack[s] = 0.0; //Not part of player train, so irrelevant } else { - Function.Stack[s] = Train.Cars[Train.DriverCar].Windscreen.Wipers.CurrentPosition; + function.Stack[s] = train.Cars[train.DriverCar].Windscreen.Wipers.CurrentPosition; } s++; break; case Instructions.BrightnessOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].Brightness.CurrentBrightness(Program.Renderer.Lighting.DynamicCabBrightness, 0.0); + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].Brightness.CurrentBrightness(Program.Renderer.Lighting.DynamicCabBrightness, 0.0); } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.TrainCarNumber: - if (!IsPartOfTrain) + if (!isPartOfTrain) { - Function.Stack[s] = -1; + function.Stack[s] = -1; } else { - Function.Stack[s] = CarIndex; + function.Stack[s] = carIndex; } s++; break; case Instructions.WheelSlip: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].FrontAxle.CurrentWheelSlip ? 1 : 0; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].FrontAxle.CurrentWheelSlip ? 1 : 0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.WheelSlipCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.CurrentWheelSlip ? 1 : 0; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].FrontAxle.CurrentWheelSlip ? 1 : 0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.Sanders: { - if (Train != null && Train.Cars[CarIndex].ReAdhesionDevice is Sanders sanders) { - Function.Stack[s] = sanders.Active ? 1 : 0; + if (train != null && train.Cars[carIndex].ReAdhesionDevice is Sanders sanders) { + function.Stack[s] = sanders.Active ? 1 : 0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.SandLevel: { - if (Train != null && Train.Cars[CarIndex].ReAdhesionDevice is Sanders sanders) { - Function.Stack[s] = sanders.SandLevel; + if (train != null && train.Cars[carIndex].ReAdhesionDevice is Sanders sanders) { + function.Stack[s] = sanders.SandLevel; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.SandShots: { - if (Train != null && Train.Cars[CarIndex].ReAdhesionDevice is Sanders sanders) { - Function.Stack[s] = sanders.NumberOfShots; + if (train != null && train.Cars[carIndex].ReAdhesionDevice is Sanders sanders) { + function.Stack[s] = sanders.NumberOfShots; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.DSD: { - if (Train != null && Train.Cars[Train.DriverCar].DSD != null) + if (train != null && train.Cars[train.DriverCar].DSD != null) { - Function.Stack[s] = Train.Cars[Train.DriverCar].DSD.Triggered ? 1 : 0; + function.Stack[s] = train.Cars[train.DriverCar].DSD.Triggered ? 1 : 0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.AmbientTemperature: { - if (Train != null) + if (train != null) { - Function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(Train.Cars[CarIndex].FrontAxle.Follower.WorldPosition.Y + Program.CurrentRoute.Atmosphere.InitialElevation); + function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(train.Cars[carIndex].FrontAxle.Follower.WorldPosition.Y + Program.CurrentRoute.Atmosphere.InitialElevation); } else { - Function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(Position.Y + Program.CurrentRoute.Atmosphere.InitialElevation); + function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(position.Y + Program.CurrentRoute.Atmosphere.InitialElevation); } } s++; break; // default default: - throw new InvalidOperationException("The unknown instruction " + Function.InstructionSet[i] + " was encountered in ExecuteFunctionScript."); + throw new InvalidOperationException("The unknown instruction " + function.InstructionSet[i] + " was encountered in ExecuteFunctionScript."); } } - Function.LastResult = Function.Stack[s - 1]; + function.LastResult = function.Stack[s - 1]; } // mathematical functions diff --git a/source/OpenBVE/Game/ObjectManager/ObjectManager.cs b/source/OpenBVE/Game/ObjectManager/ObjectManager.cs index 26e2f0e99..1065e475d 100644 --- a/source/OpenBVE/Game/ObjectManager/ObjectManager.cs +++ b/source/OpenBVE/Game/ObjectManager/ObjectManager.cs @@ -15,9 +15,9 @@ public static class ObjectManager internal static int AnimatedWorldObjectsUsed = 0; /// Is called once a frame to update all animated objects - /// The total frame time elapsed - /// Whether this is a forced update (e.g. camera change etc) - internal static void UpdateAnimatedWorldObjects(double TimeElapsed, bool ForceUpdate) + /// The total frame time elapsed + /// Whether this is a forced update (e.g. camera change etc) + internal static void UpdateAnimatedWorldObjects(double timeElapsed, bool forceUpdate) { for (int i = 0; i < AnimatedWorldObjectsUsed; i++) { @@ -25,31 +25,31 @@ internal static void UpdateAnimatedWorldObjects(double TimeElapsed, bool ForceUp Vector3 cameraPos = Program.Renderer.Camera.Alignment.Position; cameraPos.Z += Program.Renderer.CameraTrackFollower.TrackPosition; bool visible = AnimatedWorldObjects[i].IsVisible(cameraPos, Program.CurrentRoute.CurrentBackground.BackgroundImageDistance, Program.Renderer.Camera.ExtraViewingDistance); - if (visible | ForceUpdate) + if (visible | forceUpdate) { //Find the closest train train = Program.CurrentHost.ClosestTrain(AnimatedWorldObjects[i].RelativeTrackPosition); } - if (ForceUpdate) + if (forceUpdate) { if (Interface.CurrentOptions.DelayedAnimatedUpdates == false || AnimatedWorldObjects[i].TrackPosition - Math.Abs(Program.Renderer.CameraTrackFollower.TrackPosition) <= 5000 || AnimatedWorldObjects[i].Object.TrackFollowerFunction != null) { - AnimatedWorldObjects[i].Update(train, TimeElapsed, true, visible); + AnimatedWorldObjects[i].Update(train, timeElapsed, true, visible); } } else { - AnimatedWorldObjects[i].Update(train, TimeElapsed, false, visible); + AnimatedWorldObjects[i].Update(train, timeElapsed, false, visible); } } } /// Updates any TFOs within the world after a jump - /// The train which has jumped - public static void ProcessJump(AbstractTrain Train) + /// The train which has jumped + public static void ProcessJump(AbstractTrain train) { - if (Train.IsPlayerTrain) + if (train.IsPlayerTrain) { for (int i = 0; i < AnimatedWorldObjects.Length; i++) { diff --git a/source/OpenBVE/Game/PointsOfInterest.cs b/source/OpenBVE/Game/PointsOfInterest.cs index 614e61ab5..0cc24acc1 100644 --- a/source/OpenBVE/Game/PointsOfInterest.cs +++ b/source/OpenBVE/Game/PointsOfInterest.cs @@ -8,20 +8,20 @@ namespace OpenBve internal static partial class Game { /// Moves the camera to a point of interest - /// The value of the jump to perform: + /// The value of the jump to perform: /// -1= Previous POI /// 0= Return to currently selected POI (From cab etc.) /// 1= Next POI - /// Whether the relative camera position should be retained + /// Whether the relative camera position should be retained /// False if the previous / next POI would be outside those defined, true otherwise - internal static bool ApplyPointOfInterest(int Value, bool Relative) + internal static bool ApplyPointOfInterest(int newValue, bool newValueIsRelative) { double t = 0.0; int j = -1; - if (Relative) + if (newValueIsRelative) { // relative - if (Value < 0) + if (newValue < 0) { // previous poi t = double.NegativeInfinity; @@ -37,7 +37,7 @@ internal static bool ApplyPointOfInterest(int Value, bool Relative) } } } - else if (Value > 0) + else if (newValue > 0) { // next poi t = double.PositiveInfinity; @@ -57,7 +57,7 @@ internal static bool ApplyPointOfInterest(int Value, bool Relative) else { // absolute - j = Value >= 0 & Value < Program.CurrentRoute.PointsOfInterest.Length ? Value : -1; + j = newValue >= 0 & newValue < Program.CurrentRoute.PointsOfInterest.Length ? newValue : -1; } // process poi if (j < 0) return false; diff --git a/source/OpenBVE/Game/RouteInfoOverlay.cs b/source/OpenBVE/Game/RouteInfoOverlay.cs index 5602babbb..3415c618a 100644 --- a/source/OpenBVE/Game/RouteInfoOverlay.cs +++ b/source/OpenBVE/Game/RouteInfoOverlay.cs @@ -14,13 +14,12 @@ ROUTE INFO OVERLAY /// Displays an in-game overlay with information about the route, including a map and gradient profile public class RouteInfoOverlay { - private enum state + private enum OverlayState { - none = 0, - map, - gradient, - numOf - }; + None = 0, + Map, + Gradient, + } /// The width of the gradient position bar in pixels private const int gradientPosWidth= 2; @@ -35,7 +34,7 @@ private enum state /// The color used to render the dot for the player train private static readonly Color128 playerTrainDotColour = Color128.Green; - private state currentState = state.none; + private OverlayState currentOverlayState = OverlayState.None; private Texture gradientImage; private Vector2 gradientSize; private Texture mapImage; @@ -49,22 +48,22 @@ internal bool ProcessCommand(Translations.Command command) if (command != Translations.Command.RouteInformation) // only accept RouteInformation command return false; // cycle through available state - setState( (state)((int)(currentState + 1) % (int)state.numOf) ); + SetState((OverlayState)((int)(currentOverlayState + 1) % 3)); return true; } /// Displays the current state into the simulation window. public void Show() { - if (currentState == state.none) + if (currentOverlayState == OverlayState.None) return; - Vector2 Pos = Vector2.Null; + Vector2 currentPosition = Vector2.Null; Vector2 origin = Vector2.Null; GL.Color4(1.0f, 1.0f, 1.0f, 1.0f); // draw the relevant image - switch (currentState) + switch (currentOverlayState) { - case state.map: + case OverlayState.Map: Program.Renderer.Rectangle.Draw(mapImage, origin, mapSize); // get current train position int n = Program.TrainManager.Trains.Length; @@ -73,44 +72,44 @@ public void Show() int trainX = (int)Program.TrainManager.Trains[i].Cars[0].FrontAxle.Follower.WorldPosition.X; int trainZ = (int)Program.TrainManager.Trains[i].Cars[0].FrontAxle.Follower.WorldPosition.Z; // convert to route map coordinates - Pos.X = mapSize.X * (trainX - Program.CurrentRoute.Information.RouteMinX) / + currentPosition.X = mapSize.X * (trainX - Program.CurrentRoute.Information.RouteMinX) / (Program.CurrentRoute.Information.RouteMaxX - Program.CurrentRoute.Information.RouteMinX) - trainDotRadius; - Pos.Y = mapSize.Y - mapSize.Y * (trainZ - Program.CurrentRoute.Information.RouteMinZ) / + currentPosition.Y = mapSize.Y - mapSize.Y * (trainZ - Program.CurrentRoute.Information.RouteMinZ) / (Program.CurrentRoute.Information.RouteMaxZ - Program.CurrentRoute.Information.RouteMinZ) - trainDotRadius; // draw a dot at current train position - Program.Renderer.Rectangle.Draw(null, Pos, + Program.Renderer.Rectangle.Draw(null, currentPosition, new Vector2(trainDotDiameter, trainDotDiameter), Program.TrainManager.Trains[i].IsPlayerTrain ? playerTrainDotColour : trainDotColour); } break; - case state.gradient: + case OverlayState.Gradient: Program.Renderer.Rectangle.Draw(gradientImage, origin, gradientSize); // get current train position in track int trackPos = (int)(TrainManager.PlayerTrain.FrontCarTrackPosition); // convert to gradient profile offset - Pos.X = gradientSize.Y * (trackPos - Program.CurrentRoute.Information.GradientMinTrack) / + currentPosition.X = gradientSize.Y * (trackPos - Program.CurrentRoute.Information.GradientMinTrack) / (Program.CurrentRoute.Information.GradientMaxTrack - Program.CurrentRoute.Information.GradientMinTrack); // draw a vertical bar at the current train position - Program.Renderer.Rectangle.Draw(null, new Vector2(Pos.X, gradientSize.Y / 2), + Program.Renderer.Rectangle.Draw(null, new Vector2(currentPosition.X, gradientSize.Y / 2), new Vector2(gradientPosWidth, gradientSize.Y / 2), gradientPosBar); break; } } /// Sets the state, intializing any required resource. - /// The new state to set to. - private void setState(state newState) + /// The new state to set to. + private void SetState(OverlayState newOverlayState) { - switch (newState) + switch (newOverlayState) { - case state.map: + case OverlayState.Map: if (mapImage == null) { mapImage = new Texture(Program.CurrentRoute.Information.RouteMap); mapSize = new Vector2(Program.CurrentRoute.Information.RouteMap.Width, Program.CurrentRoute.Information.RouteMap.Height); } break; - case state.gradient: + case OverlayState.Gradient: if (gradientImage == null) { gradientImage = new Texture(Program.CurrentRoute.Information.GradientProfile); @@ -118,7 +117,7 @@ private void setState(state newState) } break; } - currentState = newState; + currentOverlayState = newOverlayState; } } } diff --git a/source/OpenBVE/Game/Score/Score.ScoreMessage.cs b/source/OpenBVE/Game/Score/Score.ScoreMessage.cs index 81c7c9c4e..b86ed1348 100644 --- a/source/OpenBVE/Game/Score/Score.ScoreMessage.cs +++ b/source/OpenBVE/Game/Score/Score.ScoreMessage.cs @@ -6,7 +6,7 @@ namespace OpenBve internal static partial class Game { /// Holds all current score messages to be rendered - internal static ScoreMessage[] ScoreMessages = new ScoreMessage[] { }; + internal static ScoreMessage[] ScoreMessages = { }; /// Holds the current on-screen size in px of the area occupied by score messages internal static Vector2 ScoreMessagesRendererSize = new Vector2(16.0, 16.0); diff --git a/source/OpenBVE/Game/Score/Score.Values.cs b/source/OpenBVE/Game/Score/Score.Values.cs index 8f25394e5..b0455c90e 100644 --- a/source/OpenBVE/Game/Score/Score.Values.cs +++ b/source/OpenBVE/Game/Score/Score.Values.cs @@ -2,29 +2,32 @@ { internal static partial class Game { - /// The default number of points lost when the doors are opened unexpectedly - private const double ScoreFactorOpenedDoors = -10.0; - /// The default number of points lost per second when running overspeed - private const double ScoreFactorOverspeed = -1.0; - /// The default number of points lost when toppling the train through overspeed - private const double ScoreFactorToppling = -10.0; - /// The default number of points lost per second late - private const double ScoreFactorStationLate = -0.333333333333333; - /// The default number of points lost when missing a station's defined stop point - private const double ScoreFactorStationStop = -50.0; - /// The default number of points lost when departing unexpectedly from a station - private const double ScoreFactorStationDeparture = -1.5; - /// The default number of points lost when the train is derailed - private const int ScoreValueDerailment = -1000; - /// The default number of points lost when a red signal is passed - private const int ScoreValueRedSignal = -100; - /// The default number of points gained when arriving at a station on time - private const int ScoreValueStationPerfectTime = 15; - /// The default number of points gained when stopping within tolerance of a station's defined stop point - private const int ScoreValueStationPerfectStop = 15; - /// The default number of points lost when the passengers are experiencing discomfort (Excessive speed through curves etc) - private const int ScoreValuePassengerDiscomfort = -20; - /// The default number of points gained when stopping at a scheduled station - internal const int ScoreValueStationArrival = 100; + internal partial class Score + { + /// The default number of points lost when the doors are opened unexpectedly + private const double FactorOpenedDoors = -10.0; + /// The default number of points lost per second when running overspeed + private const double FactorOverspeed = -1.0; + /// The default number of points lost when toppling the train through overspeed + private const double FactorToppling = -10.0; + /// The default number of points lost per second late + private const double FactorStationLate = -0.333333333333333; + /// The default number of points lost when missing a station's defined stop point + private const double FactorStationStop = -50.0; + /// The default number of points lost when departing unexpectedly from a station + private const double FactorStationDeparture = -1.5; + /// The default number of points lost when the train is derailed + private const int ValueDerailment = -1000; + /// The default number of points lost when a red signal is passed + private const int ValueRedSignal = -100; + /// The default number of points gained when arriving at a station on time + private const int ValueStationPerfectTime = 15; + /// The default number of points gained when stopping within tolerance of a station's defined stop point + private const int ValueStationPerfectStop = 15; + /// The default number of points lost when the passengers are experiencing discomfort (Excessive speed through curves etc) + private const int ValuePassengerDiscomfort = -20; + /// The default number of points gained when stopping at a scheduled station + internal const int ValueStationArrival = 100; + } } } diff --git a/source/OpenBVE/Game/Score/Score.cs b/source/OpenBVE/Game/Score/Score.cs index d8fb3bae8..260eab7a6 100644 --- a/source/OpenBVE/Game/Score/Score.cs +++ b/source/OpenBVE/Game/Score/Score.cs @@ -15,7 +15,7 @@ internal static partial class Game internal static Score CurrentScore = new Score(); /// The score class - internal class Score + internal partial class Score { /// The current total score internal int CurrentValue; @@ -36,8 +36,8 @@ internal class Score internal double PassengerTimer; /// This method should be called once a frame to update the player's score - /// The time elapsed since this function was last called - internal void Update(double TimeElapsed) + /// The time elapsed since this function was last called + internal void Update(double timeElapsed) { if (TrainManager.PlayerTrain == null) { @@ -90,11 +90,11 @@ internal void Update(double TimeElapsed) } if (bad) { - OpenedDoorsCounter += (Math.Abs(TrainManager.PlayerTrain.CurrentSpeed) + 0.25) * TimeElapsed; + OpenedDoorsCounter += (Math.Abs(TrainManager.PlayerTrain.CurrentSpeed) + 0.25) * timeElapsed; } else if (OpenedDoorsCounter != 0.0) { - int x = (int)Math.Ceiling(ScoreFactorOpenedDoors * OpenedDoorsCounter); + int x = (int)Math.Ceiling(FactorOpenedDoors * OpenedDoorsCounter); CurrentValue += x; if (x != 0) { @@ -110,11 +110,11 @@ internal void Update(double TimeElapsed) double a = Math.Abs(TrainManager.PlayerTrain.CurrentSpeed) - 0.277777777777778; if (a > n) { - OverspeedCounter += (a - n) * TimeElapsed; + OverspeedCounter += (a - n) * timeElapsed; } else if (OverspeedCounter != 0.0) { - int x = (int)Math.Ceiling(ScoreFactorOverspeed * OverspeedCounter); + int x = (int)Math.Ceiling(FactorOverspeed * OverspeedCounter); CurrentValue += x; if (x != 0) { @@ -135,11 +135,11 @@ internal void Update(double TimeElapsed) } if (q) { - TopplingCounter += TimeElapsed; + TopplingCounter += timeElapsed; } else if (TopplingCounter != 0.0) { - int x = (int)Math.Ceiling(ScoreFactorToppling * TopplingCounter); + int x = (int)Math.Ceiling(FactorToppling * TopplingCounter); CurrentValue += x; if (x != 0) { @@ -162,7 +162,7 @@ internal void Update(double TimeElapsed) } if (q) { - int x = ScoreValueDerailment; + int x = ValueDerailment; if (CurrentValue > 0) x -= CurrentValue; CurrentValue += x; if (x != 0) @@ -178,7 +178,7 @@ internal void Update(double TimeElapsed) { if (!RedSignal) { - int x = ScoreValueRedSignal; + int x = ValueRedSignal; CurrentValue += x; AddScore(x, ScoreTextToken.PassedRedSignal, 5.0); RedSignal = true; @@ -199,7 +199,7 @@ internal void Update(double TimeElapsed) if (j == 0 || Program.CurrentRoute.Stations[j - 1].Type != StationType.ChangeEnds && Program.CurrentRoute.Stations[j - 1].Type != StationType.Jump) { // arrival - int xa = ScoreValueStationArrival; + int xa = ValueStationArrival; CurrentValue += xa; AddScore(xa, ScoreTextToken.ArrivedAtStation, 10.0); // early/late @@ -209,13 +209,13 @@ internal void Update(double TimeElapsed) double d = Program.CurrentRoute.SecondsSinceMidnight - Program.CurrentRoute.Stations[j].ArrivalTime; if (d >= -5.0 & d <= 0.0) { - xb = ScoreValueStationPerfectTime; + xb = ValueStationPerfectTime; CurrentValue += xb; AddScore(xb, ScoreTextToken.PerfectTimeBonus, 10.0); } else if (d > 0.0) { - xb = (int)Math.Ceiling(ScoreFactorStationLate * (d - 1.0)); + xb = (int)Math.Ceiling(FactorStationLate * (d - 1.0)); CurrentValue += xb; if (xb != 0) { @@ -250,7 +250,7 @@ internal void Update(double TimeElapsed) } if (r < 0.01) { - xc = ScoreValueStationPerfectStop; + xc = ValueStationPerfectStop; CurrentValue += xc; AddScore(xc, ScoreTextToken.PerfectStopBonus, 10.0); } @@ -258,7 +258,7 @@ internal void Update(double TimeElapsed) { if (r > 1.0) r = 1.0; r = (r - 0.01) * 1.01010101010101; - xc = (int)Math.Ceiling(ScoreFactorStationStop * r); + xc = (int)Math.Ceiling(FactorStationStop * r); CurrentValue += xc; if (xc != 0) { @@ -319,7 +319,7 @@ internal void Update(double TimeElapsed) double r = TrainManager.PlayerTrain.StationDepartureTime - Program.CurrentRoute.SecondsSinceMidnight; if (r > 0.0) { - int x = (int)Math.Ceiling(ScoreFactorStationDeparture * r); + int x = (int)Math.Ceiling(FactorStationDeparture * r); CurrentValue += x; if (x != 0) { @@ -347,14 +347,14 @@ internal void Update(double TimeElapsed) } if (fallenOver & PassengerTimer == 0.0) { - int x = ScoreValuePassengerDiscomfort; + int x = ValuePassengerDiscomfort; CurrentValue += x; AddScore(x, ScoreTextToken.PassengerDiscomfort, 5.0); PassengerTimer = 5.0; } else { - PassengerTimer -= TimeElapsed; + PassengerTimer -= timeElapsed; if (PassengerTimer <= 0.0) { PassengerTimer = fallenOver ? 5.0 : 0.0; @@ -363,26 +363,26 @@ internal void Update(double TimeElapsed) } /// Is called by the update function to add a new score event to the log - /// The value of the score event - /// The token type which caused the score event - /// The duration of the score event (e.g. overspeed) - /// Whether this should be counted as a unique event (NOTE: Scheduled stops are the only case which are not) - private void AddScore(int Value, ScoreTextToken TextToken, double Duration, bool Count = true) + /// The value of the score event + /// The token type which caused the score event + /// The duration of the score event (e.g. overspeed) + /// Whether this should be counted as a unique event (NOTE: Scheduled stops are the only case which are not) + private void AddScore(int scoreValue, ScoreTextToken textToken, double scoreDuration, bool countedEvent = true) { if (Interface.CurrentOptions.GameMode == GameMode.Arcade) { int n = ScoreMessages.Length; Array.Resize(ref ScoreMessages, n + 1); - ScoreMessages[n].Value = Value; - ScoreMessages[n].Text = Interface.GetScoreText(TextToken) + ": " + Value.ToString(System.Globalization.CultureInfo.InvariantCulture); - ScoreMessages[n].Timeout = Program.CurrentRoute.SecondsSinceMidnight + Duration; + ScoreMessages[n].Value = scoreValue; + ScoreMessages[n].Text = Interface.GetScoreText(textToken) + ": " + scoreValue.ToString(System.Globalization.CultureInfo.InvariantCulture); + ScoreMessages[n].Timeout = Program.CurrentRoute.SecondsSinceMidnight + scoreDuration; ScoreMessages[n].RendererPosition = new Vector2(0.0, 0.0); ScoreMessages[n].RendererAlpha = 0.0; - if (Value < 0.0) + if (scoreValue < 0.0) { ScoreMessages[n].Color = MessageColor.Red; } - else if (Value > 0.0) + else if (scoreValue > 0.0) { ScoreMessages[n].Color = MessageColor.Green; } @@ -391,14 +391,14 @@ private void AddScore(int Value, ScoreTextToken TextToken, double Duration, bool ScoreMessages[n].Color = MessageColor.White; } } - if (Value != 0 & Count) + if (scoreValue != 0 & countedEvent) { if (ScoreLogCount == ScoreLogs.Length) { Array.Resize(ref ScoreLogs, ScoreLogs.Length << 1); } - ScoreLogs[ScoreLogCount].Value = Value; - ScoreLogs[ScoreLogCount].TextToken = TextToken; + ScoreLogs[ScoreLogCount].Value = scoreValue; + ScoreLogs[ScoreLogCount].TextToken = textToken; ScoreLogs[ScoreLogCount].Position = TrainManager.PlayerTrain.Cars[0].TrackPosition; ScoreLogs[ScoreLogCount].Time = Program.CurrentRoute.SecondsSinceMidnight; ScoreLogCount++; @@ -406,17 +406,17 @@ private void AddScore(int Value, ScoreTextToken TextToken, double Duration, bool } /// Is called by the update function to add a new score event to the log - /// The log text for this score event - /// The duration of the score event (e.g. overspeed) - private void AddScore(string Text, double Duration) + /// The log text for this score event + /// The duration of the score event (e.g. overspeed) + private void AddScore(string scoreText, double scoreDuration) { if (Interface.CurrentOptions.GameMode == GameMode.Arcade) { int n = ScoreMessages.Length; Array.Resize(ref ScoreMessages, n + 1); ScoreMessages[n].Value = 0; - ScoreMessages[n].Text = Text.Length != 0 ? Text : "══════════"; - ScoreMessages[n].Timeout = Program.CurrentRoute.SecondsSinceMidnight + Duration; + ScoreMessages[n].Text = scoreText.Length != 0 ? scoreText : "══════════"; + ScoreMessages[n].Timeout = Program.CurrentRoute.SecondsSinceMidnight + scoreDuration; ScoreMessages[n].RendererPosition = new Vector2(0.0, 0.0); ScoreMessages[n].RendererAlpha = 0.0; ScoreMessages[n].Color = MessageColor.White; diff --git a/source/OpenBVE/Game/Timetable.cs b/source/OpenBVE/Game/Timetable.cs index 6463b61ae..51ee3323d 100644 --- a/source/OpenBVE/Game/Timetable.cs +++ b/source/OpenBVE/Game/Timetable.cs @@ -57,16 +57,16 @@ internal void CollectData() Stations = new List(); Tracks = new Track[16]; int n = 0; - double Limit = -1.0, LastLimit = 6.94444444444444; - int LastArrivalHours = -1, LastDepartureHours = -1; - double LastTime = -1.0; + double limit = -1.0, lastLimit = 6.94444444444444; + int lastArrivalHours = -1, lastDepartureHours = -1; + double lastTime = -1.0; for (int i = 0; i < Program.CurrentRoute.Tracks[0].Elements.Length; i++) { for (int j = 0; j < Program.CurrentRoute.Tracks[0].Elements[i].Events.Count; j++) { if (Program.CurrentRoute.Tracks[0].Elements[i].Events[j] is StationStartEvent sse && Program.CurrentRoute.Stations[sse.StationIndex].Name != string.Empty && !Program.CurrentRoute.Stations[sse.StationIndex].Dummy) { - if (Limit == -1.0) Limit = LastLimit; + if (limit == -1.0) limit = lastLimit; // update station Station currentStation; @@ -84,10 +84,10 @@ internal void CollectData() int minutes = (int) Math.Floor(x / 60.0); x -= 60.0 * minutes; int seconds = (int) Math.Floor(x); - currentStation.Arrival.Hour = hours != LastArrivalHours ? hours.ToString("00", Culture) : ""; + currentStation.Arrival.Hour = hours != lastArrivalHours ? hours.ToString("00", Culture) : ""; currentStation.Arrival.Minute = minutes.ToString("00", Culture); currentStation.Arrival.Second = seconds.ToString("00", Culture); - LastArrivalHours = hours; + lastArrivalHours = hours; } else { @@ -105,10 +105,10 @@ internal void CollectData() int minutes = (int) Math.Floor(x / 60.0); x -= 60.0 * minutes; int seconds = (int) Math.Floor(x); - currentStation.Departure.Hour = hours != LastDepartureHours ? hours.ToString("00", Culture) : ""; + currentStation.Departure.Hour = hours != lastDepartureHours ? hours.ToString("00", Culture) : ""; currentStation.Departure.Minute = minutes.ToString("00", Culture); currentStation.Departure.Second = seconds.ToString("00", Culture); - LastDepartureHours = hours; + lastDepartureHours = hours; } else { @@ -127,10 +127,10 @@ internal void CollectData() } // speed - x = Math.Round(3.6 * Limit); + x = Math.Round(3.6 * limit); Tracks[m].Speed = x.ToString(Culture); // time - if (LastTime >= 0.0) + if (lastTime >= 0.0) { if (Program.CurrentRoute.Stations[sse.StationIndex].ArrivalTime >= 0.0) { @@ -144,7 +144,7 @@ internal void CollectData() if (x >= 0.0) { - x -= LastTime; + x -= lastTime; int hours = (int) Math.Floor(x / 3600.0); x -= 3600.0 * hours; int minutes = (int) Math.Floor(x / 60.0); @@ -172,19 +172,19 @@ internal void CollectData() // update last data if (Program.CurrentRoute.Stations[sse.StationIndex].DepartureTime >= 0.0) { - LastTime = Program.CurrentRoute.Stations[sse.StationIndex].DepartureTime; + lastTime = Program.CurrentRoute.Stations[sse.StationIndex].DepartureTime; } else if (Program.CurrentRoute.Stations[sse.StationIndex].ArrivalTime >= 0.0) { - LastTime = Program.CurrentRoute.Stations[sse.StationIndex].ArrivalTime; + lastTime = Program.CurrentRoute.Stations[sse.StationIndex].ArrivalTime; } else { - LastTime = -1.0; + lastTime = -1.0; } - LastLimit = Limit; - Limit = -1.0; + lastLimit = limit; + limit = -1.0; n++; Stations.Add(currentStation); } @@ -193,7 +193,7 @@ internal void CollectData() { if (Program.CurrentRoute.Tracks[0].Elements[i].Events[j] is LimitChangeEvent lce) { - if (lce.NextSpeedLimit != double.PositiveInfinity & lce.NextSpeedLimit > Limit) Limit = lce.NextSpeedLimit; + if (lce.NextSpeedLimit != double.PositiveInfinity & lce.NextSpeedLimit > limit) limit = lce.NextSpeedLimit; } } } @@ -509,9 +509,9 @@ internal static void CreateTimetable() { try { - Table Table = new Table(); - Table.CollectData(); - Table.RenderData(ref DefaultTimetableTexture); + Table table = new Table(); + table.CollectData(); + table.RenderData(ref DefaultTimetableTexture); } catch { @@ -521,24 +521,24 @@ internal static void CreateTimetable() // update custom timetable - internal static void UpdateCustomTimetable(Texture daytime, Texture nighttime) { + internal static void UpdateCustomTimetable(Texture daytimeTexture, Texture nighttimeTexture) { for (int i = 0; i < CustomObjectsUsed; i++) { for (int j = 0; j < CustomObjects[i].States.Length; j++) { for (int k = 0; k < CustomObjects[i].States[j].Prototype.Mesh.Materials.Length; k++) { - if (daytime != null) { - CustomObjects[i].States[j].Prototype.Mesh.Materials[k].DaytimeTexture = daytime; + if (daytimeTexture != null) { + CustomObjects[i].States[j].Prototype.Mesh.Materials[k].DaytimeTexture = daytimeTexture; } - if (nighttime != null) { - CustomObjects[i].States[j].Prototype.Mesh.Materials[k].NighttimeTexture = nighttime; + if (nighttimeTexture != null) { + CustomObjects[i].States[j].Prototype.Mesh.Materials[k].NighttimeTexture = nighttimeTexture; } } } } - if (daytime != null) { - CurrentCustomTimetableDaytimeTexture = daytime; + if (daytimeTexture != null) { + CurrentCustomTimetableDaytimeTexture = daytimeTexture; } - if (nighttime != null) { - CurrentCustomTimetableNighttimeTexture = nighttime; + if (nighttimeTexture != null) { + CurrentCustomTimetableNighttimeTexture = nighttimeTexture; } if (CurrentCustomTimetableDaytimeTexture != null | CurrentCustomTimetableNighttimeTexture != null) { CustomTimetableAvailable = true; diff --git a/source/OpenBVE/Game/TrainManager.cs b/source/OpenBVE/Game/TrainManager.cs index 4ccfe244e..7a3ef9097 100644 --- a/source/OpenBVE/Game/TrainManager.cs +++ b/source/OpenBVE/Game/TrainManager.cs @@ -18,21 +18,21 @@ public TrainManager(HostInterface host, BaseRenderer renderer, BaseOptions optio } /// This method should be called once a frame to update the position, speed and state of all trains within the simulation - /// The time elapsed since the last call to this function - internal void UpdateTrains(double TimeElapsed) + /// The time elapsed since the last call to this function + internal void UpdateTrains(double timeElapsed) { if (Interface.CurrentOptions.GameMode == GameMode.Developer) { return; } for (int i = 0; i < Trains.Length; i++) { - Trains[i].Update(TimeElapsed); + Trains[i].Update(timeElapsed); } // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop - foreach (ScriptedTrain Train in TFOs) //Must not use var, as otherwise the wrong inferred type + foreach (ScriptedTrain scriptedTrain in TFOs) //Must not use var, as otherwise the wrong inferred type { - Train.Update(TimeElapsed); + scriptedTrain.Update(timeElapsed); } // detect collision @@ -86,9 +86,9 @@ internal void UpdateTrains(double TimeElapsed) double vi = v * fi; double vj = v * fj; if (vi > Trains[i].CriticalCollisionSpeedDifference) - Trains[i].Derail(k, TimeElapsed); + Trains[i].Derail(k, timeElapsed); if (vj > Trains[j].CriticalCollisionSpeedDifference) - Trains[j].Derail(i, TimeElapsed); + Trains[j].Derail(i, timeElapsed); } // adjust cars for train i @@ -112,9 +112,9 @@ internal void UpdateTrains(double TimeElapsed) double vi = v * fi; double vj = v * fj; if (vi > Trains[i].CriticalCollisionSpeedDifference) - Trains[i].Derail(h + 1, TimeElapsed); + Trains[i].Derail(h + 1, timeElapsed); if (vj > Trains[j].CriticalCollisionSpeedDifference) - Trains[i].Derail(h, TimeElapsed); + Trains[i].Derail(h, timeElapsed); } Trains[i].Cars[h].CurrentSpeed = @@ -143,9 +143,9 @@ internal void UpdateTrains(double TimeElapsed) double vi = v * fi; double vj = v * fj; if (vi > Trains[j].CriticalCollisionSpeedDifference) - Trains[j].Derail(h - 1, TimeElapsed); + Trains[j].Derail(h - 1, timeElapsed); if (vj > Trains[j].CriticalCollisionSpeedDifference) - Trains[j].Derail(h, TimeElapsed); + Trains[j].Derail(h, timeElapsed); } Trains[j].Cars[h].CurrentSpeed = @@ -185,9 +185,9 @@ internal void UpdateTrains(double TimeElapsed) double vi = v * fi; double vj = v * fj; if (vi > Trains[i].CriticalCollisionSpeedDifference) - Trains[i].Derail(0, TimeElapsed); + Trains[i].Derail(0, timeElapsed); if (vj > Trains[j].CriticalCollisionSpeedDifference) - Trains[j].Derail(k, TimeElapsed); + Trains[j].Derail(k, timeElapsed); } // adjust cars for train i @@ -211,9 +211,9 @@ internal void UpdateTrains(double TimeElapsed) double vi = v * fi; double vj = v * fj; if (vi > Trains[i].CriticalCollisionSpeedDifference) - Trains[i].Derail(h - 1, TimeElapsed); + Trains[i].Derail(h - 1, timeElapsed); if (vj > Trains[i].CriticalCollisionSpeedDifference) - Trains[i].Derail(h, TimeElapsed); + Trains[i].Derail(h, timeElapsed); } Trains[i].Cars[h].CurrentSpeed = @@ -242,9 +242,9 @@ internal void UpdateTrains(double TimeElapsed) double vi = v * fi; double vj = v * fj; if (vi > Trains[i].CriticalCollisionSpeedDifference) - Trains[j].Derail(h + 1, TimeElapsed); + Trains[j].Derail(h + 1, timeElapsed); if (vj > Trains[j].CriticalCollisionSpeedDifference) - Trains[j].Derail(h, TimeElapsed); + Trains[j].Derail(h, timeElapsed); } Trains[j].Cars[h].CurrentSpeed = @@ -289,7 +289,7 @@ internal void UpdateTrains(double TimeElapsed) if (Interface.CurrentOptions.Derailments && Math.Abs(Trains[i].Cars[0].CurrentSpeed) > Trains[i].CriticalCollisionSpeedDifference) { - Trains[i].Derail(0, TimeElapsed); + Trains[i].Derail(0, timeElapsed); } Trains[i].Cars[0].CurrentSpeed = 0.0; @@ -308,7 +308,7 @@ internal void UpdateTrains(double TimeElapsed) Math.Abs(Trains[i].Cars[h].CurrentSpeed) > Trains[i].CriticalCollisionSpeedDifference) { - Trains[i].Derail(h, TimeElapsed); + Trains[i].Derail(h, timeElapsed); } Trains[i].Cars[h].CurrentSpeed = 0.0; @@ -328,7 +328,7 @@ internal void UpdateTrains(double TimeElapsed) if (Interface.CurrentOptions.Derailments && Math.Abs(Trains[i].Cars[c].CurrentSpeed) > Trains[i].CriticalCollisionSpeedDifference) { - Trains[i].Derail(c, TimeElapsed); + Trains[i].Derail(c, timeElapsed); } Trains[i].Cars[c].CurrentSpeed = 0.0; @@ -347,7 +347,7 @@ internal void UpdateTrains(double TimeElapsed) Math.Abs(Trains[i].Cars[h].CurrentSpeed) > Trains[i].CriticalCollisionSpeedDifference) { - Trains[i].Derail(h, TimeElapsed); + Trains[i].Derail(h, timeElapsed); } Trains[i].Cars[h].CurrentSpeed = 0.0; @@ -373,12 +373,12 @@ internal void UpdateTrains(double TimeElapsed) Trains[i].Cars[j].RearAxle.Follower.UpdateWorldCoordinates(true); Trains[i].Cars[j].RearBogie.FrontAxle.Follower.UpdateWorldCoordinates(true); Trains[i].Cars[j].RearBogie.RearAxle.Follower.UpdateWorldCoordinates(true); - if (TimeElapsed == 0.0 | TimeElapsed > 0.5) + if (timeElapsed == 0.0 | timeElapsed > 0.5) { //Don't update the toppling etc. with excessive or no time continue; } - Trains[i].Cars[j].UpdateTopplingCantAndSpring(TimeElapsed); + Trains[i].Cars[j].UpdateTopplingCantAndSpring(timeElapsed); Trains[i].Cars[j].FrontBogie.UpdateTopplingCantAndSpring(); Trains[i].Cars[j].RearBogie.UpdateTopplingCantAndSpring(); } @@ -398,12 +398,12 @@ internal void UpdateTrains(double TimeElapsed) Car.RearAxle.Follower.UpdateWorldCoordinates(true); Car.RearBogie.FrontAxle.Follower.UpdateWorldCoordinates(true); Car.RearBogie.RearAxle.Follower.UpdateWorldCoordinates(true); - if (TimeElapsed == 0.0 | TimeElapsed > 0.5) + if (timeElapsed == 0.0 | timeElapsed > 0.5) { //Don't update the toppling etc. with excessive or no time continue; } - Car.UpdateTopplingCantAndSpring(TimeElapsed); + Car.UpdateTopplingCantAndSpring(timeElapsed); Car.FrontBogie.UpdateTopplingCantAndSpring(); Car.RearBogie.UpdateTopplingCantAndSpring(); } diff --git a/source/OpenBVE/Game/World.cs b/source/OpenBVE/Game/World.cs index 362bbb29d..5c9223404 100644 --- a/source/OpenBVE/Game/World.cs +++ b/source/OpenBVE/Game/World.cs @@ -67,19 +67,19 @@ internal static bool PerformBoundingBoxTest(ref StaticObject bounding, ref Vecto // update absolute camera - internal static void UpdateAbsoluteCamera(double TimeElapsed = 0.0) { + internal static void UpdateAbsoluteCamera(double timeElapsed = 0.0) { // zoom double zm = Program.Renderer.Camera.Alignment.Zoom; - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Zoom, Program.Renderer.Camera.AlignmentDirection.Zoom, ref Program.Renderer.Camera.AlignmentSpeed.Zoom, TimeElapsed, true, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Zoom, Program.Renderer.Camera.AlignmentDirection.Zoom, ref Program.Renderer.Camera.AlignmentSpeed.Zoom, timeElapsed, true, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); if (zm != Program.Renderer.Camera.Alignment.Zoom) { Program.Renderer.Camera.ApplyZoom(); } if (Program.Renderer.Camera.CurrentMode == CameraViewMode.FlyBy | Program.Renderer.Camera.CurrentMode == CameraViewMode.FlyByZooming) { // fly-by - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.X, Program.Renderer.Camera.AlignmentDirection.Position.X, ref Program.Renderer.Camera.AlignmentSpeed.Position.X, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.Y, Program.Renderer.Camera.AlignmentDirection.Position.Y, ref Program.Renderer.Camera.AlignmentSpeed.Position.Y, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.X, Program.Renderer.Camera.AlignmentDirection.Position.X, ref Program.Renderer.Camera.AlignmentSpeed.Position.X, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.Y, Program.Renderer.Camera.AlignmentDirection.Position.Y, ref Program.Renderer.Camera.AlignmentSpeed.Position.Y, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); double tr = Program.Renderer.Camera.Alignment.TrackPosition; - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.TrackPosition, Program.Renderer.Camera.AlignmentDirection.TrackPosition, ref Program.Renderer.Camera.AlignmentSpeed.TrackPosition, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.TrackPosition, Program.Renderer.Camera.AlignmentDirection.TrackPosition, ref Program.Renderer.Camera.AlignmentSpeed.TrackPosition, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); if (tr != Program.Renderer.Camera.Alignment.TrackPosition) { Program.Renderer.CameraTrackFollower.UpdateAbsolute(Program.Renderer.Camera.Alignment.TrackPosition, true, false); Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance); @@ -175,20 +175,20 @@ internal static void UpdateAbsoluteCamera(double TimeElapsed = 0.0) { // non-fly-by { // current alignment - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.X, Program.Renderer.Camera.AlignmentDirection.Position.X, ref Program.Renderer.Camera.AlignmentSpeed.Position.X, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.Y, Program.Renderer.Camera.AlignmentDirection.Position.Y, ref Program.Renderer.Camera.AlignmentSpeed.Position.Y, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.Z, Program.Renderer.Camera.AlignmentDirection.Position.Z, ref Program.Renderer.Camera.AlignmentSpeed.Position.Z, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.X, Program.Renderer.Camera.AlignmentDirection.Position.X, ref Program.Renderer.Camera.AlignmentSpeed.Position.X, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.Y, Program.Renderer.Camera.AlignmentDirection.Position.Y, ref Program.Renderer.Camera.AlignmentSpeed.Position.Y, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Position.Z, Program.Renderer.Camera.AlignmentDirection.Position.Z, ref Program.Renderer.Camera.AlignmentSpeed.Position.Z, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); if ((Program.Renderer.Camera.CurrentMode == CameraViewMode.Interior | Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead) & Program.Renderer.Camera.CurrentRestriction == CameraRestrictionMode.On) { if (Program.Renderer.Camera.Alignment.Position.Z > 0.75) { Program.Renderer.Camera.Alignment.Position.Z = 0.75; } } bool q = Program.Renderer.Camera.AlignmentSpeed.Yaw != 0.0 | Program.Renderer.Camera.AlignmentSpeed.Pitch != 0.0 | Program.Renderer.Camera.AlignmentSpeed.Roll != 0.0; - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Yaw, Program.Renderer.Camera.AlignmentDirection.Yaw, ref Program.Renderer.Camera.AlignmentSpeed.Yaw, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Pitch, Program.Renderer.Camera.AlignmentDirection.Pitch, ref Program.Renderer.Camera.AlignmentSpeed.Pitch, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Roll, Program.Renderer.Camera.AlignmentDirection.Roll, ref Program.Renderer.Camera.AlignmentSpeed.Roll, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Yaw, Program.Renderer.Camera.AlignmentDirection.Yaw, ref Program.Renderer.Camera.AlignmentSpeed.Yaw, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Pitch, Program.Renderer.Camera.AlignmentDirection.Pitch, ref Program.Renderer.Camera.AlignmentSpeed.Pitch, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.Roll, Program.Renderer.Camera.AlignmentDirection.Roll, ref Program.Renderer.Camera.AlignmentSpeed.Roll, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); double tr = Program.Renderer.Camera.Alignment.TrackPosition; - Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.TrackPosition, Program.Renderer.Camera.AlignmentDirection.TrackPosition, ref Program.Renderer.Camera.AlignmentSpeed.TrackPosition, TimeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); + Program.Renderer.Camera.AdjustAlignment(ref Program.Renderer.Camera.Alignment.TrackPosition, Program.Renderer.Camera.AlignmentDirection.TrackPosition, ref Program.Renderer.Camera.AlignmentSpeed.TrackPosition, timeElapsed, false, TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].CameraRestriction); if (tr != Program.Renderer.Camera.Alignment.TrackPosition) { Program.Renderer.CameraTrackFollower.UpdateAbsolute(Program.Renderer.Camera.Alignment.TrackPosition, true, false); q = true; diff --git a/source/OpenBVE/Graphics/Renderers/Overlays.cs b/source/OpenBVE/Graphics/Renderers/Overlays.cs index d687e987a..229f73bfa 100644 --- a/source/OpenBVE/Graphics/Renderers/Overlays.cs +++ b/source/OpenBVE/Graphics/Renderers/Overlays.cs @@ -52,7 +52,7 @@ internal void Render(double TimeElapsed) case OutputMode.Default: //Route info overlay (if selected) - Game.routeInfoOverlay.Show(); + Game.RouteInfoOverlay.Show(); //HUD foreach (HUD.Element element in HUD.CurrentHudElements) @@ -169,7 +169,7 @@ internal void Render(double TimeElapsed) PauseAnnounced = false; break; case InterfaceType.SwitchChangeMap: - Game.switchChangeDialog.Draw(); + Game.SwitchChangeDialog.Draw(); break; default: PauseAnnounced = false; diff --git a/source/OpenBVE/System/GameWindow.cs b/source/OpenBVE/System/GameWindow.cs index a0c647397..54e504a75 100644 --- a/source/OpenBVE/System/GameWindow.cs +++ b/source/OpenBVE/System/GameWindow.cs @@ -362,7 +362,7 @@ protected override void OnResize(EventArgs e) if (Program.Renderer.CurrentInterface == InterfaceType.SwitchChangeMap) { // call the show method again to trigger resize - Game.switchChangeDialog.Show(); + Game.SwitchChangeDialog.Show(); } } @@ -759,13 +759,13 @@ private void SetupSimulation() { if (i == 0 || Program.CurrentRoute.Stations[i - 1].Type != StationType.ChangeEnds && Program.CurrentRoute.Stations[i - 1].Type != StationType.Jump) { - Game.CurrentScore.Maximum += Game.ScoreValueStationArrival; + Game.CurrentScore.Maximum += Game.Score.ValueStationArrival; } } } if (Game.CurrentScore.Maximum <= 0) { - Game.CurrentScore.Maximum = Game.ScoreValueStationArrival; + Game.CurrentScore.Maximum = Game.Score.ValueStationArrival; } // signals if (Program.CurrentRoute.Sections.Length > 0) diff --git a/source/OpenBVE/System/Input/ProcessControls.Digital.cs b/source/OpenBVE/System/Input/ProcessControls.Digital.cs index 148fe87dd..6212eb608 100644 --- a/source/OpenBVE/System/Input/ProcessControls.Digital.cs +++ b/source/OpenBVE/System/Input/ProcessControls.Digital.cs @@ -1339,7 +1339,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro Program.Sounds.Update(TimeElapsed, Interface.CurrentOptions.SoundModel); break; case Translations.Command.RouteInformation: - Game.routeInfoOverlay.ProcessCommand(Translations.Command.RouteInformation); + Game.RouteInfoOverlay.ProcessCommand(Translations.Command.RouteInformation); break; case Translations.Command.AccessibilityCurrentSpeed: string s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"message","train_currentspeed"}).Replace("[speed]", $"{TrainManagerBase.PlayerTrain.CurrentSpeed * 3.6:0.0}") + "km/h"; @@ -1373,10 +1373,10 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro { case InterfaceType.Normal: Program.Renderer.CurrentInterface = InterfaceType.SwitchChangeMap; - Game.switchChangeDialog.Show(); + Game.SwitchChangeDialog.Show(); break; case InterfaceType.SwitchChangeMap: - Game.switchChangeDialog.Close(null, null); + Game.SwitchChangeDialog.Close(null, null); break; } break; diff --git a/source/OpenBVE/System/Input/ProcessControls.cs b/source/OpenBVE/System/Input/ProcessControls.cs index 01c7c965e..5f88d930d 100644 --- a/source/OpenBVE/System/Input/ProcessControls.cs +++ b/source/OpenBVE/System/Input/ProcessControls.cs @@ -189,7 +189,7 @@ internal static void ProcessControls(double TimeElapsed) break; case Translations.Command.SwitchMenu: Program.Renderer.CurrentInterface = InterfaceType.SwitchChangeMap; - Game.switchChangeDialog.Show(); + Game.SwitchChangeDialog.Show(); break; } } diff --git a/source/OpenBVE/System/MainLoop.cs b/source/OpenBVE/System/MainLoop.cs index a56a4e754..f6fef2cc6 100644 --- a/source/OpenBVE/System/MainLoop.cs +++ b/source/OpenBVE/System/MainLoop.cs @@ -174,7 +174,7 @@ internal static void mouseDownEvent(object sender, MouseButtonEventArgs e) Game.Menu.ProcessMouseDown(e.X, e.Y); break; case InterfaceType.SwitchChangeMap: - Game.switchChangeDialog.ProcessMouseDown(e.X, e.Y); + Game.SwitchChangeDialog.ProcessMouseDown(e.X, e.Y); break; } } @@ -211,7 +211,7 @@ internal static void mouseMoveEvent(object sender, MouseMoveEventArgs e) Game.Menu.ProcessMouseMove(e.X, e.Y); break; case InterfaceType.SwitchChangeMap: - Game.switchChangeDialog.ProcessMouseMove(e.X, e.Y); + Game.SwitchChangeDialog.ProcessMouseMove(e.X, e.Y); break; } } From b2b309ea49dd374e542821f72ad257175212c5e6 Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Mon, 11 Nov 2024 18:24:06 +0000 Subject: [PATCH 6/7] Change: Enforce camelCase for parameter names (P6) Object Viewer --- source/ObjectViewer/FunctionScripts.cs | 978 +++++++++--------- source/ObjectViewer/Game/Menu.SingleMenu.cs | 7 +- source/ObjectViewer/Game/Menu.cs | 18 +- source/ObjectViewer/Graphics/NewRendererS.cs | 18 +- source/ObjectViewer/InterfaceS.cs | 4 +- source/ObjectViewer/ObjectManager.cs | 6 +- source/ObjectViewer/ProgramS.cs | 35 +- .../ObjectViewer/Trains/NearestTrainStatus.cs | 1 - source/ObjectViewer/formOptions.cs | 6 +- 9 files changed, 535 insertions(+), 538 deletions(-) diff --git a/source/ObjectViewer/FunctionScripts.cs b/source/ObjectViewer/FunctionScripts.cs index 1b7bed6e4..0f01b7ef6 100644 --- a/source/ObjectViewer/FunctionScripts.cs +++ b/source/ObjectViewer/FunctionScripts.cs @@ -13,885 +13,885 @@ namespace ObjectViewer { internal static class FunctionScripts { // execute function script - internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Train, int CarIndex, Vector3 Position, double TrackPosition, int SectionIndex, bool IsPartOfTrain, double TimeElapsed, int CurrentState) { + internal static void ExecuteFunctionScript(FunctionScript function, TrainBase train, int carIndex, Vector3 position, double trackPosition, int sectionIndex, bool isPartOfTrain, double timeElapsed, int currentState) { int s = 0, c = 0; - for (int i = 0; i < Function.InstructionSet.Length; i++) { - switch (Function.InstructionSet[i]) { + for (int i = 0; i < function.InstructionSet.Length; i++) { + switch (function.InstructionSet[i]) { // system case Instructions.SystemHalt: - i = Function.InstructionSet.Length; + i = function.InstructionSet.Length; break; case Instructions.SystemConstant: - Function.Stack[s] = Function.Constants[c]; + function.Stack[s] = function.Constants[c]; s++; c++; break; case Instructions.SystemConstantArray: { - int n = (int)Function.InstructionSet[i + 1]; + int n = (int)function.InstructionSet[i + 1]; for (int j = 0; j < n; j++) { - Function.Stack[s + j] = Function.Constants[c + j]; + function.Stack[s + j] = function.Constants[c + j]; } s += n; c += n; i++; } break; case Instructions.SystemValue: - Function.Stack[s] = Function.LastResult; + function.Stack[s] = function.LastResult; s++; break; case Instructions.SystemDelta: - Function.Stack[s] = TimeElapsed; + function.Stack[s] = timeElapsed; s++; break; // stack case Instructions.StackCopy: - Function.Stack[s] = Function.Stack[s - 1]; + function.Stack[s] = function.Stack[s - 1]; s++; break; case Instructions.StackSwap: - (Function.Stack[s - 1], Function.Stack[s - 2]) = (Function.Stack[s - 2], Function.Stack[s - 1]); + (function.Stack[s - 1], function.Stack[s - 2]) = (function.Stack[s - 2], function.Stack[s - 1]); break; // math case Instructions.MathPlus: - Function.Stack[s - 2] += Function.Stack[s - 1]; + function.Stack[s - 2] += function.Stack[s - 1]; s--; break; case Instructions.MathSubtract: - Function.Stack[s - 2] -= Function.Stack[s - 1]; + function.Stack[s - 2] -= function.Stack[s - 1]; s--; break; case Instructions.MathMinus: - Function.Stack[s - 1] = -Function.Stack[s - 1]; + function.Stack[s - 1] = -function.Stack[s - 1]; break; case Instructions.MathTimes: - Function.Stack[s - 2] *= Function.Stack[s - 1]; + function.Stack[s - 2] *= function.Stack[s - 1]; s--; break; case Instructions.MathDivide: - Function.Stack[s - 2] = Function.Stack[s - 1] == 0.0 ? 0.0 : Function.Stack[s - 2] / Function.Stack[s - 1]; + function.Stack[s - 2] = function.Stack[s - 1] == 0.0 ? 0.0 : function.Stack[s - 2] / function.Stack[s - 1]; s--; break; case Instructions.MathReciprocal: - Function.Stack[s - 1] = Function.Stack[s - 1] == 0.0 ? 0.0 : 1.0 / Function.Stack[s - 1]; + function.Stack[s - 1] = function.Stack[s - 1] == 0.0 ? 0.0 : 1.0 / function.Stack[s - 1]; break; case Instructions.MathPower: { - double a = Function.Stack[s - 2]; - double b = Function.Stack[s - 1]; + double a = function.Stack[s - 2]; + double b = function.Stack[s - 1]; if (b == 2.0) { - Function.Stack[s - 2] = a * a; + function.Stack[s - 2] = a * a; } else if (b == 3.0) { - Function.Stack[s - 2] = a * a * a; + function.Stack[s - 2] = a * a * a; } else if (b == 4.0) { double t = a * a; - Function.Stack[s - 2] = t * t; + function.Stack[s - 2] = t * t; } else if (b == 5.0) { double t = a * a; - Function.Stack[s - 2] = t * t * a; + function.Stack[s - 2] = t * t * a; } else if (b == 6.0) { double t = a * a * a; - Function.Stack[s - 2] = t * t; + function.Stack[s - 2] = t * t; } else if (b == 7.0) { double t = a * a * a; - Function.Stack[s - 2] = t * t * a; + function.Stack[s - 2] = t * t * a; } else if (b == 8.0) { double t = a * a; t *= t; - Function.Stack[s - 2] = t * t; + function.Stack[s - 2] = t * t; } else if (b == 0.0) { - Function.Stack[s - 2] = 1.0; + function.Stack[s - 2] = 1.0; } else if (b < 0.0) { - Function.Stack[s - 2] = 0.0; + function.Stack[s - 2] = 0.0; } else { - Function.Stack[s - 2] = Math.Pow(a, b); + function.Stack[s - 2] = Math.Pow(a, b); } s--; break; } case Instructions.MathRandom: { //Generates a random number between two given doubles - double min = Function.Stack[s - 2]; - double max = Function.Stack[s - 1]; + double min = function.Stack[s - 2]; + double max = function.Stack[s - 1]; var randomGenerator = new Random(); - Function.Stack[s - 2] = min + randomGenerator.NextDouble() * (max - min); + function.Stack[s - 2] = min + randomGenerator.NextDouble() * (max - min); s--; } break; case Instructions.MathRandomInt: { //Generates a random number between two given doubles - int min = (int)Function.Stack[s - 2]; - int max = (int)Function.Stack[s - 1]; + int min = (int)function.Stack[s - 2]; + int max = (int)function.Stack[s - 1]; var randomGenerator = new Random(); - Function.Stack[s - 2] = randomGenerator.Next(min, max); + function.Stack[s - 2] = randomGenerator.Next(min, max); s--; } break; case Instructions.MathIncrement: - Function.Stack[s - 1] += 1.0; + function.Stack[s - 1] += 1.0; break; case Instructions.MathDecrement: - Function.Stack[s - 1] -= 1.0; + function.Stack[s - 1] -= 1.0; break; case Instructions.MathFusedMultiplyAdd: - Function.Stack[s - 3] = Function.Stack[s - 3] * Function.Stack[s - 2] + Function.Stack[s - 1]; + function.Stack[s - 3] = function.Stack[s - 3] * function.Stack[s - 2] + function.Stack[s - 1]; s -= 2; break; case Instructions.MathQuotient: - Function.Stack[s - 2] = Function.Stack[s - 1] == 0.0 ? 0.0 : Math.Floor(Function.Stack[s - 2] / Function.Stack[s - 1]); + function.Stack[s - 2] = function.Stack[s - 1] == 0.0 ? 0.0 : Math.Floor(function.Stack[s - 2] / function.Stack[s - 1]); s--; break; case Instructions.MathMod: - Function.Stack[s - 2] = Function.Stack[s - 1] == 0.0 ? 0.0 : Function.Stack[s - 2] - Function.Stack[s - 1] * Math.Floor(Function.Stack[s - 2] / Function.Stack[s - 1]); + function.Stack[s - 2] = function.Stack[s - 1] == 0.0 ? 0.0 : function.Stack[s - 2] - function.Stack[s - 1] * Math.Floor(function.Stack[s - 2] / function.Stack[s - 1]); s--; break; case Instructions.MathFloor: - Function.Stack[s - 1] = Math.Floor(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Floor(function.Stack[s - 1]); break; case Instructions.MathCeiling: - Function.Stack[s - 1] = Math.Ceiling(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Ceiling(function.Stack[s - 1]); break; case Instructions.MathRound: - Function.Stack[s - 1] = Math.Round(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Round(function.Stack[s - 1]); break; case Instructions.MathMin: - Function.Stack[s - 2] = Function.Stack[s - 2] < Function.Stack[s - 1] ? Function.Stack[s - 2] : Function.Stack[s - 1]; + function.Stack[s - 2] = function.Stack[s - 2] < function.Stack[s - 1] ? function.Stack[s - 2] : function.Stack[s - 1]; s--; break; case Instructions.MathMax: - Function.Stack[s - 2] = Function.Stack[s - 2] > Function.Stack[s - 1] ? Function.Stack[s - 2] : Function.Stack[s - 1]; + function.Stack[s - 2] = function.Stack[s - 2] > function.Stack[s - 1] ? function.Stack[s - 2] : function.Stack[s - 1]; s--; break; case Instructions.MathAbs: - Function.Stack[s - 1] = Math.Abs(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Abs(function.Stack[s - 1]); break; case Instructions.MathSign: - Function.Stack[s - 1] = Math.Sign(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Sign(function.Stack[s - 1]); break; case Instructions.MathExp: - Function.Stack[s - 1] = Math.Exp(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Exp(function.Stack[s - 1]); break; case Instructions.MathLog: - Function.Stack[s - 1] = Log(Function.Stack[s - 1]); + function.Stack[s - 1] = Log(function.Stack[s - 1]); break; case Instructions.MathSqrt: - Function.Stack[s - 1] = Sqrt(Function.Stack[s - 1]); + function.Stack[s - 1] = Sqrt(function.Stack[s - 1]); break; case Instructions.MathSin: - Function.Stack[s - 1] = Math.Sin(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Sin(function.Stack[s - 1]); break; case Instructions.MathCos: - Function.Stack[s - 1] = Math.Cos(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Cos(function.Stack[s - 1]); break; case Instructions.MathTan: - Function.Stack[s - 1] = Tan(Function.Stack[s - 1]); + function.Stack[s - 1] = Tan(function.Stack[s - 1]); break; case Instructions.MathArcTan: - Function.Stack[s - 1] = Math.Atan(Function.Stack[s - 1]); + function.Stack[s - 1] = Math.Atan(function.Stack[s - 1]); break; case Instructions.MathPi: - Function.Stack[s] = Math.PI; + function.Stack[s] = Math.PI; s++; break; // comparisons case Instructions.CompareEqual: - Function.Stack[s - 2] = Function.Stack[s - 2] == Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] == function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareUnequal: - Function.Stack[s - 2] = Function.Stack[s - 2] != Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareLess: - Function.Stack[s - 2] = Function.Stack[s - 2] < Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] < function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareGreater: - Function.Stack[s - 2] = Function.Stack[s - 2] > Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] > function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareLessEqual: - Function.Stack[s - 2] = Function.Stack[s - 2] <= Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] <= function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareGreaterEqual: - Function.Stack[s - 2] = Function.Stack[s - 2] >= Function.Stack[s - 1] ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] >= function.Stack[s - 1] ? 1.0 : 0.0; s--; break; case Instructions.CompareConditional: - Function.Stack[s - 3] = Function.Stack[s - 3] != 0.0 ? Function.Stack[s - 2] : Function.Stack[s - 1]; + function.Stack[s - 3] = function.Stack[s - 3] != 0.0 ? function.Stack[s - 2] : function.Stack[s - 1]; s -= 2; break; // logical case Instructions.LogicalNot: - Function.Stack[s - 1] = Function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; + function.Stack[s - 1] = function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; break; case Instructions.LogicalAnd: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 & Function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 & function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; s--; break; case Instructions.LogicalOr: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 | Function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 | function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; s--; break; case Instructions.LogicalNand: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 & Function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 & function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; s--; break; case Instructions.LogicalNor: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 | Function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 | function.Stack[s - 1] != 0.0 ? 0.0 : 1.0; s--; break; case Instructions.LogicalXor: - Function.Stack[s - 2] = Function.Stack[s - 2] != 0.0 ^ Function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; + function.Stack[s - 2] = function.Stack[s - 2] != 0.0 ^ function.Stack[s - 1] != 0.0 ? 1.0 : 0.0; s--; break; case Instructions.CurrentObjectState: - Function.Stack[s] = CurrentState; + function.Stack[s] = currentState; s++; break; // time/camera case Instructions.TimeSecondsSinceMidnight: - Function.Stack[s] = Game.SecondsSinceMidnight; + function.Stack[s] = Game.SecondsSinceMidnight; s++; break; case Instructions.TimeHourDigit: - Function.Stack[s] = Math.Floor(Game.SecondsSinceMidnight / 3600.0); + function.Stack[s] = Math.Floor(Game.SecondsSinceMidnight / 3600.0); s++; break; case Instructions.TimeMinuteDigit: - Function.Stack[s] = Math.Floor(Game.SecondsSinceMidnight / 60 % 60); + function.Stack[s] = Math.Floor(Game.SecondsSinceMidnight / 60 % 60); s++; break; case Instructions.TimeSecondDigit: - Function.Stack[s] = Math.Floor(Game.SecondsSinceMidnight % 60); + function.Stack[s] = Math.Floor(Game.SecondsSinceMidnight % 60); s++; break; case Instructions.CameraDistance: { - double dx = Program.Renderer.Camera.AbsolutePosition.X - Position.X; - double dy = Program.Renderer.Camera.AbsolutePosition.Y - Position.Y; - double dz = Program.Renderer.Camera.AbsolutePosition.Z - Position.Z; - Function.Stack[s] = Math.Sqrt(dx * dx + dy * dy + dz * dz); + double dx = Program.Renderer.Camera.AbsolutePosition.X - position.X; + double dy = Program.Renderer.Camera.AbsolutePosition.Y - position.Y; + double dz = Program.Renderer.Camera.AbsolutePosition.Z - position.Z; + function.Stack[s] = Math.Sqrt(dx * dx + dy * dy + dz * dz); s++; } break; case Instructions.CameraXDistance: { - Function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.X - Position.X; + function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.X - position.X; s++; } break; case Instructions.CameraYDistance: { - Function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Y - Position.Y; + function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Y - position.Y; s++; } break; case Instructions.CameraZDistance: { - Function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Z - Position.Z; + function.Stack[s] = Program.Renderer.Camera.AbsolutePosition.Z - position.Z; s++; } break; case Instructions.BillboardX: { - Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - Position; - Function.Stack[s] = Math.Atan2(toCamera.Y, -toCamera.Z); + Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - position; + function.Stack[s] = Math.Atan2(toCamera.Y, -toCamera.Z); s++; } break; case Instructions.BillboardY: { - Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - Position; - Function.Stack[s] = Math.Atan2(-toCamera.Z, toCamera.X); + Vector3 toCamera = Program.Renderer.Camera.AbsolutePosition - position; + function.Stack[s] = Math.Atan2(-toCamera.Z, toCamera.X); s++; } break; case Instructions.CameraView: //Returns whether the camera is in interior or exterior mode if (Program.Renderer.Camera.CurrentMode == CameraViewMode.Interior) { - Function.Stack[s] = 0; + function.Stack[s] = 0; } else { - Function.Stack[s] = 1; + function.Stack[s] = 1; } s++; break; // train case Instructions.PlayerTrain: - if (IsPartOfTrain && Train != null) + if (isPartOfTrain && train != null) { - Function.Stack[s] = Train.IsPlayerTrain ? 1.0 : 0.0; + function.Stack[s] = train.IsPlayerTrain ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainCars: - if (Train != null) { - Function.Stack[s] = (double)Train.Cars.Length; + if (train != null) { + function.Stack[s] = (double)train.Cars.Length; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainDestination: - if (Train != null) { - Function.Stack[s] = (double)Train.Destination; + if (train != null) { + function.Stack[s] = (double)train.Destination; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainLength: - if (Train != null) { - Function.Stack[s] = Train.Length; + if (train != null) { + function.Stack[s] = train.Length; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainSpeed: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CurrentSpeed; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CurrentSpeed; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainSpeedOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CurrentSpeed; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CurrentSpeed; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.TrainSpeedometer: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].Specs.PerceivedSpeed; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].Specs.PerceivedSpeed; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainSpeedometerOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].Specs.PerceivedSpeed; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].Specs.PerceivedSpeed; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.TrainAcceleration: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].Specs.Acceleration; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].Specs.Acceleration; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainAccelerationOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].Specs.Acceleration; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].Specs.Acceleration; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.TrainAccelerationMotor: - if (Train != null) { - Function.Stack[s] = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - if (Train.Cars[j].Specs.IsMotorCar) { + if (train != null) { + function.Stack[s] = 0.0; + for (int j = 0; j < train.Cars.Length; j++) { + if (train.Cars[j].Specs.IsMotorCar) { // hack: MotorAcceleration does not distinguish between forward/backward - if (Train.Cars[j].Specs.MotorAcceleration < 0.0) { - Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * (double)Math.Sign(Train.Cars[j].CurrentSpeed); - } else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) { - Function.Stack[s] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual; + if (train.Cars[j].Specs.MotorAcceleration < 0.0) { + function.Stack[s] = train.Cars[j].Specs.MotorAcceleration * (double)Math.Sign(train.Cars[j].CurrentSpeed); + } else if (train.Cars[j].Specs.MotorAcceleration > 0.0) { + function.Stack[s] = train.Cars[j].Specs.MotorAcceleration * (double)train.Handles.Reverser.Actual; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } break; } } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainAccelerationMotorOfCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { // hack: MotorAcceleration does not distinguish between forward/backward - if (Train.Cars[j].Specs.MotorAcceleration < 0.0) { - Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * (double)Math.Sign(Train.Cars[j].CurrentSpeed); - } else if (Train.Cars[j].Specs.MotorAcceleration > 0.0) { - Function.Stack[s - 1] = Train.Cars[j].Specs.MotorAcceleration * (double)Train.Handles.Reverser.Actual; + if (train.Cars[j].Specs.MotorAcceleration < 0.0) { + function.Stack[s - 1] = train.Cars[j].Specs.MotorAcceleration * (double)Math.Sign(train.Cars[j].CurrentSpeed); + } else if (train.Cars[j].Specs.MotorAcceleration > 0.0) { + function.Stack[s - 1] = train.Cars[j].Specs.MotorAcceleration * (double)train.Handles.Reverser.Actual; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } 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 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 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); + function.Stack[s] = Math.Sqrt(playerDist); s++; break; case Instructions.TrainDistance: - if (Train != null) { + if (train != null) { double dist = double.MaxValue; - for (int j = 0; j < Train.Cars.Length; j++) { - double fx = Train.Cars[j].FrontAxle.Follower.WorldPosition.X - Position.X; - double fy = Train.Cars[j].FrontAxle.Follower.WorldPosition.Y - Position.Y; - double fz = Train.Cars[j].FrontAxle.Follower.WorldPosition.Z - Position.Z; + for (int j = 0; j < train.Cars.Length; j++) { + double fx = train.Cars[j].FrontAxle.Follower.WorldPosition.X - position.X; + double fy = train.Cars[j].FrontAxle.Follower.WorldPosition.Y - position.Y; + double fz = train.Cars[j].FrontAxle.Follower.WorldPosition.Z - position.Z; double f = fx * fx + fy * fy + fz * fz; if (f < dist) dist = f; - double rx = Train.Cars[j].RearAxle.Follower.WorldPosition.X - Position.X; - double ry = Train.Cars[j].RearAxle.Follower.WorldPosition.Y - Position.Y; - double rz = Train.Cars[j].RearAxle.Follower.WorldPosition.Z - Position.Z; + double rx = train.Cars[j].RearAxle.Follower.WorldPosition.X - position.X; + double ry = train.Cars[j].RearAxle.Follower.WorldPosition.Y - position.Y; + double rz = train.Cars[j].RearAxle.Follower.WorldPosition.Z - position.Z; double r = rx * rx + ry * ry + rz * rz; if (r < dist) dist = r; } - Function.Stack[s] = Math.Sqrt(dist); + function.Stack[s] = Math.Sqrt(dist); } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.TrainDistanceToCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - double x = 0.5 * (Train.Cars[j].FrontAxle.Follower.WorldPosition.X + Train.Cars[j].RearAxle.Follower.WorldPosition.X) - Position.X; - double y = 0.5 * (Train.Cars[j].FrontAxle.Follower.WorldPosition.Y + Train.Cars[j].RearAxle.Follower.WorldPosition.Y) - Position.Y; - double z = 0.5 * (Train.Cars[j].FrontAxle.Follower.WorldPosition.Z + Train.Cars[j].RearAxle.Follower.WorldPosition.Z) - Position.Z; - Function.Stack[s - 1] = Math.Sqrt(x * x + y * y + z * z); + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + double x = 0.5 * (train.Cars[j].FrontAxle.Follower.WorldPosition.X + train.Cars[j].RearAxle.Follower.WorldPosition.X) - position.X; + double y = 0.5 * (train.Cars[j].FrontAxle.Follower.WorldPosition.Y + train.Cars[j].RearAxle.Follower.WorldPosition.Y) - position.Y; + double z = 0.5 * (train.Cars[j].FrontAxle.Follower.WorldPosition.Z + train.Cars[j].RearAxle.Follower.WorldPosition.Z) - position.Z; + function.Stack[s - 1] = Math.Sqrt(x * x + y * y + z * z); } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } 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; + function.Stack[s] = trackPosition > pt0 ? trackPosition - pt0 : trackPosition < pt1 ? trackPosition - pt1 : 0.0; s++; break; case Instructions.TrainTrackDistance: - if (Train != null) { - double t0 = Train.FrontCarTrackPosition; - double t1 = Train.RearCarTrackPosition; - Function.Stack[s] = TrackPosition > t0 ? TrackPosition - t0 : TrackPosition < t1 ? TrackPosition - t1 : 0.0; + if (train != null) { + double t0 = train.FrontCarTrackPosition; + double t1 = train.RearCarTrackPosition; + function.Stack[s] = trackPosition > t0 ? trackPosition - t0 : trackPosition < t1 ? trackPosition - t1 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.CurveRadius: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.CurveRadiusOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = (Train.Cars[j].FrontAxle.Follower.CurveRadius + Train.Cars[j].RearAxle.Follower.CurveRadius) / 2; + function.Stack[s - 1] = (train.Cars[j].FrontAxle.Follower.CurveRadius + train.Cars[j].RearAxle.Follower.CurveRadius) / 2; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.FrontAxleCurveRadius: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.FrontAxleCurveRadiusOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.CurveRadius; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.CurveRadius; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.RearAxleCurveRadius: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.RearAxleCurveRadiusOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].RearAxle.Follower.CurveRadius; + function.Stack[s - 1] = train.Cars[j].RearAxle.Follower.CurveRadius; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.CurveCant: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.CurveCantOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.CurveCant; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.CurveCant; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.Pitch: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.PitchOfCar: - if (Train == null) + if (train == null) { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.Follower.Pitch; + function.Stack[s - 1] = train.Cars[j].FrontAxle.Follower.Pitch; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.Odometer: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.OdometerOfCar: - Function.Stack[s -1] = 0.0; + function.Stack[s -1] = 0.0; break; case Instructions.TrainTrackDistanceToCar: - if (Train != null) { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - double p = 0.5 * (Train.Cars[j].FrontAxle.Follower.TrackPosition + Train.Cars[j].RearAxle.Follower.TrackPosition); - Function.Stack[s - 1] = TrackPosition - p; + if (train != null) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + double p = 0.5 * (train.Cars[j].FrontAxle.Follower.TrackPosition + train.Cars[j].RearAxle.Follower.TrackPosition); + function.Stack[s - 1] = trackPosition - p; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; // door case Instructions.Doors: - if (Train != null) { + if (train != null) { double a = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + for (int j = 0; j < train.Cars.Length; j++) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s] = a; + function.Stack[s] = a; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.DoorsIndex: - if (Train != null) { + if (train != null) { double a = 0.0; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s - 1] = a; + function.Stack[s - 1] = a; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.LeftDoors: - if (Train != null) { + if (train != null) { double a = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == -1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + for (int j = 0; j < train.Cars.Length; j++) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == -1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s] = a; + function.Stack[s] = a; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LeftDoorsIndex: - if (Train != null) { + if (train != null) { double a = 0.0; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == -1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == -1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s - 1] = a; + function.Stack[s - 1] = a; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.RightDoors: - if (Train != null) { + if (train != null) { double a = 0.0; - for (int j = 0; j < Train.Cars.Length; j++) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == 1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + for (int j = 0; j < train.Cars.Length; j++) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == 1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s] = a; + function.Stack[s] = a; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.RightDoorsIndex: - if (Train != null) { + if (train != null) { double a = 0.0; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[k].Direction == 1 & Train.Cars[j].Doors[k].State > a) { - a = Train.Cars[j].Doors[k].State; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[k].Direction == 1 & train.Cars[j].Doors[k].State > a) { + a = train.Cars[j].Doors[k].State; } } } - Function.Stack[s - 1] = a; + function.Stack[s - 1] = a; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.LeftDoorsTarget: - if (Train != null) { + if (train != null) { bool q = false; - for (int j = 0; j < Train.Cars.Length; j++) { - if (Train.Cars[j].Doors[0].AnticipatedOpen) { + for (int j = 0; j < train.Cars.Length; j++) { + if (train.Cars[j].Doors[0].AnticipatedOpen) { q = true; break; } } - Function.Stack[s] = q ? 1.0 : 0.0; + function.Stack[s] = q ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LeftDoorsTargetIndex: - if (Train != null) { + if (train != null) { bool q = false; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[0].AnticipatedOpen) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[0].AnticipatedOpen) { q = true; break; } } } - Function.Stack[s - 1] = q ? 1.0 : 0.0; + function.Stack[s - 1] = q ? 1.0 : 0.0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.RightDoorsTarget: - if (Train != null) { + if (train != null) { bool q = false; - for (int j = 0; j < Train.Cars.Length; j++) { - if (Train.Cars[j].Doors[1].AnticipatedOpen) { + for (int j = 0; j < train.Cars.Length; j++) { + if (train.Cars[j].Doors[1].AnticipatedOpen) { q = true; break; } } - Function.Stack[s] = q ? 1.0 : 0.0; + function.Stack[s] = q ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.RightDoorsTargetIndex: - if (Train != null) { + if (train != null) { bool q = false; - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - for (int k = 0; k < Train.Cars[j].Doors.Length; k++) { - if (Train.Cars[j].Doors[1].AnticipatedOpen) { + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + for (int k = 0; k < train.Cars[j].Doors.Length; k++) { + if (train.Cars[j].Doors[1].AnticipatedOpen) { q = true; break; } } } - Function.Stack[s - 1] = q ? 1.0 : 0.0; + function.Stack[s - 1] = q ? 1.0 : 0.0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } break; case Instructions.PilotLamp: //Not currently supported in viewers - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.PassAlarm: //Not currently supported in viewers - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.StationAdjustAlarm: //Not currently supported in viewers - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.Headlights: - if (Train != null) + if (train != null) { - Function.Stack[s] = Train.SafetySystems.Headlights.CurrentState; + function.Stack[s] = train.SafetySystems.Headlights.CurrentState; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; // handles case Instructions.ReverserNotch: - if (Train != null) { - Function.Stack[s] = (double)Train.Handles.Reverser.Driver; + if (train != null) { + function.Stack[s] = (double)train.Handles.Reverser.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PowerNotch: - if (Train != null) { - Function.Stack[s] = (double)Train.Handles.Power.Driver; + if (train != null) { + function.Stack[s] = (double)train.Handles.Power.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PowerNotches: - if (Train != null) { - Function.Stack[s] = (double)Train.Handles.Power.MaximumNotch; + if (train != null) { + function.Stack[s] = (double)train.Handles.Power.MaximumNotch; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LocoBrakeNotch: - if (Train != null && Train.Handles.LocoBrake != null) { - Function.Stack[s] = Train.Handles.LocoBrake.Driver; + if (train != null && train.Handles.LocoBrake != null) { + function.Stack[s] = train.Handles.LocoBrake.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.LocoBrakeNotches: - if (Train != null) { - Function.Stack[s] = Train.Handles.LocoBrake.MaximumNotch; + if (train != null) { + function.Stack[s] = train.Handles.LocoBrake.MaximumNotch; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotch: - if (Train != null) { - Function.Stack[s] = (double)Train.Handles.Brake.Driver; + if (train != null) { + function.Stack[s] = (double)train.Handles.Brake.Driver; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotches: - if (Train != null) { - if (Train.Handles.Brake is AirBrakeHandle) { - Function.Stack[s] = 2.0; + if (train != null) { + if (train.Handles.Brake is AirBrakeHandle) { + function.Stack[s] = 2.0; } else { - Function.Stack[s] = (double)Train.Handles.Brake.MaximumNotch; + function.Stack[s] = (double)train.Handles.Brake.MaximumNotch; } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotchLinear: - if (Train != null) { - if (Train.Handles.Brake is AirBrakeHandle) { - if (Train.Handles.EmergencyBrake.Driver) { - Function.Stack[s] = 3.0; + if (train != null) { + if (train.Handles.Brake is AirBrakeHandle) { + if (train.Handles.EmergencyBrake.Driver) { + function.Stack[s] = 3.0; } else { - Function.Stack[s] = (double)Train.Handles.Brake.Driver; + function.Stack[s] = (double)train.Handles.Brake.Driver; } - } else if (Train.Handles.HasHoldBrake) { - if (Train.Handles.EmergencyBrake.Driver) { - Function.Stack[s] = (double)Train.Handles.Brake.MaximumNotch + 2.0; - } else if (Train.Handles.Brake.Driver > 0) { - Function.Stack[s] = (double)Train.Handles.Brake.Driver + 1.0; + } else if (train.Handles.HasHoldBrake) { + if (train.Handles.EmergencyBrake.Driver) { + function.Stack[s] = (double)train.Handles.Brake.MaximumNotch + 2.0; + } else if (train.Handles.Brake.Driver > 0) { + function.Stack[s] = (double)train.Handles.Brake.Driver + 1.0; } else { - Function.Stack[s] = Train.Handles.HoldBrake.Driver ? 1.0 : 0.0; + function.Stack[s] = train.Handles.HoldBrake.Driver ? 1.0 : 0.0; } } else { - if (Train.Handles.EmergencyBrake.Driver) { - Function.Stack[s] = (double)Train.Handles.Brake.MaximumNotch + 1.0; + if (train.Handles.EmergencyBrake.Driver) { + function.Stack[s] = (double)train.Handles.Brake.MaximumNotch + 1.0; } else { - Function.Stack[s] = (double)Train.Handles.Brake.Driver; + function.Stack[s] = (double)train.Handles.Brake.Driver; } } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeNotchesLinear: - if (Train != null) { - if (Train.Handles.Brake is AirBrakeHandle) { - Function.Stack[s] = 3.0; - } else if (Train.Handles.HasHoldBrake) { - Function.Stack[s] = Train.Handles.Brake.MaximumNotch + 2.0; + if (train != null) { + if (train.Handles.Brake is AirBrakeHandle) { + function.Stack[s] = 3.0; + } else if (train.Handles.HasHoldBrake) { + function.Stack[s] = train.Handles.Brake.MaximumNotch + 2.0; } else { - Function.Stack[s] = Train.Handles.Brake.MaximumNotch + 1.0; + function.Stack[s] = train.Handles.Brake.MaximumNotch + 1.0; } } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.EmergencyBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.EmergencyBrake.Driver ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.EmergencyBrake.Driver ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.PrimaryKlaxon: @@ -899,165 +899,165 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr case Instructions.SecondaryKlaxon: case Instructions.MusicKlaxon: //Object Viewer doesn't actually have a sound player, so we can't test against it, thus return zero.... - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; s++; break; case Instructions.HasAirBrake: - if (Train != null) { - Function.Stack[s] = Train.Cars[Train.DriverCar].CarBrake is AutomaticAirBrake ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Cars[train.DriverCar].CarBrake is AutomaticAirBrake ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.HoldBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.HoldBrake.Driver ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.HoldBrake.Driver ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.HasHoldBrake: - if (Train != null) { - Function.Stack[s] = Train.Handles.HasHoldBrake ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Handles.HasHoldBrake ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.ConstSpeed: - if (Train != null) { - Function.Stack[s] = Train.Specs.CurrentConstSpeed ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Specs.CurrentConstSpeed ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.HasConstSpeed: - if (Train != null) { - Function.Stack[s] = Train.Specs.HasConstSpeed ? 1.0 : 0.0; + if (train != null) { + function.Stack[s] = train.Specs.HasConstSpeed ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; // brake case Instructions.BrakeMainReservoir: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.MainReservoir.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.MainReservoir.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeMainReservoirOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.MainReservoir.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.MainReservoir.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeEqualizingReservoir: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.EqualizingReservoir.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.EqualizingReservoir.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeEqualizingReservoirOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.EqualizingReservoir.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.EqualizingReservoir.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeBrakePipe: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakePipe.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.BrakePipe.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeBrakePipeOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakePipe.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.BrakePipe.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeBrakeCylinder: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.BrakeCylinder.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.BrakeCylinder.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeBrakeCylinderOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.BrakeCylinder.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.BrakeCylinder.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.BrakeStraightAirPipe: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].CarBrake.StraightAirPipe.CurrentPressure; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].CarBrake.StraightAirPipe.CurrentPressure; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.BrakeStraightAirPipeOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].CarBrake.StraightAirPipe.CurrentPressure; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].CarBrake.StraightAirPipe.CurrentPressure; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; // safety case Instructions.SafetyPluginAvailable: - if (Train != null && Train.IsPlayerTrain) { - Function.Stack[s] = NearestTrain.EnablePluginSimulation ? 1.0 : 0.0; + if (train != null && train.IsPlayerTrain) { + function.Stack[s] = NearestTrain.EnablePluginSimulation ? 1.0 : 0.0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.SafetyPluginState: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int n = (int)Math.Round(Function.Stack[s - 1]); + int n = (int)Math.Round(function.Stack[s - 1]); if (NearestTrain.EnablePluginSimulation) { if (n >= 0 & n < PluginManager.CurrentPlugin.Panel.Length) { - Function.Stack[s - 1] = (double)PluginManager.CurrentPlugin.Panel[n]; + function.Stack[s - 1] = (double)PluginManager.CurrentPlugin.Panel[n]; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; @@ -1067,10 +1067,10 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr { case DisplayedTimetable.Custom: case DisplayedTimetable.Default: - Function.Stack[s] = 1.0; + function.Stack[s] = 1.0; break; case DisplayedTimetable.None: - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; break; } s++; break; @@ -1081,135 +1081,135 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr case Instructions.NextStationStop: case Instructions.RouteLimit: case Instructions.TerminalStation: - Function.Stack[s] = 0.0; //Unsupported in viewers + function.Stack[s] = 0.0; //Unsupported in viewers s++; break; case Instructions.DistanceStation: case Instructions.StopsStation: - Function.Stack[s - 1] = 0.0; //Unsupported in viewers + function.Stack[s - 1] = 0.0; //Unsupported in viewers break; // sections case Instructions.SectionAspectNumber: - if (IsPartOfTrain) { - int nextSectionIndex = Train.CurrentSectionIndex + 1; + if (isPartOfTrain) { + int nextSectionIndex = train.CurrentSectionIndex + 1; if (nextSectionIndex >= 0 & nextSectionIndex < Program.CurrentRoute.Sections.Length) { int a = Program.CurrentRoute.Sections[nextSectionIndex].CurrentAspect; if (a >= 0 & a < Program.CurrentRoute.Sections[nextSectionIndex].Aspects.Length) { - Function.Stack[s] = (double)Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; + function.Stack[s] = (double)Program.CurrentRoute.Sections[nextSectionIndex].Aspects[a].Number; } else { - Function.Stack[s] = 0; + function.Stack[s] = 0; } } - } else if (SectionIndex >= 0 & SectionIndex < Program.CurrentRoute.Sections.Length) { - int a = Program.CurrentRoute.Sections[SectionIndex].CurrentAspect; - if (a >= 0 & a < Program.CurrentRoute.Sections[SectionIndex].Aspects.Length) { - Function.Stack[s] = (double)Program.CurrentRoute.Sections[SectionIndex].Aspects[a].Number; + } else if (sectionIndex >= 0 & sectionIndex < Program.CurrentRoute.Sections.Length) { + int a = Program.CurrentRoute.Sections[sectionIndex].CurrentAspect; + if (a >= 0 & a < Program.CurrentRoute.Sections[sectionIndex].Aspects.Length) { + function.Stack[s] = (double)Program.CurrentRoute.Sections[sectionIndex].Aspects[a].Number; } else { - Function.Stack[s] = 0; + function.Stack[s] = 0; } } else { - Function.Stack[s] = 0; + function.Stack[s] = 0; } s++; break; case Instructions.Panel2Timetable: - throw new InvalidOperationException("The instruction " + Function.InstructionSet[i].ToString() + " is for internal use only, and should not be added to objects."); + throw new InvalidOperationException("The instruction " + function.InstructionSet[i].ToString() + " is for internal use only, and should not be added to objects."); case Instructions.BrightnessOfCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].Brightness.CurrentBrightness(Program.Renderer.Lighting.DynamicCabBrightness, 0.0); + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].Brightness.CurrentBrightness(Program.Renderer.Lighting.DynamicCabBrightness, 0.0); } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.TrainCarNumber: - if (!IsPartOfTrain) + if (!isPartOfTrain) { - Function.Stack[s] = -1; + function.Stack[s] = -1; } else { - Function.Stack[s] = CarIndex; + function.Stack[s] = carIndex; } s++; break; case Instructions.WheelSlip: - if (Train != null) { - Function.Stack[s] = Train.Cars[CarIndex].FrontAxle.CurrentWheelSlip ? 1 : 0; + if (train != null) { + function.Stack[s] = train.Cars[carIndex].FrontAxle.CurrentWheelSlip ? 1 : 0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } s++; break; case Instructions.WheelSlipCar: - if (Train == null) { - Function.Stack[s - 1] = 0.0; + if (train == null) { + function.Stack[s - 1] = 0.0; } else { - int j = (int)Math.Round(Function.Stack[s - 1]); - if (j < 0) j += Train.Cars.Length; - if (j >= 0 & j < Train.Cars.Length) { - Function.Stack[s - 1] = Train.Cars[j].FrontAxle.CurrentWheelSlip ? 1 : 0; + int j = (int)Math.Round(function.Stack[s - 1]); + if (j < 0) j += train.Cars.Length; + if (j >= 0 & j < train.Cars.Length) { + function.Stack[s - 1] = train.Cars[j].FrontAxle.CurrentWheelSlip ? 1 : 0; } else { - Function.Stack[s - 1] = 0.0; + function.Stack[s - 1] = 0.0; } } break; case Instructions.Sanders: { - if (Train != null && Train.Cars[CarIndex].ReAdhesionDevice is Sanders sanders) + if (train != null && train.Cars[carIndex].ReAdhesionDevice is Sanders sanders) { - Function.Stack[s] = sanders.Active ? 1 : 0; + function.Stack[s] = sanders.Active ? 1 : 0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.SandLevel: { - if (Train != null && Train.Cars[CarIndex].ReAdhesionDevice is Sanders sanders) + if (train != null && train.Cars[carIndex].ReAdhesionDevice is Sanders sanders) { - Function.Stack[s] = sanders.SandLevel; + function.Stack[s] = sanders.SandLevel; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.SandShots: { - if (Train != null && Train.Cars[CarIndex].ReAdhesionDevice is Sanders sanders) { - Function.Stack[s] = sanders.NumberOfShots; + if (train != null && train.Cars[carIndex].ReAdhesionDevice is Sanders sanders) { + function.Stack[s] = sanders.NumberOfShots; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.DSD: { - if (Train != null && Train.Cars[Train.DriverCar].DSD != null) + if (train != null && train.Cars[train.DriverCar].DSD != null) { - Function.Stack[s] = Train.Cars[Train.DriverCar].DSD.Triggered ? 1 : 0; + function.Stack[s] = train.Cars[train.DriverCar].DSD.Triggered ? 1 : 0; } else { - Function.Stack[s] = 0.0; + function.Stack[s] = 0.0; } } s++; break; case Instructions.AmbientTemperature: { - if (Train != null) + if (train != null) { - Function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(Train.Cars[CarIndex].FrontAxle.Follower.WorldPosition.Y + Program.CurrentRoute.Atmosphere.InitialElevation); + function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(train.Cars[carIndex].FrontAxle.Follower.WorldPosition.Y + Program.CurrentRoute.Atmosphere.InitialElevation); } else { - Function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(Position.Y + Program.CurrentRoute.Atmosphere.InitialElevation); + function.Stack[s] = Program.CurrentRoute.Atmosphere.GetAirTemperature(position.Y + Program.CurrentRoute.Atmosphere.InitialElevation); } } s++; break; @@ -1218,16 +1218,16 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr // Viewers don't simulate weather // Force all these to show to allow the developer to place them // In-game, they'll randomise appropriately.... - Function.Stack[s - 1] = 1.0; + function.Stack[s - 1] = 1.0; break; case Instructions.WiperPosition: - Function.Stack[s] = 1.0; + function.Stack[s] = 1.0; s++; break; default: - throw new InvalidOperationException("The unknown instruction " + Function.InstructionSet[i] + " was encountered in ExecuteFunctionScript."); + throw new InvalidOperationException("The unknown instruction " + function.InstructionSet[i] + " was encountered in ExecuteFunctionScript."); } } - Function.LastResult = Function.Stack[s - 1]; + function.LastResult = function.Stack[s - 1]; } // mathematical functions diff --git a/source/ObjectViewer/Game/Menu.SingleMenu.cs b/source/ObjectViewer/Game/Menu.SingleMenu.cs index f5590cd2d..648a2beb6 100644 --- a/source/ObjectViewer/Game/Menu.SingleMenu.cs +++ b/source/ObjectViewer/Game/Menu.SingleMenu.cs @@ -5,7 +5,6 @@ using OpenBveApi.Textures; using System; using System.IO; -using OpenBveApi.Math; using Path = OpenBveApi.Path; namespace ObjectViewer @@ -15,9 +14,9 @@ public sealed partial class GameMenu /// Provides implementation for a single menu of the menu stack. /// The class is private to Menu, but all its fields are public to allow 'quick-and-dirty' /// access from Menu itself. - private class SingleMenu : MenuBase + private sealed class SingleMenu : MenuBase { - public SingleMenu(AbstractMenu menu, MenuType menuType, int data = 0, double MaxWidth = 0) : base(menuType) + public SingleMenu(AbstractMenu menu, MenuType menuType, int data = 0, double maxWidth = 0) : base(menuType) { //Vector2 size; Align = TextAlignment.TopMiddle; @@ -165,7 +164,7 @@ public SingleMenu(AbstractMenu menu, MenuType menuType, int data = 0, double Max break; } - ComputeExtent(menuType, Game.Menu.MenuFont, MaxWidth); + ComputeExtent(menuType, Game.Menu.MenuFont, maxWidth); Height = Items.Length * Game.Menu.lineHeight; TopItem = 0; diff --git a/source/ObjectViewer/Game/Menu.cs b/source/ObjectViewer/Game/Menu.cs index 4c9ddc67d..3e285b945 100644 --- a/source/ObjectViewer/Game/Menu.cs +++ b/source/ObjectViewer/Game/Menu.cs @@ -17,8 +17,8 @@ namespace ObjectViewer public sealed partial class GameMenu: AbstractMenu { - internal Picturebox filePictureBox; - internal Textbox fileTextBox; + private Picturebox filePictureBox; + private Textbox fileTextBox; private double lastTimeElapsed; private static string SearchDirectory; private static string currentFile; @@ -220,7 +220,7 @@ public override void ProcessCommand(Translations.Command cmd, double timeElapsed public override bool ProcessMouseMove(int x, int y) { - Program.currentGameWindow.CursorVisible = true; + Program.CurrentGameWindow.CursorVisible = true; if (CurrMenu < 0) { return false; @@ -266,10 +266,10 @@ public override bool ProcessMouseMove(int x, int y) return false; } - public override void Draw(double RealTimeElapsed) + public override void Draw(double realTimeElapsed) { - double TimeElapsed = RealTimeElapsed - lastTimeElapsed; - lastTimeElapsed = RealTimeElapsed; + double timeElapsed = realTimeElapsed - lastTimeElapsed; + lastTimeElapsed = realTimeElapsed; int i; if (CurrMenu < 0 || CurrMenu >= Menus.Length) @@ -358,14 +358,14 @@ public override void Draw(double RealTimeElapsed) } // draw the text - Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(TimeElapsed), new Vector2(itemX, itemY), + Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(timeElapsed), new Vector2(itemX, itemY), menu.Align, ColourHighlight, false); } else if (menu.Items[i] is MenuCaption) - Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(TimeElapsed), new Vector2(itemX, itemY), + Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(timeElapsed), new Vector2(itemX, itemY), menu.Align, ColourCaption, false); else - Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(TimeElapsed), new Vector2(itemX, itemY), + Renderer.OpenGlString.Draw(MenuFont, menu.Items[i].DisplayText(timeElapsed), new Vector2(itemX, itemY), menu.Align, ColourNormal, false); if (menu.Items[i] is MenuOption opt) { diff --git a/source/ObjectViewer/Graphics/NewRendererS.cs b/source/ObjectViewer/Graphics/NewRendererS.cs index 0f20da1c9..801b1e0b8 100644 --- a/source/ObjectViewer/Graphics/NewRendererS.cs +++ b/source/ObjectViewer/Graphics/NewRendererS.cs @@ -429,28 +429,28 @@ private void RenderOverlays(double timeElapsed) public override void SetWindowState(WindowState windowState) { - Program.currentGameWindow.WindowState = windowState; + Program.CurrentGameWindow.WindowState = windowState; if (windowState == WindowState.Fullscreen) { // move origin appropriately - Program.currentGameWindow.X = 0; - Program.currentGameWindow.Y = 0; + Program.CurrentGameWindow.X = 0; + Program.CurrentGameWindow.Y = 0; } } public override void SetWindowSize(int width, int height) { - Program.currentGameWindow.Width = width; - Program.currentGameWindow.Height = height; + Program.CurrentGameWindow.Width = width; + Program.CurrentGameWindow.Height = height; Screen.Width = width; Screen.Height = height; } - public NewRenderer(HostInterface CurrentHost, BaseOptions CurrentOptions, FileSystem FileSystem) : base(CurrentHost, CurrentOptions, FileSystem) + public NewRenderer(HostInterface currentHost, BaseOptions currentOptions, FileSystem fileSystem) : base(currentHost, currentOptions, fileSystem) { - Screen.Width = CurrentOptions.WindowWidth; - Screen.Height = CurrentOptions.WindowHeight; - CameraTrackFollower = new TrackFollower(CurrentHost); + Screen.Width = currentOptions.WindowWidth; + Screen.Height = currentOptions.WindowHeight; + CameraTrackFollower = new TrackFollower(currentHost); } } } diff --git a/source/ObjectViewer/InterfaceS.cs b/source/ObjectViewer/InterfaceS.cs index e5db1f715..dd12a0ba8 100644 --- a/source/ObjectViewer/InterfaceS.cs +++ b/source/ObjectViewer/InterfaceS.cs @@ -36,8 +36,8 @@ internal static class Interface { internal static readonly List LogMessages = new List(); - internal static void AddMessage(MessageType Type, bool FileNotFound, string Text) { - LogMessages.Add(new LogMessage(Type, FileNotFound, Text)); + internal static void AddMessage(MessageType messageType, bool fileNotFound, string messageText) { + LogMessages.Add(new LogMessage(messageType, fileNotFound, messageText)); } /// The current options in use diff --git a/source/ObjectViewer/ObjectManager.cs b/source/ObjectViewer/ObjectManager.cs index 81bb20ddc..706425695 100644 --- a/source/ObjectViewer/ObjectManager.cs +++ b/source/ObjectViewer/ObjectManager.cs @@ -8,17 +8,17 @@ internal static class ObjectManager internal static WorldObject[] AnimatedWorldObjects = new WorldObject[4]; internal static int AnimatedWorldObjectsUsed = 0; - internal static void UpdateAnimatedWorldObjects(double TimeElapsed, bool ForceUpdate) + internal static void UpdateAnimatedWorldObjects(double timeElapsed, bool forceUpdate) { for (int i = 0; i < AnimatedWorldObjectsUsed; i++) { AbstractTrain train = null; bool visible = AnimatedWorldObjects[i].IsVisible(Program.Renderer.Camera.Alignment.Position, Program.CurrentRoute.CurrentBackground.BackgroundImageDistance, Program.Renderer.Camera.ExtraViewingDistance); - if (visible | ForceUpdate) + if (visible | forceUpdate) { train = Program.CurrentHost.ClosestTrain(AnimatedWorldObjects[i].RelativeTrackPosition); } - AnimatedWorldObjects[i].Update(train, TimeElapsed, ForceUpdate, visible); + AnimatedWorldObjects[i].Update(train, timeElapsed, forceUpdate, visible); } } } diff --git a/source/ObjectViewer/ProgramS.cs b/source/ObjectViewer/ProgramS.cs index fd1ea2723..ffcb167bf 100644 --- a/source/ObjectViewer/ProgramS.cs +++ b/source/ObjectViewer/ProgramS.cs @@ -19,7 +19,6 @@ using OpenBveApi.Hosts; using OpenBveApi.Interface; using OpenBveApi.Objects; -using OpenBveApi.Routes; using OpenBveApi.Trains; using OpenTK; using OpenTK.Graphics; @@ -54,10 +53,10 @@ internal static class Program { private static bool ShiftPressed = false; - internal static GameWindow currentGameWindow; - internal static GraphicsMode currentGraphicsMode; + internal static GameWindow CurrentGameWindow; + internal static GraphicsMode CurrentGraphicsMode; - internal static OpenBveApi.Hosts.HostInterface CurrentHost; + internal static HostInterface CurrentHost; internal static NewRenderer Renderer; @@ -165,15 +164,15 @@ internal static void Main(string[] args) Translations.LoadLanguageFiles(folder); GameMenu.Instance = new GameMenu(); // initialize camera - currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8,Interface.CurrentOptions.AntiAliasingLevel); - currentGameWindow = new ObjectViewer(Renderer.Screen.Width, Renderer.Screen.Height, currentGraphicsMode, "Object Viewer", GameWindowFlags.Default) + CurrentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8,Interface.CurrentOptions.AntiAliasingLevel); + CurrentGameWindow = new ObjectViewer(Renderer.Screen.Width, Renderer.Screen.Height, CurrentGraphicsMode, "Object Viewer", GameWindowFlags.Default) { Visible = true, TargetUpdateFrequency = 0, TargetRenderFrequency = 0, Title = "Object Viewer" }; - currentGameWindow.Run(); + CurrentGameWindow.Run(); // quit Renderer.TextureManager.UnloadAllTextures(false); @@ -241,7 +240,7 @@ internal static void MouseEvent(object sender, MouseButtonEventArgs e) { MouseButton = e.Mouse.RightButton == ButtonState.Pressed ? 3 : 0; } - previousMouseState = Mouse.GetState(); + PreviousMouseState = Mouse.GetState(); break; } @@ -260,14 +259,14 @@ internal static void DragFile(object sender, FileDropEventArgs e) Renderer.ApplyBackgroundColor(); } - internal static MouseState currentMouseState; - internal static MouseState previousMouseState; + internal static MouseState CurrentMouseState; + internal static MouseState PreviousMouseState; internal static void MouseMovement() { if (MouseButton == 0 || Program.Renderer.CurrentInterface != InterfaceType.Normal) return; - currentMouseState = Mouse.GetState(); - if (currentMouseState != previousMouseState) + CurrentMouseState = Mouse.GetState(); + if (CurrentMouseState != PreviousMouseState) { if (MouseButton == 1) { @@ -275,13 +274,13 @@ internal static void MouseMovement() Renderer.Camera.AbsoluteUp = MouseCameraUp; Renderer.Camera.AbsoluteSide = MouseCameraSide; { - double dx = 0.0025 * (previousMouseState.X - currentMouseState.X); + double dx = 0.0025 * (PreviousMouseState.X - CurrentMouseState.X); Renderer.Camera.AbsoluteDirection.Rotate(Vector3.Down, dx); Renderer.Camera.AbsoluteUp.Rotate(Vector3.Down, dx); Renderer.Camera.AbsoluteSide.Rotate(Vector3.Down, dx); } { - double dy = 0.0025 * (previousMouseState.Y - currentMouseState.Y); + double dy = 0.0025 * (PreviousMouseState.Y - CurrentMouseState.Y); Renderer.Camera.AbsoluteDirection.Rotate(Renderer.Camera.AbsoluteSide, dy); Renderer.Camera.AbsoluteUp.Rotate(Renderer.Camera.AbsoluteSide, dy); } @@ -289,17 +288,17 @@ internal static void MouseMovement() else if(MouseButton == 2) { Renderer.Camera.AbsolutePosition = MouseCameraPosition; - double dx = -0.025 * (currentMouseState.X - previousMouseState.X); + double dx = -0.025 * (CurrentMouseState.X - PreviousMouseState.X); Renderer.Camera.AbsolutePosition += dx * Renderer.Camera.AbsoluteSide; - double dy = 0.025 * (currentMouseState.Y - previousMouseState.Y); + double dy = 0.025 * (CurrentMouseState.Y - PreviousMouseState.Y); Renderer.Camera.AbsolutePosition += dy * Renderer.Camera.AbsoluteUp; } else { Renderer.Camera.AbsolutePosition = MouseCameraPosition; - double dx = -0.025 * (currentMouseState.X - previousMouseState.X); + double dx = -0.025 * (CurrentMouseState.X - PreviousMouseState.X); Renderer.Camera.AbsolutePosition += dx * Renderer.Camera.AbsoluteSide; - double dz = -0.025 * (currentMouseState.Y - previousMouseState.Y); + double dz = -0.025 * (CurrentMouseState.Y - PreviousMouseState.Y); Renderer.Camera.AbsolutePosition += dz * Renderer.Camera.AbsoluteDirection; } } diff --git a/source/ObjectViewer/Trains/NearestTrainStatus.cs b/source/ObjectViewer/Trains/NearestTrainStatus.cs index 02e6946f0..32b1199b7 100644 --- a/source/ObjectViewer/Trains/NearestTrainStatus.cs +++ b/source/ObjectViewer/Trains/NearestTrainStatus.cs @@ -1,5 +1,4 @@ using System.Linq; -using OpenBveApi.Runtime; using TrainManager.Car; using TrainManager.Handles; using TrainManager.Trains; diff --git a/source/ObjectViewer/formOptions.cs b/source/ObjectViewer/formOptions.cs index dc30330c7..7674d271d 100644 --- a/source/ObjectViewer/formOptions.cs +++ b/source/ObjectViewer/formOptions.cs @@ -84,7 +84,7 @@ private void CloseButton_Click(object sender, EventArgs e) Interface.CurrentOptions.AntiAliasingLevel = (int) AntialiasingLevel.Value; if (Interface.CurrentOptions.AntiAliasingLevel != previousAntialasingLevel) { - Program.currentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel); + Program.CurrentGraphicsMode = new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8, Interface.CurrentOptions.AntiAliasingLevel); } //Transparency quality @@ -104,13 +104,13 @@ private void CloseButton_Click(object sender, EventArgs e) if (width.Value >= 300) { Program.Renderer.Screen.Width = (int) width.Value; - Program.currentGameWindow.Width = (int) width.Value; + Program.CurrentGameWindow.Width = (int) width.Value; } if (height.Value >= 300) { Program.Renderer.Screen.Height = (int) height.Value; - Program.currentGameWindow.Height = (int) height.Value; + Program.CurrentGameWindow.Height = (int) height.Value; } Program.Renderer.UpdateViewport(); From 7f2ea55a0c75adde39b43dd40db2d06532ce50fe Mon Sep 17 00:00:00 2001 From: Christopher Lees Date: Tue, 12 Nov 2024 11:00:05 +0000 Subject: [PATCH 7/7] Change: Enforce lowerCamelCase for parameter names (P7) Main program --- source/LibRender2/BaseRenderer.cs | 2 +- source/OpenBVE/Graphics/NewRenderer.cs | 32 +- source/OpenBVE/Graphics/Renderers/Touch.cs | 12 +- source/OpenBVE/System/GameWindow.cs | 20 +- source/OpenBVE/System/Input/Controls.cs | 324 +++++++++--------- source/OpenBVE/System/Input/Keyboard.cs | 4 +- .../System/Input/ProcessControls.Analog.cs | 80 ++--- .../System/Input/ProcessControls.Digital.cs | 72 ++-- .../OpenBVE/System/Input/ProcessControls.cs | 16 +- source/OpenBVE/System/Interface.cs | 48 +-- source/OpenBVE/System/Loading.cs | 134 ++++---- source/OpenBVE/System/Logging/BlackBox.cs | 306 ++++++++--------- source/OpenBVE/System/Logging/Score.cs | 144 ++++---- source/OpenBVE/System/MainLoop.cs | 46 +-- source/OpenBVE/System/Options.cs | 12 +- source/OpenBVE/System/Program.cs | 2 +- source/OpenBVE/System/Program/CommandLine.cs | 42 +-- .../UserInterface/formMain.Packages.cs | 2 +- source/OpenBVE/UserInterface/formMain.cs | 8 +- 19 files changed, 643 insertions(+), 663 deletions(-) diff --git a/source/LibRender2/BaseRenderer.cs b/source/LibRender2/BaseRenderer.cs index 284a4e385..599e25cf5 100644 --- a/source/LibRender2/BaseRenderer.cs +++ b/source/LibRender2/BaseRenderer.cs @@ -1721,7 +1721,7 @@ public void SetCursor(OpenTK.MouseCursor newCursor) /// Sets the window state /// The new window state - public void SetWindowState(OpenTK.WindowState windowState) + public void SetWindowState(WindowState windowState) { GameWindow.WindowState = windowState; if (windowState == WindowState.Fullscreen) diff --git a/source/OpenBVE/Graphics/NewRenderer.cs b/source/OpenBVE/Graphics/NewRenderer.cs index 2cacf5d2f..4bd1917d1 100644 --- a/source/OpenBVE/Graphics/NewRenderer.cs +++ b/source/OpenBVE/Graphics/NewRenderer.cs @@ -18,9 +18,7 @@ using OpenBveApi.Objects; using OpenBveApi.Routes; using OpenBveApi.World; -using OpenTK; using OpenTK.Graphics.OpenGL; -using MouseCursor = OpenTK.MouseCursor; using Vector3 = OpenBveApi.Math.Vector3; namespace OpenBve.Graphics @@ -51,7 +49,7 @@ internal enum DistanceToNextStationDisplayMode internal bool OptionBrakeSystems = false; internal bool DebugTouchMode = false; - internal Shader pickingShader; + internal Shader PickingShader; private Events events; private Overlays overlays; internal Touch Touch; @@ -63,13 +61,13 @@ public override void Initialize() { try { - if (pickingShader == null) + if (PickingShader == null) { - pickingShader = new Shader(this, "default", "picking", true); + PickingShader = new Shader(this, "default", "picking", true); } - pickingShader.Activate(); - pickingShader.Deactivate(); + PickingShader.Activate(); + PickingShader.Deactivate(); } catch { @@ -89,22 +87,22 @@ public override void Initialize() Program.FileSystem.AppendToLogFile("Renderer initialised successfully."); } - internal int CreateStaticObject(UnifiedObject Prototype, Vector3 Position, Transformation WorldTransformation, Transformation LocalTransformation, ObjectDisposalMode AccurateObjectDisposal, double AccurateObjectDisposalZOffset, double StartingDistance, double EndingDistance, double BlockLength, double TrackPosition, double Brightness) + internal int CreateStaticObject(UnifiedObject prototype, Vector3 position, Transformation worldTransformation, Transformation localTransformation, ObjectDisposalMode accurateObjectDisposal, double accurateObjectDisposalZOffset, double startingDistance, double endingDistance, double blockLength, double trackPosition, double brightness) { - StaticObject obj = Prototype as StaticObject; + StaticObject obj = prototype as StaticObject; if (obj == null) { Interface.AddMessage(MessageType.Error, false, "Attempted to use an animated object where only static objects are allowed."); return -1; } - return base.CreateStaticObject(obj, Position, WorldTransformation, LocalTransformation, AccurateObjectDisposal, AccurateObjectDisposalZOffset, StartingDistance, EndingDistance, BlockLength, TrackPosition, Brightness); + return base.CreateStaticObject(obj, position, worldTransformation, localTransformation, accurateObjectDisposal, accurateObjectDisposalZOffset, startingDistance, endingDistance, blockLength, trackPosition, brightness); } - public override void UpdateViewport(int Width, int Height) + public override void UpdateViewport(int width, int height) { _programLogo = null; - Screen.Width = Width; - Screen.Height = Height; + Screen.Width = width; + Screen.Height = height; GL.Viewport(0, 0, Screen.Width, Screen.Height); Screen.AspectRatio = Screen.Width / (double)Screen.Height; @@ -125,7 +123,7 @@ public override void UpdateViewport(int Width, int Height) } // render scene - internal void RenderScene(double TimeElapsed, double RealTimeElapsed) + internal void RenderScene(double timeElapsed, double realTimeElapsed) { ReleaseResources(); // initialize @@ -200,7 +198,7 @@ internal void RenderScene(double TimeElapsed, double RealTimeElapsed) // render background GL.Disable(EnableCap.DepthTest); - Program.CurrentRoute.UpdateBackground(TimeElapsed, Program.Renderer.CurrentInterface != InterfaceType.Normal); + Program.CurrentRoute.UpdateBackground(timeElapsed, Program.Renderer.CurrentInterface != InterfaceType.Normal); events.Render(Camera.AbsolutePosition); @@ -482,11 +480,11 @@ internal void RenderScene(double TimeElapsed, double RealTimeElapsed) UnsetAlphaFunc(); SetBlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); //FIXME: Remove when text switches between two renderer types GL.Disable(EnableCap.DepthTest); - overlays.Render(RealTimeElapsed); + overlays.Render(realTimeElapsed); OptionLighting = true; } - public NewRenderer(HostInterface CurrentHost, BaseOptions CurrentOptions, FileSystem FileSystem) : base(CurrentHost, CurrentOptions, FileSystem) + public NewRenderer(HostInterface currentHost, BaseOptions currentOptions, FileSystem fileSystem) : base(currentHost, currentOptions, fileSystem) { } } diff --git a/source/OpenBVE/Graphics/Renderers/Touch.cs b/source/OpenBVE/Graphics/Renderers/Touch.cs index 83e3df07f..98176a3bc 100644 --- a/source/OpenBVE/Graphics/Renderers/Touch.cs +++ b/source/OpenBVE/Graphics/Renderers/Touch.cs @@ -60,7 +60,7 @@ private void ShowObject(ObjectState state) if (renderer.AvailableNewRenderer && state.Prototype.Mesh.VAO == null) { - VAOExtensions.CreateVAO(ref state.Prototype.Mesh, state.Prototype.Dynamic, renderer.pickingShader.VertexLayout, renderer); + VAOExtensions.CreateVAO(ref state.Prototype.Mesh, state.Prototype.Dynamic, renderer.PickingShader.VertexLayout, renderer); } } @@ -116,21 +116,21 @@ internal void RenderScene() fbo.Bind(); GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - renderer.pickingShader.Activate(); - renderer.pickingShader.SetCurrentProjectionMatrix(renderer.CurrentProjectionMatrix); + renderer.PickingShader.Activate(); + renderer.PickingShader.SetCurrentProjectionMatrix(renderer.CurrentProjectionMatrix); for (int i = 0; i < touchableObject.Count; i++) { - renderer.pickingShader.SetObjectIndex(i + 1); + renderer.PickingShader.SetObjectIndex(i + 1); foreach (MeshFace face in touchableObject[i].Prototype.Mesh.Faces) { - renderer.RenderFace(renderer.pickingShader, touchableObject[i], face); + renderer.RenderFace(renderer.PickingShader, touchableObject[i], face); } } //Must deactivate and unbind here - renderer.pickingShader.Deactivate(); + renderer.PickingShader.Deactivate(); fbo.UnBind(); } diff --git a/source/OpenBVE/System/GameWindow.cs b/source/OpenBVE/System/GameWindow.cs index dc69e7d1f..cbe31b449 100644 --- a/source/OpenBVE/System/GameWindow.cs +++ b/source/OpenBVE/System/GameWindow.cs @@ -403,7 +403,7 @@ protected override void OnLoad(EventArgs e) Program.Renderer.Loading.InitLoading(Program.FileSystem.GetDataFolder("In-game"), typeof(NewRenderer).Assembly.GetName().Version.ToString()); Program.Renderer.UpdateViewport(ViewportChangeMode.NoChange); Program.Renderer.MotionBlur.Initialize(Interface.CurrentOptions.MotionBlur); - if (string.IsNullOrEmpty(MainLoop.currentResult.RouteFile)) + if (string.IsNullOrEmpty(MainLoop.CurrentResult.RouteFile)) { Game.Menu.PushMenu(MenuType.GameStart); Loading.Complete = true; @@ -412,17 +412,17 @@ protected override void OnLoad(EventArgs e) } else { - Loading.LoadAsynchronously(MainLoop.currentResult.RouteFile, MainLoop.currentResult.RouteEncoding, MainLoop.currentResult.TrainFolder, MainLoop.currentResult.TrainEncoding); + Loading.LoadAsynchronously(MainLoop.CurrentResult.RouteFile, MainLoop.CurrentResult.RouteEncoding, MainLoop.CurrentResult.TrainFolder, MainLoop.CurrentResult.TrainEncoding); LoadingScreenLoop(); } //Add event handler hooks for keyboard and mouse buttons //Do this after the renderer has init and the loop has started to prevent timing issues - KeyDown += MainLoop.keyDownEvent; - KeyUp += MainLoop.keyUpEvent; - MouseDown += MainLoop.mouseDownEvent; - MouseUp += MainLoop.mouseUpEvent; - MouseMove += MainLoop.mouseMoveEvent; - MouseWheel += MainLoop.mouseWheelEvent; + KeyDown += MainLoop.KeyDownEvent; + KeyUp += MainLoop.KeyUpEvent; + MouseDown += MainLoop.MouseDownEvent; + MouseUp += MainLoop.MouseUpEvent; + MouseMove += MainLoop.MouseMoveEvent; + MouseWheel += MainLoop.MouseWheelEvent; FileDrop += GameMenu.Instance.DragFile; for (int i = 0; i < InputDevicePlugin.AvailablePluginInfos.Count; i++) @@ -575,8 +575,8 @@ private void SetupSimulation() } } Program.Renderer.Lighting.Initialize(); - Game.LogRouteName = Path.GetFileName(MainLoop.currentResult.RouteFile); - Game.LogTrainName = Path.GetFileName(MainLoop.currentResult.TrainFolder); + Game.LogRouteName = Path.GetFileName(MainLoop.CurrentResult.RouteFile); + Game.LogTrainName = Path.GetFileName(MainLoop.CurrentResult.TrainFolder); Game.LogDateTime = DateTime.Now; if (Interface.CurrentOptions.LoadInAdvance) diff --git a/source/OpenBVE/System/Input/Controls.cs b/source/OpenBVE/System/Input/Controls.cs index 84fa2f169..f8be06630 100644 --- a/source/OpenBVE/System/Input/Controls.cs +++ b/source/OpenBVE/System/Input/Controls.cs @@ -17,28 +17,28 @@ internal static partial class Interface internal static Control[] CurrentControls = { }; /// Saves a control configuration to disk - /// An absolute file path if we are exporting the controls, or a null reference to save to the default configuration location + /// An absolute file path if we are exporting the controls, or a null reference to save to the default configuration location /// The list of controls to save - internal static void SaveControls(string FileOrNull, Control[] controlsToSave) { - System.Text.StringBuilder Builder = new System.Text.StringBuilder(); - Builder.AppendLine("; Current control configuration"); - Builder.AppendLine("; ============================="); - Builder.AppendLine("; This file was automatically generated. Please modify only if you know what you're doing."); - Builder.AppendLine("; This file is INCOMPATIBLE with versions older than 1.4.4."); - Builder.AppendLine(); + internal static void SaveControls(string fileOrNull, Control[] controlsToSave) { + System.Text.StringBuilder builder = new System.Text.StringBuilder(); + builder.AppendLine("; Current control configuration"); + builder.AppendLine("; ============================="); + builder.AppendLine("; This file was automatically generated. Please modify only if you know what you're doing."); + builder.AppendLine("; This file is INCOMPATIBLE with versions older than 1.4.4."); + builder.AppendLine(); for (int i = 0; i < controlsToSave.Length; i++) { if (controlsToSave[i].Command == Translations.Command.None) { // don't save a control with no command set, just stores up problems for later continue; } - Translations.CommandInfo Info = Translations.CommandInfos.TryGetInfo(controlsToSave[i].Command); - Builder.Append(Info.Name + ", " + controlsToSave[i]); + Translations.CommandInfo info = Translations.CommandInfos.TryGetInfo(controlsToSave[i].Command); + builder.Append(info.Name + ", " + controlsToSave[i]); - Builder.Append("\n"); + builder.Append("\n"); } - string File = FileOrNull ?? OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "1.5.0/controls.cfg"); - System.IO.File.WriteAllText(File, Builder.ToString(), new System.Text.UTF8Encoding(true)); + string file = fileOrNull ?? OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "1.5.0/controls.cfg"); + File.WriteAllText(file, builder.ToString(), new System.Text.UTF8Encoding(true)); } private static bool ControlsReset = false; @@ -58,35 +58,35 @@ private static string[] GetLines(Stream resourceStream) } /// Loads the current controls from the controls.cfg file - /// An absolute path reference to a saved controls.cfg file, or a null reference to check the default locations - /// The current controls array - internal static void LoadControls(string FileOrNull, out Control[] Controls) + /// An absolute path reference to a saved controls.cfg file, or a null reference to check the default locations + /// The current controls array + internal static void LoadControls(string fileOrNull, out Control[] controls) { - string File; - string[] Lines = {}; + string file; + string[] lines = {}; try { //Don't crash horribly if the embedded default controls file is missing (makefile.....) - Lines = GetLines(Assembly.GetExecutingAssembly().GetManifestResourceStream("OpenBve.Default.controls")); + lines = GetLines(Assembly.GetExecutingAssembly().GetManifestResourceStream("OpenBve.Default.controls")); } catch { //ignored } - if (FileOrNull == null) + if (fileOrNull == null) { - File = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "1.5.0/controls.cfg"); - if (!System.IO.File.Exists(File)) + file = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "1.5.0/controls.cfg"); + if (!File.Exists(file)) { - File = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "controls.cfg"); + file = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "controls.cfg"); } - if (!System.IO.File.Exists(File)) + if (!File.Exists(file)) { //Load the default key assignments if the user settings don't exist - File = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Controls"), "Default.controls"); - if (!System.IO.File.Exists(File)) + file = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Controls"), "Default.controls"); + if (!File.Exists(file)) { MessageBox.Show(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"errors","warning"}) + Environment.NewLine + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"errors","controls_missing"}), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); @@ -95,57 +95,57 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls) } else { - File = FileOrNull; + file = fileOrNull; } - Controls = new Control[256]; - int Length = 0; - CultureInfo Culture = CultureInfo.InvariantCulture; - if (System.IO.File.Exists(File)) + controls = new Control[256]; + int length = 0; + CultureInfo culture = CultureInfo.InvariantCulture; + if (File.Exists(file)) { - Lines = System.IO.File.ReadAllLines(File, new System.Text.UTF8Encoding()); + lines = File.ReadAllLines(file, new System.Text.UTF8Encoding()); } - for (int i = 0; i < Lines.Length; i++) + for (int i = 0; i < lines.Length; i++) { - Lines[i] = Lines[i].Trim(); - if (Lines[i].Length != 0 && !Lines[i].StartsWith(";", StringComparison.OrdinalIgnoreCase)) + lines[i] = lines[i].Trim(); + if (lines[i].Length != 0 && !lines[i].StartsWith(";", StringComparison.OrdinalIgnoreCase)) { - string[] Terms = Lines[i].Split(','); - for (int j = 0; j < Terms.Length; j++) + string[] terms = lines[i].Split(','); + for (int j = 0; j < terms.Length; j++) { - Terms[j] = Terms[j].Trim(); + terms[j] = terms[j].Trim(); } - if (Terms.Length >= 2) + if (terms.Length >= 2) { - if (Length >= Controls.Length) + if (length >= controls.Length) { - Array.Resize(ref Controls, Controls.Length << 1); + Array.Resize(ref controls, controls.Length << 1); } // note: to get rid of the underscore in the saved commmand file would require a format change, and this isn't a performance sensitive area hence don't bother.... - if (!Enum.TryParse(Terms[0].Replace("_", string.Empty), true, out Translations.Command parsedCommand)) + if (!Enum.TryParse(terms[0].Replace("_", string.Empty), true, out Translations.Command parsedCommand)) { - Controls[Length].Command = Translations.Command.None; - Controls[Length].InheritedType = Translations.CommandType.Digital; - Controls[Length].Method = ControlMethod.Invalid; - Controls[Length].Device = Guid.Empty; - Controls[Length].Component = JoystickComponent.Invalid; - Controls[Length].Element = -1; - Controls[Length].Direction = 0; - Controls[Length].Modifier = KeyboardModifier.None; - Controls[Length].Option = 0; + controls[length].Command = Translations.Command.None; + controls[length].InheritedType = Translations.CommandType.Digital; + controls[length].Method = ControlMethod.Invalid; + controls[length].Device = Guid.Empty; + controls[length].Component = JoystickComponent.Invalid; + controls[length].Element = -1; + controls[length].Direction = 0; + controls[length].Modifier = KeyboardModifier.None; + controls[length].Option = 0; } else { - Controls[Length].Command = parsedCommand; - Controls[Length].InheritedType = Translations.CommandInfos[parsedCommand].Type; - Enum.TryParse(Terms[1], true, out ControlMethod Method); - bool Valid = false; - if (Method == ControlMethod.Keyboard & Terms.Length >= 4) + controls[length].Command = parsedCommand; + controls[length].InheritedType = Translations.CommandInfos[parsedCommand].Type; + Enum.TryParse(terms[1], true, out ControlMethod method); + bool valid = false; + if (method == ControlMethod.Keyboard & terms.Length >= 4) { - if (int.TryParse(Terms[2], out _)) + if (int.TryParse(terms[2], out _)) { //We've discovered a SDL keybinding is present, so reset the loading process with the default keyconfig & show an appropriate error message if (ControlsReset == false) @@ -154,20 +154,20 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls) MessageBoxButtons.OK, MessageBoxIcon.Hand); } - var DefaultControls = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Controls"), "Default keyboard assignment.controls"); - if (System.IO.File.Exists(DefaultControls)) + var defaultControls = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Controls"), "Default keyboard assignment.controls"); + if (File.Exists(defaultControls)) { if (ControlsReset == false) { ControlsReset = true; - LoadControls(DefaultControls, out CurrentControls); + LoadControls(defaultControls, out CurrentControls); } else { MessageBox.Show(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"errors","warning"}) + Environment.NewLine + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"errors","controls_default_oldversion"}), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); i = 0; - Lines = GetLines(Assembly.GetExecutingAssembly().GetManifestResourceStream("OpenBve.Default.controls")); + lines = GetLines(Assembly.GetExecutingAssembly().GetManifestResourceStream("OpenBve.Default.controls")); continue; } @@ -176,196 +176,196 @@ internal static void LoadControls(string FileOrNull, out Control[] Controls) { MessageBox.Show(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"errors","warning"}) + Environment.NewLine + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"errors","controls_default_missing"}), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); - Controls = new Control[0]; + controls = new Control[0]; } return; } - if (Enum.TryParse(Terms[2], true, out Key CurrentKey)) + if (Enum.TryParse(terms[2], true, out Key currentKey)) { - if (int.TryParse(Terms[3], NumberStyles.Integer, Culture, out int Modifiers)) + if (int.TryParse(terms[3], NumberStyles.Integer, culture, out int modifiers)) { - Controls[Length].Method = Method; - Controls[Length].Device = Guid.Empty; - Controls[Length].Component = JoystickComponent.Invalid; - Controls[Length].Key = (OpenBveApi.Input.Key)CurrentKey; - Controls[Length].Direction = 0; - Controls[Length].Modifier = (KeyboardModifier) Modifiers; - if (Terms.Length >= 5 && int.TryParse(Terms[4], NumberStyles.Integer, Culture, out int Option)) + controls[length].Method = method; + controls[length].Device = Guid.Empty; + controls[length].Component = JoystickComponent.Invalid; + controls[length].Key = (OpenBveApi.Input.Key)currentKey; + controls[length].Direction = 0; + controls[length].Modifier = (KeyboardModifier) modifiers; + if (terms.Length >= 5 && int.TryParse(terms[4], NumberStyles.Integer, culture, out int option)) { - Controls[Length].Option = Option; + controls[length].Option = option; } - Valid = true; + valid = true; } } } - else if (Method == ControlMethod.Joystick & Terms.Length >= 4) + else if (method == ControlMethod.Joystick & terms.Length >= 4) { - Guid Device = Guid.Empty; - if (int.TryParse(Terms[2], NumberStyles.Integer, Culture, out int oldDevice)) + Guid device = Guid.Empty; + if (int.TryParse(terms[2], NumberStyles.Integer, culture, out int oldDevice)) { - Device = Joystick.GetGuid(oldDevice); + device = Joystick.GetGuid(oldDevice); } - Enum.TryParse(Terms[3], true, out JoystickComponent Component); + Enum.TryParse(terms[3], true, out JoystickComponent component); - if (Device != Guid.Empty || Guid.TryParse(Terms[2], out Device)) + if (device != Guid.Empty || Guid.TryParse(terms[2], out device)) { - if (Component == JoystickComponent.Axis & Terms.Length >= 6) + if (component == JoystickComponent.Axis & terms.Length >= 6) { - if (int.TryParse(Terms[4], out int CurrentAxis)) + if (int.TryParse(terms[4], out int currentAxis)) { - if (int.TryParse(Terms[5], NumberStyles.Integer, Culture, out int Direction)) + if (int.TryParse(terms[5], NumberStyles.Integer, culture, out int direction)) { - Controls[Length].Method = Method; - Controls[Length].Device = Device; - Controls[Length].Component = JoystickComponent.Axis; - Controls[Length].Element = CurrentAxis; - Controls[Length].Direction = Direction; - Controls[Length].Modifier = KeyboardModifier.None; - if (Terms.Length >= 7 && int.TryParse(Terms[6], NumberStyles.Integer, Culture, out int Option)) + controls[length].Method = method; + controls[length].Device = device; + controls[length].Component = JoystickComponent.Axis; + controls[length].Element = currentAxis; + controls[length].Direction = direction; + controls[length].Modifier = KeyboardModifier.None; + if (terms.Length >= 7 && int.TryParse(terms[6], NumberStyles.Integer, culture, out int option)) { - Controls[Length].Option = Option; + controls[length].Option = option; } - Valid = true; + valid = true; } } } - else if (Component == JoystickComponent.Hat & Terms.Length >= 6) + else if (component == JoystickComponent.Hat & terms.Length >= 6) { - if (int.TryParse(Terms[4], out int CurrentHat)) + if (int.TryParse(terms[4], out int currentHat)) { - if (int.TryParse(Terms[5], out int HatDirection)) + if (int.TryParse(terms[5], out int hatDirection)) { - Controls[Length].Method = Method; - Controls[Length].Device = Device; - Controls[Length].Component = JoystickComponent.Hat; - Controls[Length].Element = CurrentHat; - Controls[Length].Direction = HatDirection; - Controls[Length].Modifier = KeyboardModifier.None; - if (Terms.Length >= 7 && int.TryParse(Terms[6], NumberStyles.Integer, Culture, out int Option)) + controls[length].Method = method; + controls[length].Device = device; + controls[length].Component = JoystickComponent.Hat; + controls[length].Element = currentHat; + controls[length].Direction = hatDirection; + controls[length].Modifier = KeyboardModifier.None; + if (terms.Length >= 7 && int.TryParse(terms[6], NumberStyles.Integer, culture, out int option)) { - Controls[Length].Option = Option; + controls[length].Option = option; } - Valid = true; + valid = true; } } } - else if (Component == JoystickComponent.Button & Terms.Length >= 5) + else if (component == JoystickComponent.Button & terms.Length >= 5) { - if (int.TryParse(Terms[4], out int CurrentButton)) + if (int.TryParse(terms[4], out int currentButton)) { - Controls[Length].Method = Method; - Controls[Length].Device = Device; - Controls[Length].Component = JoystickComponent.Button; - Controls[Length].Element = CurrentButton; - Controls[Length].Direction = 0; - Controls[Length].Modifier = KeyboardModifier.None; - if (Terms.Length >= 6 && int.TryParse(Terms[5], NumberStyles.Integer, Culture, out int Option)) + controls[length].Method = method; + controls[length].Device = device; + controls[length].Component = JoystickComponent.Button; + controls[length].Element = currentButton; + controls[length].Direction = 0; + controls[length].Modifier = KeyboardModifier.None; + if (terms.Length >= 6 && int.TryParse(terms[5], NumberStyles.Integer, culture, out int option)) { - Controls[Length].Option = Option; + controls[length].Option = option; } - Valid = true; + valid = true; } } } } - else if (Method == ControlMethod.RailDriver & Terms.Length >= 4) + else if (method == ControlMethod.RailDriver & terms.Length >= 4) { - Guid Device = Guid.Empty; - if (int.TryParse(Terms[2], NumberStyles.Integer, Culture, out int oldDevice)) + Guid device = Guid.Empty; + if (int.TryParse(terms[2], NumberStyles.Integer, culture, out int oldDevice)) { - Device = Joystick.GetGuid(oldDevice); + device = Joystick.GetGuid(oldDevice); } - if (Device != Guid.Empty || Guid.TryParse(Terms[2], out Device)) + if (device != Guid.Empty || Guid.TryParse(terms[2], out device)) { - Enum.TryParse(Terms[3], true, out JoystickComponent Component); - if (Component == JoystickComponent.Axis & Terms.Length >= 6) + Enum.TryParse(terms[3], true, out JoystickComponent component); + if (component == JoystickComponent.Axis & terms.Length >= 6) { - if (int.TryParse(Terms[4], out int CurrentAxis)) + if (int.TryParse(terms[4], out int currentAxis)) { - if (int.TryParse(Terms[5], NumberStyles.Integer, Culture, out int Direction)) + if (int.TryParse(terms[5], NumberStyles.Integer, culture, out int direction)) { - Controls[Length].Method = Method; - Controls[Length].Device = Device; - Controls[Length].Component = JoystickComponent.Axis; - Controls[Length].Element = CurrentAxis; - Controls[Length].Direction = Direction; - Controls[Length].Modifier = KeyboardModifier.None; - if (Terms.Length >= 7 && int.TryParse(Terms[6], NumberStyles.Integer, Culture, out int Option)) + controls[length].Method = method; + controls[length].Device = device; + controls[length].Component = JoystickComponent.Axis; + controls[length].Element = currentAxis; + controls[length].Direction = direction; + controls[length].Modifier = KeyboardModifier.None; + if (terms.Length >= 7 && int.TryParse(terms[6], NumberStyles.Integer, culture, out int option)) { - Controls[Length].Option = Option; + controls[length].Option = option; } - Valid = true; + valid = true; } } } - else if (Component == JoystickComponent.Button & Terms.Length >= 5) + else if (component == JoystickComponent.Button & terms.Length >= 5) { - if (int.TryParse(Terms[4], out int CurrentButton)) + if (int.TryParse(terms[4], out int currentButton)) { - Controls[Length].Method = ControlMethod.RailDriver; - Controls[Length].Device = Device; - Controls[Length].Component = JoystickComponent.Button; - Controls[Length].Element = CurrentButton; - Controls[Length].Direction = 0; - Controls[Length].Modifier = KeyboardModifier.None; - if (Terms.Length >= 6 && int.TryParse(Terms[5], NumberStyles.Integer, Culture, out int Option)) + controls[length].Method = ControlMethod.RailDriver; + controls[length].Device = device; + controls[length].Component = JoystickComponent.Button; + controls[length].Element = currentButton; + controls[length].Direction = 0; + controls[length].Modifier = KeyboardModifier.None; + if (terms.Length >= 6 && int.TryParse(terms[5], NumberStyles.Integer, culture, out int option)) { - Controls[Length].Option = Option; + controls[length].Option = option; } - Valid = true; + valid = true; } } } } - if (!Valid) + if (!valid) { - Controls[Length].Method = ControlMethod.Invalid; - Controls[Length].Device = Guid.Empty; - Controls[Length].Component = JoystickComponent.Invalid; - Controls[Length].Element = -1; - Controls[Length].Direction = 0; - Controls[Length].Modifier = KeyboardModifier.None; - Controls[Length].Option = 0; + controls[length].Method = ControlMethod.Invalid; + controls[length].Device = Guid.Empty; + controls[length].Component = JoystickComponent.Invalid; + controls[length].Element = -1; + controls[length].Direction = 0; + controls[length].Modifier = KeyboardModifier.None; + controls[length].Option = 0; } } - Length++; + length++; } } } - Array.Resize(ref Controls, Length); + Array.Resize(ref controls, length); } /// Adds an array of controls to an existing control array - /// The base control array - /// The new controls to add - internal static void AddControls(ref Control[] Base, Control[] Add) { - for (int i = 0; i < Add.Length; i++) { + /// The base control array + /// The new controls to add + internal static void AddControls(ref Control[] baseControls, Control[] additionalControls) { + for (int i = 0; i < additionalControls.Length; i++) { int j; - for (j = 0; j < Base.Length; j++) { - if (Add[i].Command == Base[j].Command) break; + for (j = 0; j < baseControls.Length; j++) { + if (additionalControls[i].Command == baseControls[j].Command) break; } - if (j == Base.Length) { - Array.Resize(ref Base, Base.Length + 1); - Base[Base.Length - 1] = Add[i]; + if (j == baseControls.Length) { + Array.Resize(ref baseControls, baseControls.Length + 1); + baseControls[baseControls.Length - 1] = additionalControls[i]; } } } diff --git a/source/OpenBVE/System/Input/Keyboard.cs b/source/OpenBVE/System/Input/Keyboard.cs index 4deabf8d4..71107b2a5 100644 --- a/source/OpenBVE/System/Input/Keyboard.cs +++ b/source/OpenBVE/System/Input/Keyboard.cs @@ -9,7 +9,7 @@ namespace OpenBve internal static partial class MainLoop { /// Called when a KeyDown event is generated - internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) + internal static void KeyDownEvent(object sender, KeyboardKeyEventArgs e) { if (Interface.CurrentOptions.KioskMode && Program.Renderer.CurrentInterface != InterfaceType.GLMainMenu) { @@ -85,7 +85,7 @@ internal static void keyDownEvent(object sender, KeyboardKeyEventArgs e) } /// Called when a KeyUp event is generated - internal static void keyUpEvent(object sender, KeyboardKeyEventArgs e) + internal static void KeyUpEvent(object sender, KeyboardKeyEventArgs e) { if (Interface.CurrentOptions.KioskMode && Program.Renderer.CurrentInterface != InterfaceType.GLMainMenu) { diff --git a/source/OpenBVE/System/Input/ProcessControls.Analog.cs b/source/OpenBVE/System/Input/ProcessControls.Analog.cs index c30331ebe..6587c27b7 100644 --- a/source/OpenBVE/System/Input/ProcessControls.Analog.cs +++ b/source/OpenBVE/System/Input/ProcessControls.Analog.cs @@ -11,12 +11,12 @@ namespace OpenBve { internal static partial class MainLoop { - private static void ProcessAnalogControl(double TimeElapsed, ref Control Control) + private static void ProcessAnalogControl(double timeElapsed, ref Control control) { // analog control - if (Control.AnalogState != 0.0) + if (control.AnalogState != 0.0) { - switch (Control.Command) + switch (control.Command) { case Translations.Command.PowerHalfAxis: case Translations.Command.PowerFullAxis: @@ -29,8 +29,8 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control // power half/full-axis if (TrainManager.PlayerTrain.Handles.HandleType != HandleType.SingleHandle) { - double a = Control.AnalogState; - if (Control.Command == Translations.Command.PowerFullAxis) + double a = control.AnalogState; + if (control.Command == Translations.Command.PowerFullAxis) { a = 0.5 * (a + 1.0); } @@ -54,8 +54,8 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control { if (TrainManager.PlayerTrain.Handles.Brake is AirBrakeHandle) { - double a = Control.AnalogState; - if (Control.Command == + double a = control.AnalogState; + if (control.Command == Translations.Command.BrakeFullAxis) { a = 0.5 * (a + 1.0); @@ -92,8 +92,8 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control { if (TrainManager.PlayerTrain.Handles.HasHoldBrake) { - double a = Control.AnalogState; - if (Control.Command == + double a = control.AnalogState; + if (control.Command == Translations.Command.BrakeFullAxis) { a = 0.5 * (a + 1.0); @@ -117,8 +117,8 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control } else { - double a = Control.AnalogState; - if (Control.Command == + double a = control.AnalogState; + if (control.Command == Translations.Command.BrakeFullAxis) { a = 0.5 * (a + 1.0); @@ -155,8 +155,8 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control { if (TrainManager.PlayerTrain.Handles.HasHoldBrake) { - int p = (int)Math.Round(Control.AnalogState * TrainManager.PlayerTrain.Handles.Power.MaximumNotch); - int b = (int)Math.Round(-Control.AnalogState * (TrainManager.PlayerTrain.Handles.Brake.MaximumNotch + 2.0)); + int p = (int)Math.Round(control.AnalogState * TrainManager.PlayerTrain.Handles.Power.MaximumNotch); + int b = (int)Math.Round(-control.AnalogState * (TrainManager.PlayerTrain.Handles.Brake.MaximumNotch + 2.0)); if (p < 0) p = 0; if (b < 0) b = 0; bool q = b == 1; @@ -179,8 +179,8 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control } else { - int p = (int)Math.Round(Control.AnalogState * TrainManager.PlayerTrain.Handles.Power.MaximumNotch); - int b = (int)Math.Round(-Control.AnalogState * (TrainManager.PlayerTrain.Handles.Brake.MaximumNotch + 1.0)); + int p = (int)Math.Round(control.AnalogState * TrainManager.PlayerTrain.Handles.Power.MaximumNotch); + int b = (int)Math.Round(-control.AnalogState * (TrainManager.PlayerTrain.Handles.Brake.MaximumNotch + 1.0)); if (p < 0) p = 0; if (b < 0) b = 0; if (b <= TrainManager.PlayerTrain.Handles.Brake.MaximumNotch) @@ -208,7 +208,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control } // reverser full axis - TrainManager.PlayerTrain.Handles.Reverser.ApplyState((ReverserPosition)(int)Math.Round(Control.AnalogState)); + TrainManager.PlayerTrain.Handles.Reverser.ApplyState((ReverserPosition)(int)Math.Round(control.AnalogState)); break; case Translations.Command.CameraMoveForward: // camera move forward @@ -220,7 +220,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopSpeed : CameraProperties.ExteriorTopSpeed; - Program.Renderer.Camera.AlignmentDirection.Position.Z = s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Position.Z = s * control.AnalogState; } else { @@ -230,7 +230,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control break; } - Program.Renderer.Camera.AlignmentDirection.TrackPosition = CameraProperties.ExteriorTopSpeed * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.TrackPosition = CameraProperties.ExteriorTopSpeed * control.AnalogState; } break; @@ -244,12 +244,12 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopSpeed : CameraProperties.ExteriorTopSpeed; - Program.Renderer.Camera.AlignmentDirection.Position.Z = -s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Position.Z = -s * control.AnalogState; } else { Program.Renderer.Camera.AlignmentDirection.TrackPosition = - -CameraProperties.ExteriorTopSpeed * Control.AnalogState; + -CameraProperties.ExteriorTopSpeed * control.AnalogState; } break; @@ -260,7 +260,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopSpeed : CameraProperties.ExteriorTopSpeed; - Program.Renderer.Camera.AlignmentDirection.Position.X = -s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Position.X = -s * control.AnalogState; } break; case Translations.Command.CameraMoveRight: @@ -270,7 +270,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopSpeed : CameraProperties.ExteriorTopSpeed; - Program.Renderer.Camera.AlignmentDirection.Position.X = s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Position.X = s * control.AnalogState; } break; case Translations.Command.CameraMoveUp: @@ -280,7 +280,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopSpeed : CameraProperties.ExteriorTopSpeed; - Program.Renderer.Camera.AlignmentDirection.Position.Y = s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Position.Y = s * control.AnalogState; } break; case Translations.Command.CameraMoveDown: @@ -290,7 +290,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopSpeed : CameraProperties.ExteriorTopSpeed; - Program.Renderer.Camera.AlignmentDirection.Position.Y = -s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Position.Y = -s * control.AnalogState; } break; case Translations.Command.CameraRotateLeft: @@ -300,7 +300,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopAngularSpeed : CameraProperties.ExteriorTopAngularSpeed; - Program.Renderer.Camera.AlignmentDirection.Yaw = -s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Yaw = -s * control.AnalogState; } break; case Translations.Command.CameraRotateRight: @@ -310,7 +310,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopAngularSpeed : CameraProperties.ExteriorTopAngularSpeed; - Program.Renderer.Camera.AlignmentDirection.Yaw = s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Yaw = s * control.AnalogState; } break; case Translations.Command.CameraRotateUp: @@ -320,7 +320,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopAngularSpeed : CameraProperties.ExteriorTopAngularSpeed; - Program.Renderer.Camera.AlignmentDirection.Pitch = s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Pitch = s * control.AnalogState; } break; case Translations.Command.CameraRotateDown: @@ -330,7 +330,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopAngularSpeed : CameraProperties.ExteriorTopAngularSpeed; - Program.Renderer.Camera.AlignmentDirection.Pitch = -s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Pitch = -s * control.AnalogState; } break; case Translations.Command.CameraRotateCCW: @@ -343,7 +343,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopAngularSpeed : CameraProperties.ExteriorTopAngularSpeed; - Program.Renderer.Camera.AlignmentDirection.Roll = -s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Roll = -s * control.AnalogState; } break; @@ -357,40 +357,40 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead ? CameraProperties.InteriorTopAngularSpeed : CameraProperties.ExteriorTopAngularSpeed; - Program.Renderer.Camera.AlignmentDirection.Roll = s * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Roll = s * control.AnalogState; } break; case Translations.Command.CameraZoomIn: // camera zoom in - if (TimeElapsed > 0.0) + if (timeElapsed > 0.0) { - Program.Renderer.Camera.AlignmentDirection.Zoom = -CameraProperties.ZoomTopSpeed * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Zoom = -CameraProperties.ZoomTopSpeed * control.AnalogState; } break; case Translations.Command.CameraZoomOut: // camera zoom out - if (TimeElapsed > 0.0) + if (timeElapsed > 0.0) { - Program.Renderer.Camera.AlignmentDirection.Zoom = CameraProperties.ZoomTopSpeed * Control.AnalogState; + Program.Renderer.Camera.AlignmentDirection.Zoom = CameraProperties.ZoomTopSpeed * control.AnalogState; } break; case Translations.Command.TimetableUp: // timetable up - if (TimeElapsed > 0.0) + if (timeElapsed > 0.0) { const double scrollSpeed = 250.0; if (Program.Renderer.CurrentTimetable == DisplayedTimetable.Default) { - Timetable.DefaultTimetablePosition += scrollSpeed * Control.AnalogState * TimeElapsed; + Timetable.DefaultTimetablePosition += scrollSpeed * control.AnalogState * timeElapsed; if (Timetable.DefaultTimetablePosition > 0.0) Timetable.DefaultTimetablePosition = 0.0; } else if (Program.Renderer.CurrentTimetable == DisplayedTimetable.Custom) { - Timetable.CustomTimetablePosition += scrollSpeed * Control.AnalogState * TimeElapsed; + Timetable.CustomTimetablePosition += scrollSpeed * control.AnalogState * timeElapsed; if (Timetable.CustomTimetablePosition > 0.0) Timetable.CustomTimetablePosition = 0.0; } @@ -399,12 +399,12 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control break; case Translations.Command.TimetableDown: // timetable down - if (TimeElapsed > 0.0) + if (timeElapsed > 0.0) { const double scrollSpeed = 250.0; if (Program.Renderer.CurrentTimetable == DisplayedTimetable.Default) { - Timetable.DefaultTimetablePosition -= scrollSpeed * Control.AnalogState * TimeElapsed; + Timetable.DefaultTimetablePosition -= scrollSpeed * control.AnalogState * timeElapsed; double max; if (Timetable.DefaultTimetableTexture != null) { @@ -423,7 +423,7 @@ private static void ProcessAnalogControl(double TimeElapsed, ref Control Control } else if (Program.Renderer.CurrentTimetable == DisplayedTimetable.Custom) { - Timetable.CustomTimetablePosition -= scrollSpeed * Control.AnalogState * TimeElapsed; + Timetable.CustomTimetablePosition -= scrollSpeed * control.AnalogState * timeElapsed; Texture texture = Timetable.CurrentCustomTimetableDaytimeTexture ?? Timetable.CurrentCustomTimetableNighttimeTexture; double max; if (texture != null) diff --git a/source/OpenBVE/System/Input/ProcessControls.Digital.cs b/source/OpenBVE/System/Input/ProcessControls.Digital.cs index 6212eb608..6de3731d1 100644 --- a/source/OpenBVE/System/Input/ProcessControls.Digital.cs +++ b/source/OpenBVE/System/Input/ProcessControls.Digital.cs @@ -24,18 +24,18 @@ namespace OpenBve { internal static partial class MainLoop { - private static void ProcessDigitalControl(double TimeElapsed, ref Control Control) + private static void ProcessDigitalControl(double timeElapsed, ref Control control) { bool lookahead = false; bool returnToCab = false; // digital control - if (Control.DigitalState == DigitalControlState.Pressed) + if (control.DigitalState == DigitalControlState.Pressed) { // pressed - Control.DigitalState = + control.DigitalState = DigitalControlState.PressedAcknowledged; - TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].DSD?.ControlDown(Control.Command); - switch (Control.Command) + TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].DSD?.ControlDown(control.Command); + switch (control.Command) { case Translations.Command.MiscQuit: // quit @@ -100,7 +100,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro Program.Renderer.Camera.AlignmentDirection = new CameraAlignment(); Program.Renderer.Camera.AlignmentSpeed = new CameraAlignment(); Program.Renderer.UpdateViewport(ViewportChangeMode.NoChange); - World.UpdateAbsoluteCamera(TimeElapsed); + World.UpdateAbsoluteCamera(timeElapsed); Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance); if (Program.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.NotAvailable) { @@ -175,7 +175,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro Program.Renderer.Camera.AlignmentDirection = new CameraAlignment(); Program.Renderer.Camera.AlignmentSpeed = new CameraAlignment(); Program.Renderer.UpdateViewport(ViewportChangeMode.NoChange); - World.UpdateAbsoluteCamera(TimeElapsed); + World.UpdateAbsoluteCamera(timeElapsed); Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance); if (Program.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.NotAvailable) { @@ -217,7 +217,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro Program.Renderer.Camera.AlignmentDirection = new CameraAlignment(); Program.Renderer.Camera.AlignmentSpeed = new CameraAlignment(); Program.Renderer.UpdateViewport(ViewportChangeMode.NoChange); - World.UpdateAbsoluteCamera(TimeElapsed); + World.UpdateAbsoluteCamera(timeElapsed); Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance); break; case Translations.Command.CameraTrack: @@ -225,7 +225,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro // camera: track / fly-by { SaveCameraSettings(); - if (Control.Command == Translations.Command.CameraTrack) + if (control.Command == Translations.Command.CameraTrack) { Program.Renderer.Camera.CurrentMode = CameraViewMode.Track; MessageManager.AddMessage(Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"notification","track"}), @@ -264,7 +264,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro Program.Renderer.Camera.AlignmentDirection = new CameraAlignment(); Program.Renderer.Camera.AlignmentSpeed = new CameraAlignment(); Program.Renderer.UpdateViewport(ViewportChangeMode.NoChange); - World.UpdateAbsoluteCamera(TimeElapsed); + World.UpdateAbsoluteCamera(timeElapsed); Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance); } break; @@ -307,7 +307,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro Program.Renderer.Camera.Alignment.TrackPosition = Program.Renderer.CameraTrackFollower.TrackPosition; Program.Renderer.Camera.VerticalViewingAngle = Program.Renderer.Camera.OriginalVerticalViewingAngle; Program.Renderer.UpdateViewport(ViewportChangeMode.NoChange); - World.UpdateAbsoluteCamera(TimeElapsed); + World.UpdateAbsoluteCamera(timeElapsed); Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance); } @@ -352,7 +352,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro Program.Renderer.CameraTrackFollower.TrackPosition; Program.Renderer.Camera.VerticalViewingAngle = Program.Renderer.Camera.OriginalVerticalViewingAngle; Program.Renderer.UpdateViewport(ViewportChangeMode.NoChange); - World.UpdateAbsoluteCamera(TimeElapsed); + World.UpdateAbsoluteCamera(timeElapsed); Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance); } @@ -404,7 +404,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro Program.Renderer.Camera.AlignmentDirection = new CameraAlignment(); Program.Renderer.Camera.AlignmentSpeed = new CameraAlignment(); Program.Renderer.UpdateViewport(ViewportChangeMode.NoChange); - World.UpdateAbsoluteCamera(TimeElapsed); + World.UpdateAbsoluteCamera(timeElapsed); Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance); if ((Program.Renderer.Camera.CurrentMode == CameraViewMode.Interior | Program.Renderer.Camera.CurrentMode == CameraViewMode.InteriorLookAhead) & @@ -750,7 +750,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro } TrainManager.PlayerTrain.Handles.Brake.ApplyState(0, TrainManager.PlayerTrain.Handles.HandleType != HandleType.SingleHandle); - TrainManager.PlayerTrain.Handles.Power.ApplyState(Control.Option, false); + TrainManager.PlayerTrain.Handles.Power.ApplyState(control.Option, false); break; case Translations.Command.BrakeAnyNotch: if (TrainManager.PlayerTrain.Handles.Brake is AirBrakeHandle) @@ -761,11 +761,11 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro } TrainManager.PlayerTrain.Handles.HoldBrake.ApplyState(false); - if (Control.Option <= (int)AirBrakeHandleState.Release) + if (control.Option <= (int)AirBrakeHandleState.Release) { TrainManager.PlayerTrain.Handles.Brake.ApplyState(AirBrakeHandleState.Release); } - else if (Control.Option == (int)AirBrakeHandleState.Lap) + else if (control.Option == (int)AirBrakeHandleState.Lap) { TrainManager.PlayerTrain.Handles.Brake.ApplyState(AirBrakeHandleState.Lap); } @@ -782,13 +782,13 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro } TrainManager.PlayerTrain.Handles.HoldBrake.ApplyState(false); - TrainManager.PlayerTrain.Handles.Brake.ApplyState(Control.Option, false); + TrainManager.PlayerTrain.Handles.Brake.ApplyState(control.Option, false); TrainManager.PlayerTrain.Handles.Power.ApplyState(0, TrainManager.PlayerTrain.Handles.HandleType != HandleType.SingleHandle); } break; case Translations.Command.ReverserAnyPosition: - TrainManager.PlayerTrain.Handles.Reverser.ApplyState((ReverserPosition)Control.Option); + TrainManager.PlayerTrain.Handles.Reverser.ApplyState((ReverserPosition)control.Option); break; case Translations.Command.HoldBrake: if (TrainManager.PlayerTrain.Handles.HasHoldBrake && (TrainManager.PlayerTrain.Handles.Brake.Driver == 0 || TrainManager.PlayerTrain.Handles.Brake.Driver == 1) && !TrainManager.PlayerTrain.Handles.HoldBrake.Driver) @@ -820,9 +820,9 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro case Translations.Command.HornMusic: // horn { - int j = Control.Command == Translations.Command.HornPrimary + int j = control.Command == Translations.Command.HornPrimary ? 0 - : Control.Command == Translations.Command.HornSecondary + : control.Command == Translations.Command.HornSecondary ? 1 : 2; int d = TrainManager.PlayerTrain.DriverCar; @@ -942,7 +942,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro if (TrainManager.PlayerTrain.Plugin != null) { TrainManager.PlayerTrain.Plugin.KeyDown( - Translations.SecurityToVirtualKey(Control.Command)); + Translations.SecurityToVirtualKey(control.Command)); } break; @@ -950,7 +950,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro if (TrainManager.PlayerTrain.Plugin != null) { TrainManager.PlayerTrain.Plugin.KeyDown( - Translations.SecurityToVirtualKey(Control.Command)); + Translations.SecurityToVirtualKey(control.Command)); } TrainManager.PlayerTrain.SafetySystems.Headlights.ChangeState(); @@ -959,7 +959,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro if (TrainManager.PlayerTrain.Plugin != null) { TrainManager.PlayerTrain.Plugin.KeyDown( - Translations.SecurityToVirtualKey(Control.Command)); + Translations.SecurityToVirtualKey(control.Command)); } break; @@ -967,21 +967,21 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro case Translations.Command.WiperSpeedDown: if (TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Windscreen != null) { - TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Windscreen.Wipers.ChangeSpeed(Control.Command); + TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].Windscreen.Wipers.ChangeSpeed(control.Command); } if (TrainManager.PlayerTrain.Plugin != null) { //Also inform the plugin that these keys have been pressed TrainManager.PlayerTrain.Plugin.KeyDown( - Translations.SecurityToVirtualKey(Control.Command)); + Translations.SecurityToVirtualKey(control.Command)); } break; case Translations.Command.Sanders: if (TrainManager.PlayerTrain.Plugin != null) { TrainManager.PlayerTrain.Plugin.KeyDown( - Translations.SecurityToVirtualKey(Control.Command)); + Translations.SecurityToVirtualKey(control.Command)); } for (int c = 0; c < TrainManager.PlayerTrain.Cars.Length; c++) @@ -1330,13 +1330,13 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro case Translations.Command.MiscFullscreen: // toggle fullscreen Screen.ToggleFullscreen(); - Control.AnalogState = 0.0; - Control.DigitalState = DigitalControlState.Released; + control.AnalogState = 0.0; + control.DigitalState = DigitalControlState.Released; break; case Translations.Command.MiscMute: // mute Program.Sounds.GlobalMute = !Program.Sounds.GlobalMute; - Program.Sounds.Update(TimeElapsed, Interface.CurrentOptions.SoundModel); + Program.Sounds.Update(timeElapsed, Interface.CurrentOptions.SoundModel); break; case Translations.Command.RouteInformation: Game.RouteInfoOverlay.ProcessCommand(Translations.Command.RouteInformation); @@ -1382,13 +1382,13 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro break; } } - else if (Control.DigitalState == DigitalControlState.Released) + else if (control.DigitalState == DigitalControlState.Released) { // released - Control.DigitalState = + control.DigitalState = DigitalControlState.ReleasedAcknowledged; - TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].DSD?.ControlUp(Control.Command); - switch (Control.Command) + TrainManager.PlayerTrain.Cars[TrainManager.PlayerTrain.DriverCar].DSD?.ControlUp(control.Command); + switch (control.Command) { case Translations.Command.SingleBrake: case Translations.Command.BrakeIncrease: @@ -1450,7 +1450,7 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro if (TrainManager.PlayerTrain.Plugin != null) { TrainManager.PlayerTrain.Plugin.KeyUp( - Translations.SecurityToVirtualKey(Control.Command)); + Translations.SecurityToVirtualKey(control.Command)); } break; @@ -1459,9 +1459,9 @@ private static void ProcessDigitalControl(double TimeElapsed, ref Control Contro case Translations.Command.HornSecondary: case Translations.Command.HornMusic: // horn - int j = Control.Command == Translations.Command.HornPrimary + int j = control.Command == Translations.Command.HornPrimary ? 0 - : Control.Command == Translations.Command.HornSecondary + : control.Command == Translations.Command.HornSecondary ? 1 : 2; int d = TrainManager.PlayerTrain.DriverCar; diff --git a/source/OpenBVE/System/Input/ProcessControls.cs b/source/OpenBVE/System/Input/ProcessControls.cs index 5f88d930d..560d87c16 100644 --- a/source/OpenBVE/System/Input/ProcessControls.cs +++ b/source/OpenBVE/System/Input/ProcessControls.cs @@ -19,8 +19,8 @@ namespace OpenBve internal static partial class MainLoop { /// The ProcessControls function should be called once a frame, and updates the simulation accordingly - /// The time elapsed in ms since the last call to this function - internal static void ProcessControls(double TimeElapsed) + /// The time elapsed in ms since the last call to this function + internal static void ProcessControls(double timeElapsed) { for (int i = 0; i < Program.Joysticks.AttachedJoysticks.Count; i++) { @@ -52,7 +52,7 @@ internal static void ProcessControls(double TimeElapsed) } if (Interface.CurrentOptions.KioskMode) { - kioskModeTimer += TimeElapsed; + kioskModeTimer += timeElapsed; if (kioskModeTimer > Interface.CurrentOptions.KioskModeTimer && TrainManager.PlayerTrain.AI == null) { /* @@ -122,7 +122,7 @@ internal static void ProcessControls(double TimeElapsed) Program.Renderer.Camera.AlignmentDirection = new CameraAlignment(); Program.Renderer.Camera.AlignmentSpeed = new CameraAlignment(); Program.Renderer.UpdateViewport(ViewportChangeMode.NoChange); - World.UpdateAbsoluteCamera(TimeElapsed); + World.UpdateAbsoluteCamera(timeElapsed); Program.Renderer.UpdateViewingDistances(Program.CurrentRoute.CurrentBackground.BackgroundImageDistance); if (Program.Renderer.Camera.CurrentRestriction != CameraRestrictionMode.NotAvailable) { @@ -185,7 +185,7 @@ internal static void ProcessControls(double TimeElapsed) break; case Translations.Command.MiscMute: Program.Sounds.GlobalMute = !Program.Sounds.GlobalMute; - Program.Sounds.Update(TimeElapsed, Interface.CurrentOptions.SoundModel); + Program.Sounds.Update(timeElapsed, Interface.CurrentOptions.SoundModel); break; case Translations.Command.SwitchMenu: Program.Renderer.CurrentInterface = InterfaceType.SwitchChangeMap; @@ -210,7 +210,7 @@ internal static void ProcessControls(double TimeElapsed) { Interface.CurrentControls[i].DigitalState = DigitalControlState.PressedAcknowledged; - Game.Menu.ProcessCommand(Interface.CurrentControls[i].Command, TimeElapsed); + Game.Menu.ProcessCommand(Interface.CurrentControls[i].Command, timeElapsed); } } break; @@ -223,11 +223,11 @@ internal static void ProcessControls(double TimeElapsed) if (Interface.CurrentControls[i].InheritedType == Translations.CommandType.AnalogHalf | Interface.CurrentControls[i].InheritedType == Translations.CommandType.AnalogFull) { - ProcessAnalogControl(TimeElapsed, ref Interface.CurrentControls[i]); + ProcessAnalogControl(timeElapsed, ref Interface.CurrentControls[i]); } else if (Interface.CurrentControls[i].InheritedType == Translations.CommandType.Digital) { - ProcessDigitalControl(TimeElapsed, ref Interface.CurrentControls[i]); + ProcessDigitalControl(timeElapsed, ref Interface.CurrentControls[i]); } } break; diff --git a/source/OpenBVE/System/Interface.cs b/source/OpenBVE/System/Interface.cs index 17fabec7e..0923fe170 100644 --- a/source/OpenBVE/System/Interface.cs +++ b/source/OpenBVE/System/Interface.cs @@ -6,34 +6,34 @@ namespace OpenBve { internal static partial class Interface { internal static List LogMessages = new List(); - internal static void AddMessage(MessageType Type, bool FileNotFound, string Text) { - if (Type == MessageType.Warning & !CurrentOptions.ShowWarningMessages) return; - if (Type == MessageType.Error & !CurrentOptions.ShowErrorMessages) return; - LogMessages.Add(new LogMessage(Type, FileNotFound, Text)); - Program.FileSystem.AppendToLogFile(Text); + internal static void AddMessage(MessageType messageType, bool fileNotFound, string messageText) { + if (messageType == MessageType.Warning & !CurrentOptions.ShowWarningMessages) return; + if (messageType == MessageType.Error & !CurrentOptions.ShowErrorMessages) return; + LogMessages.Add(new LogMessage(messageType, fileNotFound, messageText)); + Program.FileSystem.AppendToLogFile(messageText); } /// Parses a string into OpenBVE's internal time representation (Seconds since midnight on the first day) - /// The time in string format - /// The number of seconds since midnight on the first day this represents, updated via 'out' + /// The time in string format + /// The number of seconds since midnight on the first day this represents, updated via 'out' /// True if the parse succeeds, false if it does not - internal static bool TryParseTime(string Expression, out double Value) + internal static bool TryParseTime(string expression, out double value) { - Expression = Expression.TrimInside(); - if (Expression.Length != 0) { - CultureInfo Culture = CultureInfo.InvariantCulture; - int i = Expression.IndexOf('.'); + expression = expression.TrimInside(); + if (expression.Length != 0) { + CultureInfo culture = CultureInfo.InvariantCulture; + int i = expression.IndexOf('.'); if (i == -1) { - i = Expression.IndexOf(':'); + i = expression.IndexOf(':'); } if (i >= 1) { - if (int.TryParse(Expression.Substring(0, i), NumberStyles.Integer, Culture, out int h)) { - int n = Expression.Length - i - 1; + if (int.TryParse(expression.Substring(0, i), NumberStyles.Integer, culture, out int h)) { + int n = expression.Length - i - 1; if (n == 1 | n == 2) { - if (uint.TryParse(Expression.Substring(i + 1, n), NumberStyles.None, Culture, out uint m)) { - Value = 3600.0 * h + 60.0 * m; + if (uint.TryParse(expression.Substring(i + 1, n), NumberStyles.None, culture, out uint m)) { + value = 3600.0 * h + 60.0 * m; return true; } } else if (n >= 3) { @@ -42,8 +42,8 @@ internal static bool TryParseTime(string Expression, out double Value) Program.CurrentHost.AddMessage(MessageType.Warning, false, "A maximum of 4 digits of precision are supported in TIME values"); n = 4; } - if (uint.TryParse(Expression.Substring(i + 1, 2), NumberStyles.None, Culture, out uint m)) { - string ss = Expression.Substring(i + 3, n - 2); + if (uint.TryParse(expression.Substring(i + 1, 2), NumberStyles.None, culture, out uint m)) { + string ss = expression.Substring(i + 3, n - 2); if (Interface.CurrentOptions.EnableBveTsHacks) { /* @@ -55,21 +55,21 @@ internal static bool TryParseTime(string Expression, out double Value) ss = ss.Substring(1, ss.Length - 1); } } - if (uint.TryParse(ss, NumberStyles.None, Culture, out uint s)) { - Value = 3600.0 * h + 60.0 * m + s; + if (uint.TryParse(ss, NumberStyles.None, culture, out uint s)) { + value = 3600.0 * h + 60.0 * m + s; return true; } } } } } else if (i == -1) { - if (int.TryParse(Expression, NumberStyles.Integer, Culture, out int h)) { - Value = 3600.0 * h; + if (int.TryParse(expression, NumberStyles.Integer, culture, out int h)) { + value = 3600.0 * h; return true; } } } - Value = 0.0; + value = 0.0; return false; } } diff --git a/source/OpenBVE/System/Loading.cs b/source/OpenBVE/System/Loading.cs index 99b9f322e..285d39bf4 100644 --- a/source/OpenBVE/System/Loading.cs +++ b/source/OpenBVE/System/Loading.cs @@ -64,17 +64,17 @@ internal static bool Cancel // load /// Initializes loading the route and train asynchronously. Set the Loading.Cancel member to cancel loading. Check the Loading.Complete member to see when loading has finished. - internal static void LoadAsynchronously(string RouteFile, Encoding RouteEncoding, string TrainFolder, Encoding TrainEncoding) { + internal static void LoadAsynchronously(string routeFile, Encoding routeEncoding, string trainFolder, Encoding trainEncoding) { // members Cancel = false; Complete = false; - CurrentRouteFile = RouteFile; - CurrentRouteEncoding = RouteEncoding; - CurrentTrainFolder = TrainFolder; - CurrentTrainEncoding = TrainEncoding; + CurrentRouteFile = routeFile; + CurrentRouteEncoding = routeEncoding; + CurrentTrainFolder = trainFolder; + CurrentTrainEncoding = trainEncoding; //Set the route and train folders in the info class - Program.CurrentRoute.Information.RouteFile = RouteFile; - Program.CurrentRoute.Information.TrainFolder = TrainFolder; + Program.CurrentRoute.Information.RouteFile = routeFile; + Program.CurrentRoute.Information.TrainFolder = trainFolder; Program.CurrentRoute.Information.FilesNotFound = null; Program.CurrentRoute.Information.ErrorsAndWarnings = null; Loader = new Thread(LoadThreaded) {IsBackground = true}; @@ -83,31 +83,31 @@ internal static void LoadAsynchronously(string RouteFile, Encoding RouteEncoding /// Gets the absolute Railway folder for a given route file /// The absolute on-disk path of the railway folder - internal static string GetRailwayFolder(string RouteFile) { + internal static string GetRailwayFolder(string routeFile) { try { - string Folder = Path.GetDirectoryName(RouteFile); + string folder = Path.GetDirectoryName(routeFile); while (true) { - string Subfolder = Path.CombineDirectory(Folder, "Railway"); - if (Directory.Exists(Subfolder)) + string subfolder = Path.CombineDirectory(folder, "Railway"); + if (Directory.Exists(subfolder)) { - if (Directory.EnumerateDirectories(Subfolder).Any() || Directory.EnumerateFiles(Subfolder).Any()) + if (Directory.EnumerateDirectories(subfolder).Any() || Directory.EnumerateFiles(subfolder).Any()) { //HACK: Ignore completely empty directories //Doesn't handle wrong directories, or those with stuff missing, TODO..... - Program.FileSystem.AppendToLogFile(Subfolder + " : Railway folder found."); - return Subfolder; + Program.FileSystem.AppendToLogFile(subfolder + " : Railway folder found."); + return subfolder; } - Program.FileSystem.AppendToLogFile(Subfolder + " : Railway folder candidate rejected- Directory empty."); + Program.FileSystem.AppendToLogFile(subfolder + " : Railway folder candidate rejected- Directory empty."); } - if (Folder == null) continue; - DirectoryInfo Info = Directory.GetParent(Folder); - if (Info == null) break; - Folder = Info.FullName; + if (folder == null) continue; + DirectoryInfo info = Directory.GetParent(folder); + if (info == null) break; // root of drive + folder = info.FullName; } } catch @@ -118,8 +118,8 @@ internal static string GetRailwayFolder(string RouteFile) { // If the Route, Object and Sound folders exist, but are not in a railway folder..... try { - string Folder = Path.GetDirectoryName(RouteFile); - if (Folder == null) + string folder = Path.GetDirectoryName(routeFile); + if (folder == null) { // Unlikely to work, but attempt to make the best of it Program.FileSystem.AppendToLogFile("The route file appears to be stored on a root path- Returning the " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"program","title"}) + " startup path."); @@ -128,33 +128,33 @@ internal static string GetRailwayFolder(string RouteFile) { string candidate = null; while (true) { - string RouteFolder = Path.CombineDirectory(Folder, "Route"); - string ObjectFolder = Path.CombineDirectory(Folder, "Object"); - string SoundFolder = Path.CombineDirectory(Folder, "Sound"); - if (Directory.Exists(RouteFolder) && Directory.Exists(ObjectFolder) && Directory.Exists(SoundFolder)) + string routeFolder = Path.CombineDirectory(folder, "Route"); + string objectFolder = Path.CombineDirectory(folder, "Object"); + string soundFolder = Path.CombineDirectory(folder, "Sound"); + if (Directory.Exists(routeFolder) && Directory.Exists(objectFolder) && Directory.Exists(soundFolder)) { - Program.FileSystem.AppendToLogFile(Folder + " : Railway folder found."); - return Folder; + Program.FileSystem.AppendToLogFile(folder + " : Railway folder found."); + return folder; } - if (Directory.Exists(RouteFolder) && Directory.Exists(ObjectFolder)) + if (Directory.Exists(routeFolder) && Directory.Exists(objectFolder)) { - candidate = Folder; + candidate = folder; } - DirectoryInfo Info = Directory.GetParent(Folder); - if (Info == null) + DirectoryInfo info = Directory.GetParent(folder); + if (info == null) { if (candidate != null) { - Program.FileSystem.AppendToLogFile(Folder + " : The best candidate for the Railway folder has been selected- Sound folder not detected."); + Program.FileSystem.AppendToLogFile(folder + " : The best candidate for the Railway folder has been selected- Sound folder not detected."); return candidate; } break; } - Folder = Info.FullName; + folder = info.FullName; } } catch @@ -167,27 +167,27 @@ internal static string GetRailwayFolder(string RouteFile) { /// Gets the default train folder for a given route file /// The absolute on-disk path of the train folder - internal static string GetDefaultTrainFolder(string RouteFile) + internal static string GetDefaultTrainFolder(string routeFile) { - if (string.IsNullOrEmpty(RouteFile) || string.IsNullOrEmpty(Interface.CurrentOptions.TrainName)) { + if (string.IsNullOrEmpty(routeFile) || string.IsNullOrEmpty(Interface.CurrentOptions.TrainName)) { return string.Empty; } - string Folder; + string folder; try { - Folder = Path.GetDirectoryName(RouteFile); + folder = Path.GetDirectoryName(routeFile); if (Interface.CurrentOptions.TrainName[0] == '$') { - Folder = Path.CombineDirectory(Folder, Interface.CurrentOptions.TrainName); - if (Directory.Exists(Folder)) { - string File = Path.CombineFile(Folder, "train.dat"); - if (System.IO.File.Exists(File)) { + folder = Path.CombineDirectory(folder, Interface.CurrentOptions.TrainName); + if (Directory.Exists(folder)) { + string file = Path.CombineFile(folder, "train.dat"); + if (System.IO.File.Exists(file)) { - return Folder; + return folder; } } } } catch { - Folder = null; + folder = null; } bool recursionTest = false; string lastFolder = null; @@ -195,13 +195,13 @@ internal static string GetDefaultTrainFolder(string RouteFile) { while (true) { - string TrainFolder = Path.CombineDirectory(Folder, "Train"); - var OldFolder = Folder; - if (Directory.Exists(TrainFolder)) + string trainFolder = Path.CombineDirectory(folder, "Train"); + var oldFolder = folder; + if (Directory.Exists(trainFolder)) { try { - Folder = Path.CombineDirectory(TrainFolder, Interface.CurrentOptions.TrainName); + folder = Path.CombineDirectory(trainFolder, Interface.CurrentOptions.TrainName); } catch (Exception ex) { @@ -210,36 +210,36 @@ internal static string GetDefaultTrainFolder(string RouteFile) break; // Invalid character in path causes infinite recursion } - Folder = null; + folder = null; } - if (Folder != null) + if (folder != null) { char c = System.IO.Path.DirectorySeparatorChar; - if (Directory.Exists(Folder)) + if (Directory.Exists(folder)) { - string File = Path.CombineFile(Folder, "train.dat"); - if (System.IO.File.Exists(File)) + string file = Path.CombineFile(folder, "train.dat"); + if (System.IO.File.Exists(file)) { // train found - return Folder; + return folder; } - if (lastFolder == Folder || recursionTest) + if (lastFolder == folder || recursionTest) { break; } - lastFolder = Folder; + lastFolder = folder; } - else if (Folder.ToLowerInvariant().Contains(c + "railway" + c)) + else if (folder.ToLowerInvariant().Contains(c + "railway" + c)) { //If we have a misplaced Train folder in either our Railway\Route //or Railway folders, this can cause the train search to fail //Detect the presence of a railway folder and carry on traversing upwards if this is the case recursionTest = true; - Folder = OldFolder; + folder = oldFolder; } else { @@ -248,11 +248,11 @@ internal static string GetDefaultTrainFolder(string RouteFile) } } - if (Folder == null) continue; - DirectoryInfo Info = Directory.GetParent(Folder); - if (Info != null) + if (folder == null) continue; + DirectoryInfo info = Directory.GetParent(folder); + if (info != null) { - Folder = Info.FullName; + folder = info.FullName; } else { @@ -313,9 +313,9 @@ private static void LoadThreaded() { } private static void LoadEverythingThreaded() { - string RailwayFolder = GetRailwayFolder(CurrentRouteFile); - string ObjectFolder = Path.CombineDirectory(RailwayFolder, "Object"); - string SoundFolder = Path.CombineDirectory(RailwayFolder, "Sound"); + string railwayFolder = GetRailwayFolder(CurrentRouteFile); + string objectFolder = Path.CombineDirectory(railwayFolder, "Object"); + string soundFolder = Path.CombineDirectory(railwayFolder, "Sound"); Game.Reset(true); Game.MinimalisticSimulation = true; // screen @@ -331,10 +331,10 @@ private static void LoadEverythingThreaded() { { if (Program.CurrentHost.Plugins[i].Route != null && Program.CurrentHost.Plugins[i].Route.CanLoadRoute(CurrentRouteFile)) { - object Route = (object)Program.CurrentRoute; //must cast to allow us to use the ref keyword. - if (Program.CurrentHost.Plugins[i].Route.LoadRoute(CurrentRouteFile, CurrentRouteEncoding, CurrentTrainFolder, ObjectFolder, SoundFolder, false, ref Route)) + object route = (object)Program.CurrentRoute; //must cast to allow us to use the ref keyword. + if (Program.CurrentHost.Plugins[i].Route.LoadRoute(CurrentRouteFile, CurrentRouteEncoding, CurrentTrainFolder, objectFolder, soundFolder, false, ref route)) { - Program.CurrentRoute = (CurrentRoute) Route; + Program.CurrentRoute = (CurrentRoute) route; Program.CurrentRoute.UpdateLighting(); loaded = true; diff --git a/source/OpenBVE/System/Logging/BlackBox.cs b/source/OpenBVE/System/Logging/BlackBox.cs index 00e964837..d362fd9c0 100644 --- a/source/OpenBVE/System/Logging/BlackBox.cs +++ b/source/OpenBVE/System/Logging/BlackBox.cs @@ -11,76 +11,76 @@ internal static partial class Interface { /// Magic bytes identifying this as an OpenBVE blackbox file /// openBVELOGS in UTF-8 - private static readonly byte[] Identifier = { 111, 112, 101, 110, 66, 86, 69, 95, 76, 79, 71, 83 }; + private static readonly byte[] identifier = { 111, 112, 101, 110, 66, 86, 69, 95, 76, 79, 71, 83 }; /// Magic bytes identifying the EOF /// _fileEND in UTF-8 - private static readonly byte[] Footer = { 95, 102, 105, 108, 101, 69, 78, 68 }; + private static readonly byte[] footer = { 95, 102, 105, 108, 101, 69, 78, 68 }; /// Loads the black-box logs from the previous simulation run internal static void LoadLogs() { - string BlackBoxFile = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "logs.bin"); - if (File.Exists(BlackBoxFile)) + string blackBoxFile = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "logs.bin"); + if (File.Exists(blackBoxFile)) { try { - using (FileStream Stream = new FileStream(BlackBoxFile, FileMode.Open, FileAccess.Read)) + using (FileStream stream = new FileStream(blackBoxFile, FileMode.Open, FileAccess.Read)) { - using (BinaryReader Reader = new BinaryReader(Stream, System.Text.Encoding.UTF8)) + using (BinaryReader reader = new BinaryReader(stream, System.Text.Encoding.UTF8)) { - const short Version = 1; - byte[] Data = Reader.ReadBytes(Identifier.Length); - for (int i = 0; i < Identifier.Length; i++) + const short version = 1; + byte[] data = reader.ReadBytes(identifier.Length); + for (int i = 0; i < identifier.Length; i++) { - if (Identifier[i] != Data[i]) throw new InvalidDataException(); + if (identifier[i] != data[i]) throw new InvalidDataException(); } - short Number = Reader.ReadInt16(); - if (Version != Number) throw new InvalidDataException(); - Game.LogRouteName = Reader.ReadString(); - Game.LogTrainName = Reader.ReadString(); - Game.LogDateTime = DateTime.FromBinary(Reader.ReadInt64()); - Interface.CurrentOptions.PreviousGameMode = (GameMode) Reader.ReadInt16(); - Game.BlackBoxEntryCount = Reader.ReadInt32(); + short number = reader.ReadInt16(); + if (version != number) throw new InvalidDataException(); + Game.LogRouteName = reader.ReadString(); + Game.LogTrainName = reader.ReadString(); + Game.LogDateTime = DateTime.FromBinary(reader.ReadInt64()); + CurrentOptions.PreviousGameMode = (GameMode) reader.ReadInt16(); + Game.BlackBoxEntryCount = reader.ReadInt32(); Game.BlackBoxEntries = new Game.BlackBoxEntry[Game.BlackBoxEntryCount]; for (int i = 0; i < Game.BlackBoxEntryCount; i++) { - Game.BlackBoxEntries[i].Time = Reader.ReadDouble(); - Game.BlackBoxEntries[i].Position = Reader.ReadDouble(); - Game.BlackBoxEntries[i].Speed = Reader.ReadSingle(); - Game.BlackBoxEntries[i].Acceleration = Reader.ReadSingle(); - Game.BlackBoxEntries[i].ReverserDriver = Reader.ReadInt16(); - Game.BlackBoxEntries[i].ReverserSafety = Reader.ReadInt16(); - Game.BlackBoxEntries[i].PowerDriver = (Game.BlackBoxPower) Reader.ReadInt16(); - Game.BlackBoxEntries[i].PowerSafety = (Game.BlackBoxPower) Reader.ReadInt16(); - Game.BlackBoxEntries[i].BrakeDriver = (Game.BlackBoxBrake) Reader.ReadInt16(); - Game.BlackBoxEntries[i].BrakeSafety = (Game.BlackBoxBrake) Reader.ReadInt16(); - Game.BlackBoxEntries[i].EventToken = (Game.BlackBoxEventToken) Reader.ReadInt16(); + Game.BlackBoxEntries[i].Time = reader.ReadDouble(); + Game.BlackBoxEntries[i].Position = reader.ReadDouble(); + Game.BlackBoxEntries[i].Speed = reader.ReadSingle(); + Game.BlackBoxEntries[i].Acceleration = reader.ReadSingle(); + Game.BlackBoxEntries[i].ReverserDriver = reader.ReadInt16(); + Game.BlackBoxEntries[i].ReverserSafety = reader.ReadInt16(); + Game.BlackBoxEntries[i].PowerDriver = (Game.BlackBoxPower) reader.ReadInt16(); + Game.BlackBoxEntries[i].PowerSafety = (Game.BlackBoxPower) reader.ReadInt16(); + Game.BlackBoxEntries[i].BrakeDriver = (Game.BlackBoxBrake) reader.ReadInt16(); + Game.BlackBoxEntries[i].BrakeSafety = (Game.BlackBoxBrake) reader.ReadInt16(); + Game.BlackBoxEntries[i].EventToken = (Game.BlackBoxEventToken) reader.ReadInt16(); } - Game.ScoreLogCount = Reader.ReadInt32(); + Game.ScoreLogCount = reader.ReadInt32(); Game.ScoreLogs = new Game.ScoreLog[Game.ScoreLogCount]; Game.CurrentScore.CurrentValue = 0; for (int i = 0; i < Game.ScoreLogCount; i++) { - Game.ScoreLogs[i].Time = Reader.ReadDouble(); - Game.ScoreLogs[i].Position = Reader.ReadDouble(); - Game.ScoreLogs[i].Value = Reader.ReadInt32(); - Game.ScoreLogs[i].TextToken = (Game.ScoreTextToken) Reader.ReadInt16(); + Game.ScoreLogs[i].Time = reader.ReadDouble(); + Game.ScoreLogs[i].Position = reader.ReadDouble(); + Game.ScoreLogs[i].Value = reader.ReadInt32(); + Game.ScoreLogs[i].TextToken = (Game.ScoreTextToken) reader.ReadInt16(); Game.CurrentScore.CurrentValue += Game.ScoreLogs[i].Value; } - Game.CurrentScore.Maximum = Reader.ReadInt32(); - Data = Reader.ReadBytes(Footer.Length); - for (int i = 0; i < Footer.Length; i++) + Game.CurrentScore.Maximum = reader.ReadInt32(); + data = reader.ReadBytes(footer.Length); + for (int i = 0; i < footer.Length; i++) { - if (Footer[i] != Data[i]) throw new InvalidDataException(); + if (footer[i] != data[i]) throw new InvalidDataException(); } - Reader.Close(); + reader.Close(); } - Stream.Close(); + stream.Close(); } return; } @@ -116,51 +116,51 @@ internal static void SaveLogs(bool forceSave = false) return; } lastLogSaveTime = Program.CurrentRoute.SecondsSinceMidnight; - string BlackBoxFile = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "logs.bin"); + string blackBoxFile = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "logs.bin"); try { - using (FileStream Stream = new FileStream(BlackBoxFile, FileMode.Create, FileAccess.Write)) + using (FileStream stream = new FileStream(blackBoxFile, FileMode.Create, FileAccess.Write)) { - using (BinaryWriter Writer = new BinaryWriter(Stream, System.Text.Encoding.UTF8)) + using (BinaryWriter writer = new BinaryWriter(stream, System.Text.Encoding.UTF8)) { - const short Version = 1; - Writer.Write(Identifier); - Writer.Write(Version); - Writer.Write(Game.LogRouteName); - Writer.Write(Game.LogTrainName); - Writer.Write(Game.LogDateTime.ToBinary()); - Writer.Write((short) Interface.CurrentOptions.GameMode); - Writer.Write(Game.BlackBoxEntryCount); + const short version = 1; + writer.Write(identifier); + writer.Write(version); + writer.Write(Game.LogRouteName); + writer.Write(Game.LogTrainName); + writer.Write(Game.LogDateTime.ToBinary()); + writer.Write((short) Interface.CurrentOptions.GameMode); + writer.Write(Game.BlackBoxEntryCount); for (int i = 0; i < Game.BlackBoxEntryCount; i++) { - Writer.Write(Game.BlackBoxEntries[i].Time); - Writer.Write(Game.BlackBoxEntries[i].Position); - Writer.Write(Game.BlackBoxEntries[i].Speed); - Writer.Write(Game.BlackBoxEntries[i].Acceleration); - Writer.Write(Game.BlackBoxEntries[i].ReverserDriver); - Writer.Write(Game.BlackBoxEntries[i].ReverserSafety); - Writer.Write((short) Game.BlackBoxEntries[i].PowerDriver); - Writer.Write((short) Game.BlackBoxEntries[i].PowerSafety); - Writer.Write((short) Game.BlackBoxEntries[i].BrakeDriver); - Writer.Write((short) Game.BlackBoxEntries[i].BrakeSafety); - Writer.Write((short) Game.BlackBoxEntries[i].EventToken); + writer.Write(Game.BlackBoxEntries[i].Time); + writer.Write(Game.BlackBoxEntries[i].Position); + writer.Write(Game.BlackBoxEntries[i].Speed); + writer.Write(Game.BlackBoxEntries[i].Acceleration); + writer.Write(Game.BlackBoxEntries[i].ReverserDriver); + writer.Write(Game.BlackBoxEntries[i].ReverserSafety); + writer.Write((short) Game.BlackBoxEntries[i].PowerDriver); + writer.Write((short) Game.BlackBoxEntries[i].PowerSafety); + writer.Write((short) Game.BlackBoxEntries[i].BrakeDriver); + writer.Write((short) Game.BlackBoxEntries[i].BrakeSafety); + writer.Write((short) Game.BlackBoxEntries[i].EventToken); } - Writer.Write(Game.ScoreLogCount); + writer.Write(Game.ScoreLogCount); for (int i = 0; i < Game.ScoreLogCount; i++) { - Writer.Write(Game.ScoreLogs[i].Time); - Writer.Write(Game.ScoreLogs[i].Position); - Writer.Write(Game.ScoreLogs[i].Value); - Writer.Write((short) Game.ScoreLogs[i].TextToken); + writer.Write(Game.ScoreLogs[i].Time); + writer.Write(Game.ScoreLogs[i].Position); + writer.Write(Game.ScoreLogs[i].Value); + writer.Write((short) Game.ScoreLogs[i].TextToken); } - Writer.Write(Game.CurrentScore.Maximum); - Writer.Write(Footer); - Writer.Close(); + writer.Write(Game.CurrentScore.Maximum); + writer.Write(footer); + writer.Close(); } - Stream.Close(); + stream.Close(); } } catch @@ -177,52 +177,52 @@ internal enum BlackBoxFormat FormattedText = 1 } /// Gets the formatted output text for a black box event token - /// The event token for which to get the text - internal static string GetBlackBoxText(Game.BlackBoxEventToken EventToken) + /// The event token for which to get the text + internal static string GetBlackBoxText(Game.BlackBoxEventToken eventToken) { //TODO: Only returns a blank string, what was intended here??? - switch (EventToken) + switch (eventToken) { default: return ""; } } /// Exports the current black box data to a file - /// The file to write - /// The format in which to write the data - internal static void ExportBlackBox(string File, BlackBoxFormat Format) + /// The file to write + /// The format in which to write the data + internal static void ExportBlackBox(string file, BlackBoxFormat format) { - switch (Format) + switch (format) { // comma separated value case BlackBoxFormat.CommaSeparatedValue: { - CultureInfo Culture = CultureInfo.InvariantCulture; - System.Text.StringBuilder Builder = new System.Text.StringBuilder(); + CultureInfo culture = CultureInfo.InvariantCulture; + System.Text.StringBuilder builder = new System.Text.StringBuilder(); for (int i = 0; i < Game.BlackBoxEntryCount; i++) { - Builder.Append(Game.BlackBoxEntries[i].Time.ToString(Culture) + ","); - Builder.Append(Game.BlackBoxEntries[i].Position.ToString(Culture) + ","); - Builder.Append(Game.BlackBoxEntries[i].Speed.ToString(Culture) + ","); - Builder.Append(Game.BlackBoxEntries[i].Acceleration.ToString(Culture) + ","); - Builder.Append((Game.BlackBoxEntries[i].ReverserDriver).ToString(Culture) + ","); - Builder.Append((Game.BlackBoxEntries[i].ReverserSafety).ToString(Culture) + ","); - Builder.Append(((short)Game.BlackBoxEntries[i].PowerDriver).ToString(Culture) + ","); - Builder.Append(((short)Game.BlackBoxEntries[i].PowerSafety).ToString(Culture) + ","); - Builder.Append(((short)Game.BlackBoxEntries[i].BrakeDriver).ToString(Culture) + ","); - Builder.Append(((short)Game.BlackBoxEntries[i].BrakeSafety).ToString(Culture) + ","); - Builder.Append(((short)Game.BlackBoxEntries[i].EventToken).ToString(Culture)); - Builder.Append("\r\n"); + builder.Append(Game.BlackBoxEntries[i].Time.ToString(culture) + ","); + builder.Append(Game.BlackBoxEntries[i].Position.ToString(culture) + ","); + builder.Append(Game.BlackBoxEntries[i].Speed.ToString(culture) + ","); + builder.Append(Game.BlackBoxEntries[i].Acceleration.ToString(culture) + ","); + builder.Append((Game.BlackBoxEntries[i].ReverserDriver).ToString(culture) + ","); + builder.Append((Game.BlackBoxEntries[i].ReverserSafety).ToString(culture) + ","); + builder.Append(((short)Game.BlackBoxEntries[i].PowerDriver).ToString(culture) + ","); + builder.Append(((short)Game.BlackBoxEntries[i].PowerSafety).ToString(culture) + ","); + builder.Append(((short)Game.BlackBoxEntries[i].BrakeDriver).ToString(culture) + ","); + builder.Append(((short)Game.BlackBoxEntries[i].BrakeSafety).ToString(culture) + ","); + builder.Append(((short)Game.BlackBoxEntries[i].EventToken).ToString(culture)); + builder.Append("\r\n"); } - System.IO.File.WriteAllText(File, Builder.ToString(), new System.Text.UTF8Encoding(true)); + File.WriteAllText(file, builder.ToString(), new System.Text.UTF8Encoding(true)); } break; // formatted text case BlackBoxFormat.FormattedText: { - CultureInfo Culture = CultureInfo.InvariantCulture; - System.Text.StringBuilder Builder = new System.Text.StringBuilder(); - string[][] Lines = new string[Game.BlackBoxEntryCount + 1][]; - Lines[0] = new[] { + CultureInfo culture = CultureInfo.InvariantCulture; + System.Text.StringBuilder builder = new System.Text.StringBuilder(); + string[][] lines = new string[Game.BlackBoxEntryCount + 1][]; + lines[0] = new[] { Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","time"}), Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","position"}), Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","speed"}), @@ -232,11 +232,11 @@ internal static void ExportBlackBox(string File, BlackBoxFormat Format) Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","brake"}), Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","event"}), }; - int Columns = Lines[0].Length; + int columns = lines[0].Length; for (int i = 0; i < Game.BlackBoxEntryCount; i++) { int j = i + 1; - Lines[j] = new string[Columns]; + lines[j] = new string[columns]; { double x = Game.BlackBoxEntries[i].Time; int h = (int)Math.Floor(x / 3600.0); @@ -246,11 +246,11 @@ internal static void ExportBlackBox(string File, BlackBoxFormat Format) int s = (int)Math.Floor(x); x -= s; int n = (int)Math.Floor(1000.0 * x); - Lines[j][0] = h.ToString("00", Culture) + ":" + m.ToString("00", Culture) + ":" + s.ToString("00", Culture) + ":" + n.ToString("000", Culture); + lines[j][0] = h.ToString("00", culture) + ":" + m.ToString("00", culture) + ":" + s.ToString("00", culture) + ":" + n.ToString("000", culture); } - Lines[j][1] = Game.BlackBoxEntries[i].Position.ToString("0.000", Culture); - Lines[j][2] = Game.BlackBoxEntries[i].Speed.ToString("0.0000", Culture); - Lines[j][3] = Game.BlackBoxEntries[i].Acceleration.ToString("0.0000", Culture); + lines[j][1] = Game.BlackBoxEntries[i].Position.ToString("0.000", culture); + lines[j][2] = Game.BlackBoxEntries[i].Speed.ToString("0.0000", culture); + lines[j][3] = Game.BlackBoxEntries[i].Acceleration.ToString("0.0000", culture); { string[] reverser = new string[2]; for (int k = 0; k < 2; k++) @@ -268,11 +268,11 @@ internal static void ExportBlackBox(string File, BlackBoxFormat Format) reverser[k] = Translations.QuickReferences.HandleForward; break; default: - reverser[k] = r.ToString(Culture); + reverser[k] = r.ToString(culture); break; } } - Lines[j][4] = reverser[0] + " → " + reverser[1]; + lines[j][4] = reverser[0] + " → " + reverser[1]; } { string[] power = new string[2]; @@ -285,11 +285,11 @@ internal static void ExportBlackBox(string File, BlackBoxFormat Format) power[k] = Translations.QuickReferences.HandlePowerNull; break; default: - power[k] = Translations.QuickReferences.HandlePower + ((short)p).ToString(Culture); + power[k] = Translations.QuickReferences.HandlePower + ((short)p).ToString(culture); break; } } - Lines[j][5] = power[0] + " → " + power[1]; + lines[j][5] = power[0] + " → " + power[1]; } { string[] brake = new string[2]; @@ -317,97 +317,97 @@ internal static void ExportBlackBox(string File, BlackBoxFormat Format) brake[k] = Translations.QuickReferences.HandleService; break; default: - brake[k] = Translations.QuickReferences.HandleBrake + ((short)b).ToString(Culture); + brake[k] = Translations.QuickReferences.HandleBrake + ((short)b).ToString(culture); break; } } - Lines[j][6] = brake[0] + " → " + brake[1]; + lines[j][6] = brake[0] + " → " + brake[1]; } - Lines[j][7] = GetBlackBoxText(Game.BlackBoxEntries[i].EventToken); + lines[j][7] = GetBlackBoxText(Game.BlackBoxEntries[i].EventToken); } - int[] Widths = new int[Columns]; - for (int i = 0; i < Lines.Length; i++) + int[] widths = new int[columns]; + for (int i = 0; i < lines.Length; i++) { - for (int j = 0; j < Columns; j++) + for (int j = 0; j < columns; j++) { - if (Lines[i][j].Length > Widths[j]) + if (lines[i][j].Length > widths[j]) { - Widths[j] = Lines[i][j].Length; + widths[j] = lines[i][j].Length; } } } { // header rows - int TotalWidth = 0; - for (int j = 0; j < Columns; j++) + int totalWidth = 0; + for (int j = 0; j < columns; j++) { - TotalWidth += Widths[j] + 2; + totalWidth += widths[j] + 2; } - TotalWidth += Columns - 1; - Builder.Append('╔'); - Builder.Append('═', TotalWidth); - Builder.Append("╗\r\n"); + totalWidth += columns - 1; + builder.Append('╔'); + builder.Append('═', totalWidth); + builder.Append("╗\r\n"); { - Builder.Append('║'); - Builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","route"}) + " " + Game.LogRouteName).PadRight(TotalWidth, ' ')); - Builder.Append("║\r\n║"); - Builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","train"}) + " " + Game.LogTrainName).PadRight(TotalWidth, ' ')); - Builder.Append("║\r\n║"); - Builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","date"}) + " " + Game.LogDateTime.ToString("yyyy-MM-dd HH:mm:ss", Culture)).PadRight(TotalWidth, ' ')); - Builder.Append("║\r\n"); + builder.Append('║'); + builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","route"}) + " " + Game.LogRouteName).PadRight(totalWidth, ' ')); + builder.Append("║\r\n║"); + builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","train"}) + " " + Game.LogTrainName).PadRight(totalWidth, ' ')); + builder.Append("║\r\n║"); + builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","date"}) + " " + Game.LogDateTime.ToString("yyyy-MM-dd HH:mm:ss", culture)).PadRight(totalWidth, ' ')); + builder.Append("║\r\n"); } } { // top border row - Builder.Append('╠'); - for (int j = 0; j < Columns; j++) + builder.Append('╠'); + for (int j = 0; j < columns; j++) { if (j != 0) { - Builder.Append('╤'); - } Builder.Append('═', Widths[j] + 2); - } Builder.Append("╣\r\n"); + builder.Append('╤'); + } builder.Append('═', widths[j] + 2); + } builder.Append("╣\r\n"); } - for (int i = 0; i < Lines.Length; i++) + for (int i = 0; i < lines.Length; i++) { // center border row if (i != 0) { - Builder.Append('╟'); - for (int j = 0; j < Columns; j++) + builder.Append('╟'); + for (int j = 0; j < columns; j++) { if (j != 0) { - Builder.Append('┼'); - } Builder.Append('─', Widths[j] + 2); - } Builder.Append("╢\r\n"); + builder.Append('┼'); + } builder.Append('─', widths[j] + 2); + } builder.Append("╢\r\n"); } // cell content - Builder.Append('║'); - for (int j = 0; j < Columns; j++) + builder.Append('║'); + for (int j = 0; j < columns; j++) { - if (j != 0) Builder.Append('│'); - Builder.Append(' '); + if (j != 0) builder.Append('│'); + builder.Append(' '); if (i != 0 & j <= 3) { - Builder.Append(Lines[i][j].PadLeft(Widths[j], ' ')); + builder.Append(lines[i][j].PadLeft(widths[j], ' ')); } else { - Builder.Append(Lines[i][j].PadRight(Widths[j], ' ')); + builder.Append(lines[i][j].PadRight(widths[j], ' ')); } - Builder.Append(' '); - } Builder.Append("║\r\n"); + builder.Append(' '); + } builder.Append("║\r\n"); } { // bottom border row - Builder.Append('╚'); - for (int j = 0; j < Columns; j++) + builder.Append('╚'); + for (int j = 0; j < columns; j++) { if (j != 0) { - Builder.Append('╧'); - } Builder.Append('═', Widths[j] + 2); - } Builder.Append('╝'); + builder.Append('╧'); + } builder.Append('═', widths[j] + 2); + } builder.Append('╝'); } - System.IO.File.WriteAllText(File, Builder.ToString(), new System.Text.UTF8Encoding(true)); + File.WriteAllText(file, builder.ToString(), new System.Text.UTF8Encoding(true)); } break; } } diff --git a/source/OpenBVE/System/Logging/Score.cs b/source/OpenBVE/System/Logging/Score.cs index 998a728bd..835e3e064 100644 --- a/source/OpenBVE/System/Logging/Score.cs +++ b/source/OpenBVE/System/Logging/Score.cs @@ -9,9 +9,9 @@ namespace OpenBve internal static partial class Interface { /// Gets the formatted text for an in-game score event - /// The in-game score event - internal static string GetScoreText(Game.ScoreTextToken TextToken) { - switch (TextToken) { + /// The in-game score event + internal static string GetScoreText(Game.ScoreTextToken textToken) { + switch (textToken) { case Game.ScoreTextToken.Overspeed: return Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"score","overspeed"}); case Game.ScoreTextToken.PassedRedSignal: return Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"score","redsignal"}); case Game.ScoreTextToken.Toppling: return Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"score","toppling"}); @@ -30,23 +30,23 @@ internal static string GetScoreText(Game.ScoreTextToken TextToken) { } /// Exports the current score data to a file - /// The file to write - internal static void ExportScore(string File) { - CultureInfo Culture = CultureInfo.InvariantCulture; - System.Text.StringBuilder Builder = new System.Text.StringBuilder(); - string[][] Lines = new string[Game.ScoreLogCount + 1][]; - Lines[0] = new[] { + /// The file to write + internal static void ExportScore(string file) { + CultureInfo culture = CultureInfo.InvariantCulture; + System.Text.StringBuilder builder = new System.Text.StringBuilder(); + string[][] lines = new string[Game.ScoreLogCount + 1][]; + lines[0] = new[] { Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","time"}), Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","position"}), Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","value"}), Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","cumulative"}), Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","reason"}) }; - int Columns = Lines[0].Length; - int TotalScore = 0; + int columns = lines[0].Length; + int totalScore = 0; for (int i = 0; i < Game.ScoreLogCount; i++) { int j = i + 1; - Lines[j] = new string[Columns]; + lines[j] = new string[columns]; { double x = Game.ScoreLogs[i].Time; int h = (int)Math.Floor(x / 3600.0); @@ -54,43 +54,43 @@ internal static void ExportScore(string File) { int m = (int)Math.Floor(x / 60.0); x -= m * 60.0; int s = (int)Math.Floor(x); - Lines[j][0] = h.ToString("00", Culture) + ":" + m.ToString("00", Culture) + ":" + s.ToString("00", Culture); + lines[j][0] = h.ToString("00", culture) + ":" + m.ToString("00", culture) + ":" + s.ToString("00", culture); } - Lines[j][1] = Game.ScoreLogs[i].Position.ToString("0", Culture); - Lines[j][2] = Game.ScoreLogs[i].Value.ToString(Culture); - TotalScore += Game.ScoreLogs[i].Value; - Lines[j][3] = TotalScore.ToString(Culture); - Lines[j][4] = GetScoreText(Game.ScoreLogs[i].TextToken); + lines[j][1] = Game.ScoreLogs[i].Position.ToString("0", culture); + lines[j][2] = Game.ScoreLogs[i].Value.ToString(culture); + totalScore += Game.ScoreLogs[i].Value; + lines[j][3] = totalScore.ToString(culture); + lines[j][4] = GetScoreText(Game.ScoreLogs[i].TextToken); } - int[] Widths = new int[Columns]; - for (int i = 0; i < Lines.Length; i++) { - for (int j = 0; j < Columns; j++) { - if (Lines[i][j].Length > Widths[j]) { - Widths[j] = Lines[i][j].Length; + int[] widths = new int[columns]; + for (int i = 0; i < lines.Length; i++) { + for (int j = 0; j < columns; j++) { + if (lines[i][j].Length > widths[j]) { + widths[j] = lines[i][j].Length; } } } { // header rows - int TotalWidth = 0; - for (int j = 0; j < Columns; j++) { - TotalWidth += Widths[j] + 2; + int totalWidth = 0; + for (int j = 0; j < columns; j++) { + totalWidth += widths[j] + 2; } - TotalWidth += Columns - 1; - Builder.Append('╔'); - Builder.Append('═', TotalWidth); - Builder.Append("╗\n"); + totalWidth += columns - 1; + builder.Append('╔'); + builder.Append('═', totalWidth); + builder.Append("╗\n"); { - Builder.Append('║'); - Builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","route"}) + " " + Game.LogRouteName).PadRight(TotalWidth, ' ')); - Builder.Append("║\n║"); - Builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","train"}) + " " + Game.LogTrainName).PadRight(TotalWidth, ' ')); - Builder.Append("║\n║"); - Builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","date"}) + " " + Game.LogDateTime.ToString("yyyy-MM-dd HH:mm:ss", Culture)).PadRight(TotalWidth, ' ')); - Builder.Append("║\n"); + builder.Append('║'); + builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","route"}) + " " + Game.LogRouteName).PadRight(totalWidth, ' ')); + builder.Append("║\n║"); + builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","train"}) + " " + Game.LogTrainName).PadRight(totalWidth, ' ')); + builder.Append("║\n║"); + builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","date"}) + " " + Game.LogDateTime.ToString("yyyy-MM-dd HH:mm:ss", culture)).PadRight(totalWidth, ' ')); + builder.Append("║\n"); } - Builder.Append('╠'); - Builder.Append('═', TotalWidth); - Builder.Append("╣\n"); + builder.Append('╠'); + builder.Append('═', totalWidth); + builder.Append("╣\n"); { double ratio = Game.CurrentScore.Maximum == 0 ? 0.0 : Game.CurrentScore.CurrentValue / (double)Game.CurrentScore.Maximum; if (ratio < 0.0) ratio = 0.0; @@ -104,55 +104,55 @@ internal static void ExportScore(string File) { case GameMode.Expert: s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"mode","expert"}); break; default: s = Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"mode","unknown"}); break; } - Builder.Append('║'); - Builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","mode"}) + " " + s).PadRight(TotalWidth, ' ')); - Builder.Append("║\n║"); - Builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","score"}) + " " + Game.CurrentScore.CurrentValue.ToString(Culture) + " / " + Game.CurrentScore.Maximum.ToString(Culture)).PadRight(TotalWidth, ' ')); - Builder.Append("║\n║"); - Builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"log","rating"}) + " " + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"rating" , index.ToString(Culture)}) + " (" + (100.0 * ratio).ToString("0.00") + "%)").PadRight(TotalWidth, ' ')); - Builder.Append("║\n"); + builder.Append('║'); + builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","mode"}) + " " + s).PadRight(totalWidth, ' ')); + builder.Append("║\n║"); + builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new[] {"log","score"}) + " " + Game.CurrentScore.CurrentValue.ToString(culture) + " / " + Game.CurrentScore.Maximum.ToString(culture)).PadRight(totalWidth, ' ')); + builder.Append("║\n║"); + builder.Append((" " + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"log","rating"}) + " " + Translations.GetInterfaceString(HostApplication.OpenBve, new [] {"rating" , index.ToString(culture)}) + " (" + (100.0 * ratio).ToString("0.00") + "%)").PadRight(totalWidth, ' ')); + builder.Append("║\n"); } } { // top border row - Builder.Append('╠'); - for (int j = 0; j < Columns; j++) { + builder.Append('╠'); + for (int j = 0; j < columns; j++) { if (j != 0) { - Builder.Append('╤'); - } Builder.Append('═', Widths[j] + 2); - } Builder.Append("╣\n"); + builder.Append('╤'); + } builder.Append('═', widths[j] + 2); + } builder.Append("╣\n"); } - for (int i = 0; i < Lines.Length; i++) { + for (int i = 0; i < lines.Length; i++) { // center border row if (i != 0) { - Builder.Append('╟'); - for (int j = 0; j < Columns; j++) { + builder.Append('╟'); + for (int j = 0; j < columns; j++) { if (j != 0) { - Builder.Append('┼'); - } Builder.Append('─', Widths[j] + 2); - } Builder.Append("╢\n"); + builder.Append('┼'); + } builder.Append('─', widths[j] + 2); + } builder.Append("╢\n"); } // cell content - Builder.Append('║'); - for (int j = 0; j < Columns; j++) { - if (j != 0) Builder.Append('│'); - Builder.Append(' '); + builder.Append('║'); + for (int j = 0; j < columns; j++) { + if (j != 0) builder.Append('│'); + builder.Append(' '); if (i != 0 & j <= 3) { - Builder.Append(Lines[i][j].PadLeft(Widths[j], ' ')); + builder.Append(lines[i][j].PadLeft(widths[j], ' ')); } else { - Builder.Append(Lines[i][j].PadRight(Widths[j], ' ')); + builder.Append(lines[i][j].PadRight(widths[j], ' ')); } - Builder.Append(' '); - } Builder.Append("║\n"); + builder.Append(' '); + } builder.Append("║\n"); } { // bottom border row - Builder.Append('╚'); - for (int j = 0; j < Columns; j++) { + builder.Append('╚'); + for (int j = 0; j < columns; j++) { if (j != 0) { - Builder.Append('╧'); - } Builder.Append('═', Widths[j] + 2); - } Builder.Append('╝'); + builder.Append('╧'); + } builder.Append('═', widths[j] + 2); + } builder.Append('╝'); } - System.IO.File.WriteAllText(File, Builder.ToString(), new System.Text.UTF8Encoding(true)); + System.IO.File.WriteAllText(file, builder.ToString(), new System.Text.UTF8Encoding(true)); } } } diff --git a/source/OpenBVE/System/MainLoop.cs b/source/OpenBVE/System/MainLoop.cs index cd288cf66..5a5d44834 100644 --- a/source/OpenBVE/System/MainLoop.cs +++ b/source/OpenBVE/System/MainLoop.cs @@ -33,9 +33,9 @@ internal enum QuitMode /// The current simulation time-factor internal static int TimeFactor = 1; - internal static double timeSinceLastMouseEvent; + private static double timeSinceLastMouseEvent; - internal static LaunchParameters currentResult; + internal static LaunchParameters CurrentResult; private static double kioskModeTimer; @@ -110,36 +110,18 @@ internal static void StartLoopEx(LaunchParameters result) Program.FileSystem.AppendToLogFile("Initialising game window of size " + Interface.CurrentOptions.WindowWidth + " x " + Interface.CurrentOptions.WindowHeight); } Screen.Initialize(); - currentResult = result; + CurrentResult = result; Program.Renderer.GameWindow.Closing += OpenTKQuit; Program.Renderer.GameWindow.Run(); } - - // -------------------------------- - - // repeats - - - // private static void ThreadProc() - // { - // RouteInformationForm = new formRouteInformation(); - // Application.Run(RouteInformationForm); - // } - + private static void OpenTKQuit(object sender, CancelEventArgs e) { Quit = QuitMode.QuitProgram; } - /******************** - PROCESS EVENTS - ********************/ - // - // MOUSE EVENTS - // - /// The current mouse state - internal static MouseState currentMouseState, previousMouseState; + private static MouseState currentMouseState, previousMouseState; internal static bool MouseGrabEnabled = false; internal static bool MouseGrabIgnoreOnce = false; @@ -148,7 +130,7 @@ PROCESS EVENTS /// Called when a mouse button is pressed /// The sender /// The button arguments - internal static void mouseDownEvent(object sender, MouseButtonEventArgs e) + internal static void MouseDownEvent(object sender, MouseButtonEventArgs e) { if (Program.Renderer.CurrentInterface == InterfaceType.LoadScreen) { @@ -180,7 +162,7 @@ internal static void mouseDownEvent(object sender, MouseButtonEventArgs e) } } - internal static void mouseUpEvent(object sender, MouseButtonEventArgs e) + internal static void MouseUpEvent(object sender, MouseButtonEventArgs e) { if (Program.Renderer.CurrentInterface == InterfaceType.LoadScreen) { @@ -200,7 +182,7 @@ internal static void mouseUpEvent(object sender, MouseButtonEventArgs e) /// Called when the mouse is moved /// The sender /// The move arguments - internal static void mouseMoveEvent(object sender, MouseMoveEventArgs e) + internal static void MouseMoveEvent(object sender, MouseMoveEventArgs e) { timeSinceLastMouseEvent = 0; // Forward movement appropriately @@ -219,7 +201,7 @@ internal static void mouseMoveEvent(object sender, MouseMoveEventArgs e) /// Called when the state of the mouse wheel changes /// The sender /// The button arguments - internal static void mouseWheelEvent(object sender, MouseWheelEventArgs e) + internal static void MouseWheelEvent(object sender, MouseWheelEventArgs e) { timeSinceLastMouseEvent = 0; if (Program.Renderer.CurrentInterface >= InterfaceType.Menu) @@ -228,11 +210,11 @@ internal static void mouseWheelEvent(object sender, MouseWheelEventArgs e) } } - internal static void UpdateMouse(double TimeElapsed) + internal static void UpdateMouse(double timeElapsed) { if (Program.Renderer.CurrentInterface < InterfaceType.Menu) { - timeSinceLastMouseEvent += TimeElapsed; + timeSinceLastMouseEvent += timeElapsed; } else { @@ -567,15 +549,15 @@ internal static void RestoreCameraSettings() #if DEBUG /// Checks whether an OpenGL error has occured this frame - /// The location of the caller (The main loop or the loading screen loop) - internal static void CheckForOpenGlError(string Location) { + /// The location of the caller (The main loop or the loading screen loop) + internal static void CheckForOpenGlError(string errorLocation) { if (Program.Renderer.ReShadeInUse) { return; } var error = GL.GetError(); if (error != ErrorCode.NoError) { - string message = Location + ": "; + string message = errorLocation + ": "; switch (error) { case ErrorCode.InvalidEnum: message += "GL_INVALID_ENUM"; diff --git a/source/OpenBVE/System/Options.cs b/source/OpenBVE/System/Options.cs index b07c7da72..050d0c873 100644 --- a/source/OpenBVE/System/Options.cs +++ b/source/OpenBVE/System/Options.cs @@ -87,10 +87,10 @@ internal class Options : BaseOptions /// Whether a screen reader is available /// Not saved, detected on game init internal bool ScreenReaderAvailable; - + /// The mode the timetable is displayed in internal TimeTableMode TimeTableStyle; - - internal CompressionType packageCompressionType; + /// The type of compression used when creating packages + internal CompressionType PackageCompressionType; /* * Only relevant in developer mode, not saved */ @@ -158,7 +158,7 @@ internal Options() TimeAccelerationFactor = 5; AllowAxisEB = true; TimeTableStyle = TimeTableMode.Default; - packageCompressionType = CompressionType.Zip; + PackageCompressionType = CompressionType.Zip; RailDriverMPH = true; EnableBveTsHacks = true; OldTransparencyMode = true; @@ -452,7 +452,7 @@ public override void Save(string fileName) Builder.AppendLine(); Builder.AppendLine("[packages]"); Builder.Append("compression = "); - switch (packageCompressionType) + switch (PackageCompressionType) { case CompressionType.Zip: Builder.AppendLine("zip"); @@ -659,7 +659,7 @@ internal static void LoadOptions() block.GetValue(OptionsKey.Train, out CurrentOptions.TrainFolder); break; case OptionsSection.Packages: - block.GetEnumValue(OptionsKey.Compression, out CurrentOptions.packageCompressionType); + block.GetEnumValue(OptionsKey.Compression, out CurrentOptions.PackageCompressionType); break; case OptionsSection.RecentlyUsedRoutes: Array.Resize(ref CurrentOptions.RecentlyUsedRoutes, block.RemainingDataValues); diff --git a/source/OpenBVE/System/Program.cs b/source/OpenBVE/System/Program.cs index 992a63940..8bf09a81e 100644 --- a/source/OpenBVE/System/Program.cs +++ b/source/OpenBVE/System/Program.cs @@ -29,7 +29,7 @@ internal static partial class Program { [DllImport("libc")] private static extern uint geteuid(); - [System.Runtime.InteropServices.DllImport("user32.dll")] + [DllImport("user32.dll")] private static extern bool SetProcessDPIAware(); #pragma warning restore IDE1006 diff --git a/source/OpenBVE/System/Program/CommandLine.cs b/source/OpenBVE/System/Program/CommandLine.cs index 0b5f12c6f..63868351d 100644 --- a/source/OpenBVE/System/Program/CommandLine.cs +++ b/source/OpenBVE/System/Program/CommandLine.cs @@ -7,65 +7,65 @@ namespace OpenBve class CommandLine { /// Parses any command-line arguments passed to the main program - /// A string array of arguments - internal static LaunchParameters ParseArguments(string[] Arguments) + /// A string array of arguments + internal static LaunchParameters ParseArguments(string[] arguments) { - LaunchParameters Result = new LaunchParameters(); - if (Arguments.Length == 0) + LaunchParameters result = new LaunchParameters(); + if (arguments.Length == 0) { - return Result; + return result; } - for (int i = 0; i < Arguments.Length; i++) + for (int i = 0; i < arguments.Length; i++) { - int equals = Arguments[i].IndexOf('='); + int equals = arguments[i].IndexOf('='); if (equals >= 0) { - string key = Arguments[i].Substring(0, equals).Trim(new char[] { }).ToLowerInvariant(); - string value = Arguments[i].Substring(equals + 1).Trim(new char[] { }); + string key = arguments[i].Substring(0, equals).Trim(new char[] { }).ToLowerInvariant(); + string value = arguments[i].Substring(equals + 1).Trim(new char[] { }); switch (key) { case "/route": - Result.RouteFile = value; - Result.RouteEncoding = TextEncoding.GetSystemEncodingFromFile(Result.RouteFile); + result.RouteFile = value; + result.RouteEncoding = TextEncoding.GetSystemEncodingFromFile(result.RouteFile); break; case "/train": - Result.TrainFolder = value; - Result.TrainEncoding = TextEncoding.GetSystemEncodingFromFile(Result.TrainFolder, "train.txt"); + result.TrainFolder = value; + result.TrainEncoding = TextEncoding.GetSystemEncodingFromFile(result.TrainFolder, "train.txt"); break; case "/station": - Result.InitialStation = value; + result.InitialStation = value; break; case "/time": - Interface.TryParseTime(value, out Result.StartTime); + Interface.TryParseTime(value, out result.StartTime); break; case "/ai": if (value.ToLowerInvariant() == "true" || value.ToLowerInvariant() == "1") { - Result.AIDriver = true; + result.AIDriver = true; } break; case "/fullscreen": if (value.ToLowerInvariant() == "true" || value.ToLowerInvariant() == "1") { - Result.FullScreen = true; + result.FullScreen = true; } break; case "/width": - NumberFormats.TryParseIntVb6(value, out Result.Width); + NumberFormats.TryParseIntVb6(value, out result.Width); break; case "/height": - NumberFormats.TryParseIntVb6(value, out Result.Height); + NumberFormats.TryParseIntVb6(value, out result.Height); break; case "/glmenu": if (value.ToLowerInvariant() == "true" || value.ToLowerInvariant() == "1") { - Result.ExperimentalGLMenu = true; + result.ExperimentalGLMenu = true; } break; } } } - return Result; + return result; } } } diff --git a/source/OpenBVE/UserInterface/formMain.Packages.cs b/source/OpenBVE/UserInterface/formMain.Packages.cs index 99611b3cc..e8575c26e 100644 --- a/source/OpenBVE/UserInterface/formMain.Packages.cs +++ b/source/OpenBVE/UserInterface/formMain.Packages.cs @@ -935,7 +935,7 @@ private void buttonCreatePackage_Click(object sender, EventArgs e) ProblemEncountered = false; workerThread.DoWork += delegate { - Manipulation.CreatePackage(currentPackage, Interface.CurrentOptions.packageCompressionType, currentPackage.FileName, ImageFile, filesToPackage); + Manipulation.CreatePackage(currentPackage, Interface.CurrentOptions.PackageCompressionType, currentPackage.FileName, ImageFile, filesToPackage); }; workerThread.RunWorkerCompleted += delegate { diff --git a/source/OpenBVE/UserInterface/formMain.cs b/source/OpenBVE/UserInterface/formMain.cs index ae6dd6502..810ea4cff 100644 --- a/source/OpenBVE/UserInterface/formMain.cs +++ b/source/OpenBVE/UserInterface/formMain.cs @@ -486,7 +486,7 @@ private void formMain_Load(object sender, EventArgs e) updownSoundNumber.Value = Interface.CurrentOptions.SoundNumber; checkboxWarningMessages.Checked = Interface.CurrentOptions.ShowWarningMessages; checkboxErrorMessages.Checked = Interface.CurrentOptions.ShowErrorMessages; - comboBoxCompressionFormat.SelectedIndex = (int)Interface.CurrentOptions.packageCompressionType; + comboBoxCompressionFormat.SelectedIndex = (int)Interface.CurrentOptions.PackageCompressionType; comboBoxRailDriverUnits.SelectedIndex = Interface.CurrentOptions.RailDriverMPH ? 0 : 1; checkBoxEnableKiosk.Checked = Interface.CurrentOptions.KioskMode; numericUpDownKioskTimeout.Value = (decimal)Interface.CurrentOptions.KioskModeTimer; @@ -1992,13 +1992,13 @@ private void comboBoxCompressionFormat_SelectedIndexChanged(object sender, Event switch (comboBoxCompressionFormat.SelectedIndex) { case 0: - Interface.CurrentOptions.packageCompressionType = CompressionType.Zip; + Interface.CurrentOptions.PackageCompressionType = CompressionType.Zip; break; case 1: - Interface.CurrentOptions.packageCompressionType = CompressionType.TarGZ; + Interface.CurrentOptions.PackageCompressionType = CompressionType.TarGZ; break; case 2: - Interface.CurrentOptions.packageCompressionType = CompressionType.BZ2; + Interface.CurrentOptions.PackageCompressionType = CompressionType.BZ2; break; } }