public override bool Load(ConfigNode configNode)
        {
            bool hasTargetBody = configNode.HasValue("targetBody");

            // Load base class
            bool valid = base.Load(configNode);

            // Base class attempts to load a default, remove it and re-load
            if (!hasTargetBody)
            {
                configNode.RemoveValue("targetBody");
                valid &= ConfigNodeUtil.ParseValue<CelestialBody>(configNode, "targetBody", x => _targetBody = x, this, (CelestialBody)null);
            }

            // Before loading, verify the RemoteTech version
            valid &= Util.Version.VerifyRemoteTechVersion();

            valid &= ConfigNodeUtil.ParseValue<int>(configNode, "minCount", x => minCount = x, this, 1, x => Validation.GE(x, 0));
            valid &= ConfigNodeUtil.ParseValue<int>(configNode, "maxCount", x => maxCount = x, this, int.MaxValue, x => Validation.GE(x, 0));
            valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "activeVessel", x => activeVessel = x, this, false);
            valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minRange", x => minRange = x, this, 0.0, x => Validation.GE(x, 0.0));
            valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxRange", x => maxRange = x, this, double.MaxValue, x => Validation.GE(x, 0.0));
            valid &= ConfigNodeUtil.ParseValue<HasAntennaParameter.AntennaType?>(configNode, "antennaType", x => antennaType = x, this, (HasAntennaParameter.AntennaType?)null);
            valid &= ConfigNodeUtil.MutuallyExclusive(configNode, new string[] { "activeVessel" }, new string[] { "targetBody" }, this);

            return valid;
        }
        public static void DoExport()
        {
            ConfigNode configNode = new ConfigNode("CUSTOM_WAYPOINTS");
            Instance.Save(configNode);

            configNode.RemoveValue("name");
            configNode.RemoveValue("scene");

            configNode.Save(CustomWaypointsFileName,
                "Waypoint Manager Custom Waypoints File\r\n" +
                "//\r\n" +
                "// This file contains an extract of Waypoint Manager custom waypoints.");

            int count = Instance.waypoints.Count;
            ScreenMessages.PostScreenMessage("Exported " + count + " waypoint" + (count != 1 ? "s" : "") + " to " + CustomWaypointsFileName,
                6.0f, ScreenMessageStyle.UPPER_CENTER);
        }
Example #3
0
 private static void WriteValue(ConfigNode configNode, string ValueName, object value)
 {
     if (configNode.HasValue(ValueName))
         configNode.RemoveValue(ValueName);
     configNode.AddValue(ValueName, value.ToString());
 }
        public virtual void SetConfiguration(string newConfiguration = null, bool resetTechLevels = false)
        {
            if (newConfiguration == null)
                newConfiguration = configuration;

            ConfigSaveLoad();

            ConfigNode newConfig = configs.Find (c => c.GetValue ("name").Equals (newConfiguration));
            if (!UnlockedConfig(newConfig, part))
            {
                if(newConfig == null)
                    Debug.Log("*RFMEC* ERROR Can't find configuration " + newConfiguration + ", falling back to first tech-available config.");

                foreach(ConfigNode cfg in configs)
                    if (UnlockedConfig(cfg, part))
                    {
                        newConfig = cfg;
                        newConfiguration = cfg.GetValue("name");
                        break;
                    }
            }
            if (newConfig != null)
            {
                if (configuration != newConfiguration && resetTechLevels)
                    techLevel = origTechLevel;

                // for asmi
                if (useConfigAsTitle)
                    part.partInfo.title = configuration;

                configuration = newConfiguration;
                config = new ConfigNode("MODULE");
                newConfig.CopyTo(config);
                config.name = "MODULE";

            #if DEBUG
                print ("replacing " + type + " with:");
                print (newConfig.ToString ());
            #endif

                pModule = null;
                // get correct module
                pModule = GetSpecifiedModule(part, engineID, moduleIndex, type, useWeakType);

                if ((object)pModule == null)
                {
                    Debug.Log("*RFMEC* Could not find appropriate module of type " + type + ", with ID=" + engineID + " and index " + moduleIndex);
                    return;
                }

                Type mType = pModule.GetType();
                config.SetValue("name", mType.Name);

                // clear all FloatCurves we need to clear (i.e. if our config has one, or techlevels are enabled)
                bool delAtmo = config.HasNode("atmosphereCurve") || techLevel >= 0;
                bool delDens = config.HasNode("atmCurve") || techLevel >= 0;
                bool delVel = config.HasNode("velCurve") || techLevel >= 0;
                foreach (FieldInfo field in mType.GetFields())
                {
                    if (field.FieldType == typeof(FloatCurve) &&
                        ((field.Name.Equals("atmosphereCurve") && delAtmo)
                        || (field.Name.Equals("atmCurve") && delDens)
                        || (field.Name.Equals("velCurve") && delVel)))
                    {
                        field.SetValue(pModule, new FloatCurve());
                    }
                }
                // clear propellant gauges
                foreach (FieldInfo field in mType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    if (field.FieldType == typeof(Dictionary<Propellant, VInfoBox>))
                    {
                        Dictionary<Propellant, VInfoBox> boxes = (Dictionary<Propellant, VInfoBox>)(field.GetValue(pModule));
                        if (boxes == null)
                            continue;
                        foreach (VInfoBox v in boxes.Values)
                        {
                            if (v == null) //just in case...
                                continue;
                            try
                            {
                                part.stackIcon.RemoveInfo(v);
                            }
                            catch (Exception e)
                            {
                                Debug.Log("*RFMEC* Trying to remove info box: " + e.Message);
                            }
                        }
                        boxes.Clear();
                    }
                }
                if (type.Equals("ModuleRCS") || type.Equals("ModuleRCSFX"))
                {
                    ModuleRCS rcs = (ModuleRCS)pModule;
                    if (rcs != null)
                    {
                        DoConfig(config);
                        if (config.HasNode("PROPELLANT"))
                        {
                            rcs.propellants.Clear();
                        }
                        pModule.Load(config);
                    }
                }
                else
                { // is an ENGINE
                    ModuleEngines mE = (ModuleEngines)pModule;
                    if (mE != null)
                    {
                        if (config.HasNode("PROPELLANT"))
                        {
                            mE.propellants.Clear();
                        }
                    }

                    DoConfig(config);

                    // Handle Engine Ignitor
                    if (config.HasNode("ModuleEngineIgnitor"))
                    {
                        if (part.Modules.Contains("ModuleEngineIgnitor"))
                        {
                            ConfigNode eiNode = config.GetNode("ModuleEngineIgnitor");
                            if (eiNode.HasValue("ignitionsAvailable"))
                            {
                                int ignitions;
                                if (int.TryParse(eiNode.GetValue("ignitionsAvailable"), out ignitions))
                                {
                                    ignitions = ConfigIgnitions(ignitions);

                                    eiNode.SetValue("ignitionsAvailable", ignitions.ToString());
                                    if (eiNode.HasValue("ignitionsRemained"))
                                        eiNode.SetValue("ignitionsRemained", ignitions.ToString());
                                    else
                                        eiNode.AddValue("ignitionsRemained", ignitions.ToString());
                                }
                            }
                            if (!HighLogic.LoadedSceneIsEditor && !(HighLogic.LoadedSceneIsFlight && vessel != null && vessel.situation == Vessel.Situations.PRELAUNCH)) // fix for prelaunch
                            {
                                int remaining = (int)(part.Modules["ModuleEngineIgnitor"].GetType().GetField("ignitionsRemained").GetValue(part.Modules["ModuleEngineIgnitor"]));
                                if (eiNode.HasValue("ignitionsRemained"))
                                    eiNode.SetValue("ignitionsRemained", remaining.ToString());
                                else
                                    eiNode.AddValue("ignitionsRemained", remaining.ToString());
                            }
                            ConfigNode tNode = new ConfigNode("MODULE");
                            eiNode.CopyTo(tNode);
                            tNode.SetValue("name", "ModuleEngineIgnitor");
                            part.Modules["ModuleEngineIgnitor"].Load(tNode);
                        }
                        else // backwards compatible with EI nodes when using RF ullage etc.
                        {
                            ConfigNode eiNode = config.GetNode("ModuleEngineIgnitor");
                            if (eiNode.HasValue("ignitionsAvailable") && !config.HasValue("ignitions"))
                            {
                                config.AddValue("ignitions", eiNode.GetValue("ignitionsAvailable"));
                            }
                            if (eiNode.HasValue("useUllageSimulation") && !config.HasValue("ullage"))
                                config.AddValue("ullage", eiNode.GetValue("useUllageSimulation"));
                            if (eiNode.HasValue("isPressureFed") && !config.HasValue("pressureFed"))
                                config.AddValue("pressureFed", eiNode.GetValue("isPressureFed"));
                            if (!config.HasNode("IGNITOR_RESOURCE"))
                                foreach (ConfigNode resNode in eiNode.GetNodes("IGNITOR_RESOURCE"))
                                    config.AddNode(resNode);
                        }
                    }
                    if (config.HasValue("ignitions"))
                    {
                        int ignitions;
                        if ((!HighLogic.LoadedSceneIsFlight || (vessel != null && vessel.situation == Vessel.Situations.PRELAUNCH)))
                        {
                            if (int.TryParse(config.GetValue("ignitions"), out ignitions))
                            {
                                ignitions = ConfigIgnitions(ignitions);
                                config.SetValue("ignitions", ignitions.ToString());
                            }
                        }
                        else
                            config.RemoveValue("ignitions");
                    }

                    if (pModule is ModuleEnginesRF)
                        (pModule as ModuleEnginesRF).SetScale(1d);
                    pModule.Load(config);
                }
                // fix for editor NaN
                if (part.Resources.Contains("ElectricCharge") && part.Resources["ElectricCharge"].maxAmount < 0.1)
                { // hacking around a KSP bug here
                    part.Resources["ElectricCharge"].amount = 0;
                    part.Resources["ElectricCharge"].maxAmount = 0.1;
                }

                // set gimbal
                if (config.HasValue("gimbalRange"))
                {
                    float newGimbal = float.Parse(config.GetValue("gimbalRange"));
                    for (int m = 0; m < part.Modules.Count; ++m)
                    {
                        if (part.Modules[m] is ModuleGimbal)
                        {
                            ModuleGimbal g = part.Modules[m] as ModuleGimbal;
                            if (gimbalTransform.Equals("") || g.gimbalTransformName.Equals(gimbalTransform))
                            {
                                g.gimbalRange = newGimbal;
                                break;
                            }
                        }
                    }
                }
                if (config.HasValue("cost"))
                    configCost = scale * float.Parse(config.GetValue("cost"));
                else
                    configCost = 0f;

                UpdateOtherModules(config);

                // GUI disabled for now - UpdateTweakableMenu();

                // Finally, fire the modified event
                // more trouble than it is worth...
                /*if((object)(EditorLogic.fetch) != null && (object)(EditorLogic.fetch.ship) != null && HighLogic.LoadedSceneIsEditor)
                    GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);*/

                // fire config modified event
                /*if(HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight)
                    EngineConfigChanged();*/
                // do it manually
                List<Part> parts;
                if (HighLogic.LoadedSceneIsEditor && EditorLogic.fetch.ship != null)
                    parts = EditorLogic.fetch.ship.parts;
                else if (HighLogic.LoadedSceneIsFlight && vessel != null)
                    parts = vessel.parts;
                else parts = new List<Part>();
                for (int i = parts.Count - 1; i >= 0; --i)
                    parts[i].SendMessage("UpdateUsedBy");

                SetupFX();

                UpdateTFInterops(); // update TestFlight if it's installed
            }
            else
            {
                Debug.Log("*RFMEC* ERROR could not find configuration of name " + configuration + " and could find no fallback config.");
                Debug.Log("For part " + part.name + ", Current nodes:" + Utilities.PrintConfigs(configs));
            }
        }
