コード例 #1
0
        [KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "[Debug] log volume/surface", active = false, groupName = "Habitat", groupDisplayName = "#KERBALISM_Group_Habitat")]        //Habitat
#endif
        public void LogVolumeAndSurface()
        {
            Lib.GetPartVolumeAndSurface(part, true);
        }
コード例 #2
0
        // volume / surface evaluation at prefab compilation
        public override void OnLoad(ConfigNode node)
        {
            // volume/surface calcs are quite slow and memory intensive, so we do them only once on the prefab
            // then get the prefab values from OnStart. Moreover, we cache the results in the
            // Kerbalism\HabitatData.cache file and reuse those cached results on next game launch.
            if (HighLogic.LoadedScene == GameScenes.LOADING)
            {
                if (volume <= 0.0 || surface <= 0.0)
                {
                    if (habitatDatabase == null)
                    {
                        ConfigNode   dbRootNode   = ConfigNode.Load(HabitatDataCachePath);
                        ConfigNode[] habInfoNodes = dbRootNode?.GetNodes(habitatDataCacheNodeName);
                        habitatDatabase = new Dictionary <string, Lib.PartVolumeAndSurfaceInfo>();

                        if (habInfoNodes != null)
                        {
                            for (int i = 0; i < habInfoNodes.Length; i++)
                            {
                                string partName = habInfoNodes[i].GetValue("partName") ?? string.Empty;
                                if (!string.IsNullOrEmpty(partName) && !habitatDatabase.ContainsKey(partName))
                                {
                                    habitatDatabase.Add(partName, new Lib.PartVolumeAndSurfaceInfo(habInfoNodes[i]));
                                }
                            }
                        }
                    }

                    // SSTU specific support copypasted from the old system, not sure how well this works
                    foreach (PartModule pm in part.Modules)
                    {
                        if (pm.moduleName == "SSTUModularPart")
                        {
                            Bounds bb = Lib.ReflectionCall <Bounds>(pm, "getModuleBounds", new Type[] { typeof(string) }, new string[] { "CORE" });
                            if (bb != null)
                            {
                                if (volume <= 0.0)
                                {
                                    volume = Lib.BoundsVolume(bb) * 0.785398;                                                // assume it's a cylinder
                                }
                                if (surface <= 0.0)
                                {
                                    surface = Lib.BoundsSurface(bb) * 0.95493;                                                 // assume it's a cylinder
                                }
                            }
                            return;
                        }
                    }

                    string configPartName = part.name.Replace('.', '_');
                    Lib.PartVolumeAndSurfaceInfo partInfo;
                    if (!habitatDatabase.TryGetValue(configPartName, out partInfo))
                    {
                        // Find deploy/retract animations, either here on in the gravityring module
                        // then set the part to the deployed state before doing the volume/surface calcs
                        // if part has Gravity Ring, find it.
                        gravityRing    = part.FindModuleImplementing <GravityRing>();
                        hasGravityRing = gravityRing != null;

                        // create animators and set the model to the deployed state
                        if (hasGravityRing)
                        {
                            gravityRing.deploy_anim          = new Animator(part, gravityRing.deploy);
                            gravityRing.deploy_anim.reversed = gravityRing.animBackwards;

                            if (gravityRing.deploy_anim.IsDefined)
                            {
                                gravityRing.deploy_anim.Still(1.0);
                            }
                        }
                        else
                        {
                            inflate_anim          = new Animator(part, inflate);
                            inflate_anim.reversed = animBackwards;

                            if (inflate_anim.IsDefined)
                            {
                                inflate_anim.Still(1.0);
                            }
                        }

                        // get surface and volume
                        partInfo = Lib.GetPartVolumeAndSurface(part, Settings.VolumeAndSurfaceLogging);

                        habitatDatabase.Add(configPartName, partInfo);
                    }

                    partInfo.GetUsingMethod(
                        volumeAndSurfaceMethod != Lib.VolumeAndSurfaceMethod.Best ? volumeAndSurfaceMethod : partInfo.bestMethod,
                        out double infoVolume, out double infoSurface, substractAttachementNodesSurface);

                    if (volume <= 0.0)
                    {
                        volume = infoVolume;
                    }
                    if (surface <= 0.0)
                    {
                        surface = infoSurface;
                    }
                }
            }
        }