Beispiel #1
0
        public void SpawnVessel()
        {
            //var allowedSituations = Vessel.Situations.LANDED | Vessel.Situations.PRELAUNCH | Vessel.Situations.SPLASHED;
            //if (allowedSituations != (allowedSituations & FlightGlobals.ActiveVessel.situation))
            //{
            //    throw new Exception(_notLandedErrorText);
            //}

            if (string.IsNullOrEmpty(_selectedCraftFilePath))
            {
                throw new Exception(_noVesselSelectedErrorText);
            }

            PartUtilities.ConsumeResources(_cachedCostData);

            // Backup the ship config from the VAB/SPH, load the selected .craft file
            //   and restore the cached config from the VAB/SPH
            var constructBak = ShipConstruction.ShipConfig;
            var construct    = ShipConstruction.LoadShip(_selectedCraftFilePath);

            ShipConstruction.ShipConfig = constructBak;

            ShipConstruction.PutShipToGround(construct, transform);
            ShipConstruction.AssembleForLaunch(
                construct,
                vessel.landedAt,
                vessel.displaylandedAt,
                construct.missionFlag,
                HighLogic.CurrentGame,
                new VesselCrewManifest());

            _window.CloseWindow();
        }
        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;
            }
        }
Beispiel #3
0
        private void BuildAndLaunchCraft()
        {
            // build craft
            ShipConstruct nship = ShipConstruction.LoadShip(uis.craftfile);

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

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

            ShipConstruction.CreateBackup(nship);
            ShipConstruction.PutShipToGround(nship, GetLanchTransform());

            ShipConstruction.AssembleForLaunch(nship, landedAt, flag, state, crew);

            Vessel vsl = FlightGlobals.Vessels[FlightGlobals.Vessels.Count - 1];

            FlightGlobals.ForceSetActiveVessel(vsl);
            vsl.Landed = false;

            if (kethane_present && !DebugPad)
            {
                UseResources(vsl);
            }

            if (vessel.situation == Vessel.Situations.ORBITING)
            {
                HackStruts(vsl);
                uis.vesselInfo             = new DockedVesselInfo();
                uis.vesselInfo.name        = vsl.vesselName;
                uis.vesselInfo.vesselType  = vsl.vesselType;
                uis.vesselInfo.rootPartUId = vsl.rootPart.flightID;
                vsl.rootPart.Couple(part);
                FlightGlobals.ForceSetActiveVessel(vessel);
            }
            else
            {
                uis.timer    = 3.0f;
                uis.launchee = vsl;
            }

            Staging.beginFlight();
        }
Beispiel #4
0
        private void BuildCraft()
        {
            // build craft
            ShipConstruct nship           = ShipConstruction.LoadShip(uifs.craftfile);
            Transform     launchtransform = GetLaunchTransform();

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

            nship.Parts[0].transform.Translate(-offset);
            Game state = FlightDriver.FlightStateCache;
            VesselCrewManifest crew = new VesselCrewManifest();

            ShipConstruction.CreateBackup(nship);
            ShipConstruction.PutShipToGround(nship, launchtransform);
            ShipConstruction.AssembleForLaunch(nship, uifs.LaunchSiteName, uifs.flagname, state, crew);

            Vessel vsl = FlightGlobals.Vessels[FlightGlobals.Vessels.Count - 1];

            FlightGlobals.ForceSetActiveVessel(vsl);
            vsl.Landed = false;

            HackStruts(vsl);
            uifs.vesselInfo              = new DockedVesselInfo();
            uifs.vesselInfo.name         = vsl.vesselName;
            uifs.vesselInfo.vesselType   = vsl.vesselType;
            uifs.vesselInfo.rootPartUId  = vsl.rootPart.uid;
            uifs.vesselFlightID          = vsl.rootPart.flightID;
            FlightDriver.flightStarted   = true;
            FlightDriver.newShipFlagURL  = uifs.flagname;
            FlightDriver.newShipManifest = crew;
            vsl.state     = Vessel.State.ACTIVE;
            vsl.situation = Vessel.Situations.ORBITING;
            Staging.beginFlight();
            vsl.ResumeStaging();
            Staging.GenerateStagingSequence(vsl.rootPart);
            Staging.RecalculateVesselStaging(vsl);

            FlightGlobals.ForceSetActiveVessel(vessel);
            vsl.rootPart.Couple(part);
            vessel.ResumeStaging();
            Staging.GenerateStagingSequence(vessel.rootPart);
            Staging.RecalculateVesselStaging(vessel);

            Events[("DecoupleVessel")].active = true;
        }
