internal Brake()
 {
     BrakeType          = BrakeTypes.ElectromagneticStraightAirBrake;
     LocoBrakeType      = LocoBrakeTypes.NotFitted;
     BrakeControlSystem = BrakeControlSystems.None;
     BrakeControlSpeed  = 0.0;
 }
示例#2
0
            internal VehicleSpecs vehicleSpecs()
            {
                BrakeTypes brakeType = (BrakeTypes)Cars[DriverCar].CarBrake.brakeType;
                int        brakeNotches;
                int        powerNotches;
                bool       hasHoldBrake;

                if (brakeType == BrakeTypes.AutomaticAirBrake)
                {
                    brakeNotches = 2;
                    powerNotches = Handles.Power.MaximumNotch;
                    hasHoldBrake = false;
                }
                else
                {
                    brakeNotches = Handles.Brake.MaximumNotch + (Handles.HasHoldBrake ? 1 : 0);
                    powerNotches = Handles.Power.MaximumNotch;
                    hasHoldBrake = Handles.HasHoldBrake;
                }

                bool hasLocoBrake = Handles.HasLocoBrake;
                int  cars         = Cars.Length;

                return(new VehicleSpecs(powerNotches, brakeType, brakeNotches, hasHoldBrake, hasLocoBrake, cars));
            }
示例#3
0
 // --- constructors ---
 /// <summary>Creates a new instance of this class.</summary>
 /// <param name="powerNotches">The number of power notches the train has.</param>
 /// <param name="brakeType">The type of brake the train uses.</param>
 /// <param name="brakeNotches">The number of brake notches the train has, including the hold brake, but excluding the emergency brake.</param>
 /// <param name="hasHoldBrake">Whether the train has a hold brake.</param>
 /// <param name="cars">The number of cars the train has.</param>
 public VehicleSpecs(int powerNotches, BrakeTypes brakeType, int brakeNotches, bool hasHoldBrake, int cars)
 {
     this.MyPowerNotches = powerNotches;
     this.MyBrakeType    = brakeType;
     this.MyBrakeNotches = brakeNotches;
     this.MyHasHoldBrake = hasHoldBrake;
     this.MyCars         = cars;
 }
示例#4
0
			internal Brake() {
				this.BrakeType = BrakeTypes.ElectromagneticStraightAirBrake;
				this.BrakeControlSystem = BrakeControlSystems.None;
				this.BrakeControlSpeed = 0.0;
			}
示例#5
0
        /// <summary>Loads the specified plugin for the specified train.</summary>
        /// <param name="train">The train to attach the plugin to.</param>
        /// <param name="pluginFile">The file to the plugin.</param>
        /// <param name="trainFolder">The train folder.</param>
        /// <returns>Whether the plugin was loaded successfully.</returns>
        private static bool LoadPlugin(TrainManager.Train train, string pluginFile, string trainFolder)
        {
            string pluginTitle = System.IO.Path.GetFileName(pluginFile);

            if (!System.IO.File.Exists(pluginFile))
            {
                Interface.AddMessage(MessageType.Error, true, "The train plugin " + pluginTitle + " could not be found.");
                return(false);
            }

            /*
             * Unload plugin if already loaded.
             * */
            if (train.Plugin != null)
            {
                UnloadPlugin(train);
            }

            /*
             * Prepare initialization data for the plugin.
             * */
            BrakeTypes brakeType = (BrakeTypes)train.Cars[train.DriverCar].CarBrake.brakeType;
            int        brakeNotches;
            int        powerNotches;
            bool       hasHoldBrake;

            if (brakeType == BrakeTypes.AutomaticAirBrake)
            {
                brakeNotches = 2;
                powerNotches = train.Handles.Power.MaximumNotch;
                hasHoldBrake = false;
            }
            else
            {
                brakeNotches = train.Handles.Brake.MaximumNotch + (train.Handles.HasHoldBrake ? 1 : 0);
                powerNotches = train.Handles.Power.MaximumNotch;
                hasHoldBrake = train.Handles.HasHoldBrake;
            }

            bool                hasLocoBrake = train.Handles.HasLocoBrake;
            int                 cars         = train.Cars.Length;
            VehicleSpecs        specs        = new VehicleSpecs(powerNotches, brakeType, brakeNotches, hasHoldBrake, hasLocoBrake, cars);
            InitializationModes mode         = (InitializationModes)Game.TrainStart;

            /*
             * Check if the plugin is a .NET plugin.
             * */
            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFile(pluginFile);
            }
            catch (BadImageFormatException)
            {
                assembly = null;
            }
            catch (Exception ex)
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be loaded due to the following exception: " + ex.Message);
                return(false);
            }
            if (assembly != null)
            {
                Type[] types;
                try
                {
                    types = assembly.GetTypes();
                }
                catch (ReflectionTypeLoadException ex)
                {
                    foreach (Exception e in ex.LoaderExceptions)
                    {
                        Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " raised an exception on loading: " + e.Message);
                    }
                    return(false);
                }
                foreach (Type type in types)
                {
                    if (typeof(IRuntime).IsAssignableFrom(type))
                    {
                        if (type.FullName == null)
                        {
                            //Should never happen, but static code inspection suggests that it's possible....
                            throw new InvalidOperationException();
                        }
                        IRuntime api = assembly.CreateInstance(type.FullName) as IRuntime;
                        train.Plugin = new NetPlugin(pluginFile, trainFolder, api, train);
                        if (train.Plugin.Load(specs, mode))
                        {
                            return(true);
                        }
                        else
                        {
                            train.Plugin = null;
                            return(false);
                        }
                    }
                }
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }

            /*
             * Check if the plugin is a Win32 plugin.
             *
             */
            try
            {
                if (!CheckWin32Header(pluginFile))
                {
                    Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " is of an unsupported binary format and therefore cannot be used with openBVE.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be read due to the following reason: " + ex.Message);
                return(false);
            }
            if (!Program.CurrentlyRunningOnWindows | IntPtr.Size != 4)
            {
                Interface.AddMessage(MessageType.Warning, false, "The train plugin " + pluginTitle + " can only be used on 32-bit Microsoft Windows or compatible.");
                return(false);
            }
            if (Program.CurrentlyRunningOnWindows && !System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\AtsPluginProxy.dll"))
            {
                Interface.AddMessage(MessageType.Warning, false, "AtsPluginProxy.dll is missing or corrupt- Please reinstall.");
                return(false);
            }
            train.Plugin = new Win32Plugin(pluginFile, train);
            if (train.Plugin.Load(specs, mode))
            {
                return(true);
            }
            else
            {
                train.Plugin = null;
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }
        }
