Example #1
0
        private ConfigNode FromInFlightVessel(Vessel VesselToSave, ListType listType)
        {
            //This code is taken from InflightShipSave by Claw, using the CC-BY-NC-SA license.
            //This code thus is licensed under the same license, despite the GPLv3 license covering original KCT code
            //See https://github.com/ClawKSP/InflightShipSave

            string        ShipName        = VesselToSave.vesselName;
            ShipConstruct ConstructToSave = new ShipConstruct(ShipName, "", VesselToSave.parts[0]);

            Quaternion OriginalRotation = VesselToSave.vesselTransform.rotation;
            Vector3    OriginalPosition = VesselToSave.vesselTransform.position;

            if (listType == ListType.SPH)
            {
                VesselToSave.SetRotation(new Quaternion((float)Math.Sqrt(0.5), 0, 0, (float)Math.Sqrt(0.5)));
            }
            else
            {
                VesselToSave.SetRotation(new Quaternion(0, 0, 0, 1));
            }
            Vector3 ShipSize = ShipConstruction.CalculateCraftSize(ConstructToSave);

            VesselToSave.SetPosition(new Vector3(0, Math.Min(ShipSize.y + 2, 15), 0));    //Try to limit the max height we put the ship at

            ConfigNode cn = ConstructToSave.SaveShip();

            SanitizeShipNode(cn);
            // override KSP sizing of the ship construct
            cn.SetValue("size", KSPUtil.WriteVector(Utilities.GetShipSize(ConstructToSave, true)));
            // These are actually needed, do not comment them out
            VesselToSave.SetRotation(OriginalRotation);
            VesselToSave.SetPosition(OriginalPosition);
            //End of Claw's code. Thanks Claw!
            return(cn);
        }
Example #2
0
        public bool CanLaunchVessel(KCT_BuildListVessel vessel, out string reason)
        {
            if (vessel == null)
            {
                reason = "No vessel";
                return(false);
            }
            double mass = vessel.GetTotalMass();

            if (mass > MaxMass)
            {
                reason = $"mass ({mass:0.#}t) is higher than the allowed {MaxMass:0.#}";
                return(false);
            }

            ShipTemplate template = new ShipTemplate();

            template.LoadShip(vessel.shipNode);
            Vector3 dimensions = ShipConstruction.CalculateCraftSize(template);

            if (dimensions.x > MaxSize.x | dimensions.y > MaxSize.y | dimensions.z > MaxSize.z)
            {
                reason = $"size ({dimensions.x:0.#} x {dimensions.y:0.#} x {dimensions.z:0.#} m) is more than the allowed {MaxSize.x:0.#} x {MaxSize.y:0.#} x {MaxSize.z:0.#} m";
                return(false);
            }

            reason = null;
            return(true);
        }
Example #3
0
        public static string TemporarySaveVessel(Vessel VesselToSave)
        {
            string ShipName = VesselToSave.vesselName;

            ShipConstruct ConstructToSave = new ShipConstruct(ShipName, "", VesselToSave.parts[0]);

            Quaternion OriginalRotation = VesselToSave.vesselTransform.rotation;
            Vector3    OriginalPosition = VesselToSave.vesselTransform.position;

            VesselToSave.SetRotation(new Quaternion(0, 0, 0, 1));
            Vector3 ShipSize = ShipConstruction.CalculateCraftSize(ConstructToSave);

            VesselToSave.SetPosition(new Vector3(0, ShipSize.y + 2, 0));

            ConfigNode CN = new ConfigNode("ShipConstruct");

            CN = ConstructToSave.SaveShip();

            VesselToSave.SetRotation(OriginalRotation);
            VesselToSave.SetPosition(OriginalPosition);

            string filename = UrlDir.ApplicationRootPath + "GameData/FlightEdit/temp.craft";

            CN.Save(filename);
            return(filename);
        }
