Example #1
0
    public override void OnLoad(ConfigNode node)
    {
        base.OnLoad(node);
        if (node.HasValue("cameraPosition"))
        {
            cameraPosition = KSPUtil.ParseVector3(node.GetValue("cameraPosition"));
        }
        if (node.HasValue("cameraForward"))
        {
            cameraForward = KSPUtil.ParseVector3(node.GetValue("cameraForward"));
        }
        if (node.HasValue("cameraUp"))
        {
            cameraUp = KSPUtil.ParseVector3(node.GetValue("cameraUp"));
        }
        if (node.HasValue("camEnabled"))
        {
            camEnabled = bool.Parse(node.GetValue("camEnabled"));
        }
        if (node.HasValue("cameraFoV"))
        {
            cameraFoV = float.Parse(node.GetValue("cameraFoV"));
        }
        if (node.HasValue("cameraClip"))
        {
            cameraClip = float.Parse(node.GetValue("cameraClip"));
        }

        camActive = false;
    }
Example #2
0
 private void _createNewNode()
 {
     try
     {
         if (string.IsNullOrEmpty(this._newNodeName))
         {
             OSD.PostMessageUpperCenter("[NH] name for new node emtpy");
             return;
         }
         var pos = KSPUtil.ParseVector3(this._newNodePos);
         var an  = new AttachNode
         {
             owner         = this._selectedPart,
             position      = pos,
             nodeType      = AttachNode.NodeType.Stack,
             size          = 1,
             id            = this._findUniqueId(this._newNodeName),
             attachMethod  = AttachNodeMethod.FIXED_JOINT,
             nodeTransform = this._selectedPart.transform,
             orientation   = this._selectedPart.transform.up
         };
         this._selectedPart.attachNodes.Add(an);
         this._clearMapping(false);
         OSD.PostMessageUpperCenter("[NH] new node created");
     }
     catch (Exception e)
     {
         Debug.Log("[NH] creating new node threw exception: " + e.Message);
         OSD.PostMessageUpperCenter("[NH] unable to create node, please check vector format");
     }
 }
Example #3
0
 /// <summary>
 /// Returns true if the string can be parsed and stores it into the ref value.
 /// </summary>
 /// <param name="text">String to parse</param>
 /// <param name="result">Value to store the result in</param>
 public static bool TryParseVector3(string text, ref Vector3 result)
 {
     if (KSPUtil.ParseVector3(text) != null)
     {
         result = KSPUtil.ParseVector3(text);
         return(true);
     }
     return(false);
 }
 public override void OnLoad(ConfigNode node)
 {
     base.OnLoad(node);
     foreach (ConfigNode sectionPosNode in node.GetNodes("SECTIONPOS"))
     {
         if (sectionPosNode.HasValue("index") && sectionPosNode.HasValue("localPos") && sectionPosNode.HasValue("localRot"))
         {
             int     index    = int.Parse(sectionPosNode.GetValue("index"));
             Vector3 localPos = KSPUtil.ParseVector3(sectionPosNode.GetValue("localPos"));
             savedSectionsLocalPos.Add(index, localPos);
         }
     }
 }
Example #5
0
 private void _setToPos()
 {
     try
     {
         var nPos = KSPUtil.ParseVector3(this._targetPos);
         this._setToPos(nPos);
     }
     catch (Exception e)
     {
         Debug.Log("set to pos throw exception: " + e.Message);
         OSD.PostMessageUpperCenter("[NH] unable to set position, please check vector format");
     }
 }
            public Strut(Part part, string[] parms)
            {
                gameObject = part.gameObject;
                if (part is StrutConnector)
                {
                    maxLength = ((StrutConnector)part).maxLength;
                }
                else if (part is FuelLine)
                {
                    maxLength = ((FuelLine)part).maxLength;
                }
                else
                {
                    // not expected to happen, but...
                    maxLength = 10;
                }
                for (int i = 0; i < parms.Length; i++)
                {
                    string[] keyval = parms[i].Split(':');
                    string   Key    = keyval[0].Trim();
                    string   Value  = keyval[1].Trim();
                    if (Key == "tgt")
                    {
                        //targetName = Value.Split ('_')[0];
                    }
                    else if (Key == "pos")
                    {
                        pos = KSPUtil.ParseVector3(Value);
                    }
                    else if (Key == "dir")
                    {
                        dir = KSPUtil.ParseVector3(Value);
                    }
                }
                target = null;
                Transform  xform = gameObject.transform;
                RaycastHit hitInfo;
                Vector3    castPos = xform.TransformPoint(pos);
                Vector3    castDir = xform.TransformDirection(dir);

                if (Physics.Raycast(castPos, castDir, out hitInfo,
                                    maxLength))
                {
                    GameObject hit = hitInfo.collider.gameObject;
                    target = EditorLogic.GetComponentUpwards <Part>(hit);
                }
                //Debug.Log (String.Format ("[EL] {0} {1} {2} {3}", target,
                //						  targetName, xform.position,
                //						  xform.rotation));
            }
