Beispiel #1
0
 public override double ChangePerDay(ProtoCrewMember pcm)
 {
     if (Core.IsInEditor)
     {
         return(IsEnabledInEditor() ? BaseChangePerDay : 0);
     }
     return((pcm.IsLoaded() && (pcm.GetVessel().Connection != null) && pcm.GetVessel().Connection.IsConnectedHome)
         ? BaseChangePerDay
         : 0);
 }
        public override double ChangePerDay(ProtoCrewMember pcm)
        {
            if (Core.IsInEditor)
            {
                return(IsEnabledInEditor() ? BaseChangePerDay : 0);
            }
            if (Core.KerbalHealthList[pcm] == null)
            {
                Core.Log(pcm.name + " not found in KerbalHealthList. The list has " + Core.KerbalHealthList.Count + " records.", LogLevel.Error);
                return(0);
            }
            Vessel vessel = pcm.GetVessel();

            if (vessel == null)
            {
                Core.Log("MicrogravityFactor.ChangePerDay: Core.GetVessel(pcm) is null for " + pcm.name + "! EVA is " + Core.KerbalHealthList[pcm].IsOnEVA, LogLevel.Error);
                return(0);
            }
            if ((vessel.situation & (Vessel.Situations.ORBITING | Vessel.Situations.SUB_ORBITAL | Vessel.Situations.ESCAPING)) != 0)
            {
                Core.Log("Microgravity is on due to being in a " + vessel.situation + " situation.");
                return(BaseChangePerDay);
            }
            if (pcm.geeForce < 0.1)
            {
                Core.Log("Microgravity is on due to g = " + pcm.geeForce.ToString("F2"));
                return(BaseChangePerDay);
            }
            Core.Log("Microgravity is off, g = " + pcm.geeForce);
            return(0);
        }
Beispiel #3
0
        public override double ChangePerDay(ProtoCrewMember pcm)
        {
            if (Core.IsInEditor)
            {
                return(IsEnabledInEditor() ? BaseChangePerDay : 0);
            }
            if (pcm.rosterStatus != ProtoCrewMember.RosterStatus.Assigned)
            {
                Core.Log("Home factor is off when kerbal is not assigned.");
                return(0);
            }
            Vessel        vessel = pcm.GetVessel();
            CelestialBody body   = vessel?.mainBody;

            if (body == null)
            {
                Core.Log("Could not find main body for " + pcm.name, LogLevel.Error);
                return(0);
            }
            if (body.isHomeWorld && (vessel.altitude < body.scienceValues.flyingAltitudeThreshold))
            {
                Core.Log("Home factor is on.");
                return(BaseChangePerDay);
            }
            Core.Log("Home factor is off. Main body: " + body.name + "; altitude: " + vessel.altitude + ".");
            return(0);
        }
Beispiel #4
0
 /// <summary>
 /// Returns vessel health modifiers for the vessel with the given kerbal
 /// </summary>
 /// <param name="pcm"></param>
 /// <returns></returns>
 public static HealthModifierSet GetVesselModifiers(ProtoCrewMember pcm)
 {
     if (Core.IsInEditor)
     {
         if (VesselCache.Count > 0)
         {
             Core.Log("In editor and VesselHealthInfo found in cache. Retrieving.");
             return(VesselCache.First().Value);
         }
         Core.Log("In editor and VesselHealthInfo not found in cache. Calculating and adding to cache.");
         return(VesselCache[Guid.Empty] = new HealthModifierSet(EditorLogic.SortedShipList, ShipConstruction.ShipManifest.CrewCount));
     }
     return(pcm.rosterStatus != ProtoCrewMember.RosterStatus.Assigned ? new HealthModifierSet() : GetVesselModifiers(pcm.GetVessel()));
 }
