Ejemplo n.º 1
0
        public Supply(ConfigNode node)
        {
            resource  = Lib.ConfigValue(node, "resource", string.Empty);
            on_pod    = Lib.ConfigValue(node, "on_pod", 0.0);
            on_eva    = Lib.ConfigValue(node, "on_eva", 0.0);
            on_rescue = Lib.ConfigValue(node, "on_rescue", Lib.ConfigValue(node, "on_resque", 0.0)); //< old typo, pre 1.1.9
            empty     = Lib.ConfigValue(node, "empty", false);

            low_threshold  = Lib.ConfigValue(node, "low_threshold", 0.15);
            low_message    = Lib.ConfigValue(node, "low_message", string.Empty);
            empty_message  = Lib.ConfigValue(node, "empty_message", string.Empty);
            refill_message = Lib.ConfigValue(node, "refill_message", string.Empty);

            // check that resource is specified
            if (resource.Length == 0)
            {
                throw new Exception("skipping resource-less supply");
            }

            // check that resource exist
            if (Lib.GetDefinition(resource) == null)
            {
                throw new Exception("resource " + resource + " doesn't exist");
            }
        }
Ejemplo n.º 2
0
		public void SetupPod(AvailablePart p)
		{
			// get prefab
			Part prefab = p.partPrefab;

			// avoid problems with some parts that don't have a resource container (like flags)
			if (prefab.Resources == null) return;

			// do nothing if no resource on pod
			if (on_pod <= double.Epsilon) return;

			// do nothing for EVA kerbals, that have now CrewCapacity
			if (prefab.partInfo.name == "kerbalEVA" || prefab.partInfo.name == "kerbalEVAfemale") return;

			// do nothing if not manned
			if (prefab.CrewCapacity == 0) return;

			// do nothing if this isn't a command pod
			if (prefab.FindModuleImplementing<ModuleCommand>() == null) return;

			// calculate quantity
			double quantity = on_pod * (double)prefab.CrewCapacity;

			// add the resource
			Lib.AddResource(prefab, resource, empty ? 0.0 : quantity, quantity);

			// add resource cost
			p.cost += (float)(Lib.GetDefinition(resource).unitCost * (empty ? 0.0 : quantity));
		}
Ejemplo n.º 3
0
        public Rule(ConfigNode node)
        {
            name              = Lib.ConfigValue(node, "name", string.Empty);
            input             = Lib.ConfigValue(node, "input", string.Empty);
            output            = Lib.ConfigValue(node, "output", string.Empty);
            interval          = Lib.ConfigValue(node, "interval", 0.0);
            rate              = Lib.ConfigValue(node, "rate", 0.0);
            ratio             = Lib.ConfigValue(node, "ratio", 0.0);
            input_threshold   = Lib.ConfigValue(node, "input_threshold", 0.0);
            degeneration      = Lib.ConfigValue(node, "degeneration", 0.0);
            variance          = Lib.ConfigValue(node, "variance", 0.0);
            modifiers         = Lib.Tokenize(Lib.ConfigValue(node, "modifier", string.Empty), ',');
            breakdown         = Lib.ConfigValue(node, "breakdown", false);
            output_only       = Lib.ConfigValue(node, "output_only", false);
            warning_threshold = Lib.ConfigValue(node, "warning_threshold", 0.33);
            danger_threshold  = Lib.ConfigValue(node, "danger_threshold", 0.66);
            fatal_threshold   = Lib.ConfigValue(node, "fatal_threshold", 1.0);
            warning_message   = Lib.ConfigValue(node, "warning_message", string.Empty);
            danger_message    = Lib.ConfigValue(node, "danger_message", string.Empty);
            fatal_message     = Lib.ConfigValue(node, "fatal_message", string.Empty);
            relax_message     = Lib.ConfigValue(node, "relax_message", string.Empty);

            // check that name is specified
            if (name.Length == 0)
            {
                throw new Exception("skipping unnamed rule");
            }

            // check that degeneration is not zero
            if (degeneration <= double.Epsilon)
            {
                throw new Exception("skipping zero degeneration rule");
            }

            // check that resources exist
            if (input.Length > 0 && Lib.GetDefinition(input) == null)
            {
                throw new Exception("resource '" + input + "' doesn't exist");
            }
            if (output.Length > 0 && Lib.GetDefinition(output) == null)
            {
                throw new Exception("resource '" + output + "' doesn't exist");
            }

            // calculate ratio of input vs output resource
            if (input.Length > 0 && output.Length > 0 && ratio <= double.Epsilon)
            {
                var input_density  = Lib.GetDefinition(input).density;
                var output_density = Lib.GetDefinition(output).density;
                ratio = Math.Min(input_density, output_density) > double.Epsilon ? input_density / output_density : 1.0;
            }

            trigger = false;
        }
