void ProcessInputs(ConverterRecipe recipe, double blend, int ind1, int ind2) { BlendRecipes(recipe.InputRecipes[0], blend, InputRecipes[ind1], InputRecipes[ind2]); recipe.Masses[0] = Blend(blend, Masses[ind1], Masses[ind2]); }
protected override ConversionRecipe PrepareRecipe(double deltatime) { if (!IsActivated && ratio_recipe != null) { return null; } if (ratio_recipe == null) { ratio_recipe = new ConversionRecipe (); int real_inputs = RealIngredients (current_recipe.InputRecipes[0]); int real_outputs = RealIngredients (current_recipe.OutputRecipes[0]); ratio_recipe.Inputs.AddRange (new ResourceRatio[real_inputs]); ratio_recipe.Outputs.AddRange (new ResourceRatio[real_outputs]); } efficiency = DetermineEfficiency (part.temperature); if (efficiency != prevEfficiency) { prevEfficiency = efficiency; prevDeltaTime = -1; //force rebake current_recipe = converter_recipe.Bake (efficiency, current_recipe); } if (deltatime != prevDeltaTime) { prevDeltaTime = deltatime; double mass = current_recipe.Masses[0] * Rate; Recipe inputs = current_recipe.InputRecipes[0].Bake (mass); Recipe outputs = current_recipe.OutputRecipes[0].Bake (mass); heatFlux = 0; // positive input heat consumes heat heatFlux -= SetRatios (inputs, ratio_recipe.Inputs); // positive output heat generates heat heatFlux += SetRatios (outputs, ratio_recipe.Outputs); heatFlux *= 1e3; } return ratio_recipe; }
public override void OnLoad(ConfigNode node) { var effKeys = node.GetValues("efficiency"); if (effKeys.Length == 1) { double eff; double.TryParse(effKeys[0], out eff); efficiencyCurve = SinglePoint(eff); } else if (effKeys.Length > 1) { efficiencyCurve = MulitplePoints(effKeys); } else { ELConverter prefab = null; // loading in-flight? if (part.partInfo != null && part.partInfo.partPrefab != null) { int index = part.Modules.IndexOf(this); PartModule module = part.partInfo.partPrefab.Modules[index]; prefab = module as ELConverter; } if (prefab != null) { efficiencyCurve = prefab.efficiencyCurve; } else { efficiencyCurve = SinglePoint(1); } } converter_recipe = ELRecipeDatabase.ConverterRecipe(ConverterRecipe); for (int i = 0; i < efficiencyCurve.Length; i++) { Debug.LogFormat("efficiency: {0}", efficiencyCurve[i]); } if (converter_recipe == null) { Debug.LogFormat("[ELConverter] unknown recipe \"{0}\"", ConverterRecipe); } else { Debug.LogFormat("[ELConverter] found recipe \"{0}\"", ConverterRecipe); current_recipe = converter_recipe.Bake(0.5, current_recipe); } // two birds with one stone: make it clear that the config is // broken and ensure the stock converter doesn't mess with us RemoveConflictingNodes(node, "INPUT_RESOURCE"); RemoveConflictingNodes(node, "OUTPUT_RESOURCE"); RemoveConflictingNodes(node, "REQUIRED_RESOURCE"); base.OnLoad(node); }
public ConverterRecipe Bake(double efficiency, ConverterRecipe recipe) { if (recipe == null) { recipe = new ConverterRecipe(); recipe.InputRecipes[0] = new Recipe(InputRecipes[0]); recipe.OutputRecipes[0] = new Recipe(OutputRecipes[0]); } int maxI = InputRecipes.Length - 1; if (efficiency <= InputEfficiencies[0]) { ProcessInputs(recipe, 0, 0, 0); } else if (efficiency >= InputEfficiencies[maxI]) { ProcessInputs(recipe, 1, maxI, maxI); } else { int i = maxI; while (i > 0 && efficiency < InputEfficiencies[--i]) { } double gap = InputEfficiencies[i + 1] - InputEfficiencies[i]; double blend = (efficiency - InputEfficiencies[i]) / gap; ProcessInputs(recipe, blend, i, i + 1); } int maxO = OutputRecipes.Length - 1; if (efficiency <= OutputEfficiencies[0]) { ProcessOutputs(recipe, 0, 0, 0); } else if (efficiency >= OutputEfficiencies[maxO]) { ProcessOutputs(recipe, 1, maxO, maxO); } else { int i = maxO; while (i > 0 && efficiency < OutputEfficiencies[--i]) { } double gap = OutputEfficiencies[i + 1] - OutputEfficiencies[i]; double blend = (efficiency - OutputEfficiencies[i]) / gap; ProcessOutputs(recipe, blend, i, i + 1); } return(recipe); }
IEnumerator LoadConverterRecipes() { var dbase = GameDatabase.Instance; var node_list = dbase.GetConfigNodes("EL_ConverterRecipe"); for (int i = 0; i < node_list.Length; i++) { var node = node_list[i]; string name = node.GetValue("name"); if (String.IsNullOrEmpty(name)) { print("[EL Recipes] skipping unnamed EL_ConverterRecipe"); continue; } print("[EL ConverterRecipe] " + name); var recipe = new ConverterRecipe(node); ELRecipeDatabase.converter_recipes[name] = recipe; yield return(null); } }
void ProcessOutputs(ConverterRecipe recipe, double blend, int ind1, int ind2) { BlendRecipes(recipe.OutputRecipes[0], blend, OutputRecipes[ind1], OutputRecipes[ind2]); }