Пример #1
0
        /// <summary>
        /// Ejects the Kerbal from the capsule
        /// </summary>
        private void GoEject()
        {
            print("Go eject...");
            InternalSeat commandSeat = part.internalModel.seats[0];

            if (commandSeat.taken == true)
            {
                activeKerbal = commandSeat.kerbalRef;
                commandSeat.DespawnCrew();
                FlightEVA.SpawnEVA(activeKerbal);

                bool test = FlightGlobals.ActiveVessel;

                currentKerbalEVA = FlightGlobals.ActiveVessel.GetComponent <KerbalEVA>();
                print("OK...");

                if (currentKerbalEVA.OnALadder)
                {
                    print("On ladder...");
                    currentKerbalEVA.OnVesselGoOffRails(FlightGlobals.ActiveVessel);
                }

                CameraManager.Instance.SetCameraFlight();
                activeKerbal = null;
            }
        }
Пример #2
0
        public static void GoEVA()
        {
            List <ProtoCrewMember> crew = FlightGlobals.ActiveVessel.GetVesselCrew();

            for (int i = 0; i < crew.Count; i++)
            {
                ProtoCrewMember pcm = crew[i];
                if (pcm != null && HighLogic.CurrentGame.Parameters.Flight.CanEVA)
                {
                    if (pcm.KerbalRef.eyeTransform == InternalCamera.Instance.transform.parent)
                    {
                        if (!(pcm.KerbalRef.state == Kerbal.States.ALIVE &&
                              !pcm.KerbalRef.InPart.packed &&
                              HighLogic.CurrentGame.Parameters.Flight.CanEVA &&
                              !pcm.KerbalRef.InPart.NoAutoEVA &&
                              !pcm.inactive &&
                              pcm.type != ProtoCrewMember.KerbalType.Tourist &&
                              (GameVariables.Instance.UnlockedEVA(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.AstronautComplex)) ||
                               (FlightGlobals.ActiveVessel.mainBody == Planetarium.fetch.Home && FlightGlobals.ActiveVessel.LandedOrSplashed))))
                        {
                            ScreenMessages.PostScreenMessage(GameVariables.Instance.GetEVALockedReason(FlightGlobals.ActiveVessel, pcm), 5);
                            return;
                        }
                        FlightEVA.SpawnEVA(pcm.KerbalRef);
                        CameraManager.Instance.SetCameraFlight();
                        pcm.KerbalRef.state = Kerbal.States.BAILED_OUT;
                        break;
                    }
                }
            }
        }
        protected virtual bool ExpelCrewman()
        {
            List <ProtoCrewMember> crewChoices = new List <ProtoCrewMember>();

            foreach (var crewable in crewableParts)
            {
                crewChoices.AddRange(crewable.protoModuleCrew);
            }

            if (crewChoices.Count == 0)
            {
                return(false);
            }
            if (MapView.MapIsEnabled)
            {
                MapView.ExitMapView();
            }

            if ((CameraManager.Instance.currentCameraMode & (CameraManager.CameraMode.Internal | CameraManager.CameraMode.IVA)) != 0)
            {
                CameraManager.Instance.SetCameraFlight();
            }

            var luckyKerbal = crewChoices[UnityEngine.Random.Range(0, crewChoices.Count - 1)];

            return(FlightEVA.SpawnEVA(luckyKerbal.KerbalRef));
        }
Пример #4
0
        private void CheckForLatching()
        {
            FindPotato();
            //If we're connected, then we should be latched.
            bool expectedLatch = _potato != null;

            if (expectedLatch != _isLatched)
            {
                _isLatched = expectedLatch;
                if (_isLatched)
                {
                    status            = "Connected";
                    part.CrewCapacity = 4;
                    LatchAnimation[latchAnimationName].speed = 1;
                    LatchAnimation.Play(latchAnimationName);
                }
                else
                {
                    status = "Not Connected";
                    foreach (var c in part.protoModuleCrew)
                    {
                        FlightEVA.SpawnEVA(c.KerbalRef);
                    }
                    part.CrewCapacity = part.protoModuleCrew.Count();
                    LatchAnimation[latchAnimationName].speed = -1;
                    LatchAnimation[latchAnimationName].time  = LatchAnimation[latchAnimationName].length;
                    LatchAnimation.Play(latchAnimationName);
                }
            }
        }