Example #7
0
        void _setToPos()
        {
            try
            {
                var nPos = KSPUtil.ParseVector3(_targetPos);

                _setToPos(nPos);
            }
            catch (Exception e)
            {
                Debug.Log("[NH]: setToPos threw exception: " + e.Message);

                OSD.PostMessageUpperCenter("NodeHelper: Unable to set attachment node position, please check vector format!");
            }
        }
Example #8
0
 private void _orientNodeToCust()
 {
     if (this._selectedNode == null)
     {
         return;
     }
     try
     {
         var custOr = KSPUtil.ParseVector3(this._nodeOrientationCust);
         this._selectedNode.orientation = custOr;
     }
     catch (Exception)
     {
         OSD.PostMessageUpperCenter("[NH] unable to set node orientation, please check vector format");
     }
 }
Example #9
0
        void _orientNodeToCust()
        {
            if (_selectedNode == null)
            {
                return;
            }

            try
            {
                var custOr = KSPUtil.ParseVector3(_nodeOrientationCust);

                _selectedNode.orientation = custOr;
            }
            catch (Exception)
            {
                OSD.PostMessageUpperCenter("NodeHelper: Unable to set attachment node orientation, please check vector format!");
            }
        }
Example #10
0
        public static bool setSite(ConfigNode KSC)
        {
            bool          hasChanged = false;
            double        dtmp;
            float         ftmp;
            bool          btmp;
            CelestialBody Kerbin   = getKSCBody();
            var           mods     = Kerbin.pqsController.transform.GetComponentsInChildren(typeof(PQSMod), true);
            ConfigNode    pqsCity  = KSC.GetNode("PQSCity");
            ConfigNode    pqsDecal = KSC.GetNode("PQSMod_MapDecalTangent");

            if (pqsCity == null)
            {
                return(false);
            }

            foreach (var m in mods)
            {
                if (m.GetType().ToString().Equals("PQSCity"))
                {
                    PQSCity mod = m as PQSCity;
                    if (pqsCity.HasValue("KEYname"))
                    {
                        if (!(mod.name.Equals(pqsCity.GetValue("KEYname"))))
                        {
                            continue;
                        }
                    }
                    if (pqsCity.HasValue("repositionRadial"))
                    {
                        mod.repositionRadial = KSPUtil.ParseVector3(pqsCity.GetValue("repositionRadial"));
                    }
                    if (pqsCity.HasValue("latitude") && pqsCity.HasValue("longitude"))
                    {
                        double lat, lon;
                        double.TryParse(pqsCity.GetValue("latitude"), out lat);
                        double.TryParse(pqsCity.GetValue("longitude"), out lon);

                        mod.repositionRadial = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius);
                    }
                    if (pqsCity.HasValue("reorientInitialUp"))
                    {
                        mod.reorientInitialUp = KSPUtil.ParseVector3(pqsCity.GetValue("reorientInitialUp"));
                    }
                    if (pqsCity.HasValue("repositionToSphere"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphere"), out btmp))
                        {
                            mod.repositionToSphere = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionToSphereSurface"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurface"), out btmp))
                        {
                            mod.repositionToSphereSurface = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionToSphereSurfaceAddHeight"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurfaceAddHeight"), out btmp))
                        {
                            mod.repositionToSphereSurfaceAddHeight = btmp;
                        }
                    }
                    if (pqsCity.HasValue("reorientToSphere"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("reorientToSphere"), out btmp))
                        {
                            mod.reorientToSphere = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionRadiusOffset"))
                    {
                        if (double.TryParse(pqsCity.GetValue("repositionRadiusOffset"), out dtmp))
                        {
                            mod.repositionRadiusOffset = dtmp;
                        }
                    }
                    if (pqsCity.HasValue("lodvisibleRangeMult"))
                    {
                        if (double.TryParse(pqsCity.GetValue("lodvisibleRangeMult"), out dtmp))
                        {
                            foreach (PQSCity.LODRange l in mod.lod)
                            {
                                l.visibleRange *= (float)dtmp;
                            }
                        }
                    }
                    if (pqsCity.HasValue("reorientFinalAngle"))
                    {
                        if (float.TryParse(pqsCity.GetValue("reorientFinalAngle"), out ftmp))
                        {
                            mod.reorientFinalAngle = ftmp;
                        }
                    }
                    print("*RSS* changed PQSCity");

                    hasChanged = true;
                    mod.OnSetup();
                    mod.OnPostSetup();
                    SpaceCenter.Instance.transform.localPosition = mod.transform.localPosition;
                    SpaceCenter.Instance.transform.localRotation = mod.transform.localRotation;
                }

                // KSC Flat area
                if (pqsDecal != null && m.GetType().ToString().Equals("PQSMod_MapDecalTangent"))
                {
                    // thanks to asmi for this!
                    PQSMod_MapDecalTangent mod = m as PQSMod_MapDecalTangent;
                    if (pqsDecal.HasValue("position"))
                    {
                        mod.position = KSPUtil.ParseVector3(pqsDecal.GetValue("position"));
                    }
                    if (pqsDecal.HasValue("radius"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("radius"), out dtmp))
                        {
                            mod.radius = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("heightMapDeformity"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("heightMapDeformity"), out dtmp))
                        {
                            mod.heightMapDeformity = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("absoluteOffset"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("absoluteOffset"), out dtmp))
                        {
                            mod.absoluteOffset = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("absolute"))
                    {
                        if (bool.TryParse(pqsDecal.GetValue("absolute"), out btmp))
                        {
                            mod.absolute = btmp;
                        }
                    }
                    if (pqsDecal.HasValue("latitude") && pqsDecal.HasValue("longitude"))
                    {
                        double lat, lon;
                        double.TryParse(pqsDecal.GetValue("latitude"), out lat);
                        double.TryParse(pqsDecal.GetValue("longitude"), out lon);

                        mod.position = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius);
                    }
                    print("*RSS* changed MapDecal_Tangent");

                    hasChanged = true;
                    mod.OnSetup();
                }
            }

            if (hasChanged)
            {
                Kerbin.pqsController.RebuildSphere();
            }

            return(hasChanged);
        }
