Exemple #1
0
        public void CleanManifest()
        {
            if (CrewAssignmentDialog.Instance != null)
            {
                VesselCrewManifest       originalVesselManifest = CrewAssignmentDialog.Instance.GetManifest();
                IList <PartCrewManifest> partCrewManifests      = originalVesselManifest.GetCrewableParts();

                if (partCrewManifests != null && partCrewManifests.Count > 0)
                {
                    PartCrewManifest partManifest = partCrewManifests[0];
                    foreach (ProtoCrewMember crewMember in partManifest.GetPartCrew())
                    {
                        if (crewMember != null)
                        {
                            // Clean the root part
                            partManifest.RemoveCrewFromSeat(partManifest.GetCrewSeat(crewMember));
                        }
                    }
                    if (CrewRandRSettings.Instance != null && CrewRandRSettings.Instance.AssignCrews)
                    {
                        partManifest.AddCrewToOpenSeats(CrewRandR.Instance.GetCrewForPart(partManifest.PartInfo.partPrefab, new List <ProtoCrewMember>(), true));
                    }
                }

                CrewAssignmentDialog.Instance.RefreshCrewLists(originalVesselManifest, true, true);
            }
        }
 /// <summary>
 /// Clears all crew out of the crewable.
 /// </summary>
 public void Clear()
 {
     for (int index = 0; index < Capacity; ++index)
     {
         manifest.RemoveCrewFromSeat(index);
     }
     crewSlots = CrewSlot.GetSlots(part, manifest);
 }
        /// <summary>
        /// Copies crew assignments from the dialog to the ship construct.
        /// </summary>
        private void CopyCrew()
        {
            VesselCrewManifest dialogVessel = CurrentDialogContents;

            if (dialogVessel == null)
            {
                Logging.Error("No dialog manifest, can't copy");
                return;
            }
            VesselCrewManifest      currentVessel = ShipConstruction.ShipManifest;
            List <PartCrewManifest> dialogParts   = dialogVessel.GetCrewableParts();
            List <PartCrewManifest> currentParts  = currentVessel.GetCrewableParts();

            if (dialogParts.Count != currentParts.Count)
            {
                Logging.Error("Crew dialog has " + dialogParts.Count
                              + " crewable parts, but vessel has only " + currentParts.Count + ". Can't copy.");
                return;
            }
            for (int partIndex = 0; partIndex < dialogParts.Count; ++partIndex)
            {
                PartCrewManifest  dialogPart  = dialogParts[partIndex];
                PartCrewManifest  currentPart = currentParts[partIndex];
                ProtoCrewMember[] dialogCrew  = dialogPart.GetPartCrew();
                ProtoCrewMember[] currentCrew = currentPart.GetPartCrew();
                if ((dialogPart.PartID != currentPart.PartID) || (dialogCrew.Length != currentCrew.Length))
                {
                    Logging.Error("Mismatched manifests at index " + partIndex + ", can't copy.");
                    return;
                }
                for (int slotIndex = 0; slotIndex < dialogCrew.Length; ++slotIndex)
                {
                    ProtoCrewMember dialogMember  = dialogCrew[slotIndex];
                    ProtoCrewMember currentMember = currentCrew[slotIndex];
                    if (!AreSame(dialogMember, currentMember))
                    {
                        Logging.Log("Crew change in " + currentPart.PartInfo.title + " slot " + slotIndex + ": "
                                    + DescribeCrew(currentMember) + " -> " + DescribeCrew(dialogMember));
                        currentPart.RemoveCrewFromSeat(slotIndex);
                        if (dialogMember != null)
                        {
                            if (currentVessel.Contains(dialogMember))
                            {
                                PartCrewManifest previousPart = currentVessel.GetPartForCrew(dialogMember);
                                previousPart.RemoveCrewFromSeat(previousPart.GetCrewSeat(dialogMember));
                            }
                            currentPart.AddCrewToSeat(dialogMember, slotIndex);
                        }
                    } // if there's an assignment difference
                }     // for each slot in the part
            }         // for each crewable part in the vessel
        }
