示例#1
0
        private void CheckForMine()
        {
            var navalMine = FlightGlobals.ActiveVessel.FindPartModuleImplementing <ModuleEnemyMine_Naval>();
            var landMine  = FlightGlobals.ActiveVessel.FindPartModuleImplementing <ModuleEnemyMine_Land>();

            if (navalMine != null || landMine != null)
            {
                count = 0.0f;
                foreach (Vessel v in FlightGlobals.Vessels)
                {
                    if (!v.HoldPhysics)
                    {
                        double targetDistance = Vector3d.Distance(FlightGlobals.ActiveVessel.GetWorldPos3D(), v.GetWorldPos3D());

                        if (targetDistance <= 2500 && count <= 1)
                        {
                            count += 1;
                            FlightGlobals.ActiveVessel.DiscoveryInfo.SetLevel(DiscoveryLevels.Unowned);
                            FlightGlobals.ForceSetActiveVessel(v);
                            FlightInputHandler.ResumeVesselCtrlState(v);
                            return;
                        }
                    }
                }
            }
        }
示例#2
0
        private void FireHoD()
        {
            var wmPart = FlightGlobals.ActiveVessel.FindPartModuleImplementing <MissileFire>();

            team = wmPart.team;

            playerVessel = FlightGlobals.ActiveVessel.id;

            var SatCount = 0;

            foreach (Vessel v in FlightGlobals.Vessels)
            {
                if (!v.HoldPhysics && v.atmDensity <= 0.000005)
                {
                    var HoD = FlightGlobals.ActiveVessel.FindPartModuleImplementing <ModuleHammerOfDawn>();
                    if (HoD != null)
                    {
                        if (HoD.myTeam == team && SatCount == 0)
                        {
                            SatCount    += 1;
                            playerVessel = FlightGlobals.ActiveVessel.id;
                            HoD.Fire();
                            HoD.fireLaser = true;
                            BDArmorySetup.Instance.showVSGUI = true;
                            FlightGlobals.ForceSetActiveVessel(v);
                            FlightInputHandler.ResumeVesselCtrlState(v);
                            StartCoroutine(FocusSwitchRoutine());
                        }
                    }
                }
            }
        }
示例#3
0
 protected override void on_vessel_launched(Vessel vsl)
 {
     part.UpdateCoMOffset(BaseCoMOffset);
     FlightInputHandler.ResumeVesselCtrlState(vsl);
     //transfer the flight plan
     if (flightPlanNode != null && vsl.patchedConicSolver != null)
     {
         var max_tries = 10;
         vsl.flightPlanNode = flightPlanNode;
         vsl.patchedConicSolver.Load(flightPlanNode);
         vsl.patchedConicSolver.UpdateFlightPlan();
         vsl.StartCoroutine(CallbackUtil.WaitUntil(
                                () => vsl.patchedConicSolver.maneuverNodes.Count > 0 || max_tries-- < 0,
                                () =>
         {
             if (vsl.patchedConicSolver.maneuverNodes.Count == 0)
             {
                 return;
             }
             var nearest_node    = vsl.patchedConicSolver.maneuverNodes[0];
             var o               = nearest_node.patch;
             var orbitalDeltaV   = orbitalVelocityAfterNode - o.getOrbitalVelocityAtUT(nearest_node.UT);
             nearest_node.DeltaV = Utils.Orbital2NodeDeltaV(o, orbitalDeltaV, nearest_node.UT);
             vsl.patchedConicSolver.UpdateFlightPlan();
         }));
     }
     //disable storage, launch event and action
     Storage.EnableModule(false);
     update_crew_capacity(0);
     base.on_vessel_launched(vsl);
 }
示例#4
0
        // Extracted method, so we dont have to call these two lines everywhere
        private void ForceSwitchVessel(Vessel v)
        {
            if (BDArmorySettings.MULTIPLAYER_ACTIVE)
            {
                return;
            }

            FlightGlobals.ForceSetActiveVessel(v);
            FlightInputHandler.ResumeVesselCtrlState(v);
        }
