Exemplo n.º 1
0
        public static void CouplePart(Part srcPart, Part tgtPart, string srcAttachNodeID = null, AttachNode tgtAttachNode = null)
        {
            // Node links
            if (srcAttachNodeID != null)
            {
                if (srcAttachNodeID == "srfAttach")
                {
                    KIS_Shared.DebugLog("Attach type : " + srcPart.srfAttachNode.nodeType + " | ID : " + srcPart.srfAttachNode.id);
                    srcPart.attachMode = AttachModes.SRF_ATTACH;
                    srcPart.srfAttachNode.attachedPart = tgtPart;
                }
                else
                {
                    AttachNode srcAttachNode = srcPart.findAttachNode(srcAttachNodeID);
                    if (srcAttachNode != null)
                    {
                        KIS_Shared.DebugLog("Attach type : " + srcPart.srfAttachNode.nodeType + " | ID : " + srcAttachNode.id);
                        srcPart.attachMode         = AttachModes.STACK;
                        srcAttachNode.attachedPart = tgtPart;
                        if (tgtAttachNode != null)
                        {
                            tgtAttachNode.attachedPart = srcPart;
                        }
                    }
                    else
                    {
                        KIS_Shared.DebugError("Source attach node not found !");
                    }
                }
            }
            else
            {
                KIS_Shared.DebugWarning("Missing source attach node !");
            }

            srcPart.Couple(tgtPart);
        }
