示例#1
0
 public override bool MeetRequirements()
 {
   // stop checking when requirements are met
   if (!meet_requirements)
   {
     meet_requirements =
       PartLoader.getPartInfoByName("Greenhouse") != null  // greenhouse part is present
       && Lib.TechReady() && Lib.HasTech("scienceTech")    // greenhouse unlocked
       && DB.Ready() && DB.Landmarks().space_harvest == 0; // greenhouse never harvested in space before
   }
   return meet_requirements;
 }
示例#2
0
        public List <ConfigureSetup> GetUnlockedSetups()
        {
            List <ConfigureSetup> unlockedSetups = new List <ConfigureSetup>();

            foreach (ConfigureSetup setup in setups)
            {
                // if unlocked
                if (setup.tech.Length == 0 || Lib.HasTech(setup.tech))
                {
                    // unlock
                    unlockedSetups.Add(setup);
                }
            }
            return(unlockedSetups);
        }
示例#3
0
        public void configure()
        {
            // shortcut to resource library
            var reslib = PartResourceLibrary.Instance.resourceDefinitions;

            // reset extra cost and mass
            extra_cost = 0.0;
            extra_mass = 0.0;

            // find modules unlocked by tech
            unlocked = new List <ConfigureSetup>();
            foreach (ConfigureSetup setup in setups)
            {
                // if unlocked
                if (setup.tech.Length == 0 || Lib.HasTech(setup.tech))
                {
                    // unlock
                    unlocked.Add(setup);
                }
            }

            // make sure configuration include all available slots
            // this also create default configuration
            // - we don it only in the editor
            // - we avoid corner case when cfg was never set up (because craft was never in VAB)
            if (Lib.IsEditor() || selected.Count == 0)
            {
                while (selected.Count < Math.Min(slots, (uint)unlocked.Count))
                {
                    selected.Add(unlocked.Find(k => selected.IndexOf(k.name) == -1).name);
                }
            }

            // for each setup
            foreach (ConfigureSetup setup in setups)
            {
                // detect if the setup is selected
                bool active = selected.Contains(setup.name);

                // detect if the setup was previously selected
                bool prev_active = prev_selected.Contains(setup.name);

                // for each module specification in the setup
                foreach (ConfigureModule cm in setup.modules)
                {
                    // try to find the module
                    PartModule m = find_module(cm);

                    // if the module exist
                    if (m != null)
                    {
                        // call configure/deconfigure functions on module if available
                        IConfigurable configurable_module = m as IConfigurable;
                        if (configurable_module != null)
                        {
                            configurable_module.Configure(active);
                        }

                        // enable/disable the module
                        m.isEnabled = active;
                        m.enabled   = active;
                    }
                }

                // for each resource specification in the setup
                foreach (ConfigureResource cr in setup.resources)
                {
                    // ignore non-existing resources
                    if (!reslib.Contains(cr.name))
                    {
                        continue;
                    }

                    // get resource unit cost
                    double unit_cost = reslib[cr.name].unitCost;

                    // parse resource amount and capacity
                    double amount   = Lib.Parse.ToDouble(cr.amount);
                    double capacity = Lib.Parse.ToDouble(cr.maxAmount);

                    // (de)install resource
                    if ((prev_active != (active && capacity > 0.0)) || (reconfigure_cs && initialized))
                    {
                        // if previously selected
                        if (prev_active)
                        {
                            // remove the resources
                            Lib.RemoveResource(part, cr.name, amount, capacity);
                        }

                        // if selected
                        if (active && capacity > 0.0)
                        {
                            // add the resources
                            // - in flight, do not add amount
                            Lib.AddResource(part, cr.name, Lib.IsFlight() ? 0.0 : amount, capacity);
                        }
                    }

                    // add resource cost
                    if (active)
                    {
                        extra_cost += amount * unit_cost;
                    }
                }

                // add setup extra cost and mass
                if (active)
                {
                    extra_cost += setup.cost;
                    extra_mass += setup.mass;
                }
            }

            // remember previously selected setups
            prev_selected.Clear();
            foreach (string s in selected)
            {
                prev_selected.Add(s);
            }

            // save configuration
            WriteArchive archive = new WriteArchive();

            archive.save(selected.Count);
            foreach (string s in selected)
            {
                archive.save(s);
            }
            cfg = archive.serialize();

            // save previous configuration
            archive = new WriteArchive();
            archive.save(prev_selected.Count);
            foreach (string s in prev_selected)
            {
                archive.save(s);
            }
            prev_cfg = archive.serialize();

            // in the editor
            if (Lib.IsEditor())
            {
                // for each part in the symmetry group (avoid infinite recursion)
                if (!avoid_inf_recursion)
                {
                    avoid_inf_recursion = true;
                    foreach (Part p in part.symmetryCounterparts)
                    {
                        // get the Configure module
                        Configure c = p.FindModulesImplementing <Configure>().Find(k => k.title == title);

                        // both modules will share configuration
                        c.selected = selected;

                        // re-configure the other module
                        c.configure();
                    }
                    avoid_inf_recursion = false;
                }
            }

            // refresh this part ui
            MonoUtilities.RefreshContextWindows(part);

            // refresh VAB ui
            if (Lib.IsEditor())
            {
                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
            }

            // this was configured at least once
            initialized = true;
        }
