예제 #1
0
        /// <summary>
        /// The main method for updating all kerbals' health and processing events
        /// </summary>
        /// <param name="forced">Whether to process kerbals regardless of the amount of time passed</param>
        void UpdateKerbals(bool forced)
        {
            double time       = Planetarium.GetUniversalTime();
            double timePassed = time - lastUpdated;

            if (timePassed <= 0)
            {
                return;
            }
            if (forced || ((timePassed >= Core.UpdateInterval) && (timePassed >= Core.MinUpdateInterval * TimeWarp.CurrentRate)))
            {
                Core.Log("UT is " + time + ". Updating for " + timePassed + " seconds.");
                Core.ClearCache();
                Core.KerbalHealthList.Update(timePassed);
                lastUpdated = time;
                if (Core.EventsEnabled)
                {
                    while (time >= nextEventTime)  // Can take several turns of event processing at high time warp
                    {
                        Core.Log("Processing events...");
                        Core.KerbalHealthList.ProcessEvents();
                        nextEventTime += GetNextEventInterval();
                        Core.Log("Next event processing is scheduled at " + KSPUtil.PrintDateCompact(nextEventTime, true), Core.LogLevel.Important);
                    }
                }
                dirty = true;
            }
        }
예제 #2
0
        private void updateVesselData()
        {
            var vessel = this.currentVessel;

            bool hasNextNode = false;

            var nextNodeTime = Vessel.GetNextManeuverTime(vessel, out hasNextNode);

            // some stuff doesn't need to be updated if it's not changing
            var shouldUpdate = vessel.isActiveVessel || vessel.loaded || !this.vesselData.Id.Equals(vessel.id);

            var vesselData = new VesselData
            {
                Id           = vessel.id,
                OrbitData    = OrbitData.FromOrbit(vessel.orbit),
                Resources    = shouldUpdate ? updateVesselResourceData(vessel) : this.vesselData.Resources,
                CrewData     = shouldUpdate ? this.updateVesselCrewData(vessel) : this.vesselData.CrewData,
                MET          = Converters.Duration(Math.Abs(vessel.missionTime)),
                HasNextNode  = hasNextNode,
                NextNodeIn   = "T " + KSPUtil.PrintTime(Planetarium.GetUniversalTime() - nextNodeTime, 3, true),
                NextNodeTime = KSPUtil.PrintDateCompact(nextNodeTime, true, true),
                Situation    = Vessel.GetSituationString(vessel),
            };

            this.vesselData = vesselData;
        }
