Beispiel #1
0
        public void AddTechEvent(string nodeName)
        {
            if (!IsEnabled)
            {
                return;
            }

            _techEvents.Add(new TechResearchEvent(KSPUtils.GetUT())
            {
                NodeName = nodeName
            });
        }
Beispiel #2
0
        private void VesselSituationChange(GameEvents.HostedFromToAction <Vessel, Vessel.Situations> ev)
        {
            // KJR can clobber the vessel back to prelaunch state in case of clamp wobble. Need to exclude such events.
            if (!_launched && ev.from == Vessel.Situations.PRELAUNCH && ev.host == FlightGlobals.ActiveVessel)
            {
                Debug.Log($"[RP-0] Launching {FlightGlobals.ActiveVessel?.vesselName}");

                _launched = true;
                _launchedVessels.Add(new LaunchEvent(KSPUtils.GetUT())
                {
                    VesselName = FlightGlobals.ActiveVessel?.vesselName
                });
            }
        }
Beispiel #3
0
        public void AddTechEvent(TechItem tech)
        {
            if (CareerEventScope.ShouldIgnore || !IsEnabled)
            {
                return;
            }

            _techEvents.Add(new TechResearchEvent(KSPUtils.GetUT())
            {
                NodeName     = tech.ProtoNode.techID,
                YearMult     = tech.YearBasedRateMult,
                ResearchRate = tech.BuildRate
            });
        }
Beispiel #4
0
 private void ContractAccepted(Contract c)
 {
     if (CareerEventScope.ShouldIgnore || c.AutoAccept)
     {
         return;                                                  // Do not record the Accept event for record contracts
     }
     _contractDict.Add(new ContractEvent(KSPUtils.GetUT())
     {
         Type         = ContractEventType.Accept,
         FundsChange  = c.FundsAdvance,
         RepChange    = 0,
         DisplayName  = c.Title,
         InternalName = GetContractInternalName(c)
     });
 }
Beispiel #5
0
        public void AddFailureEvent(Vessel v, string part, string type)
        {
            if (!IsEnabled)
            {
                return;
            }

            _failures.Add(new FailureEvent(KSPUtils.GetUT())
            {
                VesselUID = v.GetKCTVesselId(),
                LaunchID  = v.GetVesselLaunchId(),
                Part      = part,
                Type      = type
            });
        }
Beispiel #6
0
        public void AddFacilityConstructionEvent(SpaceCenterFacility facility, int newLevel, double cost, ConstructionState state)
        {
            if (CareerEventScope.ShouldIgnore || !IsEnabled)
            {
                return;
            }

            _facilityConstructions.Add(new FacilityConstructionEvent(KSPUtils.GetUT())
            {
                Facility = facility,
                NewLevel = newLevel,
                Cost     = cost,
                State    = state
            });
        }
Beispiel #7
0
        private void ContractCompleted(Contract c)
        {
            if (CareerEventScope.ShouldIgnore)
            {
                return;
            }

            _contractDict.Add(new ContractEvent(KSPUtils.GetUT())
            {
                Type         = ContractEventType.Complete,
                FundsChange  = c.FundsCompletion,
                RepChange    = c.ReputationCompletion,
                DisplayName  = c.Title,
                InternalName = GetContractInternalName(c)
            });
        }
Beispiel #8
0
        private void ContractFailed(Contract c)
        {
            string internalName = GetContractInternalName(c);
            double ut           = KSPUtils.GetUT();

            if (_contractDict.Any(c2 => c2.UT == ut && c2.InternalName == internalName))
            {
                // This contract was actually cancelled, not failed
                return;
            }

            _contractDict.Add(new ContractEvent(ut)
            {
                Type         = ContractEventType.Fail,
                FundsChange  = c.FundsFailure,
                RepChange    = c.ReputationFailure,
                DisplayName  = c.Title,
                InternalName = internalName
            });
        }
Beispiel #9
0
        private void ContractCancelled(Contract c)
        {
            // KSP first takes the contract penalty and then fires the contract events
            double fundsChange = 0;

            if (_prevFundsChangeReason == TransactionReasons.ContractPenalty)
            {
                Debug.Log($"[RP-0] Found that {_prevFundsChangeAmount} was given as contract penalty");
                fundsChange = _prevFundsChangeAmount;
            }

            _contractDict.Add(new ContractEvent(KSPUtils.GetUT())
            {
                Type         = ContractEventType.Cancel,
                FundsChange  = fundsChange,
                RepChange    = 0,
                DisplayName  = c.Title,
                InternalName = GetContractInternalName(c)
            });
        }
