public void Awake()
        {
            //            Debug.Log("********************************************************************" + HighLogic.LoadedScene + "*********************************************************************");
            settings = ConfigNode.Load("GameData/CustomerSatisfactionProgram/Config.cfg");

            if (settings.HasNode("SETTINGS")) {
                Debug.Log("Loading Settings");
                settings = settings.GetNode("SETTINGS");

                if (settings.HasValue("VERSION")) {
                    version = (settings.GetValue("VERSION"));
                }
                if (settings.HasValue("CAP")) {
                    cap = (int.Parse(settings.GetValue("CAP")));
                }
                if (settings.HasValue("CLEANUP")) {
                    cleanup = (int.Parse(settings.GetValue("CLEANUP")));
                    if (cleanup == 2) {
                        settings.AddValue("CLEANUP", 0);
                    }
                }
            }

            GameEvents.onKerbalRemoved.Add(OnKerbalRemoved);
            GameEvents.onKerbalAdded.Add(OnKerbalAdded);
            GameEvents.onKerbalTypeChange.Add(OnKerbalTypeChange);
            GameEvents.onGameSceneLoadRequested.Add(OnGameSceneLoadRequested);
        }
Exemplo n.º 2
0
 /// <summary>Creates a new part from save.</summary>
 public KIS_Item(AvailablePart availablePart, ConfigNode itemNode, ModuleKISInventory inventory,
           float quantity = 1)
 {
     // Get part node
     this.availablePart = availablePart;
     partNode = new ConfigNode();
     itemNode.GetNode("PART").CopyTo(partNode);
     // init config
     this.InitConfig(availablePart, inventory, quantity);
     // Get mass
     if (itemNode.HasValue("resourceMass")) {
       resourceMass = float.Parse(itemNode.GetValue("resourceMass"));
     } else {
       resourceMass = availablePart.partPrefab.GetResourceMass();
     }
     if (itemNode.HasValue("contentMass")) {
       contentMass = float.Parse(itemNode.GetValue("contentMass"));
     }
     if (itemNode.HasValue("contentCost")) {
       contentCost = float.Parse(itemNode.GetValue("contentCost"));
     }
     if (itemNode.HasValue("inventoryName")) {
       inventoryName = itemNode.GetValue("inventoryName");
     }
 }
Exemplo n.º 3
0
 public void Load(ConfigNode node)
 {
     if(node.HasValue("ConversionRate"))
         ConversionRate = float.Parse(node.GetValue("ConversionRate"));
     if(node.HasValue("ConsumptionRate"))
         ConsumptionRate = float.Parse(node.GetValue("ConsumptionRate"));
 }
Exemplo n.º 4
0
        public SatSettingNode(ProtoPartModuleSnapshot s, Vessel v, ProtoPartSnapshot sn)
        {
            this.protoPartModule = s;
            this.vessel = v;
            this.snapshot = sn;
            isLoaded = false;

            ConfigNode n = new ConfigNode();
            protoPartModule.Save(n);

            if (n.HasValue("pointedAt"))
                this.pointedAt = new Target(n.GetValue("pointedAt"));
            else
                this.pointedAt = new Target();

            if (n.HasValue("dishRange"))
                this.dishRange = float.Parse(n.GetValue("dishRange"));
            else
                this.dishRange = 0;

            if (n.HasValue("antennaName"))
                this.antennaName = n.GetValue("antennaName");

            for (int i = 0; i < RTGlobals.targets.Count; i++)
            {
                if (pointedAt.Equals(RTGlobals.targets[i])) { selectedTarget = i; break; }
            }
        }
