예제 #1
0
        public void TryRestoreVessel(StoredVessel stored_vessel)
        {
            if (!can_restore())
            {
                return;
            }
            ScreenMessager.showMessage(string.Format("Launching {0}...", stored_vessel.vessel.vesselName), 3);
            //clean up
            stored_vessels.Remove(stored_vessel.vessel.vesselID);
            //switch hangar state
            hangar_state = HangarState.Inactive;
            //transfer resources
            transferResources(stored_vessel);
            //set restored vessel orbit
            GetLaunchTransform();
            position_vessel(stored_vessel);
            //restore vessel
            stored_vessel.Load();
            //get restored vessel from the world
            launched_vessel = stored_vessel.vessel.vesselRef;
            //transfer crew back to the launched vessel
            List <ProtoCrewMember> crew_to_transfer = CrewTransfer.delCrew(vessel, stored_vessel.crew);

            //change volume and mass
            change_part_params(stored_vessel.metric, -1f);
            //switch to restored vessel
            FlightGlobals.ForceSetActiveVessel(launched_vessel);
            SetupVessel(new LaunchedVessel(stored_vessel, launched_vessel, crew_to_transfer, part.flightID));
        }
예제 #2
0
        bool can_restore()
        {
            //if hangar is not ready, return
            if (hangar_state == HangarState.Inactive)
            {
                ScreenMessager.showMessage("Activate the hangar first", 3);
                return(false);
            }
            if (hangar_gates.State != AnimatorState.Opened)
            {
                ScreenMessager.showMessage("Open hangar gates first", 3);
                return(false);
            }
            //if something is docked to the hangar docking port (if its present)
            ModuleDockingNode dport = part.Modules.OfType <ModuleDockingNode>().SingleOrDefault();

            if (dport != null && dport.vesselInfo != null)
            {
                ScreenMessager.showMessage("Cannot launch a vessel while another is docked", 3);
                return(false);
            }
            //if in orbit or on the ground and not moving
            switch (FlightGlobals.ClearToSave())
            {
            case ClearToSaveStatus.NOT_IN_ATMOSPHERE:
            {
                ScreenMessager.showMessage("Cannot launch a vessel while flying in atmosphere", 3);
                return(false);
            }

            case ClearToSaveStatus.NOT_UNDER_ACCELERATION:
            {
                ScreenMessager.showMessage("Cannot launch a vessel hangar is under accelleration", 3);
                return(false);
            }

            case ClearToSaveStatus.NOT_WHILE_ABOUT_TO_CRASH:
            {
                ScreenMessager.showMessage("Cannot launch a vessel while about to crush", 3);
                return(false);
            }

            case ClearToSaveStatus.NOT_WHILE_MOVING_OVER_SURFACE:
            {
                ScreenMessager.showMessage("Cannot launch a vessel while moving over the surface", 3);
                return(false);
            }
            }
            if (vessel.angularVelocity.magnitude > 0.003)
            {
                ScreenMessager.showMessage("Cannot launch a vessel while rotating", 3);
                return(false);
            }
            return(true);
        }
예제 #3
0
 IEnumerator <YieldInstruction> check_joint()
 {
     while (true)
     {
         if (StaticAttach.connectedGameObject &&
             !StaticAttach.connectedGameObject.GetComponent <FixedJoint>())
         {
             ScreenMessager.showMessage("The anchor was ripped of the ground.", 3);
             Detach();
         }
         yield return(new WaitForSeconds(0.5f));
     }
 }
예제 #4
0
        //store vessel
        void store_vessel(Vessel vsl, bool perform_checks = true)
        {
            StoredVessel stored_vessel = new StoredVessel();

            if (perform_checks)            //for normal operation
            {
                //check momentary states
                if (!can_store(vsl))
                {
                    return;
                }
                //check if the vessel can be stored, if unknown, try to store
                bool storable;
                if (!probed_ids.TryGetValue(vsl.id, out storable))
                {
                    stored_vessel = try_store(vsl);
                    storable      = stored_vessel != null;
                    probed_ids.Add(vsl.id, storable);
                }
                if (!storable)
                {
                    return;
                }
            }
            else             //for storing packed constructs upon hangar launch
            {
                stored_vessel = new StoredVessel(vsl);
                stored_vessels.ForceAdd(stored_vessel);
            }
            //get vessel crew on board
            List <ProtoCrewMember> _crew = new List <ProtoCrewMember>(stored_vessel.crew);

            CrewTransfer.delCrew(vsl, _crew);
            vsl.DespawnCrew();
            //first of, add crew to the hangar if there's a place
            CrewTransfer.addCrew(part, _crew);
            //then add to other vessel parts if needed
            CrewTransfer.addCrew(vessel, _crew);
            //recalculate volume and mass
            change_part_params(stored_vessel.metric);
            //switch to hangar vessel before storing
            if (FlightGlobals.ActiveVessel.id == vsl.id)
            {
                FlightGlobals.ForceSetActiveVessel(vessel);
            }
            //destroy vessel
            vsl.Die();
            ScreenMessager.showMessage("Vessel has been docked inside the hangar", 3);
        }
