예제 #1
0
        /// <summary>
        /// Add or remove crew from a part based on the part snapshot
        /// </summary>
        private static bool AdjustCrewMembersInPart(Part part, ProtoPartSnapshot partSnapshot)
        {
            if (part.protoModuleCrew.Count != partSnapshot.protoModuleCrew.Count)
            {
                MembersToAdd.Clear();
                MembersToRemove.Clear();
                MembersToAdd.AddRange(partSnapshot.protoModuleCrew.Where(mp => part.protoModuleCrew.All(m => m.name != mp.name)));
                MembersToRemove.AddRange(part.protoModuleCrew.Select(c => c.name).Except(partSnapshot.protoModuleCrew.Select(c => c.name)));

                foreach (var memberToAdd in MembersToAdd)
                {
                    part.AddCrewmember(memberToAdd);
                }

                foreach (var memberToRemove in MembersToRemove)
                {
                    var member = part.protoModuleCrew.First(c => c.name == memberToRemove);
                    part.RemoveCrewmember(member);
                }

                return(true);
            }

            return(false);
        }
예제 #2
0
        private void ShipToShip_AddCrew(Vessel targetShip, Part targetPart, ProtoCrewMember kerbalToMove)
        {
            //UnityEngine.Debug.Log("ImpulseDrive Transporter ShipToShip_AddCrew begin " + kerbalToMove.name);
            //targetShip.GoOffRails();
            if (!ShipToShip_PartIsFull(targetPart))
            {
                targetPart.AddCrewmember(kerbalToMove);
                targetShip.SpawnCrew();
                targetShip.ResumeStaging();
                targetShip.MakeActive();
            }

            /*
             * foreach (Part part in targetShip.Parts)
             * {
             *  if (!ShipToShip_PartIsFull(part))
             *  {
             *      UnityEngine.Debug.Log("ImpulseDrive Transporter ShipToShip_AddCrew 1 " );
             *
             *      part.AddCrewmember(kerbalToMove);
             *      UnityEngine.Debug.Log("ImpulseDrive Transporter ShipToShip_AddCrew 2 " );
             *
             *      targetShip.SpawnCrew();
             *      UnityEngine.Debug.Log("ImpulseDrive Transporter ShipToShip_AddCrew 3 ");
             *
             *      targetShip.ResumeStaging();
             *      UnityEngine.Debug.Log("ImpulseDrive Transporter ShipToShip_AddCrew 4 ");
             *
             *      targetShip.MakeActive();
             *      UnityEngine.Debug.Log("ImpulseDrive Transporter ShipToShip_AddCrew end ");
             *      return;
             *  }
             * }
             */
        }
예제 #3
0
        public void birthOfNewCivilans(double date, CivPopRepository repo)
        {
            List <CivPopKerbal> childs = new List <CivPopKerbal>();

            IEnumerable <CivPopKerbal> females = repo.GetRoster()
                                                 .Where(kerbal => kerbal.GetExpectingBirthAt() > 0)
                                                 .Where(kerbal => !kerbal.IsDead())
                                                 .Where(kerbal => kerbal.GetExpectingBirthAt() < date)
            ;

            foreach (CivPopKerbal female in females)
            {
                female.SetExpectingBirthAt(-1);
                if (female.GetVesselId() != null)
                {
                    CivPopVessel vessel = repo.GetVessel(female.GetVesselId());
                    if (vessel.GetCapacity() > repo.GetLivingRosterForVessel(vessel.GetId()).Count())
                    {
                        CivPopKerbal child = builder.build(date);
                        child.SetBirthdate(date);
                        child.SetVesselId(female.GetVesselId());

                        ProtoCrewMember pcm = new ProtoCrewMember(ProtoCrewMember.KerbalType.Crew, child.GetName());
                        KerbalRoster.SetExperienceTrait(pcm, "Civilian");//Set the Kerbal as the specified role (kerbalTraitName)
                        var plist = vessel.KSPVessel.parts.FindAll(p => p.CrewCapacity > p.protoModuleCrew.Count);

                        // There may be a better way, but this will look for space in the same part as the female giving birth
                        Part part = null;
                        foreach (var p in plist)
                        {
                            var crew = p.protoModuleCrew.Find(c => c.name == female.GetName());
                            if (crew != null)
                            {
                                part = p;
                                SimpleLogger.fetch.Info("Crew member: " + female.GetName() + ", found on part: " + p.partInfo.title);
                                break;
                            }
                        }
                        // If part is null, no room in same part, so just find a part with room
                        if (part == null)
                        {
                            part = vessel.KSPVessel.parts.Find(p => p.CrewCapacity > p.protoModuleCrew.Count);
                        }
                        if (part != null)
                        {
                            part.AddCrewmember(pcm);
                            vessel.KSPVessel.SpawnCrew();
                            SimpleLogger.fetch.Info("Child added to childs, name: " + child.GetName());
                        }
                        childs.Add(child);
                    }
                }
            }

            foreach (CivPopKerbal child in childs)
            {
                repo.Add(child);
            }
        }
예제 #4
0
 /// <summary>
 /// Adds a crew member to a specific Part, into a specific Seat, if provided.
 /// </summary>
 /// <param name="pKerbal"></param>
 /// <param name="part"></param>
 /// <param name="seat"></param>
 internal static void AddCrewMember(ProtoCrewMember pKerbal, Part part, InternalSeat seat = null)
 {
     if (seat != null)
     {
         part.AddCrewmemberAt(pKerbal, part.internalModel.seats.IndexOf(seat));
     }
     else
     {
         part.AddCrewmember(pKerbal);
     }
 }
        private void AddCrew(Part part, ProtoCrewMember kerbal, bool fireVesselUpdate)
        {
            part.AddCrewmember(kerbal);

            kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
            if (kerbal.seat != null)
            {
                kerbal.seat.SpawnCrew();
            }

            GameEvents.onVesselChange.Fire(FlightGlobals.ActiveVessel);
        }
예제 #6
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 > Utilities.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();
       }
 }
예제 #7
0
        private bool AddCrew(Part p, ProtoCrewMember kerbal)
        {
            p.AddCrewmember(kerbal);

            kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;

            if (kerbal.seat != null)
            {
                kerbal.seat.SpawnCrew();
            }

            return(true);
        }
예제 #8
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();
 }
예제 #9
0
 internal static void AddCrewMember(ProtoCrewMember pKerbal, Part part)
 {
     part.AddCrewmember(pKerbal);
     pKerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
     if (part.internalModel != null)
     {
         if (pKerbal.seat != null)
         {
             pKerbal.seat.SpawnCrew();
         }
     }
     FireEventTriggers(part.vessel);
 }
