Exemplo n.º 1
0
        /// <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);

            valid &= ConfigNodeUtil.ParseValue <CelestialBody>(configNode, "targetBody", x => _targetBody = x, this, (CelestialBody)null);

            // 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, "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);

            config = configNode.ToString();
            return(valid);
        }
Exemplo n.º 2
0
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            valid &= ConfigNodeUtil.ParseValue <List <VesselIdentifier> >(configNode, "vessel", x => vessels = x, this, new List <VesselIdentifier>());
            valid &= ConfigNodeUtil.ParseValue <VesselIdentifier>(configNode, "defineDockedVessel", x => defineDockedVessel = x, this, (VesselIdentifier)null);

            // Validate using the config node instead of the list as it may undergo deferred loading
            if (parent is VesselParameterGroupFactory)
            {
                if (configNode.GetValues("vessel").Count() > 1)
                {
                    LoggingUtil.LogError(this, "{0}: When used under a VesselParameterGroup, no more than one vessel may be specified for the Docking parameter.", ErrorPrefix());
                    valid = false;
                }
            }
            else
            {
                if (configNode.GetValues("vessel").Count() == 0)
                {
                    LoggingUtil.LogError(this, "{0}: Need at least one vessel specified for the Docking parameter.", ErrorPrefix());
                    valid = false;
                }
                if (configNode.GetValues("vessel").Count() > 2)
                {
                    LoggingUtil.LogError(this, "{0}: Cannot specify more than two vessels for the Docking parameter.", ErrorPrefix());
                    valid = false;
                }
            }

            return(valid);
        }
        public override bool LoadFromConfig(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.LoadFromConfig(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);
        }
Exemplo n.º 4
0
        public override void OnLoad(ConfigNode node)
        {
            try
            {
                lastMCButton            = ConfigNodeUtil.ParseValue <MissionControlButton>(node, "lastMCButton", MissionControlButton.All);
                DisplayOfferedOrbits    = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayOfferedOrbits", (bool?)ContractDefs.DisplayOfferedOrbits).Value;
                DisplayOfferedWaypoints = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayOfferedWaypoints", (bool?)ContractDefs.DisplayOfferedWaypoints).Value;
                DisplayActiveOrbits     = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayActiveOrbits", (bool?)true).Value;
                DisplayActiveWaypoints  = ConfigNodeUtil.ParseValue <bool?>(node, "DisplayActiveWaypoints", (bool?)true).Value;

                foreach (ConfigNode groupNode in node.GetNodes("CONTRACT_GROUP"))
                {
                    string groupName = groupNode.GetValue("group");

                    if (ContractGroup.contractGroups.ContainsKey(groupName))
                    {
                        ContractGroup group = ContractGroup.contractGroups[groupName];

                        ContractGroupDetails details = new ContractGroupDetails(group);
                        details.enabled = ConfigNodeUtil.ParseValue <bool>(groupNode, "enabled");

                        contractGroupDetails[group.name] = details;
                    }
                    else
                    {
                        LoggingUtil.LogWarning(this, "Couldn't find contract group with name '" + groupName + "'");
                    }
                }

                foreach (ConfigNode stateNode in node.GetNodes("CONTRACT_STATE"))
                {
                    string typeName = stateNode.GetValue("type");
                    if (!string.IsNullOrEmpty(typeName))
                    {
                        Type contractType = null;
                        try
                        {
                            contractType = ConfigNodeUtil.ParseTypeValue(typeName);
                            StockContractDetails details = new StockContractDetails(contractType);
                            details.enabled = ConfigNodeUtil.ParseValue <bool>(stateNode, "enabled");

                            stockContractDetails[contractType] = details;

                            ContractDisabler.SetContractState(contractType, details.enabled);
                        }
                        catch (ArgumentException)
                        {
                            LoggingUtil.LogWarning(this, "Couldn't find contract type with name '" + typeName + "'");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LoggingUtil.LogError(this, "Error loading ContractConfiguratorSettings from persistance file!");
                LoggingUtil.LogException(e);
                ExceptionLogWindow.DisplayFatalException(ExceptionLogWindow.ExceptionSituation.SCENARIO_MODULE_LOAD, e, "ContractConfiguratorSettings");
            }
        }
 public override void OnLoad(ConfigNode configNode)
 {
     trait         = ConfigNodeUtil.ParseValue <string>(configNode, "trait", (string)null);
     minExperience = ConfigNodeUtil.ParseValue <int>(configNode, "minExperience");
     maxExperience = ConfigNodeUtil.ParseValue <int>(configNode, "maxExperience");
     minCount      = ConfigNodeUtil.ParseValue <int>(configNode, "minCount");
     maxCount      = ConfigNodeUtil.ParseValue <int>(configNode, "maxCount");
 }
Exemplo n.º 6
0
        private static bool SetupTech()
        {
            if (HighLogic.CurrentGame == null)
            {
                return(false);
            }

            // Cache the tech tree
            if (allTech == null)
            {
                ConfigNode techTreeRoot = ConfigNode.Load(HighLogic.CurrentGame.Parameters.Career.TechTreeUrl);
                ConfigNode techTree     = null;
                if (techTreeRoot != null)
                {
                    techTree = techTreeRoot.GetNode("TechTree");
                }

                if (techTreeRoot == null || techTree == null)
                {
                    LoggingUtil.LogError(typeof(Tech), "Couldn't load tech tree from " + HighLogic.CurrentGame.Parameters.Career.TechTreeUrl);
                    return(false);
                }

                allTech = new Dictionary <string, Tech>();

                foreach (ConfigNode techNode in techTree.GetNodes("RDNode"))
                {
                    Tech current = new Tech(techNode.GetValue("id"));
                    current.title       = ConfigNodeUtil.ParseValue <string>(techNode, "title");
                    current.description = ConfigNodeUtil.ParseValue <string>(techNode, "description");
                    current.cost        = ConfigNodeUtil.ParseValue <float>(techNode, "cost");
                    current.anyToUnlock = ConfigNodeUtil.ParseValue <bool>(techNode, "anyToUnlock");

                    bool hasParent = false;
                    foreach (ConfigNode parentNode in techNode.GetNodes("Parent"))
                    {
                        string parentID = parentNode.GetValue("parentID");
                        if (allTech.ContainsKey(parentID))
                        {
                            hasParent = true;
                            allTech[parentID].children.Add(current);

                            current.level = allTech[parentID].level + 1;
                        }
                    }

                    if (!hasParent)
                    {
                        current.level = 0;
                    }

                    allTech[current.techID] = current;
                }
            }

            return(true);
        }
Exemplo n.º 7
0
        public override bool LoadFromConfig(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.LoadFromConfig(configNode);

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

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

            valid &= ConfigNodeUtil.ParseValue <VesselType>(configNode, "vesselType", x => vesselType = x, this);

            return(valid);
        }
Exemplo n.º 9
0
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "failContract", x => failContract = x, this, true);

            return(valid);
        }
Exemplo n.º 10
0
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "mustImpactTerrain", x => mustImpactTerrain = x, this, false, x => true);

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

            valid &= ConfigNodeUtil.ParseValue <List <VesselIdentifier> >(configNode, "vessel", x => vessels = x, this);

            return(valid);
        }