Beispiel #10
0
        private void VesselSituationChange(GameEvents.HostedFromToAction <Vessel, Vessel.Situations> ev)
        {
            if (CareerEventScope.ShouldIgnore)
            {
                return;
            }

            // KJR can clobber the vessel back to prelaunch state in case of clamp wobble. Need to exclude such events.
            if (!_launched && ev.from == Vessel.Situations.PRELAUNCH && ev.host == FlightGlobals.ActiveVessel)
            {
                Debug.Log($"[RP-0] Launching {FlightGlobals.ActiveVessel?.vesselName}");

                _launched = true;
                _launchedVessels.Add(new LaunchEvent(KSPUtils.GetUT())
                {
                    VesselName = FlightGlobals.ActiveVessel?.vesselName,
                    VesselUID  = ev.host.GetKCTVesselId(),
                    LaunchID   = ev.host.GetVesselLaunchId(),
                    BuiltAt    = ev.host.GetVesselBuiltAt() ?? EditorFacility.None // KSP can't serialize nullables
                });
            }
        }
Beispiel #11
0
        protected void FixedUpdate()
        {
            int pC;

            if (HighLogic.LoadedSceneIsFlight && part.CrewCapacity > 0 && (pC = part.protoModuleCrew.Count) > 0)
            {
                double UT = KSPUtils.GetUT();
                if (lastCheck < 0d)
                {
                    lastCheck = UT;
                }

                double deltaTime = UT - lastCheck;
                if (deltaTime > checkInterval)
                {
                    if (!_origDoStockGCalcs.HasValue)
                    {
                        _origDoStockGCalcs = ProtoCrewMember.doStockGCalcs;
                    }

                    lastCheck = UT;
                    double curAltitute = part.vessel.altitude;
                    if (curAltitute > crewDeathAltitude)
                    {
                        // Assume the standard atmosphere
                        if (referenceDensity < 0d)
                        {
                            referenceDensity    = Planetarium.fetch.Home.GetDensity(Planetarium.fetch.Home.GetPressure(crewDeathAltitude), Planetarium.fetch.Home.GetTemperature(crewDeathAltitude));
                            referenceDensityMin = referenceDensity * 0.02d;
                        }

                        timeSinceHypoxiaStarted += deltaTime;

                        ScreenMessages.PostScreenMessage($"Cockpit is above the safe altitude which will lead to crew incapacitation and eventually to death", 1f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red);

                        if (!_origDoStockGCalcs.HasValue)
                        {
                            _origDoStockGCalcs = ProtoCrewMember.doStockGCalcs;
                        }
                        ProtoCrewMember.doStockGCalcs = false;

                        bool killed = false;
                        for (int i = pC; i-- > 0;)
                        {
                            ProtoCrewMember pcm = part.protoModuleCrew[i];

                            double highGPenalty = vessel.geeForce > 3d ? System.Math.Pow(vessel.geeForce - 2d, 2d) : 1;

                            double curDensity = part.atmDensity;
                            if (curDensity < referenceDensityMin)
                            {
                                curDensity = referenceDensityMin;
                            }

                            double altitudeMult = (curAltitute - crewDeathAltitude) / crewDeathAltitude * 10d + referenceDensity / curDensity - 1d;

                            double timeMult = System.Math.Pow(timeSinceHypoxiaStarted, 1.5d) * 0.01d;

                            pcm.gExperienced += (0.5d + rnd.NextDouble()) * gDamageAdder * highGPenalty * altitudeMult * timeMult;

                            double gMult = ProtoCrewMember.GToleranceMult(pcm) * HighLogic.CurrentGame.Parameters.CustomParams <GameParameters.AdvancedParams>().KerbalGToleranceMult;
                            _anyCrewAboveWarnThreshold = pcm.gExperienced > PhysicsGlobals.KerbalGThresholdWarn * gMult;

                            double locThreshold = PhysicsGlobals.KerbalGThresholdLOC * gMult;
                            if (!pcm.outDueToG && pcm.gExperienced > locThreshold)
                            {
                                // Just passed out
                                ScreenMessages.PostScreenMessage($"<color=red>{pcm.name} has lost consciousness due to hypoxia!</color>", 5.5f, ScreenMessageStyle.UPPER_CENTER);
                            }

                            // There's at least one cycle of delay after passing out before the death chance rolls start
                            if (pcm.outDueToG && rnd.NextDouble() < crewDeathChance * altitudeMult * timeMult)
                            {
                                killed = true;
                                ScreenMessages.PostScreenMessage($"{vessel.vesselName}: Crewmember {pcm.name} has died from exposure to near-vacuum.", 30.0f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red);
                                FlightLogger.fetch.LogEvent($"[{KSPUtil.PrintTime(vessel.missionTime, 3, false)}] {pcm.name} died from exposure to near-vacuum.");
                                part.RemoveCrewmember(pcm);
                                pcm.Die();
                            }
                        }

                        if (killed && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA)
                        {
                            CameraManager.Instance.SetCameraFlight();
                        }
                    }
                    else
                    {
                        timeSinceHypoxiaStarted = 0d;

                        if (_origDoStockGCalcs.HasValue)
                        {
                            ProtoCrewMember.doStockGCalcs = _origDoStockGCalcs.Value;
                            _origDoStockGCalcs            = null;
                        }
                    }
                }
            }
        }