示例#5
0
        IEnumerator FocusSwitchRoutine()
        {
            yield return(new WaitForSeconds(2));

            foreach (Vessel v in FlightGlobals.Vessels)
            {
                if (v.id == playerVessel)
                {
                    FlightGlobals.ForceSetActiveVessel(v);
                    FlightInputHandler.ResumeVesselCtrlState(v);
                }
            }
        }
示例#6
0
        private void jumpToVessel(Vessel target)
        {
            if (!target.loaded)
            {
                print("Bug: Trying to switch to unloaded vessel " + target);
                scheduleUpdate(null);
                errorMsg = "Target ship was not loaded";
                return;
            }

            if (!isSwitchAllowed(target))
            {
                return;
            }

            FlightGlobals.ForceSetActiveVessel(target);
            FlightInputHandler.ResumeVesselCtrlState(FlightGlobals.ActiveVessel);
        }
示例#7
0
        protected void retrainKerbals()
        {
            ProtoCrewMember trainee;

            foreach (string kerbalName in newProfessions.Keys)
            {
                trainee = trainees[kerbalName];

                //If the kerbal is currently a tourist, then unregister the kerbal from any tourism contracts.
                if (trainee.trait == "Tourist")
                {
                    WBIContractScenario.Instance.unregisterKerbal(kerbalName);
                }

                //Set the new trait
                KerbalPortraitGallery.Instance.UnregisterActiveCrew(trainee.KerbalRef);

                trainee.UnregisterExperienceTraits(trainee.KerbalRef.InPart);
                trainee.KerbalRef.InVessel.CrewListSetDirty();
                KerbalRoster.SetExperienceTrait(trainee, newProfessions[kerbalName]);
                trainee.RegisterExperienceTraits(trainee.KerbalRef.InPart);
                trainee.KerbalRef.InVessel.CrewListSetDirty();

                KerbalPortraitGallery.Instance.RegisterActiveCrew(trainee.KerbalRef);
                KerbalPortraitGallery.Instance.UpdatePortrait(trainee.KerbalRef);
                KerbalPortraitGallery.Instance.StartReset(this.part.vessel);

                //Reset experience
                if (resetExperience)
                {
                    KerbalRoster.SetExperienceLevel(trainee, 0);
                }

                Vessel.CrewWasModified(trainee.KerbalRef.InVessel);
                FlightInputHandler.ResumeVesselCtrlState(trainee.KerbalRef.InVessel);
            }
        }
示例#8
0
 // Extracted method, so we dont have to call these two lines everywhere
 private void ForceSwitchVessel(Vessel v)
 {
     FlightGlobals.ForceSetActiveVessel(v);
     FlightInputHandler.ResumeVesselCtrlState(v);
 }