Exemplo n.º 2
0
        public void Awake()
        {
            // Set inventory module for every eva kerbal
            KIS_Shared.DebugLog("Set KIS config...");
            ConfigNode nodeSettings = GameDatabase.Instance.GetConfigNode("KIS/settings/KISConfig");

            if (nodeSettings == null)
            {
                KIS_Shared.DebugError("KIS settings.cfg not found or invalid !");
                return;
            }

            // Set global settings
            ConfigNode nodeGlobal = nodeSettings.GetNode("Global");

            if (nodeGlobal.HasValue("itemDebug"))
            {
                ModuleKISInventory.debugContextMenu = bool.Parse(nodeGlobal.GetValue("itemDebug"));
            }
            if (nodeGlobal.HasValue("breathableAtmoPressure"))
            {
                breathableAtmoPressure = float.Parse(nodeGlobal.GetValue("breathableAtmoPressure"));
            }

            ConfigNode nodeEvaInventory    = nodeSettings.GetNode("EvaInventory");
            ConfigNode nodeEvaPickup       = nodeSettings.GetNode("EvaPickup");
            ConfigNode nodeStackable       = nodeSettings.GetNode("StackableItemOverride");
            ConfigNode nodeStackableModule = nodeSettings.GetNode("StackableModule");

            // Set stackable items list
            stackableList.Clear();
            foreach (string partName in nodeStackable.GetValues("partName"))
            {
                stackableList.Add(partName);
            }

            // Set stackable module list
            stackableModules.Clear();
            foreach (string moduleName in nodeStackableModule.GetValues("moduleName"))
            {
                stackableModules.Add(moduleName);
            }

            //-------Male Kerbal
            // Adding module to EVA cause an unknown error but work
            Part evaPrefab = PartLoader.getPartInfoByName("kerbalEVA").partPrefab;

            try { evaPrefab.AddModule("ModuleKISInventory"); }
            catch {}
            try { evaPrefab.AddModule("ModuleKISPickup"); }
            catch { }

            // Set inventory module for eva
            ModuleKISInventory evaInventory = evaPrefab.GetComponent <ModuleKISInventory>();

            if (evaInventory)
            {
                if (nodeGlobal.HasValue("kerbalDefaultMass"))
                {
                    evaInventory.kerbalDefaultMass = float.Parse(nodeGlobal.GetValue("kerbalDefaultMass"));
                }
                SetInventoryConfig(nodeEvaInventory, evaInventory);
                evaInventory.invType = ModuleKISInventory.InventoryType.Eva;
                KIS_Shared.DebugLog("Eva inventory module loaded successfully");
            }

            // Set pickup module for eva
            ModuleKISPickup evaPickup = evaPrefab.GetComponent <ModuleKISPickup>();

            if (evaPickup)
            {
                if (nodeEvaPickup.HasValue("grabKey"))
                {
                    KISAddonPickup.grabKey = nodeEvaPickup.GetValue("grabKey");
                }
                if (nodeEvaPickup.HasValue("attachKey"))
                {
                    KISAddonPickup.attachKey = nodeEvaPickup.GetValue("attachKey");
                }
                if (nodeEvaPickup.HasValue("allowPartAttach"))
                {
                    evaPickup.allowPartAttach = bool.Parse(nodeEvaPickup.GetValue("allowPartAttach"));
                }
                if (nodeEvaPickup.HasValue("allowStaticAttach"))
                {
                    evaPickup.allowStaticAttach = bool.Parse(nodeEvaPickup.GetValue("allowStaticAttach"));
                }
                if (nodeEvaPickup.HasValue("allowPartStack"))
                {
                    evaPickup.allowPartStack = bool.Parse(nodeEvaPickup.GetValue("allowPartStack"));
                }
                if (nodeEvaPickup.HasValue("maxDistance"))
                {
                    evaPickup.maxDistance = float.Parse(nodeEvaPickup.GetValue("maxDistance"));
                }
                if (nodeEvaPickup.HasValue("grabMaxMass"))
                {
                    evaPickup.grabMaxMass = float.Parse(nodeEvaPickup.GetValue("grabMaxMass"));
                }
                if (nodeEvaPickup.HasValue("dropSndPath"))
                {
                    evaPickup.dropSndPath = nodeEvaPickup.GetValue("dropSndPath");
                }
                if (nodeEvaPickup.HasValue("attachPartSndPath"))
                {
                    evaPickup.attachPartSndPath = nodeEvaPickup.GetValue("attachPartSndPath");
                }
                if (nodeEvaPickup.HasValue("detachPartSndPath"))
                {
                    evaPickup.detachPartSndPath = nodeEvaPickup.GetValue("detachPartSndPath");
                }
                if (nodeEvaPickup.HasValue("attachStaticSndPath"))
                {
                    evaPickup.attachStaticSndPath = nodeEvaPickup.GetValue("attachStaticSndPath");
                }
                if (nodeEvaPickup.HasValue("detachStaticSndPath"))
                {
                    evaPickup.detachStaticSndPath = nodeEvaPickup.GetValue("detachStaticSndPath");
                }
                if (nodeEvaPickup.HasValue("draggedIconResolution"))
                {
                    KISAddonPickup.draggedIconResolution = int.Parse(nodeEvaPickup.GetValue("draggedIconResolution"));
                }
                KIS_Shared.DebugLog("Eva pickup module loaded successfully");
            }

            //-------Female Kerbal
            // Adding module to EVA cause an unknown error but work
            Part evaFemalePrefab = PartLoader.getPartInfoByName("kerbalEVAfemale").partPrefab;

            try { evaFemalePrefab.AddModule("ModuleKISInventory"); }
            catch { }
            try { evaFemalePrefab.AddModule("ModuleKISPickup"); }
            catch { }

            // Set inventory module for eva
            ModuleKISInventory evaFemaleInventory = evaFemalePrefab.GetComponent <ModuleKISInventory>();

            if (evaFemaleInventory)
            {
                if (nodeGlobal.HasValue("kerbalDefaultMass"))
                {
                    evaFemaleInventory.kerbalDefaultMass = float.Parse(nodeGlobal.GetValue("kerbalDefaultMass"));
                }
                SetInventoryConfig(nodeEvaInventory, evaFemaleInventory);
                evaFemaleInventory.invType = ModuleKISInventory.InventoryType.Eva;
                KIS_Shared.DebugLog("Eva inventory module loaded successfully");
            }

            // Set pickup module for eva
            ModuleKISPickup evaFemalePickup = evaFemalePrefab.GetComponent <ModuleKISPickup>();

            if (evaFemalePickup)
            {
                if (nodeEvaPickup.HasValue("grabKey"))
                {
                    KISAddonPickup.grabKey = nodeEvaPickup.GetValue("grabKey");
                }
                if (nodeEvaPickup.HasValue("attachKey"))
                {
                    KISAddonPickup.attachKey = nodeEvaPickup.GetValue("attachKey");
                }
                if (nodeEvaPickup.HasValue("allowPartAttach"))
                {
                    evaFemalePickup.allowPartAttach = bool.Parse(nodeEvaPickup.GetValue("allowPartAttach"));
                }
                if (nodeEvaPickup.HasValue("allowStaticAttach"))
                {
                    evaFemalePickup.allowStaticAttach = bool.Parse(nodeEvaPickup.GetValue("allowStaticAttach"));
                }
                if (nodeEvaPickup.HasValue("allowPartStack"))
                {
                    evaFemalePickup.allowPartStack = bool.Parse(nodeEvaPickup.GetValue("allowPartStack"));
                }
                if (nodeEvaPickup.HasValue("maxDistance"))
                {
                    evaFemalePickup.maxDistance = float.Parse(nodeEvaPickup.GetValue("maxDistance"));
                }
                if (nodeEvaPickup.HasValue("grabMaxMass"))
                {
                    evaFemalePickup.grabMaxMass = float.Parse(nodeEvaPickup.GetValue("grabMaxMass"));
                }
                if (nodeEvaPickup.HasValue("dropSndPath"))
                {
                    evaFemalePickup.dropSndPath = nodeEvaPickup.GetValue("dropSndPath");
                }
                if (nodeEvaPickup.HasValue("attachPartSndPath"))
                {
                    evaFemalePickup.attachPartSndPath = nodeEvaPickup.GetValue("attachPartSndPath");
                }
                if (nodeEvaPickup.HasValue("detachPartSndPath"))
                {
                    evaFemalePickup.detachPartSndPath = nodeEvaPickup.GetValue("detachPartSndPath");
                }
                if (nodeEvaPickup.HasValue("attachStaticSndPath"))
                {
                    evaFemalePickup.attachStaticSndPath = nodeEvaPickup.GetValue("attachStaticSndPath");
                }
                if (nodeEvaPickup.HasValue("detachStaticSndPath"))
                {
                    evaFemalePickup.detachStaticSndPath = nodeEvaPickup.GetValue("detachStaticSndPath");
                }
                if (nodeEvaPickup.HasValue("draggedIconResolution"))
                {
                    KISAddonPickup.draggedIconResolution = int.Parse(nodeEvaPickup.GetValue("draggedIconResolution"));
                }
                KIS_Shared.DebugLog("Eva pickup module loaded successfully");
            }

            // Set inventory module for every pod with crew capacity
            KIS_Shared.DebugLog("Loading pod inventory...");
            foreach (AvailablePart avPart in PartLoader.LoadedPartsList)
            {
                if (avPart.name == "kerbalEVA")
                {
                    continue;
                }
                if (avPart.name == "kerbalEVA_RD")
                {
                    continue;
                }
                if (avPart.name == "kerbalEVAfemale")
                {
                    continue;
                }
                if (!avPart.partPrefab)
                {
                    continue;
                }
                if (avPart.partPrefab.CrewCapacity < 1)
                {
                    continue;
                }
                KIS_Shared.DebugLog("Found part with CrewCapacity : " + avPart.name);


                for (int i = 0; i < avPart.partPrefab.CrewCapacity; i++)
                {
                    try
                    {
                        ModuleKISInventory moduleInventory = avPart.partPrefab.AddModule("ModuleKISInventory") as ModuleKISInventory;
                        SetInventoryConfig(nodeEvaInventory, moduleInventory);
                        moduleInventory.podSeat = i;
                        moduleInventory.invType = ModuleKISInventory.InventoryType.Pod;
                        KIS_Shared.DebugLog("Pod inventory module(s) for seat " + i + " loaded successfully");
                    }
                    catch
                    {
                        KIS_Shared.DebugWarning("Pod inventory module(s) for seat " + i + " can't be loaded !");
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static ConfigNode PartSnapshot(Part part)
        {
            ConfigNode        node     = new ConfigNode("PART");
            ProtoPartSnapshot snapshot = null;

            try
            {
                // Seems fine with a null vessel in 0.23 if some empty lists are allocated below
                snapshot = new ProtoPartSnapshot(part, null);
            }
            catch
            {
                // workaround for command module
                KIS_Shared.DebugWarning("Error during part snapshot, spawning part for snapshot (workaround for command module)");
                Part p = (Part)UnityEngine.Object.Instantiate(part.partInfo.partPrefab);
                p.gameObject.SetActive(true);
                p.name = part.partInfo.name;
                p.InitializeModules();
                snapshot = new ProtoPartSnapshot(p, null);
                UnityEngine.Object.Destroy(p.gameObject);
            }
            snapshot.attachNodes   = new List <AttachNodeSnapshot>();
            snapshot.srfAttachNode = new AttachNodeSnapshot("attach,-1");
            snapshot.symLinks      = new List <ProtoPartSnapshot>();
            snapshot.symLinkIdxs   = new List <int>();
            snapshot.Save(node);

            // Prune unimportant data
            node.RemoveValues("parent");
            node.RemoveValues("position");
            node.RemoveValues("rotation");
            node.RemoveValues("istg");
            node.RemoveValues("dstg");
            node.RemoveValues("sqor");
            node.RemoveValues("sidx");
            node.RemoveValues("attm");
            node.RemoveValues("srfN");
            node.RemoveValues("attN");
            node.RemoveValues("connected");
            node.RemoveValues("attached");
            node.RemoveValues("flag");

            node.RemoveNodes("ACTIONS");

            // Remove modules that are not in prefab since they won't load anyway
            var module_nodes   = node.GetNodes("MODULE");
            var prefab_modules = part.partInfo.partPrefab.GetComponents <PartModule>();

            node.RemoveNodes("MODULE");

            for (int i = 0; i < prefab_modules.Length && i < module_nodes.Length; i++)
            {
                var module = module_nodes[i];
                var name   = module.GetValue("name") ?? "";

                node.AddNode(module);

                if (name == "KASModuleContainer")
                {
                    // Containers get to keep their contents
                    module.RemoveNodes("EVENTS");
                }
                else if (name.StartsWith("KASModule"))
                {
                    // Prune the state of the KAS modules completely
                    module.ClearData();
                    module.AddValue("name", name);
                    continue;
                }

                module.RemoveNodes("ACTIONS");
            }

            return(node);
        }