예제 #3
0
        private void Render(int windowID)
        {
            //All this defines the window itself
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace(); //This setup will center the text in the window

            TimeSpan?timer = timeKeeper.OutsourceTimer();

            if (timer.HasValue)
            {
                GUILayout.Label(timer.Value.Minutes + "m " + timer.Value.Seconds + "s ", HighLogic.Skin.label);
            }
            else if (mouseOver)
            {
                if (GUILayout.Button("Outsource!", HighLogic.Skin.button))
                {
                    timeKeeper.Outsource();
                }
            }
            else
            {
                GUILayout.Label(KSPUtil.PrintDateCompact((int)HighLogic.CurrentGame.flightState.universalTime, true, true), HighLogic.Skin.label);
            }

            if (Event.current.type == EventType.Repaint)
            {
                mouseOver = GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            //Allow the window to be dragged around
            GUI.DragWindow();
        }
예제 #4
0
        public void TimeWindow(int windowID)
        {
            //All this defines the window itself
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace(); //This setup will center the text in the window
            GUILayout.Label(KSPUtil.PrintDateCompact((int)HighLogic.CurrentGame.flightState.universalTime, true, true), HighLogic.Skin.label);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            //Allow the window to be dragged around
            GUI.DragWindow();
        }
예제 #5
0
        public static string GetTimeLabel(SubspaceDisplayEntry currentEntry)
        {
            StringBuilder.Length = 0;

            var subspaceTime = WarpSystem.Singleton.GetSubspaceTime(currentEntry.SubspaceId);

            StringBuilder.Append(KSPUtil.PrintDateCompact(subspaceTime, true, true));

            if (WarpSystem.Singleton.CurrentSubspace != currentEntry.SubspaceId)
            {
                AppendDeltaTime(subspaceTime);
            }

            return(StringBuilder.ToString());
        }
예제 #6
0
 public static OrbitData FromOrbit(Orbit orbit)
 {
     return(new OrbitData
     {
         SOI = orbit.referenceBody.bodyName,
         AP = Converters.Distance(Math.Max(0, orbit.ApA)),
         PE = Converters.Distance(Math.Max(0, orbit.PeA)),
         timeToAP = Converters.Duration(Math.Max(0, orbit.timeToAp)),
         timeToPE = Converters.Duration(Math.Max(0, orbit.timeToPe)),
         INC = orbit.inclination.ToString("F3") + "°",
         Period = Converters.Duration(Math.Max(0, orbit.period), 4),
         IsSOIChange = orbit.patchEndTransition == Orbit.PatchTransitionType.ESCAPE || orbit.patchEndTransition == Orbit.PatchTransitionType.ENCOUNTER,
         SOIChangeTime = Converters.Duration(orbit.UTsoi - Planetarium.GetUniversalTime()),
         SOIChangeDate = KSPUtil.PrintDateCompact(orbit.UTsoi, true, true)
     });
 }
예제 #7
0
        protected override void DrawContent()
        {
            var orbit = FlightGlobals.ActiveVessel.GetOrbit();

            Util.Columns(new [] { "Parameter", "Value" });
            Util.Table(new Dictionary <string, string>
            {
                { "ApA", string.Format("{0:F3} km", orbit.ApA / 1000) },
                { "PeA", string.Format("{0:F3} km", orbit.PeA / 1000) },
                { "ApT", KSPUtil.PrintDateCompact(orbit.timeToAp, false, true) },
                { "PeT", KSPUtil.PrintDateCompact(orbit.timeToPe, false, true) },
                { "Alt", string.Format("{0:F3} km", orbit.altitude / 1000) },
                { "Inc", string.Format("{0:F3} °", orbit.inclination) },
                { "Ecc", string.Format("{0:F3}", orbit.eccentricity) },
                { "Per", KSPUtil.PrintDateCompact(orbit.period, false, true) },
            });
        }
예제 #8
0
        /// <summary>
        /// The main method for updating all kerbals' health and processing events
        /// </summary>
        /// <param name="forced">Whether to process kerbals regardless of the amount of time passed</param>
        void UpdateKerbals(bool forced)
        {
            double time       = Planetarium.GetUniversalTime();
            double timePassed = time - lastUpdated;

            if (timePassed <= 0)
            {
                return;
            }
            if (forced || ((timePassed >= Core.UpdateInterval) && (timePassed >= Core.MinUpdateInterval * TimeWarp.CurrentRate)))
            {
                Core.Log("UT is " + time + ". Updating for " + timePassed + " seconds.");
                Core.ClearCache();
                Core.KerbalHealthList.Update(timePassed);
                lastUpdated = time;
                if (Core.ConditionsEnabled)
                {
                    while (time >= nextEventTime)  // Can take several turns of event processing at high time warp
                    {
                        Core.Log("Processing conditions...");
                        foreach (KerbalHealthStatus khs in Core.KerbalHealthList.Values)
                        {
                            ProtoCrewMember pcm = khs.PCM;
                            if (khs.IsFrozen || khs.IsDecontaminating || !Core.IsKerbalTrackable(pcm))
                            {
                                continue;
                            }
                            for (int i = 0; i < khs.Conditions.Count; i++)
                            {
                                HealthCondition hc = khs.Conditions[i];
                                foreach (Outcome o in hc.Outcomes)
                                {
                                    if (Core.rand.NextDouble() < o.GetChancePerDay(pcm) * HighLogic.CurrentGame.Parameters.CustomParams <KerbalHealthQuirkSettings>().ConditionsChance)
                                    {
                                        Core.Log("Condition " + hc.Name + " has outcome: " + o);
                                        if (o.Condition != "")
                                        {
                                            khs.AddCondition(o.Condition);
                                        }
                                        if (o.RemoveOldCondition)
                                        {
                                            khs.RemoveCondition(hc);
                                            i--;
                                            break;
                                        }
                                    }
                                }
                            }
                            foreach (HealthCondition hc in Core.HealthConditions.Values)
                            {
                                if ((hc.ChancePerDay > 0) && (hc.Stackable || !khs.HasCondition(hc)) && hc.IsCompatibleWith(khs.Conditions) && hc.Logic.Test(pcm) && (Core.rand.NextDouble() < hc.GetChancePerDay(pcm) * HighLogic.CurrentGame.Parameters.CustomParams <KerbalHealthQuirkSettings>().ConditionsChance))
                                {
                                    Core.Log(khs.Name + " acquires " + hc.Name + " condition.");
                                    khs.AddCondition(hc);
                                }
                            }
                        }
                        nextEventTime += GetNextEventInterval();
                        Core.Log("Next event processing is scheduled at " + KSPUtil.PrintDateCompact(nextEventTime, true), Core.LogLevel.Important);
                    }
                }
                dirty = true;
            }
        }