private void InitializeParts(Vessel vessel) { Log("TestFlightManager: Initializing parts for vessel " + vessel.GetName()); // Launch time is equal to current UT unless we have already chached this vessel's launch time double launchTime = Planetarium.GetUniversalTime(); if (knownVessels.ContainsKey(vessel.id)) { launchTime = knownVessels[vessel.id]; } foreach (Part part in vessel.parts) { ITestFlightCore core = TestFlightUtil.GetCore(part); if (core != null) { Log("TestFlightManager: Found core. Getting part data"); PartFlightData partData = tfScenario.GetFlightDataForPartName(TestFlightUtil.GetFullPartName(part)); if (partData == null) { Log("TestFlightManager: Unable to find part data. Starting fresh."); core.InitializeFlightData(null); } else { core.InitializeFlightData(partData.GetFlightData()); } } } }
internal void Log(string message) { PartModule pm = this.Module; if (pm == null) { return; } Part part = pm.part; if (part == null) { return; } string meType = "UNKNOWN"; if (EngineType == EngineModuleType.ENGINE) { meType = "ENGINE"; } if (EngineType == EngineModuleType.ENGINEFX) { meType = "ENGINEFX"; } if (EngineType == EngineModuleType.REALENGINE) { meType = "REALENGINE"; } message = String.Format("TestFlight_EngineModuleWrapper({0}[{1}]): {2}", TestFlightUtil.GetFullPartName(part), meType, message); TestFlightUtil.Log(message, part); }
internal void Log(string message) { bool debug = TestFlightManagerScenario.Instance.userSettings.debugLog; message = String.Format("TestFlightCore({0}[{1}]): {2}", TestFlightUtil.GetFullPartName(this.part), Configuration, message); TestFlightUtil.Log(message, debug); }
public void SetFlightTime(float flightTime) { if (TestFlightManagerScenario.Instance != null) { TestFlightManagerScenario.Instance.GetPartDataForPart(TestFlightUtil.GetFullPartName(this.part)).AddValue("flightTime", flightTime); } }
public float ModifyFlightTime(float flightTime, bool additive) { float newFlightTime = -1f; if (TestFlightManagerScenario.Instance != null) { newFlightTime = TestFlightManagerScenario.Instance.GetPartDataForPart(TestFlightUtil.GetFullPartName(this.part)).GetFloat("flightTime"); if (additive) { newFlightTime += flightTime; } else { newFlightTime *= flightTime; } TestFlightManagerScenario.Instance.GetPartDataForPart(TestFlightUtil.GetFullPartName(this.part)).AddValue("flightTime", newFlightTime); } return(newFlightTime); }
private void InitializeParts(Vessel vessel) { Log("TestFlightManager: Initializing parts for vessel " + vessel.GetName()); // Launch time is equal to current UT unless we have already cached this vessel's launch time double launchTime = Planetarium.GetUniversalTime(); if (knownVessels.ContainsKey(vessel.id)) { launchTime = knownVessels[vessel.id]; } foreach (Part part in vessel.parts) { ITestFlightCore core = TestFlightUtil.GetCore(part); if (core != null) { Log("TestFlightManager: Found core. Getting part data"); if (TestFlightManagerScenario.Instance.SettingsAlwaysMaxData) { core.InitializeFlightData(core.GetMaximumData()); } else { TestFlightPartData partData = tfScenario.GetPartDataForPart(TestFlightUtil.GetFullPartName(part)); if (partData != null) { core.InitializeFlightData(partData.GetFloat("flightData")); } else { core.InitializeFlightData(0f); } } } } }
internal void Log(string message) { message = String.Format("TestFlightFailure_ShutDownEngine({0}[{1}]): {2}", TestFlightUtil.GetFullPartName(this.part), Configuration, message); TestFlightUtil.Log(message, this.part); }
internal override void Update() { if (!isReady) { return; } if (masterStatus == null) { masterStatus = new Dictionary <Guid, MasterStatusItem>(); } currentUTC = Planetarium.GetUniversalTime(); // ensure out vessel list is up to date CacheVessels(); if (currentUTC >= lastMasterStatusUpdate + tfScenario.userSettings.masterStatusUpdateFrequency) { lastMasterStatusUpdate = currentUTC; VerifyMasterStatus(); } // process vessels foreach (var entry in knownVessels) { Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == entry.Key); if (vessel.loaded) { foreach (Part part in vessel.parts) { ITestFlightCore core = TestFlightUtil.GetCore(part); if (core != null) { // Poll for flight data and part status if (currentUTC >= lastDataPoll + tfScenario.userSettings.masterStatusUpdateFrequency) { TestFlightData currentFlightData = new TestFlightData(); currentFlightData.scope = core.GetScope(); currentFlightData.flightData = core.GetFlightData(); currentFlightData.flightTime = core.GetFlightTime(); PartStatus partStatus = new PartStatus(); partStatus.flightCore = core; partStatus.partName = TestFlightUtil.GetPartTitle(part); partStatus.partID = part.flightID; partStatus.flightData = currentFlightData.flightData; partStatus.flightTime = currentFlightData.flightTime; partStatus.partStatus = core.GetPartStatus(); partStatus.timeToRepair = core.GetRepairTime(); double failureRate = core.GetBaseFailureRate(); MomentaryFailureRate momentaryFailureRate = core.GetWorstMomentaryFailureRate(); if (momentaryFailureRate.valid && momentaryFailureRate.failureRate > failureRate) { failureRate = momentaryFailureRate.failureRate; } partStatus.momentaryFailureRate = failureRate; partStatus.repairRequirements = core.GetRequirementsTooltip(); partStatus.acknowledged = core.IsFailureAcknowledged(); partStatus.activeFailure = core.GetFailureModule(); partStatus.mtbfString = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999); // Update or Add part status in Master Status if (masterStatus.ContainsKey(vessel.id)) { // Vessel is already in the Master Status, so check if part is in there as well int numItems = masterStatus[vessel.id].allPartsStatus.Count(p => p.partID == part.flightID); int existingPartIndex; if (numItems == 1) { existingPartIndex = masterStatus[vessel.id].allPartsStatus.FindIndex(p => p.partID == part.flightID); masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus; } else if (numItems == 0) { masterStatus[vessel.id].allPartsStatus.Add(partStatus); } else { existingPartIndex = masterStatus[vessel.id].allPartsStatus.FindIndex(p => p.partID == part.flightID); masterStatus[vessel.id].allPartsStatus[existingPartIndex] = partStatus; Log("[ERROR] TestFlightManager: Found " + numItems + " matching parts in Master Status Display!"); } } else { // Vessel is not in the Master Status so create a new entry for it and add this part MasterStatusItem masterStatusItem = new MasterStatusItem(); masterStatusItem.vesselID = vessel.id; masterStatusItem.vesselName = vessel.GetName(); masterStatusItem.allPartsStatus = new List <PartStatus>(); masterStatusItem.allPartsStatus.Add(partStatus); masterStatus.Add(vessel.id, masterStatusItem); } PartFlightData data = tfScenario.GetFlightDataForPartName(TestFlightUtil.GetFullPartName(part)); if (data != null) { data.AddFlightData(part.name, currentFlightData); } else { data = new PartFlightData(); data.AddFlightData(TestFlightUtil.GetFullPartName(part), currentFlightData); tfScenario.SetFlightDataForPartName(TestFlightUtil.GetFullPartName(part), data); } } } } } if (currentUTC >= lastDataPoll + tfScenario.userSettings.minTimeBetweenDataPoll) { lastDataPoll = currentUTC; } if (currentUTC >= lastFailurePoll + tfScenario.userSettings.minTimeBetweenFailurePoll) { lastFailurePoll = currentUTC; } } }
internal override void DrawWindow(int id) { if (!isReady) { return; } if (SelectedPart == null) { GUILayout.BeginVertical(); GUILayout.Label("Select a part to display its details", Styles.styleEditorTitle); GUILayout.Label("MouseOver part in bin or 3D view to quickview", Styles.styleEditorText); GUILayout.Label("RightClick part in bin (not 3D) to toggle window lock on that part", Styles.styleEditorText); GUILayout.EndVertical(); if (DrawToggle(ref tfScenario.userSettings.editorWindowLocked, "Lock Window", Styles.styleToggle)) { if (tfScenario.userSettings.editorWindowLocked) { CalculateWindowBounds(); tfScenario.userSettings.editorWindowPosition = WindowRect; DragEnabled = false; } else { DragEnabled = true; } tfScenario.userSettings.Save(); } return; } ITestFlightCore core = null; GUILayout.BeginVertical(); GUILayout.Label(String.Format("Selected Part: {0}", TestFlightUtil.GetFullPartName(SelectedPart)), Styles.styleEditorTitle); tfScenario.userSettings.currentEditorScrollPosition = GUILayout.BeginScrollView(tfScenario.userSettings.currentEditorScrollPosition); TestFlightPartData partData = tfScenario.GetPartDataForPart(TestFlightUtil.GetFullPartName(SelectedPart)); if (partData != null) { float flightData = partData.GetFloat("flightData"); core = TestFlightUtil.GetCore(SelectedPart); if (core != null) { core.InitializeFlightData(flightData); GUILayout.BeginHorizontal(); double failureRate = core.GetBaseFailureRate(); String mtbfString = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999); // 10 characters for body max plus 10 characters for situation plus underscore = 21 characters needed for longest scope string GUILayout.Label(String.Format("{0,-7:F2}<b>du</b>", flightData), GUILayout.Width(75)); GUILayout.Label(String.Format("{0,-5:F2} MTBF", mtbfString), GUILayout.Width(125)); GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); if (DrawToggle(ref tfScenario.userSettings.editorWindowLocked, "Lock Window", Styles.styleToggle)) { if (tfScenario.userSettings.editorWindowLocked) { CalculateWindowBounds(); tfScenario.userSettings.editorWindowPosition = WindowRect; DragEnabled = false; } else { DragEnabled = true; } tfScenario.userSettings.Save(); } GUILayout.EndVertical(); }
internal override void Start() { GetComponent <UIButton>().AddInputDelegate(OnInput); selectedPart = GetComponent <EditorPartIcon>().partInfo; Log("TestFlightEditor: Added input delegate to " + TestFlightUtil.GetFullPartName(selectedPart.partPrefab)); }
internal override void DrawWindow(int id) { if (!isReady) { return; } if (SelectedPart == null) { GUILayout.BeginVertical(); GUILayout.Label("Select a part to display its details", Styles.styleEditorTitle); GUILayout.Label("MouseOver part in bin or 3D view to quickview", Styles.styleEditorText); GUILayout.Label("RightClick part in bin (not 3D) to toggle window lock on that part", Styles.styleEditorText); GUILayout.EndVertical(); if (DrawToggle(ref tfScenario.userSettings.editorWindowLocked, "Lock Window", Styles.styleToggle)) { if (tfScenario.userSettings.editorWindowLocked) { CalculateWindowBounds(); tfScenario.userSettings.editorWindowPosition = WindowRect; DragEnabled = false; } else { DragEnabled = true; } tfScenario.userSettings.Save(); } return; } ITestFlightCore core = null; GUILayout.BeginVertical(); GUILayout.Label(String.Format("Selected Part: {0}", TestFlightUtil.GetFullPartName(SelectedPart)), Styles.styleEditorTitle); tfScenario.userSettings.currentEditorScrollPosition = GUILayout.BeginScrollView(tfScenario.userSettings.currentEditorScrollPosition); PartFlightData partData = tfScenario.GetFlightDataForPartName(TestFlightUtil.GetFullPartName(SelectedPart)); if (partData != null) { string configuration; if (SelectedPart.Modules.Contains("ModuleEngineConfigs")) { configuration = (string)(SelectedPart.Modules["ModuleEngineConfigs"].GetType().GetField("configuration").GetValue(SelectedPart.Modules["ModuleEngineConfigs"])); } else { configuration = ""; } foreach (PartModule pm in SelectedPart.Modules) { core = pm as ITestFlightCore; if (core != null && core.Configuration == configuration) { break; } } if (core != null) { List <TestFlightData> flightData = partData.GetFlightData(); core.InitializeFlightData(flightData); foreach (TestFlightData data in flightData) { GUILayout.BeginHorizontal(); double failureRate = core.GetBaseFailureRateForScope(data.scope); String mtbfString = core.FailureRateToMTBFString(failureRate, TestFlightUtil.MTBFUnits.SECONDS, 999); // 10 characters for body max plus 10 characters for situation plus underscore = 21 characters needed for longest scope string GUILayout.Label(core.PrettyStringForScope(data.scope), GUILayout.Width(125)); GUILayout.Label(String.Format("{0,-7:F2}<b>du</b>", data.flightData), GUILayout.Width(75)); GUILayout.Label(String.Format("{0,-5:F2} MTBF", mtbfString), GUILayout.Width(125)); GUILayout.EndHorizontal(); } } } GUILayout.EndScrollView(); if (DrawToggle(ref tfScenario.userSettings.editorWindowLocked, "Lock Window", Styles.styleToggle)) { if (tfScenario.userSettings.editorWindowLocked) { CalculateWindowBounds(); tfScenario.userSettings.editorWindowPosition = WindowRect; DragEnabled = false; } else { DragEnabled = true; } tfScenario.userSettings.Save(); } GUILayout.EndVertical(); }
internal void CalculateWindowBounds() { if (appLauncherButton == null) { return; } if (tfScenario == null) { return; } float windowWidth = 350f; float left = Screen.width - windowWidth - 75f; float windowHeight = 50f; float numItems = 0; ITestFlightCore core = GetCore(); if (core != null) { List <TestFlightData> flightData = null; PartFlightData partData = tfScenario.GetFlightDataForPartName(TestFlightUtil.GetFullPartName(SelectedPart)); if (partData == null) { numItems = 0; } else { flightData = partData.GetFlightData(); if (flightData != null) { numItems = flightData.Count; } } } windowHeight += numItems * 20f; float top = Screen.height - windowHeight - 60f; if (!tfScenario.userSettings.editorWindowLocked) { left = tfScenario.userSettings.editorWindowPosition.xMin; top = tfScenario.userSettings.editorWindowPosition.yMin; } WindowRect = new Rect(left, top, windowWidth, windowHeight); }
public float GetFlightTime() { if (TestFlightManagerScenario.Instance != null) { TestFlightPartData partData = TestFlightManagerScenario.Instance.GetPartDataForPart(TestFlightUtil.GetFullPartName(this.part)); return(partData.GetFloat("flightTime")); } else { return(0f); } }