Exemplo n.º 5
0
        public MappedVariable(ConfigNode node)
        {
            if (!node.HasValue("mappedVariable") || !node.HasValue("mappedRange") || !node.HasValue("sourceVariable") || !node.HasValue("sourceRange"))
            {
                throw new ArgumentException("MappedVariable missing required values");
            }

            sourceVariable = node.GetValue("sourceVariable");
            string sourceRange = node.GetValue("sourceRange");
            string[] sources = sourceRange.Split(',');
            if (sources.Length != 2)
            {
                throw new ArgumentException("MappedVariable sourceRange does not have exactly two values");
            }

            if (!float.TryParse(sources[0].Trim(), out sourceMin))
            {
                sourceMinStr = sources[0].Trim();
            }
            if (!float.TryParse(sources[1].Trim(), out sourceMax))
            {
                sourceMaxStr = sources[1].Trim();
            }

            mappedVariable = node.GetValue("mappedVariable");
            mappedRange = ConfigNode.ParseVector2(node.GetValue("mappedRange"));
        }
        /// <summary>
        /// Loads any additional fields not loaded automatically.
        /// </summary>
        /// <param name="node">The config node for this module.</param>
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            if (node.HasValue("chanceToFailPerfect")) { chanceToFailPerfect = double.Parse(node.GetValue("chanceToFailPerfect")); }
            if (node.HasValue("chanceToFailTerrible")) { chanceToFailTerrible = double.Parse(node.GetValue("chanceToFailTerrible")); }
        }
        /// <summary>
        /// Load the saved CancelCommand and find the element to cancel, based on the saved queue position
        /// </summary>
        /// <returns>true - loaded successfull</returns>
        public override bool Load(ConfigNode n, FlightComputer computer)
        {
            if(base.Load(n, computer))
            {
                if (n.HasValue("CancelCmdGuid"))
                {
                    this.CancelCmdGuid = new Guid(n.GetValue("CancelCmdGuid"));
                }

                // old way to cancel a command
                if (n.HasValue("queueIndex"))
                {
                    try
                    {
                        int queueIndex = int.Parse(n.GetValue("queueIndex"));
                        // try to find the command to cancel
                        this.CancelCmdGuid = computer.QueuedCommands.ElementAt(queueIndex).CmdGuid;
                    }
                    catch (Exception)
                    { }
                }

                // loaded successfull
                if (this.CancelCmdGuid != Guid.Empty)
                    return true;
            }
            return false;
        }
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            // Check on active contracts too
            checkOnActiveContract = configNode.HasValue("checkOnActiveContract") ? checkOnActiveContract : true;

            valid &= ConfigNodeUtil.ParseValue<List<string>>(configNode, "tech", x => techs = x, this, new List<string>());

            if (configNode.HasValue("part"))
            {
                List<AvailablePart> parts = new List<AvailablePart>();
                valid &= ConfigNodeUtil.ParseValue<List<AvailablePart>>(configNode, "part", x => parts = x, this);

                foreach (AvailablePart part in parts)
                {
                    techs.AddUnique(part.TechRequired);
                }
            }

            valid &= ConfigNodeUtil.AtLeastOne(configNode, new string[] { "tech", "part" }, this);

            return valid;
        }
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            valid &= ConfigNodeUtil.ParseValue<ExperimentalPart.UnlockCriteria>(configNode, "unlockCriteria", x => unlockCriteria = x, this, ExperimentalPart.UnlockCriteria.CONTRACT_ACCEPTANCE);
            if (unlockCriteria == ExperimentalPart.UnlockCriteria.PARAMETER_COMPLETION)
            {
                valid &= ConfigNodeUtil.ParseValue<string>(configNode, "unlockParameter", x => unlockParameter = x, this);
            }
            valid &= ConfigNodeUtil.ParseValue<ExperimentalPart.LockCriteria>(configNode, "lockCriteria", x => lockCriteria = x, this, ExperimentalPart.LockCriteria.CONTRACT_COMPLETION);
            if (lockCriteria == ExperimentalPart.LockCriteria.PARAMETER_COMPLETION)
            {
                valid &= ConfigNodeUtil.ParseValue<string>(configNode, "lockParameter", x => lockParameter = x, this);
            }

            valid &= ConfigNodeUtil.ParseValue<List<AvailablePart>>(configNode, "part", x => parts = x, this);

            if (configNode.HasValue("add"))
            {
                LoggingUtil.LogWarning(this, "The 'add' attribute of ExperimentalPartFactory is deprecated.  Use 'unlockCriteria' instead.");
                valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "add", x => unlockCriteria = x ? ExperimentalPart.UnlockCriteria.CONTRACT_ACCEPTANCE : ExperimentalPart.UnlockCriteria.DO_NOT_UNLOCK, this);
            }
            if (configNode.HasValue("remove"))
            {
                LoggingUtil.LogWarning(this, "The 'remove' attribute of ExperimentalPartFactory is deprecated.  Use 'lockCriteria' instead.");
                valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "remove", x => lockCriteria = x ? ExperimentalPart.LockCriteria.CONTRACT_COMPLETION : ExperimentalPart.LockCriteria.DO_NOT_LOCK, this);
            }

            return valid;
        }
        public MappedVariable(ConfigNode node, RasterPropMonitorComputer rpmComp)
        {
            if (!node.HasValue("mappedVariable") || !node.HasValue("mappedRange") || !node.HasValue("sourceVariable") || !node.HasValue("sourceRange"))
            {
                throw new ArgumentException("MappedVariable missing required values");
            }

            string sourceVariableStr = node.GetValue("sourceVariable");
            string sourceRange = node.GetValue("sourceRange");
            string[] sources = sourceRange.Split(',');
            if (sources.Length != 2)
            {
                throw new ArgumentException("MappedVariable sourceRange does not have exactly two values");
            }

            sourceVariable = new VariableOrNumberRange(rpmComp, sourceVariableStr, sources[0], sources[1]);

            mappedVariable = node.GetValue("mappedVariable");
            string[] destinations = node.GetValue("mappedRange").Split(',');
            if (destinations.Length != 2)
            {
                throw new ArgumentException("MappedVariable mappedRange does not have exactly two values");
            }
            mappedExtent1 = rpmComp.InstantiateVariableOrNumber(destinations[0]);
            mappedExtent2 = rpmComp.InstantiateVariableOrNumber(destinations[1]);
        }
        public override void OnLoad(ConfigNode node)
        {
            return;
            if (node.HasValue ("difficultySetting"))
                difficultySetting = int.Parse (node.GetValue ("difficultySetting"));

            if (node.HasValue("displayParachuteWarning"))
                bool.TryParse(node.GetValue("displayParachuteWarning"), out displayParachuteWarning);
        }
