Пример #1
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);
        }
Пример #2
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);
        }