Пример #1
0
        internal void CrewTransferStopAction()
        {
            // This adds the kerbal(s) to the destination part(s)
            try
            {
                // Add Source Crewmember to target part
                if (FromCrewMember != null && ToPart.CrewCapacity > ToPart.protoModuleCrew.Count)
                {
                    AddCrewMember(FromCrewMember, ToPart, ToSeat);
                }

                // Add Target Crewmember to source part
                if (ToCrewMember != null && FromPart.CrewCapacity > FromPart.protoModuleCrew.Count)
                {
                    AddCrewMember(ToCrewMember, FromPart, FromSeat);
                }

                SMAddon.SmVessel.TransferCrewObj.IvaDelayActive = true;
                SMAddon.FireEventTriggers();
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage(
                    $"in CrewTransferAction.  Error moving crewmember.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", SmUtils.LogType.Error, true);
            }
        }
Пример #2
0
 internal void FillVesselCrew()
 {
     foreach (var part in _partsByResource["Crew"])
     {
         FillPartCrew(part.CrewCapacity - part.protoModuleCrew.Count, part);
     }
     SMAddon.FireEventTriggers();
 }
Пример #3
0
 internal void CloseHatch(bool fireEvent = false)
 {
     Module.HatchEvents["CloseHatch"].active = false;
     Module.HatchEvents["OpenHatch"].active  = true;
     Module.HatchOpen = false;
     if (fireEvent)
     {
         SMAddon.FireEventTriggers();
     }
 }
Пример #4
0
 internal void EmptyVesselCrew()
 {
     foreach (var part in _partsByResource["Crew"])
     {
         for (int i = part.protoModuleCrew.Count - 1; i >= 0; i--)
         {
             RemoveCrewMember(part.protoModuleCrew[i], part);
         }
         SMAddon.FireEventTriggers();
     }
 }
Пример #5
0
 internal static void AddCrewMember(ProtoCrewMember kerbal, Part part)
 {
     part.AddCrewmember(kerbal);
     kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
     if (part.internalModel != null)
     {
         if (kerbal.seat != null)
         {
             kerbal.seat.SpawnCrew();
         }
     }
     SMAddon.FireEventTriggers();
 }
Пример #6
0
 internal void FillCrew()
 {
     //Utilities.LogMessage("Entering FillCrew", Utilities.LogType.Info, true);
     List <Part> .Enumerator parts = PartsByResource[SMConditions.ResourceType.Crew.ToString()].GetEnumerator();
     while (parts.MoveNext())
     {
         if (parts.Current == null)
         {
             continue;
         }
         //Utilities.LogMessage(string.Format("Processing FillCrew with part {0}", parts.Current.partInfo.name), Utilities.LogType.Info, true);
         SMPart.FillCrew(parts.Current);
     }
     parts.Dispose();
     SMAddon.FireEventTriggers();
 }
Пример #7
0
 internal void EmptyCrew()
 {
     List <Part> .Enumerator parts = PartsByResource[SMConditions.ResourceType.Crew.ToString()].GetEnumerator();
     while (parts.MoveNext())
     {
         if (parts.Current == null)
         {
             continue;
         }
         for (int i = parts.Current.protoModuleCrew.Count - 1; i >= 0; i--)
         {
             TransferCrew.RemoveCrewMember(parts.Current.protoModuleCrew[i], parts.Current);
         }
         SMAddon.FireEventTriggers();
     }
     parts.Dispose();
 }
Пример #8
0
 internal static void FillCrew(Part part)
 {
     //Utilities.LogMessage(string.Format("Entering Fill Crew with part {0}", part.partInfo.name), Utilities.LogType.Info, true);
     if (IsCrewFull(part))
     {
         return;
     }
     while (part.CrewCapacity > SMUtils.GetPartCrewCount(part))
     {
         ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.GetNextOrNewKerbal();
         part.AddCrewmember(kerbal);
         //Utilities.LogMessage(string.Format("Filling crew in part {0}", part.partInfo.name), Utilities.LogType.Info, true);
         if (kerbal.seat != null)
         {
             kerbal.seat.SpawnCrew();
         }
     }
     SMAddon.FireEventTriggers();
 }