예제 #10
0
 static void move_crew(ProtoCrewMember crew, Part toP, Part fromP = null)
 {
     toP.AddCrewmember(crew);
     fromP?.RemoveCrewmember(crew);
     if (fromP != null)
     {
         GameEvents.onCrewTransferred.Fire(new GameEvents.HostedFromToAction <ProtoCrewMember, Part>(crew, fromP, toP));
     }
     else
     {
         Debug.LogWarning($"Dodged exception that might have come from transfering directly from the roster. From part: {fromP?.name} To part: {toP.name}");
         GameEvents.onCrewTransferred.Fire(new GameEvents.HostedFromToAction <ProtoCrewMember, Part>(crew, toP, toP));
     }
 }
예제 #11
0
 //add some crew to a part
 public static bool addCrew(Part p, List<ProtoCrewMember> crew)
 {
     if(crew.Count == 0) return false;
     if(p.CrewCapacity <= p.protoModuleCrew.Count) return false;
     while(p.protoModuleCrew.Count < p.CrewCapacity && crew.Count > 0)
     {
         var kerbal = crew[0];
         p.AddCrewmember(kerbal);
         if(kerbal.seat != null)
             kerbal.seat.SpawnCrew();
         crew.RemoveAt(0);
     }
     return true;
 }
        void generateCrew(string kerbalTrait, ProtoCrewMember.Gender gender)
        {
            ProtoCrewMember crew = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);

            while (crew.trait != kerbalTrait)
            {
                crew = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
            }
            crew.ChangeName(crewName);
            crew.type            = ProtoCrewMember.KerbalType.Crew;
            crew.gender          = gender;
            crew.experienceLevel = 5;
            FlightLog flight = new FlightLog();

            flight.AddEntry("Land,Eeloo");
            flight.AddEntry("Land,Dres");
            flight.AddEntry("Land,Pol");
            flight.AddEntry("Land,Gilly");
            flight.AddEntry("Land,Tylo");
            flight.AddEntry("Land,Bop");
            flight.AddEntry("Land,Vall");
            flight.AddEntry("Land,Laythe");
            crew.careerLog.AddFlight();
            for (int i = flight.Entries.Count - 1; i >= 0; --i)
            {
                FlightLog.Entry entries = flight.Entries[i];
                crew.careerLog.AddEntry(entries);
            }
            for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; --i)
            {
                Vessel vessel = FlightGlobals.Vessels[i];
                if (vessel.vesselName == "Kerbin Station")
                {
                    for (int j = vessel.Parts.Count - 1; j >= 0; --j)
                    {
                        Part part = vessel.Parts[j];
                        if (part.protoModuleCrew.Count < part.CrewCapacity)
                        {
                            part.AddCrewmember(crew);
                            part.Actions.part.SpawnIVA();
                            CameraManager.Instance.SetCameraMap();
                            CameraManager.Instance.SetCameraFlight();
                            break;
                        }
                    }
                    break;
                }
            }
        }
예제 #13
0
        private void AddCrew(Part part, ProtoCrewMember kerbal, bool fireVesselUpdate)
        {
            part.AddCrewmember(kerbal);

            kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
            if (kerbal.seat != null)
            {
                kerbal.seat.SpawnCrew();
            }

            if (fireVesselUpdate)
            {
                ManifestBehaviour.FireVesselUpdated();
            }
        }
예제 #14
0
        private void FillPartCrew(int count, Part part)
        {
            if (IsPreLaunch && !CrewPartIsFull(part))
            {
                for (int i = 0; i < part.CrewCapacity && i < count; i++)
                {
                    ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.GetNextOrNewKerbal();
                    part.AddCrewmember(kerbal);

                    if (kerbal.seat != null)
                    {
                        kerbal.seat.SpawnCrew();
                    }
                }
            }
        }
예제 #15
0
    private void addCrew(Part part, CrewMember crew)  //from kerbal crew manifest by vXSovereignXv
    {
        ProtoCrewMember kerbal = new ProtoCrewMember();

        kerbal.name         = crew.Name;
        kerbal.isBadass     = crew.isBadass;
        kerbal.stupidity    = crew.Stupidity;
        kerbal.courage      = crew.Courage;
        kerbal.rosterStatus = ProtoCrewMember.RosterStatus.ASSIGNED;
        //kerbal.seat = null;
        //kerbal.seatIdx = -1;
        part.AddCrewmember(kerbal);
        if (kerbal.seat != null)
        {
            kerbal.seat.SpawnCrew();
        }
    }
예제 #16
0
        private static void FillPartCrew(int count, Part part)
        {
            if (CrewPartIsFull(part))
            {
                return;
            }
            for (var i = 0; i < part.CrewCapacity && i < count; i++)
            {
                var kerbal = HighLogic.CurrentGame.CrewRoster.GetNextOrNewKerbal();
                part.AddCrewmember(kerbal);

                if (kerbal.seat != null)
                {
                    kerbal.seat.SpawnCrew();
                }
            }
        }
예제 #17
0
        public void AddPassengersToActiveVessel()
        {
            LoggingUtil.LogVerbose(this, "AddPassengersToActiveVessel");

            // Check the active vessel
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || !HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            foreach (ProtoCrewMember crewMember in passengers.Keys.ToList())
            {
                // Find a seat for the crew
                Part part = v.parts.Find(p => p.protoModuleCrew.Count < p.CrewCapacity);

                // Add the crew member
                bool success = false;
                if (part != null)
                {
                    // Add them to the part
                    success = part.AddCrewmember(crewMember);
                    if (success)
                    {
                        crewMember.type        = ProtoCrewMember.KerbalType.Tourist;
                        passengers[crewMember] = true;
                        GameEvents.onCrewBoardVessel.Fire(new GameEvents.FromToAction <Part, Part>(part, part));
                        GameEvents.onCrewTransferred.Fire(new GameEvents.HostedFromToAction <ProtoCrewMember, Part>(crewMember, part, part));
                    }
                }

                if (!success)
                {
                    LoggingUtil.LogError(this, "Unable to add crew to vessel named '" + v.name + "'.  Perhaps there's no room?");
                    break;
                }
            }

            // This will force the crew members to appear
            v.SpawnCrew();

            // Update the parameters and force a re-check to update their state
            onPassengersLoaded.Fire();
        }
예제 #18
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();
 }