示例#6
0
文件: Runtime.cs 项目: sladen/openbve
 // --- constructors ---
 /// <summary>Creates a new instance of this class.</summary>
 /// <param name="powerNotches">The number of power notches the train has.</param>
 /// <param name="brakeType">The type of brake the train uses.</param>
 /// <param name="brakeNotches">The number of brake notches the train has, including the hold brake, but excluding the emergency brake.</param>
 /// <param name="hasHoldBrake">Whether the train has a hold brake.</param>
 /// <param name="cars">The number of cars the train has.</param>
 public VehicleSpecs(int powerNotches, BrakeTypes brakeType, int brakeNotches, bool hasHoldBrake, int cars)
 {
     this.MyPowerNotches = powerNotches;
     this.MyBrakeType = brakeType;
     this.MyBrakeNotches = brakeNotches;
     this.MyHasHoldBrake = hasHoldBrake;
     this.MyCars = cars;
 }
示例#7
0
 internal Brake()
 {
     this.BrakeType          = BrakeTypes.ElectromagneticStraightAirBrake;
     this.BrakeControlSystem = BrakeControlSystems.None;
     this.BrakeControlSpeed  = 0.0;
 }
        /// <summary>Loads the specified plugin for the specified train.</summary>
        /// <param name="train">The train to attach the plugin to.</param>
        /// <param name="pluginFile">The file to the plugin.</param>
        /// <param name="trainFolder">The train folder.</param>
        /// <returns>Whether the plugin was loaded successfully.</returns>
        private static bool LoadPlugin(TrainManager.Train train, string pluginFile, string trainFolder)
        {
            string pluginTitle = System.IO.Path.GetFileName(pluginFile);

            if (!System.IO.File.Exists(pluginFile))
            {
                Interface.AddMessage(Interface.MessageType.Error, true, "The train plugin " + pluginTitle + " could not be found.");
                return(false);
            }

            /*
             * Unload plugin if already loaded.
             * */
            if (train.Plugin != null)
            {
                UnloadPlugin(train);
            }

            /*
             * Prepare initialization data for the plugin.
             * */
            BrakeTypes brakeType = (BrakeTypes)train.Cars[train.DriverCar].Specs.BrakeType;
            int        brakeNotches;
            int        powerNotches;
            bool       hasHoldBrake;

            if (brakeType == BrakeTypes.AutomaticAirBrake)
            {
                brakeNotches = 2;
                powerNotches = train.Specs.MaximumPowerNotch;
                hasHoldBrake = false;
            }
            else
            {
                brakeNotches = train.Specs.MaximumBrakeNotch + (train.Specs.HasHoldBrake ? 1 : 0);
                powerNotches = train.Specs.MaximumPowerNotch;
                hasHoldBrake = train.Specs.HasHoldBrake;
            }
            int                 cars  = train.Cars.Length;
            VehicleSpecs        specs = new VehicleSpecs(powerNotches, brakeType, brakeNotches, hasHoldBrake, cars);
            InitializationModes mode  = (InitializationModes)Game.TrainStart;

            /*
             * Check if the plugin is a .NET plugin.
             * */
            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFile(pluginFile);
            }
            catch
            {
                assembly = null;
            }
            if (assembly != null)
            {
                Type[] types;
                try
                {
                    types = assembly.GetTypes();
                }
                catch (ReflectionTypeLoadException ex)
                {
                    foreach (Exception e in ex.LoaderExceptions)
                    {
                        Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " raised an exception on loading: " + e.Message);
                    }
                    return(false);
                }
                foreach (Type type in types)
                {
                    if (type.IsPublic && (type.Attributes & TypeAttributes.Abstract) == 0)
                    {
                        object   instance = assembly.CreateInstance(type.FullName);
                        IRuntime api      = instance as IRuntime;
                        if (api != null)
                        {
                            train.Plugin = new NetPlugin(pluginFile, trainFolder, api, train);
                            if (train.Plugin.Load(specs, mode))
                            {
                                return(true);
                            }
                            else
                            {
                                train.Plugin = null;
                                return(false);
                            }
                        }
                    }
                }
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }

            /*
             * Check if the plugin is a Win32 plugin.
             * */
            try
            {
                if (!CheckWin32Header(pluginFile))
                {
                    Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " is of an unsupported binary format and therefore cannot be used with openBVE.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " could not be read due to the following reason: " + ex.Message);
                return(false);
            }
            if (Program.CurrentPlatform != Program.Platform.Windows | IntPtr.Size != 4)
            {
                Interface.AddMessage(Interface.MessageType.Warning, false, "The train plugin " + pluginTitle + " can only be used on 32-bit Microsoft Windows.");
                return(false);
            }
            train.Plugin = new LegacyPlugin(pluginFile, train);
            if (train.Plugin.Load(specs, mode))
            {
                return(true);
            }
            else
            {
                train.Plugin = null;
                return(false);
            }
        }