Beispiel #12
0
        protected void FixedUpdate()
        {
            int pC;

            if (HighLogic.LoadedSceneIsFlight && part.CrewCapacity > 0 && (pC = part.protoModuleCrew.Count) > 0)
            {
                double UT = KSPUtils.GetUT();
                if (nextCheck < 0d)
                {
                    nextCheck = UT + checkInterval;
                }
                else if (UT > nextCheck)
                {
                    if (pressureAtKillAltitude == default)
                    {
                        pressureAtKillAltitude = FlightGlobals.GetHomeBody().GetPressureAtm(crewDeathAltitude);
                        _origDoStockGCalcs     = ProtoCrewMember.doStockGCalcs;
                    }

                    nextCheck = UT + checkInterval;
                    if (part.staticPressureAtm < pressureAtKillAltitude)
                    {
                        ScreenMessages.PostScreenMessage($"Cockpit is above the safe altitude which will lead to crew incapacitation and eventually to death", 1f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red);

                        if (!_origDoStockGCalcs.HasValue)
                        {
                            _origDoStockGCalcs = ProtoCrewMember.doStockGCalcs;
                        }
                        ProtoCrewMember.doStockGCalcs = false;

                        bool killed = false;
                        for (int i = pC; i-- > 0;)
                        {
                            ProtoCrewMember pcm = part.protoModuleCrew[i];

                            double highGPenalty = vessel.geeForce > 3 ? vessel.geeForce : 1;
                            pcm.gExperienced += (0.5d + rnd.NextDouble()) * gDamageAdder * highGPenalty;

                            double gMult = ProtoCrewMember.GToleranceMult(pcm) * HighLogic.CurrentGame.Parameters.CustomParams <GameParameters.AdvancedParams>().KerbalGToleranceMult;
                            _anyCrewAboveWarnThreshold = pcm.gExperienced > PhysicsGlobals.KerbalGThresholdWarn * gMult;

                            double locThreshold = PhysicsGlobals.KerbalGThresholdLOC * gMult;
                            if (!pcm.outDueToG && pcm.gExperienced > locThreshold)
                            {
                                // Just passed out
                                ScreenMessages.PostScreenMessage($"<color=red>{pcm.name} has lost consciousness due to hypoxia!</color>", 5.5f, ScreenMessageStyle.UPPER_CENTER);
                            }

                            // There's at least one cycle of delay after passing out before the death chance rolls start
                            if (pcm.outDueToG && rnd.NextDouble() < crewDeathChance)
                            {
                                killed = true;
                                ScreenMessages.PostScreenMessage($"{vessel.vesselName}: Crewmember {pcm.name} has died from exposure to near-vacuum.", 30.0f, ScreenMessageStyle.UPPER_CENTER, XKCDColors.Red);
                                FlightLogger.fetch.LogEvent($"[{KSPUtil.PrintTime(vessel.missionTime, 3, false)}] {pcm.name} died from exposure to near-vacuum.");
                                part.RemoveCrewmember(pcm);
                                pcm.Die();
                            }
                        }

                        if (killed && CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA)
                        {
                            CameraManager.Instance.SetCameraFlight();
                        }
                    }
                    else
                    {
                        if (_origDoStockGCalcs.HasValue)
                        {
                            ProtoCrewMember.doStockGCalcs = _origDoStockGCalcs.Value;
                            _origDoStockGCalcs            = null;
                        }
                    }
                }
            }
        }