Example #1
0
 static void enable_engine(EngineWrapper e)
 {
     if (!e.engine.EngineIgnited)
     {
         e.engine.Activate();
     }
 }
Example #2
0
 static void disable_engine(EngineWrapper e)
 {
     if (e.engine.EngineIgnited)
     {
         e.engine.Shutdown();
     }
 }
Example #3
0
 public void Add(EngineWrapper e)
 {
     Engines.Add(e);
     MaxThrust   = MaxThrust + VSL.LocalDir(e.defThrustDir) * e.engine.maxThrust;
     MaxMassFlow = MaxMassFlow + e.engine.maxFuelFlow;
     Dir         = MaxThrust.normalized;
 }
Example #4
0
 void process_active_engine(EngineWrapper e)
 {
     e.throttle = e.VSF = e.thrustMod = 1;
     e.UpdateThrustInfo();
     e.InitLimits();
     e.InitTorque(EditorLogic.RootPart.transform, CoM,
                  EngineOptimizer.C.TorqueRatioFactor);
     e.UpdateCurrentTorque(1);
 }
Example #5
0
 static void collect_fuels(EngineWrapper e, Dictionary <int, PartResourceDefinition> db)
 {
     e.engine.GetConsumedResources()
     .ForEach(r => { if (!db.ContainsKey(r.id))
                     {
                         db.Add(r.id, r);
                     }
              });
 }
 //FIXME: generates Number overflow on flight scene load
 public EngineID(EngineWrapper e)
 {
     if(e.part == null || e.engine == null) return;
     var rT  = e.part.localRoot == null? e.part.transform : e.part.localRoot.transform;
     var to  = rT.InverseTransformPoint(e.part.partTransform.position);
     var td  = rT.InverseTransformDirection(e.part.partTransform.forward);
     var ids = string.Format("{0} {1} {2:F1} {3:F1} {4:F1} {5:F1} {6:F1} {7:F1}",
                             e.part.partInfo.name, e.engine.engineID, to.x, to.y, to.z, td.x, td.y, td.z);
     id = (uint)ids.GetHashCode();
     //			Utils.Log("{}: {}", ids, id);//debug
 }
Example #7
0
 public void Update(EngineWrapper e, bool with_On = false)
 {
     Limit = e.thrustLimit;
     Role  = e.Role;
     if (with_On)
     {
         On = e.engine.EngineIgnited;
     }
     else
     {
         Changed |= On != e.engine.EngineIgnited;
     }
 }
Example #8
0
        //FIXME: generates Number overflow on flight scene load
        public EngineID(EngineWrapper e)
        {
            if (e.part == null || e.engine == null)
            {
                return;
            }
            var rT  = e.part.localRoot == null ? e.part.transform : e.part.localRoot.transform;
            var to  = rT.InverseTransformPoint(e.part.partTransform.position);
            var td  = rT.InverseTransformDirection(e.part.partTransform.forward);
            var ids = string.Format("{0} {1} {2:F1} {3:F1} {4:F1} {5:F1} {6:F1} {7:F1}",
                                    e.part.partInfo.name, e.engine.engineID, to.x, to.y, to.z, td.x, td.y, td.z);

            id = (uint)ids.GetHashCode();
            //            Utils.Log("{}: {}", ids, id);//debug
        }
 static void set_engine_limit(EngineWrapper e, float errorF, float max_lim)
 {
     if (e.Role == TCARole.MANEUVER || e.Role == TCARole.MANUAL)
     {
         return;
     }
     if (e.Role == TCARole.BALANCE || e.Role == TCARole.UNBALANCE)
     {
         e.preset_limit = errorF;
     }
     else
     {
         e.preset_limit = Mathf.Lerp(errorF, max_lim, e.torqueRatio);
     }
 }
 static void set_engine_limit(EngineWrapper e, float errorF)
 {
     if (e.Role == TCARole.MANEUVER || e.Role == TCARole.MANUAL)
     {
         return;
     }
     if (e.Role == TCARole.BALANCE || e.Role == TCARole.UNBALANCE)
     {
         e.PresetLimit(errorF);
     }
     else
     {
         e.PresetLimit(Mathf.Lerp(errorF, 1, e.torqueRatio));
     }
 }