예제 #19
0
        private ProtoCrewMember spawn()
        {
            KerbalRoster    kspRoster = HighLogic.CurrentGame.CrewRoster;
            ProtoCrewMember newKerbal = kspRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);

            foreach (Vessel vessel in FlightGlobals.Vessels)
            {
                log(vessel.GetName());
                if (vessel.GetName().Equals("Ground Base - Laythe"))
                {
                    log("Adding crew : " + newKerbal.name + " to vessel");
                    Part part = vessel.parts.Find(p => p.CrewCapacity > p.protoModuleCrew.Count);
                    if (part != null)
                    {
                        log("Adding crew : " + newKerbal.name + " to part");
                        part.AddCrewmember(newKerbal);
                    }
                }
            }
            return(newKerbal);
        }
        /// <summary>
        /// When a part is selected.
        /// </summary>
        /// <param name="p">The selected part.</param>
        private void OnPartSelected(Part p)
        {
            // Add the crew member.
            p.AddCrewmember(toAdd);
            // Set roster status to Assigned.
            toAdd.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;

            // If the seat isn't null,
            if (toAdd.seat != null)
            {
                // Spawn the crew.
                toAdd.seat.SpawnCrew();
            }

            // Fire a fake crew transfer event to update the crew portraits.
            GameEvents.onCrewTransferred.Fire(new GameEvents.HostedFromToAction <ProtoCrewMember, Part>(toAdd, p, p));

            // Post to the screen and leave it.
            ScreenMessages.PostScreenMessage(toAdd.name + " added to " + p.partInfo.title + ".", 3f, ScreenMessageStyle.LOWER_CENTER);

            // Clean up the manager
            CleanUp();
        }
 private void MoveKerbal(Part source, Part target, ProtoCrewMember kerbal)
 {
     RemoveCrew(kerbal, source);
     target.AddCrewmember(kerbal);
     if (kerbal.seat != null)
         kerbal.seat.SpawnCrew();
     kerbal.rosterStatus = ProtoCrewMember.RosterStatus.ASSIGNED;
 }
예제 #22
0
        protected void abandonShip(Vessel vessel)
        {
            //If the vessel has no crew then we're done.
            if (vessel.GetVesselCrew().Count == 0)
            {
                debugLog("No crew to evacuate");
                return;
            }
            List <Part>     escapePods     = new List <Part>();
            Part            escapePod      = null;
            int             podIndex       = 0;
            int             evacuatedCount = 0;
            ProtoCrewMember astronaut;

            //Find all ModuleEscapePod modules that are marked as escape pods and transfer crew to them.
            List <ModuleEscapePod> pods = vessel.FindPartModulesImplementing <ModuleEscapePod>();

            foreach (ModuleEscapePod pod in pods)
            {
                if (pod.part.CrewCapacity > 0 && pod.escapePodEnabled)
                {
                    escapePods.Add(pod.part);
                }
            }
            debugLog("Found " + escapePods.Count + " escape pods");

            //If we have no escape pods then we're done.
            if (escapePods.Count == 0)
            {
                debugLog("No escape pods!");
                return;
            }

            //Get the initial escape pod
            escapePod = escapePods[podIndex];

            //Yank all the crew and stick them in an escape pod. If we can.
            foreach (Part part in vessel.parts)
            {
                while (part.protoModuleCrew.Count > 0)
                {
                    //If the pod is out of space then get another pod
                    if (escapePod.protoModuleCrew.Count >= escapePod.CrewCapacity)
                    {
                        podIndex += 1;
                        if (podIndex < escapePods.Count)
                        {
                            escapePod = escapePods[podIndex];
                        }
                        else
                        {
                            break;
                        }
                    }

                    //Get the astronaut
                    astronaut = part.protoModuleCrew[0];

                    //Remove the astronaut
                    part.RemoveCrewmember(astronaut);
                    astronaut.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                    debugLog("Removed " + astronaut.name + " from " + part.partInfo.title);

                    //Add astronaut to the pod
                    escapePod.AddCrewmember(astronaut);
                    astronaut.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                    escapePod.RegisterCrew();
                    astronaut.seat.SpawnCrew();
                    KerbalPortraitGallery.Instance.UpdatePortrait(astronaut.KerbalRef);
                    debugLog("Added " + astronaut.name + " to " + escapePod.partInfo.title);
                    evacuatedCount += 1;
                }
            }

            //Inform player that astronauts reached escape pods.
            string message = vessel.vesselName + Localizer.Format(BARISScenario.AstronautsEvacuatedMsg);

            BARISScenario.Instance.LogPlayerMessage(message);
            StartCoroutine(spawnIVA());
        }
예제 #23
0
        private void AddCrew(Part part, ProtoCrewMember kerbal, bool fireVesselUpdate)
        {
            part.AddCrewmember(kerbal);

            kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
            if (kerbal.seat != null)
                kerbal.seat.SpawnCrew();

            if (fireVesselUpdate)
                ManifestBehaviour.FireVesselUpdated();
        }
예제 #24
0
 internal static void AddCrewMember(ProtoCrewMember pKerbal, Part part)
 {
   part.AddCrewmember(pKerbal);
   if (part.internalModel != null)
   {
     if (pKerbal.seat != null)
       pKerbal.seat.SpawnCrew();
   }
   pKerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
   SMAddon.FireEventTriggers();
 }
예제 #25
0
 private void addCrew(Part part, CrewMember crew)  //from kerbal crew manifest by vXSovereignXv
 {
     ProtoCrewMember kerbal = new ProtoCrewMember();
     kerbal.name = crew.Name;
     kerbal.isBadass = crew.isBadass;
     kerbal.stupidity = crew.Stupidity;
     kerbal.courage = crew.Courage;
     kerbal.rosterStatus = ProtoCrewMember.RosterStatus.ASSIGNED;
     //kerbal.seat = null;
     //kerbal.seatIdx = -1;
     part.AddCrewmember(kerbal);        
     if (kerbal.seat != null)
         kerbal.seat.SpawnCrew();
 }
예제 #26
0
        private void FillPartCrew(int count, Part part)
        {
            if (!CrewPartIsFull(part))
            {
                for (int i = 0; i < part.CrewCapacity && i < count; i++)
                {
                    ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.GetNextOrNewKerbal();
                    part.AddCrewmember(kerbal);

                    if (kerbal.seat != null)
                        kerbal.seat.SpawnCrew();
                }
            }
        }
예제 #27
0
        private bool AddCrew(Part p, ProtoCrewMember kerbal)
        {
            p.AddCrewmember(kerbal);

            kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;

            if (kerbal.seat != null)
                kerbal.seat.SpawnCrew();

            return (true);
        }