示例#4
0
        void configure()
        {
            // store list of modules to remove
            var module_to_remove = new List <PartModule>();

            // store list of resources to remove
            var resource_to_remove = new List <PartResource>();

            // shortcut to resource library
            var reslib = PartResourceLibrary.Instance.resourceDefinitions;

            // reset extra cost and mass
            extra_cost = 0.0;
            extra_mass = 0.0;

            // find modules unlocked by tech
            unlocked = new List <ConfigureSetup>();
            foreach (ConfigureSetup setup in setups)
            {
                // if unlocked
                if (setup.tech.Length == 0 || Lib.HasTech(setup.tech))
                {
                    // unlock
                    unlocked.Add(setup);
                }
            }

            // make sure configuration include all available slots
            // this also create default configuration
            if (HighLogic.LoadedSceneIsEditor)
            {
                while (selected.Count < Math.Min(slots, (uint)unlocked.Count))
                {
                    selected.Add(unlocked.Find(k => selected.IndexOf(k.name) == -1).name);
                }
            }

            // for each setup
            foreach (ConfigureSetup setup in setups)
            {
                // detect if the setup is selected
                bool active = selected.Contains(setup.name);

                // for each module specification in the setup
                foreach (ConfigureModule cm in setup.modules)
                {
                    // try to find the module
                    PartModule m = find_module(cm);

                    // if the module exist
                    if (m != null)
                    {
                        // in the editor, enable/disable it
                        if (HighLogic.LoadedSceneIsEditor)
                        {
                            m.isEnabled = active;
                        }
                        // in flight, add to list of modules to remove
                        else if (Lib.SceneIsGame())
                        {
                            if (!active)
                            {
                                module_to_remove.Add(m);
                            }
                        }
                    }
                }

                // only in the editor
                if (HighLogic.LoadedSceneIsEditor)
                {
                    // for each resource specification in the setup
                    foreach (ConfigureResource cr in setup.resources)
                    {
                        // ignore non-existing resources
                        if (!reslib.Contains(cr.name))
                        {
                            continue;
                        }

                        // get resource unit cost
                        double unit_cost = reslib[cr.name].unitCost;

                        // parse resource amount and capacity
                        double amount   = Lib.Parse.ToDouble(cr.amount);
                        double capacity = Lib.Parse.ToDouble(cr.maxAmount);

                        // get resources to remove first
                        resource_to_remove.Clear();
                        foreach (PartResource res in part.Resources)
                        {
                            if (res.resourceName == cr.name)
                            {
                                resource_to_remove.Add(res);
                            }
                        }

                        // remove resources
                        foreach (PartResource r in resource_to_remove)
                        {
                            if (part.Resources.list.Contains(r))
                            {
                                part.Resources.list.Remove(r);
                                Destroy(r);
                            }
                        }

                        // if selected
                        if (active && capacity > 0.0)
                        {
                            // add the resource
                            ConfigNode res = new ConfigNode("RESOURCE");
                            res.AddValue("name", cr.name);
                            res.AddValue("amount", cr.amount);
                            res.AddValue("maxAmount", cr.maxAmount);
                            res.AddValue("isVisible", true);
                            res.AddValue("isTweakable", true);
                            part.Resources.Add(res);

                            // add extra cost
                            extra_cost += amount * unit_cost;
                        }
                    }
                }

                // add setup extra cost and mass
                if (active)
                {
                    extra_cost += setup.cost;
                    extra_mass += setup.mass;
                }
            }

            // remove non-selected modules
            foreach (PartModule m in module_to_remove)
            {
                part.RemoveModule(m);
            }

            // save configuration
            WriteArchive archive = new WriteArchive();

            archive.save(selected.Count);
            foreach (string s in selected)
            {
                archive.save(s);
            }
            cfg = archive.serialize();
        }