Пример #1
0
        // Physics update
        public void FixedUpdate()
        {
            if (anyPersistent)
            {
                // Universal time
                double UT = Planetarium.GetUniversalTime();

                // Force attitude to specified frame & hold throttle
                if (FlightGlobals.fetch != null && IsLocked)
                {
                    // Set attitude
                    Control control = controls.Lookup(UT);
                    vessel.SetRotation(control.frame.qfn(vessel.orbit, UT, control.angles));
                    // Set throttle
                    if (isEnabled)
                    {
                        // Realtime mode
                        if (!vessel.packed)
                        {
                            vessel.ctrlState.mainThrottle = control.throttle;
                        }
                        // Warp mode
                        else
                        {
                            foreach (var pe in persistentEngines)
                            {
                                pe.ThrottlePersistent = control.throttle;
                                pe.ThrustPersistent   = control.throttle * pe.engine.maxThrust;
                                pe.IspPersistent      = pe.engine.atmosphereCurve.Evaluate(0);
                            }
                        }
                    }
                    // Are sails in use?
                    foreach (var s in solarSails)
                    {
                        // Control's "sailon" changes relative to sail's "IsEnabled"
                        if (control.sailon != s.IsEnabled)
                        {
                            if (control.sailon)   // Sail on
                            {
                                s.DeploySail();
                            }
                            else   // Sail not on
                            {
                                s.RetractSail();
                            }
                        }
                    }
                }
            }

            // Update preview trajectory if it exists
            if (anyPersistent)
            {
                controls.preview.Update(vessel);
            }
        }
        // Physics update
        public void FixedUpdate()
        {
            if (anyPersistent)
            {
                // Universal time
                double UT = Planetarium.GetUniversalTime();

                // Force attitude to specified frame & hold throttle
                if (FlightGlobals.fetch != null && IsLocked)
                {
                    // Set attitude
                    Control control = controls.Lookup(UT);
                    vessel.SetRotation(control.frame.qfn(vessel.orbit, UT, control.angles));
                    // Set throttle
                    if (isEnabled)
                    {
                        // Realtime mode
                        if (!vessel.packed)
                        {
                            vessel.ctrlState.mainThrottle = control.throttle;
                        }
                        // Warp mode
                        else
                        {
                            // Get the needed attributes via reflection.
                            var ThrottlePersistant = typeof(ModuleEnginesWarp).GetField("_throttlePersistent", BindingFlags.NonPublic | BindingFlags.Instance);
                            var ThrustPersistant   = typeof(ModuleEnginesWarp).GetField("_thrustPersistent", BindingFlags.NonPublic | BindingFlags.Instance);
                            var IspPersistant      = typeof(ModuleEnginesWarp).GetField("_throttlePersistent", BindingFlags.NonPublic | BindingFlags.Instance);
                            // public float maxThrust; inherited from ModuleEngines
                            var MaxThrust = typeof(ModuleEngines).GetField("maxThrust", BindingFlags.NonPublic | BindingFlags.Instance);
                            foreach (var pe in persistentEngines)
                            {
                                // Original code:
                                //pe.ThrottlePersistent = control.throttle;
                                //pe.ThrustPersistent = control.throttle * pe.engine.maxThrust;
                                //pe.IspPersistent = pe.engine.atmosphereCurve.Evaluate(0);
                                ThrottlePersistant.SetValue(pe, control.throttle);
                                var _maxthrust = (float)MaxThrust.GetValue(pe);
                                ThrustPersistant.SetValue(pe, control.throttle * _maxthrust);
                                IspPersistant.SetValue(pe, pe.atmosphereCurve.Evaluate(0));
                            }
                        }
                    }
                    // Are sails in use?
                    foreach (var s in solarSails)
                    {
                        // Control's "sailon" changes relative to sail's "IsEnabled"
                        if (control.sailon != s.IsEnabled)
                        {
                            if (control.sailon)               // Sail on
                            {
                                s.DeploySail();
                            }
                            else               // Sail not on
                            {
                                s.RetractSail();
                            }
                        }
                    }
                }
            }

            // Update preview trajectory if it exists
            if (anyPersistent)
            {
                controls.preview.Update(vessel);
            }
        }