/// <summary>
 /// Pick an available, unassigned kerbal matching the assignment, or null if none is available.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="chooser"></param>
 /// <returns></returns>
 public ProtoCrewMember PickAvailable(AssignmentType type, KerbalChooser chooser = null)
 {
     while ((Head != null) && (Head.Type == type))
     {
         ProtoCrewMember crew = Pop().PickAvailable(chooser);
         if (crew != null)
         {
             return(crew);
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Pick an available, unassigned kerbal matching the assignment, or null if none is available.
        /// </summary>
        /// <returns></returns>
        public ProtoCrewMember PickAvailable(KerbalChooser chooser = null)
        {
            bool isTourist = (Type == AssignmentType.KerbalType) && (ProtoCrewMember.KerbalType.Tourist.ToString().Equals(value));
            IEnumerable <ProtoCrewMember> kerbals = isTourist ? Roster.Tourist : Roster.Crew;

            switch (Type)
            {
            case AssignmentType.Name:
                return(PickByName(value, kerbals));

            case AssignmentType.Profession:
                return(PickByProfession(value, kerbals, chooser));

            case AssignmentType.KerbalType:
                return(PickAny(kerbals, chooser));

            case AssignmentType.Empty:
            default:
                return(null);
            }
        }
 /// <summary>
 /// Go through and attempt to fill empty slots that have requested a particular profession.
 /// </summary>
 /// <param name="crewables"></param>
 private static void AssignKerbalsByProfession(IEnumerable <Crewable> crewables, int sasLevel)
 {
     foreach (Crewable crewable in crewables)
     {
         foreach (CrewSlot slot in crewable.Slots)
         {
             if (!slot.NeedsOccupant)
             {
                 continue;                      // either there's already someone there, or we want it empty
             }
             if (slot.Assignment == null)
             {
                 continue;                          // no assignment for this slot
             }
             KerbalChooser   chooser = PilotChooser.ForSasLevel(sasLevel);
             ProtoCrewMember crew    = slot.Assignment.PickAvailable(AssignmentType.Profession, chooser);
             if (crew != null)
             {
                 slot.Occupant = crew;
                 Logging.Log(crewable.ToString() + " slot " + slot.Index + ": Need " + crew.trait.ToLower() + ", assigned " + Logging.ToString(crew));
             }
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Pick the first available kerbal.
        /// </summary>
        /// <param name="kerbals"></param>
        /// <returns></returns>
        private static ProtoCrewMember PickAny(IEnumerable <ProtoCrewMember> kerbals, KerbalChooser chooser)
        {
            ProtoCrewMember best = null;

            foreach (ProtoCrewMember kerbal in kerbals)
            {
                if (IsAvailableAndUnassigned(kerbal))
                {
                    if (chooser == null)
                    {
                        return(kerbal);
                    }
                    best = chooser.Choose(best, kerbal);
                }
            }
            return(best);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Pick the first available kerbal whose profession matches.
        /// </summary>
        /// <param name="profession"></param>
        /// <param name="kerbals"></param>
        /// <returns></returns>
        private static ProtoCrewMember PickByProfession(String profession, IEnumerable <ProtoCrewMember> kerbals, KerbalChooser chooser)
        {
            ProtoCrewMember best = null;

            foreach (ProtoCrewMember kerbal in kerbals)
            {
                if (kerbal.trait.Equals(profession) && IsAvailableAndUnassigned(kerbal))
                {
                    if (chooser == null)
                    {
                        return(kerbal);
                    }
                    best = chooser.Choose(best, kerbal);
                }
            }
            return(best);
        }