public void AddOre(SO_Ore ore) { decalTile = ore.oreTile; score = ore.oreScore; isOccuped = true; }
public IEnumerator AddOre(MapTile[,] map) { isGenerating = true; int width = map.GetLength(0); int height = map.GetLength(1); BoundsInt bounds = new BoundsInt(-1, -1, 0, 3, 3, 1); int nbChunk = map.GetLength(0) / rule_chunkSize; for (int i = 0; i < nbChunk; i++) { for (int j = 0; j < nbChunk; j++) { #region Get solid tiles in chunk List <MapTile> solidTiles = new List <MapTile>(); for (int x = 0; x < rule_chunkSize; x++) { for (int y = 0; y < rule_chunkSize; y++) { Vector2Int pos = new Vector2Int(x + i * rule_chunkSize, y + j * rule_chunkSize); if (pos.x >= 0 && pos.x < width && pos.y >= 0 && pos.y < height) { MapTile t = map[pos.x, pos.y]; if (t.type == MapTile.TileType.SOLID) { solidTiles.Add(t); } } } } #endregion #region Create vein int nbVein = Random.Range(1, rule_veinPerChunk); while (nbVein > 0 && solidTiles.Count > 0) { MapTile currentTile = solidTiles[Random.Range(0, solidTiles.Count)]; solidTiles.Remove(currentTile); if (!currentTile.isOccuped) { SO_Ore selectedOre = GetRandomOre(); int veinSize = Random.Range(0, rule_maxOrePerVein + 1); List <MapTile> possibleTile = new List <MapTile>(); possibleTile.Add(currentTile); while (possibleTile.Count > 0 && veinSize > 0) { MapTile t = possibleTile[Random.Range(0, possibleTile.Count)]; foreach (Vector3Int b in bounds.allPositionsWithin) { if (t.position.x + b.x >= 0 && t.position.x + b.x < width && t.position.y + b.y >= 0 && t.position.y + b.y < height) { if (solidTiles.Contains(map[t.position.x + b.x, t.position.y + b.y])) { if (!map[t.position.x + b.x, t.position.y + b.y].isOccuped) { possibleTile.Add(map[t.position.x + b.x, t.position.y + b.y]); } } } } possibleTile.Remove(t); t.AddOre(selectedOre); veinSize--; } nbVein--; } } #endregion } } isGenerating = false; yield return(null); }