Example #1
0
		// --- constructors ---
		
		/// <summary>Creates a new instance of this system with default parameters.</summary>
		/// <param name="train">The train.</param>
		internal AtsSx(Train train) {
			this.Train = train;
			this.State = States.Disabled;
			this.AlarmCountdown = 0.0;
			this.SpeedCheckCountdown = 0.0;
			this.RedSignalLocation = 0.0;
		}
Example #2
0
 /// <summary>Is called when the plugin is loaded.</summary>
 /// <param name="properties">The properties supplied to the plugin on loading.</param>
 /// <returns>Whether the plugin was loaded successfully.</returns>
 public bool Load(LoadProperties properties)
 {
     properties.Panel = new int[256];
     properties.AISupport = AISupport.Basic;
     train = new Train(properties.Panel, properties.PlaySound);
     return true;
 }
Example #3
0
 // --- constructors ---
 /// <summary>Creates a new instance of this system.</summary>
 /// <param name="train">The train.</param>
 /// <param name="automaticSwitch">Whether to switch automatically between ATS to ATC.</param>
 internal Atc(Train train, bool automaticSwitch)
 {
     this.Train = train;
     this.State = States.Disabled;
     this.CompatibilityState = CompatibilityStates.Ats;
     this.CompatibilityLimits = new List<CompatibilityLimit>();
     this.AutomaticSwitch = automaticSwitch;
 }
Example #4
0
 // --- constructors ---
 /// <summary>Creates a new instance of this system.</summary>
 /// <param name="train">The train.</param>
 internal AtsP(Train train)
 {
     this.Train = train;
     this.State = States.Disabled;
     this.InitializationCountdown = 0.0;
     this.CompatibilityLimits = new List<CompatibilityLimit>();
     this.CompatibilityLimitPointer = 0;
     this.SignalPattern = new Pattern(this);
     this.CompatibilityTemporaryPattern = new Pattern(this);
     this.CompatibilityPermanentPattern = new Pattern(this);
     List<Pattern> patterns = new List<Pattern>();
     patterns.Add(this.SignalPattern);
     patterns.Add(this.CompatibilityTemporaryPattern);
     patterns.Add(this.CompatibilityPermanentPattern);
     this.Patterns = patterns.ToArray();
 }
Example #5
0
		// --- interface functions ---
		
		/// <summary>Is called when the plugin is loaded.</summary>
		/// <param name="properties">The properties supplied to the plugin on loading.</param>
		/// <returns>Whether the plugin was loaded successfully.</returns>
		public bool Load(LoadProperties properties) {
			properties.Panel = new int[272];
			properties.AISupport = AISupport.Basic;
			this.Train = new Train(properties.Panel, properties.PlaySound);
			try {
				string file = OpenBveApi.Path.CombineFile(properties.TrainFolder, "train.dat");
				if (!this.Train.LoadTrainDatFile(file)) {
					this.Train.AtsSx = new AtsSx(this.Train);
					this.Train.Devices = new Device[] { this.Train.AtsSx };
				}
			} catch {
				this.Train.AtsSx = new AtsSx(this.Train);
				this.Train.Devices = new Device[] { this.Train.AtsSx };
			}
			return true;
		}
Example #6
0
 public Mode_ATO(Train train)
 {
     this.train = train;
 }
Example #7
0
		// --- constructors ---
		
		/// <summary>Creates a new AI.</summary>
		/// <param name="train">The underlying train.</param>
		internal AI(Train train) {
			this.Train = train;
		}
Example #8
0
File: ATP.cs Project: joeyfoo/SgATC
 public ATP(Train train)
 {
     this.train = train;
 }
Example #9
0
 public ModeSelector(Train train)
 {
     this.train = train;
 }
Example #10
0
        // --- constructors ---

        /// <summary>Creates a new AI.</summary>
        /// <param name="train">The underlying train.</param>
        internal AI(Train train)
        {
            this.Train = train;
        }
Example #11
0
 public Interlock(Train train)
 {
     this.train = train;
 }
Example #12
0
 internal AWS(Train train)
 {
     this.Train = train;
 }
Example #13
0
 internal Windscreen(Train train)
 {
     this.Train = train;
 }
Example #14
0
        private bool isForcedBraking  = false; //If the train is actively being braked by motor cutout speed.

        public Mode_RM(Train train)
        {
            this.train = train;
        }
Example #15
0
 internal GearBox(Train train)
 {
     this.Train = train;
 }