Пример #9
0
 internal static void OpenAllHatches()
 {
     // TODO: for realism, add a closing/opening sound
     // ReSharper disable once SuspiciousTypeConversion.Global
     List <IModuleDockingHatch> .Enumerator iModules = SMAddon.SmVessel.Hatches.Select(iHatch => (IModuleDockingHatch)iHatch.HatchModule)
                                                       .Where(iModule => iModule.IsDocked).ToList().GetEnumerator();
     while (iModules.MoveNext())
     {
         if (iModules.Current == null)
         {
             continue;
         }
         iModules.Current.HatchEvents["CloseHatch"].active = true;
         iModules.Current.HatchEvents["OpenHatch"].active  = false;
         iModules.Current.HatchOpen = true;
     }
     iModules.Dispose();
     SMAddon.FireEventTriggers();
 }
Пример #10
0
 internal void CrewTransferStartAction()
 {
     // This removes the kerbal(s) from the current (source) part(s)
     try
     {
         if (FromCrewMember != null)
         {
             RemoveCrewMember(FromCrewMember, FromPart);
         }
         if (ToCrewMember != null)
         {
             RemoveCrewMember(ToCrewMember, ToPart);
         }
         SMAddon.FireEventTriggers();
     }
     catch (Exception ex)
     {
         SmUtils.LogMessage(
             $"in CrewTransferStartAction.  Error moving crewmember.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", SmUtils.LogType.Error, true);
     }
 }
Пример #11
0
        internal static void DumpCrew(Part part)
        {
            if (!part.vessel.IsRecoverable)
            {
                return;
            }
            while (part.protoModuleCrew.Count > 0)
            {
                ProtoCrewMember kerbal = part.protoModuleCrew.FirstOrDefault();
                if (kerbal != null)
                {
                    part.RemoveCrewmember(kerbal);
                    kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Available;

                    if (kerbal.seat != null)
                    {
                        kerbal.seat.SpawnCrew();
                    }
                }
            }
            SMAddon.FireEventTriggers();
        }
Пример #12
0
 internal void RespawnCrew()
 {
     this.Vessel.SpawnCrew();
     SMAddon.FireEventTriggers();
 }
Пример #13
0
        internal void CrewTransferAction()
        {
            try
            {
                // Both parts have internal models...
                if (FromPart.internalModel != null && ToPart.internalModel != null)
                {
                    if (ToSeat.taken)
                    {
                        // Remove the crew members from the part(s)...
                        RemoveCrewMember(FromCrewMember, FromPart);

                        // Swap places if there is no standing room available
                        if (ToPart.CrewCapacity == ToPart.protoModuleCrew.Count)
                        {
                            RemoveCrewMember(ToCrewMember, ToPart);
                            FromPart.AddCrewmemberAt(ToCrewMember, FromPart.internalModel.seats.IndexOf(FromSeat));
                            // Add the crew members back into the part(s) at their new seats.
                            ToPart.AddCrewmemberAt(FromCrewMember, ToPart.internalModel.seats.IndexOf(ToSeat));
                        }
                        else
                        {
                            // Just move.
                            RemoveCrewMember(FromCrewMember, FromPart);
                            AddCrewMember(FromCrewMember, ToPart);
                        }
                        SMAddon.FireEventTriggers();
                    }
                    else
                    {
                        // Just move.
                        RemoveCrewMember(FromCrewMember, FromPart);
                        ToPart.AddCrewmemberAt(FromCrewMember, ToPart.internalModel.seats.IndexOf(ToSeat));
                        SMAddon.FireEventTriggers();
                    }
                }
                else // one or both parts do not have an internal model
                {
                    // no portraits, so let's just move kerbals...
                    if (ToCrewMember != null)
                    {
                        RemoveCrewMember(FromCrewMember, FromPart);
                        RemoveCrewMember(ToCrewMember, ToPart);
                        AddCrewMember(FromCrewMember, ToPart);
                        AddCrewMember(ToCrewMember, FromPart);
                    }
                    else
                    {
                        RemoveCrewMember(FromCrewMember, FromPart);
                        AddCrewMember(FromCrewMember, ToPart);
                    }
                    SMAddon.FireEventTriggers();
                }
                if (SMSettings.EnableStockCrewXfer)
                {
                    // Now let's deal with third party mod support...
                    SourceAction        = new GameEvents.HostedFromToAction <ProtoCrewMember, Part>(FromCrewMember, FromPart, ToPart);
                    FireSourceXferEvent = true;

                    //If a swap, we need to handle that too...
                    if (ToCrewMember != null)
                    {
                        TargetAction        = new GameEvents.HostedFromToAction <ProtoCrewMember, Part>(ToCrewMember, ToPart, FromPart);
                        FireTargetXferEvent = true;
                    }
                }

                FromPart.vessel.SpawnCrew();

                // not sure if these help.   We have been experiencing issues with "ghost" kerbals & EVAs/docking/undocking after Crew Moves.
                // trying this to see if it "cleans up" any internal tracking inside of KSP...
                FromPart.RegisterCrew();
                ToPart.RegisterCrew();

                SMAddon.SmVessel.RespawnCrew();
                SMAddon.SmVessel.TransferCrewObj.IvaDelayActive = true;
            }
            catch (Exception ex)
            {
                SmUtils.LogMessage(
                    $"in CrewTransferAction.  Error moving crewmember.  Error:  {ex.Message} \r\n\r\n{ex.StackTrace}", SmUtils.LogType.Error, true);
            }
        }
