Пример #1
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();
        }
Пример #2
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());
        }
Пример #3
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;
        }
Пример #4
0
            /// <summary>
            /// Spawn ship construct
            /// https://github.com/KospY/KAS/blob/master/Plugin/KAS_Shared.cs
            /// </summary>
            /// <param name="_shipConstruct">Shipconstruct to spawn</param>
            /// <param name="_srcPart">Source part to spawn relative to</param>
            /// <param name="_spawnOffset">Offset spawn from Source part position</param>
            private void SpawnVessel(ShipConstruct _shipConstruct, Part _srcPart, Vector3 _spawnOffset)
            {
                //Store construct root
                Part _newConstructRootPart = _shipConstruct.parts[0];

                //Center rootpart
                Vector3 offset = _newConstructRootPart.transform.localPosition;

                _newConstructRootPart.transform.Translate(-offset);

                //Get launch spawn point, relative to part
                Transform  t         = _srcPart.transform;
                GameObject launchPos = new GameObject();

                launchPos.transform.parent    = _srcPart.transform;
                launchPos.transform.position  = t.position;
                launchPos.transform.position += t.TransformDirection(_spawnOffset);
                launchPos.transform.rotation  = t.rotation;
                //Store our launch / spawn position
                Transform launchTransform = launchPos.transform;

                //Kill original object
                launchPos.DestroyGameObject();
                //Set rootpart origin
                _shipConstruct.Parts[0].localRoot.transform.Translate(launchPos.transform.position, Space.World);
                //Position
                float   angle;
                Vector3 axis;

                //Extract ToAngleAxis data from selected spawning location
                launchTransform.rotation.ToAngleAxis(out angle, out axis);
                //TRANSFORM Rotate localRootPart in relation to root
                _shipConstruct.Parts[0].localRoot.transform.RotateAround(launchTransform.position, axis, angle);

                //Create vessel object
                Vessel _newVessel = _newConstructRootPart.localRoot.gameObject.AddComponent <Vessel>();

                //Attach vessel information
                _newVessel.id         = Guid.NewGuid();
                _newVessel.vesselName = _srcPart.vessel.vesselName + " - " + _shipConstruct.shipName;
                _newVessel.landedAt   = _srcPart.vessel.vesselName;

                //Store backup
                ShipConstruction.CreateBackup(_shipConstruct);

                //Init from VAB
                _newVessel.Initialize(true);
                //Set Landed
                _newVessel.Landed = true;

                //_newVessel.situation = Vessel.Situations.PRELAUNCH;
                // _newVessel.GoOffRails();
                //_newVessel.IgnoreGForces(240);


                //Set Orbit
                InitiateOrbit(launchTransform.position, _srcPart.vessel, _newVessel);

                //Set Mission info
                uint   missionId = (uint)Guid.NewGuid().GetHashCode();
                string flagUrl   = _srcPart.flagURL;
                uint   launchId  = HighLogic.CurrentGame.launchID++;

                //Set part mission info
                for (int i = 0; i < _newVessel.parts.Count; i++)
                {
                    Part part = _newVessel.parts[i];
                    part.flightID  = ShipConstruction.GetUniqueFlightID(FlightDriver.FlightStateCache.flightState);
                    part.flagURL   = flagUrl;
                    part.launchID  = launchId;
                    part.missionID = missionId;
                }

                //Generate staging
                KSP.UI.Screens.StageManager.BeginFlight();
                _newConstructRootPart.vessel.ResumeStaging();
                KSP.UI.Screens.StageManager.GenerateStagingSequence(_newConstructRootPart.localRoot);
                KSP.UI.Screens.StageManager.RecalculateVesselStaging(_newConstructRootPart.vessel);

                //Set position, again
                _newVessel.SetPosition(launchTransform.position);
                _newVessel.SetRotation(launchTransform.rotation);



                //Save Protovessel
                ProtoVessel _newProto = new ProtoVessel(_newVessel);

                //Kill and remove spawned vessel, had some serious problems with spawn position warping/glitching
                _newVessel.Die();

                //Set the protovessels position to the relative one we found, maybe redundant
                _newProto.position = launchPos.transform.position;

                //If you check this value, you will see the height change from launch scene to resume scene, extra dafuq
                //float height = _newProto.height;

                if (FlightDriver.StartupBehaviour == FlightDriver.StartupBehaviours.RESUME_SAVED_FILE ||
                    FlightDriver.StartupBehaviour == FlightDriver.StartupBehaviours.RESUME_SAVED_CACHE)
                {
                    //Odd behaviour with positioning during different flight scenes, workaround awaaaay
                    Log.Info("Workaround of height");
                    _newProto.height = TrueAlt(launchTransform.position, _srcPart.vessel);
                }
                _newProto.altitude += 10;
                _newProto.height   += 10;
                _newProto.situation = Vessel.Situations.FLYING;

                //Load Protovessel
                _newProto.Load(HighLogic.CurrentGame.flightState);

                // _newVessel.GoOnRails();

                // Restore ShipConstruction ship, otherwise player sees loaded craft in VAB
                ShipConstruction.ShipConfig = _OldVabShip.GetConfigNode();

                //Fix Control Lock
                FlightInputHandler.ResumeVesselCtrlState(FlightGlobals.ActiveVessel);
                //Fix active vessel staging
                FlightGlobals.ActiveVessel.ResumeStaging();
            }