Пример #1
0
        public void MergeSpaces(Part part1, Part part2)
        {
            ICLSPart clsPart1 = null;
            ICLSPart clsPart2 = null;

            for (int i = listParts.Count - 1; i >= 0; i--)
            {
                if (listParts[i].Part == part1)
                {
                    clsPart1 = listParts[i];
                }
                if (listParts[i].Part == part2)
                {
                    clsPart2 = listParts[i];
                }
                if (clsPart1 != null && clsPart2 != null)
                {
                    break;
                }
            }
            if (clsPart1 == null || clsPart2 == null)
            {
                return;
            }

            MergeSpaces(clsPart1, clsPart2);
        }
 public void MergeSpaces(ICLSPart part1, ICLSPart part2)
 {
     if (part1.Space == null || part2.Space == null)
     {
         return;
     }
     MergeSpaces(part1.Space, part2.Space);
 }
Пример #3
0
        private void OnCrewTransferPartListCreated(GameEvents.HostedFromToAction <Part, List <Part> > eventData)
        {
            if (_allowUnrestrictedTransfers)
            {
                return;
            }

            // How can I tell if the parts are in the same space?... I need a starting point!  What part initiated the event?
            Part sourcePart = null;

            // Get the Dialog and find the source part.
            CrewHatchDialog dialog = Resources.FindObjectsOfTypeAll <CrewHatchDialog>().FirstOrDefault();

            if (dialog?.Part == null)
            {
                return;
            }
            sourcePart = dialog.Part;
            ICLSPart clsFrom = Instance.Vessel.Parts.Find(x => x.Part == sourcePart);

            //Let's manhandle the lists
            List <Part> fullList = new List <Part>();

            List <Part> .Enumerator fromList = eventData.from.GetEnumerator();
            while (fromList.MoveNext())
            {
                if (fromList.Current == null)
                {
                    continue;
                }
                ICLSPart clsTo = Instance.Vessel.Parts.Find(x => x.Part == fromList.Current);

                // If in same space, ignore
                if (clsFrom != null && clsTo != null && clsFrom.Space == clsTo.Space)
                {
                    continue;
                }
                fullList.Add(fromList.Current);
            }
            fromList.Dispose();

            if (fullList.Count <= 0)
            {
                return;
            }
            //CrewTransfer.fullMessage = "<color=orange>CLS - This module is either full or internally unreachable.</color>";
            List <Part> .Enumerator removeList = fullList.GetEnumerator();
            while (removeList.MoveNext())
            {
                eventData.from.Remove(removeList.Current);
            }
            removeList.Dispose();
            eventData.to.AddRange(fullList);
        }
Пример #4
0
        internal static bool IsClsInSameSpace(Part source, Part target)
        {
            bool results = false;

            if (source == null || target == null)
            {
                return(results);
            }
            if (SMSettings.EnableCls && SMSettings.RealXfers)
            {
                if (SMAddon.ClsAddon.Vessel == null)
                {
                    return(results);
                }
                ICLSSpace sourceSpace             = null;
                ICLSSpace targetSpace             = null;
                List <ICLSPart> .Enumerator parts = SMAddon.ClsAddon.Vessel.Parts.GetEnumerator();
                while (parts.MoveNext())
                {
                    ICLSPart ipart = parts.Current;
                    if (ipart == null)
                    {
                        continue;
                    }
                    if (ipart.Part == source)
                    {
                        sourceSpace = ipart.Space;
                    }
                    if (ipart.Part == target)
                    {
                        targetSpace = ipart.Space;
                    }
                    if (sourceSpace != null && targetSpace != null)
                    {
                        break;
                    }
                }
                parts.Dispose();
                if (sourceSpace != null && targetSpace != null && sourceSpace == targetSpace)
                {
                    results = true;
                }
            }
            else
            {
                results = true;
            }
            return(results);
        }
Пример #5
0
        private void MoveKerbal(ICLSKerbal k)
        {
            // Debug.Log("MoveKerbal");
            // If there is only one seat in this space, then our friend is not going anywhere!
            ICLSPart  temppart = k.Part;
            ICLSSpace s        = temppart.Space;

            if (null == s)
            {
                Debug.LogWarning("space is null :(");
            }

            int maxCrew = s.MaxCrew;

            if (k.Part.Space.MaxCrew > 1)
            {
                //Debug.Log("vessel has more than 1 seat");

                List <PartSeat> listSeats = new List <PartSeat>();

                // There are other seats in the space that our chosen kerbal is in. Pick one of them at random, and then we can arrange the swap.
                foreach (ICLSPart p in k.Part.Space.Parts)
                {
                    for (int counter = 0; counter < p.Part.CrewCapacity; counter++)
                    {
                        //Debug.Log("Adding " + p.partInfo.title + " seat "+counter);
                        listSeats.Add(new PartSeat(p.Part, counter));
                    }
                }

                // Now we have a list of all the possible places we could move the kerbal to - choose one of them.

                int choosenLocation = this.random.Next(listSeats.Count);

                // TODO remove debugging
                //Debug.Log("choosen location: " + choosenLocation);

                // Do the swap
                bool kerbalsSwapped = SwapKerbals(k, listSeats[choosenLocation].part, listSeats[choosenLocation].seat);
            }
            else
            {
                //Debug.Log("Unable to move kerbal as there is only one seat in this vessel!");
            }
        }
