/**
         * Prepare the recipe with regard to the amount of crew in this module
         */
        protected override ConversionRecipe PrepareRecipe(double deltatime)
        {
            double rate = currentRate;

            ConversionRecipe newRecipe = new ConversionRecipe();

            //the amounts (use?)
            newRecipe.FillAmount = 1;
            newRecipe.TakeAmount = 1;

            if (ModuleIsActive())
            {
                status = "In Progress";
            }
            else
            {
                status = "Inactive";
            }

            //the amounts (use?)
            newRecipe.FillAmount = 1;// (float)rate;
            newRecipe.TakeAmount = 1;// (float)rate;

            //add the inputs to the recipe
            foreach (ResourceRatio res in inputList)
            {
                ResourceRatio newRes = new ResourceRatio();
                newRes.ResourceName = res.ResourceName;
                newRes.FlowMode = res.FlowMode;
                newRes.Ratio = res.Ratio * rate;
                newRes.DumpExcess = res.DumpExcess;
                newRecipe.Inputs.Add(newRes);
            }
            //add the outputs to the recipe
            foreach (ResourceRatio res in outputList)
            {
                ResourceRatio newRes = new ResourceRatio();
                newRes.ResourceName = res.ResourceName;
                newRes.FlowMode = res.FlowMode;
                newRes.DumpExcess = res.DumpExcess;
                newRes.Ratio = res.Ratio * rate;
                newRecipe.Outputs.Add(newRes);
            }

            //only add the fertilizer as a requirement when it is used
            foreach (ResourceRatio res in reqList)
            {
                ResourceRatio newRes = new ResourceRatio();
                newRes.ResourceName = res.ResourceName;
                newRes.FlowMode = res.FlowMode;
                newRes.DumpExcess = res.DumpExcess;
                newRes.Ratio = res.Ratio * rate;
                newRecipe.Outputs.Add(newRes);
            }
            return newRecipe;
        }
        private ConversionRecipe LoadRecipe()
        {
            var r = new ConversionRecipe();
            try
            {

                if (!String.IsNullOrEmpty(RecipeInputs))
                {
                    var inputs = RecipeInputs.Split(',');
                    for (int ip = 0; ip < inputs.Length; ip += 2)
                    {
                        print(String.Format("[REGOLITH] - INPUT {0} {1}", inputs[ip], inputs[ip + 1]));
                        r.Inputs.Add(new ResourceRatio
                        {
                            ResourceName = inputs[ip].Trim(),
                            Ratio = Convert.ToDouble(inputs[ip + 1].Trim())
                        });
                    }
                }

                if (!String.IsNullOrEmpty(RecipeOutputs))
                {
                    var outputs = RecipeOutputs.Split(',');
                    for (int op = 0; op < outputs.Length; op += 3)
                    {
                        print(String.Format("[REGOLITH] - OUTPUTS {0} {1} {2}", outputs[op], outputs[op + 1],
                            outputs[op + 2]));
                        r.Outputs.Add(new ResourceRatio
                        {
                            ResourceName = outputs[op].Trim(),
                            Ratio = Convert.ToDouble(outputs[op + 1].Trim()),
                            DumpExcess = Convert.ToBoolean(outputs[op + 2].Trim())
                        });
                    }
                }

                if (!String.IsNullOrEmpty(RequiredResources))
                {
                    var requirements = RequiredResources.Split(',');
                    for (int rr = 0; rr < requirements.Length; rr += 2)
                    {
                        print(String.Format("[REGOLITH] - REQUIREMENTS {0} {1}", requirements[rr], requirements[rr + 1]));
                        r.Requirements.Add(new ResourceRatio
                        {
                            ResourceName = requirements[rr].Trim(),
                            Ratio = Convert.ToDouble(requirements[rr + 1].Trim()),
                        });
                    }
                }
            }
            catch (Exception)
            {
                print(String.Format("[REGOLITH] Error performing conversion for '{0}' - '{1}' - '{2}'", RecipeInputs, RecipeOutputs, RequiredResources));
            }
            return r;
        }
        protected override ConversionRecipe PrepareRecipe(double deltatime)
        {

            if (_recipe == null)
                _recipe = LoadRecipe();
            UpdateConverterStatus();
            if (!IsActivated)
                return null;
            return _recipe;
        }
