void LoadDefautStructureRecipe()
 {
     var node = LoadRecipeNode ("EL_DefaultStructureRecipe");
     if (node != null) {
         var recipe = new Recipe (node);
         if (recipe.ingredients.Count > 0) {
             ExRecipeDatabase.default_structure_recipe = recipe;
         }
     }
 }
		public PartRecipe (ConfigNode recipe)
		{
			part_recipe = new Recipe (recipe);
			if (!part_recipe.HasIngredient ("structure")) {
				part_recipe.AddIngredient (new Ingredient ("structure", 5));
			}
			if (recipe.HasNode ("Resources")) {
				structure_recipe = new Recipe (recipe.GetNode ("Resources"));
			} else {
				structure_recipe = ExRecipeDatabase.default_structure_recipe;
			}
		}
		IEnumerator LoadRecycleRecipes ()
		{
			var dbase = GameDatabase.Instance;
			var node_list = dbase.GetConfigNodes ("EL_RecycleRecipe");
			for (int i = 0; i < node_list.Length; i++) {
				var node = node_list[i];
				string name = node.GetValue ("name");

				var recipe_node = node.GetNode ("Resources");
				var recipe = new Recipe (recipe_node);
				print ("[EL RecycleRecipe] " + name);
				ExRecipeDatabase.recycle_recipes[name] = recipe;
				yield return null;
			}
		}
		public Recipe Bake (double mass)
		{
			double total = 0;
			for (int i = 0; i < ingredients.Count; i++) {
				total += ingredients[i].ratio;
			}

			Recipe bake = new Recipe ();
			for (int i = 0; i < ingredients.Count; i++) {
				var name = ingredients[i].name;
				var ratio = mass * ingredients[i].ratio / total;
				Debug.Log(String.Format("Bake: {0} {1} {2} {3}", name, ratio, ingredients[i].ratio, total));
				var ingredient = new Ingredient (name, ratio);
				bake.ingredients.Add (ingredient);
			}
			return bake;
		}
		public Recipe Bake (double mass)
		{
			var recipe = new Recipe ();
			var prec = part_recipe.Bake (mass);
			for (int i = 0; i < prec.ingredients.Count; i++) {
				var pi = prec.ingredients[i];
				Recipe rec;
				if (pi.name == "structure") {
					rec = structure_recipe;
				} else {
					rec = ExRecipeDatabase.module_recipes[pi.name];
				}
				var subr = rec.Bake (pi.ratio);
				for (int j = 0; j < subr.ingredients.Count; j++) {
					var si = subr.ingredients[j];
					recipe.AddIngredient (subr.ingredients[j]);
				}
			}
			return recipe;
		}
        IEnumerator LoadModuleRecipes()
        {
            var dbase = GameDatabase.Instance;
            var node_list = dbase.GetConfigNodes ("EL_ModuleRecipe");
            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_ModuleRecipe");
                    continue;
                }

                Type mod;
                mod = AssemblyLoader.GetClassByName(typeof(PartModule), name);
                if (mod == null) {
                    print ("[EL ModuleRecipe] no such module: " + name);
                    continue;
                }
                var recipe_node = GetResources (node, "EL_ModuleRecipe");
                if (recipe_node == null) {
                    continue;
                }
                //print ("[EL ModuleRecipe] " + name);
                var recipe = new Recipe (recipe_node);
                ExRecipeDatabase.module_recipes[name] = recipe;
                yield return null;
            }
        }
        IEnumerator LoadTransferRecipes()
        {
            var dbase = GameDatabase.Instance;
            var node_list = dbase.GetConfigNodes ("EL_TransferRecipe");
            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_TransferRecipe");
                    continue;
                }

                var recipe_node = GetResources (node, "EL_TransferRecipe");
                if (recipe_node == null) {
                    continue;
                }
                var recipe = new Recipe (recipe_node);
                //print ("[EL TransferRecipe] " + name);
                ExRecipeDatabase.transfer_recipes[name] = recipe;
                yield return null;
            }
        }
		void Awake ()
		{
			part_recipes = new Dictionary<string, PartRecipe> ();
			module_recipes = new Dictionary<string, Recipe> ();
			resource_recipes = new Dictionary<string, Recipe> ();
			recycle_recipes = new Dictionary<string, Recipe> ();
			transfer_recipes = new Dictionary<string, Recipe> ();
			default_structure_recipe = new Recipe ("RocketParts = 1");

			List<LoadingSystem> list = LoadingScreen.Instance.loaders;
			if (list != null) {
				for (int i = 0; i < list.Count; i++) {
					if (list[i] is ExRecipeLoader) {
						print("[EL Recipes] found ExRecipeLoader: " + i);
						(list[i] as ExRecipeLoader).done = false;
						break;
					}
					if (list[i] is PartLoader) {
						print("[EL Recipes] found PartLoader: " + i);
						GameObject go = new GameObject();
						ExRecipeLoader scanner = go.AddComponent<ExRecipeLoader>();
						list.Insert (i, scanner);
						break;
					}
				}
			}
		}
		public PartRecipe ()
		{
			part_recipe = new Recipe ();
			part_recipe.AddIngredient (new Ingredient ("structure", 5));
			structure_recipe = ExRecipeDatabase.default_structure_recipe;
		}
		IEnumerator LoadModuleRecipes ()
		{
			var dbase = GameDatabase.Instance;
			var node_list = dbase.GetConfigNodes ("EL_ModuleRecipe");
			for (int i = 0; i < node_list.Length; i++) {
				var node = node_list[i];
				string name = node.GetValue ("name");

				Type mod;
				mod = AssemblyLoader.GetClassByName(typeof(PartModule), name);
				if (mod != null) {
					var recipe_node = node.GetNode ("Resources");
					var recipe = new Recipe (recipe_node);
					print ("[EL ModuleRecipe] " + name);
					ExRecipeDatabase.module_recipes[name] = recipe;
				} else {
					print ("[EL ModuleRecipe] no such module: " + name);
				}
				yield return null;
			}
		}