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);
        }
예제 #2
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);
        }
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            valid &= ConfigNodeUtil.ParseValue <int>(configNode, "countMax", x => countMax = x, this, 1, x => Validation.GT(x, 0));
            valid &= ConfigNodeUtil.ParseValue <List <Kerbal> >(configNode, "kerbal", x => kerbal = x, this, new List <Kerbal>());
            valid &= ConfigNodeUtil.ParseValue <VesselIdentifier>(configNode, "vessel", x => vessel = x, this, (VesselIdentifier)null);

            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);
        }
예제 #5
0
        /*
         * Loads the contract type details from the given config node.
         */
        public bool Load(ConfigNode configNode)
        {
            ConfigNodeUtil.ClearFoundCache();
            bool valid = true;

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

            // Load contract text details
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "title", ref title, this);
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "description", ref description, this, (string)null);
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "topic", ref topic, this, (string)null);
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "subject", ref subject, this, (string)null);
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "motivation", ref motivation, this, (string)null);
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "notes", ref notes, this, (string)null);
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "synopsis", ref synopsis, this);
            valid &= ConfigNodeUtil.ParseValue <string>(configNode, "completedMessage", ref completedMessage, this);

            // Load optional attributes
            valid &= ConfigNodeUtil.ParseValue <Agent>(configNode, "agent", ref agent, this, (Agent)null);
            valid &= ConfigNodeUtil.ParseValue <float>(configNode, "minExpiry", ref minExpiry, this, 0.0f, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue <float>(configNode, "maxExpiry", ref maxExpiry, this, 0.0f, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue <float>(configNode, "deadline", ref deadline, this, 0.0f, x => Validation.GE(x, 0.0f));
            valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "cancellable", ref cancellable, this, true);
            valid &= ConfigNodeUtil.ParseValue <bool>(configNode, "declinable", ref declinable, this, true);
            valid &= ConfigNodeUtil.ParseValue <Contract.ContractPrestige?>(configNode, "prestige", ref prestige, this, (Contract.ContractPrestige?)null);
            valid &= ConfigNodeUtil.ParseValue <CelestialBody>(configNode, "targetBody", ref targetBody, this, (CelestialBody)null);

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

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

            // Load other values
            valid &= ConfigNodeUtil.ParseValue <double>(configNode, "weight", ref weight, this, 1.0, x => Validation.GT(x, 0.0f));

            // Check for unexpected values - always do this last
            valid &= ConfigNodeUtil.ValidateUnexpectedValues(configNode, this);

            // Load parameters
            paramFactories = new List <ParameterFactory>();
            foreach (ConfigNode contractParameter in configNode.GetNodes("PARAMETER"))
            {
                ParameterFactory paramFactory = ParameterFactory.GenerateParameterFactory(contractParameter, this);
                if (paramFactory != null)
                {
                    paramFactories.Add(paramFactory);
                }
                else
                {
                    valid = false;
                }
            }

            // Check we have at least one valid parameter
            if (paramFactories.Count() == 0)
            {
                LoggingUtil.LogError(this.GetType(), ErrorPrefix() + ": Need at least one parameter for a contract!");
                valid = false;
            }

            // Load behaviours
            behaviourFactories = new List <BehaviourFactory>();
            foreach (ConfigNode requirementNode in configNode.GetNodes("BEHAVIOUR"))
            {
                BehaviourFactory behaviourFactory = BehaviourFactory.GenerateBehaviourFactory(requirementNode, this);
                if (behaviourFactory != null)
                {
                    behaviourFactories.Add(behaviourFactory);
                }
                else
                {
                    valid = false;
                }
            }

            // Load requirements
            requirements = new List <ContractRequirement>();
            foreach (ConfigNode requirementNode in configNode.GetNodes("REQUIREMENT"))
            {
                ContractRequirement requirement = ContractRequirement.GenerateRequirement(requirementNode, this);
                if (requirement != null)
                {
                    requirements.Add(requirement);
                }
                else
                {
                    valid = false;
                }
            }


            return(valid);
        }