Пример #5
0
        protected virtual bool ExpelCrewman()
        {
            List <ProtoCrewMember> crewChoices = new List <ProtoCrewMember>();

            //crewChoices.AddRange(crewableParts[i].protoModuleCrew);

            for (int i = crewableParts.Count - 1; i >= 0; i--)
            {
                for (int i1 = crewableParts[i].protoModuleCrew.Count - 1; i1 >= 0; i1--)
                {
                    if (crewableParts[i].protoModuleCrew[i1].type == ProtoCrewMember.KerbalType.Crew)
                    {
                        crewChoices.Add(crewableParts[i].protoModuleCrew[i1]);
                    }
                }
            }
            if (crewChoices.Count == 0)
            {
                return(false);
            }
            if (MapView.MapIsEnabled)
            {
                MapView.ExitMapView();
            }

            if ((CameraManager.Instance.currentCameraMode & (CameraManager.CameraMode.Internal | CameraManager.CameraMode.IVA)) != 0)
            {
                CameraManager.Instance.SetCameraFlight();
            }

            var luckyKerbal = crewChoices[UnityEngine.Random.Range(0, crewChoices.Count - 1)];

            return(FlightEVA.SpawnEVA(luckyKerbal.KerbalRef));
        }
Пример #6
0
        private bool EjectFromOtherPart()
        {
            Part fromPart = part;

            foreach (var toPart in part.vessel.parts)
            {
                if (toPart == part)
                {
                    continue;
                }
                if (toPart.CrewCapacity > 0 && !FlightEVA.hatchInsideFairing(toPart) && !FlightEVA.HatchIsObstructed(toPart, toPart.airlock))
                {
                    var crewTransfer = CrewTransfer.Create(fromPart, crew, OnDialogDismiss);
                    if (crewTransfer.validParts.Contains(toPart))
                    {
                        Debug.Log("[BDArmory.KerbalSafety]: Transferring " + kerbalName + " from " + fromPart + " to " + toPart + " then ejecting.");
                        crewTransfer.MoveCrewTo(toPart);
                        if (ProcessEjection(toPart))
                        {
                            return(true);
                        }
                        fromPart = toPart;
                    }
                }
            }
            return(false);
        }
Пример #7
0
 private void GoEva()
 {
     if (activeKerbal != null)
     {
         FlightEVA.SpawnEVA(activeKerbal);
         CameraManager.Instance.SetCameraFlight();
         activeKerbal = null;
     }
 }
Пример #8
0
        /// <summary>
        /// Toss a random kerbal out the airlock
        /// </summary>
        /// <returns></returns>
        protected virtual bool ExpelCrewman()
        {
            // You might think HighLogic.CurrentGame.CrewRoster.GetNextAvailableCrewMember
            // is a logical function to use.  Actually it's possible for it to
            // generate a crew member out of thin air and put it outside, so nope
            //
            // luckily we can specify a particular onboard Kerbal.  We'll do so by
            // finding the possibilities and then picking one totally at
            // pseudorandom

            List <ProtoCrewMember> crewChoices = new List <ProtoCrewMember>();

            foreach (var crewable in crewableParts)
            {
                crewChoices.AddRange(crewable.protoModuleCrew);
            }

            if (crewChoices.Count == 0)
            {
                Log.Error("{0}.Deploy - No crew choices available.  Check logic", GetType().Name);
                return(false);
            }
            else
            {
                // 1.4b bugfix for the 1.4a buxfix:
                //  if the player is in map view, SetCameraFlight won't shut it
                // down for us. Whoops
                if (MapView.MapIsEnabled)
                {
                    MapView.ExitMapView();
                }

                // 1.4a bugfix:
                //   if the player is in IVA view when we spawn eva, it looks
                // like KSP doesn't switch cameras automatically
                if ((CameraManager.Instance.currentCameraMode & (CameraManager.CameraMode.Internal | CameraManager.CameraMode.IVA)) != 0)
                {
                    Log.Normal("Detected IVA or internal cam; switching to flight cam");
                    CameraManager.Instance.SetCameraFlight();
                }


                Log.Debug("Choices of kerbal:");
                foreach (var crew in crewChoices)
                {
                    Log.Debug(" - {0}", crew.name);
                }

                // select a kerbal target...
                var luckyKerbal = crewChoices[UnityEngine.Random.Range(0, crewChoices.Count - 1)];
                Log.Debug("{0} is the lucky Kerbal.  Out the airlock with him!", luckyKerbal.name);

                // out he goes!
                return(FlightEVA.SpawnEVA(luckyKerbal.KerbalRef));
            }
        }