Example #4
0
        private ConfigNode FromInFlightVessel(Vessel VesselToSave)
        {
            //This code is taken from InflightShipSave by Claw, using the CC-BY-NC-SA license.
            //This code thus is licensed under the same license, despite the GPLv3 license covering original KCT code
            //See https://github.com/ClawKSP/InflightShipSave

            string ShipName = VesselToSave.vesselName;
            // Debug.LogWarning("Saving: " + ShipName);

            ShipConstruct ConstructToSave = new ShipConstruct(ShipName, "", VesselToSave.parts[0]);

            Quaternion OriginalRotation = VesselToSave.vesselTransform.rotation;
            Vector3    OriginalPosition = VesselToSave.vesselTransform.position;

            VesselToSave.SetRotation(new Quaternion(0, 0, 0, 1));
            Vector3 ShipSize = ShipConstruction.CalculateCraftSize(ConstructToSave);

            VesselToSave.SetPosition(new Vector3(0, ShipSize.y + 2, 0));

            ConfigNode CN = new ConfigNode("ShipConstruct");

            CN = ConstructToSave.SaveShip();
            SanitizeShipNode(CN);

            VesselToSave.SetRotation(OriginalRotation);
            VesselToSave.SetPosition(OriginalPosition);
            //End of Claw's code. Thanks Claw!
            return(CN);
        }
Example #5
0
        public void Save()
        {
            if (!Directory.Exists(UrlDir.ApplicationRootPath + "GameData/OrXHoloCache/" + HoloCacheName))
            {
                Directory.CreateDirectory(UrlDir.ApplicationRootPath + "GameData/OrXHoloCache/" + HoloCacheName);
            }

            ShipName = VesselToSave.vesselName;

            if (holo)
            {
                Debug.Log("[OrX Ship Save] HoloCache Identified .......................");
                shipDescription = "HoloCache";
            }
            else
            {
                Debug.Log("[OrX Ship Save] Vessel Identified .......................");

                shipDescription = "";
            }
            ShipConstruct ConstructToSave = new ShipConstruct(ShipName, shipDescription, VesselToSave.parts[0]);

            Debug.Log("[OrX Ship Save] Saving: " + ShipName + " ............");

            ScreenMsg("<color=#cfc100ff><b>Saving: " + ShipName + "</b></color>");

            Quaternion OriginalRotation = VesselToSave.vesselTransform.rotation;
            Vector3    OriginalPosition = VesselToSave.vesselTransform.position;

            VesselToSave.SetRotation(new Quaternion(0, 0, 0, 1));
            Vector3 ShipSize = ShipConstruction.CalculateCraftSize(ConstructToSave);

            VesselToSave.SetPosition(new Vector3(0, ShipSize.y + 2, 0));

            ConfigNode CN = new ConfigNode("ShipConstruct");

            CN = ConstructToSave.SaveShip();
            CleanEditorNodes(CN);

            VesselToSave.SetRotation(OriginalRotation);
            VesselToSave.SetPosition(OriginalPosition);

            Debug.Log("Facility: " + ConstructToSave.shipFacility);

            Debug.Log("[OrX Ship Save] Saving: " + UrlDir.ApplicationRootPath + "GameData/OrXHoloCache/" + HoloCacheName + "/" + ShipName + ".craft");
            CN.Save(UrlDir.ApplicationRootPath + "GameData/OrXHoloCache/" + HoloCacheName + "/" + ShipName + ".craft");

            ScreenMsg("<color=#cfc100ff><b>" + ShipName + " Saved to GameData/OrXHoloCache/" + HoloCacheName + "</b></color>");
            if (sthTargets)
            {
                sthTargets = false;
            }
            saveShip = false;
            holo     = true;
        }
