private void AddVehicleRandom()
        {
            for (int i = 0; i < 4; ++i)
            {
                if (RandomSpawnNow())
                {
                    Driver       driver       = WorldDrivers.GetRandomDriver();
                    VehicleSpecs vehicleSpecs = VehicleModels.GetRandomCar();
                    foreach (Junction junction in Junctions)
                    {
                        junction.Simulation.Roads[i].LeftLane.AddVehicleManual(driver, vehicleSpecs);
                    }
                }

                if (RandomSpawnNow())
                {
                    Driver       driver       = WorldDrivers.GetRandomDriver();
                    VehicleSpecs vehicleSpecs = VehicleModels.GetRandomCar();
                    foreach (Junction junction in Junctions)
                    {
                        junction.Simulation.Roads[i].RightLane.AddVehicleManual(driver, vehicleSpecs);
                    }
                }
            }
        }
Example #2
0
 /// <summary>車両読み込み時に呼び出されます。</summary>
 /// <param name="specs">車両諸元</param>
 public void SetVehicleSpecs(VehicleSpecs specs)
 {
     foreach (IRuntime plugin in plugins_)
     {
         plugin.SetVehicleSpecs(specs);
     }
 }
Example #3
0
 public VehicleType(int bookValue, int millage, VehicleSpecs vehicleSpecs, VehicleColor vehicleColor, ServiceHistory serviceHistory, string vehicleSeries, int vehicleYearProduced)
 {
     BookValue           = bookValue;
     Millage             = millage;
     VehicleSpecs        = vehicleSpecs;
     VehicleColor        = vehicleColor;
     ServiceHistory      = serviceHistory;
     VehicleSeries       = vehicleSeries;
     VehicleYearProduced = vehicleYearProduced;
 }
Example #4
0
 public void SetVehicleSpecs(VehicleSpecs specs)
 {
     ATSPlugin.Cpp.ATS_VEHICLESPEC vehicleSpec;
     vehicleSpec.AtsNotch     = specs.AtsNotch;
     vehicleSpec.B67Notch     = specs.B67Notch;
     vehicleSpec.BrakeNotches = specs.BrakeNotches;
     vehicleSpec.Cars         = specs.Cars;
     vehicleSpec.PowerNotches = specs.PowerNotches;
     ATSPlugin.Cpp.SetVehicleSpec(vehicleSpec);
 }
        private void addVehicleWESTRToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Driver       driver       = WorldDrivers.GetRandomDriver();
            VehicleSpecs vehicleSpecs = VehicleModels.GetRandomCar();

            foreach (Junction junction in Junctions)
            {
                junction.Simulation.Roads[3].RightLane.AddVehicleManual(driver, vehicleSpecs);
            }
        }
        private void mstrip_addWest_Click(object sender, EventArgs e)
        {
            Driver       driver       = WorldDrivers.GetRandomDriver();
            VehicleSpecs vehicleSpecs = VehicleModels.GetRandomCar();

            foreach (Junction junction in Junctions)
            {
                junction.Simulation.Roads[3].LeftLane.AddVehicleManual(driver, vehicleSpecs);
            }
        }
Example #7
0
        // --- functions ---
        internal override bool Load(VehicleSpecs specs, InitializationModes mode)
        {
            LoadProperties properties = new LoadProperties(this.PluginFolder, this.TrainFolder, this.PlaySound, this.PlaySound, this.AddInterfaceMessage, this.AddScore);
            bool           success;

            try
            {
                success         = this.Api.Load(properties);
                base.SupportsAI = properties.AISupport == AISupport.Basic;
            }
            catch (Exception ex)
            {
                if (ex is ThreadStateException)
                {
                    //TTC plugin, broken when multi-threading is used
                    success = false;
                    properties.FailureReason = "This plugin does not function correctly with current versions of openBVE. Please ask the plugin developer to fix this.";
                }
                else
                {
                    success = false;
                    properties.FailureReason = ex.Message;
                }
            }
            if (success)
            {
                base.Panel = properties.Panel ?? new int[] { };
#if !DEBUG
                try {
#endif
                Api.SetVehicleSpecs(specs);
                Api.Initialize(mode);
#if !DEBUG
            }
            catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
#endif
                UpdatePower();
                UpdateBrake();
                UpdateReverser();
                return(true);
            }
            else if (properties.FailureReason != null)
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for the following reason: " + properties.FailureReason);
                return(false);
            }
            else
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for an unspecified reason.");
                return(false);
            }
        }