예제 #28
0
        public void Start()
        {
            KCTDebug.Log("Start called");
            if (Utilities.CurrentGameIsMission())
            {
                return;
            }

            // Subscribe to events from KSP and other mods
            if (!KCTEvents.Instance.SubscribedToEvents)
            {
                KCTEvents.Instance.SubscribeToEvents();
            }

            if (KCTGameStates.IsFirstStart)
            {
                PresetManager.Instance.SaveActiveToSaveData();
            }

            // Ghetto event queue
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                InvokeRepeating("EditorRecalculation", 1, 1);

                KCT_GUI.BuildRateForDisplay = null;
                if (!KCT_GUI.IsPrimarilyDisabled)
                {
                    Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);
                }
            }

            if (KCT_GUI.IsPrimarilyDisabled &&
                InputLockManager.GetControlLock("KCTLaunchLock") == ControlTypes.EDITOR_LAUNCH)
            {
                InputLockManager.RemoveControlLock("KCTLaunchLock");
            }

            KACWrapper.InitKACWrapper();

            if (!PresetManager.Instance.ActivePreset.GeneralSettings.Enabled)
            {
                if (InputLockManager.GetControlLock("KCTKSCLock") == ControlTypes.KSC_FACILITIES)
                {
                    InputLockManager.RemoveControlLock("KCTKSCLock");
                }
                return;
            }

            //Begin primary mod functions

            KCTGameStates.UT = Utilities.GetUT();

            KCT_GUI.GuiDataSaver.Load();
            KCT_GUI.GUIStates.HideAllNonMainWindows();

            if (!HighLogic.LoadedSceneIsFlight)
            {
                bool b = KCTGameStates.SimulationParams.BuildSimulatedVessel;
                KCTGameStates.SimulationParams.Reset();
                if (b && KCTGameStates.LaunchedVessel != null)
                {
                    Utilities.AddVesselToBuildList(KCTGameStates.LaunchedVessel);
                }
            }

            switch (HighLogic.LoadedScene)
            {
            case GameScenes.EDITOR:
                KCT_GUI.HideAll();
                if (!KCT_GUI.IsPrimarilyDisabled)
                {
                    KCT_GUI.GUIStates.ShowEditorGUI = KCTGameStates.ShowWindows[1];
                    if (KCTGameStates.EditorShipEditingMode)
                    {
                        KCT_GUI.EnsureEditModeIsVisible();
                    }
                    else if (KCT_GUI.GUIStates.ShowEditorGUI)
                    {
                        KCT_GUI.ToggleVisibility(true);
                    }
                    else
                    {
                        KCT_GUI.ToggleVisibility(false);
                    }
                }
                break;

            case GameScenes.SPACECENTER:
                bool shouldStart = KCT_GUI.GUIStates.ShowFirstRun;
                KCT_GUI.HideAll();
                KCTGameStates.ClearVesselEditMode();
                if (!shouldStart)
                {
                    KCT_GUI.GUIStates.ShowBuildList = KCTGameStates.ShowWindows[0];
                    if (KCT_GUI.GUIStates.ShowBuildList)
                    {
                        KCT_GUI.ToggleVisibility(true);
                    }
                    else
                    {
                        KCT_GUI.ToggleVisibility(false);
                    }
                }
                KCT_GUI.GUIStates.ShowFirstRun = shouldStart;
                break;

            case GameScenes.TRACKSTATION:
                KCTGameStates.ClearVesselEditMode();
                break;

            case GameScenes.FLIGHT:
                if (!KCTGameStates.IsSimulatedFlight &&
                    FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH &&
                    FlightGlobals.ActiveVessel.GetCrewCount() == 0 && KCTGameStates.LaunchedCrew.Count > 0)
                {
                    KerbalRoster roster = HighLogic.CurrentGame.CrewRoster;

                    for (int i = 0; i < FlightGlobals.ActiveVessel.parts.Count; i++)
                    {
                        Part p = FlightGlobals.ActiveVessel.parts[i];
                        KCTDebug.Log("Part being tested: " + p.partInfo.title);
                        {
                            CrewedPart cp = KCTGameStates.LaunchedCrew.Find(part => part.PartID == p.craftID);
                            if (cp == null)
                            {
                                continue;
                            }
                            List <ProtoCrewMember> crewList = cp.CrewList;
                            KCTDebug.Log("cP.crewList.Count: " + cp.CrewList.Count);
                            foreach (ProtoCrewMember crewMember in crewList)
                            {
                                if (crewMember != null)
                                {
                                    ProtoCrewMember finalCrewMember = crewMember;
                                    if (crewMember.type == ProtoCrewMember.KerbalType.Crew)
                                    {
                                        finalCrewMember = roster.Crew.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    else if (crewMember.type == ProtoCrewMember.KerbalType.Tourist)
                                    {
                                        finalCrewMember = roster.Tourist.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    if (finalCrewMember == null)
                                    {
                                        KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}. Cannot find Kerbal in list.");
                                        continue;
                                    }
                                    try
                                    {
                                        KCTDebug.Log($"Assigning {finalCrewMember.name } to {p.partInfo.name}");
                                        if (p.AddCrewmember(finalCrewMember))
                                        {
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                                            if (finalCrewMember.seat != null)
                                            {
                                                finalCrewMember.seat.SpawnCrew();
                                            }
                                        }
                                        else
                                        {
                                            KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}");
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                            continue;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        KCTDebug.LogError($"Error when assigning {crewMember.name} to {p.partInfo.name}: {ex}");
                                        finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                    KCTGameStates.LaunchedCrew.Clear();
                }

                KCT_GUI.HideAll();
                if (!KCTGameStates.IsSimulatedFlight && KCTGameStates.LaunchedVessel != null && FlightGlobals.ActiveVessel?.situation == Vessel.Situations.PRELAUNCH)
                {
                    KCTGameStates.LaunchedVessel.KSC = null;     //it's invalid now
                    KCTDebug.Log("Attempting to remove launched vessel from build list");
                    bool removed = KCTGameStates.LaunchedVessel.RemoveFromBuildList();
                    if (removed)     //Only do these when the vessel is first removed from the list
                    {
                        //Add the cost of the ship to the funds so it can be removed again by KSP
                        Utilities.AddFunds(KCTGameStates.LaunchedVessel.Cost, TransactionReasons.VesselRollout);
                        FlightGlobals.ActiveVessel.vesselName = KCTGameStates.LaunchedVessel.ShipName;
                    }

                    ReconRollout rollout = KCTGameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.AssociatedID == KCTGameStates.LaunchedVessel.Id.ToString());
                    if (rollout != null)
                    {
                        KCTGameStates.ActiveKSC.Recon_Rollout.Remove(rollout);
                    }

                    AirlaunchPrep alPrep = KCTGameStates.ActiveKSC.AirlaunchPrep.FirstOrDefault(r => r.AssociatedID == KCTGameStates.LaunchedVessel.Id.ToString());
                    if (alPrep != null)
                    {
                        KCTGameStates.ActiveKSC.AirlaunchPrep.Remove(alPrep);
                    }

                    AirlaunchParams alParams = KCTGameStates.AirlaunchParams;
                    if (alParams != null && alParams.KCTVesselId == KCTGameStates.LaunchedVessel.Id &&
                        (!alParams.KSPVesselId.HasValue || alParams.KSPVesselId == FlightGlobals.ActiveVessel.id))
                    {
                        if (!alParams.KSPVesselId.HasValue)
                        {
                            alParams.KSPVesselId = FlightGlobals.ActiveVessel.id;
                        }
                        StartCoroutine(AirlaunchRoutine(alParams, FlightGlobals.ActiveVessel.id));
                    }
                }
                break;
            }

            _ratesUpdated = false;
            KCTDebug.Log("Start finished");

            _wfsOne  = new WaitForSeconds(1f);
            _wfsTwo  = new WaitForSeconds(2f);
            _wfsHalf = new WaitForSeconds(0.5f);

            DelayedStart();

            UpdateTechlistIconColor();
            StartCoroutine(HandleEditorButton_Coroutine());
        }
예제 #29
0
 static void move_crew(Part fromP, Part toP, ProtoCrewMember crew)
 {
     fromP.RemoveCrewmember(crew);
     toP.AddCrewmember(crew);
     GameEvents.onCrewTransferred.Fire(new GameEvents.HostedFromToAction <ProtoCrewMember, Part>(crew, fromP, toP));
 }
예제 #30
0
    internal static void FillPartCrew(Part part)
    {
      if (part.vessel.IsRecoverable && !IsPartCrewFull(part))
      {
        while (part.CrewCapacity > Utilities.GetPartCrewCount(part))
        {
          ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.GetNextOrNewKerbal();
          part.AddCrewmember(kerbal);

          if (kerbal.seat != null)
            kerbal.seat.SpawnCrew();
        }
      }
    }
예제 #31
0
 public void AddCrew(ProtoCrewMember kerbal, Part part)
 {
     part.AddCrewmember(kerbal);
     kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
     if (part.internalModel != null)
     {
         if (kerbal.seat != null)
             kerbal.seat.SpawnCrew();
     }
     ShipManifestBehaviour.FireEventTriggers();
 }
예제 #32
0
        public void Start()
        {
            if (KCT_Utilities.CurrentGameIsMission())
            {
                return;
            }

            KCTDebug.Log("Start called");

            // Subscribe to events from KSP and other mods
            if (!KCT_Events.instance.subscribedToEvents)
            {
                KCT_Events.instance.SubscribeToEvents();
            }

            KCT_GameStates.settings.Save(); //Save the settings file, with defaults if it doesn't exist
            KCT_PresetManager.Instance.SaveActiveToSaveData();

            // Ghetto event queue
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                InvokeRepeating("EditorRecalculation", 1, 1);

                KCT_GUI.buildRateForDisplay = null;
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);
                }
            }

            if (KCT_GUI.PrimarilyDisabled)
            {
                if (InputLockManager.GetControlLock("KCTLaunchLock") == ControlTypes.EDITOR_LAUNCH)
                {
                    InputLockManager.RemoveControlLock("KCTLaunchLock");
                }
            }

            KACWrapper.InitKACWrapper();

            if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                if (InputLockManager.GetControlLock("KCTKSCLock") == ControlTypes.KSC_FACILITIES)
                {
                    InputLockManager.RemoveControlLock("KCTKSCLock");
                }
                return;
            }

            //Begin primary mod functions

            KCT_GameStates.UT = Planetarium.GetUniversalTime();

            KCT_GUI.guiDataSaver.Load();

            switch (HighLogic.LoadedScene)
            {
            case GameScenes.EDITOR:

                //if (HighLogic.LoadedSceneIsEditor)
            {
                KCT_GUI.hideAll();
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_GUI.showEditorGUI = KCT_GameStates.showWindows[1];
                    if (KCT_GUI.showEditorGUI)
                    {
                        KCT_GUI.ClickOn();
                    }
                    else
                    {
                        KCT_GUI.ClickOff();
                    }
                }
            }
            break;

            case GameScenes.SPACECENTER:
                //else if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                bool shouldStart = KCT_GUI.showFirstRun;
                KCT_GUI.hideAll();
                if (!shouldStart)
                {
                    KCT_GUI.showBuildList = KCT_GameStates.showWindows[0];
                    if (KCT_GUI.showBuildList)
                    {
                        KCT_GUI.ClickOn();
                    }
                    else
                    {
                        KCT_GUI.ClickOff();
                    }
                }
                KCT_GUI.showFirstRun = shouldStart;
            }
            break;

            case GameScenes.FLIGHT:
                if (/*HighLogic.LoadedSceneIsFlight && */ FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH &&
                    FlightGlobals.ActiveVessel.GetCrewCount() == 0 && KCT_GameStates.launchedCrew.Count > 0)
                {
                    KerbalRoster roster = HighLogic.CurrentGame.CrewRoster;

                    for (int i = 0; i < FlightGlobals.ActiveVessel.parts.Count; i++)
                    {
                        Part p = FlightGlobals.ActiveVessel.parts[i];
                        //KCTDebug.Log("craft: " + p.craftID);
                        KCTDebug.LogError("Part being tested: " + p.partInfo.title);
                        {
                            CrewedPart cP = KCT_GameStates.launchedCrew.Find(part => part.partID == p.craftID);
                            if (cP == null)
                            {
                                continue;
                            }
                            List <ProtoCrewMember> crewList = cP.crewList;
                            KCTDebug.LogError("cP.crewList.Count: " + cP.crewList.Count);
                            foreach (ProtoCrewMember crewMember in crewList)
                            {
                                if (crewMember != null)
                                {
                                    ProtoCrewMember finalCrewMember = crewMember;
                                    if (crewMember.type == ProtoCrewMember.KerbalType.Crew)
                                    {
                                        finalCrewMember = roster.Crew.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    else if (crewMember.type == ProtoCrewMember.KerbalType.Tourist)
                                    {
                                        finalCrewMember = roster.Tourist.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    if (finalCrewMember == null)
                                    {
                                        KCTDebug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name + ". Cannot find Kerbal in list.");
                                        continue;
                                    }
                                    try
                                    {
                                        KCTDebug.Log("Assigning " + finalCrewMember.name + " to " + p.partInfo.name);
                                        if (p.AddCrewmember(finalCrewMember))    //p.AddCrewmemberAt(finalCrewMember, crewList.IndexOf(crewMember)))
                                        {
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                                            if (finalCrewMember.seat != null)
                                            {
                                                finalCrewMember.seat.SpawnCrew();
                                            }
                                        }
                                        else
                                        {
                                            KCTDebug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                            continue;
                                        }
                                    }
                                    catch
                                    {
                                        KCTDebug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                        finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                    KCT_GameStates.launchedCrew.Clear();
                }
                //if (HighLogic.LoadedSceneIsFlight)
                {
                    KCT_GUI.hideAll();
                    if (KCT_GameStates.launchedVessel != null && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH)
                    {
                        KCT_GameStates.launchedVessel.KSC = null;     //it's invalid now
                        KCTDebug.Log("Attempting to remove launched vessel from build list");
                        bool removed = KCT_GameStates.launchedVessel.RemoveFromBuildList();
                        if (removed)     //Only do these when the vessel is first removed from the list
                        {
                            //Add the cost of the ship to the funds so it can be removed again by KSP
                            KCT_Utilities.AddFunds(KCT_GameStates.launchedVessel.cost, TransactionReasons.VesselRollout);
                            FlightGlobals.ActiveVessel.vesselName = KCT_GameStates.launchedVessel.shipName;
                        }

                        KCT_Recon_Rollout rollout = KCT_GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == KCT_GameStates.launchedVessel.id.ToString());
                        if (rollout != null)
                        {
                            KCT_GameStates.ActiveKSC.Recon_Rollout.Remove(rollout);
                        }

                        KCT_AirlaunchPrep alPrep = KCT_GameStates.ActiveKSC.AirlaunchPrep.FirstOrDefault(r => r.associatedID == KCT_GameStates.launchedVessel.id.ToString());
                        if (alPrep != null)
                        {
                            KCT_GameStates.ActiveKSC.AirlaunchPrep.Remove(alPrep);
                        }

                        AirlaunchParams alParams = KCT_GameStates.AirlaunchParams;
                        if (alParams != null && alParams.KCTVesselId == KCT_GameStates.launchedVessel.id &&
                            (!alParams.KSPVesselId.HasValue || alParams.KSPVesselId == FlightGlobals.ActiveVessel.id))
                        {
                            if (!alParams.KSPVesselId.HasValue)
                            {
                                alParams.KSPVesselId = FlightGlobals.ActiveVessel.id;
                            }
                            StartCoroutine(AirlaunchRoutine(alParams, FlightGlobals.ActiveVessel.id));
                        }
                    }
                }
                break;
            }

            ratesUpdated = false;
            KCTDebug.Log("Start finished");

            wfsOne  = new WaitForSeconds(1f);
            wfsTwo  = new WaitForSeconds(2f);
            wfsHalf = new WaitForSeconds(0.5f);

            DelayedStart();

            UpdateTechlistIconColor();
            StartCoroutine(HandleEditorButton_Coroutine());
        }
예제 #33
0
        public void Start()
        {
            const string logBlockName = nameof(KerbalConstructionTime) + "." + nameof(Start);

            using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All))
            {
                if (KCT_Utilities.CurrentGameIsMission())
                {
                    return;
                }

                Log.Trace("Start called");

                //add the events
                if (!KCTEvents.instance.eventAdded)
                {
                    KCTEvents.instance.addEvents();
                }

                GameStates.settings.Save(); //Save the settings file, with defaults if it doesn't exist
                KCT_PresetManager.Instance.SaveActiveToSaveData();

                // Ghetto event queue
                if (HighLogic.LoadedScene == GameScenes.EDITOR)
                {
                    InvokeRepeating("EditorRecalculation", 1, 1);

                    KCT_GUI.buildRateForDisplay = null;
                    if (!KCT_GUI.PrimarilyDisabled)
                    {
                        KCT_Utilities.RecalculateEditorBuildTime(EditorLogic.fetch.ship);
                    }
                }

                if (KCT_GUI.PrimarilyDisabled)
                {
                    if (InputLockManager.GetControlLock("KCTLaunchLock") == ControlTypes.EDITOR_LAUNCH)
                    {
                        InputLockManager.RemoveControlLock("KCTLaunchLock");
                    }
                }

                KACWrapper.InitKACWrapper();

                if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                {
                    if (InputLockManager.GetControlLock("KCTKSCLock") == ControlTypes.KSC_FACILITIES)
                    {
                        InputLockManager.RemoveControlLock("KCTKSCLock");
                    }
                    return;
                }

                //Begin primary mod functions

                GameStates.UT = Planetarium.GetUniversalTime();

                KCT_GUI.guiDataSaver.Load();

                if (HighLogic.LoadedSceneIsEditor)
                {
                    KCT_GUI.hideAll();
                    if (!KCT_GUI.PrimarilyDisabled)
                    {
                        KCT_GUI.showEditorGUI = GameStates.showWindows[1];
                        if (KCT_GUI.showEditorGUI)
                        {
                            KCT_GUI.ClickOn();
                        }
                        else
                        {
                            KCT_GUI.ClickOff();
                        }
                    }
                }
                else if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
                {
                    bool shouldStart = KCT_GUI.showFirstRun;
                    KCT_GUI.hideAll();
                    if (!shouldStart)
                    {
                        KCT_GUI.showBuildList = GameStates.showWindows[0];
                        if (KCT_GUI.showBuildList)
                        {
                            KCT_GUI.ClickOn();
                        }
                        else
                        {
                            KCT_GUI.ClickOff();
                        }
                    }
                    KCT_GUI.showFirstRun = shouldStart;
                }

                if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH)
                {
                    if (FlightGlobals.ActiveVessel.GetCrewCount() == 0 && GameStates.launchedCrew.Count > 0)
                    {
                        KerbalRoster roster = HighLogic.CurrentGame.CrewRoster;

                        for (int i = 0; i < FlightGlobals.ActiveVessel.parts.Count; i++)
                        {
                            Part p = FlightGlobals.ActiveVessel.parts[i];
                            //Log.Trace("craft: " + p.craftID);
                            {
                                CrewedPart cP = GameStates.launchedCrew.Find(part => part.partID == p.craftID);
                                if (cP == null)
                                {
                                    continue;
                                }
                                List <ProtoCrewMember> crewList = cP.crewList;
                                foreach (ProtoCrewMember crewMember in crewList)
                                {
                                    if (crewMember != null)
                                    {
                                        ProtoCrewMember finalCrewMember = crewMember;
                                        if (crewMember.type == ProtoCrewMember.KerbalType.Crew)
                                        {
                                            finalCrewMember = roster.Crew.FirstOrDefault(c => c.name == crewMember.name);
                                        }
                                        else if (crewMember.type == ProtoCrewMember.KerbalType.Tourist)
                                        {
                                            finalCrewMember = roster.Tourist.FirstOrDefault(c => c.name == crewMember.name);
                                        }
                                        if (finalCrewMember == null)
                                        {
                                            Debug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name + ". Cannot find Kerbal in list.");
                                            continue;
                                        }
                                        try
                                        {
                                            Log.Trace("Assigning " + finalCrewMember.name + " to " + p.partInfo.name);
                                            if (p.AddCrewmember(finalCrewMember))  //p.AddCrewmemberAt(finalCrewMember, crewList.IndexOf(crewMember)))
                                            {
                                                finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                                                if (finalCrewMember.seat != null)
                                                {
                                                    finalCrewMember.seat.SpawnCrew();
                                                }
                                            }
                                            else
                                            {
                                                Debug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                                finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                                continue;
                                            }
                                        }
                                        catch
                                        {
                                            Debug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                        GameStates.launchedCrew.Clear();
                    }
                }
                if (HighLogic.LoadedSceneIsFlight)
                {
                    KCT_GUI.hideAll();
                    if (GameStates.launchedVessel != null && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH)
                    {
                        GameStates.launchedVessel.KSC = null; //it's invalid now
                        Log.Trace("Attempting to remove launched vessel from build list");
                        bool removed = GameStates.launchedVessel.RemoveFromBuildList();
                        if (removed) //Only do these when the vessel is first removed from the list
                        {
                            //Add the cost of the ship to the funds so it can be removed again by KSP
                            KCT_Utilities.AddFunds(GameStates.launchedVessel.cost, TransactionReasons.VesselRollout);
                            FlightGlobals.ActiveVessel.vesselName = GameStates.launchedVessel.shipName;
                        }
                        Recon_Rollout rollout = GameStates.ActiveKSC.Recon_Rollout.FirstOrDefault(r => r.associatedID == GameStates.launchedVessel.id.ToString());
                        if (rollout != null)
                        {
                            GameStates.ActiveKSC.Recon_Rollout.Remove(rollout);
                        }
                    }
                }
                ratesUpdated = false;
                DelayedStart();
            }
        }
 private void AddCrew(Part part, ProtoCrewMember kerbal)
 {
     part.AddCrewmember(kerbal);
     kerbal.rosterStatus = ProtoCrewMember.RosterStatus.ASSIGNED;
     if (kerbal.seat != null)
         kerbal.seat.SpawnCrew();
 }
예제 #35
0
    internal static void RevertCrewTransfer(ProtoCrewMember fromCrew, Part fromPart, Part toPart)
    {
      // If a Stock crew Transfer occurred, let's revert the crew and activate the SM transfer mechanism...
      toPart.RemoveCrewmember(fromCrew);
      fromPart.AddCrewmember(fromCrew);
      if (fromCrew.seat != null)
        fromCrew.seat.SpawnCrew();

      SMAddon.smController.RespawnCrew();
    }
예제 #36
0
        private void UpdateEvents()
        {
            var windows = Util.GetActionWindows();

            Events.Clear();
            // Return if more than two parts are selected or not all of the parts
            // selected are crewable
            if (!(windows.Count == 2 &&
                  Util.FindRightClickedParts().Contains(part) &&
                  windows.All((w) => w.part.CrewCapacity > 0)))
            {
                heldKerbal = null;
                return;
            }

            foreach (var crew in part.protoModuleCrew)
            {
                var actionType = (heldKerbal == crew) ? "Swapping " : "Transfer ";

                Events.Add(new BaseEvent(Events, "transfer" + crew.name, () =>
                {
                    Part otherPart = FindSelectedCrewModule();
                    if (!otherPart)
                    {
                        return;
                    }

                    var otherModule = otherPart.Modules.OfType <CrewXferModule>().First();

                    if (CLSClient.CLSInstalled && !Util.PartsAreConnected(part, otherPart))
                    {
                        Util.PostPebkac("Part's aren't connected");
                        return;
                    }

                    if (!otherPart.HasSpace())
                    {
                        if (otherModule.heldKerbal != null)
                        {
                            otherPart.RemoveCrewmember(otherModule.heldKerbal);
                            part.RemoveCrewmember(crew);
                            otherPart.AddCrewmember(crew);
                            part.AddCrewmember(otherModule.heldKerbal);
                            otherModule.heldKerbal.seat.SpawnCrew();
                            crew.seat.SpawnCrew();

                            otherModule.heldKerbal = null;
                        }
                        else
                        {
                            Util.PostPebkac("Swapping " + crew.name);
                            heldKerbal = crew;
                        }

                        updateStartTime = Planetarium.GetUniversalTime();
                        return;
                    }

                    Debug.Log("Moving " + crew.name);
                    part.RemoveCrewmember(crew);
                    otherPart.AddCrewmember(crew);
                    crew.seat.SpawnCrew(); // Not entirely sure if this is necessary

                    // Delay before spawning the crew again
                    updateStartTime = Planetarium.GetUniversalTime();
                }, new KSPEvent {
                    guiName = actionType + crew.name, guiActive = true
                }));
            }
        }
예제 #37
0
        public void Start()
        {
            KCT_GameStates.settings.Save(); //Save the settings file, with defaults if it doesn't exist
            KCT_PresetManager.Instance.SaveActiveToSaveData();

            /* KCT_GameStates.timeSettings.Load(); //Load the time settings
             * KCT_GameStates.timeSettings.Save(); //Save the time settings
             * UpdateOldFormulaCFG(); //Update the formula cfg file to the new format so things aren't broken
             * KCT_GameStates.formulaSettings.Load();
             * KCT_GameStates.formulaSettings.Save();*/

            // Ghetto event queue
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                InvokeRepeating("EditorRecalculation", 1, 1);
            }

            //Code for saving to the persistence.sfs
            ProtoScenarioModule scenario = HighLogic.CurrentGame.scenarios.Find(s => s.moduleName == typeof(KerbalConstructionTimeData).Name);

            if (scenario == null)
            {
                try
                {
                    Debug.Log("[KCT] Adding InternalModule scenario to game '" + HighLogic.CurrentGame.Title + "'");
                    HighLogic.CurrentGame.AddProtoScenarioModule(typeof(KerbalConstructionTimeData), new GameScenes[] { GameScenes.FLIGHT, GameScenes.SPACECENTER, GameScenes.EDITOR, GameScenes.TRACKSTATION });
                    // the game will add this scenario to the appropriate persistent file on save from now on
                }
                catch (ArgumentException ae)
                {
                    Debug.LogException(ae);
                }
                catch
                {
                    Debug.Log("[KCT] Unknown failure while adding scenario.");
                }
            }
            else
            {
                if (!scenario.targetScenes.Contains(GameScenes.SPACECENTER))
                {
                    scenario.targetScenes.Add(GameScenes.SPACECENTER);
                }
                if (!scenario.targetScenes.Contains(GameScenes.FLIGHT))
                {
                    scenario.targetScenes.Add(GameScenes.FLIGHT);
                }
                if (!scenario.targetScenes.Contains(GameScenes.EDITOR))
                {
                    scenario.targetScenes.Add(GameScenes.EDITOR);
                }
                if (!scenario.targetScenes.Contains(GameScenes.TRACKSTATION))
                {
                    scenario.targetScenes.Add(GameScenes.TRACKSTATION);
                }
            }
            //End code for persistence.sfs

            if (KCT_GUI.PrimarilyDisabled)
            {
                if (InputLockManager.GetControlLock("KCTLaunchLock") == ControlTypes.EDITOR_LAUNCH)
                {
                    InputLockManager.RemoveControlLock("KCTLaunchLock");
                }
            }

            KACWrapper.InitKACWrapper();

            if (!KCT_Events.instance.eventAdded)
            {
                KCT_Events.instance.addEvents();
            }

            if (!KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
            {
                if (InputLockManager.GetControlLock("KCTKSCLock") == ControlTypes.KSC_FACILITIES)
                {
                    InputLockManager.RemoveControlLock("KCTKSCLock");
                }
                return;
            }

            //Begin primary mod functions

            KCT_GameStates.UT = Planetarium.GetUniversalTime();

            /* List<GameScenes> validScenes = new List<GameScenes> { GameScenes.SPACECENTER, GameScenes.TRACKSTATION, GameScenes.EDITOR };
             * if (validScenes.Contains(HighLogic.LoadedScene) && System.IO.File.Exists(KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/KCT_simulation_backup.sfs"))
             * {
             *   KCT_Utilities.LoadSimulationSave();
             * }*/

            KCT_GUI.guiDataSaver.Load();
            if (!HighLogic.LoadedSceneIsFlight && KCT_GameStates.flightSimulated)
            {
                KCT_GameStates.reset();
            }

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (KCT_GUI.showSimulationCompleteEditor)
                {
                    KCT_GUI.hideAll();
                    KCT_GUI.showSimulationCompleteEditor = true;
                }
                else
                {
                    KCT_GUI.hideAll();
                }
                if (!KCT_GUI.PrimarilyDisabled)
                {
                    KCT_GUI.showEditorGUI = KCT_GameStates.showWindows[1];
                }
                if (KCT_GameStates.EditorShipEditingMode && KCT_GameStates.delayStart)
                {
                    KCT_GameStates.delayStart            = false;
                    EditorLogic.fetch.shipNameField.Text = KCT_GameStates.editedVessel.shipName;
                }
            }
            else if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                /* if (System.IO.File.Exists(KSPUtil.ApplicationRootPath + "saves/" + HighLogic.SaveFolder + "/KCT_simulation_backup.sfs"))
                 * {
                 *   KCT_Utilities.LoadSimulationSave();
                 * }*/
                KCT_GUI.hideAll();
                //       KCT_GameStates.ActiveKSC.SwitchLaunchPad(KCT_GameStates.ActiveKSC.ActiveLaunchPadID);
            }

            if (HighLogic.LoadedSceneIsFlight && !KCT_GameStates.flightSimulated && FlightGlobals.ActiveVessel.situation == Vessel.Situations.PRELAUNCH)
            {
                if (FlightGlobals.ActiveVessel.GetCrewCount() == 0 && KCT_GameStates.launchedCrew.Count > 0)
                {
                    KerbalRoster roster = HighLogic.CurrentGame.CrewRoster;

                    /*  foreach (CrewedPart c in KCT_GameStates.launchedCrew)
                     * {
                     *    KCTDebug.Log(c.partID);
                     * }*/

                    for (int i = 0; i < FlightGlobals.ActiveVessel.parts.Count; i++)
                    {
                        Part p = FlightGlobals.ActiveVessel.parts[i];
                        //KCTDebug.Log("craft: " + p.craftID);
                        {
                            CrewedPart cP = KCT_GameStates.launchedCrew.Find(part => part.partID == p.craftID);
                            if (cP == null)
                            {
                                continue;
                            }
                            List <ProtoCrewMember> crewList = cP.crewList;
                            foreach (ProtoCrewMember crewMember in crewList)
                            {
                                if (crewMember != null)
                                {
                                    ProtoCrewMember finalCrewMember = crewMember;
                                    if (crewMember.type == ProtoCrewMember.KerbalType.Crew)
                                    {
                                        finalCrewMember = roster.Crew.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    else if (crewMember.type == ProtoCrewMember.KerbalType.Tourist)
                                    {
                                        finalCrewMember = roster.Tourist.FirstOrDefault(c => c.name == crewMember.name);
                                    }
                                    if (finalCrewMember == null)
                                    {
                                        Debug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name + ". Cannot find Kerbal in list.");
                                        continue;
                                    }
                                    try
                                    {
                                        KCTDebug.Log("Assigning " + finalCrewMember.name + " to " + p.partInfo.name);
                                        if (p.AddCrewmember(finalCrewMember))//p.AddCrewmemberAt(finalCrewMember, crewList.IndexOf(crewMember)))
                                        {
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                                            if (finalCrewMember.seat != null)
                                            {
                                                finalCrewMember.seat.SpawnCrew();
                                            }
                                        }
                                        else
                                        {
                                            Debug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                            finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                            continue;
                                        }
                                    }
                                    catch
                                    {
                                        Debug.LogError("Error when assigning " + crewMember.name + " to " + p.partInfo.name);
                                        finalCrewMember.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                    KCT_GameStates.launchedCrew.Clear();
                }
            }
            KCT_GameStates.erroredDuringOnLoad.OnLoadStart();
        }