public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            // load ignition resources
            if (node.HasNode("IGNITOR_RESOURCE"))
            {
                ignitionResources.Clear();
            }
            foreach (ConfigNode n in node.GetNodes("IGNITOR_RESOURCE"))
            {
                ModuleResource res = new ModuleResource();
                res.Load(n);
                ignitionResources.Add(res);
            }

            // Determine thrustAxis when creating prefab
            if (HighLogic.LoadedScene == GameScenes.LOADING)
            {
                thrustAxis = Vector3.zero;
                foreach (Transform t in part.FindModelTransforms(thrustVectorTransformName))
                {
                    thrustAxis -= t.forward;
                }
                thrustAxis = thrustAxis.normalized;
            }

            node.TryGetNode("Ullage", ref ullageNode);
        }
Beispiel #2
0
        public override void OnLoad(ConfigNode node)
        {
            if (node.HasNode("RESOURCE"))
            {
                resources = new List <ModuleResource>();

                ConfigNode[] resourceNodes = node.GetNodes("RESOURCE");

                int r = resourceNodes.Length;

                for (int j = 0; j < r; j++)
                {
                    ConfigNode     resource = resourceNodes[j];
                    ModuleResource mod      = new ModuleResource();
                    mod.Load(resource);
                    resources.Add(mod);
                }
            }

            if (resources.Count > 0)
            {
                usingEC = true;
            }

            StartCoroutine(delayedLoad(node));
        }
 public override void OnLoad(ConfigNode node)
 {
     if (RequiredResources == null)
     {
         RequiredResources = new List <ModuleResource>();
     }
     foreach (ConfigNode cn in node.nodes)
     {
         if (!cn.name.Equals("RESOURCE"))
         {
             continue;
         }
         ModuleResource rs = new ModuleResource();
         rs.Load(cn);
         RequiredResources.Add(rs);
     }
 }
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            // Manually reload ignitions if not in editor
            if (!HighLogic.LoadedSceneIsEditor)
            {
                node.TryGetValue("ignited", ref ignited);
            }
            int pCount = propellants.Count;

            // thrust curve
            useThrustCurve = false;
            if (node.HasNode("thrustCurve") && node.HasValue("curveResource"))
            {
                if (node.GetValue("curveResource") != curveResource)
                {
                    Debug.LogError("*RFE* ERROR: curveResource doesn't match node's!");
                    curveResource = node.GetValue("curveResource");
                }
                if (thrustCurve == null)
                {
                    Debug.LogError("*RFE* ERROR: have curve node but thrustCurve is null!");
                    thrustCurve = new FloatCurve();
                    thrustCurve.Load(node.GetNode("thrustCurve"));
                }

                if (curveResource != string.Empty)
                {
                    for (int i = 0; i < pCount; ++i)
                    {
                        if (propellants[i].name.Equals(curveResource))
                        {
                            curveProp = i;
                            break;
                        }
                    }
                    if (curveProp != -1)
                    {
                        useThrustCurve = true;
                    }
                }

                Fields["thrustPercentage"].guiActive = Fields["thrustPercentage"].guiActiveEditor = (minFuelFlow != maxFuelFlow);
            }

            // Set from propellants
            bool instantThrottle = false;

            for (int i = 0; i < pCount; ++i)
            {
                if (RFSettings.Instance.instantThrottleProps.Contains(propellants[i].name))
                {
                    instantThrottle = true;
                }
                // any other stuff
            }

            // FIXME calculating throttle change rate
            if (!instantThrottle)
            {
                if (throttleResponseRate <= 0f)
                {
                    throttleResponseRate = (float)(RFSettings.Instance.throttlingRate / Math.Log(Math.Max(RFSettings.Instance.throttlingClamp, Math.Sqrt(part.mass * maxThrust * maxThrust))));
                }
            }
            else
            {
                throttleResponseRate = 1000000f;
            }

            minThrottle = minFuelFlow / maxFuelFlow;

            // set fields
            Fields["thrustCurveDisplay"].guiActive = useThrustCurve;
            CreateEngine();

            if (ullageSet == null)
            {
                ullageSet = new Ullage.UllageSet(this);
            }

            // Get thrust axis (only on create prefabs)
            if (part.partInfo == null || part.partInfo.partPrefab == null)
            {
                thrustAxis = Vector3.zero;
                foreach (Transform t in part.FindModelTransforms(thrustVectorTransformName))
                {
                    thrustAxis -= t.forward;
                }
                thrustAxis = thrustAxis.normalized;
            }
            ullageSet.SetThrustAxis(thrustAxis);

            // ullage
            if (node.HasNode("Ullage"))
            {
                ullageSet.Load(node.GetNode("Ullage"));
            }
            if (node.HasValue("pressureFed"))
            {
                bool.TryParse(node.GetValue("pressureFed"), out pressureFed);
                Debug.Log(this.name + ".pressureFed = " + this.pressureFed);
            }
            ullageSet.SetUllageEnabled(ullage);

            // load ignition resources
            if (node.HasNode("IGNITOR_RESOURCE"))
            {
                ignitionResources.Clear();
            }
            foreach (ConfigNode n in node.GetNodes("IGNITOR_RESOURCE"))
            {
                ModuleResource res = new ModuleResource();
                res.Load(n);
                ignitionResources.Add(res);
            }
        }
 public override void OnLoad(ConfigNode node)
 {
     if (RequiredResources == null) {
         RequiredResources = new List<ModuleResource>();
     }
     foreach (ConfigNode cn in node.nodes) {
         if(!cn.name.Equals("RESOURCE")) continue;
         ModuleResource rs = new ModuleResource();
         rs.Load(cn);
         RequiredResources.Add(rs);
     }
 }
        public override void OnLoad(ConfigNode node)
        {
            if (thrustCurve == null)
                thrustCurve = new FloatCurve();

            base.OnLoad(node);
            // Manually reload ignitions if not in editor
            if(!HighLogic.LoadedSceneIsEditor)
                node.TryGetValue("ignited", ref ignited);
            int pCount = propellants.Count;
            // thrust curve
            useThrustCurve = false;
            if (node.HasNode("thrustCurve") && node.HasValue("curveResource"))
            {
                if (node.GetValue("curveResource") != curveResource)
                {
                    Debug.Log("*RFE* ERROR: curveResource doesn't match node's!");
                    curveResource = node.GetValue("curveResource");
                }
                if (thrustCurve == null)
                {
                    Debug.Log("*RFE* ERROR: have curve node but thrustCurve is null!");
                    thrustCurve = new FloatCurve();
                    thrustCurve.Load(node.GetNode("thrustCurve"));
                }

                if (curveResource != "")
                {
                    for (int i = 0; i < pCount; ++i)
                    {
                        if (propellants[i].name.Equals(curveResource))
                        {
                            curveProp = i;
                            break;
                        }
                    }
                    if (curveProp != -1)
                    {
                        useThrustCurve = true;
                    }
                }
            }

            // Set from propellants
            bool instantThrottle = true;
            for (int i = 0; i < pCount; ++i)
            {
                if (RFSettings.Instance.instantThrottleProps.Contains(propellants[i].name))
                {
                    instantThrottle = false;
                }
                // any other stuff
            }

            // FIXME calculating throttle change rate
            if (!instantThrottle)
                throttleResponseRate = (float)(10d / Math.Sqrt(Math.Sqrt(part.mass * maxThrust)));
            else
                throttleResponseRate = 1000000f;

            // set fields
            Fields["thrustCurveDisplay"].guiActive = useThrustCurve;
            CreateEngine();

            if (ullageSet == null)
                ullageSet = new Ullage.UllageSet(this);

            // Get thrust axis (only on create prefabs)
            if (part.partInfo == null || part.partInfo.partPrefab == null)
            {
                thrustAxis = Vector3.zero;
                foreach(Transform t in part.FindModelTransforms(thrustVectorTransformName))
                {
                    thrustAxis -= t.forward;
                }
                thrustAxis = thrustAxis.normalized;
            }
            ullageSet.SetThrustAxis(thrustAxis);

            // ullage
            if (node.HasNode("Ullage"))
            {
                ullageSet.Load(node.GetNode("Ullage"));
            }
            ullageSet.SetUllageEnabled(ullage);

            // load ignition resources
            if (node.HasNode("IGNITOR_RESOURCE"))
                ignitionResources.Clear();
            foreach (ConfigNode n in node.GetNodes("IGNITOR_RESOURCE"))
            {
                ModuleResource res = new ModuleResource();
                res.Load(n);
                ignitionResources.Add(res);
            }
        }