Beispiel #5
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());
        }
Beispiel #6
0
 public IEnumerator <YieldInstruction> SpawnShipConstructToGround(ShipConstruct construct,
                                                                  Transform spawn_transform,
                                                                  Vector3 spawn_offset,
                                                                  Callback <Vessel> on_vessel_positioned = null,
                                                                  Callback <Vessel> on_vessel_loaded     = null,
                                                                  Callback <Vessel> on_vessel_off_rails  = null,
                                                                  Callback <Vessel> on_vessel_launched   = null,
                                                                  int easing_frames = 0)
 {
     begin_launch(spawn_transform);
     PutShipToGround(construct, spawn_transform, spawn_offset);
     ShipConstruction.AssembleForLaunch(construct,
                                        vessel.landedAt, vessel.displaylandedAt, part.flagURL,
                                        FlightDriver.FlightStateCache,
                                        new VesselCrewManifest());
     launched_vessel = FlightGlobals.Vessels[FlightGlobals.Vessels.Count - 1];
     on_vessel_positioned?.Invoke(launched_vessel);
     while (!launched_vessel.loaded)
     {
         FlightCameraOverride.UpdateDurationSeconds(1);
         yield return(new WaitForFixedUpdate());
     }
     on_vessel_loaded?.Invoke(launched_vessel);
     while (launched_vessel.packed)
     {
         launched_vessel.precalc.isEasingGravity = true;
         launched_vessel.situation = Vessel.Situations.PRELAUNCH;
         stabilize_launched_vessel(0);
         FlightCameraOverride.UpdateDurationSeconds(1);
         yield return(new WaitForFixedUpdate());
     }
     on_vessel_off_rails?.Invoke(launched_vessel);
     if (easing_frames > 0)
     {
         foreach (var n in stabilize_launched_vessel(easing_frames))
         {
             FlightCameraOverride.UpdateDurationSeconds(1);
             yield return(new WaitForFixedUpdate());
         }
     }
     on_vessel_launched?.Invoke(launched_vessel);
     StageManager.BeginFlight();
     end_launch();
 }
Beispiel #7
0
        IEnumerator <YieldInstruction> store_constructs()
        {
            if (FlightGlobals.fetch == null ||
                FlightGlobals.ActiveVessel == null ||
                packed_constructs.Count == 0)
            {
                yield break;
            }
            //wait for hangar.vessel to be loaded
            VesselWaiter self = new VesselWaiter(vessel);

            while (!self.launched)
            {
                yield return(new WaitForFixedUpdate());
            }
            while (!enabled)
            {
                yield return(new WaitForFixedUpdate());
            }
            //create vessels from constructs and store them
            HangarState cur_state = hangar_state; Deactivate();

            foreach (PackedConstruct pc in packed_constructs.Values)
            {
                remove_construct(pc);
                GetLaunchTransform();
                if (!pc.LoadConstruct())
                {
                    Utils.Log("PackedConstruct: unable to load ShipConstruct {0}. " +
                              "This usually means that some parts are missing " +
                              "or some modules failed to initialize.", pc.name);
                    ScreenMessager.showMessage(string.Format("Unable to load {0}", pc.name), 3);
                    continue;
                }
                ShipConstruction.PutShipToGround(pc.construct, launchTransform);
                ShipConstruction.AssembleForLaunch(pc.construct, "Hangar", pc.flag,
                                                   FlightDriver.FlightStateCache,
                                                   new VesselCrewManifest());
                VesselWaiter vsl = new VesselWaiter(FlightGlobals.Vessels[FlightGlobals.Vessels.Count - 1]);
                FlightGlobals.ForceSetActiveVessel(vsl.vessel);
                Staging.beginFlight();
                //wait for vsl to be launched
                while (!vsl.launched)
                {
                    yield return(new WaitForFixedUpdate());
                }
                store_vessel(vsl.vessel, false);
                //wait a 0.1 sec, otherwise the vessel may not be destroyed properly
                yield return(new WaitForSeconds(0.1f));
            }
            stored_mass = Utils.formatMass(vessels_mass);
            if (cur_state == HangarState.Active)
            {
                Activate();
            }
            //save game afterwards
            FlightGlobals.ForceSetActiveVessel(vessel);
            while (!self.launched)
            {
                yield return(null);
            }
            yield return(new WaitForSeconds(0.5f));

            GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
        }
Beispiel #8
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();
            }
        }
        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();
            }
        }