Example #11
0
        public static bool setSite(ConfigNode KSC)
        {
            bool   hasChanged = false;
            double dtmp;
            float  ftmp;
            bool   btmp;

            ConfigNode pqsCity = KSC.GetNode("PQSCity");

            if (pqsCity == null)
            {
                return(false);
            }
            ConfigNode    pqsDecal = KSC.GetNode("PQSMod_MapDecalTangent");
            CelestialBody home     = getKSCBody();

            PQSCity ksc = findKSC(home);

            if (ksc != null)
            {
                if (pqsCity.HasValue("KEYname"))
                {
                    if (!(ksc.name.Equals(pqsCity.GetValue("KEYname"))))
                    {
                        Debug.Log("KSCSwitcher: Could not retrieve KSC to move, reporting failure and moving on.");
                        return(false);
                    }
                }
                if (pqsCity.HasValue("repositionRadial"))
                {
                    ksc.repositionRadial = KSPUtil.ParseVector3(pqsCity.GetValue("repositionRadial"));
                }
                if (pqsCity.HasValue("latitude") && pqsCity.HasValue("longitude"))
                {
                    double lat, lon;
                    double.TryParse(pqsCity.GetValue("latitude"), out lat);
                    double.TryParse(pqsCity.GetValue("longitude"), out lon);

                    ksc.repositionRadial = KSCSwitcher.LLAtoECEF(lat, lon, 0, home.Radius);
                }
                if (pqsCity.HasValue("reorientInitialUp"))
                {
                    ksc.reorientInitialUp = KSPUtil.ParseVector3(pqsCity.GetValue("reorientInitialUp"));
                }
                if (pqsCity.HasValue("repositionToSphere"))
                {
                    if (bool.TryParse(pqsCity.GetValue("repositionToSphere"), out btmp))
                    {
                        ksc.repositionToSphere = btmp;
                    }
                }
                if (pqsCity.HasValue("repositionToSphereSurface"))
                {
                    if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurface"), out btmp))
                    {
                        ksc.repositionToSphereSurface = btmp;
                    }
                }
                if (pqsCity.HasValue("repositionToSphereSurfaceAddHeight"))
                {
                    if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurfaceAddHeight"), out btmp))
                    {
                        ksc.repositionToSphereSurfaceAddHeight = btmp;
                    }
                }
                if (pqsCity.HasValue("reorientToSphere"))
                {
                    if (bool.TryParse(pqsCity.GetValue("reorientToSphere"), out btmp))
                    {
                        ksc.reorientToSphere = btmp;
                    }
                }
                if (pqsCity.HasValue("repositionRadiusOffset"))
                {
                    if (double.TryParse(pqsCity.GetValue("repositionRadiusOffset"), out dtmp))
                    {
                        ksc.repositionRadiusOffset = dtmp;
                    }
                }
                if (pqsCity.HasValue("lodvisibleRangeMult"))
                {
                    if (double.TryParse(pqsCity.GetValue("lodvisibleRangeMult"), out dtmp))
                    {
                        foreach (PQSCity.LODRange l in ksc.lod)
                        {
                            l.visibleRange *= (float)dtmp;
                        }
                    }
                }
                if (pqsCity.HasValue("reorientFinalAngle"))
                {
                    if (float.TryParse(pqsCity.GetValue("reorientFinalAngle"), out ftmp))
                    {
                        ksc.reorientFinalAngle = ftmp;
                    }
                }
                print("KSCSwitcher changed PQSCity");

                hasChanged = true;
                ksc.OnSetup();
                ksc.OnPostSetup();
                SpaceCenter.Instance.transform.localPosition = ksc.transform.localPosition;
                SpaceCenter.Instance.transform.localRotation = ksc.transform.localRotation;
            }
            else
            {
                Debug.LogError("KSCSwitcher: Could not retrieve KSC to move, reporting failure and moving on.");
                return(false);
            }

            PQSMod_MapDecalTangent decal = findKSCMapDecal(home);

            if (decal != null && pqsDecal != null)
            {
                // KSC Flat area
                if (pqsDecal.HasValue("position"))
                {
                    decal.position = KSPUtil.ParseVector3(pqsDecal.GetValue("position"));
                }
                if (pqsDecal.HasValue("radius"))
                {
                    if (double.TryParse(pqsDecal.GetValue("radius"), out dtmp))
                    {
                        decal.radius = dtmp;
                    }
                }
                if (pqsDecal.HasValue("heightMapDeformity"))
                {
                    if (double.TryParse(pqsDecal.GetValue("heightMapDeformity"), out dtmp))
                    {
                        decal.heightMapDeformity = dtmp;
                    }
                }
                if (pqsDecal.HasValue("absoluteOffset"))
                {
                    if (double.TryParse(pqsDecal.GetValue("absoluteOffset"), out dtmp))
                    {
                        decal.absoluteOffset = dtmp;
                    }
                }
                if (pqsDecal.HasValue("absolute"))
                {
                    if (bool.TryParse(pqsDecal.GetValue("absolute"), out btmp))
                    {
                        decal.absolute = btmp;
                    }
                }
                if (pqsDecal.HasValue("latitude") && pqsDecal.HasValue("longitude"))
                {
                    double lat, lon;
                    double.TryParse(pqsDecal.GetValue("latitude"), out lat);
                    double.TryParse(pqsDecal.GetValue("longitude"), out lon);

                    decal.position = KSCSwitcher.LLAtoECEF(lat, lon, 0, home.Radius);
                }
                print("KSCSwitcher changed MapDecal_Tangent");

                hasChanged = true;
                decal.OnSetup();
            }

            if (hasChanged)
            {
                SpaceCenter.Instance.Start();                  // 1.0.5
                if (KSC.HasValue("name"))
                {
                    KSCLoader.instance.Sites.lastSite = LastKSC.fetch.lastSite = KSC.GetValue("name");
                    print("KSCSwitcher changed MapDecal_Tangent");
                }
            }

            return(hasChanged);
        }