示例#9
0
        public void AttachDocked(KASModuleAttachCore otherAttachModule, Vessel forceDominant = null)
        {
            // Don't overwrite vesselInfo on redundant calls
            if (this.part.vessel == otherAttachModule.part.vessel &&
                attachMode.Docked && dockedAttachModule == otherAttachModule &&
                otherAttachModule.attachMode.Docked && otherAttachModule.dockedAttachModule == this &&
                this.vesselInfo != null && otherAttachModule.vesselInfo != null)
            {
                KAS_Shared.DebugWarning("DockTo(Core) Parts already docked, nothing to do at all");
                return;
            }

            // Save vessel Info
            this.vesselInfo             = new DockedVesselInfo();
            this.vesselInfo.name        = this.vessel.vesselName;
            this.vesselInfo.vesselType  = this.vessel.vesselType;
            this.vesselInfo.rootPartUId = this.vessel.rootPart.flightID;
            this.dockedAttachModule     = otherAttachModule;
            this.dockedPartID           = otherAttachModule.part.flightID.ToString();

            otherAttachModule.vesselInfo             = new DockedVesselInfo();
            otherAttachModule.vesselInfo.name        = otherAttachModule.vessel.vesselName;
            otherAttachModule.vesselInfo.vesselType  = otherAttachModule.vessel.vesselType;
            otherAttachModule.vesselInfo.rootPartUId = otherAttachModule.vessel.rootPart.flightID;
            otherAttachModule.dockedAttachModule     = this;
            otherAttachModule.dockedPartID           = this.part.flightID.ToString();

            // Set reference
            attachMode.Docked = otherAttachModule.attachMode.Docked = true;

            // Stop if already docked
            if (otherAttachModule.part.parent == this.part || this.part.parent == otherAttachModule.part)
            {
                KAS_Shared.DebugWarning("DockTo(Core) Parts already docked, nothing more to do");
                return;
            }

            // This results in a somewhat wrong state, but it's better to not make it even more wrong
            if (otherAttachModule.part.vessel == this.part.vessel)
            {
                KAS_Shared.DebugWarning("DockTo(Core) BUG: Parts belong to the same vessel, doing nothing");
                return;
            }

            // Reset vessels position and rotation for returning all parts to their original position and rotation before coupling
            this.vessel.SetPosition(this.vessel.transform.position, true);
            this.vessel.SetRotation(this.vessel.transform.rotation);
            otherAttachModule.vessel.SetPosition(otherAttachModule.vessel.transform.position, true);
            otherAttachModule.vessel.SetRotation(otherAttachModule.vessel.transform.rotation);

            // Couple depending of mass

            Vessel dominantVessel = GetDominantVessel(this.vessel, otherAttachModule.vessel);

            if (forceDominant == this.vessel || forceDominant == otherAttachModule.vessel)
            {
                dominantVessel = forceDominant;
            }

            KAS_Shared.DebugLog("DockTo(Core) Master vessel is " + dominantVessel.vesselName);

            if (dominantVessel == this.vessel)
            {
                KAS_Shared.DebugLog("DockTo(Core) Docking " + otherAttachModule.part.partInfo.title + " from " + otherAttachModule.vessel.vesselName + " with " + this.part.partInfo.title + " from " + this.vessel.vesselName);
                if (FlightGlobals.ActiveVessel == otherAttachModule.part.vessel)
                {
                    KAS_Shared.DebugLog("DockTo(Core) Switching focus to " + this.part.vessel.vesselName);
                    FlightGlobals.ForceSetActiveVessel(this.part.vessel);
                    FlightInputHandler.ResumeVesselCtrlState(this.part.vessel);
                }
                otherAttachModule.part.Couple(this.part);
            }
            else
            {
                KAS_Shared.DebugLog("DockTo(Core) Docking " + this.part.partInfo.title + " from " + this.vessel.vesselName + " with " + otherAttachModule.part.partInfo.title + " from " + otherAttachModule.vessel.vesselName);
                if (FlightGlobals.ActiveVessel == this.part.vessel)
                {
                    KAS_Shared.DebugLog("DockTo(Core) Switching focus to " + otherAttachModule.part.vessel.vesselName);
                    FlightGlobals.ForceSetActiveVessel(otherAttachModule.part.vessel);
                    FlightInputHandler.ResumeVesselCtrlState(otherAttachModule.part.vessel);
                }
                this.part.Couple(otherAttachModule.part);
            }

            GameEvents.onVesselWasModified.Fire(this.part.vessel);
        }