Exemplo n.º 12
0
 public void OnLoad(ConfigNode node)
 {
     if (node.HasValue("cancerTime"))
         Double.TryParse(node.GetValue("cancerTime"), out mCancerTime);
     if (node.HasValue("softDose"))
         Double.TryParse(node.GetValue("softDose"), out softDose);
     if (node.HasValue("hardDose"))
         Double.TryParse(node.GetValue("hardDose"), out hardDose);
 }
Exemplo n.º 13
0
 public override void OnLoad(ConfigNode node)
 {
     base.OnLoad(node);
     if (node.HasValue("chargeRate"))
         Single.TryParse(node.GetValue("chargeRate"), out chargeRate);
     if (node.HasValue("initChargeRate"))
         Single.TryParse(node.GetValue("initChargeRate"), out initChargeRate);
     else
         initChargeRate = chargeRate;
 }
Exemplo n.º 14
0
        public void FromConfigNode(ConfigNode node)
        {
            if (node.HasValue("Name"))
                Name = node.GetValue("Name");

            if (node.HasValue("LastUpdated"))
                double.TryParse(node.GetValue("LastUpdated"), out LastUpdated);

            if (node.HasValue("LastSated"))
                double.TryParse(node.GetValue("LastSated"), out LastSated);
        }
Exemplo n.º 15
0
        public Harddisk(ConfigNode node)
        {
            Capacity = 10000;

            if (node.HasValue("capacity")) Capacity = int.Parse(node.GetValue("capacity"));
            if (node.HasValue("volumeName")) Name = node.GetValue("volumeName");

            foreach (ConfigNode fileNode in node.GetNodes("file"))
            {
                Add(new ProgramFile(fileNode));
            }
        }