Example #5
0
        public override void OnSave(ConfigNode node)
        {

            //print("a");
            
                //print("AGXFlightSave " + currentFlightNode);
                if(node.HasValue("LastSave"))
                {
                   // print("c");
                    lastAGXSave = Convert.ToInt32(node.GetValue("LastSave"));
                   // print("d");
                    node.RemoveValue("LastSave");
                }
                //print("e");
                //print("scensave1 " + currentFlightNode);
                ConfigNode flightToSave = AGXFlight.FlightSaveToFile(currentFlightNode);
                //print("f");
                lastAGXSave = lastAGXSave + 1;
                while (File.Exists(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExt" + lastAGXSave.ToString("00000") + ".cfg"))
                {
                    lastAGXSave = lastAGXSave + 1;
                }
               // print("g " + flightToSave);
                flightToSave.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExt" + lastAGXSave.ToString("00000") + ".cfg");
               //print("scensave2 " + flightToSave);
                node.AddValue("LastSave", lastAGXSave.ToString());
                //print("i");
            
           // print("j");
        }
Example #6
0
        public ConfigNode ExpandNode(ConfigNode node, int level)
        {
            // Handle min/max level
            int minLevel = ConfigNodeUtil.ParseValue<int>(node, "minLevel", 1);
            int maxLevel = ConfigNodeUtil.ParseValue<int>(node, "maxLevel", 3);
            if (level < minLevel || level > maxLevel)
            {
                return null;
            }

            ConfigNode newNode = new ConfigNode(node.name);

            foreach (ConfigNode.Value pair in node.values)
            {
                newNode.AddValue(pair.name, FormatString(pair.value));
            }

            foreach (ConfigNode overrideNode in node.GetNodes())
            {
                if (overrideNode.name == "EFFECT")
                {
                    continue;
                }

                if (overrideNode.HasValue(level.ToString()))
                {
                    if (newNode.HasValue(overrideNode.name))
                    {
                        newNode.RemoveValue(overrideNode.name);
                    }
                    if (overrideNode.HasValue(level.ToString()))
                    {
                        newNode.AddValue(overrideNode.name, FormatString(overrideNode.GetValue(level.ToString())));
                    }
                }
            }

            return newNode;
        }
Example #7
0
        public void Update()
        {
            //Debug.Log("Start update!");//print("lock " + InputLockManager.IsLocked(ControlTypes.ALL_SHIP_CONTROLS));
            //if ((ControlTypes.ALL_SHIP_CONTROLS & (ControlTypes)InputLockManager.lockMask) == 0)
            //{
            //    print("not Locked");
            //}
            //else
            //{
            //    print("locked");
            //}
            //print("AGXLock state " + AGXLockSet);
            string errLine = "1";
            try
            {
                bool RootPartExists = new bool();
                errLine = "2";
                try
                {
                    errLine = "3";
                    if (FlightGlobals.ActiveVessel.parts.Count > 0) //we are actually checking null here on teh try-catch block, the if statement is a dummy
                    {
                        errLine = "4";
                    }
                    errLine = "5";
                    RootPartExists = true;
                }
                catch
                {
                    errLine = "6";
                    RootPartExists = false;
                }
                errLine = "7";

                if (flightNodeIsLoaded)
                {
                    if (RootPartExists)
                    {

                        errLine = "8";
                        if (AGXRoot != FlightGlobals.ActiveVessel.rootPart) //root part change, refresh stuff
                        {
                            // print("AGX Root change");
                            bool isDocking = false;
                            bool isUndocking = false;
                            try
                            {
                                if (FlightGlobals.ActiveVessel.parts.Contains(AGXRoot))
                                {
                                    isDocking = true;
                                    // print("AGX: Is a dock ");// + AGXRoot.ConstructID + " " + FlightGlobals.ActiveVessel.rootPart.ConstructID);
                                }
                                else if (oldShipParts.Contains(FlightGlobals.ActiveVessel.rootPart))
                                {
                                    isUndocking = true;
                                    //print("AGX: is an undock");
                                    //only clear actions if not a docking event
                                }
                                else
                                {
                                    //print("AGX: vessel switch");
                                    //CurrentVesselActions.Clear();
                                }
                            }
                            catch
                            {
                                //print("AGX: something was null in docking check");
                            }
                            errLine = "8a";
                            //print("Root part changed, AGX reloading");
                            //print("Root prt ch");
                            //if(!overrideRootChange) //no longer using DockingEvent
                            //{
                            errLine = "8b";
                            //print("Root part changed, AGX reloading B");
                            //loadFinished = false;

                            //CurrentVesselActions.Clear(); //we have saved old ship so clear actions
                            //if (!isDocking && !isUndocking)
                            //{
                            //    CurrentVesselActions.Clear();
                            //}
                            errLine = "24";
                            if (isDocking) //is a docking maneuver
                            {
                                DockingEvent();
                                RefreshCurrentActions();
                            }
                            if (isUndocking)
                            {
                                CheckListForMultipleVessels();
                                //RefreshCurrentActions();
                            }
                            //else //not a docking or undocking, load single node //this else closed at line 3792
                            //{
                            if (!isUndocking && !isDocking)
                            {
                                ConfigNode oldVsl = new ConfigNode();
                                errLine = "8c";
                                if (AGXRoot != null)
                                {
                                    errLine = "9";
                                    // print("Root part changed, AGX reloadinga");
                                    oldVsl = new ConfigNode(AGXRoot.vessel.rootPart.flightID.ToString());
                                    if (AGXFlightNode.HasNode(AGXRoot.vessel.rootPart.flightID.ToString()))
                                    {
                                        errLine = "10";
                                        //print("Root part changed, AGX reloadingb");
                                        oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.rootPart.flightID.ToString());
                                        AGXFlightNode.RemoveNode(AGXRoot.vessel.rootPart.flightID.ToString());
                                    }
                                    else if (AGXFlightNode.HasNode(AGXRoot.vessel.id.ToString()))
                                    {
                                        errLine = "10";
                                        //print("Root part changed, AGX reloadingb");
                                        oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.id.ToString());
                                        AGXFlightNode.RemoveNode(AGXRoot.vessel.id.ToString());
                                    }
                                    errLine = "11";
                                    //print("Root part changed, AGX reloadingc");
                                    if (oldVsl.HasValue("name"))
                                    {
                                        oldVsl.RemoveValue("name");
                                    }
                                    oldVsl.AddValue("name", AGXRoot.vessel.vesselName);
                                    errLine = "12";
                                    // errLine = "13";
                                    if (oldVsl.HasValue("currentKeyset"))
                                    {
                                        oldVsl.RemoveValue("currentKeyset");
                                    }
                                    oldVsl.AddValue("currentKeyset", CurrentKeySetFlight.ToString());
                                    errLine = "13";
                                    //errLine = "14";
                                    if (oldVsl.HasValue("groupNames"))
                                    {
                                        oldVsl.RemoveValue("groupNames");
                                    }
                                    oldVsl.AddValue("groupNames", SaveGroupNames(""));
                                    errLine = "14";
                                    //errLine = "15";
                                    if (oldVsl.HasValue("groupVisibility"))
                                    {
                                        oldVsl.RemoveValue("groupVisibility");
                                    }
                                    oldVsl.AddValue("groupVisibility", SaveGroupVisibility(""));
                                    errLine = "15";
                                    //errLine = "16";
                                    if (oldVsl.HasValue("groupVisibilityNames"))
                                    {
                                        errLine = "15b";
                                        oldVsl.RemoveValue("groupVisibilityNames");
                                        errLine = "15c";
                                    }
                                    errLine = "15d";

                                    oldVsl.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                                    errLine = "16";
                                    if (oldVsl.HasValue("DirectActionState"))
                                    {
                                        errLine = "16b";
                                        oldVsl.RemoveValue("DirectActionState");
                                        errLine = "16c";
                                    }
                                    errLine = "16d";

                                    oldVsl.AddValue("DirectActionState", SaveDirectActionState(""));

                                    oldVsl.RemoveNodes("PART");

                                    foreach (Part p in AGXRoot.vessel.Parts)
                                    {
                                        errLine = "17";
                                        List<AGXAction> thisPartsActions = new List<AGXAction>();
                                        errLine = "18 ";
                                        //print("part 18a" + p.ConstructID + " " + CurrentVesselActions);
                                        thisPartsActions.AddRange(StaticData.CurrentVesselActions.FindAll(p2 => p2.ba.listParent.part == p));
                                        errLine = "18a";

                                        //errLine = "18";
                                        if (thisPartsActions.Count > 0)
                                        {
                                            errLine = "18b";
                                            ConfigNode partTemp = new ConfigNode("PART");
                                            errLine = "19";
                                            partTemp.AddValue("name", p.vessel.vesselName);
                                            partTemp.AddValue("vesselID", p.vessel.id);
                                            //partTemp.AddValue("relLocX", AGXRoot.vessel.rootPart.transform.InverseTransformPoint(p.transform.position).x);
                                            //partTemp.AddValue("relLocY", AGXRoot.vessel.rootPart.transform.InverseTransformPoint(p.transform.position).y);
                                            //partTemp.AddValue("relLocZ", AGXRoot.vessel.rootPart.transform.InverseTransformPoint(p.transform.position).z);
                                            partTemp.AddValue("flightID", p.flightID.ToString());
                                            errLine = "20";
                                            foreach (AGXAction agxAct in thisPartsActions)
                                            {
                                                errLine = "21";
                                                partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                                            }
                                            errLine = "22";

                                            oldVsl.AddNode(partTemp);
                                            errLine = "23";
                                        }
                                        errLine = "24";
                                    }

                                    //print("AGX Save old vessel "+ oldVsl);
                                    AGXFlightNode.AddNode(oldVsl);
                                    //print("Root part changed, AGX reloadingd " + oldVsl.GetValue("groupNames"));
                                }
                                errLine = "24a";

                                StaticData.CurrentVesselActions.Clear();
                                errLine = "24b";
                            }
                            errLine = "24c";
                            if (!isDocking)
                            {

                                errLine = "24d";
                                bool checkIsVab = true;
                                ConfigNode vslNode = new ConfigNode();
                                try
                                {
                                    if (FlightGlobals.ActiveVessel.landedAt == "Runway")
                                    {
                                        //print("Runway found");
                                        checkIsVab = false;
                                    }
                                    else
                                    {
                                        //print("runway not found");
                                        checkIsVab = true;
                                    }

                                }
                                catch
                                {
                                    //print("runway iffy");
                                    checkIsVab = true;
                                }
                                errLine = "24e";
                                if (AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.id.ToString()))
                                {
                                    //print("AGX flight node found");
                                    vslNode = AGXFlightNode.GetNode(FlightGlobals.ActiveVessel.id.ToString());

                                }
                                else if (AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()))
                                {
                                    // print("AGX flightID found");
                                    vslNode = AGXFlightNode.GetNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString());

                                }
                                //else if(RootParts.HasNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()) && AGXRoot != null)  //replace with previously docked ship check, in other parts of code
                                //{
                                //    print("AGX root part found");
                                //    vslNode = oldVsl;
                                //    ConfigNode FoundRootPart = RootParts.GetNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString());
                                //    vslNode.RemoveValue("currentKeyset");
                                //    vslNode.AddValue("currentKeyset", FoundRootPart.GetValue("currentKeyset"));
                                //    vslNode.RemoveValue("groupVisibility");
                                //    vslNode.AddValue("groupVisibility", FoundRootPart.GetValue("groupVisibility"));
                                //    vslNode.RemoveValue("groupVisibilityNames");
                                //    vslNode.AddValue("groupVisibilityNames", FoundRootPart.GetValue("groupVisibilityNames"));
                                //    ShowAmbiguousMessage = false;
                                //}

                                else if (AGXEditorNodeFlight.HasNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, checkIsVab)))
                                {
                                    // print("AGX VAB1 ");// + FlightGlobals.ActiveVessel.vesselName + " " + FlightGlobals.ActiveVessel.rootPart.ConstructID);
                                    vslNode = AGXEditorNodeFlight.GetNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, checkIsVab));
                                    vslNode.name = FlightGlobals.ActiveVessel.rootPart.flightID.ToString();
                                    AGXFlightNode.AddNode(vslNode);
                                    // print("node check " + vslNode.ToString());
                                }
                                else if (AGXEditorNodeFlight.HasNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, !checkIsVab)))
                                {
                                    //print("AGX vab2");
                                    vslNode = AGXEditorNodeFlight.GetNode(AGextScenario.EditorHashShipName(FlightGlobals.ActiveVessel.vesselName, !checkIsVab));
                                    vslNode.name = FlightGlobals.ActiveVessel.rootPart.flightID.ToString();
                                    AGXFlightNode.AddNode(vslNode);
                                }
                                else
                                {
                                    //print("AGX notfound");
                                    vslNode = new ConfigNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString());
                                    vslNode.AddValue("name", FlightGlobals.ActiveVessel.vesselName);
                                    vslNode.AddValue("currentKeyset", "1");
                                    vslNode.AddValue("groupNames", "");
                                    vslNode.AddValue("groupVisibility", "1011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111011111");
                                    vslNode.AddValue("groupVisibilityNames", "Group 1‣Group 2‣Group 3‣Group 4‣Group 5");
                                    vslNode.AddValue("DirectActionState", "");
                                    AGXFlightNode.AddNode(vslNode);
                                }
                                errLine = "24f";
                                CurrentKeySetFlight = Convert.ToInt32((string)vslNode.GetValue("currentKeyset"));
                                //LoadCurrentKeyBindings();
                                try
                                {
                                    if (CurrentKeySetFlight < 1 || CurrentKeySetFlight > 5)
                                    {
                                        CurrentKeySetFlight = 1;
                                    }
                                }
                                catch
                                {
                                    CurrentKeySetFlight = 1;
                                }
                                CurrentKeySetNameFlight = KeySetNamesFlight[CurrentKeySetFlight - 1];
                                LoadGroupNames(vslNode.GetValue("groupNames"));
                                LoadGroupVisibility(vslNode.GetValue("groupVisibility"));
                                LoadGroupVisibilityNames(vslNode.GetValue("groupVisibilityNames"));
                                //Debug.Log(vslNode);
                                if (vslNode.HasValue("DirectActionState"))
                                {
                                    //Debug.Log("has state");
                                    LoadDirectActionState(vslNode.GetValue("DirectActionState"));
                                }
                                else
                                {
                                    //Debug.Log("no state");
                                    LoadDirectActionState("");
                                }
                                errLine = "24fg";
                                foreach (ConfigNode prtNode in vslNode.nodes)
                                {

                                    float partDist = 100f;
                                    Part gamePart = new Part();
                                    if (prtNode.HasValue("flightID"))
                                    {
                                        errLine = "24h";
                                        try
                                        {
                                            uint flightIDFromFile = Convert.ToUInt32(prtNode.GetValue("flightID"));
                                            gamePart = FlightGlobals.ActiveVessel.parts.First(prt => prt.flightID == flightIDFromFile);
                                            partDist = 0f;
                                        }
                                        catch
                                        {
                                            continue; //bad FLightID in file, skip this action
                                        }
                                    }

                                    else
                                    {
                                        errLine = "24i";
                                        foreach (Part p in FlightGlobals.ActiveVessel.parts) //do a distance compare check, floats do not guarantee perfect decimal accuray so use part with least distance, should be zero distance in most cases
                                        {
                                            Vector3 partLoc = new Vector3((float)Convert.ToDouble(prtNode.GetValue("relLocX")), (float)Convert.ToDouble(prtNode.GetValue("relLocY")), (float)Convert.ToDouble(prtNode.GetValue("relLocZ")));
                                            float thisPartDist = Vector3.Distance(partLoc, FlightGlobals.ActiveVessel.rootPart.transform.InverseTransformPoint(p.transform.position));
                                            if (thisPartDist < partDist)
                                            {
                                                gamePart = p;
                                                partDist = thisPartDist;
                                            }
                                        }
                                    }
                                    bool ShowAmbiguousMessage2 = true; //show actions ambiguous message?
                                    errLine = "24j";
                                    //if (ShowAmbiguousMessage && partDist < 0.3f)
                                    if (partDist < 0.3f)//do not show it if part found is more then 0.3meters off
                                    {
                                        ShowAmbiguousMessage2 = true;
                                    }
                                    else
                                    {
                                        ShowAmbiguousMessage2 = false;
                                    }
                                    errLine = "24k";
                                    //print("gamepart " + gamePart.ConstructID + " " + partDist);
                                    foreach (ConfigNode actNode in prtNode.nodes)
                                    {
                                        //print("node " + actNode + " " + gamePart.ConstructID);
                                        AGXAction actToAdd = AGextScenario.LoadAGXActionVer2(actNode, gamePart, ShowAmbiguousMessage2);
                                        //print("act to add " + actToAdd.ba);
                                        if (actToAdd.ba != null && !StaticData.CurrentVesselActions.Contains(actToAdd))
                                        {
                                            StaticData.CurrentVesselActions.Add(actToAdd);
                                        }
                                    }
                                }
                                errLine = "24l";
                                List<KSPActionGroup> CustomActions = new List<KSPActionGroup>();
                                CustomActions.Add(KSPActionGroup.Custom01); //how do you add a range from enum?
                                CustomActions.Add(KSPActionGroup.Custom02);
                                CustomActions.Add(KSPActionGroup.Custom03);
                                CustomActions.Add(KSPActionGroup.Custom04);
                                CustomActions.Add(KSPActionGroup.Custom05);
                                CustomActions.Add(KSPActionGroup.Custom06);
                                CustomActions.Add(KSPActionGroup.Custom07);
                                CustomActions.Add(KSPActionGroup.Custom08);
                                CustomActions.Add(KSPActionGroup.Custom09);
                                CustomActions.Add(KSPActionGroup.Custom10);

                                //errLine = "16";
                                // string AddGroup = "";
                                List<BaseAction> partAllActions = new List<BaseAction>(); //is all vessel actions, copy pasting code
                                foreach (Part p in FlightGlobals.ActiveVessel.parts)
                                {
                                    partAllActions.AddRange(p.Actions);
                                    foreach (PartModule pm in p.Modules)
                                    {
                                        partAllActions.AddRange(pm.Actions);
                                    }

                                    //foreach (BaseAction ba in partAllActions)
                                    //{
                                    //    print(ba.listParent.part + " " + ba.listParent.module.moduleName + " " + ba.name + " " + ba.guiName);
                                    //}
                                    // print("part orgpos " + p.ConstructID+ " "  + p.orgPos + " " + p.orgRot);
                                }
                                errLine = "24m";
                                foreach (BaseAction baLoad in partAllActions)
                                {
                                    foreach (KSPActionGroup agrp in CustomActions)
                                    {

                                        if ((baLoad.actionGroup & agrp) == agrp)
                                        {
                                            // errLine = "17";
                                            ////AddGroup = AddGroup + '\u2023' + (CustomActions.IndexOf(agrp) + 1).ToString("000") + baLoad.guiName;
                                            //partAGActions2.Add(new AGXAction() { group = CustomActions.IndexOf(agrp) + 1, prt = this.part, ba = baLoad, activated = false });
                                            AGXAction ToAdd = new AGXAction() { prt = baLoad.listParent.part, ba = baLoad, group = CustomActions.IndexOf(agrp) + 1, activated = false };
                                            List<AGXAction> Checking = new List<AGXAction>();
                                            Checking.AddRange(StaticData.CurrentVesselActions);
                                            Checking.RemoveAll(p => p.group != ToAdd.group);

                                            Checking.RemoveAll(p => p.prt != ToAdd.prt);

                                            Checking.RemoveAll(p => p.ba != ToAdd.ba);

                                            if (Checking.Count == 0)
                                            {

                                                StaticData.CurrentVesselActions.Add(ToAdd);

                                            }
                                        }
                                    }
                                    // errLine = "18";
                                }
                            }
                            //} //close backet on else statment that this is not dock/undock

                            errLine = "32";

                            AGXRoot = FlightGlobals.ActiveVessel.rootPart;
                            oldShipParts = new List<Part>(FlightGlobals.ActiveVessel.parts);

                            errLine = "32a";

                            overrideRootChange = false;
                            LastPartCount = FlightGlobals.ActiveVessel.parts.Count;
                            AGEditorSelectedParts.Clear();
                            PartActionsList.Clear();
                            RefreshCurrentActions();
                            loadFinished = true;
                            //print("sit " + FlightGlobals.ActiveVessel.situation.ToString());
                            errLine = "33";
                            CurrentKeySetNameFlight = KeySetNamesFlight[CurrentKeySetFlight - 1];
                            LoadCurrentKeyBindings();
                            errLine = "33a";
                            FlightSaveToFile(AGXFlightNode);//add save current vessel here
                            errLine = "33b";
                        }
                    }
                    errLine = "34";
                    if (LastPartCount != FlightGlobals.ActiveVessel.parts.Count) //parts count changed, remove any actions assigned to parts that have disconnected/been destroyed
                    {
                        print("Part count change, reload AGX");
                        if (FlightGlobals.ActiveVessel.parts.Count > LastPartCount)
                        {
                            DockingEvent();
                        }
                        else if (LastPartCount > FlightGlobals.ActiveVessel.parts.Count) //new count is larger was a docking op, see the dock gameevent to handle that //chaged again
                        {
                            CheckListForMultipleVessels();
                        }
                        AGEditorSelectedParts.Clear();
                        PartActionsList.Clear();
                        //LoadActionGroups();
                        RefreshCurrentActions();
                        LastPartCount = FlightGlobals.ActiveVessel.parts.Count;
                        oldShipParts = new List<Part>(FlightGlobals.ActiveVessel.parts);
                        errLine = "35";

                    }
                }
                errLine = "36";

                if (InputLockManager.GetControlLock("kOSTerminal") == ControlTypes.None && (ControlTypes.KSC_ALL & (ControlTypes)InputLockManager.lockMask) == 0)// && InputLockManager.IsLocked(ControlTypes.All))//&& !InputLockManager.IsLocked(ControlTypes.All))
                {

                    foreach (KeyCode KC in ActiveKeys)
                    {

                        errLine = "37";
                        if (Input.GetKeyDown(KC))
                        {
                            //print("keydown " + KC);
                            for (int i = 1; i <= 250; i = i + 1)
                            {
                                if (AGXguiKeys[i] == KC)
                                {
                                    //print("Key act for some reason " + i);
                                    ActivateActionGroupCheckModKeys(i);
                                }
                            }
                        }
                    }

                    foreach (KeyValuePair<int, KeyCode> kcPair in ActiveKeysDirect)
                    {
                        if (Input.GetKey(kcPair.Value) && !DirectKeysState[kcPair.Key])
                        {
                            ActivateActionGroupCheckModKeys(kcPair.Key, true, true);
                            DirectKeysState[kcPair.Key] = true;
                            //Debug.Log("turn on");
                        }
                        else if (!Input.GetKey(kcPair.Value) && DirectKeysState[kcPair.Key])
                        {
                            ActivateActionGroupCheckModKeys(kcPair.Key, true, false);
                            DirectKeysState[kcPair.Key] = false;
                            //Debug.Log("turn off");
                        }
                    }
                    foreach (KeyValuePair<int, KeyCode> kcPair2 in DefaultTen) //toggle groups if no actions are assigned
                    {
                        if (Input.GetKeyDown(kcPair2.Value))
                        {
                            if (AGXguiMod1Groups[kcPair2.Key] == Input.GetKey(AGXguiMod1Key) && AGXguiMod2Groups[kcPair2.Key] == Input.GetKey(AGXguiMod2Key))
                            {
                                if (kcPair2.Key <= 10)
                                {
                                    Dictionary<int, KSPActionGroup> CustomActions = new Dictionary<int, KSPActionGroup>();
                                    CustomActions.Add(1, KSPActionGroup.Custom01); //how do you add a range from enum?
                                    CustomActions.Add(2, KSPActionGroup.Custom02);
                                    CustomActions.Add(3, KSPActionGroup.Custom03);
                                    CustomActions.Add(4, KSPActionGroup.Custom04);
                                    CustomActions.Add(5, KSPActionGroup.Custom05);
                                    CustomActions.Add(6, KSPActionGroup.Custom06);
                                    CustomActions.Add(7, KSPActionGroup.Custom07);
                                    CustomActions.Add(8, KSPActionGroup.Custom08);
                                    CustomActions.Add(9, KSPActionGroup.Custom09);
                                    CustomActions.Add(10, KSPActionGroup.Custom10);
                                    FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(CustomActions[kcPair2.Key]);
                                    groupActivatedState[kcPair2.Key] = FlightGlobals.ActiveVessel.ActionGroups[CustomActions[kcPair2.Key]];
                                }
                                else
                                {
                                    groupActivatedState[kcPair2.Key] = !groupActivatedState[kcPair2.Key];
                                }
                            }
                        }
                    }
                }
                errLine = "38";
                //if (!ActiveActionsCalculated)
                //{
                //    CalculateActiveActions();
                // Debug.Log("AGX update middel A");
                //}
                if (Input.GetKeyDown(KeyCode.Mouse0) && ShowSelectedWin)
                {
                    errLine = "39";
                    Part selPart = new Part();
                    selPart = SelectPartUnderMouse();
                    if (selPart != null)
                    {
                        AddSelectedPart(selPart);
                    }
                    errLine = "40";
                }
                //Debug.Log("AGX update middel b");
                errLine = "41";
                if (RightClickDelay < 3)
                {
                    errLine = "42";
                    if (RightClickDelay == 2)
                    {
                        errLine = "43";
                        UIPartActionWindow UIPartsListThing = new UIPartActionWindow();
                        UIPartsListThing = (UIPartActionWindow)FindObjectOfType(typeof(UIPartActionWindow));
                        //UnityEngine.Object[] TempObj = FindObjectsOfType(typeof(UIPartActionWindow));
                        //print(TempObj.Length);
                        try
                        {
                            if (UIPartsListThing != null)
                            {
                                AddSelectedPart(UIPartsListThing.part);
                            }
                            // print(UIPartsListThing.part.name); //finds part right-clicked on
                            RightLickPartAdded = true;
                        }
                        catch
                        {
                            // print("nope!");
                            RightLickPartAdded = true;
                        }
                    }

                    RightClickDelay = RightClickDelay + 1;

                    errLine = "44";
                }
                //Debug.Log("AGX update middel c");
                errLine = "45";

                if (Input.GetKeyUp(KeyCode.Mouse1) && ShowSelectedWin && RightLickPartAdded == true)
                {
                    RightClickDelay = 0;
                    RightLickPartAdded = false;

                }
                errLine = "46";
                // Debug.Log("AGX update middel d");
                //foreach (Part p in FlightGlobals.ActiveVessel.Parts)
                //{
                //    foreach (PartModule pm in p.Modules)
                //    {
                //        foreach (BaseAction ba in pm.Actions)
                //        {
                //            print(p.partName + " " + pm.moduleName + " " + ba.name + " " + ba.guiName);
                //        }
                //    }
                //}
                if (ShowAGXMod)
                {
                    if (actionsCheckFrameCount >= 15) //this increments in the FixedUpdate frame now
                    {
                        CheckActionsActive();
                        //PartVesselChangeCheck();
                        actionsCheckFrameCount = 0;
                    }
                }
                //else
                //{
                //    actionsCheckFrameCount = actionsCheckFrameCount + (int)(Time.deltaTime * 1000f);
                //}
                //print("delta time " + actionsCheckFrameCount);
                errLine = "47";
                //Debug.Log("AGX update middel e2");
                //count down action cool downs
                groupCooldowns.RemoveAll(cd => cd.delayLeft > activationCoolDown); //remove actions from list that are finished cooldown, cooldown is in Update frame passes, pulled from .cfg
                foreach (AGXCooldown agCD in groupCooldowns)
                {
                    agCD.delayLeft = agCD.delayLeft + 1;

                }
                //Debug.Log("AGX update middel e");
                errLine = "48";
                if (RTFound)
                {
                    CheckRTQueue();
                }
                //Debug.Log("AGX update middel f");
                errLine = "49";
                //PrintPartActs();
                //print("landed " + FlightGlobals.ActiveVessel.landedAt);

                //if (test == null)
                //{
                //    Debug.Log("NULL");
                //}
                //else
                //{
                //    Debug.Log("found " + test.nodes.Count + " " + test.values.Count);
                //}
                //Debug.Log("btn font " + HighLogic.Skin.font +);// AGXBtnStyle.font + AGXBtnStyle.fontSize + AGXBtnStyle.fontStyle);
                //Debug.Log("End update!");
            }
            catch (Exception e)
            {
                print("AGX Update error: " + errLine + " " + e);
            }
        }