Пример #6
0
        // Method to optionally abort an attempt to use the stock crew transfer mechanism
        private void OnCrewTransferSelected(CrewTransfer.CrewTransferData crewTransferData)
        {
            // If transfers are not restricted then we have got nothing to do here.
            if (_allowUnrestrictedTransfers)
            {
                return;
            }
            ICLSPart clsFrom = Instance.Vessel.Parts.Find(x => x.Part == crewTransferData.sourcePart);
            ICLSPart clsTo   = Instance.Vessel.Parts.Find(x => x.Part == crewTransferData.destPart);

            // If in same space, ignore
            if (clsFrom != null && clsTo != null && clsFrom.Space == clsTo.Space)
            {
                return;
            }

            // Okay, houston, we have a problem.   Prevent transfer.
            crewTransferData.canTransfer = false;
            ScreenMessages.PostScreenMessage(
                $"<color=orange>{_clsLocWarnXfer}: {crewTransferData.crewMember.name}.  {crewTransferData.sourcePart.partInfo.title} {_clsLocAnd} {crewTransferData.destPart.partInfo.title} {_clsLocNotSameLs}.</color>", 10f);
        }
Пример #7
0
 internal ModHatch(PartModule pModule, ICLSPart iPart)
 {
     HatchModule = pModule;
       ClsPart = iPart;
 }
Пример #8
0
        /// <summary>
        /// This routine is used ot remove source or taget highlighting on a part.  
        /// it is cls Aware, and preserves the base space highlighting when selected part coler is removed.
        /// </summary>
        /// <param name="IsTargetPart"></param>
        public void SetSelectedHighlighting(bool IsTargetPart)
        {
            try
            {
                Part selectedpart = null;
                if (IsTargetPart)
                    selectedpart = _selectedPartTarget;
                else
                    selectedpart = _selectedPartSource;

                if (SelectedResource == "Crew" && ShipManifestBehaviour.ShipManifestSettings.EnableCLS)
                {
                    if (selectedpart != null)
                    {
                        foreach (ICLSPart clsPart in ShipManifestBehaviour.clsVessel.Parts)
                        {
                            if (clsPart.Part == selectedpart)
                            {
                                // let's turn off CLS highlighting and Turn on Target Part Highlighing.
                                if (IsTargetPart)
                                {
                                    clsPartTarget = clsPart;
                                    clsPartTarget.Highlight(false);
                                }
                                else
                                {
                                    clsPartSource = clsPart;
                                    clsPartSource.Highlight(false);
                                }

                                //turn on Selected part highlghting
                                if (IsTargetPart)
                                    SetPartHighlight(selectedpart, SettingsManager.Colors[SettingsManager.TargetPartCrewColor]);
                                else
                                    SetPartHighlight(selectedpart, SettingsManager.Colors[SettingsManager.SourcePartColor]);

                                Part.OnActionDelegate OnMouseExit = ShipManifestBehaviour.MouseExit;
                                selectedpart.AddOnMouseExit(OnMouseExit);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    // Set part highlighting on the selected part...
                    if (IsTargetPart)
                        SetPartHighlight(selectedpart, SettingsManager.Colors[SettingsManager.TargetPartColor]);
                    else
                        SetPartHighlight(selectedpart, SettingsManager.Colors[SettingsManager.SourcePartColor]);
                }
                OnMouseHighlights();
            }
            catch (Exception ex)
            {
                ManifestUtilities.LogMessage(string.Format(" in  SetPartHighlighting(" + IsTargetPart.ToString() + ").  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), "Error", true);
            }
        }
Пример #9
0
 internal ModHatch(PartModule pModule, ICLSPart iPart)
 {
     HatchModule = pModule;
     ClsPart     = iPart;
 }
Пример #10
0
 internal ModHatch(PartModule pModule, ICLSPart iPart)
 {
     this.HatchModule = pModule;
     this.CLSPart     = iPart;
 }
Пример #11
0
 internal ModHatch(PartModule pModule, ICLSPart iPart)
 {
   this.HatchModule = pModule;
   this.CLSPart = iPart;
 }