Пример #9
0
        // FIXME to be part of an update loop (maybe)
        // void EjectOnImpendingDoom()
        // {
        //     if (!ejected && ejectOnImpendingDoom * (float)vessel.srfSpeed > ai.terrainAlertDistance)
        //     {
        //         KerbalSafety.Instance.Eject(vessel, this); // Abandon ship!
        //         ai.avoidingTerrain = false;
        //     }
        // }

        #region Ejection
        /// <summary>
        /// Eject from a vessel.
        /// </summary>
        public void Eject()
        {
            if (ejected)
            {
                return;          // We've already ejected.
            }
            if (part == null || part.vessel == null)
            {
                return;                                      // The vessel is gone, don't try to do anything.
            }
            if (BDArmorySettings.DRAW_DEBUG_LABELS)
            {
                Debug.Log("[BDArmory.KerbalSafety]: Ejection triggered for " + kerbalName + " in " + part);
            }
            if (kerbalEVA != null)
            {
                if (kerbalEVA.isActiveAndEnabled)             // Otherwise, they've been killed already and are being cleaned up by KSP.
                {
                    if (seat != null && kerbalEVA.IsSeated()) // Leave the seat.
                    {
                        Debug.Log("[BDArmory.KerbalSafety]: " + kerbalName + " is leaving their seat on " + seat.part.vessel.vesselName + ".");
                        seat.LeaveSeat(new KSPActionParam(KSPActionGroup.Abort, KSPActionType.Activate));
                    }
                    else
                    {
                        Debug.Log("[BDArmory.KerbalSafety]: " + kerbalName + " has already left their seat.");
                    }
                    StartCoroutine(DelayedChuteDeployment());
                    StartCoroutine(RecoverWhenPossible());
                }
            }
            else if (crew != null && part.protoModuleCrew.Contains(crew) && !FlightEVA.hatchInsideFairing(part)) // Eject from a cockpit.
            {
                if (BDArmorySettings.KERBAL_SAFETY < 2)
                {
                    return;
                }
                if (!ProcessEjection(part))    // All exits were blocked by something.
                {
                    if (!EjectFromOtherPart()) // Look for other airlocks to spawn from.
                    {
                        message = kerbalName + " failed to eject from " + part.vessel.vesselName + ", all exits were blocked. R.I.P.";
                        BDACompetitionMode.Instance.competitionStatus.Add(message);
                        Debug.Log("[BDArmory.KerbalSafety]: " + message);
                    }
                }
            }
            else
            {
                Debug.LogWarning("[BDArmory.KerbalSafety]: Ejection called without a kerbal present.");
            }
            ejected = true;
        }
