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(); }
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(); }
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; }
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()); }
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); }