Exemple #1
0
        public bool Test(ProtoCrewMember pcm)
        {
            Core.Log("Logic.Test('" + pcm.name + "')");
            bool res = true;

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

            if (Situation != null)
            {
                if (v != null)
                {
                    Core.Log("Checking 'situation = " + Situation + "'. " + v.vesselName + " is " + v.situation);
                    switch (Situation.ToLower())
                    {
                    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)
            {
                if (v != null)
                {
                    Core.Log("Checking 'inSOI = " + InSOI + "' rule. " + pcm.name + " is in " + v.mainBody?.name + "'s SOI.");
                    Op(ref res, InSOI.Equals(v.mainBody.name, StringComparison.CurrentCultureIgnoreCase));
                }
                else
                {
                    Core.Log("Checking 'inSOI = " + InSOI + "' rule. " + pcm.name + " is not in a vessel => this logic is false.");
                    Op(ref res, false);
                }
            }
            if (KerbalStatus != null)
            {
                Core.Log("Checking 'kerbalStatus = " + KerbalStatus + "'. " + pcm.name + " is " + pcm.rosterStatus);
                Op(ref res, KerbalStatus.Equals(pcm.rosterStatus.ToString(), StringComparison.CurrentCultureIgnoreCase));
            }
            if (!Double.IsNaN(MissionTime))
            {
                Core.Log("Checking 'missionTime = " + MissionTime + "'. MET is " + v?.missionTime + ".");
                if (v != null)
                {
                    Op(ref res, v.missionTime >= MissionTime);
                }
                else
                {
                    Op(ref res, false);
                }
            }
            if (Gender != null)
            {
                ProtoCrewMember.Gender g = pcm.gender;
                Core.Log("Checking condition 'gender = " + Gender + "'. " + pcm.name + " is " + g);
                switch (Gender.ToLower())
                {
                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.ToLower())
                {
                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";
                }
                Core.Log("Checking condition 'genderPresent = " + GenderPresent + "'. Looking for " + g + " crewmates.");
                bool found = false;
                if (v != null)
                {
                    foreach (ProtoCrewMember crewmate in v.GetVesselCrew())
                    {
                        if ((crewmate.gender == g) && (crewmate != pcm))
                        {
                            found = true;
                            break;
                        }
                    }
                }
                Core.Log(g + " crewmates " + (found ? "" : "not ") + "found.");
                Op(ref res, found);
            }
            if (TraitPresent != null)
            {
                Core.Log("Checking condition 'traitPresent = " + TraitPresent + "'.");
                bool found = false;
                if (v != null)
                {
                    foreach (ProtoCrewMember crewmate in v.GetVesselCrew())
                    {
                        if ((crewmate.trait.ToLower() == TraitPresent.ToLower()) && (crewmate != pcm))
                        {
                            found = true;
                            break;
                        }
                    }
                }
                Core.Log(TraitPresent + " crewmates " + (found ? "" : "not ") + "found.");
                Op(ref res, found);
            }
            if (ConditionPresent != null)
            {
                Core.Log("Checking condition 'conditionPresent = " + ConditionPresent + "'.");
                bool found = false;
                if (v != null)
                {
                    foreach (ProtoCrewMember crewmate in v.GetVesselCrew())
                    {
                        if ((Core.KerbalHealthList.Find(crewmate.name).HasCondition(ConditionPresent)) && (crewmate != pcm))
                        {
                            found = true;
                            break;
                        }
                    }
                }
                Core.Log("Crewmates with " + ConditionPresent + (found ? "" : " not") + " found.");
                Op(ref res, found);
            }
            foreach (Logic l in Operands)
            {
                Op(ref res, l.Test(pcm));
            }
            return(res ^ Inverse);
        }
Exemple #2
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 = Core.KerbalVessel(pcm);

            if (Situation != null)
            {
                if (v != null)
                {
                    switch (Situation.ToLower())
                    {
                    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.CurrentCultureIgnoreCase) : false);
            }

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

            if (!Double.IsNaN(MissionTime))
            {
                Op(ref res, v != null ? v.missionTime >= MissionTime : false);
            }

            if (Gender != null)
            {
                ProtoCrewMember.Gender g = pcm.gender;
                switch (Gender.ToLower())
                {
                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.ToLower())
                {
                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";
                }
                bool found = false;
                if (v != null)
                {
                    foreach (ProtoCrewMember crewmate in v.GetVesselCrew())
                    {
                        if ((crewmate.gender == g) && (crewmate != pcm))
                        {
                            found = true;
                            break;
                        }
                    }
                }
                Op(ref res, found);
            }

            if (TraitPresent != null)
            {
                bool found = false;
                if (v != null)
                {
                    foreach (ProtoCrewMember crewmate in v.GetVesselCrew())
                    {
                        if ((crewmate.trait.ToLower() == TraitPresent.ToLower()) && (crewmate != pcm))
                        {
                            found = true;
                            break;
                        }
                    }
                }
                Op(ref res, found);
            }

            if (ConditionPresent != null)
            {
                bool found = false;
                if (v != null)
                {
                    foreach (ProtoCrewMember crewmate in v.GetVesselCrew())
                    {
                        if ((Core.KerbalHealthList[crewmate].HasCondition(ConditionPresent)) && (crewmate != pcm))
                        {
                            found = true;
                            break;
                        }
                    }
                }
                Op(ref res, found);
            }

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

            return(res ^ Inverse);
        }
Exemple #3
0
        public bool Test(ProtoCrewMember pcm)
        {
            Core.Log("Logic.Test('" + pcm.name + "')");
            bool res = true;

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

            if (InSOI != null)
            {
                if (v != null)
                {
                    Core.Log("Checking 'inSOI = " + InSOI + "' rule. " + pcm.name + " is in " + v.mainBody?.name + "'s SOI.");
                    Op(ref res, InSOI.Equals(v.mainBody.name, StringComparison.CurrentCultureIgnoreCase));
                }
                else
                {
                    Core.Log("Checking 'inSOI = " + InSOI + "' rule. " + pcm.name + " is not in a vessel => this logic is false.");
                    Op(ref res, false);
                }
            }
            if (KerbalStatus != null)
            {
                Core.Log("Checking 'kerbalStatus = " + KerbalStatus + "'. " + pcm.name + " is " + pcm.rosterStatus + ".");
                Op(ref res, KerbalStatus.Equals(pcm.rosterStatus.ToString(), StringComparison.CurrentCultureIgnoreCase));
            }
            if (!Double.IsNaN(MissionTime))
            {
                Core.Log("Checking 'missionTime = " + MissionTime + "'. MET is " + v?.missionTime + ".");
                if (v != null)
                {
                    Op(ref res, v.missionTime >= MissionTime);
                }
                else
                {
                    Op(ref res, false);
                }
            }
            if (GenderPresent != null)
            {
                ProtoCrewMember.Gender g;
                switch (GenderPresent.ToLower())
                {
                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";
                }
                Core.Log("Checking condition 'genderPresent = " + GenderPresent + "'. Looking for " + g + " crewmates.");
                bool found = false;
                if (v != null)
                {
                    foreach (ProtoCrewMember crewmate in v.GetVesselCrew())
                    {
                        if (crewmate.gender == g)
                        {
                            found = true;
                            break;
                        }
                    }
                }
                Core.Log(g + " crewmates " + (found ? "" : "not ") + "found.");
                Op(ref res, found);
            }
            foreach (Logic l in Operands)
            {
                Op(ref res, l.Test(pcm));
            }
            return(res ^ Inverse);
        }