Пример #14
0
        private static void DisplayRosterListViewer()
        {
            try
            {
                GUILayout.BeginVertical();
                // Roster List Header...
                GUILayout.BeginHorizontal();
                //GUILayout.Label("", GUILayout.Width(5));
                GUILayout.Label(SMUtils.Localize("#smloc_roster_016"), GUILayout.Width(140)); // "Name"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_017"), GUILayout.Width(50));  // "Gender"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_005"), GUILayout.Width(70));  // "Profession"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_018"), GUILayout.Width(30));  // "Skill"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_019"), GUILayout.Width(220)); // "Status"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_020"), GUILayout.Width(55));  // "Edit"
                GUILayout.Label(SMUtils.Localize("#smloc_roster_021"), GUILayout.Width(65));  // "Action"
                GUILayout.EndHorizontal();

                _scrollViewerPosition = GUILayout.BeginScrollView(_scrollViewerPosition, SMStyle.ScrollStyle,
                                                                  GUILayout.Height(230), GUILayout.Width(680));

                // vars for acton to occurs after button press
                bool            isAction     = false;
                Part            actionPart   = null;
                string          actionText   = "";
                ProtoCrewMember actionKerbal = null;

                List <ProtoCrewMember> .Enumerator kerbals = RosterList.GetEnumerator();
                while (kerbals.MoveNext())
                {
                    if (kerbals.Current == null)
                    {
                        continue;
                    }
                    if (!CanDisplayKerbal(kerbals.Current))
                    {
                        continue;
                    }
                    GUIStyle labelStyle;
                    if (kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Dead ||
                        kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Missing)
                    {
                        labelStyle = SMStyle.LabelStyleRed;
                    }
                    else if (kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
                    {
                        labelStyle = SMStyle.LabelStyleYellow;
                    }
                    else
                    {
                        labelStyle = SMStyle.LabelStyle;
                    }

                    // What vessel is this Kerbal Assigned to?
                    string rosterDetails = "";
                    if (kerbals.Current.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
                    {
                        List <Vessel> .Enumerator theseVessels = FlightGlobals.Vessels.GetEnumerator();
                        while (theseVessels.MoveNext())
                        {
                            if (theseVessels.Current == null)
                            {
                                continue;
                            }
                            List <ProtoCrewMember> crew = theseVessels.Current.GetVesselCrew();
                            if (crew.Any(crewMember => crewMember == kerbals.Current))
                            {
                                rosterDetails = string.Format("{0} - {1}", SMUtils.Localize("#smloc_roster_011"), theseVessels.Current.GetName().Replace("(unloaded)", "")); // "Assigned"
                            }
                        }
                        theseVessels.Dispose();
                    }
                    else if (InstalledMods.IsDfInstalled && DFWrapper.APIReady && kerbals.Current.type == ProtoCrewMember.KerbalType.Unowned)
                    {
                        // This kerbal could be frozen.  Lets find out...
                        rosterDetails = GetFrozenKerbalDetails(kerbals.Current);
                        labelStyle    = SMStyle.LabelStyleCyan;
                    }
                    else
                    {
                        // Since the kerbal has no vessel assignment, lets show what their status...
                        rosterDetails = kerbals.Current.rosterStatus.ToString();
                    }
                    string buttonText;
                    string buttonToolTip;
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(kerbals.Current.name, labelStyle, GUILayout.Width(140), GUILayout.Height(20));
                    GUILayout.Label(kerbals.Current.gender.ToString(), labelStyle, GUILayout.Width(50));
                    GUILayout.Label(kerbals.Current.experienceTrait.Title, labelStyle, GUILayout.Width(70));
                    GUILayout.Label(kerbals.Current.experienceLevel.ToString(), labelStyle, GUILayout.Width(30));
                    GUILayout.Label(rosterDetails, labelStyle, GUILayout.Width(215));

                    SetupEditButton(kerbals.Current, out buttonText, out buttonToolTip);
                    if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(55), GUILayout.Height(20),
                                         GUILayout.Height(20)))
                    {
                        if (SelectedKerbal == null || SelectedKerbal.Kerbal != kerbals.Current)
                        {
                            SelectedKerbal = new ModKerbal(kerbals.Current, false);
                            SetProfessionFlag();
                        }
                        else
                        {
                            SelectedKerbal = null;
                        }
                    }
                    Rect rect = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && ShowToolTips)
                    {
                        ToolTip = SMToolTips.SetActiveToolTip(rect, GUI.tooltip, ref ToolTipActive, XOffset);
                    }

                    // Setup buttons with gui state, button text and tooltip.
                    SetupActionButton(kerbals.Current, out buttonText, out buttonToolTip);

                    if (GUILayout.Button(new GUIContent(buttonText, buttonToolTip), GUILayout.Width(65), GUILayout.Height(20)))
                    {
                        isAction     = true;
                        actionKerbal = kerbals.Current;
                        actionText   = buttonText;
                        if (actionText == SMUtils.Localize("#smloc_roster_022")) // "Remove"
                        {
                            actionPart = SMAddon.SmVessel.FindPartByKerbal(kerbals.Current);
                        }
                    }
                    Rect rect2 = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.Repaint && ShowToolTips)
                    {
                        ToolTip = SMToolTips.SetActiveToolTip(rect2, GUI.tooltip, ref ToolTipActive, XOffset);
                    }
                    GUILayout.EndHorizontal();
                    GUI.enabled = true;
                }
                kerbals.Dispose();
                GUILayout.EndVertical();
                GUILayout.EndScrollView();

                // perform action from button press.
                if (!isAction)
                {
                    return;
                }
                if (actionText == SMUtils.Localize("#smloc_roster_022")) // "Remove"
                {
                    TransferCrew.RemoveCrewMember(actionKerbal, actionPart);
                }
                else if (actionText == SMUtils.Localize("#smloc_roster_023")) // "Add"
                {
                    TransferCrew.AddCrewMember(actionKerbal, SMAddon.SmVessel.SelectedPartsSource[0]);
                }
                else if (actionText == SMUtils.Localize("#smloc_roster_024")) // "Respawn"
                {
                    RespawnKerbal(actionKerbal);
                }
                else if (actionText == SMUtils.Localize("#smloc_roster_025")) // "Thaw"
                {
                    ThawKerbal(actionKerbal.name);
                }
                else if (actionText == SMUtils.Localize("#smloc_roster_026"))// "Freeze"
                {
                    FreezeKerbal(actionKerbal);
                }
                SMAddon.FireEventTriggers();
            }
            catch (Exception ex)
            {
                if (!SMAddon.FrameErrTripped)
                {
                    SMUtils.LogMessage(string.Format(" in RosterListViewer.  Error:  {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true);
                }
            }
        }
Пример #15
0
        internal static void CombineSelectedVessels()
        {
            List <ModDockedVessel> .Enumerator mdv = SMAddon.SmVessel.DockedVessels.GetEnumerator();
            while (mdv.MoveNext())
            {
                if (mdv.Current == null)
                {
                    continue;
                }
                if (!mdv.Current.Combine)
                {
                    continue;
                }
                List <ModuleDockingNode> .Enumerator port;

                if (mdv.Current.Rootpart.FindModulesImplementing <ModuleDockingNode>().Any())
                {
                    port = mdv.Current.Rootpart.FindModulesImplementing <ModuleDockingNode>().GetEnumerator();
                    while (port.MoveNext())
                    {
                        if (port.Current == null)
                        {
                            continue;
                        }
                        if (port.Current.vesselInfo == null || port.Current.otherNode)
                        {
                            continue;
                        }
                        port.Current.vesselInfo           = null;
                        port.Current.otherNode.vesselInfo = null;
                        port.Current.otherNode            = null;
                    }
                    port.Dispose();
                }
                else
                {
                    // Since the root part is not a docking port, we need to locate the docking port that is currently docked.
                    List <Part> .Enumerator part = mdv.Current.VesselParts.GetEnumerator();
                    while (part.MoveNext())
                    {
                        if (part.Current == null)
                        {
                            continue;
                        }
                        if (!part.Current.FindModulesImplementing <ModuleDockingNode>().Any())
                        {
                            continue;
                        }
                        port = part.Current.FindModulesImplementing <ModuleDockingNode>().GetEnumerator();
                        while (port.MoveNext())
                        {
                            if (port.Current == null)
                            {
                                continue;
                            }
                            if (port.Current.vesselInfo == null || port.Current.otherNode == null)
                            {
                                continue;
                            }
                            // TODO:  Sort out the coupling criteria.  with current setup, still have an undock on the tweakable.  and a null ref when clicking.
                            //  That makes sense since the other node is now null.  So part/module state is still not correct after combining.
                            Part thisPart  = port.Current.part;
                            Part otherPart = port.Current.otherNode.part;

                            thisPart.Couple(otherPart);
                            otherPart.Couple(thisPart);

                            port.Current.state                             = "PreAttached";
                            port.Current.dockedPartUId                     = 0;
                            port.Current.dockingNodeModuleIndex            = 0;
                            port.Current.Events["Undock"].active           = false;
                            port.Current.Events["Undock"].guiActive        = false;
                            port.Current.Events["UndockSameVessel"].active = false;
                            port.Current.Events["Decouple"].active         = true;
                            port.Current.Events["Decouple"].guiActive      = true;

                            port.Current.otherNode.state                  = "PreAttached";
                            port.Current.otherNode.dockedPartUId          = 0;
                            port.Current.otherNode.dockingNodeModuleIndex = 0;

                            port.Current.otherNode.Events["Undock"].active           = false;
                            port.Current.Events["Undock"].guiActive                  = false;
                            port.Current.otherNode.Events["UndockSameVessel"].active = false;
                            port.Current.otherNode.Events["Decouple"].active         = true;
                            port.Current.Events["Decouple"].guiActive                = true;

                            port.Current.vesselInfo           = (DockedVesselInfo)null;
                            port.Current.otherNode.vesselInfo = (DockedVesselInfo)null;
                            port.Current.otherNode.otherNode  = (ModuleDockingNode)null;
                            port.Current.otherNode            = (ModuleDockingNode)null;
                        }
                        port.Dispose();
                    }
                    part.Dispose();
                }
            }
            mdv.Dispose();
            SMAddon.FireEventTriggers();
        }