Beispiel #5
0
        public bool Test(ProtoCrewMember pcm)
        {
            bool res = true;

            if (pcm == null)
            {
                Core.Log("ProtoCrewMember argument in Logic.Test is null!", LogLevel.Error);
                return(res);
            }
            Vessel v = pcm.GetVessel();

            if (Situation != null)
            {
                if (v != null)
                {
                    switch (Situation.ToLowerInvariant())
                    {
                    case "prelaunch":
                        Op(ref res, v.situation == Vessel.Situations.PRELAUNCH);
                        break;

                    case "landed":
                        Op(ref res, v.situation == Vessel.Situations.LANDED);
                        break;

                    case "splashed":
                        Op(ref res, v.situation == Vessel.Situations.SPLASHED);
                        break;

                    case "ground":
                        Op(ref res, (v.situation == Vessel.Situations.LANDED) || (v.situation == Vessel.Situations.SPLASHED));
                        break;

                    case "flying":
                        Op(ref res, v.situation == Vessel.Situations.FLYING);
                        break;

                    case "suborbital":
                        Op(ref res, v.situation == Vessel.Situations.SUB_ORBITAL);
                        break;

                    case "orbiting":
                        Op(ref res, v.situation == Vessel.Situations.ORBITING);
                        break;

                    case "escaping":
                        Op(ref res, v.situation == Vessel.Situations.ESCAPING);
                        break;

                    case "in space":
                        Op(ref res, (v.situation == Vessel.Situations.SUB_ORBITAL) || (v.situation == Vessel.Situations.ORBITING) || (v.situation == Vessel.Situations.ESCAPING));
                        break;
                    }
                }
                else
                {
                    Op(ref res, false);
                }
            }

            if (InSOI != null)
            {
                Op(ref res, v != null && InSOI.Equals(v.mainBody.name, StringComparison.InvariantCultureIgnoreCase));
            }

            if (KerbalStatus != null)
            {
                Op(ref res, KerbalStatus.Equals(pcm.rosterStatus.ToString(), StringComparison.InvariantCultureIgnoreCase));
            }

            if (!double.IsNaN(MissionTime))
            {
                Op(ref res, v != null && v.missionTime >= MissionTime);
            }

            if (Gender != null)
            {
                ProtoCrewMember.Gender g = pcm.gender;
                switch (Gender.ToLowerInvariant())
                {
                case "female":
                    Op(ref res, g == ProtoCrewMember.Gender.Female);
                    break;

                case "male":
                    Op(ref res, g == ProtoCrewMember.Gender.Male);
                    break;
                }
            }

            if (GenderPresent != null)
            {
                ProtoCrewMember.Gender g;
                switch (GenderPresent.ToLowerInvariant())
                {
                case "female":
                    g = ProtoCrewMember.Gender.Female;
                    break;

                case "male":
                    g = ProtoCrewMember.Gender.Male;
                    break;

                case "same":
                    g = pcm.gender;
                    break;

                case "other":
                    g = pcm.gender == ProtoCrewMember.Gender.Female ? ProtoCrewMember.Gender.Male : ProtoCrewMember.Gender.Female;
                    break;

                default:
                    Core.Log($"Unrecognized value for gender in 'genderPresent = {GenderPresent}'. Assuming 'other'.");
                    goto case "other";
                }
                Op(ref res, v != null && v.GetVesselCrew().Exists(crewmate => crewmate.gender == g && crewmate != pcm));
            }

            if (TraitPresent != null)
            {
                Op(ref res, v != null && v.GetVesselCrew().Exists(crewmate => crewmate.trait.ToLower() == TraitPresent.ToLower() && crewmate != pcm));
            }

            if (ConditionPresent != null)
            {
                Op(ref res, v != null && v.GetVesselCrew().Exists(crewmate => Core.KerbalHealthList[crewmate].HasCondition(ConditionPresent) && crewmate != pcm));
            }

            foreach (Logic l in Operands)
            {
                Op(ref res, l.Test(pcm));
            }

            return(res ^ Inverse);
        }