Exemplo n.º 1
0
        public static Vessel AssembleForLaunchUnlanded(ShipConstruct ship, IEnumerable <string> crewToDeliver, double duration, Orbit orbit,
                                                       string flagUrl, Game sceneState)
        {
            var localRoot = ship.parts[0].localRoot;
            var vessel    = localRoot.gameObject.GetComponent <Vessel>();

            if (vessel == null)
            {
                vessel = localRoot.gameObject.AddComponent <Vessel>();
            }

            vessel.id           = Guid.NewGuid();
            vessel.vesselName   = ship.shipName;
            vessel.persistentId = ship.persistentId;
            vessel.Initialize();
            if (orbit != null)
            {
                var orbitDriver = vessel.gameObject.GetComponent <OrbitDriver>();
                if (orbitDriver == null)
                {
                    orbitDriver        = vessel.gameObject.AddComponent <OrbitDriver>();
                    vessel.orbitDriver = orbitDriver;
                }
            }
            vessel.Landed   = false;
            vessel.Splashed = false;
            vessel.skipGroundPositioning = true;
            vessel.vesselSpawning        = false;
            // vessel.loaded = false;

            var pCrewMembers = CrewRoster().Where(k => crewToDeliver.Contains(k?.name)).ToList();

            // Maybe add the initial crew to the vessel:
            if (pCrewMembers.Any())
            {
                CrewTransferBatch.moveCrew(vessel, pCrewMembers, false);
                LifeSupportWrapper.Instance.PrepForLaunch(vessel, pCrewMembers, duration);
                pCrewMembers.ForEach(pcm =>
                {
                    pcm.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                    // Add the phases the kerbonaut would have gone through during his launch to his flight-log:
                    var homeBody = Planetarium.fetch.Home;
                    pcm.flightLog.AddEntry(FlightLog.EntryType.Launch, homeBody.bodyName);
                    pcm.flightLog.AddEntry(FlightLog.EntryType.Flight, homeBody.bodyName);
                    pcm.flightLog.AddEntry(FlightLog.EntryType.Suborbit, homeBody.bodyName);
                    pcm.flightLog.AddEntry(FlightLog.EntryType.Orbit, homeBody.bodyName);
                    if (orbit.referenceBody != homeBody)
                    {
                        pcm.flightLog.AddEntry(FlightLog.EntryType.Escape, homeBody.bodyName);
                        pcm.flightLog.AddEntry(FlightLog.EntryType.Orbit, orbit.referenceBody.bodyName);
                    }
                });
            }

            // TODO this seems like overkill so commenting out, we'll see...
            vessel.orbitDriver.UpdateOrbit();
            vessel.SetOrbit(orbit);
            vessel.orbitDriver.UpdateOrbit();
            var hashCode = (uint)Guid.NewGuid().GetHashCode();
            var launchId = HighLogic.CurrentGame.launchID++;

            foreach (var part in vessel.parts)
            {
                part.flightID  = ShipConstruction.GetUniqueFlightID(sceneState.flightState);
                part.missionID = hashCode;
                part.launchID  = launchId;
                part.flagURL   = flagUrl;
            }
            if (localRoot.isControlSource == Vessel.ControlLevel.NONE)
            {
                var firstCrewablePart = ShipConstruction.findFirstCrewablePart(ship.parts[0]);
                if (firstCrewablePart == null)
                {
                    var firstControlSource = ShipConstruction.findFirstControlSource(vessel);
                    firstCrewablePart = firstControlSource ?? localRoot;
                }
                vessel.SetReferenceTransform(firstCrewablePart, true);
            }
            else
            {
                vessel.SetReferenceTransform(localRoot, true);
            }

            Debug.Log("Vessel assembled for launch: " + vessel.vesselName);
            return(vessel);
        }
Exemplo n.º 2
0
        public static Vessel AssembleForLaunchUnlanded(ShipConstruct ship, Orbit orbit,
                                                       string flagURL, Game sceneState)
        {
            var localRoot = ship.parts[0].localRoot;
            var vessel    = localRoot.gameObject.GetComponent <Vessel>();

            if (vessel == null)
            {
                vessel = localRoot.gameObject.AddComponent <Vessel>();
            }
            vessel.id           = Guid.NewGuid();
            vessel.vesselName   = Localizer.Format(ship.shipName);
            vessel.persistentId = ship.persistentId;
            if (orbit != null)
            {
                var orbitDriver = vessel.gameObject.GetComponent <OrbitDriver>();
                if (orbitDriver == null)
                {
                    orbitDriver = vessel.gameObject.AddComponent <OrbitDriver>();
                }
                orbitDriver.orbit = orbit;
            }
            vessel.Initialize(true);
            vessel.orbitDriver.updateMode = OrbitDriver.UpdateMode.TRACK_Phys;
            vessel.skipGroundPositioning  = true;
            vessel.vesselSpawning         = false;
            vessel.Landed = false;
            var hashCode = (uint)Guid.NewGuid().GetHashCode();
            var launchID = HighLogic.CurrentGame.launchID++;

            for (int i = 0, count = vessel.parts.Count; i < count; ++i)
            {
                var p = vessel.parts[i];
                p.flightID  = ShipConstruction.GetUniqueFlightID(sceneState.flightState);
                p.missionID = hashCode;
                p.launchID  = launchID;
                p.flagURL   = flagURL;
            }
            if (localRoot.isControlSource == Vessel.ControlLevel.NONE)
            {
                var firstCrewablePart = ShipConstruction.findFirstCrewablePart(ship.parts[0]);
                if (firstCrewablePart == null)
                {
                    var firstControlSource = ShipConstruction.findFirstControlSource(vessel);
                    if (firstControlSource == null)
                    {
                        firstCrewablePart = localRoot;
                    }
                    else
                    {
                        firstCrewablePart = firstControlSource;
                    }
                }
                vessel.SetReferenceTransform(firstCrewablePart, true);
            }
            else
            {
                vessel.SetReferenceTransform(localRoot, true);
            }
            Utils.Log("Vessel assembled for launch: " + vessel.GetDisplayName());
            return(vessel);
        }