Exemplo n.º 16
0
 /*
  * Returns the internal name of a part given a valid ConfigNode of the part. Parts saved to a craft file are saved as "part = $partname_$idNumber", 
  * while parts from an active Vessel are saved as "name = $partname". This can handle both situations
  * */
 public static string PartNameFromNode(ConfigNode part)
 {
     string name = "";
     if (part.HasValue("part"))
     {
         name = part.GetValue("part");
         name = name.Split('_')[0];
     }
     else if (part.HasValue("name"))
         name = part.GetValue("name");
     return name;
 }
 public ElectricEnginePropellant(ConfigNode node) 
 {
     propellantname = node.GetValue("name");
     propellantguiname = node.GetValue("guiName");
     ispMultiplier = Convert.ToDouble(node.GetValue("ispMultiplier"));
     thrustMultiplier = node.HasValue("thrustMultiplier") ? Convert.ToDouble(node.GetValue("thrustMultiplier")) : 1;
     wasteheatMultiplier = node.HasValue("wasteheatMultiplier") ? Convert.ToDouble(node.GetValue("wasteheatMultiplier")) : 1;
     efficiency = Convert.ToDouble(node.GetValue("efficiency"));
     prop_type = Convert.ToInt32(node.GetValue("type"));
     effectname = node.GetValue("effectName");
     ConfigNode propellantnode = node.GetNode("PROPELLANT");
     propellant = new Propellant();
     propellant.Load(propellantnode);
 }
Exemplo n.º 18
0
 public ReactorFuelMode(ConfigNode node) 
 {
     _reactor_type = Convert.ToInt32(node.GetValue("ReactorType"));
     _mode_gui_name = node.GetValue("GUIName");
     _aneutronic = Boolean.Parse(node.GetValue("Aneutronic"));
     _normreactionrate = Double.Parse(node.GetValue("NormalisedReactionRate"));
     _normpowerrequirements = Double.Parse(node.GetValue("NormalisedPowerConsumption"));
     _charged_power_ratio = Double.Parse(node.GetValue("ChargedParticleRatio"));
     _mev_per_charged_product = node.HasValue("MeVPerChargedProduct") ? Double.Parse(node.GetValue("MeVPerChargedProduct")) : 0;
     _outputResourceName = node.HasValue("MeVPerChargedProduct") ? node.GetValue("OutputResourceName") : null;
     _outputResourceFraction = node.HasValue("OutputResourceFraction") ? Double.Parse(node.GetValue("OutputResourceFraction")) : 0;
     ConfigNode[] fuel_nodes = node.GetNodes("FUEL");
     _fuels = fuel_nodes.Select(nd => new ReactorFuel(nd)).ToList();
 }
 public override void OnLoad(ConfigNode node)
 {
     base.OnLoad(node);
     if (node.HasValue("resourceToLeak"))
         resourceToLeak = node.GetValue("resourceToLeak");
     else
         resourceToLeak = "random";
     if (node.HasValue("initialAmount"))
         initialAmount = node.GetValue("initialAmount");
     if (node.HasValue("perSecondAmount"))
         perSecondAmount = node.GetValue("perSecondAmount");
     if (node.HasValue("calculatePerTick"))
         calculatePerTick = bool.Parse(node.GetValue("calculatePerTick"));
 }
 public InterstellarResourcesConfiguration(ConfigNode plugin_settings)
 {
     if (plugin_settings != null)
     {
         if (plugin_settings.HasValue("HydrogenResourceName"))
         {
             _hydrogen = plugin_settings.GetValue("HydrogenResourceName");
             Debug.Log("[KSP Interstellar] Hydrogen resource name set to " + Hydrogen);
         }
         if (plugin_settings.HasValue("OxygenResourceName"))
         {
             _oxygen = plugin_settings.GetValue("OxygenResourceName");
             Debug.Log("[KSP Interstellar] Oxygen resource name set to " + Oxygen);
         }
         if (plugin_settings.HasValue("AluminiumResourceName"))
         {
             _aluminium = plugin_settings.GetValue("AluminiumResourceName");
             Debug.Log("[KSP Interstellar] Aluminium resource name set to " + Aluminium);
         }
         if (plugin_settings.HasValue("MethaneResourceName"))
         {
             _methane = plugin_settings.GetValue("MethaneResourceName");
             Debug.Log("[KSP Interstellar] Methane resource name set to " + Methane);
         }
         if (plugin_settings.HasValue("ArgonResourceName"))
         {
             _argon = plugin_settings.GetValue("ArgonResourceName");
             Debug.Log("[KSP Interstellar] Argon resource name set to " + Argon);
         }
         if (plugin_settings.HasValue("WaterResourceName"))
         {
             _water = plugin_settings.GetValue("WaterResourceName");
             Debug.Log("[KSP Interstellar] Water resource name set to " + Water);
         }
         if (plugin_settings.HasValue("HydrogenPeroxideResourceName"))
         {
             _hydrogen_peroxide = plugin_settings.GetValue("HydrogenPeroxideResourceName");
             Debug.Log("[KSP Interstellar] Hydrogen Peroxide resource name set to " + HydrogenPeroxide);
         }
         if (plugin_settings.HasValue("AmmoniaResourceName"))
         {
             _ammonia = plugin_settings.GetValue("AmmoniaResourceName");
             Debug.Log("[KSP Interstellar] Ammonia resource name set to " + Ammonia);
         }
     } else
     {
         PluginHelper.showInstallationErrorMessage();
     }
 }