Пример #10
0
        private void OnUpdateIVA(KerbalInfo kerbal)
        {
            _Camera.Update(kerbal);

            Debug.Log("G");
            if (Input.GetKeyDown(BeKerbal.Settings.IVA_GoToEVAKeyCode))
            {
                CameraManager.Instance.SetCameraFlight();
                FlightEVA.SpawnEVA(kerbal.Kerbal);
            }
            Debug.Log("H");
        }
        // EVA Menu
        private void CrewEVA(int index, TextMenu.Item ti)
        {
            var   vesselCrew  = vessel.GetVesselCrew();
            float acLevel     = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.AstronautComplex);
            bool  evaUnlocked = GameVariables.Instance.UnlockedEVA(acLevel);
            bool  evaPossible = GameVariables.Instance.EVAIsPossible(evaUnlocked, vessel);

            if (evaPossible && ti.id < vesselCrew.Count && vesselCrew[ti.id] != null && HighLogic.CurrentGame.Parameters.Flight.CanEVA)
            {
                FlightEVA.SpawnEVA(vesselCrew[ti.id].KerbalRef);
                CameraManager.Instance.SetCameraFlight();
            }
        }
Пример #12
0
        /// <summary>
        /// Begins the EVA for the active kerbal. Based on Mihara's Internal Module code for EVA.
        /// https://github.com/Mihara/RasterPropMonitor/blob/master/RasterPropMonitor/Auxiliary%20modules/JSIInternalEVAHatch.cs
        /// </summary>
        private void GoEva()
        {
            InternalSeat commandSeat = part.internalModel.seats[0];

            if (commandSeat.taken == true)
            {
                activeKerbal = commandSeat.kerbalRef;
                commandSeat.DespawnCrew();
                FlightEVA.SpawnEVA(activeKerbal);
                CameraManager.Instance.SetCameraFlight();
                activeKerbal = null;
            }
        }
Пример #13
0
 private void DumpCrew()
 {
     if (part.protoModuleCrew.Any())
     {
         try
         {
             var c = part.protoModuleCrew.First();
             FlightEVA.SpawnEVA(c.KerbalRef);
         }
         catch (Exception)
         {
             print("[ART] problem removing crewmember");
         }
     }
 }
Пример #14
0
 void GoEVA(Vessel vessel)
 {
     if (CheckEVAUnlocked(vessel))
     {
         if (!vessel.isEVA && !vessel.packed)
         {
             if (vessel.GetCrewCount() > 0)
             {
                 Kerbal _first;
                 if (VesselHasCrewAlive(vessel, out _first))
                 {
                     Kerbal _kerbal = (isIVA() ? CheckIVAKerbal(vessel) : _first);
                     FlightEVA.SpawnEVA(_kerbal);
                     CameraManager.Instance.SetCameraFlight();
                     Log(string.Format("GoEVA {0}({1}) experienceTrait: {2}", _kerbal.crewMemberName, _kerbal.protoCrewMember.seatIdx, _kerbal.protoCrewMember.experienceTrait.Title), "QIVA");
                 }
                 else
                 {
                     ScreenMessages.PostScreenMessage("[QuickIVA] This vessel has no crew alive.", 5, ScreenMessageStyle.UPPER_CENTER);
                 }
             }
             else
             {
                 ScreenMessages.PostScreenMessage("[QuickIVA] This vessel has no crew.", 5, ScreenMessageStyle.UPPER_CENTER);
             }
         }
         else
         {
             ScreenMessages.PostScreenMessage("[QuickIVA] You can't EVA an EVA.", 5, ScreenMessageStyle.UPPER_CENTER);
         }
     }
     else
     {
         ScreenMessages.PostScreenMessage("[QuickIVA] EVA is locked: " + GameVariables.Instance.GetEVALockedReason(vessel, vessel.GetVesselCrew()[0]), 5, ScreenMessageStyle.UPPER_CENTER);
     }
 }
        // PRIVATE METHODS //

        private IEnumerator GoEVADelayed(Kerbal kerbal)
        {
            yield return(new WaitForFixedUpdate());

            FlightEVA.SpawnEVA(kerbal);
        }