Example #8
0
        //call this when part count on vessel decrease to check for actions on split vessels
        public void CheckListForMultipleVessels()
        {
            //print("call checklistformulti");
            List<Vessel> curActsVessels = new List<Vessel>(); //find out if actions exist on vessel that left
            foreach (AGXAction agAct in StaticData.CurrentVesselActions)
            {
                if (!curActsVessels.Contains(agAct.ba.listParent.part.vessel))
                {
                    curActsVessels.Add(agAct.ba.listParent.part.vessel); //make a list of all vessels from actions in currentVesselActions list
                }
            }

            foreach (Vessel vsl2 in curActsVessels) //our list of vessels from actions in currentVesselActions lsit
            {
                if (vsl2 != FlightGlobals.ActiveVessel) //this runs only on the seperated vessel, not our focus vessel
                {
                    ConfigNode vsl2node = new ConfigNode(vsl2.rootPart.flightID.ToString()); //make our confignode
                    if (AGXFlightNode.HasNode(vsl2.rootPart.flightID.ToString())) //does this vessel exist in flight node?
                    {
                        vsl2node = AGXFlightNode.GetNode(vsl2.rootPart.flightID.ToString()); //vessel exists?  load existing node, this should not happend but might if the same vessel docks/undocks in the same scene multiple times
                        vsl2node.RemoveNodes("PART");
                        AGXFlightNode.RemoveNode(vsl2.rootPart.flightID.ToString());
                    }
                    else if (AGXFlightNode.HasNode(vsl2.id.ToString())) //does this vessel exist in flight node?
                    {
                        vsl2node = AGXFlightNode.GetNode(vsl2.id.ToString()); //vessel exists?  load existing node, this should not happend but might if the same vessel docks/undocks in the same scene multiple times
                        vsl2node.RemoveNodes("PART");
                        AGXFlightNode.RemoveNode(vsl2.id.ToString());
                    }
                    //RootPart elseif check here
                    else //new vessel, copy current values
                    {
                        vsl2node.AddValue("name", FlightGlobals.ActiveVessel.vesselName);
                        vsl2node.AddValue("currentKeyset", CurrentKeySetFlight.ToString());
                        //vsl2node.AddValue("groupNames", SaveGroupNames(""));
                        vsl2node.AddValue("groupVisibility", SaveGroupVisibility(""));
                        vsl2node.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                        vsl2node.AddValue("DirectActionState", SaveDirectActionState(""));
                    }
                    if (vsl2node.HasValue("groupNames"))
                    {
                        vsl2node.RemoveValue("groupNames");
                    }
                    vsl2node.AddValue("groupNames", SaveGroupNames(""));
                    foreach (Part p in vsl2.Parts) //cycle parts in separated vessel to find actions
                    {
                        List<AGXAction> thisPartsActions = new List<AGXAction>();
                        thisPartsActions.AddRange(StaticData.CurrentVesselActions.FindAll(p2 => p2.ba.listParent.part == p));
                        //errLine = "18";
                        if (thisPartsActions.Count > 0)
                        {
                            //print("acts count " + thisPartsActions.Count);
                            ConfigNode partTemp = new ConfigNode("PART");
                            //errLine = "19";
                            partTemp.AddValue("name", p.vessel.vesselName);
                            partTemp.AddValue("vesselID", p.vessel.id);
                            partTemp.AddValue("flightID", p.flightID.ToString());
                            // partTemp.AddValue("relLocX", vsl2.rootPart.transform.InverseTransformPoint(p.transform.position).x);
                            //partTemp.AddValue("relLocY", vsl2.rootPart.transform.InverseTransformPoint(p.transform.position).y);
                            //partTemp.AddValue("relLocZ", vsl2.rootPart.transform.InverseTransformPoint(p.transform.position).z);
                            //errLine = "20";
                            foreach (AGXAction agxAct in thisPartsActions)
                            {
                                //print("acts countb " + thisPartsActions.Count);
                                //errLine = "21";
                                partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                            }
                            //errLine = "22";

                            vsl2node.AddNode(partTemp);
                            //errLine = "23";
                        }
                    }

                    AGXFlightNode.AddNode(vsl2node);
                    StaticData.CurrentVesselActions.RemoveAll(ag => ag.ba.listParent.part.vessel == vsl2);

                }
            }
            RefreshCurrentActions();
        }
