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()); }
public void Start() { KCTDebug.Log("Start called"); _wfsOne = new WaitForSeconds(1f); _wfsTwo = new WaitForSeconds(2f); _wfsHalf = new WaitForSeconds(0.5f); KCT_GUI.InitTooltips(); 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 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 { KCT_GUI.ToggleVisibility(KCT_GUI.GUIStates.ShowEditorGUI); } } break; case GameScenes.SPACECENTER: bool shouldStart = KCT_GUI.GUIStates.ShowFirstRun; KCT_GUI.HideAll(); KCTGameStates.ClearVesselEditMode(); if (!shouldStart) { KCT_GUI.GUIStates.ShowBuildList = KCTGameStates.ShowWindows[0]; KCT_GUI.ToggleVisibility(KCT_GUI.GUIStates.ShowBuildList); } KCT_GUI.GUIStates.ShowFirstRun = shouldStart; StartCoroutine(UpdateActiveLPLevel()); StartCoroutine(UpdateBuildRates()); break; case GameScenes.TRACKSTATION: KCTGameStates.ClearVesselEditMode(); break; case GameScenes.FLIGHT: KCT_GUI.HideAll(); ProcessFlightStart(); break; } KCTDebug.Log("Start finished"); DelayedStart(); UpdateTechlistIconColor(); StartCoroutine(HandleEditorButton_Coroutine()); }