예제 #1
0
파일: Editor.cs 프로젝트: erendrake/AGExt
        public static void EditorSaveToFile()
        {
            //print("EditorSaveToFile called"); 
            string errLine = "1";
            try
            {
                ConfigNode AGXEditorNode = new ConfigNode("EDITOR");
                AGXEditorNode.AddValue("name", "editor");
                errLine = "2";
                if (File.Exists(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg"))
                {
                    errLine = "3";
                    AGXEditorNode = ConfigNode.Load(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg");
                    //print("AGX ConfigNode Load Okay! (Saving)");
                }
               // else
                //{
                    //errLine = "4";
                    //print("AGX ConfigNode not found, creating..... (Saving)");
                    //errLine = "5";
                    //AGXEditorNode.AddValue("name", "Action Groups Extended save file");
                    //AGXEditorNode.AddNode("FLIGHT");
                    //errLine = "6";
                    //AGXEditorNode.AddNode("EDITOR");
                    //errLine = "7";
                    //AGXEditorNode.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg");
                    //errLine = "8";
                //}

                errLine = "9";
                //ConfigNode AGXEditorNode = AGXBaseNode.GetNode("EDITOR");
                errLine = "10";
                string hashedShipName = AGextScenario.EditorHashShipName(EditorLogic.fetch.shipNameField.Text, inVAB);
                errLine = "11";
                ConfigNode thisVsl = new ConfigNode(hashedShipName);
                errLine = "12";
                thisVsl.AddValue("name", EditorLogic.fetch.shipNameField.Text);
                errLine = "13";
                thisVsl.AddValue("currentKeyset", CurrentKeySet.ToString());
                errLine = "14";
                thisVsl.AddValue("groupNames", SaveGroupNames(""));
                errLine = "15";
                thisVsl.AddValue("groupVisibility", SaveGroupVisibility(""));
                errLine = "16";
                thisVsl.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                errLine = "17";
                try
                {
                    errLine = "17c";
                    foreach (Part p in EditorLogic.SortedShipList)
                    {
                        errLine = "17d";
                        List<AGXAction> thisPartsActions = new List<AGXAction>();
                        thisPartsActions.AddRange(CurrentVesselActions.FindAll(p2 => p2.prt == p));
                        errLine = "18";
                        if (thisPartsActions.Count > 0)
                        {
                            ConfigNode partTemp = new ConfigNode("PART");
                            errLine = "19";
                            partTemp.AddValue("name", p.name);
                            partTemp.AddValue("vesselID", "0");
                            partTemp.AddValue("relLocX", (p.transform.position - EditorLogic.startPod.transform.position).x);
                            if (!inVAB)
                            {
                                partTemp.AddValue("relLocZ", ((p.transform.position - EditorLogic.startPod.transform.position).y) * -1f);
                                partTemp.AddValue("relLocY", (p.transform.position - EditorLogic.startPod.transform.position).z);
                            }
                            else
                            {
                                partTemp.AddValue("relLocY", (p.transform.position - EditorLogic.startPod.transform.position).y);
                                partTemp.AddValue("relLocZ", (p.transform.position - EditorLogic.startPod.transform.position).z);
                            }
                            errLine = "20";
                            foreach (AGXAction agxAct in thisPartsActions)
                            {
                                errLine = "21";
                                partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                            }
                            errLine = "22";

                            thisVsl.AddNode(partTemp);
                            errLine = "23";
                        }
                       // print("part OrgPart "+ p.ConstructID+" " + p.orgPos + " " + p.orgRot);
                    }
                }
                catch
                {
                    print("AGExt No parts to save ");
                }
                errLine = "23";
                if(AGXEditorNode.HasNode(hashedShipName))
                {
                    errLine = "23";
                    AGXEditorNode.RemoveNode(hashedShipName);
                }
                errLine = "24";
                AGXEditorNode.AddNode(thisVsl);
                errLine = "25";
                //AGXBaseNode.RemoveNode("EDITOR");
                errLine = "26";
                //AGXBaseNode.AddNode(AGXEditorNode);
                errLine = "27";
                AGXEditorNode.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg");
                //print("Saved this node " + AGXEditorNode);
                errLine = "28";
            }
            catch (Exception e)
            {
                print("AGX EditorSaveToFile FAIL " + errLine + " " + e);
            }
        }
예제 #2
0
파일: Editor.cs 프로젝트: erendrake/AGExt
        public void CheckExistingShips()
        {
            List<string> existingShipsList = new List<string>();
            string fileDir = new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/Ships/VAB";
            int fileLen = fileDir.Length;
            string[] fileList = Directory.GetFiles(fileDir);
            //print("sc3 " + loadShipList.Length);
            foreach (string file in fileList)
            {
                existingShipsList.Add(AGextScenario.EditorHashShipName(file.Substring(fileLen + 1, file.Length - fileLen - 7),true));
            }
                fileDir = new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/Ships/SPH";
            
            fileLen = fileDir.Length;
            fileList = Directory.GetFiles(fileDir);
            foreach (string file in fileList)
            {
                existingShipsList.Add(AGextScenario.EditorHashShipName(file.Substring(fileLen + 1, file.Length - fileLen - 7), false));
            }
            fileDir = new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "Ships/SPH";
            fileLen = fileDir.Length;
            fileList = Directory.GetFiles(fileDir);
            foreach (string file in fileList)
            {
                existingShipsList.Add(AGextScenario.EditorHashShipName(file.Substring(fileLen + 1, file.Length - fileLen - 7), false));
            }
            fileDir = new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "Ships/VAB";
            fileLen = fileDir.Length;
            fileList = Directory.GetFiles(fileDir);
            foreach (string file in fileList)
            {
                existingShipsList.Add(AGextScenario.EditorHashShipName(file.Substring(fileLen + 1, file.Length - fileLen - 7), true));
            }
            //ConfigNode AGXBaseNode = AGextScenario.LoadBaseNode();
            ConfigNode AGXEditorNode = new ConfigNode("EDITOR");
            AGXEditorNode.AddValue("name", "editor");
            if (File.Exists(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg"))
            {
                AGXEditorNode = ConfigNode.Load(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg");
            }
            foreach (ConfigNode VslNode in AGXEditorNode.nodes)
            {
                if (!existingShipsList.Contains(VslNode.name))
                {
                    AGXEditorNode.RemoveNode(VslNode.name);
                    //AGXBaseNode.RemoveNode("EDITOR");
                    //AGXBaseNode.AddNode(AGXEditorNode);
                    AGXEditorNode.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtEditor.cfg");
                    //print("Existing ship check node save " + AGXEditorNode);
                    goto BreakOut;
                }
            }
        BreakOut:
            fileList = null;

            
        }
        public override void OnSave(ConfigNode local, ConfigNode type, ConfigNode global)
        {
            base.OnSave(local, type, global);

            if (local == null) return;

            if (local.HasNode("Waypoints")) { local.RemoveNode("Waypoints"); }
            if (Waypoints.Count > 0) {
                ConfigNode cn = local.AddNode("Waypoints");
                cn.AddValue("Index", WaypointIndex);
                foreach (MechJebRoverWaypoint wp in Waypoints) {
                    cn.AddNode(wp.ToConfigNode());
                }
            }
        }
예제 #4
0
        public virtual void DoConfig(ConfigNode cfg)
        {
            configMaxThrust = configMinThrust = configHeat = -1f;
            // Get thrusts
            if (config.HasValue(thrustRating))
            {
                float thr;
                if (float.TryParse(config.GetValue(thrustRating), out thr))
                    configMaxThrust = scale * thr;
            }
            if (config.HasValue("minThrust"))
            {
                float thr;
                if (float.TryParse(config.GetValue("minThrust"), out thr))
                    configMinThrust = scale * thr;
            }

            // Get, multiply heat
            if (cfg.HasValue("heatProduction"))
            {
                float heat;
                if(float.TryParse(cfg.GetValue("heatProduction"), out heat))
                    configHeat = (float)Math.Round(heat * RFSettings.Instance.heatMultiplier, 0);
            }

            // load throttle (for later)
            configThrottle = throttle;
            if (cfg.HasValue("throttle"))
                float.TryParse(cfg.GetValue("throttle"), out configThrottle);
            else if (configMinThrust >= 0f && configMaxThrust >= 0f)
                configThrottle = configMinThrust / configMaxThrust;

            float TLMassMult = 1.0f;

            float gimbal = -1f;
            if (cfg.HasValue("gimbalRange"))
                gimbal = float.Parse(cfg.GetValue("gimbalRange"));

            float cost = 0f;
            if (cfg.HasValue("cost"))
                cost = scale * float.Parse(cfg.GetValue("cost"));

            if (techLevel != -1)
            {
                // load techlevels
                TechLevel cTL = new TechLevel();
                cTL.Load(cfg, techNodes, engineType, techLevel);
                TechLevel oTL = new TechLevel();
                oTL.Load(cfg, techNodes, engineType, origTechLevel);

                // set atmosphereCurve
                if (cfg.HasValue("IspSL") && cfg.HasValue("IspV"))
                {
                    cfg.RemoveNode("atmosphereCurve");

                    ConfigNode curve = new ConfigNode("atmosphereCurve");

                    // get the multipliers
                    float ispSL = 1f, ispV = 1f;
                    float.TryParse(cfg.GetValue("IspSL"), out ispSL);
                    float.TryParse(cfg.GetValue("IspV"), out ispV);

                    // Mod the curve by the multipliers
                    FloatCurve newAtmoCurve = new FloatCurve();
                    newAtmoCurve = Utilities.Mod(cTL.AtmosphereCurve, ispSL, ispV);
                    newAtmoCurve.Save(curve);

                    cfg.AddNode(curve);
                }

                // set heatProduction
                if (configHeat > 0)
                {
                    configHeat = MassTL(configHeat);
                }

                // set thrust and throttle
                if (configMaxThrust >= 0)
                {
                    configMaxThrust = ThrustTL(configMaxThrust);
                    if (configMinThrust >= 0)
                    {
                        configMinThrust = ThrustTL(configMinThrust);
                    }
                    else if (thrustRating.Equals("thrusterPower"))
                    {
                        configMinThrust = configMaxThrust * 0.5f;
                    }
                    else
                    {
                        configMinThrust = configMaxThrust;
                        if (configThrottle > 1.0f)
                        {
                            if (techLevel >= configThrottle)
                                configThrottle = 1.0f;
                            else
                                configThrottle = -1.0f;
                        }
                        if (configThrottle >= 0.0f)
                        {
                            configThrottle = (float)((double)configThrottle * cTL.Throttle());
                            configMinThrust *= configThrottle;
                        }
                    }
                    configThrottle = configMinThrust / configMaxThrust;
                    if (origMass > 0)
                        TLMassMult = MassTL(1.0f);
                }
                // Don't want to change gimbals on TL-enabled engines willy-nilly
                // So we don't unless either a transform is specified, or we override.
                // We assume if it was specified in the CONFIG that we should use it anyway.
                if (gimbal < 0 && (!gimbalTransform.Equals("") || useGimbalAnyway))
                    gimbal = cTL.GimbalRange;
                if (gimbal >= 0)
                {
                    // allow local override of gimbal mult
                    if (cfg.HasValue("gimbalMult"))
                        gimbal *= float.Parse(cfg.GetValue("gimbalMult"));
                }

                // Cost (multiplier will be 1.0 if unspecified)
                cost = scale * CostTL(cost, cfg);
            }
            else
            {
                if (cfg.HasValue(thrustRating) && configThrottle > 0f && !cfg.HasValue("minThrust"))
                {
                    configMinThrust = configThrottle * configMaxThrust;
                }
            }

            // Now update the cfg from what we did.
            // thrust updates
            if(configMaxThrust >= 0f)
                cfg.SetValue(thrustRating, configMaxThrust.ToString("0.0000"));
            if(configMinThrust >= 0f)
                cfg.SetValue("minThrust", configMinThrust.ToString("0.0000")); // will be ignored by RCS, so what.

            // heat update
            if(configHeat >= 0f)
                cfg.SetValue("heatProduction", configHeat.ToString("0"));

            // mass change
            if (origMass > 0)
            {
                float ftmp;
                configMassMult = scale;
                if (cfg.HasValue("massMult"))
                    if (float.TryParse(cfg.GetValue("massMult"), out ftmp))
                        configMassMult *= ftmp;

                part.mass = origMass * configMassMult * RFSettings.Instance.EngineMassMultiplier * TLMassMult;
                massDelta = 0;
                if ((object)(part.partInfo) != null)
                    if ((object)(part.partInfo.partPrefab) != null)
                        massDelta = part.mass - part.partInfo.partPrefab.mass;
            }

            // KIDS integration
            if (cfg.HasNode("atmosphereCurve"))
            {
                ConfigNode newCurveNode = new ConfigNode("atmosphereCurve");
                FloatCurve oldCurve = new FloatCurve();
                oldCurve.Load(cfg.GetNode("atmosphereCurve"));
                FloatCurve newCurve = Utilities.Mod(oldCurve, ispSLMult, ispVMult);
                newCurve.Save(newCurveNode);
                cfg.RemoveNode("atmosphereCurve");
                cfg.AddNode(newCurveNode);
            }
            // gimbal change
            if (gimbal >= 0 && !cfg.HasValue("gimbalRange")) // if TL set a gimbal
            {
                // apply module-wide gimbal mult on top of any local ones
                cfg.AddValue("gimbalRange", (gimbal * gimbalMult).ToString("N4"));
            }
            if (cost != 0f)
            {
                if (cfg.HasValue("cost"))
                    cfg.SetValue("cost", cost.ToString("N3"));
                else
                    cfg.AddValue("cost", cost.ToString("N3"));
            }
        }
        public static void ModifyEngineConfigNode(ConfigNode engine, float ispMultiplierVac, float ispMultiplierAtm, bool extendToZeroIsp)
        {
            ConfigNode atmoCurve = engine.GetNode("atmosphereCurve");

            FloatCurve engineCurve = ModifyCurveKeys(atmoCurve, ispMultiplierVac, ispMultiplierAtm, extendToZeroIsp);
            atmoCurve = new ConfigNode("atmosphereCurve");
            engineCurve.Save(atmoCurve);
            engine.RemoveNode("atmosphereCurve");
            engine.AddNode(atmoCurve);
        }
예제 #6
0
        public static void WriteNode(ConfigNode newNode)
        {
            var fileInfo = new FileInfo(GetSaveFilePath());
            ConfigNode persistenceNode;
            if (!fileInfo.Exists)
            {
                var cNode = new ConfigNode();
                persistenceNode = cNode.AddNode("KerbTownPersistence");
                persistenceNode.AddNode(newNode);
                cNode.Save(fileInfo.FullName);

                _ktSave = cNode;
                return;
            }

            _ktSave = ConfigNode.Load(fileInfo.FullName);
            persistenceNode = _ktSave.GetNode("KerbTownPersistence");

            var nodes = persistenceNode.GetNodes(newNode.name);
            var rootID = newNode.GetValue("ID");
            bool nodeSet = false;

            foreach (var node in from node in nodes let nodeID = node.GetValue("ID") where nodeID == rootID select node)
            {
                persistenceNode.nodes.Remove(node);
                persistenceNode.nodes.Add(newNode);
                nodeSet = true;
            }

            if (nodeSet == false)
            {
                persistenceNode.nodes.Add(newNode);
            }

            _ktSave.RemoveNode("KerbTownPersistence");
            _ktSave.AddNode(persistenceNode);

            _ktSave.Save(GetSaveFilePath());

            // Note: SetNode() isn't recursive on descendant ConfigNodes
        }
예제 #7
0
        internal void saveSettings(ConfigNode toolbarNode)
        {
            Log.info("saving toolbar settings (toolbar '{0}')", toolbarNode.name);

            toolbarNode.overwrite("x", rect.x.ToString("F0"));
            toolbarNode.overwrite("y", rect.y.ToString("F0"));
            toolbarNode.overwrite("width", savedMaxWidth.ToString("F0"));
            toolbarNode.overwrite("height", rect.height.ToString("F0"));
            toolbarNode.overwrite("autoHide", autoHide.ToString());
            toolbarNode.overwrite("drawBorder", showBorder.ToString());
            toolbarNode.overwrite("useKSPSkin", UseKSPSkin.ToString());
            toolbarNode.overwrite("buttonOrder", string.Join(",", savedButtonOrder.ToArray()));
            toolbarNode.overwrite("visibleButtons", string.Join(",", savedVisibleButtons.ToArray()));

            ConfigNode foldersNode = toolbarNode.overwriteNode("folders");
            foreach (KeyValuePair<string, FolderSettings> entry in savedFolderSettings) {
                ConfigNode folderNode = foldersNode.getOrCreateNode(entry.Key);
                folderNode.overwrite("texturePath", entry.Value.texturePath ?? "000_Toolbar/folder");
                folderNode.overwrite("toolTip", entry.Value.toolTip ?? string.Empty);
                folderNode.overwrite("buttons", string.Join(",", entry.Value.buttons.ToArray()));
            }
            if (foldersNode.CountNodes == 0) {
                toolbarNode.RemoveNode("folders");
            }
        }
예제 #8
0
        /// <summary>
        /// Saves all values for the flightcomputer to the persistant
        /// </summary>
        /// <param name="n">Node to save in</param>
        public void Save(ConfigNode n)
        {
            if (n.HasNode("FlightComputer"))
                n.RemoveNode("FlightComputer");

            ConfigNode ActiveCommands = new ConfigNode("ActiveCommands");
            ConfigNode Commands = new ConfigNode("Commands");

            foreach (KeyValuePair<int, ICommand> cmd in mActiveCommands)
            {
                // Save each active command on his own node
                ConfigNode activeCommandNode = new ConfigNode(cmd.Value.GetType().Name);
                cmd.Value.Save(activeCommandNode, this);
                ActiveCommands.AddNode(activeCommandNode);
            }

            foreach (ICommand cmd in mCommandQueue)
            {
                // Save each command on his own node
                ConfigNode commandNode = new ConfigNode(cmd.GetType().Name);
                cmd.Save(commandNode, this);
                Commands.AddNode(commandNode);
            }

            ConfigNode FlightNode = new ConfigNode("FlightComputer");
            FlightNode.AddValue("TotalDelay", TotalDelay);
            FlightNode.AddNode(ActiveCommands);
            FlightNode.AddNode(Commands);

            n.AddNode(FlightNode);
        }
        /// <summary>Saves all values for the flight computer to the persistent.</summary>
        /// <param name="n">Node to save in</param>
        public void Save(ConfigNode n)
        {
            if (n.HasNode("FlightComputer"))
                n.RemoveNode("FlightComputer");

            var activeCommands = new ConfigNode("ActiveCommands");
            var commands = new ConfigNode("Commands");

            // save active commands
            foreach (var cmd in _activeCommands)
            {
                // Save each active command on his own node
                var activeCommandNode = new ConfigNode(cmd.Value.GetType().Name);
                cmd.Value.Save(activeCommandNode, this);
                activeCommands.AddNode(activeCommandNode);
            }

            // save commands
            foreach (var cmd in _commandQueue)
            {
                // Save each command on his own node
                var commandNode = new ConfigNode(cmd.GetType().Name);
                cmd.Save(commandNode, this);
                commands.AddNode(commandNode);
            }

            var flightNode = new ConfigNode("FlightComputer");
            flightNode.AddValue("TotalDelay", TotalDelay);
            flightNode.AddNode(activeCommands);
            flightNode.AddNode(commands);

            n.AddNode(flightNode);
        }
예제 #10
0
        private bool CheckFilesChange(UrlDir.UrlFile[] files, ConfigNode shaConfigNode)
        {
            bool noChange = true;
            StringBuilder changes = new StringBuilder();
            
            for (int i = 0; i < files.Length; i++)
            {
                ConfigNode fileNode = getFileNode(shaConfigNode, files[i].url);
                string fileSha = fileNode != null ? fileNode.GetValue("SHA") : null;

                if (fileNode == null)
                    continue;

                if (fileSha == null || filesSha[files[i].url] != fileSha)
                {
                    changes.Append("Changed : " + fileNode.GetValue("filename") + ".cfg\n");
                    noChange = false;
                }
            }
            for (int i = 0; i < files.Length; i++)
            {
                ConfigNode fileNode = getFileNode(shaConfigNode, files[i].url);

                if (fileNode == null)
                {
                    changes.Append("Added   : " + files[i].url + ".cfg\n");
                    noChange = false;
                }
                shaConfigNode.RemoveNode(fileNode);
            }
            foreach (ConfigNode fileNode in shaConfigNode.GetNodes())
            {
                changes.Append("Deleted : " + fileNode.GetValue("filename") + ".cfg\n");
                noChange = false;
            }
            if (!noChange)
                log("Changes :\n" + changes.ToString());
            return noChange;
        }
예제 #11
0
        virtual public void DoConfig(ConfigNode cfg)
        {
            // fix propellant ratios to not be rounded
            if (cfg.HasNode("PROPELLANT"))
            {
                foreach (ConfigNode pNode in cfg.GetNodes("PROPELLANT"))
                {
                    if (pNode.HasValue("ratio"))
                    {
                        double dtmp;
                        if (double.TryParse(pNode.GetValue("ratio"), out dtmp))
                            pNode.SetValue("ratio", (dtmp * 100.0).ToString());
                    }
                }
            }
            float heat = -1;
            if (cfg.HasValue("heatProduction")) // ohai amsi: allow heat production to be changed by multiplier
            {
                heat = (float)Math.Round(float.Parse(cfg.GetValue("heatProduction")) * heatMult, 0);
                cfg.SetValue("heatProduction", heat.ToString());
            }

            // load throttle (for later)
            curThrottle = throttle;
            if (cfg.HasValue("throttle"))
                float.TryParse(cfg.GetValue("throttle"), out curThrottle);
            else if(cfg.HasValue("minThrust") && cfg.HasValue("maxThrust"))
                curThrottle = float.Parse(cfg.GetValue("minThrust")) / float.Parse(cfg.GetValue("maxThrust"));
            float TLMassMult = 1.0f;
            if (techLevel != -1)
            {
                // load techlevels
                TechLevel cTL = new TechLevel();
                //print("For engine " + part.name + ", config " + configuration + ", max TL: " + TechLevel.MaxTL(cfg, techNodes, engineType));
                cTL.Load(cfg, techNodes, engineType, techLevel);
                TechLevel oTL = new TechLevel();
                oTL.Load(cfg, techNodes, engineType, origTechLevel);


                // set atmosphereCurve
                if (cfg.HasValue("IspSL") && cfg.HasValue("IspV"))
                {
                    cfg.RemoveNode("atmosphereCurve");
                    ConfigNode curve = new ConfigNode("atmosphereCurve");
                    float ispSL, ispV;
                    float.TryParse(cfg.GetValue("IspSL"), out ispSL);
                    float.TryParse(cfg.GetValue("IspV"), out ispV);
                    FloatCurve aC = new FloatCurve();
                    aC = Mod(cTL.atmosphereCurve, ispSL, ispV);
                    aC.Save(curve);
                    cfg.AddNode(curve);
                }

                // set heatProduction and dissipation
                if (heat > 0)
                {
                    cfg.SetValue("heatProduction", MassTL(heat).ToString("0"));
                    part.heatDissipation = 0.12f / MassTL(1.0f);
                }

                // set thrust and throttle
                if (cfg.HasValue(thrustRating))
                {
                    float thr;
                    float.TryParse(cfg.GetValue(thrustRating), out thr);
                    configMaxThrust = ThrustTL(thr);
                    cfg.SetValue(thrustRating, configMaxThrust.ToString("0.0000"));
                    if (cfg.HasValue("minThrust"))
                    {
                        float.TryParse(cfg.GetValue("minThrust"), out thr);
                        configMinThrust = ThrustTL(thr);
                        cfg.SetValue("minThrust", configMinThrust.ToString("0.0000"));
                    }
                    else
                    {
                        if (thrustRating.Equals("thrusterPower"))
                        {
                            configMinThrust = configMaxThrust * 0.5f;
                        }
                        else
                        {
                            configMinThrust = configMaxThrust;
                            if (curThrottle > 1.0f)
                            {
                                if (techLevel >= curThrottle)
                                    curThrottle = 1.0f;
                                else
                                    curThrottle = -1.0f;
                            }
                            if (curThrottle >= 0.0f)
                            {
                                curThrottle = (float)((double)curThrottle * cTL.Throttle());
                                configMinThrust *= curThrottle;
                            }
                            cfg.SetValue("minThrust", configMinThrust.ToString("0.0000"));
                        }
                    }
                    curThrottle = configMinThrust / configMaxThrust;
                    if(origMass > 0)
                         TLMassMult =  MassTL(1.0f);
                }
            }
            else
            {
                if(cfg.HasValue(thrustRating) && curThrottle > 0f && !cfg.HasValue("minThrust"))
                {
                    configMinThrust = curThrottle * float.Parse(cfg.GetValue(thrustRating));
                    cfg.SetValue("minThrust", configMinThrust.ToString("0.0000"));
                }
            }
            // mass change
            if (origMass > 0)
            {
                float ftmp;
                configMassMult = 1.0f;
                if (cfg.HasValue("massMult"))
                    if (float.TryParse(cfg.GetValue("massMult"), out ftmp))
                        configMassMult = ftmp;

                part.mass = origMass * configMassMult * massMult * TLMassMult;
            }
            // KIDS integration
            if(cfg.HasNode("atmosphereCurve"))
            {
                ConfigNode newCurveNode = new ConfigNode("atmosphereCurve");
                FloatCurve oldCurve = new FloatCurve();
                oldCurve.Load(cfg.GetNode("atmosphereCurve"));
                FloatCurve newCurve = Mod(oldCurve, ispSLMult, ispVMult);
                newCurve.Save(newCurveNode);
                cfg.RemoveNode("atmosphereCurve");
                cfg.AddNode(newCurveNode);
            }
        }
        public virtual void DoConfig(ConfigNode cfg)
        {
            // fix propellant ratios to not be rounded
            if (cfg.HasNode("PROPELLANT"))
            {
                foreach (ConfigNode pNode in cfg.GetNodes("PROPELLANT"))
                {
                    if (pNode.HasValue("ratio"))
                    {
                        double dtmp;
                        if (double.TryParse(pNode.GetValue("ratio"), out dtmp))
                            pNode.SetValue("ratio", (dtmp * 100.0).ToString());
                    }
                }
            }
            float heat = -1;
            if (cfg.HasValue("heatProduction")) // ohai amsi: allow heat production to be changed by multiplier
            {
                heat = (float)Math.Round(float.Parse(cfg.GetValue("heatProduction")) * heatMult, 0);
                cfg.SetValue("heatProduction", heat.ToString());
            }

            // load throttle (for later)
            curThrottle = throttle;
            if (cfg.HasValue("throttle"))
                float.TryParse(cfg.GetValue("throttle"), out curThrottle);
            else if(cfg.HasValue("minThrust") && cfg.HasValue("maxThrust"))
                curThrottle = float.Parse(cfg.GetValue("minThrust")) / float.Parse(cfg.GetValue("maxThrust"));
            float TLMassMult = 1.0f;

            float gimbal = -1f;
            if (cfg.HasValue("gimbalRange"))
                gimbal = float.Parse(cfg.GetValue("gimbalRange"));

            float cost = 0f;
            if(cfg.HasValue("cost"))
                cost = float.Parse(cfg.GetValue("cost"));

            if (techLevel != -1)
            {
                // load techlevels
                TechLevel cTL = new TechLevel();
                //print("For engine " + part.name + ", config " + configuration + ", max TL: " + TechLevel.MaxTL(cfg, techNodes, engineType));
                cTL.Load(cfg, techNodes, engineType, techLevel);
                TechLevel oTL = new TechLevel();
                oTL.Load(cfg, techNodes, engineType, origTechLevel);

                // set atmosphereCurve
                if (cfg.HasValue("IspSL") && cfg.HasValue("IspV"))
                {
                    cfg.RemoveNode("atmosphereCurve");
                    ConfigNode curve = new ConfigNode("atmosphereCurve");
                    float ispSL, ispV;
                    float.TryParse(cfg.GetValue("IspSL"), out ispSL);
                    float.TryParse(cfg.GetValue("IspV"), out ispV);
                    FloatCurve aC = new FloatCurve();
                    aC = Mod(cTL.AtmosphereCurve, ispSL, ispV);
                    aC.Save(curve);
                    cfg.AddNode(curve);
                }

                // set heatProduction and dissipation
                if (heat > 0)
                {
                    cfg.SetValue("heatProduction", MassTL(heat).ToString("0"));
                    part.heatDissipation = 0.12f / MassTL(1.0f);
                }

                // set thrust and throttle
                if (cfg.HasValue(thrustRating))
                {
                    float thr;
                    float.TryParse(cfg.GetValue(thrustRating), out thr);
                    configMaxThrust = ThrustTL(thr);
                    cfg.SetValue(thrustRating, configMaxThrust.ToString("0.0000"));
                    if (cfg.HasValue("minThrust"))
                    {
                        float.TryParse(cfg.GetValue("minThrust"), out thr);
                        configMinThrust = ThrustTL(thr);
                        cfg.SetValue("minThrust", configMinThrust.ToString("0.0000"));
                    }
                    else
                    {
                        if (thrustRating.Equals("thrusterPower"))
                        {
                            configMinThrust = configMaxThrust * 0.5f;
                        }
                        else
                        {
                            configMinThrust = configMaxThrust;
                            if (curThrottle > 1.0f)
                            {
                                if (techLevel >= curThrottle)
                                    curThrottle = 1.0f;
                                else
                                    curThrottle = -1.0f;
                            }
                            if (curThrottle >= 0.0f)
                            {
                                curThrottle = (float)((double)curThrottle * cTL.Throttle());
                                configMinThrust *= curThrottle;
                            }
                            cfg.SetValue("minThrust", configMinThrust.ToString("0.0000"));
                        }
                    }
                    curThrottle = configMinThrust / configMaxThrust;
                    if(origMass > 0)
                         TLMassMult =  MassTL(1.0f);
                }
                // Don't want to change gimbals on TL-enabled engines willy-nilly
                // So we don't unless either a transform is specified, or we override.
                // We assume if it was specified in the CONFIG that we should use it anyway.
                if (gimbal < 0 && (!gimbalTransform.Equals("") || useGimbalAnyway))
                    gimbal = cTL.GimbalRange;
                if (gimbal >= 0)
                {
                    // allow local override of gimbal mult
                    if (cfg.HasValue("gimbalMult"))
                        gimbal *= float.Parse(cfg.GetValue("gimbalMult"));
                }

                // Cost (multiplier will be 1.0 if unspecified)
                cost = CostTL(cost, cfg);
            }
            else
            {
                if(cfg.HasValue(thrustRating) && curThrottle > 0f && !cfg.HasValue("minThrust"))
                {
                    configMinThrust = curThrottle * float.Parse(cfg.GetValue(thrustRating));
                    cfg.SetValue("minThrust", configMinThrust.ToString("0.0000"));
                }
            }
            // mass change
            if (origMass > 0)
            {
                float ftmp;
                configMassMult = 1.0f;
                if (cfg.HasValue("massMult"))
                    if (float.TryParse(cfg.GetValue("massMult"), out ftmp))
                        configMassMult = ftmp;

                part.mass = origMass * configMassMult * massMult * TLMassMult;
                massDelta = 0;
                if((object)(part.partInfo) != null)
                    if((object)(part.partInfo.partPrefab) != null)
                        massDelta = part.mass - part.partInfo.partPrefab.mass;
            }
            // KIDS integration
            if(cfg.HasNode("atmosphereCurve"))
            {
                ConfigNode newCurveNode = new ConfigNode("atmosphereCurve");
                FloatCurve oldCurve = new FloatCurve();
                oldCurve.Load(cfg.GetNode("atmosphereCurve"));
                FloatCurve newCurve = Mod(oldCurve, ispSLMult, ispVMult);
                newCurve.Save(newCurveNode);
                cfg.RemoveNode("atmosphereCurve");
                cfg.AddNode(newCurveNode);
            }
            // gimbal change
            if (gimbal >= 0 && !cfg.HasValue("gimbalRange")) // if TL set a gimbal
            {
                // apply module-wide gimbal mult on top of any local ones
                cfg.AddValue("gimbalRange", (gimbal * gimbalMult).ToString("N4"));
            }
            if (cost != 0f)
            {
                if (cfg.HasValue("cost"))
                    cfg.SetValue("cost", cost.ToString("N3"));
                else
                    cfg.AddValue("cost", cost.ToString("N3"));
            }
        }
 public override void OnSave(ConfigNode node)
 {
     ConfigNode c1 = new ConfigNode ("color1");
     c1.AddValue ("red", color1.r);
     c1.AddValue ("green", color1.g);
     c1.AddValue ("blue", color1.b);
     node.AddNode (c1);
     ConfigNode c2 = new ConfigNode ("color2");
     c2.AddValue ("red", color2.r);
     c2.AddValue ("green", color2.g);
     c2.AddValue ("blue", color2.b);
     node.AddNode (c2);
     node.RemoveNode ("texturePattern_UIFlight");
     node.RemoveNode ("textureRepeat_UIFlight");
     node.RemoveNode ("EVENTS");
     node.RemoveNode ("ACTIONS");
     base.OnSave (node);
 }
예제 #14
0
        public void Save(ConfigNode node)
        {
            if (node.HasNode("Processor"))
                node.RemoveNode("Processor");

            ConfigNode Proc = new ConfigNode("Processor");

            Proc.AddValue("isHibernating", isHibernating);
            if (isHibernating)
                Proc.AddValue("hibernationLine", hibernationLine);

            if (pid != null)
                pid.Save(Proc);

            ConfigNode InstList = new ConfigNode("Instructions");
            foreach (Instruction i in instructions)
            {
                ConfigNode Inst = new ConfigNode("Instruction");
                Inst.AddValue("code", i.mText);
                Inst.AddValue("lastValue", i.lastValue);
                Inst.AddValue("skip", i.skip);
                InstList.AddNode(Inst);
            }
            Proc.AddNode(InstList);

            if (latches > 0)
            {
                ConfigNode LatchList = new ConfigNode("Latches");
                for (int i = 0; i < latches; i++)
                    LatchList.AddValue(string.Format("latch{0:D}", i), latchState[i].ToString());
                Proc.AddNode(LatchList);
            }

            if (timers > 0)
            {
                ConfigNode TimerList = new ConfigNode("Timers");
                for (int i = 0; i < timers; i++)
                    TimerList.AddValue(timerState[i].name, timerState[i].startTime);
                Proc.AddNode(TimerList);
            }

            node.AddNode(Proc);
        }
예제 #15
0
        public void LoadData()
        {
            data = ConfigNode.Load(FilePath);
            bool StationKeepingfound = false;
            bool DecayTimefound = false;

            foreach (ConfigNode vessel in data.nodes)
            {
                string id = vessel.GetValue("id");
                bool stationkeeping = bool.Parse(vessel.GetValue("stationkeeping"));
                float decaytime = float.Parse(vessel.GetValue("decaytime"));
                bool vesseldead = false;
                foreach (Vessel vess in FlightGlobals.Vessels)
                {
                    if (vess.id.ToString() == id)
                    {
                        if (vess.state == Vessel.State.DEAD)
                        {
                            data.RemoveNode(vessel);
                            StationKeeping.Remove(vess.id);
                            CanStationKeep.Remove(vess.id);
                            DecayTimes.Remove(vess.id);
                            DisplayedDecayTimes.Remove(vess);
                            vesseldead = true;
                            break;
                        }
                    }
                }
                if (vesseldead == true)
                {
                    break;
                }

                foreach (Guid ship in StationKeeping.Keys)
                {
                    if (ship.ToString() == id)
                    {
                        StationKeeping.Remove(ship);
                        StationKeeping.Add(ship, stationkeeping);
                        StationKeepingfound = true;
                        break;
                    }

                    if (StationKeepingfound == false)
                    {
                    }
                }
                foreach (Guid ship in DecayTimes.Keys)
                {
                    if (ship.ToString() == id)
                    {
                        DecayTimes.Remove(ship);
                        DecayTimes.Add(ship, decaytime);
                        DecayTimefound = true;
                        break;
                    }

                    if (DecayTimefound == false)
                    {
                    }
                }
            }
        }