Пример #16
0
        /// <summary>
        /// This method controls how the window actually looks when the HUD window is displayed.
        /// </summary>
        public void PopulationManagementGUI(int windowId)
        {
            string activeVesselName   = FlightGlobals.ActiveVessel.vesselName;
            string activeVesselStatus = FlightGlobals.ActiveVessel.situation.ToString();
            string activeSoI          = FlightGlobals.currentMainBody.name;

            if (activeVesselName != null)
            {
                activeVesselName = FlightGlobals.ActiveVessel.vesselName;
            }
            else
            {
                activeVesselName = "[Could not find name]";
            }
            int numCivilians = 0;
            List <ProtoCrewMember> listCivilians = new List <ProtoCrewMember>();

            foreach (ProtoCrewMember crewMember in FlightGlobals.ActiveVessel.GetVesselCrew())
            {
                if (crewMember.trait == debuggingClass.civilianTrait)
                {
                    listCivilians.Add(crewMember);
                    numCivilians++;
                }
            }

            //begin GUI
            GUILayout.BeginVertical();

            //row for ship information
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("Vessel Name:  " + activeVesselName);
                GUILayout.Label("Status:  " + activeVesselStatus);
                GUILayout.Label("SoI:  " + activeSoI);
            }
            GUILayout.EndHorizontal();

            //row for civilian information
            GUILayout.BeginHorizontal();
            {
                GUILayout.BeginVertical();
                if (GUILayout.Button("Show Civilian Info"))
                {
                    showPopInfo = !showPopInfo;
                    Debug.Log(debuggingClass.modName + "Civilian Info button pressed. New value:  " + showPopInfo);
                }
                if (showPopInfo)
                {
                    if (listCivilians.FirstOrDefault() != null)
                    {
                        foreach (ProtoCrewMember crewMember in listCivilians)
                        {
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.Label(crewMember.trait);
                                GUILayout.Label(crewMember.name);
                                if (GUILayout.Button("EVA"))
                                {
                                    Debug.Log(debuggingClass.modName + "User pressed button to initiate EVA of " + crewMember.name);
                                    FlightEVA.SpawnEVA(crewMember.KerbalRef);
                                }

                                /*if(GUILayout.Button("Transfer")){
                                 * Debug.Log (debuggingClass.modName + "User pressed button to initiated transfer of " + crewMember.name);
                                 * CrewTransfer.Create(crewMember.seat.part,crewMember);
                                 * }Transfer disabled for now; need to figure out how to use highlighting from ShipManifest mod...*/
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                }
                GUILayout.EndVertical();
                GUILayout.Label("Civilians:  " + numCivilians);
                GUILayout.Label("Crew Capacity:  " + FlightGlobals.ActiveVessel.GetCrewCount() + "/" + FlightGlobals.ActiveVessel.GetCrewCapacity());
            }
            GUILayout.EndHorizontal();

            //row for close button
            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Close this Window", GUILayout.Width(200f)))
                {
                    Debug.Log(debuggingClass.modName + "Closing CivPopGUI window");
                    OnToggleFalse();
                }
                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUI.DragWindow();
        }
Пример #17
0
        public override void OnUpdate()
        {
            Log.Info("OnUpdate 1");
            if (HighLogic.LoadedSceneIsFlight) // && vessel.HoldPhysics == true)
            {
                // Make sure controls are unlocked (workaround for compatibility issue with Kerbal Joint Reinforcement)
                if (InputLockManager.GetControlLock("KJRLoadLock") != ControlTypes.ALL_SHIP_CONTROLS)
                {
                    if (this.part.protoModuleCrew.Count > 0 && allCommandSeats.Count == 0)
                    {
                        print("[TakeCommand] populating seat list");
                        foreach (Part p in vessel.parts)
                        {
                            if (p.Modules.OfType <TakeCommand>().Any())
                            {
                                if (p.protoModuleCrew.Count > 0)
                                {
                                    allCommandSeats.Add(p);
                                }
                            }
                        }
                        print("[TakeCommand] found " + allCommandSeats.Count + " occupied seats");
                    }
                    Log.Info("this.part.protoModuleCrew.Count: " + this.part.protoModuleCrew.Count());
#if true
                    if (!error)
                    {
                        Log.Info("OnUpdate 2");

                        if (FlightEVA.hatchInsideFairing(this.part))
                        {
                            ScreenMessages.PostScreenMessage(part.partInfo.title + " is inside a fairing (not allowed)", 15.0f, ScreenMessageStyle.UPPER_CENTER);
                            ScreenMessages.PostScreenMessage("Revert and try again", 15.0f, ScreenMessageStyle.UPPER_CENTER);
                            error = true;
                        }
                        else
                        {
                            Log.Info("OnUpdate 3");

                            if (boardKerbal == false)
                            {
                                Log.Info("OnUpdate 4");

                                Log.Info("boardKerbal");
                                if (this.part.protoModuleCrew.Count > 0 && allCommandSeats.First().GetInstanceID() == this.part.GetInstanceID())
                                {
                                    // Time to eject this crew member
                                    ProtoCrewMember kerbal;
                                    while (this.part.protoModuleCrew.Count() > 0)
                                    {
                                        kerbal = this.part.protoModuleCrew[0];
                                        //ProtoCrewMember kerbal = this.part.protoModuleCrew.First();
                                        print("[TakeCommand] ejecting " + kerbal.name + " from " + this.part.GetInstanceID());
                                        escapeHatch.GetComponent <Collider>().enabled = true;
                                        if (FlightEVA.fetch.spawnEVA(kerbal, this.part, escapeHatch.transform))
                                        {
                                            myKerbal       = "kerbalEVA (" + kerbal.name + ")";
                                            myFemaleKerbal = "kerbalEVAfemale (" + kerbal.name + ")";

                                            boardKerbal = true;
                                            escapeHatch.GetComponent <Collider>().enabled = false;
                                        }
                                        else
                                        {
                                            print("[TakeCommand] error ejecting " + kerbal.name);
                                            ScreenMessages.PostScreenMessage("Unable to put kerbal: " + kerbal.name + " into the external seat", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                                            ScreenMessages.PostScreenMessage("Revert and try again", 5.0f, ScreenMessageStyle.UPPER_CENTER);

                                            error = true;
                                            Log.Info("Error set true");
                                            break;
                                            //    this.part.protoModuleCrew.Remove(kerbal);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Log.Info("OnUpdate 5");

                                // Check and wait until the ejected Kerbal is the active vessel before proceeding
                                Log.Info("this.vessel.name: " + this.vessel.name);
                                Log.Info("FlightGlobals.ActiveVessel.name: " + FlightGlobals.ActiveVessel.name);
                                if (this.vessel == FlightGlobals.ActiveVessel)
                                {
                                    Log.Info("this.vessel is activevessel, myKerbal: " + myKerbal);
                                }
                                if (FlightGlobals.ActiveVessel.name == myKerbal || FlightGlobals.ActiveVessel.name == myFemaleKerbal)
                                {
                                    KerbalEVA kerbal = FlightGlobals.ActiveVessel.GetComponent <KerbalEVA>();
                                    Log.Info("kerbal.fsm.currentStateName: " + kerbal.fsm.currentStateName);
                                    if (kerbal.fsm.Started == true)
                                    {
                                        allCommandSeats.Remove(allCommandSeats.First());
                                        //allCommandSeats.Remove(this.part);
                                        boardKerbal = false;

                                        if (kerbal.flagItems == 0)
                                        {
                                            kerbal.AddFlag();
                                        }

                                        print("[TakeCommand]  seating " + kerbal.name + " in " + this.part.GetInstanceID());
                                        // Board in first unoccupied seat
                                        var freeModule = this.part.Modules.OfType <KerbalSeat>().First(t => t.Occupant == null);

                                        freeModule.BoardSeat();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.Info("error is true");
                    }
#endif
                }
            }
            base.OnUpdate();
        }