protected override void OnLoadFromConfig(ConfigNode node)
 {
     id = ConfigNodeUtil.ParseValue <string>(node, "id", "");
     if (!string.IsNullOrEmpty(id))
     {
         bodies = CelestialBodyUtil.GetBodiesForStrategy(id);
     }
     else if (node.HasValue("body"))
     {
         bodies = ConfigNodeUtil.ParseValue <List <CelestialBody> >(node, "body");
     }
     else
     {
         bodies = FlightGlobals.Bodies.Where(cb => cb.isHomeWorld);
     }
     invert = ConfigNodeUtil.ParseValue <bool?>(node, "invert", (bool?)false).Value;
 }
Ejemplo n.º 2
0
        public IEnumerator <YieldInstruction> LoadCoroutine()
        {
            // Do Celestial Body expansion
            foreach (UrlDir.UrlConfig config in GameDatabase.Instance.GetConfigs("STRATEGY_BODY_EXPAND"))
            {
                ConfigNode node = config.config;
                Debug.Log("Strategia: Expanding " + node.GetValue("id"));
                foreach (CelestialBody body in CelestialBodyUtil.GetBodiesForStrategy(node.GetValue("id")))
                {
                    // Duplicate the node
                    ConfigNode newStrategy = ExpandNode(node, body);
                    newStrategy.name = "STRATEGY";

                    // Name must be unique
                    string name = node.GetValue("name");
                    int    current;
                    names.TryGetValue(name, out current);
                    names[name] = current + 1;
                    name        = name + current;
                    newStrategy.SetValue("name", name);

                    // Duplicate effect nodes
                    foreach (ConfigNode effect in node.GetNodes("EFFECT"))
                    {
                        ConfigNode newEffect = ExpandNode(effect, body);
                        newStrategy.AddNode(newEffect);
                    }

                    // Add the cloned strategy to the config file
                    Debug.Log("Strategia: Generated strategy '" + newStrategy.GetValue("title") + "'");
                    config.parent.configs.Add(new UrlDir.UrlConfig(config.parent, newStrategy));

                    yield return(null);
                }
            }

            // Do level-based expansion
            foreach (UrlDir.UrlConfig config in GameDatabase.Instance.GetConfigs("STRATEGY_LEVEL_EXPAND"))
            {
                ConfigNode node = config.config;
                Debug.Log("Strategia: Expanding " + node.GetValue("name"));

                int count = ConfigNodeUtil.ParseValue <int>(node, "factorSliderSteps");
                for (int level = 1; level <= count; level++)
                {
                    // Duplicate the node
                    ConfigNode newStrategy = ExpandNode(node, level);
                    if (newStrategy == null)
                    {
                        continue;
                    }
                    newStrategy.name = "STRATEGY";

                    // Name must be unique
                    newStrategy.SetValue("name", newStrategy.GetValue("name") + level);

                    // Set the title
                    newStrategy.SetValue("title", newStrategy.GetValue("title") + " " + StringUtil.IntegerToRoman(level));

                    // Set the group tag
                    newStrategy.SetValue("groupTag", newStrategy.GetValue("groupTag") + StringUtil.IntegerToRoman(level));

                    // Set the factor slider
                    newStrategy.SetValue("factorSliderDefault", ((float)level / ConfigNodeUtil.ParseValue <int>(node, "factorSliderSteps")).ToString(), true);

                    // Set the icon
                    newStrategy.SetValue("icon", newStrategy.GetValue("icon") + level);

                    if (newStrategy.HasValue("requiredReputation"))
                    {
                        float requiredReputation = ConfigNodeUtil.ParseValue <float>(newStrategy, "requiredReputation");
                        newStrategy.SetValue("requiredReputationMin", requiredReputation.ToString(), true);
                        newStrategy.SetValue("requiredReputationMax", requiredReputation.ToString(), true);
                    }

                    // Duplicate effect nodes
                    foreach (ConfigNode effect in node.GetNodes("EFFECT"))
                    {
                        ConfigNode newEffect = ExpandNode(effect, level);
                        if (newEffect != null)
                        {
                            newStrategy.AddNode(newEffect);
                        }
                    }

                    // Add the cloned strategy to the config file
                    Debug.Log("Strategia: Generated strategy '" + newStrategy.GetValue("title") + "'");
                    config.parent.configs.Add(new UrlDir.UrlConfig(config.parent, newStrategy));

                    yield return(null);
                }
            }
        }
Ejemplo n.º 3
0
 protected override void OnLoadFromConfig(ConfigNode node)
 {
     contractType      = ConfigNodeUtil.ParseValue <string>(node, "contractType");
     targetBody        = ConfigNodeUtil.ParseValue <CelestialBody>(node, "targetBody", FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).First());
     bodies            = ConfigNodeUtil.ParseValue <List <CelestialBody> >(node, "bodies", CelestialBodyUtil.GetBodiesForStrategy(Parent.Config.Name).ToList());
     rewardFunds       = ConfigNodeUtil.ParseValue <double>(node, "rewardFunds", 0.0);
     rewardScience     = ConfigNodeUtil.ParseValue <float>(node, "rewardScience", 0.0f);
     rewardReputation  = ConfigNodeUtil.ParseValue <float>(node, "rewardReputation", 0.0f);
     failureFunds      = ConfigNodeUtil.ParseValue <double>(node, "failureFunds", 0.0);
     failureScience    = ConfigNodeUtil.ParseValue <float>(node, "failureScience", 0.0f);
     failureReputation = ConfigNodeUtil.ParseValue <float>(node, "failureReputation", 0.0f);
     advanceFunds      = ConfigNodeUtil.ParseValue <double>(node, "advanceFunds", 0.0);
     advanceScience    = ConfigNodeUtil.ParseValue <float>(node, "advanceScience", 0.0f);
     advanceReputation = ConfigNodeUtil.ParseValue <float>(node, "advanceReputation", 0.0f);
     synopsis          = ConfigNodeUtil.ParseValue <string>(node, "synopsis");
     completedMessage  = ConfigNodeUtil.ParseValue <string>(node, "completedMessage");
     failureMessage    = ConfigNodeUtil.ParseValue <string>(node, "failureMessage");
 }