Example #9
0
        public void VesselOnRails(Vessel vsl)
        {
            print("Vessel on rails! " + vsl.name );
            partOldVessel.RemoveAll(vsl2 => vsl2.pVsl == vsl);
            List<AGXAction> UnloadVslActionsCheck = new List<AGXAction>();
            UnloadVslActionsCheck.AddRange(AllVesselsActions.Where(agx => agx.ba.listParent.part.vessel == vsl));
            //print("count check " + UnloadVslActionsCheck.Count + vsl.id.ToString());
            //foreach (AGXAction agact in UnloadVslActionsCheck)
            //{
            //    print("actionunload " + agact.ba.listParent.part.vessel.id.ToString() + " " + agact.ba.listParent.part.ConstructID);
            //}
            if (UnloadVslActionsCheck.Count > 0)
            {
                ConfigNode vslToUnload = new ConfigNode(vsl.id.ToString());
                if(AGXFlightNode.HasNode(vsl.id.ToString()))
                {
                    vslToUnload = AGXFlightNode.GetNode(vsl.id.ToString());
                    vslToUnload.RemoveNodes("PART");
                    AGXFlightNode.RemoveNode(vsl.id.ToString());
                }

                if (vsl == FlightGlobals.ActiveVessel)
                {
                    if(vslToUnload.HasValue("name"))
                    {
                        vslToUnload.RemoveValue("name");
                    }
                    vslToUnload.AddValue("name",FlightGlobals.ActiveVessel.vesselName);
                    if (vslToUnload.HasValue("currentKeyset"))
                    {
                        vslToUnload.RemoveValue("currentKeyset");
                    }
                    vslToUnload.AddValue("currentKeyset", CurrentKeySet.ToString());
                    if (vslToUnload.HasValue("groupNames"))
                    {
                        vslToUnload.RemoveValue("groupNames");
                    }
                    vslToUnload.AddValue("groupNames", SaveGroupNames(""));
                    if (vslToUnload.HasValue("groupVisibility"))
                    {
                        vslToUnload.RemoveValue("groupVisibility");
                    }
                    vslToUnload.AddValue("groupVisibility", SaveGroupVisibility(""));
                    if (vslToUnload.HasValue("groupVisibilityNames"))
                    {
                        vslToUnload.RemoveValue("groupVisibilityNames");
                    }
                    vslToUnload.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                }

                foreach (Part p in vsl.Parts)
                {
                    List<AGXAction> thisPartsActions = new List<AGXAction>();
                    thisPartsActions.AddRange(UnloadVslActionsCheck.FindAll(p2 => p2.ba.listParent.part == p));
                    //errLine = "18";
                    if (thisPartsActions.Count > 0)
                    {
                        ConfigNode partTemp = new ConfigNode("PART");
                        //errLine = "19";
                        partTemp.AddValue("name", p.vessel.vesselName);
                        partTemp.AddValue("vesselID", p.vessel.id);
                        partTemp.AddValue("relLocX", p.orgPos.x);
                        partTemp.AddValue("relLocY", p.orgPos.y);
                        partTemp.AddValue("relLocZ", p.orgPos.z);
                        //errLine = "20";
                        foreach (AGXAction agxAct in thisPartsActions)
                        {
                            //errLine = "21";
                            partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                        }
                       // errLine = "22";

                        vslToUnload.AddNode(partTemp);
                        //errLine = "23";
                    }
                }
                AGXFlightNode.AddNode(vslToUnload);
            }
            AllVesselsActions.RemoveAll(act2 => act2.ba.listParent.part.vessel == vsl);
            loadedVessels.Remove(vsl); //remove vessel from loaded vessels list

        }
