Beispiel #1
0
        /// <summary>
        /// This initializer is called when we are making a new copy of a locomotive already
        /// loaded in memory.  We use this one to speed up loading by eliminating the
        /// need to parse the wag file multiple times.
        /// NOTE:  you must initialize all the same variables as you parsed above
        /// </summary>
        public override void Copy(MSTSWagon copy)
        {
            base.Copy(copy);  // each derived level initializes its own variables

            MSTSDieselLocomotive locoCopy = (MSTSDieselLocomotive)copy;

            EngineRPM                     = locoCopy.EngineRPM;
            IdleRPM                       = locoCopy.IdleRPM;
            MaxRPM                        = locoCopy.MaxRPM;
            MaxRPMChangeRate              = locoCopy.MaxRPMChangeRate;
            MaximumDieselEnginePowerW     = locoCopy.MaximumDieselEnginePowerW;
            PercentChangePerSec           = locoCopy.PercentChangePerSec;
            LocomotiveMaxRailOutputPowerW = locoCopy.LocomotiveMaxRailOutputPowerW;

            EngineRPMderivation = locoCopy.EngineRPMderivation;
            EngineRPMold        = locoCopy.EngineRPMold;

            MaxDieselLevelL = locoCopy.MaxDieselLevelL;
            DieselUsedPerHourAtMaxPowerL = locoCopy.DieselUsedPerHourAtMaxPowerL;
            DieselUsedPerHourAtIdleL     = locoCopy.DieselUsedPerHourAtIdleL;

            DieselFlowLps = 0.0f;
            InitialMassKg = MassKG;

            if (this.CarID.StartsWith("0"))
            {
                DieselLevelL = locoCopy.DieselLevelL;
            }
            else
            {
                DieselLevelL = locoCopy.MaxDieselLevelL;
            }

            if (locoCopy.GearBoxController != null)
            {
                GearBoxController = new MSTSNotchController(locoCopy.GearBoxController);
            }

            DieselEngines = new DieselEngines(locoCopy.DieselEngines, this);
            if (DieselEngines[0].GearBox != null)
            {
                GearBox = DieselEngines[0].GearBox;
            }
            for (int i = 1; i < DieselEngines.Count; i++)
            {
                if (DieselEngines[i].GearBox == null && locoCopy.DieselEngines[i].GearBox != null)
                {
                    DieselEngines[i].GearBox = new GearBox(GearBox, DieselEngines[i]);
                }
            }
            foreach (DieselEngine de in DieselEngines)
            {
                de.Initialize(true);
            }
        }
Beispiel #2
0
        public static TrainCar Load(Simulator simulator, string wagFilePath, bool initialize = true)
        {
            GenericWAGFile wagFile = SharedGenericWAGFileManager.Get(wagFilePath);
            TrainCar       car;

            if (wagFile.OpenRails != null &&
                wagFile.OpenRails.DLL != null)
            {  // wag file specifies an external DLL
                try
                {
                    // TODO search the path list
                    string   wagFolder = Path.GetDirectoryName(wagFilePath);
                    string   dllPath   = FindTrainCarPlugin(wagFolder, wagFile.OpenRails.DLL);
                    Assembly customDLL = Assembly.LoadFrom(dllPath);
                    object[] args      = new object[] { wagFilePath };
                    car = (TrainCar)customDLL.CreateInstance("ORTS.CustomCar", true, BindingFlags.CreateInstance, null, args, null, null);
                    return(car);
                }
                catch (Exception error)
                {
                    Trace.WriteLine(new FileLoadException(wagFile.OpenRails.DLL, error));
                    // on error, fall through and try loading without the custom dll
                }
            }
            if (!wagFile.IsEngine)
            {
                // its an ordinary MSTS wagon
                car = new MSTSWagon(simulator, wagFilePath);
            }
            else
            {
                // its an ordinary MSTS engine of some type.
                if (wagFile.Engine.Type == null)
                {
                    throw new InvalidDataException(wagFilePath + "\r\n\r\nEngine type missing");
                }

                switch (wagFile.Engine.Type.ToLower())
                {
                // TODO complete parsing of proper car types
                case "electric": car = new MSTSElectricLocomotive(simulator, wagFilePath); break;

                case "steam": car = new MSTSSteamLocomotive(simulator, wagFilePath); break;

                case "diesel": car = new MSTSDieselLocomotive(simulator, wagFilePath); break;

                case "control": car = new MSTSControlTrailerCar(simulator, wagFilePath); break;

                default: throw new InvalidDataException(wagFilePath + "\r\n\r\nUnknown engine type: " + wagFile.Engine.Type);
                }
            }

            MSTSWagon wagon = car as MSTSWagon;

            if (car != null)
            {
                wagon.Load();

                if (initialize)
                {
                    wagon.Initialize();
                }
            }

            return(car);
        }