Exemplo n.º 1
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 (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("[KerbalSafety]: " + kerbalName + " is leaving their seat on " + seat.part.vessel.vesselName + ".");
                        seat.LeaveSeat(new KSPActionParam(KSPActionGroup.Abort, KSPActionType.Activate));
                    }
                    else
                    {
                        Debug.Log("[KerbalSafety]: " + kerbalName + " has already left their seat.");
                    }
                    StartCoroutine(PostEjection());
                    StartCoroutine(DelayedChuteDeployment());
                    StartCoroutine(RecoverWhenPossible());
                }
            }
            else if (crew != null) // Eject from a cockpit.
            {
                Debug.Log("[KerbalSafety]: DEBUG skipping ejection for " + kerbalName + " in cockpit " + part + " for now."); return;
                // kerbalEVA = FlightEVA.fetch.spawnEVA(kerbalPCM, part, part.airlock, true);
                // if (kerbalEVA)
                // {
                //     Debug.Log("[KerbalSafety]: " + kerbalPCM.displayName + " ejected from " + part.vessel.vesselName + " at " + part.vessel.radarAltitude.ToString("0.0") + "m.");
                //     kerbalEVA.autoGrabLadderOnStart = false; // Don't grab the vessel.
                //     chute = kerbalEVA.vessel.FindPartModuleImplementing<ModuleEvaChute>();
                //     if (chute != null)
                //         chute.deploymentState = ModuleEvaChute.deploymentStates.STOWED; // Make sure the chute is stowed.
                //     // DeactivatePilot();
                //     StartCoroutine(PostEjection());
                // }
                // else
                // {
                //     // All exits were blocked by something. FIXME Try adjusting the fromAirlock Transform in spawnEVA.
                //     // BDACompetitionMode.Instance.competitionStatus.Add(kerbalPCM.displayName + " failed to eject from " + part.vessel.vesselName + ", all exits were blocked. RIP.");
                //     Debug.Log("[KerbalSafety]: " + kerbalPCM.displayName + " failed to eject from " + part.vessel.vesselName + ", all exits were blocked. RIP.");
                //     part.vessel.RemoveCrew(kerbalPCM); // Save their ghost.
                //     // StartCoroutine(ExplodeStuffThenEject());
                //     // ExplodeStuffThenEject();
                // }
            }
            else
            {
                Debug.LogError("[KerbalSafety]: Ejection called without a kerbal present.");
            }
            ejected = true;
        }
Exemplo n.º 2
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;
        }