Example #12
0
        /// <summary>Fixes incorrect part icon in the editor's parts list panel for every part which has a KFIconOverride node.
        /// The node can have several attributes.
        /// Example:
        /// KFIconOverride
        /// {
        ///     Multiplier = 1.0      // for finetuning icon zoom
        ///     Pivot = transformName // transform to rotate around; rotates around CoM if not specified
        ///     Rotation = vector     // offset to rotation point
        /// }
        /// All parameters are optional. The existence of an KFIconOverride node is enough to fix the icon.
        /// Example:
        /// KFIconOverride {}
        /// </summary>
        /// <param name="partToFix">part to fix</param>
        /// <remarks>This method uses code from xEvilReepersx's PartIconFixer.
        /// See https://bitbucket.org/xEvilReeperx/ksp_particonfixer/src/7f2ac4094c19?at=master for original code and license.</remarks>
        void FixPartIcon(AvailablePart partToFix)
        {
            Vector3 rotation;
            float   factor, max, multiplier;

            KFLog.Log(string.Format("Fixing icon of \"{0}\"", partToFix.name));

            // Preparations.
            GameObject partToFixIconPrefab = partToFix.iconPrefab;
            Bounds     bounds = CalculateBounds(partToFixIconPrefab);

            // Retrieve icon fixes from cfg and calculate max part size.
            max        = Mathf.Max(bounds.size.x, bounds.size.y, bounds.size.z);
            multiplier = 1f;

            if (HasKFIconOverrideMultiplier(partToFix))
            {
                float.TryParse(partToFix.partConfig.GetNode("KFIconOverride").GetValue("Multiplier"), out multiplier);
            }

            factor  = 40f / max * multiplier;
            factor /= 40f;

            string pivot = string.Empty;

            if (HasKFIconOverridePivot(partToFix))
            {
                pivot = partToFix.partConfig.GetNode("KFIconOverride").GetValue("Pivot");
            }

            rotation = Vector3.zero;
            if (HasKFIconOverrideRotation(partToFix))
            {
                rotation = KSPUtil.ParseVector3(partToFix.partConfig.GetNode("KFIconOverride").GetValue("Rotation"));
            }

            // Apply icon fixes.
            partToFix.iconScale = max;

            // affects only the meter scale in the tooltip.
            partToFixIconPrefab.transform.GetChild(0).localScale *= factor;
            partToFixIconPrefab.transform.GetChild(0).Rotate(rotation, Space.Self);

            // After applying the fixes the part could be off-center, correct this now.
            if (string.IsNullOrEmpty(pivot))
            {
                Transform model, target;

                model = partToFixIconPrefab.transform.GetChild(0).Find("model");
                if (Equals(model, null))
                {
                    model = partToFixIconPrefab.transform.GetChild(0);
                }

                target = model.Find(pivot);
                if (!Equals(target, null))
                {
                    partToFixIconPrefab.transform.GetChild(0).position -= target.position;
                }
            }
            else
            {
                partToFixIconPrefab.transform.GetChild(0).localPosition = Vector3.zero;
            }
        }