Example #6
0
        IEnumerator SaveDelayRoutine()
        {
            yield return(new WaitForSeconds(2));

            if (HighLogic.LoadedSceneIsFlight && !FlightGlobals.ActiveVessel.HoldPhysics)
            {
                Debug.Log("[OrX Ship Save] Active Vessel Identified .......................");

                VesselToSave    = FlightGlobals.ActiveVessel;
                ShipName        = FlightGlobals.ActiveVessel.vesselName;
                shipDescription = "_Rescued";

                ShipConstruct ConstructToSave = new ShipConstruct(ShipName, shipDescription, VesselToSave.parts[0]);

                Debug.Log("[OrX Ship Save] Saving: " + ShipName + " ............");

                ScreenMsg("<color=#cfc100ff><b>Saving: " + ShipName + "</b></color>");

                Quaternion OriginalRotation = VesselToSave.vesselTransform.rotation;
                Vector3    OriginalPosition = VesselToSave.vesselTransform.position;

                VesselToSave.SetRotation(new Quaternion(0, 0, 0, 1));
                Vector3 ShipSize = ShipConstruction.CalculateCraftSize(ConstructToSave);
                VesselToSave.SetPosition(new Vector3(0, ShipSize.y + 2, 0));

                ConfigNode CN = new ConfigNode("ShipConstruct");
                CN = ConstructToSave.SaveShip();
                CleanEditorNodes(CN);

                VesselToSave.SetRotation(OriginalRotation);
                VesselToSave.SetPosition(OriginalPosition);

                Debug.Log("Facility: " + ConstructToSave.shipFacility);

                if (ConstructToSave.shipFacility == EditorFacility.SPH)
                {
                    Debug.Log("Ship Saved: " + UrlDir.ApplicationRootPath + "saves/" + HighLogic.SaveFolder
                              + "/Ships/SPH/" + ShipName + "_Rescued.craft");
                    CN.Save(UrlDir.ApplicationRootPath + "saves/" + HighLogic.SaveFolder
                            + "/Ships/SPH/" + ShipName + "_Rescued.craft");
                }
                else
                {
                    Debug.Log("Ship Saved: " + UrlDir.ApplicationRootPath + "saves/" + HighLogic.SaveFolder
                              + "/Ships/VAB/" + ShipName + "_Rescued.craft");
                    CN.Save(UrlDir.ApplicationRootPath + "saves/" + HighLogic.SaveFolder
                            + "/Ships/VAB/" + ShipName + "_Rescued.craft");
                }
            }
            else
            {
                //Save();
            }
        }
Example #7
0
 public KKPrelaunchSizeCheck(string launchSiteName)
 {
     if (HighLogic.LoadedScene == GameScenes.EDITOR)
     {
         shipSize   = ShipConstruction.CalculateCraftSize(EditorLogic.fetch.ship);
         launchSite = LaunchSiteManager.GetLaunchSiteByName(launchSiteName);
     }
     else
     {
         allowLaunch = true;
     }
 }
Example #8
0
        public VesselInformation CalculateVesselPhysics(Vessel v)
        {
            var mW = v.GetWetMass();
            var mD = v.GetDryMass();

            // Assuming VAB by default..
            Vector3 size = ShipConstruction.CalculateCraftSize(vessel.parts, vessel.rootPart);

            return(new VesselInformation()
            {
                WetMass = mW,
                DryMass = mD,
                Height = size.y,
                Diameter = size.x,
                Width = size.z
            });
        }
Example #9
0
        public static Vector3 TargetCOMDispersion(Vessel v)
        {
            Vector3       TargetCOM_ = new Vector3(0, 0);
            ShipConstruct sc         = new ShipConstruct("ship", "temp ship", v.parts[0]);

            Vector3 size = ShipConstruction.CalculateCraftSize(sc);

            float dispersionMax = size.y;

            //float dispersionMax = 100f;

            float dispersion = Random.Range(0, dispersionMax);

            TargetCOM_ = v.CoM + new Vector3(0, dispersion);

            return(TargetCOM_);
        }