Exemplo n.º 21
0
 public void Load(ConfigNode node)
 {
     if (node.HasValue("Kp"))
     {
         Kp = Convert.ToDouble(node.GetValue("Kp"));
     }
     if (node.HasValue("Ki"))
     {
         Ki = Convert.ToDouble(node.GetValue("Ki"));
     }
     if (node.HasValue("Kd"))
     {
         Kd = Convert.ToDouble(node.GetValue("Kd"));
     }
 }
 public void Load(ConfigNode node)
 {
     if (node.HasValue("Kp"))
     {
         Kp = ConfigNode.ParseVector3D(node.GetValue("Kp"));
     }
     if (node.HasValue("Ki"))
     {
         Ki = ConfigNode.ParseVector3D(node.GetValue("Ki"));
     }
     if (node.HasValue("Kd"))
     {
         Kd = ConfigNode.ParseVector3D(node.GetValue("Kd"));
     }
 }
		public void Load (ConfigNode node)
		{
			string name = node.GetValue ("name");
			res_def = PartResourceLibrary.Instance.GetDefinition (name);
			if (node.HasValue ("isMineable")) {
				bool.TryParse (node.GetValue ("isMineable"), out isMineable);
			}
			if (node.HasValue ("isHullResource")) {
				bool.TryParse (node.GetValue ("isHullResource"),
							   out isHullResource);
			}
			if (node.HasValue ("volume")) {
				float.TryParse (node.GetValue ("volume"), out volume);
			}
		}
