private int ChooseColumnIndForRowInGrid(ZoneGrid zoneGrid, int rowInd) { var freeColumns = zoneGrid.ZonePoints[rowInd].FindAll(column => column.IsFree); var randomColumn = freeColumns[Random.Range(0, freeColumns.Count - 1)]; return(zoneGrid.ZonePoints[rowInd].IndexOf(randomColumn)); }
public static void GetTileSets(WDT wdt) { if (!wdt.IsWMOOnly) { var tileSet = new ZoneTileSet(); Tiles[(int)wdt.MapId] = tileSet; ZoneGrid grid; // Rows are along the x-axis for (var x = 0; x < 64; x++) { // Columns are along the y-axis for (var y = 0; y < 64; y++) { if (!wdt.TileProfile[y, x]) { continue; } ++count; var adt = ADTReader.ReadADT(wdt, x, y); if (adt == null) { continue; } tileSet.ZoneGrids[y, x] = grid = new ZoneGrid(new uint[TerrainConstants.ChunksPerTileSide, TerrainConstants.ChunksPerTileSide]); // Rows along the x-axis for (var chunkX = 0; chunkX < 16; chunkX++) { // Columns along the y-axis for (var chunkY = 0; chunkY < 16; chunkY++) { var areaId = adt.GetADTChunk(chunkY, chunkX).Header.AreaId; if (Enum.IsDefined(typeof(ZoneId), areaId)) { grid.ZoneIds[chunkY, chunkX] = (uint)areaId; } else { grid.ZoneIds[chunkY, chunkX] = 0; } } } //return tiles; } } } else { log.Info("Could not read Zones from WMO: " + wdt.MapId); } }
public static void GetTileSets(WDTFile wdt) { if ((wdt.Header.Header1 & WDTFlags.GlobalWMO) == 0) { var tileSet = new ZoneTileSet(); Tiles[wdt.Entry.Id] = tileSet; ZoneGrid grid; // Read in the Tiles for (var y = 0; y < 64; y++) { for (var x = 0; x < 64; x++) { if (!wdt.TileProfile[x, y]) continue; ++count; var adtName = TerrainConstants.GetADTFile(wdt.Name, x, y); var adt = ADTParser.Process(WDTParser.MpqManager, wdt.Path, adtName); if (adt == null) continue; tileSet.ZoneGrids[x, y] = grid = new ZoneGrid(new uint[TerrainConstants.ChunksPerTileSide, TerrainConstants.ChunksPerTileSide]); // Read in the TileChunks for (var j = 0; j < 16; j++) { for (var i = 0; i < 16; i++) { var areaId = adt.MapChunks[i, j].AreaId; if (Enum.IsDefined(typeof(ZoneId), areaId)) { grid.ZoneIds[i, j] = areaId; } else { grid.ZoneIds[i, j] = 0; } } } //return tiles; } } } else { log.Info("Could not read Zones from WMO: " + (MapId)wdt.Entry.Id); } }
private void GenerateCoins(ZoneGrid zoneGrid) { // Choose direction var direction = Random.Range(-1, 1); for (var rowInd = 0; rowInd < zoneGrid.ZonePoints.Count; rowInd++) { // Skip if random says it if (Random.value > _coinGenerateOnRowProbability) { continue; } // Choose column index for position var columnInd = ChooseColumnIndForRowInGrid(zoneGrid, rowInd); // Generate sequence rowInd = GenerateCoinSequence(zoneGrid, rowInd, columnInd, direction); } }
private int GenerateCoinSequence(ZoneGrid zoneGrid, int startRow, int startColumn, int direction) { // Get random coins count var coinsCount = Random.Range(_minCoinCount, _maxCoinCount); // Generate coin sequence int currentRow = startRow, currentColumn = startColumn; for (; currentRow < coinsCount + startRow && currentRow < zoneGrid.ZonePoints.Count && // Check if has row currentColumn >= 0 && currentColumn < zoneGrid.ColumnCount; // Check if has column currentRow++, currentColumn += direction) // Move to next point by direction { var currentZonePoint = zoneGrid.ZonePoints[currentRow][currentColumn]; if (currentZonePoint.IsFree) { GenerateCoin(currentZonePoint); } } return(currentRow - 1); }
private void InitGrid(Sprite background) { _zoneGrid = new ZoneGrid(background, gameObject.transform.position, _rows, _columns); }
public void GenerateOnGrid(ZoneGrid zoneGrid) { GenerateCoins(zoneGrid); }