Example #10
0
        private ConfigNode FromInFlightVessel(Vessel VesselToSave, KCT_BuildListVessel.ListType listType)
        {
            //This code is taken from InflightShipSave by Claw, using the CC-BY-NC-SA license.
            //This code thus is licensed under the same license, despite the GPLv3 license covering original KCT code
            //See https://github.com/ClawKSP/InflightShipSave

            string ShipName = VesselToSave.vesselName;
            // Debug.LogWarning("Saving: " + ShipName);

            ShipConstruct ConstructToSave = new ShipConstruct(ShipName, "", VesselToSave.parts[0]);

            Quaternion OriginalRotation = VesselToSave.vesselTransform.rotation;
            Vector3    OriginalPosition = VesselToSave.vesselTransform.position;

            if (listType == ListType.SPH)
            {
                VesselToSave.SetRotation(new Quaternion((float)Math.Sqrt(0.5), 0, 0, (float)Math.Sqrt(0.5)));
            }
            else
            {
                VesselToSave.SetRotation(new Quaternion(0, 0, 0, 1));
            }
            Vector3 ShipSize = ShipConstruction.CalculateCraftSize(ConstructToSave);

            VesselToSave.SetPosition(new Vector3(0, Math.Min(ShipSize.y + 2, 30), 0)); //Try to limit the max height we put the ship at. 60 is good for the VA but I don't know about the SPH. Lets be conservative with 30

            ConfigNode CN = new ConfigNode("ShipConstruct");

            CN = ConstructToSave.SaveShip();
            SanitizeShipNode(CN);
            // These are actually needed, do not comment them out
            VesselToSave.SetRotation(OriginalRotation);
            VesselToSave.SetPosition(OriginalPosition);
            //End of Claw's code. Thanks Claw!
            return(CN);
        }
Example #11
0
        public void VesselToCraftFile(ConfigNode VesselNode)
        {
            //This code is taken from InflightShipSave by Claw, using the CC-BY-NC-SA license.
            //This code thus is licensed under the same license, despite the GPLv3 license covering original KCT code
            //See https://github.com/ClawKSP/InflightShipSave

            ProtoVessel VesselToSave = HighLogic.CurrentGame.AddVessel(VesselNode);

            if (VesselToSave.vesselRef == null)
            {
                Log("Vessel reference is null!");
                return;
            }

            try
            {
                string ShipName = VesselToSave.vesselName;

                //Vessel FromFlight = FlightGlobals.Vessels.Find(v => v.id == VesselToSave.vesselID);
                try
                {
                    VesselToSave.vesselRef.Load();
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                    Log("Attempting to continue.");
                }

                ShipConstruct ConstructToSave  = new ShipConstruct(ShipName, "", VesselToSave.vesselRef.Parts[0]);
                Quaternion    OriginalRotation = VesselToSave.vesselRef.vesselTransform.rotation;
                Vector3       OriginalPosition = VesselToSave.vesselRef.vesselTransform.position;

                VesselToSave.vesselRef.SetRotation(new Quaternion(0, 0, 0, 1));
                Vector3 ShipSize = ShipConstruction.CalculateCraftSize(ConstructToSave);
                VesselToSave.vesselRef.SetPosition(new Vector3(0, ShipSize.y + 2, 0));


                ConfigNode CN = new ConfigNode("ShipConstruct");
                CN = ConstructToSave.SaveShip();
                //SanitizeShipNode(CN);
                CleanEditorNodes(CN);

                //VesselToSave.rotation = OriginalRotation;
                //VesselToSave.position = OriginalPosition;

                if (ConstructToSave.shipFacility == EditorFacility.SPH)
                {
                    CN.Save(UrlDir.ApplicationRootPath + "saves/" + HighLogic.SaveFolder
                            + "/Ships/SPH/" + ShipName + "_Rescued.craft");

                    ScreenMessage message = new ScreenMessage(ShipName + " converted to " + UrlDir.ApplicationRootPath + "saves/" + HighLogic.SaveFolder
                                                              + "/Ships/SPH/" + ShipName + "_Rescued.craft", 6, ScreenMessageStyle.UPPER_CENTER);
                    ScreenMessages.PostScreenMessage(message);
                }
                else
                {
                    CN.Save(UrlDir.ApplicationRootPath + "saves/" + HighLogic.SaveFolder
                            + "/Ships/VAB/" + ShipName + "_Rescued.craft");

                    ScreenMessage message = new ScreenMessage(ShipName + " converted to " + UrlDir.ApplicationRootPath + "saves/" + HighLogic.SaveFolder
                                                              + "/Ships/VAB/" + ShipName + "_Rescued.craft", 6, ScreenMessageStyle.UPPER_CENTER);
                    ScreenMessages.PostScreenMessage(message);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            finally
            {
                HighLogic.CurrentGame.DestroyVessel(VesselToSave.vesselRef);
                VesselToSave.vesselRef.Die();
            }
            //End of Claw's code. Thanks Claw!
        }