Example #8
0
 public void AddVehicleManual(Driver driver, VehicleSpecs vehicleSpecs)
 {
     if (IsFreeToSpawn())
     {
         Vehicles.Add(new Vehicle(driver, vehicleSpecs, SpawnBound, StopBound, new Rectangle2D(LaneBound), new Point2D(RandomDirectionLanePoint())));
     }
     else
     {
         errorLog.Add("VEHICLE SPAWN FAILED [EntryPointFullException]");
     }
 }
Example #9
0
 // --- constructors ---
 /// <summary>Creates a new train without any devices installed.</summary>
 /// <param name="panel">The array of panel variables.</param>
 /// <param name="playSound">The delegate to play sounds.</param>
 internal Train(int[] panel, PlaySoundDelegate playSound)
 {
     this.PluginInitializing = false;
     this.Specs   = new VehicleSpecs(0, BrakeTypes.ElectromagneticStraightAirBrake, 0, false, 0);
     this.State   = new VehicleState(0.0, new Speed(0.0), 0.0, 0.0, 0.0, 0.0, 0.0);
     this.Handles = new ReadOnlyHandles(new Handles(0, 0, 0, false));
     this.Doors   = DoorStates.None;
     this.Panel   = panel;
     this.Sounds  = new Sounds(playSound);
     this.AI      = new AI(this);
 }
Example #10
0
 public int VehicleSpec(int bookvalue, VehicleSpecs vehicleSpecs)
 {
     if (vehicleSpecs == VehicleSpecs.High)
     {
         bookvalue += (bookvalue / fullPercentage) * (int)VehicleSpecs.High;
     }
     else if (vehicleSpecs == VehicleSpecs.Mediam)
     {
         bookvalue += (bookvalue / fullPercentage) * (int)VehicleSpecs.Mediam;
     }
     return(bookvalue);
 }
 public static int VehicleSpec(int Bookvalue, VehicleSpecs vehicleSpecs)
 {
     if (vehicleSpecs == VehicleSpecs.High)
     {
         VehicleSpecAmount = (Bookvalue / fullPercentage) * (int)VehicleSpecs.High;
     }
     else if (vehicleSpecs == VehicleSpecs.Mediam)
     {
         VehicleSpecAmount = (Bookvalue / fullPercentage) * (int)VehicleSpecs.Mediam;
     }
     Console.WriteLine(VehicleSpecAmount);
     return(VehicleSpecAmount);
 }
Example #12
0
        // --- functions ---
        internal override bool Load(VehicleSpecs specs, InitializationModes mode)
        {
            LoadProperties properties = new LoadProperties(this.PluginFolder, this.TrainFolder, this.PlaySound, this.PlaySound, this.AddInterfaceMessage, this.AddScore);
            bool           success;

                        #if !DEBUG
            try {
                                #endif
            success         = this.Api.Load(properties);
            base.SupportsAI = properties.AISupport == AISupport.Basic;
                                #if !DEBUG
        }
        catch (Exception ex) {
            base.LastException = ex;
            throw;
        }
                        #endif
            if (success)
            {
                base.Panel = properties.Panel ?? new int[] { };
                                #if !DEBUG
                try {
                                        #endif
                Api.SetVehicleSpecs(specs);
                Api.Initialize(mode);
                                        #if !DEBUG
            }
            catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
                                #endif
                UpdatePower();
                UpdateBrake();
                UpdateReverser();
                return(true);
            }
            else if (properties.FailureReason != null)
            {
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for the following reason: " + properties.FailureReason);
                return(false);
            }
            else
            {
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + base.PluginTitle + " failed to load for an unspecified reason.");
                return(false);
            }
        }
Example #13
0
 public override bool Load(VehicleSpecs specs, InitializationModes mode)
 {
     if (externalCrashed)
     {
         //Most likely the plugin proxy app failed to launch or something
         return(false);
     }
     if (pipeProxy.Load(specs, mode))
     {
         UpdatePower();
         UpdateBrake();
         UpdateReverser();
         return(true);
     }
     return(false);
 }