Exemplo n.º 12
0
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            valid &= ConfigNodeUtil.ParseValue <int>(configNode, "count", x => count = x, this);

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

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

            return(valid);
        }
Exemplo n.º 14
0
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            valid &= ConfigNodeUtil.ParseValue <int>(configNode, "countMax", ref countMax, this, 1, x => Validation.GT(x, 0));

            return(valid);
        }
        /// <summary>
        /// Generates all the ContractParameter objects required for the array of ConfigNodes, and
        /// adds them to the host object.
        /// </summary>
        /// <param name="contract">Contract to generate for</param>
        /// <param name="contractParamHost">The object to use as a parent for ContractParameters</param>
        /// <param name="paramFactories">The ParameterFactory objects to use to generate parameters.</param>
        /// <returns>Whether the generation was successful.</returns>
        public static bool GenerateParameters(ConfiguredContract contract, IContractParameterHost contractParamHost, List <ParameterFactory> paramFactories)
        {
            foreach (ParameterFactory paramFactory in paramFactories)
            {
                if (paramFactory.enabled)
                {
                    // Set up the iterator
                    int count   = 1;
                    int current = 0;
                    if (paramFactory.iteratorType != null)
                    {
                        count = (int)paramFactory.dataNode["iteratorCount"];
                    }

                    // Loop through the iterator, or do a single parameter for non-iterated parameters
                    while (current++ < count)
                    {
                        // Refresh the deterministic values
                        int oldValue = DataNode.IteratorCurrentIndex;
                        if (paramFactory.iteratorType != null)
                        {
                            DataNode.IteratorCurrentIndex = current - 1;
                            ConfigNodeUtil.UpdateNonDeterministicValues(paramFactory.dataNode, paramFactory.dataNode);
                        }

                        ContractParameter parameter = paramFactory.Generate(contract, contractParamHost);

                        // Get the child parameters
                        if (parameter != null)
                        {
                            if (!GenerateParameters(contract, parameter, paramFactory.childNodes))
                            {
                                return(false);
                            }
                        }

                        ContractConfiguratorParameter ccParam = parameter as ContractConfiguratorParameter;
                        if (ccParam != null && ccParam.hideChildren)
                        {
                            foreach (ContractParameter child in ccParam.GetChildren())
                            {
                                ContractConfiguratorParameter ccChild = child as ContractConfiguratorParameter;
                                if (ccChild != null)
                                {
                                    ccChild.Hide();
                                }
                            }
                        }

                        // Restore the old value for the iterator list (for recursive iterations)
                        DataNode.IteratorCurrentIndex = oldValue;
                    }
                }
            }

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

            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "vesselKey", ref vesselKey, this);

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

            valid &= ConfigNodeUtil.ParseValue <double>(configNode, "minAltitude", x => minAltitude = x, this, x => Validation.GT(x, 0.0));

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

            valid &= ConfigNodeUtil.ParseValue <int>(configNode, "count", x => count = x, this, x => Validation.GE <int>(x, 0));

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

            valid &= ConfigNodeUtil.ParseValue <Duration>(configNode, "cooldownDuration", x => cooldownDuration = x, this, new Duration(0.0));

            return(valid);
        }
        public override void OnLoad(ConfigNode configNode)
        {
            minCount = ConfigNodeUtil.ParseValue <uint>(configNode, "minCount");
            maxCount = ConfigNodeUtil.ParseValue <uint>(configNode, "maxCount");

            string contractType = ConfigNodeUtil.ParseValue <string>(configNode, "contractType");

            SetValues(contractType);
        }