Example #13
0
        public void Load()
        {
            Debug.Log("[PR] Loading Data.");

            //This is called when all persistent rotation data is being loaded from the cfg file.

            #region ### Quicksave selection ###
            ConfigNode temp        = null;
            float      temp_delta  = 0f;
            ConfigNode load        = null;
            float      load_delta  = 0f;
            float      oldest_time = 0f;

            List <String> allPaths = GetAllPaths();

            if (allPaths.Count() == 0)
            {
                Debug.Log("[PR] No save files found.");
                return;
            }

            foreach (String path in allPaths)
            {
                temp = ConfigNode.Load(path);
                if (temp == null)
                {
                    Debug.Log("[PR] Couldn't load data: File not found.");
                    continue;
                }


                float time = float.Parse(temp.GetValue("TIME"));
                temp_delta = Mathf.Abs(time - (float)Planetarium.GetUniversalTime());

                if (time > oldest_time)
                {
                    oldest_time = time;
                }

                if (load == null)
                {
                    load       = temp;
                    load_delta = temp_delta;
                }
                else
                {
                    if (temp_delta < load_delta)
                    {
                        load       = temp;
                        load_delta = temp_delta;
                    }
                }
            }
            #endregion

            //Load global variables

            defaultReferenceMode = (DefaultReferenceMode)(int.Parse(load.GetValue("DEFAULT_REFERENCE_MODE")));

            //Pregenerate data for all vessels that currently exist

            foreach (Vessel vessel in FlightGlobals.Vessels)
            {
                FindPRVessel(vessel);
            }

            //All vessels should now have data.

            //Load PRVessel data

            foreach (PRVessel v in PRVessels)
            {
                ConfigNode cn_vessel = load.GetNode(v.vessel.id.ToString());

                if (cn_vessel != null) //If node exists at all
                {
                    Debug.Log("[PR] Found node for vessel " + v.vessel.vesselName);
                    v.momentum           = KSPUtil.ParseVector3(cn_vessel.GetValue("MOMENTUM"));
                    v.planetariumRight   = KSPUtil.ParseVector3(cn_vessel.GetValue("PLANETARIUM_RIGHT"));
                    v.mjMode             = MechJebWrapper.saTargetMap[int.Parse(cn_vessel.GetValue("MJMODE"))];
                    v.rtMode             = RemoteTechWrapper.acFlightModeMap[int.Parse(cn_vessel.GetValue("RTMODE"))];
                    v.rotationModeActive = Boolean.Parse(cn_vessel.GetValue("ROTATION_MODE_ACTIVE"));
                    v.dynamicReference   = Boolean.Parse(cn_vessel.GetValue("DYNAMIC_REFERENCE"));
                    v.rotation           = KSPUtil.ParseQuaternion(cn_vessel.GetValue("ROTATION"));
                    v.direction          = KSPUtil.ParseVector3(cn_vessel.GetValue("DIRECTION"));

                    string reference = cn_vessel.GetValue("REFERENCE");

                    v.reference = null;

                    if (reference != "NONE")
                    {
                        foreach (CelestialBody body in FlightGlobals.Bodies)
                        {
                            if (body.name == reference)
                            {
                                v.reference = body;
                            }
                        }

                        foreach (Vessel vessel in FlightGlobals.Vessels)
                        {
                            if (vessel.id.ToString() == reference)
                            {
                                v.reference = vessel;
                            }
                        }
                    }

                    v.momentumModeActive = Boolean.Parse(cn_vessel.GetValue("MOMENTUM_MODE_ACTIVE"));
                    v.desiredRPM         = float.Parse(cn_vessel.GetValue("DESIRED_RPM"));
                }
            }

            //If old save state is loaded, delete all save files!
            if (float.Parse(load.GetValue("TIME")) < oldest_time)
            {
                Debug.Log("[PR] Reloading old save, flushing data.");

                foreach (String path in GetAllPaths())
                {
                    File.Delete(path);
                }

                //Save current loaded one.
                Save();
            }

            //TODO: Delete all files on Launch / Keep all files that correspond to a quicksave

            Debug.Log("[PR] Oldest time: " + oldest_time.ToString());
            Debug.Log("[PR] Loaded time: " + load.GetValue("TIME"));

            Interface.instance.desiredRPMstr = FindPRVessel(FlightGlobals.ActiveVessel).desiredRPM.ToString(); //Set desired rpm of active vessel
        }
