public void TestIsCompatibleTileType( IsCompatibleTileTypeTestCase testCase ) { var buildingCategoryParams = new BuildingCategoryParams( compatibleTileTypes: testCase.CompatibleTileTypes, // don't care for rest of parameters. upkeepCost: 0, buildCostMoney: 0, buildCostPlanks: 0, resourceGenerationInterval: 0, outputCount: 0, efficiencyScaleTileType: MapTileType.Grass, efficiencyScaleMinNeighbors: 0, efficiencyScaleMaxNeighbors: 0, inputResources: null, outputResource: ResourceType.Wood, isProdBuilding: true ); var isCompatible = buildingCategoryParams.IsCompatibleTileType( testCase.TileType ); Assert.That( isCompatible, Is.EqualTo(testCase.ExpectedIsCompatible) ); }
public PlaceBuildingOnTileTestCase( string description, MapTile tile, uint mapX, uint mapY, BuildingCategoryParams buildingCategoryParams, MapTile expectedMapTile = null, Vector3?expectedSpawnPos = null, int initialMoney = 0, int?expectedAvailableMoney = null ) { Description = description; Tile = tile; MapX = mapX; MapY = mapY; BuildingCategoryParams = buildingCategoryParams; ExpectedMapTile = expectedMapTile; ExpectedSpawnPos = expectedSpawnPos; InitialMoney = initialMoney; ExpectedAvailableMoney = expectedAvailableMoney; }
// Get bundled parameters. public BuildingCategoryParams GetParams() { var categoryParams = new BuildingCategoryParams( upkeepCost: UpkeepCost, buildCostMoney: BuildCostMoney, buildCostPlanks: BuildCostPlanks, compatibleTileTypes: CompatibleTileTypes, resourceGenerationInterval: ResourceGenerationInterval, outputCount: OutputCount, efficiencyScaleTileType: ( EfficiencyScalesWithNeighbors ? (MapTileType?)EfficiencyScaleTileType : null ), efficiencyScaleMinNeighbors: EfficiencyScaleMinNeighbors, efficiencyScaleMaxNeighbors: EfficiencyScaleMaxNeighbors, inputResources: InputResources, outputResource: OutputResource, isProdBuilding: isProductionBuilding ); return(categoryParams); }
// Try to place a building at a certain map tile public void PlaceBuildingOnTile( MapTile tile, uint mapX, uint mapY, BuildingCategoryParams buildingCategoryParams, BuildingSpawner spawnBuilding ) { if (tile.Building != null) { return; } if (!buildingCategoryParams.IsCompatibleTileType(tile.Type)) { return; } if (!Economy.CanAfford(buildingCategoryParams.BuildCostMoney)) { return; } var enoughPlanksAvailable = this.Warehouse.IsAvailable( type: ResourceType.Plank, amount: buildingCategoryParams.BuildCostPlanks ); if (!enoughPlanksAvailable) { return; } Economy.SpendMoney(buildingCategoryParams.BuildCostMoney); this.Warehouse.Pick( type: ResourceType.Plank, amount: buildingCategoryParams.BuildCostPlanks ); var pos = this.MapToWorldMapper.GetWorldPosition( mapX: mapX, mapY: mapY, tile: tile ); spawnBuilding(pos); AbstractBuilding abstractBuilding; if (buildingCategoryParams.isProductionBuilding) { abstractBuilding = new ProductionBuilding( upkeepCost: buildingCategoryParams.UpkeepCost, resourceGenerationInterval: ( // TODO: this assumes one tick == one second (int)buildingCategoryParams.ResourceGenerationInterval ), outputResource: buildingCategoryParams.OutputResource, outputCount: buildingCategoryParams.OutputCount, inputResources: buildingCategoryParams.InputResources, efficiency: GetBuildingEfficiency( mapX: mapX, mapY: mapY, scaleTileType: ( buildingCategoryParams.EfficiencyScaleTileType ), scaleMinNeighbors: ( buildingCategoryParams.EfficiencyScaleMinNeighbors ), scaleMaxNeighbors: ( buildingCategoryParams.EfficiencyScaleMaxNeighbors ) ), areResourcesAvailable: this.Warehouse.IsAvailable, pickResources: this.Warehouse.Pick ); abstractBuilding.ResourcesProduced += (sender, args) => { var senderBuilding = (ProductionBuilding)sender; this.Warehouse.Store( type: senderBuilding.OutputResource, amount: senderBuilding.OutputCount ); }; } else { abstractBuilding = new HousingBuilding(0); } tile.Building = abstractBuilding; }