Exemplo n.º 4
0
        protected override ConversionRecipe LoadRecipe()
        {
            var r = new ConversionRecipe();
            try
            {
                //conversionRate must be > 0, otherwise set to default = 1.
                if (conversionRate < 0)
                    conversionRate = 1f;
                //if conversionRate is not equal to 1 multiply all Inputs, Outputs and Requirements resource Ratios
                // by the value of conversionRate.
                if (conversionRate != 1f)
                {
                    for (int i = 0; i < inputList.Count; i++)
                    {
                        double tmpRate = inputList[i].Ratio * conversionRate;
                        ResourceRatio tmpRat = new ResourceRatio(inputList[i].ResourceName, tmpRate,
                            inputList[i].DumpExcess) {FlowMode = inputList[i].FlowMode};
                        r.Inputs.Add(tmpRat);
                    }
                    for (int i = 0; i < outputList.Count; i++)
                    {
                        double tmpRate = outputList[i].Ratio * conversionRate;
                        ResourceRatio tmpRat = new ResourceRatio(outputList[i].ResourceName, tmpRate,
                            outputList[i].DumpExcess)
                        { FlowMode = outputList[i].FlowMode };
                        r.Outputs.Add(tmpRat);
                    }
                    for (int i = 0; i < reqList.Count; i++)
                    {
                        double tmpRate = reqList[i].Ratio * conversionRate;
                        ResourceRatio tmpRat = new ResourceRatio(reqList[i].ResourceName, tmpRate,
                            reqList[i].DumpExcess)
                        { FlowMode = reqList[i].FlowMode };
                        r.Requirements.Add(tmpRat);
                    }
                }
                // else, conversion rate is 1. We just use the values from the cfg file.
                else
                {

                    r.Inputs.AddRange(inputList);
                    r.Outputs.AddRange(outputList);
                    r.Requirements.AddRange(reqList);
                }

                // if CovertByMass then convert Recipe to Units.
                if (ConvertByMass)
                    ConvertRecipeToUnits(r);
            }
            catch (Exception)
            {
                this.LogError("[TACGenericConverter] Error creating recipe");
            }
            return r;
        }
		ConversionRecipe LoadRecipe(double rate)
		{
			ConversionRecipe recipe = new ConversionRecipe();
			recipe.Inputs.AddRange(inputList);
			bool dumpExcess = false;
			recipe.Outputs.Add(new ResourceRatio {
				ResourceName = ResourceName,
				Ratio = rate,
				DumpExcess = dumpExcess
			});
			return recipe;
		}
Exemplo n.º 6
0
 protected override ConversionRecipe PrepareRecipe(double deltatime)
 {
     //This is where the rubber hits the road.  Let us see if we can
     //keep our Kerbals cozy and warm.
     var recipe = new ConversionRecipe();
     var numCrew = part.protoModuleCrew.Count();
     var ecAmount = 0.01f;
     var supAmount = 0.00005f;
     var scrapAmount = 0.00005f;
     recipe.Inputs.Add(new ResourceRatio { FlowMode = "ALL_VESSEL", Ratio = ecAmount * numCrew, ResourceName = "ElectricCharge", DumpExcess = true });
     recipe.Inputs.Add(new ResourceRatio { FlowMode = "ALL_VESSEL", Ratio = supAmount * numCrew, ResourceName = "Supplies", DumpExcess = true });
     recipe.Outputs.Add(new ResourceRatio { FlowMode = "ALL_VESSEL", Ratio = scrapAmount * numCrew, ResourceName = "Mulch", DumpExcess = true });
     return recipe;
 }
		ConversionRecipe LoadRecipe ()
		{
			var recipe = new ConversionRecipe ();
			recipe.Inputs.AddRange (ProcessRatio (inputList));
			var inputMass = GetResourceMass (recipe.Inputs);
			recipe.Outputs.AddRange (ProcessRatio (outputList, inputMass));
			recipe.Requirements.AddRange (ProcessRatio (reqList));
			return recipe;
		}
