示例#1
0
        void vessel_selected(ConfigNode node, CraftBrowserDialog.LoadType t)
        {
            vessel_selector = null;
            //load vessel config
            var construct = new ShipConstruct();

            if (!construct.LoadShip(node))
            {
                var shipName = node.GetValue("ship");
                Utils.Error($"Unable to load ShipConstruct '{shipName}'. " +
                            "This usually means that some parts are missing " +
                            "or some modules failed to initialize.");
                Utils.Message("Unable to load {0}", shipName);
                return;
            }
            //check if it's possible to launch such vessel
            bool cant_launch    = false;
            var  preFlightCheck = new PreFlightCheck(new Callback(() => cant_launch = false), new Callback(() => cant_launch = true));

            preFlightCheck.AddTest(new PreFlightTests.ExperimentalPartsAvailable(construct));
            preFlightCheck.RunTests();
            //cleanup loaded parts and try to store construct
            if (cant_launch)
            {
                construct.Unload();
            }
            else
            {
                StartCoroutine(delayed_process_construct(construct));
            }
        }
        internal void BuildAndLaunchCraft()
        {
            // build craft
            ShipConstruct nship = new ShipConstruct();

            nship.LoadShip(craftConfig);

            string             landedAt = "External Launchpad";
            string             flag     = flagname;
            Game               game     = FlightDriver.FlightStateCache;
            VesselCrewManifest crew     = new VesselCrewManifest();

            Box vessel_bounds = GetVesselBox(nship);

            launchTransform = builder.PlaceShip(nship, vessel_bounds);

            EnableExtendingLaunchClamps(nship);
            ShipConstruction.AssembleForLaunch(nship, landedAt, landedAt,
                                               flag, game, crew);
            var FlightVessels = FlightGlobals.Vessels;

            craftVessel = FlightVessels[FlightVessels.Count - 1];

            FlightGlobals.ForceSetActiveVessel(craftVessel);
            if (builder.capture)
            {
                craftVessel.Splashed = craftVessel.Landed = false;
            }
            else
            {
                bool loaded = craftVessel.loaded;
                bool packed = craftVessel.packed;
                craftVessel.loaded = true;
                craftVessel.packed = false;
                craftVessel.GetHeightFromTerrain();
                Debug.LogFormat("[EL] hft {0}", craftVessel.heightFromTerrain);
                craftVessel.loaded = loaded;
                craftVessel.packed = packed;
            }

            Vector3 offset = craftVessel.transform.position - launchTransform.position;

            craftOffset = launchTransform.InverseTransformDirection(offset);
            SetupCraftResources(craftVessel);

            KSP.UI.Screens.StageManager.BeginFlight();

            if (builder.capture)
            {
                FlightGlobals.overrideOrbit = true;
                (builder as PartModule).StartCoroutine(CaptureCraft());
            }
            else
            {
                state = State.Idle;
            }
        }
示例#3
0
 public bool LoadConstruct()
 {
     UnloadConstruct();
     construct = new ShipConstruct();
     if (!construct.LoadShip(vessel_node))
     {
         UnloadConstruct();
         return(false);
     }
     return(true);
 }
示例#4
0
        public ShipConstruct LoadConstruct()
        {
            var ship = new ShipConstruct();

            if (!ship.LoadShip(Blueprint))
            {
                ship.Unload();
                return(null);
            }
            return(ship);
        }
示例#5
0
 public bool LoadConstruct()
 {
     UnloadConstruct();
     construct = new ShipConstruct();
     if(!construct.LoadShip(vessel_node))
     {
         UnloadConstruct();
         return false;
     }
     return true;
 }
示例#6
0
 public ShipConstruct GetShip()
 {
     if (ship != null && ship.Parts != null && ship.Parts.Count > 0) //If the parts are there, then the ship is loaded
     {
         return(ship);
     }
     else if (shipNode != null) //Otherwise load the ship from the ConfigNode
     {
         ship.LoadShip(shipNode);
     }
     return(ship);
 }