Example #11
0
        public EngineConfig GetConfig(EngineWrapper e)
        {
            EngineConfig c;

            if (e.Group > 0)
            {
                if (!Groups.TryGetValue(e.Group, out c))
                {
                    return(null);
                }
            }
            else if (!Single.TryGetValue(e.ID, out c))
            {
                return(null);
            }
            return(c);
        }
        bool UpdateEngines(ShipConstruct ship)
        {
            Engines.Clear();
            var thrust = Vector3.zero;

            Mass = DryMass = MinTWR = MaxTWR = 0f;
            ship.GetShipMass(out DryMass, out Mass);
            Mass += DryMass;
            if (TCAScenario.HasTCA && ship.Parts != null)
            {
                (from p in ship.Parts where p.Modules != null
                 from m in p.Modules.GetModules <ModuleEngines>() select m)
                .ForEach(m =>
                {
                    var e = new EngineWrapper(m);
                    Engines.Add(e);
                    e.UpdateThrustInfo();
                    if (CFG != null)
                    {
                        var ecfg = CFG.ActiveProfile.GetConfig(e);
                        if (ecfg == null || ecfg.On)
                        {
                            thrust += e.wThrustDir * e.thrustInfo.thrust;
                        }
                    }
                });
                var T = thrust.magnitude / Utils.G0;
                MinTWR = T / Mass;
                MaxTWR = T / DryMass;
            }
            var ret = Engines.Count > 0;

            if (!ret)
            {
                Reset();
            }
            return(ret);
        }
Example #13
0
 public void Apply(EngineWrapper e)
 {
     if (e == null || e.info == null)
     {
         return;
     }
     e.SetRole(Role);
     if (HighLogic.LoadedSceneIsFlight)
     {
         if (On && !e.engine.EngineIgnited)
         {
             e.engine.Activate();
         }
         else if (!On && e.engine.EngineIgnited)
         {
             e.engine.Shutdown();
         }
     }
     if (Role == TCARole.MANUAL)
     {
         e.forceThrustPercentage(Limit * 100);
     }
     Changed = false;
 }
        private List<EngineWrapper> CountEngines()
        {
            vessel = FlightGlobals.ActiveVessel;
            List<EngineWrapper> engines = new List<EngineWrapper>();

            foreach (Part p in vessel.Parts)
            {
                EngineWrapper engine = null;
                foreach (PartModule module in p.Modules) {
                    if(module.moduleName == "ModuleEngines"){
                        engine = new EngineWrapper((ModuleEngines) module);
                        if (engine.isEnabled && !engine.throttleLocked){
                            engines.Add(engine);
                        }
                    } else {
                        if (module.moduleName == "ModuleEnginesFX")
                        {
                            engine = new EngineWrapper((ModuleEnginesFX) module);
                            if (engine.isEnabled && !engine.throttleLocked){
                                engines.Add(engine);
                            }
                        }
                    }
                }
            }
            return engines;
        }
Example #15
0
 public EngineConfig(EngineWrapper e)
 {
     Name = e.Group > 0? ("Group " + e.Group) : e.name; Update(e, true);
 }
Example #16
0
 public bool DiffersFrom(EngineWrapper e)
 {
     return(On != e.engine.EngineIgnited || Role != e.Role ||
            (Role == TCARole.MANUAL && Mathf.Abs(e.thrustLimit - Limit) > lim_eps));
 }
Example #17
0
 public float DistanceTo(EngineWrapper e)
 {
     return(DistanceTo(VSL.LocalDir(e.defThrustDir)));
 }
Example #18
0
 public EngineCluster(VesselWrapper vsl, EngineWrapper e) : this(vsl) { Add(e); }