Exemplo n.º 8
0
        private ConversionRecipe GenerateSupplyRecipe()
        {
            //Two recipes are executed.  One for EC, one for Supplies.
            var v = LifeSupportManager.Instance.FetchVessel(part.vessel.id.ToString());
            var recipe = new ConversionRecipe();
            var numCrew = part.protoModuleCrew.Count;
            var recPercent = v.RecyclerMultiplier;
            var supAmount = LifeSupportScenario.Instance.settings.GetSettings().SupplyAmount;
            var scrapAmount = LifeSupportScenario.Instance.settings.GetSettings().WasteAmount;
            var repAmount = LifeSupportScenario.Instance.settings.GetSettings().ReplacementPartAmount;
            if (part.Resources.Contains("ReplacementParts"))
            {
                recipe.Inputs.Add(new ResourceRatio { FlowMode = ResourceFlowMode.ALL_VESSEL, Ratio = repAmount * numCrew, ResourceName = "ReplacementParts", DumpExcess = false });
            }

            var supRatio = supAmount * numCrew * recPercent;
            var mulchRatio = scrapAmount * numCrew * recPercent;

            recipe.Inputs.Add(new ResourceRatio { FlowMode = ResourceFlowMode.ALL_VESSEL, Ratio = supRatio, ResourceName = "Supplies", DumpExcess = true });
            recipe.Outputs.Add(new ResourceRatio { FlowMode = ResourceFlowMode.ALL_VESSEL, Ratio = mulchRatio, ResourceName = "Mulch", DumpExcess = true });
            return recipe;
        }
Exemplo n.º 9
0
 private ConversionRecipe GenerateECRecipe()
 {
     //Two recipes are executed.  One for EC, one for Supplies.
     var v = LifeSupportManager.Instance.FetchVessel(part.vessel.id.ToString());
     var recipe = new ConversionRecipe();
     var numCrew = part.protoModuleCrew.Count;
     var ecAmount = LifeSupportScenario.Instance.settings.GetSettings().ECAmount;
     recipe.Inputs.Add(new ResourceRatio { FlowMode = ResourceFlowMode.ALL_VESSEL, Ratio = ecAmount * numCrew, ResourceName = "ElectricCharge", DumpExcess = true });
     return recipe;
 }
Exemplo n.º 10
0
 public void reloadRecipe()
 {
     _recipe = LoadRecipe();
     //RecipeOutputs = pipelineShip.DictionaryFromString(RecipeOutputs);
 }
        /**
         * Prepare the recipe with regard to the amount of crew in this module
         */
        protected override ConversionRecipe PrepareRecipe(double deltatime)
        {
            double rate = currentRate;
            if (rate < 0.0d) {
                rate = maxProductionRate;
            }
            //rate = rate *deltatime * 50;

            ConversionRecipe newRecipe = new ConversionRecipe();

            if (this.ModuleIsActive())
            {
                status = "In Progress";
            }
            else
            {
                status = "Inactive";
            }

            //the amounts (use?)
            newRecipe.FillAmount = 1;// (float)rate;
            newRecipe.TakeAmount = 1;// (float)rate;

            //add the inputs to the recipe
            foreach (ResourceRatio res in inputList)
            {

                if (useGrowthPromoter || !res.ResourceName.Equals(boosterName))
                {
                    ResourceRatio newRes = new ResourceRatio();
                    newRes.ResourceName = res.ResourceName;
                    newRes.FlowMode = res.FlowMode;
                    newRes.Ratio = res.Ratio * rate;
                    newRes.DumpExcess = res.DumpExcess;
                    newRecipe.Inputs.Add(newRes);
                }
            }
            //add the outputs to the recipe
            foreach (ResourceRatio res in outputList)
            {
                ResourceRatio newRes = new ResourceRatio();
                newRes.ResourceName = res.ResourceName;
                newRes.FlowMode = res.FlowMode;
                newRes.DumpExcess = res.DumpExcess;

                //when we have the main resource and the fertilizer active
                if (useGrowthPromoter && res.ResourceName.Equals(boostedOutputName))
                {
                    newRes.Ratio = res.Ratio * rate * fertilizerBenefit;
                }
                else
                {
                    newRes.Ratio = res.Ratio * rate;
                }

                newRecipe.Outputs.Add(newRes);
            }

            //only add the fertilizer as a requirement when it is used
            foreach (ResourceRatio res in reqList)
            {
                if (res.ResourceName.Equals(boosterName))
                {
                    if (useGrowthPromoter) {
                        newRecipe.Requirements.Add(res);
                    }
                }
                else {
                    newRecipe.Requirements.Add(res);
                }
            }

            return newRecipe;
        }