Example #10
0
        public static ConfigNode FlightSaveToFile(ConfigNode origNode)  
        {
            //print("FlightSaveToFile " + AGXFlightNode);
            
            string errLine = "1";
            try
            {
                if (loadFinished)
                {
                    List<AGXAction> actionsToSave = new List<AGXAction>();
                    actionsToSave.AddRange(AllVesselsActions.Where(ag => ag.ba != null));
                    //foreach (AGXAction agAct in actionsToSave)
                    //{
                    //    print("FlightSave " + agAct.ba.name + " " + agAct.ba.listParent.part.ConstructID);
                    //}
                    if(loadedVessels.Contains(FlightGlobals.ActiveVessel))
                    {
                    ConfigNode thisVsl = new ConfigNode(FlightGlobals.ActiveVessel.id.ToString());
                    ConfigNode thisRootPart = new ConfigNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()); //copy values to root part save for future undockings
                    thisVsl.AddValue("name", FlightGlobals.ActiveVessel.vesselName);
                    thisRootPart.AddValue("name", thisVsl.GetValue("name")); //get the value from confignode rather then running all the calculations again, i think it's less processing
                    errLine = "13";
                    thisVsl.AddValue("currentKeyset", CurrentKeySet.ToString());
                    thisRootPart.AddValue("currentKeyset", thisVsl.GetValue("currentKeyset"));
                    errLine = "14";
                    thisVsl.AddValue("groupNames", SaveGroupNames(""));
                    thisRootPart.AddValue("groupNames", thisVsl.GetValue("groupNames"));
                    errLine = "15";
                    thisVsl.AddValue("groupVisibility", SaveGroupVisibility(""));
                    thisRootPart.AddValue("groupVisibility", thisVsl.GetValue("groupVisibility"));
                    errLine = "16";
                    thisVsl.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                    thisRootPart.AddValue("groupVisibilityNames", thisVsl.GetValue("groupVisibilityNames"));
                    errLine = "17";

                        if(RootParts.HasNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString()))
                        {
                            RootParts.RemoveNode(FlightGlobals.ActiveVessel.rootPart.flightID.ToString());
                        }
                        RootParts.AddNode(thisRootPart);
                        RootParts.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExtRootParts.cfg");

                        


                    foreach (Part p in FlightGlobals.ActiveVessel.Parts)
                    {
                        List<AGXAction> thisPartsActions = new List<AGXAction>();
                        thisPartsActions.AddRange(actionsToSave.FindAll(p2 => p2.ba.listParent.part == p));
                        errLine = "18";
                        if (thisPartsActions.Count > 0)
                        {
                            //print("acts count " + thisPartsActions.Count);
                            ConfigNode partTemp = new ConfigNode("PART");
                            errLine = "19";
                            partTemp.AddValue("name", p.vessel.vesselName);
                            partTemp.AddValue("vesselID", p.vessel.id);
                            partTemp.AddValue("relLocX", p.orgPos.x);
                            partTemp.AddValue("relLocY", p.orgPos.y);
                            partTemp.AddValue("relLocZ", p.orgPos.z);
                            errLine = "20";
                            foreach (AGXAction agxAct in thisPartsActions)
                            {
                                //print("acts countb " + thisPartsActions.Count);
                                errLine = "21";
                                partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                            }
                            errLine = "22";

                            thisVsl.AddNode(partTemp);
                            errLine = "23";
                        }
                    }
                    if (AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.id.ToString()))
                    {
                        AGXFlightNode.RemoveNode(FlightGlobals.ActiveVessel.id.ToString());
                    }
                    AGXFlightNode.AddNode(thisVsl);
                }
                    actionsToSave.RemoveAll(p3 => p3.ba.listParent.part.vessel == FlightGlobals.ActiveVessel);
                    //print("step1");

                    //foreach (AGXAction agAct in actionsToSave)
                    //{
                    //    print("FlightSaveFocusDone " + agAct.ba.name + " " + agAct.ba.listParent.part.ConstructID);
                    //}
                    //print("step2");
                    while (actionsToSave.Count > 0)
                    {
                        //print("step3");
                        //foreach (AGXAction agAct in actionsToSave)
                        //{
                        //    print("FlightSaveWhile " + agAct.ba.name + " " + agAct.ba.listParent.part.ConstructID);
                        //}
                        //print("step4");
                        Vessel vslToSave = actionsToSave.First().ba.listParent.part.vessel;
                        if(loadedVessels.Contains(vslToSave))
                        {
                        
                        ConfigNode thisVslNode = new ConfigNode(vslToSave.id.ToString());
                        if (AGXFlightNode.HasNode(vslToSave.id.ToString()))
                        {
                            thisVslNode = AGXFlightNode.GetNode(vslToSave.id.ToString());
                            thisVslNode.RemoveValue("name");
                            thisVslNode.AddValue("name", vslToSave.vesselName);
                        }
                        else
                        {
                            thisVslNode.AddValue("name", vslToSave.vesselName);
                            errLine = "13";
                            thisVslNode.AddValue("currentKeyset", "1");
                            errLine = "14";
                            thisVslNode.AddValue("groupNames", "");
                            errLine = "15";
                            thisVslNode.AddValue("groupVisibility", "");
                            errLine = "16";
                            thisVslNode.AddValue("groupVisibilityNames", "");
                        }
                        thisVslNode.RemoveNodes("PART");


                        foreach (Part p in vslToSave.parts)
                        {
                            List<AGXAction> thisPartsActions = new List<AGXAction>();
                            thisPartsActions.AddRange(actionsToSave.FindAll(p2 => p2.prt == p));
                            errLine = "18";
                            if (thisPartsActions.Count > 0)
                            {
                                ConfigNode partTemp = new ConfigNode("PART");
                                errLine = "19";
                                partTemp.AddValue("name", p.vessel.name);
                                partTemp.AddValue("vesselID", vslToSave.id.ToString());
                                partTemp.AddValue("relLocX", p.orgPos.x);
                                partTemp.AddValue("relLocY", p.orgPos.y);
                                partTemp.AddValue("relLocZ", p.orgPos.z);
                                errLine = "20";
                                foreach (AGXAction agxAct in thisPartsActions)
                                {
                                    errLine = "21";
                                    partTemp.AddNode(AGextScenario.SaveAGXActionVer2(agxAct));
                                }
                                errLine = "22";

                                thisVslNode.AddNode(partTemp);
                                errLine = "23";
                            }
                        }
                        
                        if (AGXFlightNode.HasNode(vslToSave.id.ToString()))
                        {
                            AGXFlightNode.RemoveNode(vslToSave.id.ToString());
                        }
                        AGXFlightNode.AddNode(thisVslNode);
                        }
                        actionsToSave.RemoveAll(p3 => p3.ba.listParent.part.vessel == vslToSave);
                        if (vslToSave.loaded == false)
                        {
                            AllVesselsActions.RemoveAll(p4 => p4.ba.listParent.part.vessel == vslToSave);
                        }
                    }
                    //AGXBaseNode.RemoveNode("FLIGHT");
                    //AGXBaseNode.AddNode(AGXFlightNode);
                    //AGXBaseNode.Save(new DirectoryInfo(KSPUtil.ApplicationRootPath).FullName + "saves/" + HighLogic.SaveFolder + "/AGExt.cfg");
                    return AGXFlightNode;
                }
                else
                {
                    return origNode;
                }
                //while(AllVesselsActions.Count>0)
                //{
                //    Vessel vslSaving = AllVesselsActions.First().prt.vessel;
                //    ConfigNode vslNode = new ConfigNode();

                //}
                //print("save 2g " + loadFinished + " " + AGXFlightNode);

                



                
            }
            catch (Exception e)
            {
                print("FlightSaveToFile error " + errLine + " " + e);
                return origNode;
            }
        }
