private ConstructionTree chooseRecipe(string desc, ItemType item) { Console.Clear(); Console.WriteLine(desc.ToUpper() + "\n"); var recipeIndex = 0; foreach (var recipe in (Database.getRecipes(item))) { Console.WriteLine("[" + recipeIndex + "] " + recipe.toString()); recipeIndex++; } var chosenRecipeIndex = 0; if (Database.getRecipes(item).Count > 1) { Console.WriteLine("Choose number of recipe"); chosenRecipeIndex = Convert.ToInt32(Console.ReadLine()); } Console.WriteLine("========= CHOSEN RECIPE ========= \n" + Database.getRecipes(item)[chosenRecipeIndex].toString() + "\n"); var tree = new ConstructionTree(new ConstructionNode(Database.getRecipes(item)[chosenRecipeIndex])); foreach (var ingredient in Database.getRecipes(item)[chosenRecipeIndex].input) { tree.addIngredient(chooseRecipe("Specify recipe for " + ingredient.type + " for building " + item, ingredient.type)); } return(tree); }
public ConstructionTree adjustComponentTreeToWantedProduction(ConstructionTree tree, double wantedProductionPerMinute) { //TO DO clean tree.root.wantedProductionPerMinute = wantedProductionPerMinute; double machinesCount = (double)tree.root.wantedProductionPerMinute / (double)tree.root.getBaseProductionPerMinute(); double newClockSpeedSum = machinesCount * 100.0; int newMachinesCount = (int)Math.Ceiling(machinesCount); for (var i = tree.root.buildingDevices.Count; i < newMachinesCount; i++) { tree.root.addMachine(); } tree.root.updateBuildingDevicesClockSpeedAndAlignPowerUsage(newClockSpeedSum / newMachinesCount); foreach (var ingredient in tree.ingredients) { var ingredientQuantity = tree.root.getIngredientQuantity(ingredient.root.getItemType()); var ingredientBaseProduction = wantedProductionPerMinute; var produced = tree.root.getProducedProduct(); var productionForIngredientToBeAligned = ingredientQuantity * ingredientBaseProduction / produced; adjustComponentTreeToWantedProduction(ingredient, productionForIngredientToBeAligned); } return(adjustComponentTreeToAdditionalCondition(tree)); }
public override ConstructionTree adjustComponentTreeToAdditionalCondition(ConstructionTree component) { while (!areMachineCountsEqual(component)) { adjustComponentTree(component); } return(component); }
private bool areMachineCountsEqual(ConstructionTree component) { var flag = true; foreach (var ingredient in component.ingredients) { if (component.root.buildingDevices.Count != ingredient.root.buildingDevices.Count) { flag = false; } } return(flag); }
private ConstructionTree adjustComponentTree(ConstructionTree component) { foreach (var ingredient in component.ingredients) { if (ingredient.root.buildingDevices.Count > component.root.buildingDevices.Count) { setBuildingDevicesCount(component.root, ingredient.root.buildingDevices.Count); } else { setBuildingDevicesCount(ingredient.root, component.root.buildingDevices.Count); } adjustComponentTree(ingredient); } return(component); }
public void addIngredient(ConstructionTree ingredient) { ingredients.Add(ingredient); }
public abstract ConstructionTree adjustComponentTreeToAdditionalCondition(ConstructionTree tree);