Exemplo n.º 12
0
 public void a_conversion_recipe_has_a_list_of_outputs()
 {
     var c = new ConversionRecipe();
     c.Outputs.Add(new ResourceRatio());
     Assert.IsNotNull(c.Outputs);
 }
Exemplo n.º 13
0
 private ConversionRecipe GetSimpleRecipe()
 {
     var recipe = new ConversionRecipe();
     recipe.Inputs.Add(new ResourceRatio { ResourceName = "Ore", Ratio = 1 });
     recipe.Outputs.Add(new ResourceRatio { ResourceName = "Metal", Ratio = 1 });
     return recipe;
 }
Exemplo n.º 14
0
 private ConversionRecipe GetComplexRecipe()
 {
     var recipe = new ConversionRecipe();
     recipe.Inputs.Add(new ResourceRatio { ResourceName = "Hydrogen", Ratio = 2 });
     recipe.Inputs.Add(new ResourceRatio { ResourceName = "Oxygen", Ratio = 2 });
     recipe.Inputs.Add(new ResourceRatio { ResourceName = "ElectricCharge", Ratio = 10 });
     recipe.Outputs.Add(new ResourceRatio { ResourceName = "LiquidFuel", Ratio = 0.9f });
     recipe.Outputs.Add(new ResourceRatio { ResourceName = "Oxidizer", Ratio = 1.1f });
     return recipe;
 }
Exemplo n.º 15
0
        /**
         * Prepare the recipe with regard to the amount of crew in this module
         */
        protected override ConversionRecipe PrepareRecipe(double deltatime)
        {
            double rate = currentRate;

            if (rate < 0.0d)
            {
                rate = maxProductionRate;
            }
            //rate = rate *deltatime * 50;

            ConversionRecipe newRecipe = new ConversionRecipe();

            if (this.ModuleIsActive())
            {
                status = "In Progress";
            }
            else
            {
                status = "Inactive";
            }

            //the amounts (use?)
            newRecipe.FillAmount = 1; // (float)rate;
            newRecipe.TakeAmount = 1; // (float)rate;

            //add the inputs to the recipe
            foreach (ResourceRatio res in inputList)
            {
                if (useGrowthPromoter || !res.ResourceName.Equals(boosterName))
                {
                    ResourceRatio newRes = new ResourceRatio();
                    newRes.ResourceName = res.ResourceName;
                    newRes.FlowMode     = res.FlowMode;
                    newRes.Ratio        = res.Ratio * rate;
                    newRes.DumpExcess   = res.DumpExcess;
                    newRecipe.Inputs.Add(newRes);
                }
            }
            //add the outputs to the recipe
            foreach (ResourceRatio res in outputList)
            {
                ResourceRatio newRes = new ResourceRatio();
                newRes.ResourceName = res.ResourceName;
                newRes.FlowMode     = res.FlowMode;
                newRes.DumpExcess   = res.DumpExcess;

                //when we have the main resource and the fertilizer active
                if (useGrowthPromoter && res.ResourceName.Equals(boostedOutputName))
                {
                    newRes.Ratio = res.Ratio * rate * fertilizerBenefit;
                }
                else
                {
                    newRes.Ratio = res.Ratio * rate;
                }

                newRecipe.Outputs.Add(newRes);
            }

            //only add the fertilizer as a requirement when it is used
            foreach (ResourceRatio res in reqList)
            {
                if (res.ResourceName.Equals(boosterName))
                {
                    if (useGrowthPromoter)
                    {
                        newRecipe.Requirements.Add(res);
                    }
                }
                else
                {
                    newRecipe.Requirements.Add(res);
                }
            }

            return(newRecipe);
        }
