public void WillTestBuildingCapacityWithLargeNumbers() { var r = new Random(); var totalNetValue = new NetValue { Cash = r.Next(1, int.MaxValue), Energy = r.Next(1, int.MaxValue), Food = r.Next(1, int.MaxValue), Iron = r.Next(1, int.MaxValue), Mana = r.Next(1, int.MaxValue) }; var buildCosts = new BuildCosts <object> { Cash = 1 * r.NextDouble(), Energy = 1 * r.NextDouble(), Food = 1 * r.NextDouble(), Iron = 1 * r.NextDouble(), Mana = 1 * r.NextDouble() }; var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, r.Next(250)); Assert.GreaterOrEqual(netValue.EntityCount, 1); }
/// <summary> /// Used to schedule buildings to be built. /// </summary> /// <param name="player"> /// The player who is building. /// </param> /// <param name="planet"> /// The planet to build on. /// </param> /// <param name="buildingCosts"> /// The building costs for a particular building type. /// </param> /// <param name="costs"> /// The costs of building. /// </param> /// <param name="type"> /// The type of building to build. /// </param> /// <returns> /// True if the build was added to the queue. /// </returns> public bool BuildBuildings(Player player, Planet planet, BuildCosts <BuildingType> buildingCosts, NetValue costs, BuildingType type) { if (this.scheduler == null) { Trace.WriteLine("this.scheduler is null", "SpaceScheduler.SubtractBuildCosts"); return(false); } if (buildingCosts == null) { Trace.WriteLine("buildCosts is null", "SpaceScheduler.SubtractBuildCosts"); return(false); } // Needs to subtract the cost here. return false if the player tries to build too many buildings. var totalCosts = buildingCosts.CalculateBuildCosts(costs, planet.TotalBuildings, planet.BuildingCapacity); player.TotalNetValue.Subtract(totalCosts); var jobSetup = new JobSetup <BuildBuildingsJob>(this.scheduler); jobSetup.Set(bbj => bbj.PlanetID, planet.ID); jobSetup.Set(bbj => bbj.BuildingType, type); jobSetup.Set(bbj => bbj.BuildingCount, totalCosts.EntityCount); jobSetup.Run(DateTimeOffset.UtcNow.AddMilliseconds(buildingCosts.Time)); return(true); }
public void WillReturnZeroBuildItems() { var totalNetValue = new NetValue(); var buildCosts = new BuildCosts <object>(); var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 1); Assert.AreEqual(netValue.EntityCount, 0); }
/// <summary> /// Calculates the maximum number of buildings a player can build on a particular planet. /// </summary> /// <typeparam name="TType"> /// The type of build cost. /// </typeparam> /// <param name="buildingCost"> /// The building Cost. /// </param> /// <param name="totalNetValue"> /// The total Net Value. /// </param> /// <param name="planetTotalBuildings"> /// The total number of buildings on the planet. This is at the time of the start of the build. /// </param> /// <param name="planetBuildCapacity"> /// The number of buildings the planet can natively hold. /// </param> /// <returns> /// The maximum buildings and the cost. /// </returns> public static NetValue CalculateBuildCosts <TType>(this BuildCosts <TType> buildingCost, NetValue totalNetValue, int planetTotalBuildings, int planetBuildCapacity) { int output = planetTotalBuildings; int maximumTobuild = totalNetValue.EntityCount == 0 ? int.MaxValue : totalNetValue.EntityCount + output; // TODO -- include empire size in calculations var calculationArray = new[] { totalNetValue.Cash, buildingCost.Cash, totalNetValue.Energy, buildingCost.Energy, totalNetValue.Food, buildingCost.Food, totalNetValue.Iron, buildingCost.Iron, totalNetValue.Mana, buildingCost.Mana }; var maxFound = false; var totals = new double[calculationArray.Length / 2]; // Make sure that we actually gave the item building costs or this could be inifinity if (buildingCost.Cash > 0 || buildingCost.Energy > 0 || buildingCost.Food > 0 || buildingCost.Iron > 0 || buildingCost.Mana > 0) { do { output++; // This will tell us to kick out of the loop if the totals never get incremented. for (var i = 0; i < calculationArray.Length; i += 2) { // Find the total cost for the resource taking into account the planet building max. var costForItem = calculationArray[i + 1] * Math.Max(1, (output / planetBuildCapacity)); // Make sure that one of the resource values hasn't gone past the maximum cash value. if (totals[i / 2] + costForItem <= calculationArray[i]) { totals[i / 2] += costForItem; continue; } maxFound = true; break; } }while (!maxFound && output <= maximumTobuild); } return(new NetValue { // Always return 0 or greater - subtract 1 for the do-while EntityCount = Math.Max(0, output - planetTotalBuildings - 1), Cash = totals[0], Energy = totals[1], Food = totals[2], Iron = totals[3], Mana = totals[4] }); }
public void WillReturnOneBuildItem() { var totalNetValue = new NetValue { Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1 }; var buildCosts = new BuildCosts <object> { Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1 }; var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 1); Assert.AreEqual(netValue.EntityCount, 1); }
public void WillTestUser() { var totalNetValue = new NetValue { EntityCount = 2, Cash = 3, Energy = 3, Food = 3, Iron = 3, Mana = 3 }; var buildCosts = new BuildCosts <object> { Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1 }; var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 100); Assert.AreEqual(netValue.EntityCount, 2); }
public void WillTestBuildingCapacityMinimum() { var totalNetValue = new NetValue { Cash = 2, Energy = 2, Food = 2, Iron = 2, Mana = 2 }; var buildCosts = new BuildCosts <object> { Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1 }; var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 1); Assert.AreEqual(netValue.EntityCount, 1); }
public void WillTestBuildingCapacityMaximum() { var totalNetValue = new NetValue { Cash = 3, Energy = 3, Food = 3, Iron = 3, Mana = 3 }; var buildCosts = new BuildCosts <object> { Cash = 1, Energy = 1, Food = 1, Iron = 1, Mana = 1 }; var netValue = buildCosts.CalculateBuildCosts(totalNetValue, 0, 1); // 2 here because of the building capacity and overbuild cost (x2) Assert.AreEqual(netValue.EntityCount, 2); }
public override string ToString() { return($"{Name} ({string.Join(", ", BuildCosts.Select(bc => bc.ToString()))})"); }
// Start is called before the first frame update void Start() { base.Start(); BuildCosts.Add("Wood", 50); ProductionIntervall = 5000; }
// Start is called before the first frame update void Start() { BuildCosts.Add("Wood", 20); }