Example #11
0
        public void Update()
        {

            string errLine = "1";
            try
            {
            bool RootPartExists = new bool();
            errLine = "2";
            try
            {
                errLine = "3";
                if (FlightGlobals.ActiveVessel.parts.Count > 0)
                {
                    errLine = "4";
                }
                errLine = "5";
                RootPartExists = true;
            }
            catch
            {
                errLine = "6";
                RootPartExists = false;
            }
            errLine = "7";

            if (RootPartExists)
            {
                errLine = "8";
                if (AGXRoot != FlightGlobals.ActiveVessel.rootPart && flightNodeIsLoaded) //load keyset also
                {
                    print("Root part changed, AGX reloading");
                    //loadFinished = false;
                    if (AGXRoot != null)
                    {
                        errLine = "9";
                       // print("Root part changed, AGX reloadinga");
                        ConfigNode oldVsl = new ConfigNode(AGXRoot.vessel.id.ToString());
                        if(AGXFlightNode.HasNode(AGXRoot.vessel.id.ToString()))
                        {
                            errLine = "10";
                            //print("Root part changed, AGX reloadingb");
                            oldVsl = AGXFlightNode.GetNode(AGXRoot.vessel.id.ToString());
                            AGXFlightNode.RemoveNode(AGXRoot.vessel.id.ToString());
                        }
                        errLine = "11";
                        //print("Root part changed, AGX reloadingc");
                        if(oldVsl.HasValue("name"));
                        {
                            oldVsl.RemoveValue("name");
                        }
                        oldVsl.AddValue("name", AGXRoot.vessel.vesselName);
                        errLine = "12";
                       // errLine = "13";
                        if (oldVsl.HasValue("currentKeyset")) ;
                        {
                            oldVsl.RemoveValue("currentKeyset");
                        }
                        oldVsl.AddValue("currentKeyset", CurrentKeySet.ToString());
                        errLine = "13";
                        //errLine = "14";
                        if (oldVsl.HasValue("groupNames")) ;
                        {
                            oldVsl.RemoveValue("groupNames");
                        }
                        oldVsl.AddValue("groupNames", SaveGroupNames(""));
                        errLine = "14";
                        //errLine = "15";
                        if (oldVsl.HasValue("groupVisibility")) ;
                        {
                            oldVsl.RemoveValue("groupVisibility");
                        }
                        oldVsl.AddValue("groupVisibility", SaveGroupVisibility(""));
                        errLine = "15";
                        //errLine = "16";
                        if (oldVsl.HasValue("groupVisibilityNames")) ;
                        {
                            oldVsl.RemoveValue("groupVisibilityNames");
                        }
                        oldVsl.AddValue("groupVisibilityNames", SaveGroupVisibilityNames(""));
                        errLine = "16";
                        AGXFlightNode.AddNode(oldVsl);
                        //print("Root part changed, AGX reloadingd " + oldVsl.GetValue("groupNames"));
                    }
                    errLine = "17";
                    //print("Root part changed, AGX reloadinge");
                    if (flightNodeIsLoaded && AGXFlightNode.HasNode(FlightGlobals.ActiveVessel.id.ToString()))
                    {
                        errLine = "18";
                        //print("Root part changed, AGX reloadingf");
                        ConfigNode currentVessel = AGXFlightNode.GetNode(FlightGlobals.ActiveVessel.id.ToString());
                        CurrentKeySet = Convert.ToInt32(currentVessel.GetValue("currentKeyset"));
                        LoadGroupNames(currentVessel.GetValue("groupNames"));
                        LoadGroupVisibility(currentVessel.GetValue("groupVisibility"));
                        LoadGroupVisibilityNames(currentVessel.GetValue("groupVisibilityNames"));
                        //print("Root part changed, AGX reloadingg");
                        errLine = "19";
                    }
                        
                    else
                    {
                        errLine = "20";
                        CurrentKeySet = 1;
                        for (int i = 1; i <= 250; i = i + 1)
                        {
                            AGXguiNames[i] = "";
                        }
                        ShowGroupInFlightCurrent = 1;
                        for (int i = 1; i <= 250; i++)
                        {
                            IsGroupToggle[i] = false;
                            for (int i2 = 1; i2 <= 5; i2++)
                            {
                                ShowGroupInFlight[i2, i] = true;
                            }
                        }
                        ShowGroupInFlightNames[1] = "Group1";
                        ShowGroupInFlightNames[2] = "Group2";
                        ShowGroupInFlightNames[3] = "Group3";
                        ShowGroupInFlightNames[4] = "Group4";
                        ShowGroupInFlightNames[5] = "Group5";
                        errLine = "21";
                    }
                    
                   errLine = "22";


                    AGXRoot = FlightGlobals.ActiveVessel.rootPart;
                    AGEditorSelectedParts.Clear();
                    PartActionsList.Clear();
                    RefreshCurrentActions();
                    //loadFinished = true;
                    //print("sit " + FlightGlobals.ActiveVessel.situation.ToString());
                    errLine = "23";
                }
            }
            errLine = "24";
            if (LastPartCount != FlightGlobals.ActiveVessel.parts.Count) //parts count changed, remove any actions assigned to parts that have disconnected/been destroyed
            {
                print("Part count change, reload AGX");
                AGEditorSelectedParts.Clear();
                PartActionsList.Clear();
                //LoadActionGroups();
                RefreshCurrentActions();
                LastPartCount = FlightGlobals.ActiveVessel.parts.Count;
                errLine = "25";
                
            }
            errLine = "26";
            foreach (KeyCode KC in ActiveKeys)
            {
                errLine = "27";
                if(Input.GetKeyDown(KC))
                {
                for (int i = 1; i <= 250; i = i + 1)
                {
                    if (AGXguiKeys[i] == KC)
                    {
                        ActivateActionGroup(i);
                    }
                }
                }
            }
            errLine = "28";
            //if (!ActiveActionsCalculated)
            //{
            //    CalculateActiveActions();
                
            //}
            if(Input.GetKeyDown(KeyCode.Mouse0) && ShowSelectedWin)
        {
            errLine = "29";
                Part selPart = new Part();
            selPart = SelectPartUnderMouse();
            if(selPart != null)
            {
                AddSelectedPart(selPart);
        }
            errLine = "30";
        }
            errLine = "31";
            if (RightClickDelay < 3)
            {
                errLine = "32";
                if (RightClickDelay == 2)
                {
                    errLine = "33";
                    UIPartActionWindow UIPartsListThing = new UIPartActionWindow();
                    UIPartsListThing = (UIPartActionWindow)FindObjectOfType(typeof(UIPartActionWindow));
                    //UnityEngine.Object[] TempObj = FindObjectsOfType(typeof(UIPartActionWindow));
                    //print(TempObj.Length);
                    try
                    {
                        if (UIPartsListThing != null)
                        {
                            AddSelectedPart(UIPartsListThing.part);
                        }
                       // print(UIPartsListThing.part.name); //finds part right-clicked on
                        RightLickPartAdded = true;
                    }
                    catch
                    {
                       // print("nope!");
                        RightLickPartAdded = true;
                    }
                }
                
                    RightClickDelay = RightClickDelay + 1; 
                
                errLine = "34";
            }

            errLine = "35";
            
            if (Input.GetKeyUp(KeyCode.Mouse1) && ShowSelectedWin && RightLickPartAdded == true)
            {
                RightClickDelay = 0;
                RightLickPartAdded = false;

            }
            errLine = "36";

            //foreach (Part p in FlightGlobals.ActiveVessel.Parts)
            //{
            //    foreach (PartModule pm in p.Modules)
            //    {
            //        foreach (BaseAction ba in pm.Actions)
            //        {
            //            print(p.partName + " " + pm.moduleName + " " + ba.name + " " + ba.guiName);
            //        }
            //    }
            //}
            if (actionsCheckFrameCount >= 20)
            {
                CheckActionsActive();
                PartVesselChangeCheck();
                actionsCheckFrameCount = 0;
            }
            else
            {
                actionsCheckFrameCount = actionsCheckFrameCount + 1;
            }
            errLine = "37";
            //print("vessel " + FlightGlobals.ActiveVessel.id.ToString());
            //print("uid " + FlightGlobals.ActiveVssel.rootPart.uid.ToString());
            //foreach (Part p in FlightGlobals.ActiveVessel.Parts)
            //{
            //    print("PartLoc " + p.ConstructID + " " + p.orgPos);
            //}
        //    print("Vessel Id " +FlightGlobals.ActiveVessel.id);
        //    print("Part Flight Id " + FlightGlobals.ActiveVessel.rootPart.flightID);
        //    print("Part UID " + FlightGlobals.ActiveVessel.rootPart.uid);
        //    print("Part mission id " + FlightGlobals.ActiveVessel.rootPart.missionID);
            if (TimeWarp.CurrentRate != 1)
            {
                if (ShowSelectedWin || ShowKeySetWin)
                {

                    SaveEverything();
                    ShowSelectedWin = false;
                    ShowKeySetWin = false;
                }

            }
        }
            catch(Exception e)
            {
                print("AGX Update error: " + errLine + " " + e);
            }
        }
