public static void PopUpVesselError(List <KCT_BuildListVessel> errored) { DialogGUIBase[] options = new DialogGUIBase[2]; options[0] = new DialogGUIButton("Understood", () => { }); // new DialogGUIBase("Understood", () => { }); //do nothing and close the window options[1] = new DialogGUIButton("Delete Vessels", () => { foreach (KCT_BuildListVessel blv in errored) { blv.RemoveFromBuildList(); KCT_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 (KCT_BuildListVessel blv in errored) { txt += blv.shipName + "\n"; txtToWrite += blv.shipName + "\n"; txtToWrite += String.Join("\n", blv.MissingParts().ToArray()); txtToWrite += "\n\n"; } //HighLogic.SaveFolder //make new file for missing ships string filename = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/missingParts.txt"; System.IO.File.WriteAllText(filename, txtToWrite); //remove all rollout and recon items since they're invalid without the ships foreach (KCT_BuildListVessel blv in errored) { //remove any associated recon_rollout foreach (KCT_KSC ksc in KCT_GameStates.KSCs) { for (int i = 0; i < ksc.Recon_Rollout.Count; i++) { KCT_Recon_Rollout 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++) { KCT_AirlaunchPrep ap = ksc.AirlaunchPrep[i]; if (ap.associatedID == blv.id.ToString()) { ksc.AirlaunchPrep.Remove(ap); i--; } } } } MultiOptionDialog 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); //PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Vessel Contains Missing Parts", "The KCT vessel " + errored.shipName + " contains missing or invalid parts. You will not be able to do anything with the vessel until the parts are available again.", "Understood", false, HighLogic.UISkin); }
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()); }
public static void DelayedStart() { if (KCT_Utilities.CurrentGameIsMission()) { return; } KCTDebug.Log("DelayedStart start"); if (KCT_PresetManager.Instance?.ActivePreset == null || !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled) { return; } if (KCT_GUI.PrimarilyDisabled) { return; } //The following should only be executed when fully enabled for the save if (KCT_GameStates.ActiveKSC == null) { KCT_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 (!KCT_GameStates.vesselErrorAlerted) { List <KCT_BuildListVessel> erroredVessels = new List <KCT_BuildListVessel>(); foreach (KCT_KSC KSC in KCT_GameStates.KSCs) //this is faster on subsequent scene changes { foreach (KCT_BuildListVessel blv in KSC.VABList) { if (!blv.allPartsValid) { //error! KCTDebug.Log(blv.shipName + " contains invalid parts!"); erroredVessels.Add(blv); } } foreach (KCT_BuildListVessel blv in KSC.VABWarehouse) { if (!blv.allPartsValid) { //error! KCTDebug.Log(blv.shipName + " contains invalid parts!"); erroredVessels.Add(blv); } } foreach (KCT_BuildListVessel blv in KSC.SPHList) { if (!blv.allPartsValid) { //error! KCTDebug.Log(blv.shipName + " contains invalid parts!"); erroredVessels.Add(blv); } } foreach (KCT_BuildListVessel blv in KSC.SPHWarehouse) { if (!blv.allPartsValid) { //error! KCTDebug.Log(blv.shipName + " contains invalid parts!"); erroredVessels.Add(blv); } } } if (erroredVessels.Count > 0) { PopUpVesselError(erroredVessels); } KCT_GameStates.vesselErrorAlerted = true; } if (HighLogic.LoadedSceneIsEditor) { if (KCT_GameStates.EditorShipEditingMode) { KCTDebug.Log("Editing " + KCT_GameStates.editedVessel.shipName); EditorLogic.fetch.shipNameField.text = KCT_GameStates.editedVessel.shipName; } } if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { KCTDebug.Log("SP Start"); if (!KCT_GUI.PrimarilyDisabled) { if (ToolbarManager.ToolbarAvailable && KCT_GameStates.settings.PreferBlizzyToolbar) { if (KCT_GameStates.showWindows[0]) { KCT_GUI.ClickOn(); } else { //if (KCT_Events.instance != null && KCT_Events.instance.KCTButtonStock != null) if (KCT_Events.instance != null && KCT_GameStates.toolbarControl != null) { if (KCT_GameStates.showWindows[0]) { KCT_GUI.ClickOn(); } } } } KCT_GUI.ResetBLWindow(); } else { KCT_GUI.showBuildList = false; KCT_GameStates.showWindows[0] = false; } KCTDebug.Log("SP UI done"); if (KCT_GameStates.firstStart) { KCTDebug.Log("Showing first start."); KCT_GameStates.firstStart = false; KCT_GUI.showFirstRun = true; //initialize the proper launchpad KCT_GameStates.ActiveKSC.ActiveLPInstance.level = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.LaunchPad); } KCTDebug.Log("SP switch starting"); KCT_GameStates.ActiveKSC.SwitchLaunchPad(KCT_GameStates.ActiveKSC.ActiveLaunchPadID); KCTDebug.Log("SP switch done"); foreach (KCT_KSC ksc in KCT_GameStates.KSCs) { for (int i = 0; i < ksc.Recon_Rollout.Count; i++) { KCT_Recon_Rollout rr = ksc.Recon_Rollout[i]; if (rr.RRType != KCT_Recon_Rollout.RolloutReconType.Reconditioning && KCT_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++) { KCT_AirlaunchPrep ap = ksc.AirlaunchPrep[i]; if (KCT_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"); }
public KCT_KSC FromConfigNode(ConfigNode node) { VABUpgrades.Clear(); SPHUpgrades.Clear(); RDUpgrades.Clear(); VABList.Clear(); VABWarehouse.Clear(); SPHList.Clear(); SPHWarehouse.Clear(); VABPlans.Clear(); SPHPlans.Clear(); KSCTech.Clear(); //TechList.Clear(); Recon_Rollout.Clear(); AirlaunchPrep.Clear(); VABRates.Clear(); SPHRates.Clear(); this.KSCName = node.GetValue("KSCName"); if (!int.TryParse(node.GetValue("ActiveLPID"), out this.ActiveLaunchPadID)) { this.ActiveLaunchPadID = 0; } ConfigNode vabup = node.GetNode("VABUpgrades"); foreach (string upgrade in vabup.GetValues("Upgrade")) { this.VABUpgrades.Add(int.Parse(upgrade)); } ConfigNode sphup = node.GetNode("SPHUpgrades"); foreach (string upgrade in sphup.GetValues("Upgrade")) { this.SPHUpgrades.Add(int.Parse(upgrade)); } ConfigNode rdup = node.GetNode("RDUpgrades"); foreach (string upgrade in rdup.GetValues("Upgrade")) { this.RDUpgrades.Add(int.Parse(upgrade)); } ConfigNode tmp = node.GetNode("VABList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABList.Add(blv); } tmp = node.GetNode("SPHList"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHList.Add(blv); } tmp = node.GetNode("VABWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.VABWarehouse.Add(blv); } tmp = node.GetNode("SPHWarehouse"); foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHWarehouse.Add(blv); } if (node.TryGetNode("VABPlans", ref tmp)) { if (tmp.HasNode("KCTVessel")) { foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; if (this.VABPlans.ContainsKey(blv.shipName)) { this.VABPlans.Remove(blv.shipName); } this.VABPlans.Add(blv.shipName, blv); } } } if (node.TryGetNode("SPHPlans", ref tmp)) { if (tmp.HasNode("KCTVessel")) { foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel")) { KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); KCT_BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; if (this.SPHPlans.ContainsKey(blv.shipName)) { this.SPHPlans.Remove(blv.shipName); } this.SPHPlans.Add(blv.shipName, blv); } } } tmp = node.GetNode("Recon_Rollout"); foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item")) { KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout(); ConfigNode.LoadObjectFromConfig(tempRR, RRCN); Recon_Rollout.Add(tempRR); } if (node.TryGetNode("Airlaunch_Prep", ref tmp)) { foreach (ConfigNode APCN in tmp.GetNodes("Airlaunch_Prep_Item")) { KCT_AirlaunchPrep temp = new KCT_AirlaunchPrep(); ConfigNode.LoadObjectFromConfig(temp, APCN); AirlaunchPrep.Add(temp); } } if (node.HasNode("KSCTech")) { tmp = node.GetNode("KSCTech"); foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding")) { KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding(); tempUP.Load(upBuild); KSCTech.Add(tempUP); } } if (node.HasNode("LaunchPads")) { LaunchPads.Clear(); tmp = node.GetNode("LaunchPads"); foreach (ConfigNode LP in tmp.GetNodes("KCT_LaunchPad")) { KCT_LaunchPad tempLP = new KCT_LaunchPad("LP0"); ConfigNode.LoadObjectFromConfig(tempLP, LP); tempLP.DestructionNode = LP.GetNode("DestructionState"); LaunchPads.Add(tempLP); } } if (node.HasNode("VABRateCache")) { foreach (string rate in node.GetNode("VABRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { VABRates.Add(r); } } } if (node.HasNode("SPHRateCache")) { foreach (string rate in node.GetNode("SPHRateCache").GetValues("rate")) { double r; if (double.TryParse(rate, out r)) { SPHRates.Add(r); } } } return(this); }