Example #14
0
        // Load all RDNode keys from config node.
        public void Load(ConfigNode node)
        {
            // RDNode keys.
            if (node.HasValue("id"))
            {
                this.techID = node.GetValue("id");
            }

            // KTT compatibility.
            if (node.HasValue("tier"))
            {
                this.tier = float.Parse(node.GetValue("tier"));
            }

            if (node.HasValue("title"))
            {
                this.title = node.GetValue("title");
            }

            if (node.HasValue("description"))
            {
                this.description = node.GetValue("description");
            }

            if (node.HasValue("cost"))
            {
                this.scienceCost = int.Parse(node.GetValue("cost"));
            }

            if (node.HasValue("hideEmpty"))
            {
                this.hideIfNoParts = bool.Parse(node.GetValue("hideEmpty"));
            }

            if (node.HasValue("nodeName"))
            {
                this.nodeName = node.GetValue("nodeName");
            }
            if (String.IsNullOrEmpty(this.nodeName))
            {
                this.nodeName = this.techID;
            }

            if (node.HasValue("anyToUnlock"))
            {
                this.AnyParentToUnlock = bool.Parse(node.GetValue("anyToUnlock"));
            }

            if (node.HasValue("icon"))
            {
                this.iconRef = node.GetValue("icon");
            }

            if (node.HasValue("pos"))
            {
                this.pos = KSPUtil.ParseVector3(node.GetValue("pos"));
            }

            if (node.HasValue("scale"))
            {
                this.scale = float.Parse(node.GetValue("scale"));
            }

            this.GetPartsAssigned();
            if (this.partsAssigned != null)
            {
                this.PartsInTotal = this.partsAssigned.Count;
            }
            else
            {
                this.PartsInTotal = 0;
            }

            // ETT fix 2 of 5.
            this.LoadUnlocks(node);
        }