Example #12
0
        //ModifyNode applies the ConfigNode mod as a 'patch' to ConfigNode original, then returns the patched ConfigNode.
        // it uses FindConfigNodeIn(src, nodeType, nodeName, nodeTag) to recurse.
        public static ConfigNode ModifyNode(ConfigNode original, ConfigNode mod)
        {
            ConfigNode newNode = new ConfigNode(original.name);
            original.CopyTo(newNode);

            foreach (ConfigNode.Value val in mod.values)
            {
                if (val.name[0] == '@')
                {
                    // Modifying a value: Format is @key = value or @key,index = value
                    string valName = val.name.Substring(1);
                    int index = 0;
                    if (valName.Contains(","))
                    {
                        int.TryParse(valName.Split(',')[1], out index);
                        valName = valName.Split(',')[0];
                    }
                    newNode.SetValue(valName, val.value, index);
                }
                else if (val.name[0] == '!')
                {
                    // Parsing: Format is @key = value or @key,index = value
                    string valName = val.name.Substring(1);
                    int index = 0;
                    if (valName.Contains(","))
                    {
                        int.TryParse(valName.Split(',')[1], out index);
                        valName = valName.Split(',')[0];
                    } // index is useless right now, but some day it might not be.
                    newNode.RemoveValue(valName);
                }
                else
                {
                    newNode.AddValue(val.name, val.value);
                }
            }

            foreach (ConfigNode subMod in mod.nodes)
            {
                if (subMod.name[0] == '@')
                {
                    // Modifying a node: Format is @NODETYPE {...}, @NODETYPE[Name] {...} or @NODETYPE[Name,Tag] {...}
                    ConfigNode subNode = null;

                    if (subMod.name.Contains("["))
                    { // format @NODETYPE[Name] {...} or @NODETYPE[Name, Tag] {...}
                        string nodeType = subMod.name.Substring(1).Split('[')[0].Trim();
                        string nodeName = subMod.name.Split('[')[1].Replace("]", "").Trim();
                        string nodeTag = null;
                        if (nodeName.Contains(","))
                        { //format @NODETYPE[Name, Tag] {...}
                            nodeTag = nodeName.Split(',')[1];
                            nodeName = nodeName.Split(',')[0];
                        }
                        subNode = FindConfigNodeIn(newNode, nodeType, nodeName, nodeTag);
                    }
                    else
                    { // format @NODETYPE {...}
                        string nodeType = subMod.name.Substring(1);
                        subNode = newNode.GetNode(nodeType);
                    }
                    // find the original subnode to modify, modify it, remove the original and add the modified.
                    if (subNode == null)
                    {
                        print("Could not find node to modify: " + subMod.name);
                    }
                    else
                    {
                        ConfigNode newSubNode = ModifyNode(subNode, subMod);
                        newNode.nodes.Remove(subNode);
                        newNode.nodes.Add(newSubNode);
                    }

                }
                else if (subMod.name[0] == '!')
                {
                    // Removing a node: Format is !NODETYPE {}, !NODETYPE[Name] {} or !NODETYPE[Name,Tag] {}

                    ConfigNode subNode;

                    if (subMod.name.Contains("["))
                    { // format !NODETYPE[Name] {} or !NODETYPE[Name, Tag] {}
                        string nodeType = subMod.name.Substring(1).Split('[')[0].Trim();
                        string nodeName = subMod.name.Split('[')[1].Replace("]", "").Trim();
                        string nodeTag = null;
                        if (nodeName.Contains(","))
                        { //format !NODETYPE[Name, Tag] {}
                            nodeTag = nodeName.Split(',')[1];
                            nodeName = nodeName.Split(',')[0];
                        }
                        subNode = FindConfigNodeIn(newNode, nodeType, nodeName, nodeTag);
                    }
                    else
                    { // format !NODETYPE {}
                        string nodeType = subMod.name.Substring(1);
                        subNode = newNode.GetNode(nodeType);
                    }
                    if (subNode != null)
                        newNode.nodes.Remove(subNode);

                }
                else
                {
                    // this is a full node, not a mod, so just add it as a new subnode.
                    newNode.AddNode(subMod);
                }
            }
            return newNode;
        }
        private static void SetValue(ConfigNode node, string key, float value)
        {
            if(node == null)
                throw new ArgumentNullException("node");

            // key is validated by public facing methods.

            if(node.HasValue(key))
            {
                node.RemoveValue(key);
            }

            node.AddValue(key, value);
        }
        /// <summary>
        /// Loads the ParameterFactory from the given ConfigNode.  The base version performs the following:
        ///   - Loads and validates the values for
        ///     - rewardScience
        ///     - rewardReputation
        ///     - rewardFunds
        ///     - failureReputation
        ///     - failureFunds
        ///     - advanceFunds
        ///     - optional
        ///     - targetBody
        ///     - disableOnStateChange
        ///     - child PARAMETER nodes
        /// </summary>
        /// <param name="configNode">The ConfigNode to load</param>
        /// <returns>Whether the load was successful</returns>
        public virtual bool Load(ConfigNode configNode)
        {
            bool valid = true;
            ConfigNodeUtil.SetCurrentDataNode(dataNode);

            // Get name and type
            valid &= ConfigNodeUtil.ParseValue<string>(configNode, "type", x => type = x, this);
            valid &= ConfigNodeUtil.ParseValue<string>(configNode, "name", x => name = x, this, type);

            // Load the iterator nodes
            valid &= DataNode.LoadIteratorNodes(configNode, this);

            if (!configNode.HasValue("targetBody"))
            {
                configNode.AddValue("targetBody", "@/targetBody");
            }
            if (!configNode.HasValue("ignoreTargetBody"))
            {
                valid &= ConfigNodeUtil.ParseValue<CelestialBody>(configNode, "targetBody", x => _targetBody = x, this);
            }
            else
            {
                configNode.RemoveValue("ignoreTargetBody");
            }

            // Load rewards
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "rewardFunds", x => rewardFunds = x, this, 0.0f, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "rewardReputation", x => rewardReputation = x, this, 0.0f, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "rewardScience", x => rewardScience = x, this, 0.0f, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "failureFunds", x => failureFunds = x, this, 0.0f, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "failureReputation", x => failureReputation = x, this, 0.0f, x => Validation.GE(x, 0.0f));

            // Load flags
            valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "optional", x => optional = x, this, false);
            valid &= ConfigNodeUtil.ParseValue<bool?>(configNode, "disableOnStateChange", x => disableOnStateChange = x, this, (bool?)null);
            valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "completeInSequence", x => completeInSequence = x, this, false);
            valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "hidden", x => hidden = x, this, false);
            valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "hideChildren", x => hideChildren = x, this, false);

            // Get title and notes
            valid &= ConfigNodeUtil.ParseValue<string>(configNode, "title", x => title = x, this, (string)null);
            valid &= ConfigNodeUtil.ParseValue<string>(configNode, "notes", x => notes = x, this, (string)null);
            valid &= ConfigNodeUtil.ParseValue<string>(configNode, "completedMessage", x => completedMessage = x, this, (string)null);

            config = configNode.ToString();
            return valid;
        }