コード例 #1
0
 private void SignalEvent(Event evt,TrainControlSystem script)
 {
     foreach (var eventHandler in Locomotive.EventHandlers)
     {
         eventHandler.HandleEvent(evt,script);
     }
 }
コード例 #2
0
 private void SignalEvent(Event evt,TrainControlSystem script)
 {
     try
     {
         foreach (var eventHandler in Locomotive.EventHandlers)
         {
             eventHandler.HandleEvent(evt,script);
         }
     }
     catch (Exception error)
     {
         Trace.TraceInformation("Sound event skipped due to thread safety problem " + error.Message);
     }
 }
コード例 #3
0
        public void Initialize()
        {
            if (!Simulator.Settings.DisableTCSScripts && ScriptName != null && ScriptName != "MSTS")
            {
                var pathArray = new string[] { Path.Combine(Path.GetDirectoryName(Locomotive.WagFilePath), "Script") };
                Script = Simulator.ScriptManager.Load(pathArray, ScriptName) as TrainControlSystem;
            }

            if (ParametersFileName != null)
            {
                ParametersFileName = Path.Combine(Path.Combine(Path.GetDirectoryName(Locomotive.WagFilePath), "Script"), ParametersFileName);
            }

            if (Script == null)
            {
                Script = new MSTSTrainControlSystem();
                ((MSTSTrainControlSystem)Script).VigilanceMonitor            = VigilanceMonitor;
                ((MSTSTrainControlSystem)Script).OverspeedMonitor            = OverspeedMonitor;
                ((MSTSTrainControlSystem)Script).EmergencyStopMonitor        = EmergencyStopMonitor;
                ((MSTSTrainControlSystem)Script).AWSMonitor                  = AWSMonitor;
                ((MSTSTrainControlSystem)Script).EmergencyCausesThrottleDown = Locomotive.EmergencyCausesThrottleDown;
                ((MSTSTrainControlSystem)Script).EmergencyEngagesHorn        = Locomotive.EmergencyEngagesHorn;
            }

            if (SoundFileName != null)
            {
                var soundPathArray = new[] {
                    Path.Combine(Path.GetDirectoryName(Locomotive.WagFilePath), "SOUND"),
                    Path.Combine(Simulator.BasePath, "SOUND"),
                };
                var soundPath = ORTSPaths.GetFileFromFolders(soundPathArray, SoundFileName);
                if (File.Exists(soundPath))
                {
                    Sounds.Add(Script, soundPath);
                }
            }

            // AbstractScriptClass
            Script.ClockTime          = () => (float)Simulator.ClockTime;
            Script.GameTime           = () => (float)Simulator.GameTime;
            Script.DistanceM          = () => Locomotive.DistanceM;
            Script.Confirm            = Locomotive.Simulator.Confirmer.Confirm;
            Script.Message            = Locomotive.Simulator.Confirmer.Message;
            Script.SignalEvent        = Locomotive.SignalEvent;
            Script.SignalEventToTrain = (evt) =>
            {
                if (Locomotive.Train != null)
                {
                    Locomotive.Train.SignalEvent(evt);
                }
            };

            // TrainControlSystem getters
            Script.IsTrainControlEnabled = () => Locomotive == Locomotive.Train.LeadLocomotive && Locomotive.Train.TrainType != Train.TRAINTYPE.AI_PLAYERHOSTING;
            Script.IsAlerterEnabled      = () =>
            {
                return(Simulator.Settings.Alerter &&
                       !(Simulator.Settings.AlerterDisableExternal &&
                         !Simulator.PlayerIsInCab
                         ));
            };
            Script.IsSpeedControlEnabled      = () => Simulator.Settings.SpeedControl;
            Script.AlerterSound               = () => Locomotive.AlerterSnd;
            Script.TrainSpeedLimitMpS         = () => TrainInfo.allowedSpeedMpS;
            Script.CurrentSignalSpeedLimitMpS = () => Locomotive.Train.allowedMaxSpeedSignalMpS;
            Script.NextSignalSpeedLimitMpS    = (value) => NextSignalItem <float>(value, ref SignalSpeedLimits, Train.TrainObjectItem.TRAINOBJECTTYPE.SIGNAL);
            Script.NextSignalAspect           = (value) => NextSignalItem <Aspect>(value,ref SignalAspects,Train.TrainObjectItem.TRAINOBJECTTYPE.SIGNAL);
            Script.NextSignalDistanceM        = (value) => NextSignalItem <float>(value,ref SignalDistances,Train.TrainObjectItem.TRAINOBJECTTYPE.SIGNAL);
            Script.CurrentPostSpeedLimitMpS   = () => Locomotive.Train.allowedMaxSpeedLimitMpS;
            Script.NextPostSpeedLimitMpS      = (value) => NextSignalItem <float>(value,ref PostSpeedLimits,Train.TrainObjectItem.TRAINOBJECTTYPE.SPEEDPOST);
            Script.NextPostDistanceM          = (value) => NextSignalItem <float>(value,ref PostDistances,Train.TrainObjectItem.TRAINOBJECTTYPE.SPEEDPOST);
            Script.TrainLengthM               = () => Locomotive.Train != null ? Locomotive.Train.Length : 0f;
            Script.SpeedMpS                   = () => Math.Abs(Locomotive.SpeedMpS);
            Script.CurrentDirection           = () => Locomotive.Direction;
            Script.IsDirectionForward         = () => Locomotive.Direction == Direction.Forward;
            Script.IsDirectionNeutral         = () => Locomotive.Direction == Direction.N;
            Script.IsDirectionReverse         = () => Locomotive.Direction == Direction.Reverse;
            Script.IsBrakeEmergency           = () => Locomotive.TrainBrakeController.EmergencyBraking;
            Script.IsBrakeFullService         = () => Locomotive.TrainBrakeController.TCSFullServiceBraking;
            Script.PowerAuthorization         = () => PowerAuthorization;
            Script.CircuitBreakerClosingOrder = () => CircuitBreakerClosingOrder;
            Script.CircuitBreakerOpeningOrder = () => CircuitBreakerOpeningOrder;
            Script.TractionAuthorization      = () => TractionAuthorization;
            Script.BrakePipePressureBar       = () => Locomotive.BrakeSystem != null?Bar.FromPSI(Locomotive.BrakeSystem.BrakeLine1PressurePSI) : float.MaxValue;

            Script.LocomotiveBrakeCylinderPressureBar = () => Locomotive.BrakeSystem != null?Bar.FromPSI(Locomotive.BrakeSystem.GetCylPressurePSI()) : float.MaxValue;

            Script.DoesBrakeCutPower = () => Locomotive.DoesBrakeCutPower;
            Script.BrakeCutsPowerAtBrakeCylinderPressureBar = () => Bar.FromPSI(Locomotive.BrakeCutsPowerAtBrakeCylinderPressurePSI);

            // TrainControlSystem functions
            Script.SpeedCurve    = (arg1,arg2,arg3,arg4,arg5) => SpeedCurve(arg1,arg2,arg3,arg4,arg5);
            Script.DistanceCurve = (arg1,arg2,arg3,arg4,arg5) => DistanceCurve(arg1,arg2,arg3,arg4,arg5);
            Script.Deceleration  = (arg1,arg2,arg3) => Deceleration(arg1,arg2,arg3);

            // TrainControlSystem setters
            Script.SetFullBrake = (value) =>
            {
                if (Locomotive.TrainBrakeController.TCSFullServiceBraking != value)
                {
                    Locomotive.TrainBrakeController.TCSFullServiceBraking = value;

                    //Debrief Eval
                    if (value && Locomotive.IsPlayerTrain && !ldbfevalfullbrakeabove16kmh && Math.Abs(Locomotive.SpeedMpS) > 4.44444)
                    {
                        var train = Simulator.PlayerLocomotive.Train;//Debrief Eval
                        DbfevalFullBrakeAbove16kmh++;
                        ldbfevalfullbrakeabove16kmh = true;
                        train.DbfEvalValueChanged   = true;//Debrief eval
                    }
                    if (!value)
                    {
                        ldbfevalfullbrakeabove16kmh = false;
                    }
                }
            };
            Script.SetEmergencyBrake = (value) =>
            {
                if (Locomotive.TrainBrakeController.TCSEmergencyBraking != value)
                {
                    Locomotive.TrainBrakeController.TCSEmergencyBraking = value;
                }
            };
            Script.SetThrottleController     = (value) => Locomotive.ThrottleController.SetValue(value);
            Script.SetDynamicBrakeController = (value) => Locomotive.DynamicBrakeController.SetValue(value);
            Script.SetPantographsDown        = () =>
            {
                if (Locomotive.Pantographs.State == PantographState.Up)
                {
                    Locomotive.Train.SignalEvent(PowerSupplyEvent.LowerPantograph);
                }
            };
            Script.SetPowerAuthorization         = (value) => PowerAuthorization = value;
            Script.SetCircuitBreakerClosingOrder = (value) => CircuitBreakerClosingOrder = value;
            Script.SetCircuitBreakerOpeningOrder = (value) => CircuitBreakerOpeningOrder = value;
            Script.SetTractionAuthorization      = (value) => TractionAuthorization = value;
            Script.SetVigilanceAlarm             = (value) => Locomotive.SignalEvent(value ? Event.VigilanceAlarmOn : Event.VigilanceAlarmOff);
            Script.SetHorn                      = (value) => Locomotive.TCSHorn = value;
            Script.TriggerSoundAlert1           = () => this.SignalEvent(Event.TrainControlSystemAlert1,Script);
            Script.TriggerSoundAlert2           = () => this.SignalEvent(Event.TrainControlSystemAlert2,Script);
            Script.TriggerSoundInfo1            = () => this.SignalEvent(Event.TrainControlSystemInfo1,Script);
            Script.TriggerSoundInfo2            = () => this.SignalEvent(Event.TrainControlSystemInfo2,Script);
            Script.TriggerSoundPenalty1         = () => this.SignalEvent(Event.TrainControlSystemPenalty1,Script);
            Script.TriggerSoundPenalty2         = () => this.SignalEvent(Event.TrainControlSystemPenalty2,Script);
            Script.TriggerSoundWarning1         = () => this.SignalEvent(Event.TrainControlSystemWarning1,Script);
            Script.TriggerSoundWarning2         = () => this.SignalEvent(Event.TrainControlSystemWarning2,Script);
            Script.TriggerSoundSystemActivate   = () => this.SignalEvent(Event.TrainControlSystemActivate,Script);
            Script.TriggerSoundSystemDeactivate = () => this.SignalEvent(Event.TrainControlSystemDeactivate,Script);
            Script.SetVigilanceAlarmDisplay     = (value) => this.VigilanceAlarm = value;
            Script.SetVigilanceEmergencyDisplay = (value) => this.VigilanceEmergency = value;
            Script.SetOverspeedWarningDisplay   = (value) => this.OverspeedWarning = value;
            Script.SetPenaltyApplicationDisplay = (value) => this.PenaltyApplication = value;
            Script.SetMonitoringStatus          = (value) => this.MonitoringStatus = value;
            Script.SetCurrentSpeedLimitMpS      = (value) => this.CurrentSpeedLimitMpS = value;
            Script.SetNextSpeedLimitMpS         = (value) => this.NextSpeedLimitMpS = value;
            Script.SetInterventionSpeedLimitMpS = (value) => this.InterventionSpeedLimitMpS = value;
            Script.SetNextSignalAspect          = (value) => this.CabSignalAspect = (TrackMonitorSignalAspect)value;

            // TrainControlSystem INI configuration file
            Script.GetBoolParameter   = (arg1,arg2,arg3) => LoadParameter <bool>(arg1,arg2,arg3);
            Script.GetIntParameter    = (arg1,arg2,arg3) => LoadParameter <int>(arg1,arg2,arg3);
            Script.GetFloatParameter  = (arg1,arg2,arg3) => LoadParameter <float>(arg1,arg2,arg3);
            Script.GetStringParameter = (arg1,arg2,arg3) => LoadParameter <string>(arg1,arg2,arg3);

            Script.Initialize();
        }