Exemplo n.º 21
0
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            valid &= ConfigNodeUtil.ParseValue <int>(configNode, "index", x => index = x, this, 0, x => Validation.GE(x, 0));
            valid &= ConfigNodeUtil.ParseValue <double>(configNode, "distance", x => distance = x, this, 0.0, x => Validation.GE(x, 0.0));

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

            valid &= ConfigNodeUtil.ParseValue <BodyLocation>(configNode, "location", ref location, this);
            valid &= ValidateTargetBody(configNode);

            return(valid);
        }
Exemplo n.º 23
0
        public void Load(ConfigNode configNode)
        {
            name                  = ConfigNodeUtil.ParseValue <string>(configNode, "name");
            type                  = ConfigNodeUtil.ParseValue <string>(configNode, "type");
            _targetBody           = ConfigNodeUtil.ParseValue <CelestialBody>(configNode, "targetBody", (CelestialBody)null);
            invertRequirement     = ConfigNodeUtil.ParseValue <bool>(configNode, "invertRequirement");
            checkOnActiveContract = ConfigNodeUtil.ParseValue <bool>(configNode, "checkOnActiveContract");

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

            // Get expression
            valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "expression", x => expression = x, this);

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

            // Get altitude
            valid &= ConfigNodeUtil.ParseValue <double>(configNode, "altitude", ref altitude, this, x => Validation.GT(x, 0.0));

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

            valid &= ConfigNodeUtil.ParseValue <List <VesselIdentifier> >(configNode, "vessel", x => vessels = x, this, new List <VesselIdentifier>(), l => ValidateVesselList(l));
            valid &= ConfigNodeUtil.ParseValue <double>(configNode, "distance", x => distance = x, this, 2000.0);

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

            // Get expression
            valid &= ConfigNodeUtil.ParseValue <VesselIdentifier>(configNode, "vessel", x => vessel = x, this);

            return(valid);
        }
Exemplo n.º 28
0
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            // Get duration
            valid &= ConfigNodeUtil.ParseValue <Duration>(configNode, "duration", x => duration = x, this, new Duration(0.0));

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

            valid &= ValidateTargetBody(configNode);
            valid &= ConfigNodeUtil.ParseValue <CheckType?>(configNode, "checkType", x => checkType = x, this, (CheckType?)null);

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

            valid &= ConfigNodeUtil.ParseValue <int>(configNode, "minCapacity", x => minCapacity = x, this, 1, x => Validation.GE(x, 0));
            valid &= ConfigNodeUtil.ParseValue <int>(configNode, "maxCapacity", x => maxCapacity = x, this, int.MaxValue, x => Validation.GE(x, 0));

            return(valid);
        }