private static void GenerateRandomTile(int GridSize, MapTile[,] map, MapTile.MapTileType TileType) { Random rng = new Random(); int i = (int)(GridSize * rng.NextDouble()); int j = (int)(GridSize * rng.NextDouble()); while ((map[i, j].Type != MapTile.MapTileType.Empty) && (map[i, j].Type != MapTile.MapTileType.Regular)) { i = (int)(GridSize * rng.NextDouble()); j = (int)(GridSize * rng.NextDouble()); } GenerateTile(GridSize, map, TileType, i, j); }
private static void GenerateTile(int GridSize, MapTile[,] map, MapTile.MapTileType TileType, int i, int j) { map[i, j] = new MapTile { Type = TileType, Exits = generateExits(map, i, j, GridSize) }; }
/// <summary> /// Determines whether this building position is allowed at the specified x, y and direction. The rules set for this building /// (eg can it be placed on a slope) are applied. /// </summary> /// <returns><c>true</c> if this building position is allowed otherwise, <c>false</c>.</returns> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="direction">Direction.</param> /// <param name="building">Building.</param> public bool IsBuildingPositionAllowed(int x, int y, int direction, SimpleBuildingType building) { int stopX = x + building.buildArea.width - 1; int stopY = y + building.buildArea.length - 1; if (x <= 0 || y <= 0 || stopX >= world.tileMapSize - 1 || stopY >= world.tileMapSize - 1) { return(false); } //If we turned the building -90 or 90 degrees then switch width and length bool isTurned = direction % 2 == 1; if (isTurned) { stopX = x + building.buildArea.length - 1; stopY = y + building.buildArea.width - 1; } for (int xT = x; xT <= stopX; xT++) { for (int yT = y; yT <= stopY; yT++) { MapTile tile = new MapTile(xT, yT); if (DoTileHaveBuilding(xT, yT)) { return(false); } //Compare this tile type to the correct corresponding one on building //First find local coordinates for building tiles int xLoc; int yLoc; switch (direction) { case 0: xLoc = xT - x; yLoc = yT - y; break; case 1: xLoc = yT - y; yLoc = xT - x; break; case 2: xLoc = building.buildArea.width - (xT - x) - 1; yLoc = building.buildArea.length - (yT - y) - 1; break; case 3: xLoc = building.buildArea.width - (yT - y) - 1; yLoc = building.buildArea.length - (xT - x) - 1; break; default: xLoc = -1; yLoc = -1; break; } //now that we have the local coordinates of the specified tile we can compare it to the building allowed tile for said coordinate //Get the tile type MapTile.MapTileType worldTileType = world.GetTileType(tile); //Get the tile type MapTile.MapTileType buildingTileType = building.buildArea.GetTileType(xLoc, yLoc); //Check if this tile is ok if (MapTile.IsTileOk(buildingTileType, worldTileType)) { continue; } else { return(false); } } } if (!world.IsAreaEmpty(x, y, stopX, stopY) && this.IsAreaEmpty(x, y, stopX, stopY)) { Debug.Log("Area not empty"); return(false); } /* Redundant now? * if(!world.IsAreaAboveWater(x, y, stopX, stopY)){ * Debug.Log("Area not above water"); * return false; * }*/ return(true); }
public void IsBuildingPositionAllowed(int x, int y, int direction, SimpleBuildingType building, out bool[,] tilesResults) { int stopX = x + building.buildArea.width - 1; int stopY = y + building.buildArea.length - 1; //If we turned the building -90 or 90 degrees then switch width and length bool isTurned = direction % 2 == 1; if (isTurned) { stopX = x + building.buildArea.length - 1; stopY = y + building.buildArea.width - 1; tilesResults = new bool[building.buildArea.length, building.buildArea.width]; } else { tilesResults = new bool[building.buildArea.width, building.buildArea.length]; } if (x <= 0 || y <= 0 || stopX >= world.tileMapSize - 1 || stopY >= world.tileMapSize - 1) { return; } for (int xT = x; xT <= stopX; xT++) { for (int yT = y; yT <= stopY; yT++) { MapTile tile = new MapTile(xT, yT); if (DoTileHaveBuilding(xT, yT)) { continue; } //Compare this tile type to the correct corresponding one on building //First find local coordinates for building tiles int xLoc; int yLoc; switch (direction) { case 0: xLoc = xT - x; yLoc = yT - y; break; case 1: xLoc = yT - y; yLoc = xT - x; break; case 2: xLoc = building.buildArea.width - (xT - x) - 1; yLoc = building.buildArea.length - (yT - y) - 1; break; case 3: xLoc = building.buildArea.width - (yT - y) - 1; yLoc = building.buildArea.length - (xT - x) - 1; break; default: xLoc = -1; yLoc = -1; break; } //now that we have the local coordinates of the specified tile we can compare it to the building allowed tile for said coordinate //Get the tile type MapTile.MapTileType worldTileType = world.GetTileType(tile); //Get the tile type MapTile.MapTileType buildingTileType = building.buildArea.GetTileType(xLoc, yLoc); //Check if this tile is ok if (MapTile.IsTileOk(buildingTileType, worldTileType) && world.IsTileEmpty(tile)) { tilesResults[xT - x, yT - y] = true; } else { tilesResults[xT - x, yT - y] = false; } } } }