public static void PopUpVesselError(List <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 (BuildListVessel blv in errored) { blv.RemoveFromBuildList(); KCT_Utilities.AddFunds(blv.cost, 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.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 (BuildListVessel blv in errored) { //remove any associated recon_rollout foreach (SpaceCenterConstruction ksc in GameStates.KSCs) { for (int i = 0; i < ksc.Recon_Rollout.Count; i++) { Recon_Rollout rr = ksc.Recon_Rollout[i]; if (rr.associatedID == blv.id.ToString()) { ksc.Recon_Rollout.Remove(rr); 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() { 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(); } }
public static void DelayedStart() { const string logBlockName = nameof(KerbalConstructionTime) + "." + nameof(DelayedStart); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { if (KCT_Utilities.CurrentGameIsMission()) { return; } Log.Trace("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 (GameStates.ActiveKSC == null) { KCT_Utilities.SetActiveKSCToRSS(); } CheckVesselsForMissingParts(); if (HighLogic.LoadedSceneIsEditor) { if (GameStates.EditorShipEditingMode) { Log.Trace("Editing " + GameStates.editedVessel.shipName); EditorLogic.fetch.shipNameField.text = GameStates.editedVessel.shipName; } } if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { Log.Trace("SP Start"); if (!KCT_GUI.PrimarilyDisabled) { if (ToolbarManager.ToolbarAvailable && GameStates.settings.PreferBlizzyToolbar) { if (GameStates.showWindows[0]) { KCT_GUI.ClickOn(); } else { if (KCTEvents.instance != null && KCTEvents.instance.KCTButtonStock != null) { if (GameStates.showWindows[0]) { KCT_GUI.ClickOn(); } } } } KCT_GUI.ResetBLWindow(); } else { KCT_GUI.showBuildList = false; GameStates.showWindows[0] = false; } Log.Trace("SP UI done"); if (GameStates.firstStart) { Log.Trace("Showing first start."); GameStates.firstStart = false; KCT_GUI.showFirstRun = true; //initialize the proper launchpad GameStates.ActiveKSC.ActiveLPInstance.level = KCT_Utilities.BuildingUpgradeLevel(SpaceCenterFacility.LaunchPad); } Log.Trace("SP switch starting"); GameStates.ActiveKSC.SwitchLaunchPad(GameStates.ActiveKSC.ActiveLaunchPadID); Log.Trace("SP switch done"); foreach (SpaceCenterConstruction ksc in GameStates.KSCs) { //foreach (KCT_Recon_Rollout rr in ksc.Recon_Rollout) for (int i = 0; i < ksc.Recon_Rollout.Count; i++) { Recon_Rollout rr = ksc.Recon_Rollout[i]; if (rr.RRType != Recon_Rollout.RolloutReconType.Reconditioning && KCT_Utilities.FindBLVesselByID(new Guid(rr.associatedID)) == null) { Log.Trace("Invalid Recon_Rollout at " + ksc.KSCName + ". ID " + rr.associatedID + " not found."); ksc.Recon_Rollout.Remove(rr); i--; } } } Log.Trace("SP done"); } } }
public SpaceCenterConstruction FromConfigNode(ConfigNode node) { const string logBlockName = nameof(SpaceCenterConstruction) + "." + nameof(AsConfigNode); using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All)) { VABUpgrades.Clear(); SPHUpgrades.Clear(); RDUpgrades.Clear(); VABList.Clear(); VABWarehouse.Clear(); SPHList.Clear(); SPHWarehouse.Clear(); KSCTech.Clear(); //TechList.Clear(); Recon_Rollout.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")) { BuildListStorage.BuildListItem listItem = new BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); 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")) { BuildListStorage.BuildListItem listItem = new BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); 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")) { BuildListStorage.BuildListItem listItem = new BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); 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")) { BuildListStorage.BuildListItem listItem = new BuildListStorage.BuildListItem(); ConfigNode.LoadObjectFromConfig(listItem, vessel); BuildListVessel blv = listItem.ToBuildListVessel(); blv.shipNode = vessel.GetNode("ShipNode"); blv.KSC = this; this.SPHWarehouse.Add(blv); } /* tmp = node.GetNode("TechList"); * foreach (ConfigNode techNode in tmp.GetNodes("Tech")) * { * KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem(); * ConfigNode.LoadObjectFromConfig(techStorageItem, techNode); * KCT_TechItem techItem = techStorageItem.ToTechItem(); * techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode")); * this.TechList.Add(techItem); * }*/ tmp = node.GetNode("Recon_Rollout"); foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item")) { Recon_Rollout tempRR = new Recon_Rollout(); ConfigNode.LoadObjectFromConfig(tempRR, RRCN); Recon_Rollout.Add(tempRR); } if (node.HasNode("KSCTech")) { tmp = node.GetNode("KSCTech"); foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding")) { UpgradingBuilding tempUP = new UpgradingBuilding(); ConfigNode.LoadObjectFromConfig(tempUP, upBuild); KSCTech.Add(tempUP); } } if (node.HasNode("LaunchPads")) { LaunchPads.Clear(); tmp = node.GetNode("LaunchPads"); foreach (ConfigNode LP in tmp.GetNodes("KCT_LaunchPad")) { LaunchPad tempLP = new 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); } }