Ejemplo n.º 1
0
        public bool IsAPrimaryMaterial(string materialName, string atomicMaterialName)
        {
            NanoFactoryRecipe materialRecipe = this.FindRecipe(materialName);

            return(materialName != "ORE" && materialRecipe.inputs.Count == 1 &&
                   materialRecipe.inputs[0].name == atomicMaterialName);
        }
Ejemplo n.º 2
0
        public long ProduceMaterial(string materialName, long amount, Dictionary <string, long> materialBag)
        {
            // Find the recipe.
            NanoFactoryRecipe recipeMaterial = this.FindRecipe(materialName);

            // Is this already in the leftover ingredients?
            NanoFactoryIngredient ingredientOnHand = this.CheckToSeeIfIHaveItAlready(materialName, amount, materialBag);
            long amountLeftToProduce = (amount - ingredientOnHand.amount);

            if (amountLeftToProduce == 0)
            {
                return(0);  // Cost zero ORE!
            }

            // If this ingredient is primary, go ahead and make it with ORE.
            if (IsAPrimaryMaterial(materialName, "ORE"))
            {
                long oreCost = 0;
                long amountOfPrimaryProduced = 0;
                while (amountLeftToProduce > amountOfPrimaryProduced)
                {
                    //Program.Assert(recipeMaterial.inputs[0].name == "ORE", "ERROR!");
                    // Program.Assert(recipeMaterial.inputs.Count == 1, "ERROR!");
                    oreCost += recipeMaterial.inputs[0].amount;
                    amountOfPrimaryProduced += recipeMaterial.output.amount;
                }

                this.AddToCollection(materialName, amountOfPrimaryProduced, materialBag);
                return(oreCost);
            }

            // If we have made it here, we need to produce a non-primary material.
            long totalOreCost            = 0;
            int  howManyTimesDoRunRecipe = (int)Math.Ceiling((((double)amountLeftToProduce) / (double)recipeMaterial.output.amount));

            foreach (NanoFactoryIngredient inputIngredient in recipeMaterial.inputs)
            {
                long amountPerRun = inputIngredient.amount;
                long amountNeeded = howManyTimesDoRunRecipe * amountPerRun;
                totalOreCost += this.ProduceMaterial(inputIngredient.name, amountNeeded, materialBag);

                this.RemoveFromCollection(inputIngredient.name, amountNeeded, materialBag);
            }

            // What did we make?
            long amountProduced = (howManyTimesDoRunRecipe * recipeMaterial.output.amount);

            this.AddToCollection(recipeMaterial.output.name, amountProduced, materialBag);

            //Console.WriteLine("Produced " + amountProduced + " " + materialName);

            return(totalOreCost);
        }