Example #16
0
		// --- constructors ---
		
		/// <summary>Creates a new instance of this system.</summary>
		/// <param name="train">The train.</param>
		internal Eb(Train train) {
			this.Train = train;
			this.Counter = 0.0;
		}
Example #17
0
 public Mode_RM(Train train)
 {
     this.train = train;
 }
Example #18
0
        /// <summary>Is called when the plugin is loaded.</summary>
        /// <param name="properties">The properties supplied to the plugin on loading.</param>
        /// <returns>Whether the plugin was loaded successfully.</returns>
        public bool Load(LoadProperties properties)
        {
            properties.Panel = new int[512];
            SoundManager.Initialise(properties.PlaySound, 512);
            MessageManager.Initialise(properties.AddMessage);
            properties.AISupport = AISupport.Basic;
            this.Train           = new Train(properties.Panel);
            //No AI Support
            //properties.AISupport = AISupport.None;

            this.Train = new Train(properties.Panel);
            string configFile         = Path.CombineFile(properties.TrainFolder, "BVEC_Ats.cfg");
            string OS_ATSDLL          = Path.CombineFile(properties.TrainFolder, "OS_ATS1.dll");
            string SZ_ATSDLL          = Path.CombineFile(properties.TrainFolder, "OS_SZ_ATS1.dll");
            string SZ_ATSDLL_2        = Path.CombineFile(properties.TrainFolder, "OS_SZ_Ats2_0.dll");
            string OS_ATSconfigFile   = Path.CombineFile(properties.TrainFolder, "OS_ATS1.cfg");
            string SZ_ATSconfigFile   = Path.CombineFile(properties.TrainFolder, "OS_SZ_ATS1.cfg");
            string SZ_ATS_2configFile = Path.CombineFile(properties.TrainFolder, "OS_SZ_Ats2_0.cfg");
            string ODF_ATSconfigFile  = Path.CombineFile(properties.TrainFolder, "OdakyufanAts.cfg");

            TrainFolder = properties.TrainFolder;
            //Delete error.log from previous run
            if (File.Exists(Path.CombineFile(properties.TrainFolder, "error.log")))
            {
                try
                {
                    File.Delete(Path.CombineFile(properties.TrainFolder, "error.log"));
                }
                catch
                {
                    FolderWriteAccess = false;
                }
            }
            if (File.Exists(configFile))
            {
                //Check for the automatic generator version
                string generatorversion;
                using (var reader = new StreamReader(configFile))
                {
                    //Read in first line
                    generatorversion = reader.ReadLine();
                }
                //If it exists
                try
                {
                    if (generatorversion != null && generatorversion.StartsWith(";GenVersion="))
                    {
                        string versiontext = Regex.Match(generatorversion, @"\d+").Value;
                        int    version     = Int32.Parse(versiontext, NumberStyles.Number, CultureInfo.InvariantCulture);
                        //If we're below the current version, try to upgrade again
                        if (version < 1)
                        {
                            if (File.Exists(OS_ATSDLL) && File.Exists(OS_ATSconfigFile))
                            {
                                try
                                {
                                    string[] Lines = UpgradeOSATS.UpgradeConfigurationFile(OS_ATSconfigFile, properties.TrainFolder);
                                }
                                catch (Exception)
                                {
                                    properties.FailureReason = "An error occured whilst attempting to upgrade the OS_ATS configuration.";
                                    return(false);
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    properties.FailureReason = "Empty configuration file detected.";
                    return(false);
                }

                //Now try loading
                try
                {
                    string[] Lines = File.ReadAllLines(configFile, Encoding.UTF8);
                    this.Train.LoadConfigurationFile(Lines);
                    return(true);
                }
                catch (Exception ex)
                {
                    properties.FailureReason = "Error loading the configuration file: " + ex.Message;
                    return(false);
                }
            }
            if (!File.Exists(configFile) && File.Exists(OS_ATSDLL) && File.Exists(OS_ATSconfigFile))
            {
                //The F92_en is blacklisted due to a custom OS_ATS version
                if (Regex.IsMatch(properties.TrainFolder, @"\\F92_en(\\)?", RegexOptions.IgnoreCase))
                {
                    properties.FailureReason = "The F92_en is not currently a supported train.";
                    try
                    {
                        using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log")))
                        {
                            sw.WriteLine("The F92_en is not currently a supported train");
                        }
                        return(false);
                    }
                    catch
                    {
                        return(false);
                    }
                }
                //If there is no existing BVEC_ATS configuration file, but OS_ATS and the appropriate
                //configuration files exist, then attempt to upgrade the existing file to BVEC_ATS
                try
                {
                    string[] Lines = UpgradeOSATS.UpgradeConfigurationFile(OS_ATSconfigFile, properties.TrainFolder);
                    try
                    {
                        File.WriteAllLines(Path.CombineFile(TrainFolder, "BVEC_ATS.cfg"), Lines);
                    }
                    catch
                    {
                        //Error writing the new configuration file
                    }
                    this.Train.LoadConfigurationFile(Lines);
                    return(true);
                }
                catch (Exception)
                {
                    properties.FailureReason = "Error upgrading the existing OS_ATS configuration.";
                    using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log")))
                    {
                        sw.WriteLine("An existing OS_ATS configuration was found.");
                        sw.WriteLine("However, an error occurred upgrading the existing OS_ATS configuration.");
                    }
                    return(false);
                }
            }
            if (File.Exists(SZ_ATSDLL))
            {
                //We've found an OS_SZ_ATS equipped train
                //Upgrade for this is in alpha
                try
                {
                    string[] Lines = UpgradeOSSZATS.UpgradeConfigurationFile(SZ_ATSconfigFile, properties.TrainFolder);
                    try
                    {
                        File.WriteAllLines(Path.CombineFile(TrainFolder, "BVEC_ATS.cfg"), Lines);
                    }
                    catch
                    {
                        //Error writing the new configuration file
                    }
                    this.Train.LoadConfigurationFile(Lines);
                    return(true);
                }
                catch (Exception)
                {
                    properties.FailureReason = "Error upgrading the existing OS_SZ_ATS configuration.";
                    using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log")))
                    {
                        sw.WriteLine("An existing OS_SZ_ATS configuration was found.");
                        sw.WriteLine("However, an error occurred upgrading the existing OS_SZ_ATS configuration.");
                    }
                    return(false);
                }
            }
            else
            {
                if (File.Exists(SZ_ATSDLL_2))
                {
                    //We've found an OS_SZ_ATS equipped train
                    //Upgrade for this is in alpha
                    try
                    {
                        string[] Lines = UpgradeOSSZATS.UpgradeConfigurationFile(SZ_ATS_2configFile, properties.TrainFolder);
                        try
                        {
                            File.WriteAllLines(Path.CombineFile(TrainFolder, "BVEC_ATS.cfg"), Lines);
                        }
                        catch
                        {
                            //Error writing the new configuration file
                        }
                        this.Train.LoadConfigurationFile(Lines);
                        return(true);
                    }
                    catch (Exception)
                    {
                        properties.FailureReason = "Error upgrading the existing OS_SZ_ATS configuration.";
                        using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log")))
                        {
                            sw.WriteLine("An existing OS_SZ_ATS configuration was found.");
                            sw.WriteLine("However, an error occurred upgrading the existing OS_SZ_ATS configuration.");
                        }
                        return(false);
                    }
                }
                if (File.Exists(ODF_ATSconfigFile))
                {
                    //We've found an OdyakufanATS equipped train
                    //Upgrade for this is in alpha
                    try
                    {
                        File.Copy(ODF_ATSconfigFile, configFile);
                        string[] Lines = File.ReadAllLines(configFile);
                        this.Train.LoadConfigurationFile(Lines);
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        properties.FailureReason = "Error loading the configuration file: " + ex.Message;
                        return(false);
                    }
                }
                else
                {
                    properties.FailureReason = "No supported configuration files exist.";
                    //Write out error.log with details of what it thinks was found and missing
                    using (StreamWriter sw = File.CreateText(Path.CombineFile(properties.TrainFolder, "error.log")))
                    {
                        sw.WriteLine("Plugin location " + Convert.ToString(properties.TrainFolder));
                        if (File.Exists(OS_ATSDLL))
                        {
                            sw.WriteLine("OS_ATS DLL found");
                        }
                        else
                        {
                            sw.WriteLine("No OS_ATS DLL found");
                        }

                        if (File.Exists(OS_ATSconfigFile))
                        {
                            sw.WriteLine("OS_ATS configuration file found");
                        }
                        else
                        {
                            sw.WriteLine("No OS_ATS configuration file found");
                        }
                    }
                    return(false);
                }
            }
        }