Exemple #1
0
        private void InstallMode(ModuleSTPModularCorridor.ModeConfig m, bool isLoading = false)
        {
            ConfigNode conf      = m.config;
            int        idx       = m.path.LastIndexOf('/');
            string     modelPath = m.path.Substring(0, idx) + "/" + conf.GetValue("model");

            Debug.Log("[STB]: Loading: " + conf.GetValue("modeName") + " mode.");
            ConfigNode[] array = m.inRes;
            for (int j = 0; j < array.Length; j++)
            {
                ConfigNode i = array[j];
                if (MBToolbox.AmountAvailable(i.GetValue("name"), FlightGlobals.ActiveVessel.rootPart) < System.Convert.ToDouble(i.GetValue("amount")))
                {
                    ScreenMessages.PostScreenMessage("Not enough " + i.GetValue("name"), 5f);
                    return;
                }
                MBToolbox.RequestResource(i.GetValue("name"), System.Convert.ToDouble(i.GetValue("amount")), FlightGlobals.ActiveVessel.rootPart);
            }
            if (this.installedModule.hasInit() && !isLoading)
            {
                Debug.Log("[STB]: Reseting modules...");
                if (this.installedModule.moduleconfs.Length != 0)
                {
                    System.Collections.Generic.List <PartModule> pmToRemoveList = new System.Collections.Generic.List <PartModule>();
                    using (var enumerator = base.part.Modules.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            PartModule pm = (PartModule)enumerator.Current;
                            array = this.installedModule.moduleconfs;
                            for (int j = 0; j < array.Length; j++)
                            {
                                ConfigNode i = array[j];
                                if (i.GetValue("name") == pm.moduleName)
                                {
                                    pmToRemoveList.Add(pm);
                                }
                            }
                        }
                    }
                    foreach (PartModule pm in pmToRemoveList)
                    {
                        base.part.RemoveModule(pm);
                        Debug.Log("[STB]: Removing: " + pm.moduleName + " module.");
                    }
                }
                Debug.Log("[STB]: Reseting resources...");
                foreach (PartResource r in base.part.Resources)
                {
                    array = this.installedModule.resconfs;
                    for (int j = 0; j < array.Length; j++)
                    {
                        ConfigNode i = array[j];
                        if (i.GetValue("name") == r.resourceName)
                        {
                            ConfigNode node = i.CreateCopy();
                            node.SetValue("name", r.resourceName, false);
                            node.SetValue("amount", "0", false);
                            node.SetValue("maxAmount", "0", false);
                            base.part.SetResource(node);
                            Debug.Log("[STB]: Reseting " + r.resourceName);
                        }
                    }
                }
                Debug.Log("[STB]: Reseting model...");
                if (this.currModel != null)
                {
                    this.currModel.SetActive(false);
                }
            }
            if (m.isDepsOk)
            {
                Debug.Log("[STB]: Adding modules...");
                array = m.moduleconfs;
                for (int j = 0; j < array.Length; j++)
                {
                    ConfigNode i  = array[j];
                    PartModule pm = base.part.AddModule(i.GetValue("name"));
                    pm.OnAwake();
                    pm.OnInitialize();
                    pm.Load(i);
                    pm.OnStart(PartModule.StartState.Landed);
                    Debug.Log(i.GetValue("name") + " is being added from: " + i.name);
                }
            }
            if (!isLoading)
            {
                Debug.Log("[STB]: Adding resources...");
                array = m.resconfs;
                for (int j = 0; j < array.Length; j++)
                {
                    ConfigNode i = array[j];
                    if (i.GetValue("amount") != "0")
                    {
                        i.SetValue("amount", "0", false);
                    }
                    base.part.SetResource(i);
                    Debug.Log(i.GetValue("name") + " " + i.name + " is being added");
                }
            }
            Debug.Log("[STB]: Adding model...");
            if (GameDatabase.Instance.ExistsModel(modelPath))
            {
                GameObject go = GameDatabase.Instance.GetModel(modelPath);
                go.SetActive(true);
                go.layer = 15;
                go.name  = conf.GetValue("modeName") + go.GetInstanceID();
                go.transform.position = base.part.partTransform.position;
                go.transform.rotation = base.part.partTransform.rotation;
                go.transform.parent   = base.part.partTransform;
                this.currModel        = go;
            }
            else
            {
                Debug.Log("[STB] says: " + modelPath + " is not found!");
            }
            this.installedModule = m;
            this.currModeName    = conf.GetValue("modeName");
            Debug.Log("[STB]: Installing done!");
        }
        private void FindPartsWithoutFARModel(Vessel v)
        {
            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.AddBasicDragModule(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.AddBasicDragModule(p);
                            m = p.Modules["FARBasicDragModel"];
                            m.OnStart(PartModule.StartState.Flying);
                            updatedModules = true;
                        }
                    }

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

                        updatedModules = true;
                    }
                }

                //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
                }
            }
            UpdateFARPartModules(v);
        }
Exemple #3
0
        private void FindPartsWithoutFARModel(Vessel v)
        {
            List <FARPartModule> FARPartModules = new List <FARPartModule>();

            bool returnValue = false;

            foreach (Part p in v.Parts)
            {
                if (p == null)
                {
                    continue;
                }

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

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

                if (p.Modules.Contains("FARPartModule"))
                {
                    foreach (PartModule m in p.Modules)
                    {
                        if (m is FARPartModule)
                        {
                            FARPartModules.Add(m as FARPartModule);
                        }
                    }
                    continue;
                }

                if (p.Modules.Contains("ModuleCommand") && !p.Modules.Contains("FARControlSys"))
                {
                    p.AddModule("FARControlSys");
                    PartModule m = p.Modules["FARControlSys"];
                    m.OnStart(PartModule.StartState.Flying);

                    FARPartModules.Add(m as FARPartModule);
                }

                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);
                        FARPartModules.Add(m as FARPartModule);

                        FARAeroUtil.AddBasicDragModule(p);
                        m = p.Modules["FARBasicDragModel"];
                        m.OnStart(PartModule.StartState.Flying);
                        FARPartModules.Add(m as FARPartModule);

                        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);
                            FARPartModules.Add(m as FARPartModule);

                            FARAeroUtil.AddBasicDragModule(p);
                            m = p.Modules["FARBasicDragModel"];
                            m.OnStart(PartModule.StartState.Flying);
                            FARPartModules.Add(m as FARPartModule);
                            updatedModules = true;
                        }
                    }

                    if (!updatedModules && !p.Modules.Contains("FARBasicDragModel"))
                    {
                        FARAeroUtil.AddBasicDragModule(p);
                        PartModule m = p.Modules["FARBasicDragModel"];
                        m.OnStart(PartModule.StartState.Flying);
                        FARPartModules.Add(m as FARPartModule);

                        updatedModules = true;
                    }
                }

                returnValue |= updatedModules;

                FARPartModule b = p.GetComponent <FARPartModule>();
                if (b != null)
                {
                    b.VesselPartList = v.Parts;             //This prevents every single part in the ship running this due to VesselPartsList not being initialized
                }
            }

            /*if (vesselFARPartModules.ContainsKey(v))
             * {
             *  List<FARPartModule> Modules = vesselFARPartModules[v];
             *  FARPartModules = FARPartModules.Union(Modules).ToList();
             *  vesselFARPartModules[v] = FARPartModules;
             * }
             * else
             *  vesselFARPartModules.Add(v, FARPartModules);*/
            //return returnValue;
        }