Example #14
0
 // --- コンストラクタ ---
 /// <summary>新しいインスタンスを作成する</summary>
 /// <param name="panel">パネルに渡す値</param>
 /// <param name="playSound">サウンドを再生するためのデリゲート</param>
 internal Train(int[] panel, PlaySoundDelegate playSound)
 {
     this.PluginInitializing = false;
     this.Specs   = new VehicleSpecs(0, BrakeTypes.ElectromagneticStraightAirBrake, 0, false, 0);
     this.State   = new VehicleState(0.0, new Speed(0.0), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
     this.Handles = new ReadOnlyHandles(new Handles(0, 0, 0, false));
     this.Doors   = DoorStates.None;
     this.Panel   = panel;
     this.Sounds  = new Sounds(playSound);
     this.Accel   = new Accel();
     this.Atc     = new Atc(this);
     this.AtsP    = new AtsP(this);
     this.Wiper   = new Wiper(this);
     this.Sub     = new Sub(this);
     this.Devices = new Device[] { this.Accel, this.Atc, this.AtsP, this.Wiper, this.Sub };
 }
        private (VehicleManufacturingInfo, VehicleLocation, VehiclePurchaseInfo, VehicleSpecs, VehicleLicenseInfo) CreateVehicleValueObjects(VehicleDto vehicleDto)
        {
            var manufacturingInfoDto = vehicleDto.VehicleManufacturingInfo;
            VehicleManufacturingInfo vehicleManufacturingInfo = null;

            if (manufacturingInfoDto != null)
            {
                vehicleManufacturingInfo = new VehicleManufacturingInfo(manufacturingInfoDto.ModelId, manufacturingInfoDto.Year, manufacturingInfoDto.ChassisNo);
            }

            var             locationInfoDto = vehicleDto.LocationInfo;
            VehicleLocation vehicleLocation = null;

            if (locationInfoDto != null)
            {
                vehicleLocation = new VehicleLocation(locationInfoDto.CurrentLocationId);
            }

            var purchaseInfoDto = vehicleDto.PurchaseInfo;
            VehiclePurchaseInfo vehiclePurchaseInfo = null;

            if (purchaseInfoDto != null)
            {
                vehiclePurchaseInfo = VehiclePurchaseInfo.CreateVehiclePurchaseInfo(purchaseInfoDto.VendorId, purchaseInfoDto.Date, purchaseInfoDto.Price);
            }

            var          spexDto     = vehicleDto.Specs;
            VehicleSpecs vehicleSpex = null;

            if (spexDto != null)
            {
                vehicleSpex = VehicleSpecs.CreateVehicleSpex(spexDto.ColorId, spexDto.TrimLevelId,
                                                             spexDto.FuelTypeId, spexDto.FuelTankSize, spexDto.EngineSize);
            }

            var licenseInfoDto = vehicleDto.VehicleLicenseInfo;
            VehicleLicenseInfo vehicleLicenseInfo = null;

            if (licenseInfoDto != null)
            {
                vehicleLicenseInfo = VehicleLicenseInfo.Create(licenseInfoDto.LicenseTypeId, licenseInfoDto.UsageTypeId,
                                                               licenseInfoDto.PlateNo, licenseInfoDto.Number, licenseInfoDto.ExpiryDate);
            }

            return(vehicleManufacturingInfo, vehicleLocation, vehiclePurchaseInfo, vehicleSpex, vehicleLicenseInfo);
        }
Example #16
0
        public bool Load(VehicleSpecs specs, InitializationModes mode)
        {
            int result;

            try
            {
                result = Win32LoadDLL(this.PluginFile, this.PluginFile);
            }
            catch (Exception ex)
            {
                Callback.ReportError("Error loading Win32 plugin: " + ex);
                throw;
            }

            if (result == 0)
            {
                int    errorCode    = Marshal.GetLastWin32Error();
                string errorMessage = new Win32Exception(errorCode).Message;
                Callback.ReportError($"Error loading Win32 plugin: {errorMessage} (0x{errorCode:x})");
                return(false);
            }

            try
            {
                Win32Load();
            }
            catch (Exception ex)
            {
                Callback.ReportError("Error loading Win32 plugin: " + ex);
                return(false);
            }

            int version;

            try
            {
                version = Win32GetPluginVersion();
            }
            catch (Exception ex)
            {
                Callback.ReportError("Error loading Win32 plugin: " + ex);
                return(false);
            }

            if (version == 0 && System.IO.Path.GetFileName(PluginFile).ToLowerInvariant() != "ats2.dll" || version != 131072)
            {
                Callback.ReportError("Win32 plugin " + PluginFile + " is of an unsupported version.");
                try
                {
                    Win32Dispose();
                }
                catch
                {
                    return(false);
                }

                Win32UnloadDLL();
                return(false);
            }

            try
            {
                Win32VehicleSpec win32Spec;
                win32Spec.BrakeNotches = specs.BrakeNotches;
                win32Spec.PowerNotches = specs.PowerNotches;
                win32Spec.AtsNotch     = specs.AtsNotch;
                win32Spec.B67Notch     = specs.B67Notch;
                win32Spec.Cars         = specs.Cars;
                Win32SetVehicleSpec(ref win32Spec.BrakeNotches);
            }
            catch (Exception ex)
            {
                Callback.ReportError("Error loading Win32 plugin: " + ex);
                return(false);
            }

            try
            {
                Console.WriteLine(@"Initializing in mode: " + mode);
                Win32Initialize((int)mode);
            }
            catch (Exception ex)
            {
                Callback.ReportError("Error loading Win32 plugin: " + ex);
                return(false);
            }

            Console.WriteLine(@"Plugin loaded successfully.");
            if (PanelHandle.IsAllocated)
            {
                PanelHandle.Free();
            }
            if (SoundHandle.IsAllocated)
            {
                SoundHandle.Free();
            }
            PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
            SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
            return(true);
        }
Example #17
0
        // --- functions ---
        internal override bool Load(VehicleSpecs specs, InitializationModes mode)
        {
            int  result;
            bool retry = true;

retryLoad:
            try {
                result = Win32LoadDLL(this.PluginFile, this.PluginFile);
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            if (result == 0)
            {
                if (retry)
                {
                    /*
                     * Win32 plugin loading is unreliable on some systems
                     * Unable to reproduce this, but let's try a sleep & single retry attempt
                     */
                    Thread.Sleep(100);
                    retry = false;
                    goto retryLoad;
                }
                int    errorCode    = Marshal.GetLastWin32Error();
                string errorMessage = new Win32Exception(errorCode).Message;
                Interface.AddMessage(MessageType.Error, true,
                                     String.Format("Error loading Win32 plugin: {0} (0x{1})", errorMessage, errorCode.ToString("x")));
                return(false);
            }
            try {
                Win32Load();
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            int version;

            try {
                version = Win32GetPluginVersion();
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            if (version != 131072)
            {
                Interface.AddMessage(MessageType.Error, false, "The train plugin " + base.PluginTitle + " is of an unsupported version.");
                try {
                    Win32Dispose();
                } catch (Exception ex) {
                    base.LastException = ex;
                    throw;
                }
                Win32UnloadDLL();
                return(false);
            }
            try {
                Win32VehicleSpec win32Spec;
                win32Spec.BrakeNotches = specs.BrakeNotches;
                win32Spec.PowerNotches = specs.PowerNotches;
                win32Spec.AtsNotch     = specs.AtsNotch;
                win32Spec.B67Notch     = specs.B67Notch;
                win32Spec.Cars         = specs.Cars;
                Win32SetVehicleSpec(ref win32Spec.BrakeNotches);
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            try {
                Win32Initialize((int)mode);
            } catch (Exception ex) {
                base.LastException = ex;
                throw;
            }
            UpdatePower();
            UpdateBrake();
            UpdateReverser();
            if (PanelHandle.IsAllocated)
            {
                PanelHandle.Free();
            }
            if (SoundHandle.IsAllocated)
            {
                SoundHandle.Free();
            }
            PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
            SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
            return(true);
        }
Example #18
0
 /// <summary>車両読み込み時に呼び出される関数</summary>
 /// <param name="specs">車両諸元</param>
 public void SetVehicleSpecs(VehicleSpecs specs)
 {
     this.Train.Specs = specs;
 }
Example #19
0
 public void SetSpecs(VehicleSpecs vehicleSpex)
 {
     Specs = vehicleSpex;
 }
Example #20
0
        public static async Task <Vehicle> CreateVehicle(int branchId, int fuel, int?odometer,
                                                         VehicleManufacturingInfo manufacturingInfo, VehiclePurchaseInfo purchaseInfo,
                                                         VehicleLocation locationInfo, VehicleSpecs vehicleSpex)
        {
            var vehicle = new Vehicle();

            vehicle.SetBasicData(branchId, fuel);
            vehicle.SetLocationInfo(locationInfo);
            vehicle.SetSpecs(vehicleSpex);
            vehicle.SetPurchaseInfo(purchaseInfo);
            vehicle.MarkVehicleAsReady();
            vehicle.Odometer = odometer;
            return(vehicle);
        }
Example #21
0
        public void CarInput()
        {
            Console.WriteLine("What is your BookValue?");
            UserInputBookValue = int.Parse(Console.ReadLine());

            Console.WriteLine("what is the Millage on the car?");
            UserInputMillage = int.Parse(Console.ReadLine());

            Console.WriteLine("What is the Vehicle Spec? \nA) High \nB) Mediam \nC) Low");
            UserInputVehicleSpec = Console.ReadLine();
            if (UserInputVehicleSpec == "A" || UserInputVehicleSpec == "a")
            {
                VehicleSpecs = VehicleSpecs.High;
            }
            else if (UserInputVehicleSpec == "B" || UserInputVehicleSpec == "b")
            {
                VehicleSpecs = VehicleSpecs.Mediam;
            }
            else if (UserInputVehicleSpec == "C" || UserInputVehicleSpec == "c")
            {
                VehicleSpecs = VehicleSpecs.Low;
            }
            else
            {
                Console.WriteLine("Invalid Input");
            }

            Console.WriteLine("What Color is the Vehicle? \nA) Flat \nB) Metalic");
            UserInputColor = Console.ReadLine();
            if (UserInputColor == "A" || UserInputColor == "a")
            {
                VehicleColor = VehicleColor.Flat;
            }
            else if (UserInputColor == "B" || UserInputColor == "b")
            {
                VehicleColor = VehicleColor.Metalic;
            }
            else
            {
                Console.WriteLine("Invalid Input");
            }

            Console.WriteLine("What is the service history on the car? \nA) Full Service History \nB) Part Service History \nC) No Service History");
            UserInputServiceHistory = Console.ReadLine();
            if (UserInputServiceHistory == "A" || UserInputServiceHistory == "a")
            {
                ServiceHistory = ServiceHistory.FullServiceHistory;
            }
            else if (UserInputServiceHistory == "B" || UserInputServiceHistory == "b")
            {
                ServiceHistory = ServiceHistory.HalfServiceHistory;
            }
            else if (UserInputServiceHistory == "C" || UserInputServiceHistory == "c")
            {
                ServiceHistory = ServiceHistory.NoServiceHistory;
            }
            else
            {
                Console.WriteLine("Invalid Input");
            }

            Console.WriteLine("What is the vehicle Model?");
            UserInputVehicleModel = Console.ReadLine();

            Console.WriteLine("What year was the vehicle Produced?");
            UserInputVehicleYearProduced = int.Parse(Console.ReadLine());
            if (UserInputVehicleYearProduced < 1885 || UserInputVehicleYearProduced > 2020)
            {
                Console.WriteLine("No Cars where produced in this Year" + UserInputVehicleYearProduced);
            }


            Cars car = new Cars();

            car.BookValue           = UserInputBookValue;
            car.Millage             = UserInputMillage;
            car.VehicleSpecs        = VehicleSpecs;
            car.VehicleColor        = VehicleColor;
            car.ServiceHistory      = ServiceHistory;
            car.VehicleSeries       = UserInputVehicleModel;
            car.VehicleYearProduced = UserInputVehicleYearProduced;
            car.Sunroof             = true;

            CarLogic.cars.Add(car);
            Console.WriteLine(car);
        }
Example #22
0
 public void SetVehicleSpecs(VehicleSpecs specs)
 {
 }
Example #23
0
 // --- functions ---
 /// <summary>Called to load and initialize the plugin.</summary>
 /// <param name="specs">The train specifications.</param>
 /// <param name="mode">The initialization mode of the train.</param>
 /// <returns>Whether loading the plugin was successful.</returns>
 internal abstract bool Load(VehicleSpecs specs, InitializationModes mode);
Example #24
0
 // --- functions ---
 /// <summary>Called to load and initialize the plugin.</summary>
 /// <param name="specs">The train specifications.</param>
 /// <param name="mode">The initialization mode of the train.</param>
 /// <returns>Whether loading the plugin was successful.</returns>
 public abstract bool Load(VehicleSpecs specs, InitializationModes mode);
        // --- functions ---
        internal override bool Load(VehicleSpecs specs, InitializationModes mode)
        {
            int result;

            try
            {
                result = Win32LoadDLL(this.PluginFile, this.PluginFile);
            }
            catch (Exception ex)
            {
                base.LastException = ex;
                throw;
            }
            if (result == 0)
            {
                return(false);
            }
            try
            {
                Win32Load();
            }
            catch (Exception ex)
            {
                base.LastException = ex;
                throw;
            }
            int version;

            try
            {
                version = Win32GetPluginVersion();
            }
            catch (Exception ex)
            {
                base.LastException = ex;
                throw;
            }
            if (version != 131072)
            {
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + base.PluginTitle + " is of an unsupported version.");
                try
                {
                    Win32Dispose();
                }
                catch (Exception ex)
                {
                    base.LastException = ex;
                    throw;
                }
                Win32UnloadDLL();
                return(false);
            }
            try
            {
                Win32VehicleSpec win32Spec;
                win32Spec.BrakeNotches = specs.BrakeNotches;
                win32Spec.PowerNotches = specs.PowerNotches;
                win32Spec.AtsNotch     = specs.AtsNotch;
                win32Spec.B67Notch     = specs.B67Notch;
                win32Spec.Cars         = specs.Cars;
                Win32SetVehicleSpec(ref win32Spec.BrakeNotches);
            }
            catch (Exception ex)
            {
                base.LastException = ex;
                throw;
            }
            try
            {
                Win32Initialize((int)mode);
            }
            catch (Exception ex)
            {
                base.LastException = ex;
                throw;
            }
            UpdatePower();
            UpdateBrake();
            UpdateReverser();
            if (PanelHandle.IsAllocated)
            {
                PanelHandle.Free();
            }
            if (SoundHandle.IsAllocated)
            {
                SoundHandle.Free();
            }
            PanelHandle = GCHandle.Alloc(Panel, GCHandleType.Pinned);
            SoundHandle = GCHandle.Alloc(Sound, GCHandleType.Pinned);
            return(true);
        }
Example #26
0
 public Suv(int bookValue, int millage, VehicleSpecs vehicleSpecs, VehicleColor vehicleColor, ServiceHistory serviceHistory, string vehicleSeries, int vehicleYearProduced) : base(bookValue, millage, vehicleSpecs, vehicleColor, serviceHistory, vehicleSeries, vehicleYearProduced)
 {
 }
Example #27
0
 public void SetVehicleSpecs(VehicleSpecs _p1)
 {
     VSpec = _p1;
 }
Example #28
0
 /// <summary>
 /// A function notifying the plugin about the train's specifications.
 /// </summary>
 /// <param name="specs">The train's specifications.</param>
 public void SetVehicleSpecs(VehicleSpecs specs)
 {
     TrainSpecs = specs;
     ConfigureMappings();
 }
Example #29
0
 public Cars(int bookValue, int millage, VehicleSpecs vehicleSpecs, VehicleColor vehicleColor, ServiceHistory serviceHistory, string vehicleSeries, int vehicleYearProduced, bool sunroof) : base(bookValue, millage, vehicleSpecs, vehicleColor, serviceHistory, vehicleSeries, vehicleYearProduced)
 {
     Sunroof = sunroof;
 }
Example #30
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);
            }
        }