public void Initialize(TileDictionary tileDict, GameBoardGenerator boardGen, DashboardData dashboardData, float pollutionChance) { tileDictionary = tileDict; boardGenerator = boardGen; dashData = dashboardData; this.pollutionChance = pollutionChance; cityDef = tileDictionary.TileDef[TileType.City]; powerDef = tileDictionary.TileDef[TileType.PowerPlant]; }
private bool CanBuild(TileType tile) { TileDefinition tileDef = tileDictionary.TileDef[tile]; bool canBuild = dashData.goldTotal >= tileDef.goldCost && dashData.woodTotal >= tileDef.woodCost && dashData.oreTotal >= tileDef.oreCost; return(canBuild); }
public RequestStatus MineCell(int row, int col) { TileType target = opsBoard.map[row, col].TileValue; if (!(target == TileType.Mountain || target == TileType.Trees || target == TileType.City || target == TileType.PowerPlant)) { Debug.Log(string.Format("Cannot mine on a {0} cell", target)); return(RequestStatus.InvalidMiningTarget); } TileDefinition tileData = tileDictionary.TileDef[target]; if (target == TileType.Mountain || target == TileType.Trees) { dashData.oreTotal += tileData.oreYield; dashData.woodTotal += tileData.woodYield; } else { dashData.oreTotal += tileData.oreCost; dashData.woodTotal += tileData.woodCost; dashData.goldTotal += tileData.goldCost; } UpdateBuildFlags(); TileType newTile = TileType.Dirt; switch (target) { case TileType.Trees: newTile = TileType.Dirt; break; case TileType.Mountain: newTile = TileType.Depleted; break; case TileType.City: case TileType.PowerPlant: newTile = (opsBoard.map[row, col].BuiltOnDepleted) ? TileType.Depleted : TileType.Dirt; break; default: throw new System.Exception("Unexpected TileType " + target); } opsBoard.map[row, col].TileValue = newTile; gameBoard.UpdateElement(row, col, opsBoard); GameEventManager.TriggerEvent(ModelEventType.CellStateChanged, row, col); GameEventManager.TriggerEvent(ModelEventType.DashboardDataChanged, row, col); return(RequestStatus.Success); }
public RequestStatus Build(int row, int col, BuildOption buildOption) { TileType currentTile = opsBoard.map[row, col].TileValue; if (!((currentTile == TileType.Dirt) || (buildOption != BuildOption.Trees && currentTile == TileType.Depleted))) { Debug.Log("Invalid build target: " + string.Format("{0},{1}", row, col)); return(RequestStatus.InvalidBuildTarget); } bool canBuild = false; switch (buildOption) { case BuildOption.City: canBuild = dashData.canBuildCity; break; case BuildOption.PowerPlant: canBuild = dashData.canBuildPowerPlant; break; case BuildOption.Trees: canBuild = dashData.canPlantTrees; break; default: throw new System.Exception("Unexpected build option " + buildOption); } if (!canBuild) { Debug.Log("Insufficient resources to build " + buildOption); return(RequestStatus.InsufficientResources); } TileType newTile = ConvertToTileType(buildOption); TileDefinition newTileData = tileDictionary.TileDef[newTile]; dashData.oreTotal -= newTileData.oreCost; dashData.woodTotal -= newTileData.woodCost; dashData.goldTotal -= newTileData.goldCost; UpdateBuildFlags(); opsBoard.map[row, col].BuiltOnDepleted = (currentTile == TileType.Depleted); opsBoard.map[row, col].TileValue = newTile; gameBoard.UpdateElement(row, col, opsBoard); GameEventManager.TriggerEvent(ModelEventType.CellStateChanged, row, col); GameEventManager.TriggerEvent(ModelEventType.DashboardDataChanged, row, col); return(RequestStatus.Success); }