Пример #1
0
        protected override void AddReferencedFiles()
        {
            string routePath;
            string basePath;

            GetRouteAndBasePath(loadedFile, out routePath, out basePath);

            List <string> possiblePaths = new List <string>
            {
                Path.GetDirectoryName(loadedFile)
            };

            if (routePath != null)
            {
                possiblePaths.Add(Path.Combine(routePath, "SOUND"));
            }
            if (basePath != null)
            {
                possiblePaths.Add(Path.Combine(basePath, "SOUND"));
            }

            // Try to also load all sound files. This is tricky, because quite deep into the structure of a sms
            foreach (var group in sms.ScalabiltyGroups)
            {
                if (group.Streams == null)
                {
                    continue;
                }
                foreach (var stream in group.Streams)
                {
                    foreach (var trigger in stream.Triggers)
                    {
                        SoundPlayCommand playCommand = trigger.SoundCommand as SoundPlayCommand;
                        if (playCommand == null)
                        {
                            continue;
                        }
                        foreach (string file in playCommand.Files)
                        {
                            if (file == null)
                            {
                                Trace.TraceWarning("Missing well-defined file name in {0}\n", loadedFile);
                                continue;
                            }

                            //The file can be in multiple places
                            //Assume .wav file for now
                            var fullPath = FolderStructure.FindFileFromFolders(possiblePaths, file);
                            if (fullPath == null)
                            {
                                //apparently the file does not exist, but we want to make that known to the user, so we make a path anyway
                                fullPath = Path.Combine(possiblePaths[0], file);
                            }
                            AddAdditionalFileAction.Invoke(fullPath, new WavLoader());
                        }
                    }
                }
            }
        }
Пример #2
0
        public void Initialize()
        {
            if (!Simulator.Settings.DisableTCSScripts && ScriptName != null && ScriptName != "MSTS")
            {
                Script = Simulator.ScriptManager.Load(Path.Combine(Path.GetDirectoryName(Locomotive.WagFilePath), "Script"), 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 = FolderStructure.FindFileFromFolders(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 <TrackMonitorSignalAspect>(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 ? (float)Pressure.Atmospheric.FromPSI(Locomotive.BrakeSystem.BrakeLine1PressurePSI) : float.MaxValue;
            Script.LocomotiveBrakeCylinderPressureBar       = () => Locomotive.BrakeSystem != null ? (float)Pressure.Atmospheric.FromPSI(Locomotive.BrakeSystem.GetCylPressurePSI()) : float.MaxValue;
            Script.DoesBrakeCutPower                        = () => Locomotive.DoesBrakeCutPower;
            Script.BrakeCutsPowerAtBrakeCylinderPressureBar = () => (float)Pressure.Atmospheric.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 ? TrainEvent.VigilanceAlarmOn : TrainEvent.VigilanceAlarmOff);
            Script.SetHorn                      = (value) => Locomotive.TCSHorn = value;
            Script.TriggerSoundAlert1           = () => this.SignalEvent(TrainEvent.TrainControlSystemAlert1,Script);
            Script.TriggerSoundAlert2           = () => this.SignalEvent(TrainEvent.TrainControlSystemAlert2,Script);
            Script.TriggerSoundInfo1            = () => this.SignalEvent(TrainEvent.TrainControlSystemInfo1,Script);
            Script.TriggerSoundInfo2            = () => this.SignalEvent(TrainEvent.TrainControlSystemInfo2,Script);
            Script.TriggerSoundPenalty1         = () => this.SignalEvent(TrainEvent.TrainControlSystemPenalty1,Script);
            Script.TriggerSoundPenalty2         = () => this.SignalEvent(TrainEvent.TrainControlSystemPenalty2,Script);
            Script.TriggerSoundWarning1         = () => this.SignalEvent(TrainEvent.TrainControlSystemWarning1,Script);
            Script.TriggerSoundWarning2         = () => this.SignalEvent(TrainEvent.TrainControlSystemWarning2,Script);
            Script.TriggerSoundSystemActivate   = () => this.SignalEvent(TrainEvent.TrainControlSystemActivate,Script);
            Script.TriggerSoundSystemDeactivate = () => this.SignalEvent(TrainEvent.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();
        }