Example #15
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
            //node and value names are compatible with ModuleGrappleNode
            //deprecated config conversion
            var vinfo = node.GetNode("THISVESSEL") ?? node.GetNode("DOCKEDVESSEL");

            if (vinfo != null)
            {
                this_vessel = new DockedVesselInfo();
                this_vessel.Load(vinfo);
            }
            //deprecated config conversion
            vinfo = node.GetNode("DOCKEDVESSEL_Other") ?? node.GetNode("DOCKEDVESSEL");
            if (vinfo != null)
            {
                docked_vessel = new DockedVesselInfo();
                docked_vessel.Load(vinfo);
            }
            if (node.HasValue("dockUId"))
            {
                dockedPartUId = uint.Parse(node.GetValue("dockUId"));
            }
            GrappleRangeSqr = GrappleRange * GrappleRange;
            DockRangeSqr    = DockRange * DockRange;
            //load grapple attach node
            if (HighLogic.LoadedSceneIsFlight)
            {
                grappleNode               = new AttachNode();
                grappleNode.size          = 1;
                grappleNode.id            = "grapple";
                grappleNode.rigid         = true;
                grappleNode.ResourceXFeed = true;
                grappleNode.attachMethod  = AttachNodeMethod.FIXED_JOINT;
                grappleNode.breakingForce = grappleNode.breakingTorque = float.PositiveInfinity;
            }
            if (node.HasValue("grapplePos"))
            {
                grapplePos = KSPUtil.ParseVector3(node.GetValue("grapplePos"));
            }
            if (node.HasValue("grappleOrt"))
            {
                grappleOrt = KSPUtil.ParseVector3(node.GetValue("grappleOrt"));
            }
            if (node.HasValue("grappleOrt2"))
            {
                grappleOrt2 = KSPUtil.ParseVector3(node.GetValue("grappleOrt2"));
            }
            //deprecated config conversion
            if (node.HasValue("Fixed"))
            {
                if (bool.Parse(node.GetValue("Fixed")))
                {
                    state = State.Fixed;
                }
                else if (dockedPartUId > 0)
                {
                    state = State.Docked;
                }
                else
                {
                    armAnimator = part.GetAnimator <MultiAnimator>(ArmAnimatorID);
                    if (armAnimator != null &&
                        armAnimator.State == AnimatorState.Opened)
                    {
                        state = State.Armed;
                    }
                    else
                    {
                        state = State.Idle;
                    }
                }
            }
        }
