Ejemplo n.º 1
0
        internal static bool CanKerbalsBeXferred(List <Part> selectedPartsSource, List <Part> selectedPartsTarget)
        {
            bool results = true;

            WindowTransfer.XferToolTip = "";
            try
            {
                if (IsTransferInProgress())
                {
                    //WindowTransfer.XferToolTip = "Transfer in progress.  Xfers disabled.";
                    WindowTransfer.XferToolTip = SmUtils.SmTags["#smloc_conditions_tt_001"];
                    return(false);
                }
                if (selectedPartsSource.Count == 0 || selectedPartsTarget.Count == 0)
                {
                    WindowTransfer.XferToolTip = SmUtils.SmTags["#smloc_conditions_tt_002"];
                    //  "Source or Target Part is not selected.\r\nPlease Select a Source AND a Target part.";
                    return(false);
                }
                if (selectedPartsSource.Count == 1 && selectedPartsTarget.Count == 1)
                {
                    if (selectedPartsSource[0] == selectedPartsTarget[0])
                    {
                        WindowTransfer.XferToolTip = SmUtils.SmTags["#smloc_conditions_tt_003"];
                        // "Source and Target Parts are the same.\r\nUse Move Kerbal (>>) instead.";
                        return(false);
                    }
                }
                else if (selectedPartsSource.Count > 1 || selectedPartsTarget.Count > 1)
                {
                    if (selectedPartsSource == selectedPartsTarget)
                    {
                        WindowTransfer.XferToolTip = SmUtils.SmTags["#smloc_conditions_tt_003"];
                        // "Source and Target Parts are the same.\r\nUse Move individual Kerbals (>>) instead.";
                        return(false);
                    }
                }
                // If one of the parts is a DeepFreeze part and no crew are showing in protoModuleCrew, check it isn't full of frozen Kerbals.
                // This is to prevent SM from Transferring crew into a DeepFreeze part that is full of frozen kerbals.
                // If there is just one spare seat or seat taken by a Thawed Kerbal that is OK because SM will just transfer them into the empty
                // seat or swap them with a thawed Kerbal.
                DfWrapper.DeepFreezer sourcepartFrzr = null; // selectedPartsSource[0].FindModuleImplementing<DFWrapper.DeepFreezer>();
                DfWrapper.DeepFreezer targetpartFrzr = null; // selectedPartsTarget[0].FindModuleImplementing<DFWrapper.DeepFreezer>();

                List <Part> .Enumerator srcPart = selectedPartsSource.GetEnumerator();
                while (srcPart.MoveNext())
                {
                    if (srcPart.Current == null)
                    {
                        continue;
                    }
                    PartModule sourcedeepFreezer = GetFreezerModule(srcPart.Current);
                    if (sourcedeepFreezer != null)
                    {
                        sourcepartFrzr = new DfWrapper.DeepFreezer(sourcedeepFreezer);
                    }
                    if (sourcepartFrzr?.FreezerSpace != 0)
                    {
                        continue;
                    }
                    WindowTransfer.XferToolTip = SmUtils.SmTags["#smloc_conditions_tt_004"];
                    // "DeepFreeze Part is full of frozen kerbals.\r\nCannot Xfer until some are thawed.";
                    return(false);
                }

                List <Part> .Enumerator tgtPart = selectedPartsSource.GetEnumerator();
                while (tgtPart.MoveNext())
                {
                    if (tgtPart.Current == null)
                    {
                        continue;
                    }
                    PartModule targetdeepFreezer = GetFreezerModule(tgtPart.Current);
                    if (targetdeepFreezer != null)
                    {
                        targetpartFrzr = new DfWrapper.DeepFreezer(targetdeepFreezer);
                    }
                    if (targetpartFrzr?.FreezerSpace != 0)
                    {
                        continue;
                    }
                    WindowTransfer.XferToolTip = SmUtils.SmTags["#smloc_conditions_tt_004"];
                    // "DeepFreeze Part is full of frozen kerbals.\r\nCannot Xfer until some are thawed.";
                    return(false);
                }

                // Are there kerbals to move?
                if (SmUtils.GetPartsCrewCount(selectedPartsSource) == 0)
                {
                    //WindowTransfer.XferToolTip = "No Kerbals to Move.";
                    WindowTransfer.XferToolTip = SmUtils.SmTags["#smloc_conditions_tt_005"];
                    return(false);
                }
                // now if realistic xfers is enabled, are the parts connected to each other in the same living space?
                results = IsClsInSameSpace(selectedPartsSource, selectedPartsTarget);
                if (!results)
                {
                    WindowTransfer.EvaToolTip = SmUtils.SmTags["#smloc_conditions_tt_006"];
                }
                // "CLS is preventing internal Crew Transfer.  Click to initiate EVA operation.";
                else
                {
                    WindowTransfer.XferToolTip = SmUtils.SmTags["#smloc_conditions_tt_007"];
                }
                // "Kerbal can be Transfered.";
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage($" in CanBeXferred.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}",
                                   SmUtils.LogType.Error, true);
            }
            return(results);
        }