示例#10
0
        private void Update()
        {
            //destroy the old one
            VesselSwitching vesselSwitching = UnityEngine.Object.FindObjectOfType <VesselSwitching> ();

            if (vesselSwitching != null)
            {
                Destroy(vesselSwitching);
                Utils.Log("vesselSwitching destroyed.");
            }

            if (!MapView.MapIsEnabled)
            {
                if (!InputLockManager.IsLocked(ControlTypes.VESSEL_SWITCHING))
                {
                    if (!FlightDriver.Pause)
                    {
                        currentIndex = -1;
                        if (GameSettings.FOCUS_PREV_VESSEL.GetKeyDown())
                        {
                            if (HighLogic.CurrentGame != null && !HighLogic.CurrentGame.Parameters.Flight.CanSwitchVesselsNear)
                            {
                                PostMessage("Cannot switch vessels because it is disabled");
                                return;
                            }
                            if (HighLogic.LoadedSceneIsFlight)
                            {
                                CameraManager.Instance.SetCameraFlight();
                            }
                            this.vesselList.Clear();
                            currentIndex = FlightGlobals.Vessels.IndexOf(FlightGlobals.ActiveVessel);
                            do
                            {
                                currentIndex--;
                                if (currentIndex < 0)
                                {
                                    currentIndex += FlightGlobals.Vessels.Count;
                                }

                                currentVessel = FlightGlobals.Vessels [currentIndex];
                                if (currentVessel.loaded && currentVessel != FlightGlobals.ActiveVessel)
                                {
                                    //only allow switching to non-creature vessels
                                    if (!(currentVessel.rootPart is CreaturePart))
                                    {
                                        this.vesselList.Add(currentVessel);
                                    }
                                }
                            }while(currentVessel != FlightGlobals.ActiveVessel);
                        }
                        if (GameSettings.FOCUS_NEXT_VESSEL.GetKeyDown())
                        {
                            if (HighLogic.CurrentGame != null && !HighLogic.CurrentGame.Parameters.Flight.CanSwitchVesselsNear)
                            {
                                PostMessage("Cannot switch vessels because it is disabled");
                                return;
                            }
                            if (HighLogic.LoadedSceneIsFlight)
                            {
                                CameraManager.Instance.SetCameraFlight();
                            }
                            this.vesselList.Clear();
                            currentIndex = FlightGlobals.Vessels.IndexOf(FlightGlobals.ActiveVessel);
                            do
                            {
                                currentIndex++;
                                if (currentIndex >= FlightGlobals.Vessels.Count)
                                {
                                    currentIndex = 0;
                                }

                                currentVessel = FlightGlobals.Vessels [currentIndex];
                                if (currentVessel.loaded && currentVessel != FlightGlobals.ActiveVessel)
                                {
                                    //only allow switching to non-creature vessels
                                    if (!(currentVessel.rootPart is CreaturePart))
                                    {
                                        this.vesselList.Add(currentVessel);
                                    }
                                }
                            }while(currentVessel != FlightGlobals.ActiveVessel);
                        }
                        if (currentIndex != -1)
                        {
                            if (vesselList.Count <= 0)
                            {
                                PostMessage("No nearby objects to focus. Use the Map View to select distant ones.");
                            }
                            else
                            {
                                ClearToSaveStatus status = FlightGlobals.ClearToSave();
                                foreach (var vessel in vesselList)
                                {
                                    if (vessel.packed)
                                    {
                                        if (status != ClearToSaveStatus.CLEAR)
                                        {
                                            continue;
                                        }
                                    }
                                    FlightGlobals.ForceSetActiveVessel(vessel);
                                    FlightInputHandler.ResumeVesselCtrlState(vessel);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#11
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();
            }
示例#12
0
        public void FindPlayerVessel() // Find player vessel and switch to it if player was killed
        {
            var count = 0;

            List <Vessel> .Enumerator v = FlightGlobals.Vessels.GetEnumerator();
            while (v.MoveNext())
            {
                if (v.Current == null)
                {
                    continue;
                }
                if (!v.Current.loaded || v.Current.packed)
                {
                    continue;
                }

                if (count == 0) // check for player kerbals and switch to the first one found if available
                {
                    var kerbal = v.Current.FindPartModuleImplementing <ModuleOrXBDAc>();

                    if (kerbal != null)
                    {
                        if (kerbal.player)
                        {
                            FlightGlobals.ForceSetActiveVessel(v.Current);
                            FlightInputHandler.ResumeVesselCtrlState(v.Current);
                            count = 1;
                            break;
                        }
                    }
                }
            }
            v.Dispose();

            if (count == 0) // if previous list above doesn't find a player kerbal then check for player vessels and switch to the first one found if available
            {
                List <Vessel> .Enumerator vv = FlightGlobals.Vessels.GetEnumerator();
                while (vv.MoveNext())
                {
                    if (vv.Current == null)
                    {
                        continue;
                    }
                    if (!vv.Current.loaded || vv.Current.packed)
                    {
                        continue;
                    }

                    if (count == 0)
                    {
                        var wmPart = vv.Current.FindPartModuleImplementing <MissileFire>();

                        if (wmPart != null)
                        {
                            if (!wmPart.team)
                            {
                                FlightGlobals.ForceSetActiveVessel(vv.Current);
                                FlightInputHandler.ResumeVesselCtrlState(vv.Current);
                                count = 1;
                                break;
                            }
                        }
                    }
                }
                vv.Dispose();
            }

            if (count == 0) // if no player kerbals or vessels are found Game Over !!!!!!!
            {
                GameOver();
            }
        }