Exemplo n.º 24
0
        /// <summary>
        /// Load infos into this object and create a new BaseEvent
        /// </summary>
        /// <returns>true - loaded successfull</returns>
        public override bool Load(ConfigNode n, FlightComputer fc)
        {
            if(base.Load(n, fc))
            {
                // deprecated since 1.6.2, we need this for upgrading from 1.6.x => 1.6.2
                int PartId = 0;
                {
                    if (n.HasValue("PartId"))
                        PartId = int.Parse(n.GetValue("PartId"));
                }

                if (n.HasValue("flightID"))
                    this.flightID = uint.Parse(n.GetValue("flightID"));

                this.Module = n.GetValue("Module");
                this.GUIName = n.GetValue("GUIName");
                this.Name = n.GetValue("Name");

                RTLog.Notify("Try to load an EventCommand from persistent with {0},{1},{2},{3},{4}",
                             PartId, this.flightID, this.Module, this.GUIName, this.Name);

                Part part = null;
                var partlist = FlightGlobals.ActiveVessel.parts;

                if (this.flightID == 0)
                {
                    // only look with the partid if we've enough parts
                    if (PartId < partlist.Count)
                        part = partlist.ElementAt(PartId);
                }
                else
                {
                    part = partlist.Where(p => p.flightID == this.flightID).FirstOrDefault();
                }

                if (part == null) return false;

                PartModule partmodule = part.Modules[Module];
                if (partmodule == null) return false;

                BaseEventList eventlist = new BaseEventList(part, partmodule);
                if (eventlist.Count <= 0) return false;

                this.BaseEvent = eventlist.Where(ba => (ba.GUIName == this.GUIName || ba.name == this.Name)).FirstOrDefault();
                return true;
            }
            return false;
        }
Exemplo n.º 25
0
 public static string GetValueDefault(ConfigNode node, string name, string vale)
 {
     if (node.HasValue(name))
         vale = (node.GetValue(name));
     //else Debug.Log("*MCEPC key not found: " + name);
     return vale;
 }
Exemplo n.º 26
0
 public static int GetValueDefault(ConfigNode node, string name, int val)
 {
     if (node.HasValue(name))
         val = atoi(node.GetValue(name));
     //else Debug.Log("*MCEPC key not found: " + name);
     return val;
 }
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            if (configNode.HasValue("passengerName"))
            {
                LoggingUtil.LogWarning(this, "The passengerName and gender attributes are obsolete since Contract Configurator 1.9.0, use kerbal instead.");
                valid &= ConfigNodeUtil.ParseValue<List<string>>(configNode, "passengerName", x => passengerName = x, this, new List<string>());
                valid &= ConfigNodeUtil.ParseValue<ProtoCrewMember.Gender>(configNode, "gender", x => gender = x, this, Kerbal.RandomGender());
                valid &= ConfigNodeUtil.ParseValue<string>(configNode, "experienceTrait", x => experienceTrait = x, this, Kerbal.RandomExperienceTrait());

                legacy = true;
            }
            else
            {
                valid &= ConfigNodeUtil.ParseValue<List<Kerbal>>(configNode, "kerbal", x => kerbals = x, this, new List<Kerbal>());
                legacy = false;
            }

            valid &= ConfigNodeUtil.ParseValue<int>(configNode, "count", x => count = x, this, 1, x => Validation.GE(x, 1));
            valid &= ConfigNodeUtil.ParseValue<ProtoCrewMember.KerbalType>(configNode, "kerbalType", x => kerbalType = x, this, ProtoCrewMember.KerbalType.Tourist);

            return valid;
        }
