private void InitializeParts(Vessel vessel) { foreach (Part part in vessel.parts) { // Each KSP part can be composed of N virtual parts List <string> cores = TestFlightInterface.GetActiveCores(part); if (cores == null || cores.Count <= 0) { continue; } foreach (string activeCore in cores) { ITestFlightCore core = TestFlightUtil.GetCore(part, activeCore); if (core != null) { if (TestFlightManagerScenario.Instance.SettingsAlwaysMaxData) { core.InitializeFlightData(core.GetMaximumData()); } else { TestFlightPartData partData = tfScenario.GetPartDataForPart(activeCore); if (partData != null) { core.InitializeFlightData(partData.GetFloat("flightData")); } else { core.InitializeFlightData(0f); } } } } } }
public float GetFlightTime() { if (TestFlightManagerScenario.Instance != null) { TestFlightPartData partData = TestFlightManagerScenario.Instance.GetPartDataForPart(Alias); return(partData.GetFloat("flightTime")); } else { return(0f); } }
public void OnTreeSpawn(RDController controller) { if (TestFlightManagerScenario.Instance == null || controller.nodes == null) { return; } List <RDNode> nodes = controller.nodes; if (this.baseCost == null) { baseCost = new Dictionary <string, int>(); for (int i = 0; i < nodes.Count; i++) { RDNode node = nodes[i]; if (node != null && node.tech != null) { baseCost.Add(nodes[i].tech.techID, nodes[i].tech.scienceCost); } } } for (int n = 0; n < nodes.Count; n++) { RDNode node = nodes[n]; if (node != null && node.tech != null && !node.IsResearched && node.tech.partsAssigned != null) { float discount = 0f; List <AvailablePart> parts = node.tech.partsAssigned; for (int p = 0; p < parts.Count; p++) { if (parts[p] != null) { Part prefab = parts[p].partPrefab; TestFlightPartData partData = TestFlightManagerScenario.Instance.GetPartDataForPart(parts[p].name); if (partData != null && prefab != null) { TestFlightCore core = (TestFlightCore)prefab.Modules.OfType <TestFlightCore>().FirstOrDefault(); float flightData = partData.GetFloat("flightData"); if (core != null && flightData > core.startFlightData) { discount += (int)(((flightData - core.startFlightData) / (core.maxData - core.startFlightData)) * core.scienceDataValue); } } } } if (discount > 0) { node.tech.scienceCost = (int)Math.Max(0, baseCost[node.tech.techID] - discount); } } } }
private void InitializeParts(Vessel vessel) { if (!tfScenario.SettingsEnabled) { return; } // 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) { // Each KSP part can be composed of N virtual parts List <string> cores = TestFlightInterface.GetActiveCores(part); if (cores == null || cores.Count <= 0) { continue; } foreach (string activeCore in cores) { ITestFlightCore core = TestFlightUtil.GetCore(part, activeCore); if (core != null) { Log("TestFlightManager: Found core. Getting part data"); if (TestFlightManagerScenario.Instance.SettingsAlwaysMaxData) { core.InitializeFlightData(core.GetMaximumData()); } else { TestFlightPartData partData = tfScenario.GetPartDataForPart(activeCore); if (partData != null) { core.InitializeFlightData(partData.GetFloat("flightData")); } else { core.InitializeFlightData(0f); } } } } } }
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 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(); }