Exemplo n.º 16
0
        protected override ConversionRecipe PrepareRecipe(double deltaTime)
        {
            //Determine if we are in fact latched to an asteroid
            var potato = GetAttachedPotato();

            if (potato == null)
            {
                status      = "No asteroid detected";
                IsActivated = false;
                return(null);
            }

            if (DirectAttach && !(part.children.Contains(potato) || part.parent == potato))
            {
                status      = "Not directly attached to asteroid";
                IsActivated = false;
                return(null);
            }

            if (!RockOnly && !potato.Modules.Contains("REGO_ModuleAsteroidResource"))
            {
                status      = "No resource data";
                IsActivated = false;
                return(null);
            }
            var resourceList = potato.FindModulesImplementing <REGO_ModuleAsteroidResource>();

            if (!CheckForImpact())
            {
                status      = "No surface impact";
                IsActivated = false;
                return(null);
            }

            var info = potato.FindModuleImplementing <REGO_ModuleAsteroidInfo>();

            if (info == null)
            {
                status      = "No info";
                IsActivated = false;
                return(null);
            }

            if (info.massThreshold >= potato.mass)
            {
                status      = "Resources Depleted";
                IsActivated = false;
                return(null);
            }

            var ec = _broker.AmountAvailable(part, "ElectricCharge");

            if (ec <= deltaTime * PowerConsumption)
            {
                status      = "Insufficient Power";
                IsActivated = false;
                return(null);
            }

            //Handle state change
            UpdateConverterStatus();
            //If we're enabled"
            if (!IsActivated)
            {
                return(null);
            }


            //Fetch our recipe
            var recipe = new ConversionRecipe();

            recipe.Inputs.Add(new ResourceRatio {
                ResourceName = "ElectricCharge", Ratio = PowerConsumption
            });


            if (RockOnly)
            {
                resourceList.Clear();
                resourceList.Add(new REGO_ModuleAsteroidResource {
                    abundance = 1, resourceName = "Rock"
                });
            }
            else
            {
                //Setup rock
                var purity  = resourceList.Sum(ar => ar.abundance);
                var rockAmt = 1 - purity;
                resourceList.Add(new REGO_ModuleAsteroidResource {
                    abundance = rockAmt, resourceName = "Rock"
                });
            }

            foreach (var ar in resourceList)
            {
                if (!(ar.abundance > Utilities.FLOAT_TOLERANCE))
                {
                    continue;
                }
                var res     = potato.Resources[ar.resourceName];
                var resInfo = PartResourceLibrary.Instance.GetDefinition(res.resourceName);
                var outRes  = new ResourceRatio {
                    ResourceName = ar.resourceName, Ratio = ar.abundance * Efficiency
                };
                //Make sure we have enough free space
                var spaceNeeded    = deltaTime * ar.abundance * Efficiency;
                var spaceAvailable = res.maxAmount - res.amount;
                if (spaceAvailable < spaceNeeded)
                {
                    var slackMass  = potato.mass - info.massThreshold;
                    var maxSpace   = slackMass / resInfo.density;
                    var unitsToAdd = Math.Min(maxSpace, (spaceNeeded - spaceAvailable));
                    var newMass    = potato.mass - ((float)(resInfo.density * unitsToAdd));
                    res.maxAmount += unitsToAdd;
                    potato.mass    = newMass;
                }
                recipe.Outputs.Add(outRes);
            }
            return(recipe);
        }