Exemplo n.º 28
0
        public void Load(ConfigNode node)
        {
            Debug.Log("FlightData Load");
            Debug.Log(node.ToString());
            if (node.HasValue("dataDeepSpace"))
                dataDeepSpace = float.Parse(node.GetValue("dataDeepSpace"));
            else
                dataDeepSpace = 0.0f;

            if (node.HasValue("flightTimeDeepSpace"))
                flightTimeDeepSpace = int.Parse(node.GetValue("flightTimeDeepSpace"));
            else
                flightTimeDeepSpace = 0;

            if (node.HasNode("bodyData"))
            {
                if (dataBodies == null)
                    dataBodies = new List<FlightDataBody>();
                else
                    dataBodies.Clear();
                foreach (ConfigNode bodyNode in node.GetNodes("bodyData"))
                {
                    FlightDataBody body = new FlightDataBody();
                    body.Load(bodyNode);
                    dataBodies.Add(body);
                }
            }
        }
        public override bool Load(ConfigNode configNode)
        {
            // Ignore the targetBody in the base class
            configNode.AddValue("ignoreTargetBody", true);

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

            valid &= ConfigNodeUtil.ParseValue<bool>(configNode, "failWhenUnmet", x => failWhenUnmet = x, this, false);
            valid &= ConfigNodeUtil.ParseValue<Biome>(configNode, "biome", x => biome = x, this, (Biome)null);
            valid &= ConfigNodeUtil.ParseValue<List<Vessel.Situations>>(configNode, "situation", x => situation = x, this, new List<Vessel.Situations>());
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "minAltitude", x => minAltitude = x, this, float.MinValue);
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "maxAltitude", x => maxAltitude = x, this, float.MaxValue);
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "minTerrainAltitude", x => minTerrainAltitude = x, this, 0.0f, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "maxTerrainAltitude", x => maxTerrainAltitude = x, this, float.MaxValue, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minSpeed", x => minSpeed = x, this, 0.0, x => Validation.GE(x, 0.0));
            valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxSpeed", x => maxSpeed = x, this, double.MaxValue, x => Validation.GE(x, 0.0));
            valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minRateOfClimb", x => minRateOfClimb = x, this, double.MinValue);
            valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxRateOfClimb", x => maxRateOfClimb = x, this, double.MaxValue);
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "minAcceleration", x => minAcceleration = x, this, 0.0f, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue<float>(configNode, "maxAcceleration", x => maxAcceleration = x, this, float.MaxValue, x => Validation.GE(x, 0.0f));

            // Overload targetBody
            if (!configNode.HasValue("targetBody"))
            {
                configNode.AddValue("targetBody", "[ @/targetBody ]");
            }
            valid &= ConfigNodeUtil.ParseValue<List<CelestialBody>>(configNode, "targetBody", x => targetBodies = x, this);

            // Validation minimum set
            valid &= ConfigNodeUtil.AtLeastOne(configNode, new string[] { "targetBody", "biome", "situation", "minAltitude", "maxAltitude",
                "minTerrainAltitude", "maxTerrainAltitude", "minSpeed", "maxSpeed", "minRateOfClimb", "maxRateOfClimb", "minAcceleration", "maxAcceleration" }, this);

            return valid;
        }
Exemplo n.º 30
0
        /*public override void OnSave(ConfigNode node)
        {
            Debug.Log("# OnSave " + node);
            return;
            base.OnSave(node);
            Debug.Log("# Saving hatches");
            ConfigNode hatchNode = new ConfigNode("Hatch");
            foreach (Hatch h in Hatches)
            {
                hatchNode.AddValue("attachNodeId", h.AttachNodeId);
                hatchNode.AddValue("position", h.Position.x + ", " +  h.Position.y + ", " + h.Position.z);
                hatchNode.AddValue("scale", h.Scale.x + ", " + h.Scale.y + ", " + h.Scale.z);
            }
            Debug.Log("# Adding hatch node " + hatchNode);
            node.AddNode(hatchNode);
        }*/
        public override void OnLoad(ConfigNode node)
        {
            if (node.HasValue("CanIva"))
                CanIva = bool.Parse(node.GetValue("CanIva"));

            if (node.HasNode("Hatch"))
            {
                ConfigNode[] hatchNodes = node.GetNodes("Hatch");
                foreach (var hn in hatchNodes)
                {
                    Hatch h = ParseHatch(hn);
                    if (h != null)
                    {
                        Hatches.Add(h);
                        if (h.Collider != null)
                            InternalColliders.Add(h.Collider);
                    }
                }
                PersistenceManager.instance.AddHatches(part.name, Hatches);
            }
            Debug.Log("# Hatches loaded from config for part " + part.name + ": " + Hatches.Count);

            if (node.HasNode("InternalCollider"))
            {
                ConfigNode[] colliderNodes = node.GetNodes("InternalCollider");
                foreach (var cn in colliderNodes)
                {
                    InternalCollider ic = ParseInternalCollider(cn);
                    if (ic != null)
                        InternalColliders.Add(ic);
                }
                PersistenceManager.instance.AddInternalColliders(part.name, InternalColliders);
                Debug.Log("# Internal colliders loaded from config for part " + part.name + ": " + InternalColliders.Count);
            }
        }