Example #16
0
        public void setSite(string name)
        {
            ConfigNode site = getSite(name);

            if (site == null)
            {
                return;
            }

            bool          hasChanged = false;
            double        dtmp;
            float         ftmp;
            bool          btmp;
            CelestialBody Kerbin = FlightGlobals.Bodies.Find(body => body.name == "Kerbin");

            if (Kerbin == null)
            {
                Kerbin = FlightGlobals.Bodies.Find(body => body.name == "Earth"); // temp fix
            }
            var        mods     = Kerbin.pqsController.transform.GetComponentsInChildren(typeof(PQSMod), true);
            ConfigNode pqsCity  = site.GetNode("PQSCity");
            ConfigNode pqsDecal = site.GetNode("PQSMod_MapDecalTangent");

            if (pqsCity == null)
            {
                return;
            }

            foreach (var m in mods)
            {
                if (m.GetType().ToString().Equals("PQSCity"))
                {
                    PQSCity mod = m as PQSCity;
                    if (pqsCity.HasValue("KEYname"))
                    {
                        if (!(mod.name.Equals(pqsCity.GetValue("KEYname"))))
                        {
                            continue;
                        }
                    }
                    if (pqsCity.HasValue("repositionRadial"))
                    {
                        mod.repositionRadial = KSPUtil.ParseVector3(pqsCity.GetValue("repositionRadial"));
                    }
                    if (pqsCity.HasValue("latitude") && pqsCity.HasValue("longitude"))
                    {
                        double lat, lon;
                        double.TryParse(pqsCity.GetValue("latitude"), out lat);
                        double.TryParse(pqsCity.GetValue("longitude"), out lon);

                        mod.repositionRadial = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius);
                    }
                    if (pqsCity.HasValue("reorientInitialUp"))
                    {
                        mod.reorientInitialUp = KSPUtil.ParseVector3(pqsCity.GetValue("reorientInitialUp"));
                    }
                    if (pqsCity.HasValue("repositionToSphere"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphere"), out btmp))
                        {
                            mod.repositionToSphere = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionToSphereSurface"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurface"), out btmp))
                        {
                            mod.repositionToSphereSurface = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionToSphereSurfaceAddHeight"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurfaceAddHeight"), out btmp))
                        {
                            mod.repositionToSphereSurfaceAddHeight = btmp;
                        }
                    }
                    if (pqsCity.HasValue("reorientToSphere"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("reorientToSphere"), out btmp))
                        {
                            mod.reorientToSphere = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionRadiusOffset"))
                    {
                        if (double.TryParse(pqsCity.GetValue("repositionRadiusOffset"), out dtmp))
                        {
                            mod.repositionRadiusOffset = dtmp;
                        }
                    }
                    if (pqsCity.HasValue("lodvisibleRangeMult"))
                    {
                        if (double.TryParse(pqsCity.GetValue("lodvisibleRangeMult"), out dtmp))
                        {
                            foreach (PQSCity.LODRange l in mod.lod)
                            {
                                l.visibleRange *= (float)dtmp;
                            }
                        }
                    }
                    if (pqsCity.HasValue("reorientFinalAngle"))
                    {
                        if (float.TryParse(pqsCity.GetValue("reorientFinalAngle"), out ftmp))
                        {
                            mod.reorientFinalAngle = ftmp;
                        }
                    }
                    print("*RSS* changed PQSCity");

                    hasChanged = true;
                    mod.OnSetup();
                }

                // KSC Flat area
                if (pqsDecal != null && m.GetType().ToString().Equals("PQSMod_MapDecalTangent"))
                {
                    // thanks to asmi for this!
                    PQSMod_MapDecalTangent mod = m as PQSMod_MapDecalTangent;
                    if (pqsDecal.HasValue("position"))
                    {
                        mod.position = KSPUtil.ParseVector3(pqsDecal.GetValue("position"));
                    }
                    if (pqsDecal.HasValue("radius"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("radius"), out dtmp))
                        {
                            mod.radius = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("heightMapDeformity"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("heightMapDeformity"), out dtmp))
                        {
                            mod.heightMapDeformity = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("absoluteOffset"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("absoluteOffset"), out dtmp))
                        {
                            mod.absoluteOffset = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("absolute"))
                    {
                        if (bool.TryParse(pqsDecal.GetValue("absolute"), out btmp))
                        {
                            mod.absolute = btmp;
                        }
                    }
                    if (pqsDecal.HasValue("latitude") && pqsDecal.HasValue("longitude"))
                    {
                        double lat, lon;
                        double.TryParse(pqsDecal.GetValue("latitude"), out lat);
                        double.TryParse(pqsDecal.GetValue("longitude"), out lon);

                        mod.position = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius);
                    }
                    print("*RSS* changed MapDecal_Tangent");

                    hasChanged = true;
                    mod.OnSetup();
                }

                if (hasChanged)
                {
                    print("*RSS* Rebuilding");
                    Kerbin.pqsController.RebuildSphere();
                    ScreenMessages.PostScreenMessage("Launch site changed to " + name, 2.5f, ScreenMessageStyle.LOWER_CENTER);
                    showWindow = false;
                    print("*RSS* Launch site change DONE");
                }
            }
        }