Пример #1
0
		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);
        }