예제 #1
0
        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());
                    }
                }
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
            if (userSettings != null)
            {
                userSettings.Load();
            }
            if (bodySettings != null)
            {
                bodySettings.Load();
            }

            InitDataStore();
            if (node.HasValue("saveData"))
            {
                rawSaveData = node.GetValue("saveData");
            }
            else
            {
                rawSaveData = "";
            }
            decodeRawSaveData();

            if (partData == null)
            {
                partData = new Dictionary <String, TestFlightPartData>();
            }
            else
            {
                partData.Clear();
            }
            // TODO: This old method of storing scope specific data is deprecated and needs to be removed in the next major release (Probably 1.4)
            if (node.HasNode("FLIGHTDATA_PART"))
            {
                foreach (ConfigNode partNode in node.GetNodes("FLIGHTDATA_PART"))
                {
                    PartFlightData partFlightData = new PartFlightData();
                    partFlightData.Load(partNode);

                    // migrates old data into new noscope layout
                    TestFlightPartData storedPartData = new TestFlightPartData();
                    storedPartData.PartName = partFlightData.GetPartName();
                    // Add up all the data and time from the old system for each scope, and then save that as the new migrated vales
                    double totalData = 0;
                    double totalTime = 0;
                    List <TestFlightData> allData = partFlightData.GetFlightData();
                    foreach (TestFlightData data in allData)
                    {
                        totalData += data.flightData;
                        totalTime += data.flightTime;
                    }
                    storedPartData.SetValue("flightData", totalData.ToString());
                    storedPartData.SetValue("flightTime", totalTime.ToString());
                    partData.Add(storedPartData.PartName, storedPartData);
                }
            }
            // new noscope
            if (node.HasNode("partData"))
            {
                foreach (ConfigNode partDataNode in node.GetNodes("partData"))
                {
                    TestFlightPartData storedPartData = new TestFlightPartData();
                    storedPartData.Load(partDataNode);
                    partData.Add(storedPartData.PartName, storedPartData);
                }
            }
        }
예제 #4
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);
            if (userSettings != null)
            {
                userSettings.Load();
            }
            if (bodySettings != null)
                bodySettings.Load();

            InitDataStore();
            if (node.HasValue("saveData"))
                rawSaveData = node.GetValue("saveData");
            else
                rawSaveData = "";
            decodeRawSaveData();

            if (partData == null)
                partData = new Dictionary<String, TestFlightPartData>();
            else
                partData.Clear();
            // TODO: This old method of storing scope specific data is deprecated and needs to be removed in the next major release (Probably 1.4)
            if (node.HasNode("FLIGHTDATA_PART"))
            {
                foreach (ConfigNode partNode in node.GetNodes("FLIGHTDATA_PART"))
                {
                    PartFlightData partFlightData = new PartFlightData();
                    partFlightData.Load(partNode);

                    // migrates old data into new noscope layout
                    TestFlightPartData storedPartData = new TestFlightPartData();
                    storedPartData.PartName = partFlightData.GetPartName();
                    // Add up all the data and time from the old system for each scope, and then save that as the new migrated vales
                    double totalData = 0;
                    double totalTime = 0;
                    List<TestFlightData> allData = partFlightData.GetFlightData();
                    foreach (TestFlightData data in allData)
                    {
                        totalData += data.flightData;
                        totalTime += data.flightTime;
                    }
                    storedPartData.SetValue("flightData", totalData.ToString());
                    storedPartData.SetValue("flightTime", totalTime.ToString());
                    partData.Add(storedPartData.PartName, storedPartData);
                }
            }
            // new noscope
            if (node.HasNode("partData"))
            {
                foreach (ConfigNode partDataNode in node.GetNodes("partData"))
                {
                    TestFlightPartData storedPartData = new TestFlightPartData();
                    storedPartData.Load(partDataNode);
                    partData.Add(storedPartData.PartName, storedPartData);
                }
            }
        }
예제 #5
0
        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();
        }
예제 #6
0
        internal List <TestFlightData> AttemptTechTransfer()
        {
            // attempts to transfer data from a predecessor part
            // parts can be referenced either by part name, full name, or configuration name
            // multiple branches can be specified with the & character
            // multiple parts in a branch can be specified by separating them with a comma
            // for each branch the first part listed is considered the closest part, and each part after is considered to be one generation removed.  An optional generation penalty is added for each level
            //  for each branch, the flight data from each part is added together including any generation penalties, to create a total for that branch, modifed by the transfer amount for that branch
            // if multiple branches are specified, each branch is then added together
            // an optional maximum data can be enforced for each scope (global setting but applied to each scope, not total)
            // Example
            // techTransfer = rs-27a,rs-27,h1-b,h1:10&lr-89-na-7,lr-89-na-6,lr-89-na-5:25
            // defines two branches, one from the RS-27 branch and one from the LR-89 branch.

            if (techTransfer.Trim() == "")
            {
                return(null);
            }

            List <TestFlightData>       transferredFlightData;
            Dictionary <string, double> dataToTransfer = null;

            string[] branches;
            string[] modifiers;
            int      generation = 0;

            branches = techTransfer.Split(new char[1] {
                '&'
            });

            foreach (string branch in branches)
            {
                modifiers = branch.Split(new char[1] {
                    ':'
                });
                if (modifiers.Length < 2)
                {
                    continue;
                }
                string[] partsInBranch = modifiers[0].Split(new char[1] {
                    ','
                });
                float branchModifier = float.Parse(modifiers[1]);
                branchModifier /= 100f;
                dataToTransfer  = new Dictionary <string, double>();
                foreach (string partNameFragment in partsInBranch)
                {
                    PartFlightData partData = TestFlightManagerScenario.Instance.GetFlightDataForPartNameFragment(partNameFragment);
                    if (partData == null)
                    {
                        continue;
                    }
                    List <TestFlightData> data = partData.GetFlightData();
                    foreach (TestFlightData scopeData in data)
                    {
                        if (dataToTransfer.ContainsKey(scopeData.scope))
                        {
                            dataToTransfer[scopeData.scope] = dataToTransfer[scopeData.scope] + ((scopeData.flightData - (scopeData.flightData * generation * techTransferGenerationPenalty)) * branchModifier);
                        }
                        else
                        {
                            dataToTransfer.Add(scopeData.scope, ((scopeData.flightData - (scopeData.flightData * generation * techTransferGenerationPenalty))) * branchModifier);
                        }
                    }
                    generation++;
                }
            }
            // When that is all done we should have a bunch of data in our dictionary dataToTransfer sorted by scope.  Now we just need to pack it into proper TestFlightData structs
            if (dataToTransfer == null || dataToTransfer.Count <= 0)
            {
                return(null);
            }
            transferredFlightData = new List <TestFlightData>();
            foreach (var scope in dataToTransfer)
            {
                TestFlightData data = new TestFlightData();
                data.scope = scope.Key;
                if (techTransferMax > 0 && scope.Value > techTransferMax)
                {
                    data.flightData = techTransferMax;
                }
                else
                {
                    data.flightData = scope.Value;
                }
                transferredFlightData.Add(data);
            }
            return(transferredFlightData);
        }