예제 #5
0
 bool try_store_construct(PackedConstruct pc)
 {
     GetLaunchTransform();
     if (!pc.metric.FitsAligned(launchTransform, part.partTransform, hangar_metric))
     {
         ScreenMessager.showMessage(string.Format("{0} does not fit into this hangar", pc.name), 3);
         return(false);
     }
     if (!packed_constructs.Add(pc))
     {
         ScreenMessager.showMessage(string.Format("There's no room in the hangar for {0}", pc.name), 3);
         return(false);
     }
     return(true);
 }
예제 #6
0
 bool CanAttach()
 {
     //always check relative velocity and acceleration
     if (!vessel.Landed)
     {
         ScreenMessager.showMessage("There's nothing to attach the anchor to", 3);
         return(false);
     }
     if (vessel.GetSrfVelocity().magnitude > 1f)
     {
         ScreenMessager.showMessage("Cannot attach the anchor while mooving quicker than 1m/s", 3);
         return(false);
     }
     return(true);
 }
예제 #7
0
        void vessel_selected(string filename, string flagname)
        {
            EditorLogic EL = EditorLogic.fetch;

            if (EL == null)
            {
                return;
            }
            //load vessel config
            vessel_selector = null;
            PackedConstruct pc = new PackedConstruct(filename, flagname);

            if (pc.construct == null)
            {
                Utils.Log("PackedConstruct: unable to load ShipConstruct from {0}. " +
                          "This usually means that some parts are missing " +
                          "or some modules failed to initialize.", filename);
                ScreenMessager.showMessage(string.Format("Unable to load {0}", filename), 3);
                return;
            }
            //check if the construct contains launch clamps
            if (Utils.HasLaunchClamp(pc.construct))
            {
                ScreenMessager.showMessage(string.Format("{0} has launch clamps. Remove them before storing.", pc.name), 3);
                pc.UnloadConstruct();
                return;
            }
            //check if it's possible to launch such vessel
            bool           cant_launch    = false;
            PreFlightCheck preFlightCheck = new PreFlightCheck(new Callback(() => cant_launch = false), new Callback(() => cant_launch = true));

            preFlightCheck.AddTest(new PreFlightTests.ExperimentalPartsAvailable(pc.construct));
            preFlightCheck.RunTests();
            pc.UnloadConstruct();
            //cleanup loaded parts and try to store construct
            if (cant_launch)
            {
                return;
            }
            if (try_store_construct(pc))
            {
                change_part_params(pc.metric);
            }
        }
예제 #8
0
 public bool CanDisable()
 {
     if (stored_vessels.Count > 0 || packed_constructs.Count > 0)
     {
         ScreenMessager.showMessage("Empty the hangar before deflating it", 3);
         return(false);
     }
     if (EditorLogic.fetch == null && hangar_state == HangarState.Active)
     {
         ScreenMessager.showMessage("Deactivate the hangar before deflating it", 3);
         return(false);
     }
     if (hangar_gates.State != AnimatorState.Closed)
     {
         ScreenMessager.showMessage("Close hangar doors before deflating it", 3);
         return(false);
     }
     return(true);
 }
예제 #9
0
        /// <summary>
        /// Checks if a vessel can be stored in the hangar right now.
        /// </summary>
        /// <param name="vsl">A vessel to check</param>
        bool can_store(Vessel vsl)
        {
            if (vsl == null || vsl == vessel || !vsl.enabled || vsl.isEVA)
            {
                return(false);
            }
            //if hangar is not ready, return
            if (hangar_state == HangarState.Inactive)
            {
                ScreenMessager.showMessage("Activate the hangar first", 3);
                return(false);
            }
            //check self state first
            switch (FlightGlobals.ClearToSave())
            {
            case ClearToSaveStatus.NOT_WHILE_ABOUT_TO_CRASH:
            {
                ScreenMessager.showMessage("Cannot accept the vessel while about to crush", 3);
                return(false);
            }
            }
            //always check relative velocity and acceleration
            Vector3 rv = vessel.GetObtVelocity() - vsl.GetObtVelocity();

            if (rv.magnitude > 1f)
            {
                ScreenMessager.showMessage("Cannot accept a vessel with a relative speed higher than 1m/s", 3);
                return(false);
            }
            Vector3 ra = vessel.acceleration - vsl.acceleration;

            if (ra.magnitude > 0.1)
            {
                ScreenMessager.showMessage("Cannot accept an accelerating vessel", 3);
                return(false);
            }
            return(true);
        }
예제 #10
0
        StoredVessel try_store(Vessel vsl)
        {
            //check vessel crew
            if (vsl.GetCrewCount() > vessel.GetCrewCapacity() - vessel.GetCrewCount())
            {
                ScreenMessager.showMessage("Not enough space for the crew of a docking vessel", 3);
                return(null);
            }
            //check vessel metrics
            GetLaunchTransform();
            StoredVessel sv = new StoredVessel(vsl);

            if (!sv.metric.FitsAligned(launchTransform, part.partTransform, hangar_metric))
            {
                ScreenMessager.showMessage("The vessel does not fit into this hangar", 3);
                return(null);
            }
            if (!stored_vessels.Add(sv))
            {
                ScreenMessager.showMessage("There's no room in the hangar for this vessel", 3);
                return(null);
            }
            return(sv);
        }
예제 #11
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);
        }