Exemple #4
0
        private void UpdateCrewManifest()
        {
            if (!HighLogic.LoadedSceneIsEditor)
            {
                return;
            }                                               //only run the following block in the editor; it updates the crew-assignment GUI

            VesselCrewManifest vcm = ShipConstruction.ShipManifest;

            if (vcm == null)
            {
                return;
            }
            PartCrewManifest pcm = vcm.GetPartCrewManifest(part.craftID);

            if (pcm == null)
            {
                return;
            }

            int len    = pcm.partCrew.Length;
            int newLen = Math.Min(part.CrewCapacity, _prefabPart.CrewCapacity);

            if (len == newLen)
            {
                return;
            }

            if (EditorLogic.fetch.editorScreen == EditorScreen.Crew)
            {
                EditorLogic.fetch.SelectPanelParts();
            }

            for (int i = 0; i < len; i++)
            {
                pcm.RemoveCrewFromSeat(i);
            }

            pcm.partCrew = new string[newLen];
            for (int i = 0; i < newLen; i++)
            {
                pcm.partCrew[i] = string.Empty;
            }

            ShipConstruction.ShipManifest.SetPartManifest(part.craftID, pcm);
        }
        /// <summary>
        /// Copies crew assignments from the dialog to the ship construct.
        /// </summary>
        private void CopyCrew()
        {
            VesselCrewManifest dialogVessel = CurrentDialogContents;

            if (dialogVessel == null)
            {
                return;
            }
            VesselCrewManifest      currentVessel = ShipConstruction.ShipManifest;
            List <PartCrewManifest> dialogParts   = dialogVessel.GetCrewableParts();
            List <PartCrewManifest> currentParts  = currentVessel.GetCrewableParts();

            if (dialogParts.Count != currentParts.Count)
            {
                return;
            }
            for (int partIndex = 0; partIndex < dialogParts.Count; ++partIndex)
            {
                PartCrewManifest  dialogPart  = dialogParts[partIndex];
                PartCrewManifest  currentPart = currentParts[partIndex];
                ProtoCrewMember[] dialogCrew  = dialogPart.GetPartCrew();
                ProtoCrewMember[] currentCrew = currentPart.GetPartCrew();
                if ((dialogPart.PartID != currentPart.PartID) || (dialogCrew.Length != currentCrew.Length))
                {
                    return;
                }
                for (int slotIndex = 0; slotIndex < dialogCrew.Length; ++slotIndex)
                {
                    ProtoCrewMember dialogMember  = dialogCrew[slotIndex];
                    ProtoCrewMember currentMember = currentCrew[slotIndex];
                    if (!AreSame(dialogMember, currentMember))
                    {
                        currentPart.RemoveCrewFromSeat(slotIndex);
                        if (dialogMember != null)
                        {
                            if (currentVessel.Contains(dialogMember))
                            {
                                PartCrewManifest previousPart = currentVessel.GetPartForCrew(dialogMember);
                                previousPart.RemoveCrewFromSeat(previousPart.GetCrewSeat(dialogMember));
                            }
                            currentPart.AddCrewToSeat(dialogMember, slotIndex);
                        }
                    } // if there's an assignment difference
                }     // for each slot in the part
            }         // for each crewable part in the vessel
        }
Exemple #6
0
        private void SetCrewManifestSize(PartCrewManifest pcm, int crewCapacity)
        {
            string[] newpartCrew = new string[crewCapacity];
            {
                for (int i = 0; i < newpartCrew.Length; ++i)
                {
                    newpartCrew[i] = string.Empty;
                }

                int SIZE = Math.Min(pcm.partCrew.Length, newpartCrew.Length);
                for (int i = 0; i < SIZE; ++i)
                {
                    newpartCrew[i] = pcm.partCrew[i];
                }

                for (int i = SIZE; i < pcm.partCrew.Length; ++i)
                {
                    pcm.RemoveCrewFromSeat(i);
                }
            }
            pcm.partCrew = newpartCrew;
        }
Exemple #7
0
        void ScaleCrewCapacity()
        {
            // scale crew capacity (balancing: conserve mass/kerbal)
            var cOld = part.CrewCapacity;
            var cNew = (int)(_prefabPart.CrewCapacity * MassScale);

            if (cOld == cNew)
            {
                Debug.Log("CrewCapacity: old=new=" + cNew.ToString());
                return;
            }
            part.CrewCapacity = cNew;

            if (HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            var manifests         = ShipConstruction.ShipManifest.GetCrewableParts();
            PartCrewManifest crew = null;

            for (int i = 0; i < manifests.StupidCount(); i++)
            {
                if (manifests[i].PartID == part.craftID)
                {
                    crew = manifests[i];
                    break;
                }
            }
            if (crew == null)
            {
                Tools.LogWf("No PartManifest found!");
                return;
            }
            if (cOld != crew.GetPartCrew().Count())
            {
                Debug.Log("Crew mismatch: part=" + cOld + ", crew=" + crew.GetPartCrew().Count().ToString());
            } //else Debug.Log("Manifest found");

            // clear seats (just for safety)
            for (int i = 0; i < crew.GetPartCrew().Count(); i++)
            {
                if (crew.GetPartCrew()[i] != null)
                {
                    Debug.Log("Removing seat:" + i.ToString() + crew.GetPartCrew()[i].name);
                    crew.RemoveCrewFromSeat(i);
                }
            } //Debug.Log("Cleared seats");

            // close crew tab (otherwise it will not update correctly)
            if (EditorLogic.fetch.editorScreen == EditorScreen.Crew)
            {
                EditorLogic.fetch.SelectPanelParts();
            }

            FieldInfo[] fields = typeof(PartCrewManifest).GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (FieldInfo f in fields)
            {
                if (f.Name == "partCrew")
                {
                    f.SetValue(crew, new string[cNew]);
                }
            }

            ShipConstruction.ShipManifest.SetPartManifest(part.craftID, crew);
        }