示例#1
0
        protected bool canLoadModule(ConfigNode node)
        {
            string value;

            //If we are in career mode, make sure we have unlocked the tech node.
            if (ResearchAndDevelopment.Instance != null)
            {
                value = node.GetValue("TechRequired");
                if (!string.IsNullOrEmpty(value) && (HighLogic.CurrentGame.Mode == Game.Modes.CAREER || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX))
                {
                    if (ResearchAndDevelopment.GetTechnologyState(value) != RDTech.State.Available)
                    {
                        return(false);
                    }
                }
            }

            //Now check for required mod
            value = node.GetValue("needs");
            if (!string.IsNullOrEmpty(value))
            {
                if (TemplateManager.CheckNeeds(value) != EInvalidTemplateReasons.TemplateIsValid)
                {
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        public EInvalidTemplateReasons CanUseTemplate(ConfigNode nodeTemplate)
        {
            string     value;
            PartModule requiredModule;
            EInvalidTemplateReasons invalidTemplateReason;

            //Make sure the vessel object is set
            if (this.vessel == null)
            {
                this.vessel = this.part.vessel;
            }

            //If we need a specific mod then check for it.
            value = nodeTemplate.GetValue("needs");
            if (string.IsNullOrEmpty(value) == false)
            {
                invalidTemplateReason = TemplateManager.CheckNeeds(value);

                if (invalidTemplateReason != EInvalidTemplateReasons.TemplateIsValid)
                {
                    return(invalidTemplateReason);
                }
            }

            //If we need a specific module then check for it.
            value = nodeTemplate.GetValue("requiresModule");
            if (string.IsNullOrEmpty(value) == false)
            {
                requiredModule = this.part.Modules[value];
                if (requiredModule == null)
                {
                    return(EInvalidTemplateReasons.RequiredModuleNotFound);
                }
            }

            //If we need a specific template type then check for it.
            //Only templates with the appropriate tag will be accepted.
            if (string.IsNullOrEmpty(templateTags) == false)
            {
                if (nodeTemplate.HasValue("templateTags") == false)
                {
                    return(EInvalidTemplateReasons.TagsNotFound);
                }

                value = nodeTemplate.GetValue("templateTags");
                string[] tags = value.Split(new char[] { ';' });
                foreach (string tag in tags)
                {
                    if (templateTags.Contains(tag))
                    {
                        return(EInvalidTemplateReasons.TemplateIsValid);
                    }
                }
                return(EInvalidTemplateReasons.TagsNotFound);
            }

            return(EInvalidTemplateReasons.TemplateIsValid);
        }