示例#7
0
        private static void RenderMergeSection(BuildListVessel ship)
        {
            if (!_showMergeSelectionList && KCTGameStates.MergingAvailable && GUILayout.Button("Merge Built Vessel"))
            {
                _showMergeSelectionList = true;
            }

            if (_showMergeSelectionList && KCTGameStates.MergingAvailable)
            {
                if (GUILayout.Button("Hide Merge Selection"))
                {
                    _showMergeSelectionList = false;
                }

                GUILayout.BeginVertical();
                GUILayout.Label("Choose a vessel");

                GUILayout.Label("VAB");
                _vabMergeScroll = GUILayout.BeginScrollView(_vabMergeScroll, GUILayout.Height(5 * 26 + 5), GUILayout.MaxHeight(1 * Screen.height / 4));

                foreach (BuildListVessel vessel in KCTGameStates.ActiveKSC.VABWarehouse)
                {
                    if (vessel.Id != ship.Id && !KCTGameStates.MergedVessels.Exists(x => x.Id == vessel.Id) && GUILayout.Button(vessel.ShipName))
                    {
                        ShipConstruct mergedShip = new ShipConstruct();
                        mergedShip.LoadShip(vessel.ShipNode);
                        EditorLogic.fetch.SpawnConstruct(mergedShip);

                        KCTGameStates.MergedVessels.Add(vessel);
                    }
                }
                GUILayout.EndScrollView();

                GUILayout.Label("SPH");
                _sphMergeScroll = GUILayout.BeginScrollView(_sphMergeScroll, GUILayout.Height(5 * 26 + 5), GUILayout.MaxHeight(1 * Screen.height / 4));

                foreach (BuildListVessel vessel in KCTGameStates.ActiveKSC.SPHWarehouse)
                {
                    if (vessel.Id != ship.Id && !KCTGameStates.MergedVessels.Exists(x => x.Id == vessel.Id) && GUILayout.Button(vessel.ShipName))
                    {
                        ShipConstruct mergedShip = new ShipConstruct();
                        mergedShip.LoadShip(vessel.ShipNode);
                        EditorLogic.fetch.SpawnConstruct(mergedShip);

                        KCTGameStates.MergedVessels.Add(vessel);
                    }
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();
            }
        }
        public CostReport getBuildCost(ConfigNode craft)
        {
            lockedParts = false;
            ShipConstruct ship = new ShipConstruct();

            if (!ship.LoadShip(craft))
            {
                return(null);
            }
            if (!ship.shipPartsUnlocked)
            {
                lockedParts = true;
            }
            GameObject ro          = ship.parts[0].localRoot.gameObject;
            Vessel     craftVessel = ro.AddComponent <Vessel>();

            craftVessel.vesselName = "EL craftVessel - " + craft.GetValue("ship");
            craftVessel.Initialize(true);
            foreach (Part part in craftVessel.parts)
            {
                part.ModulesOnStart();
            }
            if (ELSettings.B9Wings_Present)
            {
                if (!InitializeB9Wings(craftVessel) &&
                    ELSettings.FAR_Present)
                {
                    InitializeFARSurfaces(craftVessel);
                }
            }
            else if (ELSettings.FAR_Present)
            {
                InitializeFARSurfaces(craftVessel);
            }

            // needed for displaying optional resources during the planning
            // stage.
            craftResources = new RMResourceSet(craftVessel);

            BuildCost resources = new BuildCost();

            foreach (Part p in craftVessel.parts)
            {
                resources.addPart(p);
            }
            craftVessel.Die();

            return(resources.cost);
        }
示例#9
0
 /// <summary>
 /// Use this only within the Editor scene. Otherwise it can cause issues with other mods
 /// because initializing the ShipConstruct will cause the OnLoad for Parts and PartModules to be called.
 /// Some mods (like FAR for example) assume that this can only happen during the LoadScreen or Editor scene
 /// and freak out.
 /// </summary>
 /// <returns></returns>
 public ShipConstruct GetShip()
 {
     if (_ship?.Parts?.Count > 0)    //If the parts are there, then the ship is loaded
     {
         return(_ship);
     }
     else if (ShipNode != null)    //Otherwise load the ship from the ConfigNode
     {
         if (_ship == null)
         {
             _ship = new ShipConstruct();
         }
         _ship.LoadShip(ShipNode);
     }
     return(_ship);
 }
        private void craftSelectOkay(string filename,
                                     CraftBrowserDialog.LoadType lt)
        {
            ConfigNode craftNode = ConfigNode.Load(filename);

            //bool lockedParts = false;
            ShipConstruct ship = new ShipConstruct();

            //ProtoVessel cringle = new ProtoVessel (craftNode);

            //foreach (ProtoPartSnapshot ppart in cringle.protoPartSnapshots) {
            //	Debug.Log (ppart.partName);
            //}

            if (!ship.LoadShip(craftNode))
            {
                return;
            }

            //GameObject ro = ship.parts[0].localRoot.gameObject;
            //Vessel craftVessel = ro.AddComponent<Vessel>();
            //craftVessel.Initialize (true);

            //craftVessel.Die ();

            //craft = craftVessel;
            //if (!ship.shipPartsUnlocked) {
            //	lockedParts = true;
            //}
            //GameObject ro = ship.parts[0].localRoot.gameObject;
            //craft = ro.AddComponent<Vessel>();
            //craft.Initialize (true);
            //			if (ExSettings.B9Wings_Present) {
            //				if (!InitializeB9Wings (craftVessel)
            //					&& ExSettings.FAR_Present) {
            //					InitializeFARSurfaces (craftVessel);
            //				}
            //			} else if (ExSettings.FAR_Present) {
            //				InitializeFARSurfaces (craftVessel);
            //			}

            //foreach (Part p in craftVessel.parts) {
            //	resources.addPart (p);
            //}
            //craftVessel.Die ();
        }
示例#11
0
        internal void BuildAndLaunchCraft()
        {
            // build craft
            ShipConstruct nship = new ShipConstruct();

            nship.LoadShip(craftConfig);

            int numParts = vessel.parts.Count;

            if (craftType != CraftType.SubAss)
            {
                numParts = 0;
            }

            ShipConstruction.CreateBackup(nship);

            StrutFixer.HackStruts(nship, numParts);

            Vector3 offset = nship.Parts[0].transform.localPosition;

            nship.Parts[0].transform.Translate(-offset);
            string             landedAt = "External Launchpad";
            string             flag     = flagname;
            Game               state    = FlightDriver.FlightStateCache;
            VesselCrewManifest crew     = new VesselCrewManifest();

            GetLanchTransform();
            ShipConstruction.PutShipToGround(nship, launchTransform);
            ShipConstruction.AssembleForLaunch(nship, landedAt, flag, state,
                                               crew);
            var FlightVessels = FlightGlobals.Vessels;

            craftVessel          = FlightVessels[FlightVessels.Count - 1];
            offset               = craftVessel.transform.position - launchTransform.position;
            craftOffset          = launchTransform.InverseTransformDirection(offset);
            craftVessel.Splashed = craftVessel.Landed = false;
            SetupCraftResources(craftVessel);

            FlightGlobals.ForceSetActiveVessel(craftVessel);

            Staging.beginFlight();

            FlightGlobals.overrideOrbit = true;
            StartCoroutine(CaptureCraft());
        }
示例#12
0
        public BuildCost.CostReport getBuildCost(ConfigNode craft)
        {
            ShipConstruct ship = new ShipConstruct();

            ship.LoadShip(craft);
            GameObject ro    = ship.parts[0].localRoot.gameObject;
            Vessel     dummy = ro.AddComponent <Vessel>();

            dummy.Initialize(true);

            craftResources = new VesselResources(dummy);

            BuildCost resources = new BuildCost();

            foreach (Part p in ship.parts)
            {
                resources.addPart(p);
            }
            dummy.Die();

            return(resources.cost);
        }
示例#13
0
        internal void BuildAndLaunchCraft()
        {
            DestroyCraftHull();
            // build craft
            ShipConstruct nship = new ShipConstruct();

            nship.LoadShip(craftConfig);

            ApplyNodeVariants(nship);

            string             landedAt = "";
            string             flag     = flagname;
            Game               game     = FlightDriver.FlightStateCache;
            VesselCrewManifest crew     = new VesselCrewManifest();

            Box vessel_bounds = GetVesselBox(nship);
            var rootPart      = nship.parts[0].localRoot;
            var shipTransform = rootPart.transform;

            builder.SetShipTransform(shipTransform, rootPart);
            builder.PlaceShip(shipTransform, vessel_bounds);

            EnableExtendingLaunchClamps(nship);
            ShipConstruction.AssembleForLaunch(nship, landedAt, landedAt,
                                               flag, game, crew);
            var craftVessel = nship.parts[0].localRoot.GetComponent <Vessel> ();

            craftVessel.launchedFrom = builder.LaunchedFrom;

            FlightGlobals.ForceSetActiveVessel(craftVessel);
            SetCraftOrbit(craftVessel, OrbitDriver.UpdateMode.IDLE);
            builder.PostBuild(craftVessel);
            if (builder.capture)
            {
                craftVessel.Splashed = craftVessel.Landed = false;
            }
            else
            {
                bool loaded = craftVessel.loaded;
                bool packed = craftVessel.packed;
                craftVessel.loaded = true;
                craftVessel.packed = false;
                // The default situation for new vessels is PRELAUNCH, but
                // that is not so good for bases because contracts check for
                // LANDED. XXX should this be selectable?
                craftVessel.situation = Vessel.Situations.LANDED;
                craftVessel.GetHeightFromTerrain();
                Debug.Log($"[ELBuildControl] height from terrain {craftVessel.heightFromTerrain}");
                craftVessel.loaded = loaded;
                craftVessel.packed = packed;
            }

            SetupCraftResources(craftVessel);

            KSP.UI.Screens.StageManager.BeginFlight();

            builtStuff = null;                  // ensure pad mass gets reset
            SetPadMass();
            if (builder.capture)
            {
                var b = builder as PartModule;
                b.StartCoroutine(CaptureCraft(craftVessel));
            }
            else
            {
                CleanupAfterRelease();
            }
        }
示例#14
0
        public CostReport getBuildCost(ConfigNode craft, string craftText = null)
        {
            lockedParts = false;
            ShipConstruct ship = new ShipConstruct();

            if (!ship.LoadShip(craft))
            {
                lockedParts = true;
                return(null);
            }
            if (ship.vesselDeltaV != null)
            {
                // The delta-v module is not needed. It has its own gameObject
                // for ShipConstruct.
                UnityEngine.Object.Destroy(ship.vesselDeltaV.gameObject);
                ship.vesselDeltaV = null;
            }
            if (!ship.shipPartsUnlocked)
            {
                lockedParts = true;
            }
            GameObject ro          = ship.parts[0].localRoot.gameObject;
            Vessel     craftVessel = ro.AddComponent <Vessel>();

            craftVessel.vesselName = "EL craftVessel - " + craft.GetValue("ship");
            craftVessel.Initialize(true);
            SetCraftOrbit(craftVessel, OrbitDriver.UpdateMode.IDLE);
            foreach (Part part in craftVessel.parts)
            {
                SanitizePart(part);
                part.ModulesOnStart();
            }

            if (ELSettings.B9Wings_Present)
            {
                if (!InitializeB9Wings(craftVessel) &&
                    ELSettings.FAR_Present)
                {
                    InitializeFARSurfaces(craftVessel);
                }
            }
            else if (ELSettings.FAR_Present)
            {
                InitializeFARSurfaces(craftVessel);
            }

            BuildCost resources = new BuildCost();

            foreach (Part p in craftVessel.parts)
            {
                resources.addPart(p);
            }

            if (craftText != null && ELSettings.ShowCraftHull)
            {
                Quickhull.dump_points = ELSettings.DebugCraftHull;
                Quickhull.points_path = savesPath;
                DestroyCraftHull();
                craftHull = new CraftHull(craftText);
                // GetVesselBox will rotate and minimize any launchclamps,
                // which is probably a good thing.
                var rootPart = ship.parts[0].localRoot;
                var rootPos  = rootPart.transform.position;
                craftHull.SetBox(GetVesselBox(ship), rootPos);
                builder.SetShipTransform(rootPart.transform, rootPart);
                craftHull.SetTransform(rootPart.transform);
                if (ELSettings.DebugCraftHull ||
                    !craftHull.LoadHull(savesPath))
                {
                    craftHull.BuildConvexHull(craftVessel);
                    craftHull.SaveHull(savesPath);
                }
            }

            craftVessel.Die();

            return(resources.cost);
        }
示例#15
0
        public MultiplayerVessel(String name)
        {
            // Save state to reload into because the stupid methods below changes them. Who the f**k changes global methods inside class methods anyway.
            Vessel activeVessel = FlightGlobals.ActiveVessel;
            List<Part> activeParts = activeVessel.parts;
            Part activeRootPart = activeVessel.rootPart;

            // ShipConstruct nship = ShipConstruction.LoadShip(name);

            ConfigNode root = ConfigNode.Load(name);
            if (root != null)
            {
                if (root.nodes.Count > 0)
                {
                    ship = new ShipConstruct();
                    ship.LoadShip(root);

                    ShipConstruction.PutShipToGround(ship, activeVessel.transform);

                    //foreach (Part p in activeVessel.parts) p.gameObject.SetActive(false);
                    Staging.SetStageCount(activeParts);

                    EditorLogic.startPod = activeRootPart;

                    activeRootPart.gameObject.SetActive(true);

                    initializeVessel();

                    isLoaded = true;
                }
            }
            else
            {
                KSPMulti.KSPMultiplayer.print("ROOT IS NULL");
            }
        }
示例#16
0
        public override void drawWindow(int windowID)
        {
            GUIStyle mySty = new GUIStyle(GUI.skin.window);
            mySty.normal.textColor = mySty.focused.textColor = Color.white;
            mySty.hover.textColor = mySty.active.textColor = Color.yellow;
            mySty.onNormal.textColor = mySty.onFocused.textColor = mySty.onHover.textColor = mySty.onActive.textColor = Color.green;
            mySty.padding = new RectOffset(8, 8, 8, 8);

            GUILayout.BeginVertical();

            GUILayout.Label("Select an assembly");

            if (GUILayout.Button("StorePart") && EditorLogic.SelectedPart != null)
            {
                EditorLogic editor = EditorLogic.fetch;
                ShipConstruct ship = new ShipConstruct();

                Utils.addPartToShipRecursive(ship, EditorLogic.SelectedPart);

                ship.SaveShip().Save("D:/rusty.cfg");
                ShipConstruction.CaptureThumbnail(ship, "rusty_thumbs", "rusty");

                // store thumb
                KSP_rusty.Inventory.Add(ship.SaveShip());

                // root or not?
                if (EditorLogic.SelectedPart == EditorLogic.RootPart)
                {
                    KerbalGUIManager.print("[rusty] GUIInventory:StorePart: is root");
                    EditorLogic.DeletePart(EditorLogic.SelectedPart);
                }
                else
                {
                    KerbalGUIManager.print("[rusty] GUIInventory:StorePart: is not root");
                    EditorLogic.DeletePart(EditorLogic.SelectedPart);
                }
            }

            /*
            if (GUILayout.Button("Store"))
            {
                try
                {
                    EditorLogic editor = EditorLogic.fetch;
                    ShipConstruct ship = new ShipConstruct(editor.ship.shipName, editor.ship.shipFacility, editor.getSortedShipList());

                    KerbalGUIManager.print("[rusty] GUIInventory: storing");

                    try
                    {
                        inv = new ShipConstruct();
                        if (inv.LoadShip(ship.SaveShip()))
                        {
                            KerbalGUIManager.print("[rusty] GUIInventory: load OK");
                        }
                        else
                        {
                            KerbalGUIManager.print("[rusty] GUIInventory: load failed");
                        }
                    }
                    catch (Exception e)
                    {
                        KerbalGUIManager.print("Exception GUIInventory:drawWindow():Store;saveShip: " + e.Message + "\n" + e.StackTrace);
                    }

                    KerbalGUIManager.print("[rusty] GUIInventory: deleting old");
                }
                catch (Exception e)
                {
                    KerbalGUIManager.print("Exception GUIInventory:drawWindow():Store: " + e.Message + "\n" + e.StackTrace);
                }
            }
             */

            if (GUILayout.Button("Load rusty.cfg"))
            {
                ConfigNode rusty2 = ConfigNode.Load("D:/rusty.cfg");

                EditorLogic editor = null;
                ShipConstruct ship = null;

                editor = EditorLogic.fetch;
                //editor.SpawnPart(PartLoader.getPartInfoByName("mk1pod"));
                //editor.SpawnConstruct(inv);

                // fix type
                rusty2.SetValue("type", "VAB", true);
                rusty2.Save("D:/rusty2.cfg");

                ship = new ShipConstruct();
                ship.LoadShip(rusty2);
            }

            if (KSP_rusty.Inventory != null)
            {
                foreach (ConfigNode inventoryItem in KSP_rusty.Inventory) {
                    string title = "";
                    int nrOfParts = 0;

                    try
                    {
                        // get number of parts
                        ConfigNode[] partNodes = inventoryItem.GetNodes("PART");
                        if (partNodes != null)
                        {
                            nrOfParts = partNodes.GetUpperBound(0) + 1;
                        }

                        // get vessel name
                        title = inventoryItem.GetValue("ship");
                        if (title != null && title.Length > 0)
                        {
                            title = "Load " + title + " (" + nrOfParts + ")";
                        }
                        else
                        {
                            title = "Load (" + nrOfParts + " parts)";
                        }
                    }
                    catch (Exception e)
                    {
                        KerbalGUIManager.print("Exception GUIInventory:drawWindow():Button title " + e.Message + "\n" + e.StackTrace);
                    }

                    if (GUILayout.Button(title))
                    {
                        KerbalGUIManager.print("[rusty] Adding part from inventory");

                        EditorLogic editor = null;
                        ShipConstruct ship = null;
                        try
                        {
                            editor = EditorLogic.fetch;
                            ship = new ShipConstruct();
                            ship = rustyInventory.buildConstruct(inventoryItem);
                            ship.SaveShip().Save("D:/rusty.cfg");
                            editor.SpawnConstruct(ship);

                            /*
                            //editor.SpawnPart(PartLoader.getPartInfoByName("mk1pod"));
                            //editor.SpawnConstruct(inv);

                            // fix type
                            inventoryItem.SetValue("type", "VAB", true);

                            inventoryItem.Save("D:/rusty.cfg");

                            ship = new ShipConstruct();
                            ship.LoadShip(inventoryItem);
                            // TODO: editor.OnPodSpawn(PartLoader.getPartInfoByName("mk1pod"));
                            */
                            KSP_rusty.Inventory.Remove(inventoryItem);
                            break;
                        }
                        catch (Exception e)
                        {
                            if (editor == null) KerbalGUIManager.print("[rusty] editor is null");
                            if (ship == null) KerbalGUIManager.print("[rusty] ship is null");
                            KerbalGUIManager.print("[rusty] Exception GUIInventory:drawWindow():Load " + e.Message + "\n" + e.StackTrace);
                        }
                    }
                }
            }
            GUILayout.EndVertical();
        }
示例#17
0
        public static bool RecoverActiveVesselToStorage(KCT_BuildListVessel.ListType listType)
        {
            ShipConstruct test = new ShipConstruct();
            try
            {
                KCTDebug.Log("Attempting to recover active vessel to storage.");
                GamePersistence.SaveGame("KCT_Backup", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                KCT_GameStates.recoveredVessel = new KCT_BuildListVessel(FlightGlobals.ActiveVessel);
                KCT_GameStates.recoveredVessel.type = listType;
                if (listType == KCT_BuildListVessel.ListType.VAB)
                    KCT_GameStates.recoveredVessel.launchSite = "LaunchPad";
                else
                    KCT_GameStates.recoveredVessel.launchSite = "Runway";

                //check for symmetry parts and remove those references if they can't be found
                RemoveMissingSymmetry(KCT_GameStates.recoveredVessel.shipNode);

                //test if we can actually convert it
                bool success = test.LoadShip(KCT_GameStates.recoveredVessel.shipNode);
                if (success)
                    ShipConstruction.CreateBackup(test);
                KCTDebug.Log("Load test reported success = " + success);
                if (!success)
                {
                    KCT_GameStates.recoveredVessel = null;
                    return false;
                }

                GameEvents.OnVesselRecoveryRequested.Fire(FlightGlobals.ActiveVessel);
                return true;
            }
            catch
            {
                Debug.LogError("[KCT] Error while recovering craft into inventory.");
                KCT_GameStates.recoveredVessel = null;
                ShipConstruction.ClearBackups();
                return false;
            }
        }
        public CostReport getBuildCost(ConfigNode craft)
        {
            lockedParts = false;
            ShipConstruct ship = new ShipConstruct ();
            if (!ship.LoadShip (craft)) {
                return null;
            }
            if (!ship.shipPartsUnlocked) {
                lockedParts = true;
            }
            GameObject ro = ship.parts[0].localRoot.gameObject;
            Vessel dummy = ro.AddComponent<Vessel>();
            dummy.Initialize (true);
            if (ExSettings.B9Wings_Present) {
                if (!InitializeB9Wings (dummy) && ExSettings.FAR_Present) {
                    InitializeFARSurfaces (dummy);
                }
            } else if (ExSettings.FAR_Present) {
                InitializeFARSurfaces (dummy);
            }
            if (ExSettings.KAS_Present) {
                InitializeKASContainers (dummy);
            }

            craftResources = new VesselResources (dummy);

            BuildCost resources = new BuildCost ();

            foreach (Part p in ship.parts) {
                resources.addPart (p);
            }
            dummy.Die ();

            return resources.cost;
        }
示例#19
0
        private static void RenderEditMode()
        {
            BuildListVessel ship = KCTGameStates.EditedVessel;

            if (_finishedShipBP < 0 && ship.IsFinished)
            {
                // If ship is finished, then both build and integration times can be refreshed with newly calculated values
                _finishedShipBP        = Utilities.GetBuildTime(ship.ExtractedPartNodes);
                ship.BuildPoints       = _finishedShipBP;
                ship.IntegrationPoints = MathParser.ParseIntegrationTimeFormula(ship);
            }

            Utilities.GetShipEditProgress(ship, out double newProgressBP, out double originalCompletionPercent, out double newCompletionPercent);  //progress
            GUILayout.Label($"Original: {Math.Max(0, Math.Round(100 * originalCompletionPercent, 2))}%");
            GUILayout.Label($"Edited: {Math.Round(100 * newCompletionPercent, 2)}%");

            BuildListVessel.ListType type = EditorLogic.fetch.launchSiteName == "LaunchPad" ? BuildListVessel.ListType.VAB : BuildListVessel.ListType.SPH;
            GUILayout.BeginHorizontal();
            GUILayout.Label("Build Time at ");
            if (BuildRateForDisplay == null)
            {
                BuildRateForDisplay = Utilities.GetBuildRate(0, type, null).ToString();
            }
            BuildRateForDisplay = GUILayout.TextField(BuildRateForDisplay, GUILayout.Width(75));
            GUILayout.Label(" BP/s:");
            List <double> rates = new List <double>();

            if (ship.Type == BuildListVessel.ListType.VAB)
            {
                rates = Utilities.GetVABBuildRates(null);
            }
            else
            {
                rates = Utilities.GetSPHBuildRates(null);
            }
            if (double.TryParse(BuildRateForDisplay, out double bR))
            {
                if (GUILayout.Button("*", GUILayout.ExpandWidth(false)))
                {
                    _rateIndexHolder = (_rateIndexHolder + 1) % rates.Count;
                    bR = rates[_rateIndexHolder];
                    BuildRateForDisplay = bR.ToString();
                }
                GUILayout.EndHorizontal();
                GUILayout.Label(MagiCore.Utilities.GetFormattedTime(Math.Abs(KCTGameStates.EditorBuildTime + KCTGameStates.EditorIntegrationTime - newProgressBP) / bR));
            }
            else
            {
                GUILayout.EndHorizontal();
                GUILayout.Label("Invalid Build Rate");
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Save Edits"))
            {
                _finishedShipBP = -1;
                Utilities.SaveShipEdits(ship);
            }
            if (GUILayout.Button("Cancel Edits"))
            {
                KCTDebug.Log("Edits cancelled.");
                _finishedShipBP = -1;
                ScrapYardWrapper.ProcessVessel(KCTGameStates.EditedVessel.ExtractedPartNodes);
                KCTGameStates.mergedVessels = new List <BuildListVessel>();
                KCTGameStates.ClearVesselEditMode();

                HighLogic.LoadScene(GameScenes.SPACECENTER);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Simulate"))
            {
                _finishedShipBP = -1;
                _simulationConfigPosition.height = 1;
                EditorLogic.fetch.Lock(true, true, true, "KCTGUILock");
                GUIStates.ShowSimConfig = true;

                double effCost = Utilities.GetEffectiveCost(EditorLogic.fetch.ship.Parts);
                double bp      = Utilities.GetBuildTime(effCost);
                KCTGameStates.LaunchedVessel = new BuildListVessel(EditorLogic.fetch.ship, EditorLogic.fetch.launchSiteName, effCost, bp, EditorLogic.FlagURL);
            }
            GUILayout.EndHorizontal();

            if (KCTGameStates.LaunchedVessel != null && !KCTGameStates.LaunchedVessel.AreTanksFull() &&
                GUILayout.Button("Fill Tanks"))
            {
                foreach (Part p in EditorLogic.fetch.ship.parts)
                {
                    //fill as part prefab would be filled?
                    if (Utilities.PartIsProcedural(p))
                    {
                        foreach (PartResource rsc in p.Resources)
                        {
                            if (GuiDataAndWhitelistItemsDatabase.ValidFuelRes.Contains(rsc.resourceName) && rsc.flowState)
                            {
                                rsc.amount = rsc.maxAmount;
                            }
                        }
                    }
                    else
                    {
                        foreach (PartResource rsc in p.Resources)
                        {
                            if (GuiDataAndWhitelistItemsDatabase.ValidFuelRes.Contains(rsc.resourceName) && rsc.flowState)
                            {
                                PartResource templateRsc = p.partInfo.partPrefab.Resources.FirstOrDefault(r => r.resourceName == rsc.resourceName);
                                if (templateRsc != null)
                                {
                                    rsc.amount = templateRsc.amount;
                                }
                            }
                        }
                    }
                }
            }
            if (!_showMergeSelectionList && KCTGameStates.mergingAvailable)
            {
                if (GUILayout.Button("Merge Built Vessel"))
                {
                    _showMergeSelectionList = true;
                }
            }
            if (_showMergeSelectionList && KCTGameStates.mergingAvailable)
            {
                if (GUILayout.Button("Hide Merge Selection"))
                {
                    _showMergeSelectionList = false;
                }

                GUILayout.BeginVertical();
                GUILayout.Label("Choose a vessel");

                GUILayout.Label("VAB");
                VABMergeScroll = GUILayout.BeginScrollView(VABMergeScroll, GUILayout.Height(5 * 26 + 5), GUILayout.MaxHeight(1 * Screen.height / 4));

                foreach (BuildListVessel vessel in KCTGameStates.ActiveKSC.VABWarehouse)
                {
                    if (vessel.Id != ship.Id && !KCTGameStates.mergedVessels.Exists(x => x.Id == vessel.Id))
                    {
                        if (GUILayout.Button(vessel.ShipName))
                        {
                            ShipConstruct mergedShip = new ShipConstruct();
                            mergedShip.LoadShip(vessel.ShipNode);
                            EditorLogic.fetch.SpawnConstruct(mergedShip);

                            KCTGameStates.mergedVessels.Add(vessel);
                        }
                    }
                }
                GUILayout.EndScrollView();

                GUILayout.Label("SPH");
                SPHMergeScroll = GUILayout.BeginScrollView(SPHMergeScroll, GUILayout.Height(5 * 26 + 5), GUILayout.MaxHeight(1 * Screen.height / 4));

                foreach (BuildListVessel vessel in KCTGameStates.ActiveKSC.SPHWarehouse)
                {
                    if (vessel.Id != ship.Id && !KCTGameStates.mergedVessels.Exists(x => x.Id == vessel.Id))
                    {
                        if (GUILayout.Button(vessel.ShipName))
                        {
                            ShipConstruct mergedShip = new ShipConstruct();
                            mergedShip.LoadShip(vessel.ShipNode);
                            EditorLogic.fetch.SpawnConstruct(mergedShip);

                            KCTGameStates.mergedVessels.Add(vessel);
                        }
                    }
                }
                GUILayout.EndScrollView();
                GUILayout.EndVertical();
            }
        }
        internal void BuildAndLaunchCraft()
        {
            // build craft
            ShipConstruct nship = new ShipConstruct();

            nship.LoadShip(craftConfig);

            ApplyNodeVariants(nship);

            string             landedAt = "";
            string             flag     = flagname;
            Game               game     = FlightDriver.FlightStateCache;
            VesselCrewManifest crew     = new VesselCrewManifest();

            Box vessel_bounds = GetVesselBox(nship);

            launchTransform = builder.PlaceShip(nship, vessel_bounds);

            EnableExtendingLaunchClamps(nship);
            ShipConstruction.AssembleForLaunch(nship, landedAt, landedAt,
                                               flag, game, crew);
            var FlightVessels = FlightGlobals.Vessels;

            craftVessel = FlightVessels[FlightVessels.Count - 1];
            craftVessel.launchedFrom = builder.LaunchedFrom;

            FlightGlobals.ForceSetActiveVessel(craftVessel);
            builder.PostBuild(craftVessel);
            if (builder.capture)
            {
                craftVessel.Splashed = craftVessel.Landed = false;
            }
            else
            {
                bool loaded = craftVessel.loaded;
                bool packed = craftVessel.packed;
                craftVessel.loaded = true;
                craftVessel.packed = false;
                // The default situation for new vessels is PRELAUNCH, but
                // that is not so good for bases because contracts check for
                // LANDED. XXX should this be selectable?
                craftVessel.situation = Vessel.Situations.LANDED;
                craftVessel.GetHeightFromTerrain();
                Debug.Log($"[ELBuildControl] height from terrain {craftVessel.heightFromTerrain}");
                craftVessel.loaded = loaded;
                craftVessel.packed = packed;
            }

            Vector3 offset = craftVessel.transform.position - launchTransform.position;

            craftOffset = launchTransform.InverseTransformDirection(offset);
            SetupCraftResources(craftVessel);

            KSP.UI.Screens.StageManager.BeginFlight();

            builtStuff = null;                  // ensure pad mass gets reset
            SetPadMass();
            if (builder.capture)
            {
                FlightGlobals.overrideOrbit = true;
                (builder as PartModule).StartCoroutine(CaptureCraft());
            }
            else
            {
                CleaupAfterRelease();
            }
        }
		internal void BuildAndLaunchCraft ()
		{
			// build craft
			ShipConstruct nship = new ShipConstruct ();
			nship.LoadShip (craftConfig);

			int numParts = builder.vessel.parts.Count;
			if (craftType != CraftType.SubAss)
				numParts = 0;

			string landedAt = "External Launchpad";
			string flag = flagname;
			Game game = FlightDriver.FlightStateCache;
			VesselCrewManifest crew = new VesselCrewManifest ();

			Box vessel_bounds = GetVesselBox (nship);
			launchTransform = builder.PlaceShip (nship, vessel_bounds);

			EnableExtendingLaunchClamps (nship);
			ShipConstruction.AssembleForLaunch (nship, landedAt, flag, game,
												crew);
			var FlightVessels = FlightGlobals.Vessels;
			craftVessel = FlightVessels[FlightVessels.Count - 1];

			FlightGlobals.ForceSetActiveVessel (craftVessel);
			if (builder.capture) {
				craftVessel.Splashed = craftVessel.Landed = false;
			} else {
				bool loaded = craftVessel.loaded;
				bool packed = craftVessel.packed;
				craftVessel.loaded = true;
				craftVessel.packed = false;
				craftVessel.GetHeightFromTerrain ();
				Debug.Log (String.Format ("[EL] hft {0}", craftVessel.heightFromTerrain));
				craftVessel.loaded = loaded;
				craftVessel.packed = packed;
			}

			Vector3 offset = craftVessel.transform.position - launchTransform.position;
			craftOffset = launchTransform.InverseTransformDirection (offset);
			SetupCraftResources (craftVessel);

			Staging.beginFlight ();

			if (builder.capture) {
				FlightGlobals.overrideOrbit = true;
				(builder as PartModule).StartCoroutine (CaptureCraft ());
			} else {
				state = State.Idle;
			}
		}
        public void LaunchShip()
        {
            ShipConstruct vehicle = new ShipConstruct();
            if (!vehicle.LoadShip(m_VehicleConfig)) return;

            Game fsc = FlightDriver.FlightStateCache;
            VesselCrewManifest vesselCrew = new VesselCrewManifest();

            Bounds aabb = GetAABB(vehicle);
            if (aabb.min == null) Application.Quit();
            launchData = m_ConstructionPort.PlaceShip(vehicle, aabb);

            ShipConstruction.AssembleForLaunch(vehicle, "BANAAN", null, fsc, vesselCrew);
            m_Vessel = FlightGlobals.Vessels[FlightGlobals.Vessels.Count - 1];

            FlightGlobals.ForceSetActiveVessel(m_Vessel);

            Vector3 offset = m_Vessel.transform.position - launchData.position;
            craftOffset = launchData.InverseTransformDirection(offset);

            m_Vessel.SetPosition(craftOffset, true);

            Staging.beginFlight();

            FlightGlobals.overrideOrbit = true;
            m_ConstructionPort.StartCoroutine(CaptureCraft());
        }
		public CostReport getBuildCost (ConfigNode craft)
		{
			lockedParts = false;
			ShipConstruct ship = new ShipConstruct ();
			if (!ship.LoadShip (craft)) {
				return null;
			}
			if (!ship.shipPartsUnlocked) {
				lockedParts = true;
			}
			GameObject ro = ship.parts[0].localRoot.gameObject;
			Vessel craftVessel = ro.AddComponent<Vessel>();
			craftVessel.Initialize (true);
			if (ExSettings.B9Wings_Present) {
				if (!InitializeB9Wings (craftVessel)
					&& ExSettings.FAR_Present) {
					InitializeFARSurfaces (craftVessel);
				}
			} else if (ExSettings.FAR_Present) {
				InitializeFARSurfaces (craftVessel);
			}

			// needed for displaying optional resources during the planning
			// stage.
			craftResources = new VesselResources (craftVessel);

			BuildCost resources = new BuildCost ();

			foreach (Part p in craftVessel.parts) {
				resources.addPart (p);
			}
			craftVessel.Die ();

			return resources.cost;
		}
        public BuildCost.CostReport getBuildCost(ConfigNode craft)
        {
            ShipConstruct ship = new ShipConstruct ();
            ship.LoadShip (craft);
            GameObject ro = ship.parts[0].localRoot.gameObject;
            Vessel dummy = ro.AddComponent<Vessel>();
            dummy.Initialize (true);

            craftResources = new VesselResources (dummy);

            BuildCost resources = new BuildCost ();

            foreach (Part p in ship.parts) {
                resources.addPart (p);
            }
            dummy.Die ();

            return resources.cost;
        }
        internal void BuildAndLaunchCraft()
        {
            // build craft
            ShipConstruct nship = new ShipConstruct ();
            nship.LoadShip (craftConfig);

            int numParts = vessel.parts.Count;
            if (craftType != CraftType.SubAss)
                numParts = 0;

            ShipConstruction.CreateBackup (nship);

            StrutFixer.HackStruts (nship, numParts);

            Vector3 offset = nship.Parts[0].transform.localPosition;
            nship.Parts[0].transform.Translate (-offset);
            string landedAt = "External Launchpad";
            string flag = flagname;
            Game state = FlightDriver.FlightStateCache;
            VesselCrewManifest crew = new VesselCrewManifest ();

            GetLanchTransform ();
            ShipConstruction.PutShipToGround (nship, launchTransform);
            ShipConstruction.AssembleForLaunch (nship, landedAt, flag, state,
                                                crew);
            var FlightVessels = FlightGlobals.Vessels;
            craftVessel = FlightVessels[FlightVessels.Count - 1];
            offset = craftVessel.transform.position - launchTransform.position;
            craftOffset = launchTransform.InverseTransformDirection (offset);
            craftVessel.Splashed = craftVessel.Landed = false;
            SetupCraftResources (craftVessel);

            FlightGlobals.ForceSetActiveVessel (craftVessel);

            Staging.beginFlight ();

            FlightGlobals.overrideOrbit = true;
            StartCoroutine (CaptureCraft ());
        }
示例#26
0
 protected void load_craft(string load_type, bool force = false)
 {
     if (CraftData.selected_craft != null)
     {
         CraftData craft = CraftData.selected_craft;
         if (craft.missing_parts && !load_type.Contains("ignore_missing") && (load_type == "load" || load_type == "merge" || load_type == "subload"))
         {
             CraftManager.main_ui.load_craft_with_missing_parts_dialog(craft, load_type);
         }
         else
         {
             if (load_type.Contains("ignore_missing"))
             {
                 load_type = load_type.Replace("_ignore_missing", "");
             }
             if (load_type == "load")
             {
                 if (CraftData.loaded_craft_saved || force)
                 {
                     EditorLogic.LoadShipFromFile(craft.path);
                     CraftManager.main_ui.hide();
                 }
                 else
                 {
                     CraftManager.main_ui.load_craft_confirm_dialog(() => {
                         load_craft(load_type, true);
                     });
                 }
             }
             else if (load_type == "merge")
             {
                 ShipConstruct ship = new ShipConstruct();
                 ship.LoadShip(ConfigNode.Load(craft.path));
                 EditorLogic.fetch.SpawnConstruct(ship);
                 CraftManager.main_ui.hide();
             }
             else if (load_type == "subload")
             {
                 ShipTemplate subassembly = new ShipTemplate();
                 subassembly.LoadShip(ConfigNode.Load(craft.path));
                 EditorLogic.fetch.SpawnTemplate(subassembly);
                 CraftManager.main_ui.hide();
             }
             else if (load_type == "download")
             {
                 download(true, false);
             }
             else if (load_type == "update")
             {
                 download(true, true);
             }
             else if (load_type == "dl_load")
             {
                 download(true, false, load_craft);
             }
             else if (load_type == "update_load")
             {
                 download(true, true, load_craft);
             }
             else if (load_type == "dl_load_no_save")
             {
                 if (CraftData.loaded_craft_saved || force)
                 {
                     download(false);
                     CraftManager.main_ui.hide();
                 }
                 else
                 {
                     CraftManager.main_ui.load_craft_confirm_dialog(() => {
                         load_craft(load_type, true);
                     });
                 }
             }
             else if (load_type == "upload")
             {
                 craft.upload_data.post();
             }
         }
     }
 }