Exemple #1
0
        private bool FindPartsWithoutFARModel(List <Part> editorShip)
        {
            bool returnValue = false;

            for (int i = 0; i < editorShip.Count; i++)
            {
                Part p = editorShip[i];

                if (p == null)
                {
                    continue;
                }

                if (p != null && FARAeroUtil.IsNonphysical(p) &&
                    p.physicalSignificance != Part.PhysicalSignificance.NONE)
                {
                    MonoBehaviour.print(p + ": FAR correcting physical significance to fix CoM in editor");
                    p.physicalSignificance = Part.PhysicalSignificance.NONE;
                }

                string title = p.partInfo.title.ToLowerInvariant();

                if (p.Modules.Contains("FARBasicDragModel"))
                {
                    List <PartModule> modulesToRemove = new List <PartModule>();
                    for (int j = 0; j < p.Modules.Count; j++)
                    {
                        PartModule m = p.Modules[j];
                        if (!(m is FARBasicDragModel))
                        {
                            continue;
                        }
                        FARBasicDragModel d = m as FARBasicDragModel;
                        if (d.CdCurve == null || d.ClPotentialCurve == null || d.ClViscousCurve == null || d.CmCurve == null)
                        {
                            modulesToRemove.Add(m);
                        }
                    }
                    if (modulesToRemove.Count > 0)
                    {
                        for (int j = 0; j < modulesToRemove.Count; j++)
                        {
                            PartModule m = modulesToRemove[j];

                            p.RemoveModule(m);
                            Debug.Log("Removing Incomplete FAR Drag Module");
                        }
                        if (p.Modules.Contains("FARPayloadFairingModule"))
                        {
                            p.RemoveModule(p.Modules["FARPayloadFairingModule"]);
                        }
                        if (p.Modules.Contains("FARCargoBayModule"))
                        {
                            p.RemoveModule(p.Modules["FARCargoBayModule"]);
                        }
                        if (p.Modules.Contains("FARControlSys"))
                        {
                            p.RemoveModule(p.Modules["FARControlSys"]);
                        }
                    }
                }



                if (p is StrutConnector || p is FuelLine || p is ControlSurface || p is Winglet || FARPartClassification.ExemptPartFromGettingDragModel(p, title))
                {
                    continue;
                }

                FARPartModule q = p.GetComponent <FARPartModule>();
                if (q != null && !(q is FARControlSys))
                {
                    continue;
                }

                bool updatedModules = false;

                if (FARPartClassification.PartIsCargoBay(p, title))
                {
                    if (!p.Modules.Contains("FARCargoBayModule"))
                    {
                        p.AddModule("FARCargoBayModule");
                        p.Modules["FARCargoBayModule"].OnStart(PartModule.StartState.Editor);
                        FARAeroUtil.AddBasicDragModuleWithoutDragPropertySetup(p);
                        p.Modules["FARBasicDragModel"].OnStart(PartModule.StartState.Editor);
                        updatedModules = true;
                    }
                }
                if (!updatedModules)
                {
                    if (FARPartClassification.PartIsPayloadFairing(p, title))
                    {
                        if (!p.Modules.Contains("FARPayloadFairingModule"))
                        {
                            p.AddModule("FARPayloadFairingModule");
                            p.Modules["FARPayloadFairingModule"].OnStart(PartModule.StartState.Editor);
                            FARAeroUtil.AddBasicDragModuleWithoutDragPropertySetup(p);
                            p.Modules["FARBasicDragModel"].OnStart(PartModule.StartState.Editor);
                            updatedModules = true;
                        }
                    }

                    if (!updatedModules && !p.Modules.Contains("FARBasicDragModel"))
                    {
                        FARAeroUtil.AddBasicDragModuleWithoutDragPropertySetup(p);
                        p.Modules["FARBasicDragModel"].OnStart(PartModule.StartState.Editor);
                        updatedModules = true;
                    }
                }

                returnValue |= updatedModules;

                FARPartModule b = p.GetComponent <FARPartModule>();
                if (b != null)
                {
                    b.VesselPartList = editorShip;             //This prevents every single part in the ship running this due to VesselPartsList not being initialized
                }
            }
            for (int i = 0; i < editorShip.Count; i++)
            {
                Part p = editorShip[i];
                FARBasicDragModel d = p.GetComponent <FARBasicDragModel>();
                if (d != null)
                {
                    d.UpdatePropertiesWithShapeChange();
                }
            }
            return(returnValue);
        }
        private void FindPartsWithoutFARModel(Vessel v)
        {
            List <FARBasicDragModel> modulesToFullyUpdate = new List <FARBasicDragModel>();

            for (int i = 0; i < v.Parts.Count; i++)
            {
                Part p = v.Parts[i];
                if (p == null)
                {
                    continue;
                }

                string title = p.partInfo.title.ToLowerInvariant();

                if (p.Modules.Contains("FARBasicDragModel"))
                {
                    List <PartModule> modulesToRemove = new List <PartModule>();
                    for (int j = 0; j < p.Modules.Count; j++)
                    {
                        PartModule m = p.Modules[j];
                        if (!(m is FARBasicDragModel))
                        {
                            continue;
                        }
                        FARBasicDragModel d = m as FARBasicDragModel;
                        if (d.CdCurve == null || d.ClPotentialCurve == null || d.ClViscousCurve == null || d.CmCurve == null)
                        {
                            modulesToRemove.Add(m);
                        }
                    }
                    if (modulesToRemove.Count > 0)
                    {
                        for (int j = 0; j < modulesToRemove.Count; j++)
                        {
                            PartModule m = modulesToRemove[j];
                            p.RemoveModule(m);
                            Debug.Log("Removing Incomplete FAR Drag Module");
                        }
                        if (p.Modules.Contains("FARPayloadFairingModule"))
                        {
                            p.RemoveModule(p.Modules["FARPayloadFairingModule"]);
                        }
                        if (p.Modules.Contains("FARCargoBayModule"))
                        {
                            p.RemoveModule(p.Modules["FARCargoBayModule"]);
                        }
                        if (p.Modules.Contains("FARControlSys"))
                        {
                            p.RemoveModule(p.Modules["FARControlSys"]);
                        }
                    }
                }

                if (p is StrutConnector || p is FuelLine || p is ControlSurface || p is Winglet || FARPartClassification.ExemptPartFromGettingDragModel(p, title))
                {
                    continue;
                }

                if (p.Modules.Contains("ModuleCommand") && !p.Modules.Contains("FARControlSys"))
                {
                    p.AddModule("FARControlSys");
                    PartModule m = p.Modules["FARControlSys"];
                    m.OnStart(PartModule.StartState.Flying);
                    //Debug.Log("Added FARControlSys to " + p.partInfo.title);
                }

                FARPartModule q = p.GetComponent <FARPartModule>();
                if (q != null && !(q is FARControlSys))
                {
                    continue;
                }

                bool updatedModules = false;

                if (FARPartClassification.PartIsCargoBay(p, title))
                {
                    if (!p.Modules.Contains("FARCargoBayModule"))
                    {
                        p.AddModule("FARCargoBayModule");
                        PartModule m = p.Modules["FARCargoBayModule"];
                        m.OnStart(PartModule.StartState.Flying);

                        FARAeroUtil.AddBasicDragModuleWithoutDragPropertySetup(p);
                        m = p.Modules["FARBasicDragModel"];
                        m.OnStart(PartModule.StartState.Flying);

                        updatedModules = true;
                    }
                }
                if (!updatedModules)
                {
                    if (FARPartClassification.PartIsPayloadFairing(p, title))
                    {
                        if (!p.Modules.Contains("FARPayloadFairingModule"))
                        {
                            p.AddModule("FARPayloadFairingModule");
                            PartModule m = p.Modules["FARPayloadFairingModule"];
                            m.OnStart(PartModule.StartState.Flying);

                            FARAeroUtil.AddBasicDragModuleWithoutDragPropertySetup(p);
                            m = p.Modules["FARBasicDragModel"];
                            m.OnStart(PartModule.StartState.Flying);
                            updatedModules = true;
                        }
                    }

                    if (!updatedModules && !p.Modules.Contains("FARBasicDragModel"))
                    {
                        FARAeroUtil.AddBasicDragModuleWithoutDragPropertySetup(p);
                        PartModule m = p.Modules["FARBasicDragModel"];
                        m.OnStart(PartModule.StartState.Flying);

                        updatedModules = true;
                    }
                }
                if (updatedModules)
                {
                    modulesToFullyUpdate.Add((p.Modules["FARBasicDragModel"]) as FARBasicDragModel);
                }

                //returnValue |= updatedModules;

                FARPartModule b = p.GetComponent <FARPartModule>();
                if (b != null)
                {
                    b.VesselPartList = p.vessel.Parts;             //This prevents every single part in the ship running this due to VesselPartsList not being initialized
                }
            }
            for (int i = 0; i < v.parts.Count; i++)
            {
                Part p = v.parts[i];
                FARBasicDragModel d = p.GetComponent <FARBasicDragModel>();
                if (d != null)
                {
                    if (!modulesToFullyUpdate.Contains(d))
                    {
                        d.AttachNodeCdAdjust();
                    }
                    else
                    {
                        d.UpdatePropertiesWithShapeChange();
                    }
                }
            }
            UpdateFARPartModules(v);
        }