Ejemplo n.º 4
0
        public Process(ConfigNode node)
        {
            name      = Lib.ConfigValue(node, "name", string.Empty);
            modifiers = Lib.Tokenize(Lib.ConfigValue(node, "modifier", string.Empty), ',');

            // check that name is specified
            if (name.Length == 0)
            {
                throw new Exception("skipping unnamed process");
            }

            inputs = new Dictionary <string, double>();
            foreach (string input in node.GetValues("input"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(input, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed input on process " + name);
                }
                string input_res  = tok[0];
                double input_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (input_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // check that resource exist
                if (Lib.GetDefinition(input_res) == null)
                {
                    throw new Exception("resource " + input_res + " doesn't exist for process " + name);
                }

                // record input
                inputs[input_res] = input_rate;
            }

            outputs = new Dictionary <string, double>();
            foreach (string output in node.GetValues("output"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(output, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed output on process " + name);
                }
                string output_res  = tok[0];
                double output_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (output_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // check that resource exist
                if (Lib.GetDefinition(output_res) == null)
                {
                    throw new Exception("resource " + output_res + " doesn't exist for process " + name);
                }

                // record output
                outputs[output_res] = output_rate;
            }

            cures = new Dictionary <string, double>();
            foreach (string output in node.GetValues("cures"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(output, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed cure on process " + name);
                }
                string cure      = tok[0];
                double cure_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (cure.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // record cure
                cures[cure] = cure_rate;
            }

            // parse dump specs
            dump = new DumpSpecs(Lib.ConfigValue(node, "dump", "false"), Lib.ConfigValue(node, "dump_valve", "false"));
        }
Ejemplo n.º 5
0
        public void generate_details(Configure cfg)
        {
            // If a setup component is defined after the Configure module in the ConfigNode,
            // then it is not present in the part during Configure::OnLoad (at precompilation time)
            // so, find_module() will fail in that situation, resulting in no component details
            // being added to the Configure window. Therefore we are forced to generate the details
            // at first use every time the module is loaded, instead of generating them only once.

            // already generated
            if (details != null)
            {
                return;
            }

            // generate module details
            details = new List <Detail>();
            foreach (ConfigureModule cm in modules)
            {
                // find module, skip if it doesn't exist
                PartModule m = cfg.find_module(cm);
                if (m == null)
                {
                    continue;
                }

                // get title
                IModuleInfo module_info = m as IModuleInfo;
                string      title       = module_info != null?module_info.GetModuleTitle() : cm.type;

                if (title.Length == 0)
                {
                    continue;
                }

                // get specs, skip if not implemented by module
                ISpecifics specifics = m as ISpecifics;
                if (specifics == null)
                {
                    continue;
                }
                Specifics specs = specifics.Specs();
                if (specs.entries.Count == 0)
                {
                    continue;
                }

                // add title to details
                details.Add(new Detail(Lib.BuildString("<b><color=#00ffff>", title, "</color></b>")));

                // add specs to details
                foreach (Specifics.Entry e in specs.entries)
                {
                    details.Add(new Detail(e.label, e.value));
                }
            }

            // get visible resources subset
            List <ConfigureResource> visible_resources = resources.FindAll(k => Lib.GetDefinition(k.name).isVisible);

            // generate resource details
            if (visible_resources.Count > 0)
            {
                // add resources title
                details.Add(new Detail("<b><color=#00ffff>Resources</color></b>"));

                // for each visible resource
                foreach (ConfigureResource cr in visible_resources)
                {
                    // add capacity info
                    details.Add(new Detail(cr.name, Lib.Parse.ToDouble(cr.maxAmount).ToString("F2")));
                }
            }

            // generate extra details
            if (mass > double.Epsilon || cost > double.Epsilon)
            {
                details.Add(new Detail("<b><color=#00ffff>Extra</color></b>"));
                if (mass > double.Epsilon)
                {
                    details.Add(new Detail("mass", Lib.HumanReadableMass(mass)));
                }
                if (cost > double.Epsilon)
                {
                    details.Add(new Detail("cost", Lib.HumanReadableCost(cost)));
                }
            }
        }
Ejemplo n.º 6
0
        public Process(ConfigNode node)
        {
            name      = Lib.ConfigValue(node, "name", string.Empty);
            title     = Lib.ConfigValue(node, "title", name);
            broker    = ResourceBroker.GetOrCreate(name, ResourceBroker.BrokerCategory.Converter, title);
            modifiers = Lib.Tokenize(Lib.ConfigValue(node, "modifier", string.Empty), ',');

            // check that name is specified
            if (name.Length == 0)
            {
                throw new Exception("skipping unnamed process");
            }

            // fix for https://github.com/JadeOfMaar/RationalResources/issues/25
            bool skip_resources_validity_check = Lib.ConfigValue(node, "skip_resources_validity_check", false);

            inputs = new Dictionary <string, double>();
            foreach (string input in node.GetValues("input"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(input, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed input on process " + name);
                }
                string input_res  = tok[0];
                double input_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (input_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // check that resource exist
                if (skip_resources_validity_check || Lib.GetDefinition(input_res) == null)
                {
                    throw new Exception("resource " + input_res + " doesn't exist for process " + name);
                }

                // record input
                inputs[input_res] = input_rate;
            }

            outputs = new Dictionary <string, double>();
            foreach (string output in node.GetValues("output"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(output, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed output on process " + name);
                }
                string output_res  = tok[0];
                double output_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (output_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // check that resource exist
                if (skip_resources_validity_check || Lib.GetDefinition(output_res) == null)
                {
                    throw new Exception("resource " + output_res + " doesn't exist for process " + name);
                }

                // record output
                outputs[output_res] = output_rate;
            }

            cures = new Dictionary <string, double>();
            foreach (string output in node.GetValues("cures"))
            {
                // get parameters
                List <string> tok = Lib.Tokenize(output, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed cure on process " + name);
                }
                string cure      = tok[0];
                double cure_rate = Lib.Parse.ToDouble(tok[1]);

                // check that resource is specified
                if (cure.Length == 0)
                {
                    throw new Exception("skipping resource-less process " + name);
                }

                // record cure
                cures[cure] = cure_rate;
            }

            // parse dump specs
            dump = new DumpSpecs(Lib.ConfigValue(node, "dump", "false"), Lib.ConfigValue(node, "dump_valve", "false"));
        }
Ejemplo n.º 7
0
        public Process(ConfigNode node)
        {
            name      = Lib.ConfigValue(node, "name", string.Empty);
            modifiers = Lib.Tokenize(Lib.ConfigValue(node, "modifier", string.Empty), ',');

            // check that name is specified
            if (name.Length == 0)
            {
                throw new Exception("skipping unnamed process");
            }

            inputs = new Dictionary <string, double>();
            foreach (string input in node.GetValues("input"))
            {
                List <string> tok = Lib.Tokenize(input, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed input on process");
                }
                string input_res  = tok[0];
                double input_rate = Lib.Parse.ToDouble(tok[1]);
                inputs[input_res] = input_rate;

                // check that resource is specified
                if (input_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process");
                }

                // check that resource exist
                if (Lib.GetDefinition(input_res) == null)
                {
                    throw new Exception("resource " + input_res + " doesn't exist");
                }
            }

            outputs = new Dictionary <string, double>();
            foreach (string output in node.GetValues("output"))
            {
                List <string> tok = Lib.Tokenize(output, '@');
                if (tok.Count != 2)
                {
                    throw new Exception("malformed output on process");
                }
                string output_res  = tok[0];
                double output_rate = Lib.Parse.ToDouble(tok[1]);
                outputs[output_res] = output_rate;

                // check that resource is specified
                if (output_res.Length == 0)
                {
                    throw new Exception("skipping resource-less process");
                }

                // check that resource exist
                if (Lib.GetDefinition(output_res) == null)
                {
                    throw new Exception("resource " + output_res + " doesn't exist");
                }
            }

            dump = Lib.ConfigValue(node, "dump", true);
        }
Ejemplo n.º 8
0
        public Rule(ConfigNode node)
        {
            name              = Lib.ConfigValue(node, "name", string.Empty);
            title             = Lib.ConfigValue(node, "title", name);
            input             = Lib.ConfigValue(node, "input", string.Empty);
            output            = Lib.ConfigValue(node, "output", string.Empty);
            interval          = Lib.ConfigValue(node, "interval", 0.0);
            rate              = Lib.ConfigValue(node, "rate", 0.0);
            ratio             = Lib.ConfigValue(node, "ratio", 0.0);
            degeneration      = Lib.ConfigValue(node, "degeneration", 0.0);
            variance          = Lib.ConfigValue(node, "variance", 0.0);
            individuality     = Lib.ConfigValue(node, "individuality", 0.0);
            modifiers         = Lib.Tokenize(Lib.ConfigValue(node, "modifier", string.Empty), ',');
            breakdown         = Lib.ConfigValue(node, "breakdown", false);
            lifetime          = Lib.ConfigValue(node, "lifetime", false);
            warning_threshold = Lib.ConfigValue(node, "warning_threshold", 0.33);
            danger_threshold  = Lib.ConfigValue(node, "danger_threshold", 0.66);
            fatal_threshold   = Lib.ConfigValue(node, "fatal_threshold", 1.0);
            warning_message   = Lib.ConfigValue(node, "warning_message", string.Empty);
            danger_message    = Lib.ConfigValue(node, "danger_message", string.Empty);
            fatal_message     = Lib.ConfigValue(node, "fatal_message", string.Empty);
            relax_message     = Lib.ConfigValue(node, "relax_message", string.Empty);
            broker            = ResourceBroker.GetOrCreate(name, ResourceBroker.BrokerCategory.Kerbal, title);

            if (warning_message.Length > 0 && warning_message[0] == '#')
            {
                Lib.Log("Broken translation: " + warning_message, Lib.LogLevel.Warning);
            }
            if (danger_message.Length > 0 && danger_message[0] == '#')
            {
                Lib.Log("Broken translation: " + danger_message, Lib.LogLevel.Warning);
            }
            if (fatal_message.Length > 0 && fatal_message[0] == '#')
            {
                Lib.Log("Broken translation: " + fatal_message, Lib.LogLevel.Warning);
            }
            if (relax_message.Length > 0 && relax_message[0] == '#')
            {
                Lib.Log("Broken translation: " + relax_message, Lib.LogLevel.Warning);
            }

            // check that name is specified
            if (name.Length == 0)
            {
                throw new Exception("skipping unnamed rule");
            }

            // check that degeneration is not zero
            if (degeneration <= double.Epsilon)
            {
                throw new Exception("skipping zero degeneration rule");
            }

            // check that resources exist
            if (input.Length > 0 && Lib.GetDefinition(input) == null)
            {
                throw new Exception("resource '" + input + "' doesn't exist");
            }
            if (output.Length > 0 && Lib.GetDefinition(output) == null)
            {
                throw new Exception("resource '" + output + "' doesn't exist");
            }

            // calculate ratio of input vs output resource
            if (input.Length > 0 && output.Length > 0 && ratio <= double.Epsilon)
            {
                var input_density  = Lib.GetDefinition(input).density;
                var output_density = Lib.GetDefinition(output).density;
                ratio = Math.Min(input_density, output_density) > double.Epsilon ? input_density / output_density : 1.0;
            }
        }