Beispiel #7
0
        public override void OnLoad(ConfigNode node)
        {
            if (thrustCurve == null)
            {
                thrustCurve = new FloatCurve();
            }

            base.OnLoad(node);
            int pCount = propellants.Count;

            // thrust curve
            useThrustCurve = false;
            if (node.HasNode("thrustCurve") && node.HasValue("curveResource"))
            {
                if (node.GetValue("curveResource") != curveResource)
                {
                    Debug.Log("*RFE* ERROR: curveResource doesn't match node's!");
                    curveResource = node.GetValue("curveResource");
                }
                if (thrustCurve == null)
                {
                    Debug.Log("*RFE* ERROR: have curve node but thrustCurve is null!");
                    thrustCurve = new FloatCurve();
                    thrustCurve.Load(node.GetNode("thrustCurve"));
                }

                if (curveResource != "")
                {
                    for (int i = 0; i < pCount; ++i)
                    {
                        if (propellants[i].name.Equals(curveResource))
                        {
                            curveProp = i;
                            break;
                        }
                    }
                    if (curveProp != -1)
                    {
                        useThrustCurve = true;
                    }
                }
            }

            // Set from propellants
            bool instantThrottle = true;

            for (int i = 0; i < pCount; ++i)
            {
                if (RFSettings.Instance.instantThrottleProps.Contains(propellants[i].name))
                {
                    instantThrottle = false;
                }
                // any other stuff
            }

            // FIXME calculating throttle change rate
            if (!instantThrottle)
            {
                throttleResponseRate = (float)(10d / Math.Sqrt(Math.Sqrt(part.mass * maxThrust)));
            }
            else
            {
                throttleResponseRate = 1000000f;
            }

            // set fields
            Fields["thrustCurveDisplay"].guiActive = useThrustCurve;
            CreateEngine();

            if (ullageSet == null)
            {
                ullageSet = new Ullage.UllageSet(this);
            }

            // Get thrust axis (only on create prefabs)
            if (part.partInfo == null || part.partInfo.partPrefab == null)
            {
                thrustAxis = Vector3.zero;
                foreach (Transform t in part.FindModelTransforms(thrustVectorTransformName))
                {
                    thrustAxis -= t.forward;
                }
                thrustAxis = thrustAxis.normalized;
            }
            ullageSet.SetThrustAxis(thrustAxis);

            // ullage
            if (node.HasNode("Ullage"))
            {
                ullageSet.Load(node.GetNode("Ullage"));
            }

            ullageSet.SetUllageEnabled(ullage);

            // load ignition resources
            if (node.HasNode("IGNITOR_RESOURCE"))
            {
                ignitionResources.Clear();
            }
            foreach (ConfigNode n in node.GetNodes("IGNITOR_RESOURCE"))
            {
                ModuleResource res = new ModuleResource();
                res.Load(n);
                ignitionResources.Add(res);
            }
        }
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            // load ignition resources
            if (node.HasNode("IGNITOR_RESOURCE"))
            {
                ignitionResources.Clear();
            }
            foreach (ConfigNode n in node.GetNodes("IGNITOR_RESOURCE"))
            {
                ModuleResource res = new ModuleResource();
                res.Load(n);
                ignitionResources.Add(res);
            }

            // Determine thrustAxis when creating prefab
            if (HighLogic.LoadedScene == GameScenes.LOADING)
            {
                thrustAxis = Vector3.zero;
                foreach (Transform t in part.FindModelTransforms(thrustVectorTransformName))
                {
                    thrustAxis -= t.forward;
                }
                thrustAxis = thrustAxis.normalized;
            }

            node.TryGetNode("Ullage", ref ullageNode);

            localVaryFlow               = varyFlow;
            localVaryIsp                = varyIsp;
            localVaryMixture            = varyMixture;
            localResidualsThresholdBase = residualsThresholdBase;
            localVaryResiduals          = varyResiduals;

            // Use instant throttle response as proxy.
            isSolid            = false;
            numRealPropellants = 0;
            foreach (Propellant p in propellants)
            {
                if (!p.ignoreForIsp && p.resourceDef.density != 0d)
                {
                    ++numRealPropellants;
                }

                if (RFSettings.Instance.instantThrottleProps.Contains(p.name))
                {
                    isSolid = true;
                }
            }
            // Create reasonable values for variation
            // Solids
            if (isSolid)
            {
                double propMultiplier = 1d;
                string propName       = propellants.Count > 0 ? propellants[0].name : string.Empty;
                //Debug.Log("MERF: For part " + part.name + " is solid, found propellant " + propName);
                if (propName == "NGNC")
                {
                    propMultiplier = 2d;
                }
                else if (propName == "PSPC")
                {
                    propMultiplier = 1.5d;
                }
                else //if (propName == "HTPB" || propName == "PBAN")
                {
                    propMultiplier = 1d;
                }

                if (localVaryIsp < 0d)
                {
                    localVaryIsp = 0.015d * propMultiplier;
                }
                if (localVaryFlow < 0d)
                {
                    localVaryFlow = 0.06d * propMultiplier;
                }
                localVaryMixture = 0d;

                if (localResidualsThresholdBase < 0d)
                {
                    localResidualsThresholdBase = 0.01d * propMultiplier;
                }
                if (localVaryResiduals < 0d)
                {
                    localVaryResiduals = 0.003d * propMultiplier;
                }
            }
            // Liquids
            else
            {
                // Detect upper vs. lower? How?
                if (pressureFed)
                {
                    if (localVaryIsp < 0d)
                    {
                        localVaryIsp = 0.01d;
                    }
                    if (localVaryFlow < 0d)
                    {
                        localVaryFlow = 0.05d;
                    }
                    if (localVaryMixture < 0d)
                    {
                        localVaryMixture = 0.05d;
                    }

                    if (localResidualsThresholdBase < 0d)
                    {
                        localResidualsThresholdBase = 0.008d;
                    }
                    if (localVaryResiduals < 0d)
                    {
                        localVaryResiduals = 0d;
                    }
                }
                else
                {
                    if (localVaryIsp < 0d)
                    {
                        localVaryIsp = 0.003d;
                    }
                    if (localVaryFlow < 0d)
                    {
                        localVaryFlow = 0.005d;
                    }
                    if (localVaryMixture < 0d)
                    {
                        localVaryMixture = 0.005d;
                    }

                    if (residualsThresholdBase < 0d)
                    {
                        localResidualsThresholdBase = 0.004d;
                    }
                    if (localVaryResiduals < 0d)
                    {
                        localVaryResiduals = 0d;
                    }
                }

                if (ignitions == -1 || ignitions > 4)
                {
                    localResidualsThresholdBase *= 2d;
                }
                else if (ignitions == 0)
                {
                    localResidualsThresholdBase *= 0.7d;
                }
                else
                {
                    localResidualsThresholdBase *= (1d + (ignitions - 1) * 0.25d);
                }
            }
            // Double-check mixture variance makes sense
            if (numRealPropellants != 2)
            {
                localVaryMixture = 0d;
            }

            localVaryFlow               *= RFSettings.Instance.varianceAndResiduals;
            localVaryIsp                *= RFSettings.Instance.varianceAndResiduals;
            localVaryMixture            *= RFSettings.Instance.varianceAndResiduals;
            localResidualsThresholdBase *= RFSettings.Instance.varianceAndResiduals;
            localVaryResiduals          *= RFSettings.Instance.varianceAndResiduals;
        }