public static void PopUpVesselError(List <BuildListVessel> errored) { DialogGUIBase[] options = new DialogGUIBase[2]; options[0] = new DialogGUIButton("Understood", () => { }); options[1] = new DialogGUIButton("Delete Vessels", () => { foreach (BuildListVessel blv in errored) { blv.RemoveFromBuildList(); Utilities.AddFunds(blv.GetTotalCost(), TransactionReasons.VesselRollout); //remove any associated recon_rollout } }); string txt = "The following KCT vessels contain missing or invalid parts and have been quarantined. Either add the missing parts back into your game or delete the vessels. A file containing the ship names and missing parts has been added to your save folder.\n"; string txtToWrite = ""; foreach (BuildListVessel blv in errored) { txt += blv.ShipName + "\n"; txtToWrite += blv.ShipName + "\n"; txtToWrite += string.Join("\n", blv.GetMissingParts()); txtToWrite += "\n\n"; } //make new file for missing ships string filename = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/missingParts.txt"; File.WriteAllText(filename, txtToWrite); //remove all rollout and recon items since they're invalid without the ships foreach (BuildListVessel blv in errored) { //remove any associated recon_rollout foreach (KSCItem ksc in KCTGameStates.KSCs) { for (int i = 0; i < ksc.Recon_Rollout.Count; i++) { ReconRollout rr = ksc.Recon_Rollout[i]; if (rr.AssociatedID == blv.Id.ToString()) { ksc.Recon_Rollout.Remove(rr); i--; } } for (int i = 0; i < ksc.AirlaunchPrep.Count; i++) { AirlaunchPrep ap = ksc.AirlaunchPrep[i]; if (ap.AssociatedID == blv.Id.ToString()) { ksc.AirlaunchPrep.Remove(ap); i--; } } } } var diag = new MultiOptionDialog("missingPartsPopup", txt, "Vessels Contain Missing Parts", null, options); PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), diag, false, HighLogic.UISkin); }
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 DelayedStart() { if (Utilities.CurrentGameIsMission()) { return; } KCTDebug.Log("DelayedStart start"); if (PresetManager.Instance?.ActivePreset == null || !PresetManager.Instance.ActivePreset.GeneralSettings.Enabled) { return; } if (KCT_GUI.IsPrimarilyDisabled) { return; } //The following should only be executed when fully enabled for the save if (KCTGameStates.ActiveKSC == null) { Utilities.SetActiveKSCToRSS(); } KCTDebug.Log("Checking vessels for missing parts."); //check that all parts are valid in all ships. If not, warn the user and disable that vessel (once that code is written) if (!KCTGameStates.VesselErrorAlerted) { var erroredVessels = new List <BuildListVessel>(); foreach (KSCItem KSC in KCTGameStates.KSCs) //this is faster on subsequent scene changes { foreach (BuildListVessel blv in KSC.VABList) { if (!blv.AllPartsValid) { KCTDebug.Log(blv.ShipName + " contains invalid parts!"); erroredVessels.Add(blv); } } foreach (BuildListVessel blv in KSC.VABWarehouse) { if (!blv.AllPartsValid) { KCTDebug.Log(blv.ShipName + " contains invalid parts!"); erroredVessels.Add(blv); } } foreach (BuildListVessel blv in KSC.SPHList) { if (!blv.AllPartsValid) { KCTDebug.Log(blv.ShipName + " contains invalid parts!"); erroredVessels.Add(blv); } } foreach (BuildListVessel blv in KSC.SPHWarehouse) { if (!blv.AllPartsValid) { KCTDebug.Log(blv.ShipName + " contains invalid parts!"); erroredVessels.Add(blv); } } } if (erroredVessels.Count > 0) { PopUpVesselError(erroredVessels); } KCTGameStates.VesselErrorAlerted = true; } if (HighLogic.LoadedSceneIsEditor && KCTGameStates.EditorShipEditingMode) { KCTDebug.Log($"Editing {KCTGameStates.EditedVessel.ShipName}"); EditorLogic.fetch.shipNameField.text = KCTGameStates.EditedVessel.ShipName; } if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { KCTDebug.Log("SP Start"); if (!KCT_GUI.IsPrimarilyDisabled) { if (ToolbarManager.ToolbarAvailable && KCTGameStates.Settings.PreferBlizzyToolbar) { if (KCTGameStates.ShowWindows[0]) { KCT_GUI.ToggleVisibility(true); } else { if (KCTEvents.Instance != null && KCTGameStates.ToolbarControl != null) { if (KCTGameStates.ShowWindows[0]) { KCT_GUI.ToggleVisibility(true); } } } } KCT_GUI.ResetBLWindow(); } else { KCT_GUI.GUIStates.ShowBuildList = false; KCTGameStates.ShowWindows[0] = false; } KCTDebug.Log("SP UI done"); if (KCTGameStates.IsFirstStart) { KCTDebug.Log("Showing first start."); KCTGameStates.IsFirstStart = false; KCT_GUI.GUIStates.ShowFirstRun = true; //initialize the proper launchpad KCTGameStates.ActiveKSC.ActiveLPInstance.level = Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.LaunchPad); } KCTDebug.Log("SP switch starting"); KCTGameStates.ActiveKSC.SwitchLaunchPad(KCTGameStates.ActiveKSC.ActiveLaunchPadID); KCTDebug.Log("SP switch done"); foreach (KSCItem ksc in KCTGameStates.KSCs) { for (int i = 0; i < ksc.Recon_Rollout.Count; i++) { ReconRollout rr = ksc.Recon_Rollout[i]; if (rr.RRType != ReconRollout.RolloutReconType.Reconditioning && Utilities.FindBLVesselByID(new Guid(rr.AssociatedID)) == null) { KCTDebug.Log($"Invalid Recon_Rollout at {ksc.KSCName}. ID {rr.AssociatedID} not found."); ksc.Recon_Rollout.Remove(rr); i--; } } for (int i = 0; i < ksc.AirlaunchPrep.Count; i++) { AirlaunchPrep ap = ksc.AirlaunchPrep[i]; if (Utilities.FindBLVesselByID(new Guid(ap.AssociatedID)) == null) { KCTDebug.Log($"Invalid KCT_AirlaunchPrep at {ksc.KSCName}. ID {ap.AssociatedID} not found."); ksc.AirlaunchPrep.Remove(ap); i--; } } } KCTDebug.Log("SP done"); } if (HighLogic.LoadedSceneIsFlight && KCTGameStates.IsSimulatedFlight) { Utilities.EnableSimulationLocks(); if (KCTGameStates.SimulationParams.SimulationUT > 0 && FlightDriver.CanRevertToPrelaunch) // Used for checking whether the player has saved and then loaded back into that save { KCTDebug.Log($"Setting simulation UT to {KCTGameStates.SimulationParams.SimulationUT}"); Planetarium.SetUniversalTime(KCTGameStates.SimulationParams.SimulationUT); } AddSimulationWatermark(); } if (KCTGameStates.IsSimulatedFlight && HighLogic.LoadedSceneIsGame && !HighLogic.LoadedSceneIsFlight) { string msg = "Current save appears to be a simulation with no way to automatically revert to the pre-simulation state. An older save needs to be loaded manually now."; PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "errorPopup", "KCT Simulation error", msg, "Understood", false, HighLogic.UISkin); } KCTDebug.Log("DelayedStart finished"); }
public static void DelayedStart() { if (Utilities.CurrentGameIsMission()) { return; } KCTDebug.Log("DelayedStart start"); if (PresetManager.Instance?.ActivePreset == null || !PresetManager.Instance.ActivePreset.GeneralSettings.Enabled) { return; } if (KCT_GUI.IsPrimarilyDisabled) { return; } //The following should only be executed when fully enabled for the save if (KCTGameStates.ActiveKSC == null) { Utilities.SetActiveKSCToRSS(); } KCTDebug.Log("Checking vessels for missing parts."); //check that all parts are valid in all ships. If not, warn the user and disable that vessel (once that code is written) if (!KCTGameStates.VesselErrorAlerted) { var erroredVessels = new List <BuildListVessel>(); foreach (KSCItem KSC in KCTGameStates.KSCs) //this is faster on subsequent scene changes { foreach (BuildListVessel blv in KSC.VABList) { if (!blv.AllPartsValid) { KCTDebug.Log(blv.ShipName + " contains invalid parts!"); erroredVessels.Add(blv); } } foreach (BuildListVessel blv in KSC.VABWarehouse) { if (!blv.AllPartsValid) { KCTDebug.Log(blv.ShipName + " contains invalid parts!"); erroredVessels.Add(blv); } } foreach (BuildListVessel blv in KSC.SPHList) { if (!blv.AllPartsValid) { KCTDebug.Log(blv.ShipName + " contains invalid parts!"); erroredVessels.Add(blv); } } foreach (BuildListVessel blv in KSC.SPHWarehouse) { if (!blv.AllPartsValid) { KCTDebug.Log(blv.ShipName + " contains invalid parts!"); erroredVessels.Add(blv); } } } if (erroredVessels.Count > 0) { PopUpVesselError(erroredVessels); } KCTGameStates.VesselErrorAlerted = true; } if (HighLogic.LoadedSceneIsEditor && KCTGameStates.EditorShipEditingMode) { KCTDebug.Log($"Editing {KCTGameStates.EditedVessel.ShipName}"); EditorLogic.fetch.shipNameField.text = KCTGameStates.EditedVessel.ShipName; } if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { KCTDebug.Log("SP Start"); if (!KCT_GUI.IsPrimarilyDisabled) { if (ToolbarManager.ToolbarAvailable && KCTGameStates.Settings.PreferBlizzyToolbar) { if (KCTGameStates.ShowWindows[0]) { KCT_GUI.ToggleVisibility(true); } else { if (KCTEvents.Instance != null && KCTGameStates.ToolbarControl != null) { if (KCTGameStates.ShowWindows[0]) { KCT_GUI.ToggleVisibility(true); } } } } KCT_GUI.ResetBLWindow(); } else { KCT_GUI.GUIStates.ShowBuildList = false; KCTGameStates.ShowWindows[0] = false; } KCTDebug.Log("SP UI done"); if (KCTGameStates.IsFirstStart) { KCTDebug.Log("Showing first start."); KCTGameStates.IsFirstStart = false; KCT_GUI.GUIStates.ShowFirstRun = true; //initialize the proper launchpad KCTGameStates.ActiveKSC.ActiveLPInstance.level = Utilities.GetBuildingUpgradeLevel(SpaceCenterFacility.LaunchPad); } KCTDebug.Log("SP switch starting"); KCTGameStates.ActiveKSC.SwitchLaunchPad(KCTGameStates.ActiveKSC.ActiveLaunchPadID); KCTDebug.Log("SP switch done"); foreach (KSCItem ksc in KCTGameStates.KSCs) { for (int i = 0; i < ksc.Recon_Rollout.Count; i++) { ReconRollout rr = ksc.Recon_Rollout[i]; if (rr.RRType != ReconRollout.RolloutReconType.Reconditioning && Utilities.FindBLVesselByID(new Guid(rr.AssociatedID)) == null) { KCTDebug.Log($"Invalid Recon_Rollout at {ksc.KSCName}. ID {rr.AssociatedID} not found."); ksc.Recon_Rollout.Remove(rr); i--; } } for (int i = 0; i < ksc.AirlaunchPrep.Count; i++) { AirlaunchPrep ap = ksc.AirlaunchPrep[i]; if (Utilities.FindBLVesselByID(new Guid(ap.AssociatedID)) == null) { KCTDebug.Log($"Invalid KCT_AirlaunchPrep at {ksc.KSCName}. ID {ap.AssociatedID} not found."); ksc.AirlaunchPrep.Remove(ap); i--; } } } KCTDebug.Log("SP done"); } KCTDebug.Log("DelayedStart finished"); }