private static void trimCorner(Map.Orientation corner, Tile[] replacement, int landX, int landY) { int replacementCount = replacement.Length; int xStart = (corner == Map.Orientation.BottomLeft || corner == Map.Orientation.TopLeft) ? 0 : Land.LAND_WIDTH / 2; int xMax = (corner == Map.Orientation.BottomLeft || corner == Map.Orientation.TopLeft) ? Land.LAND_WIDTH / 2 : Land.LAND_WIDTH; int yStart = (corner == Map.Orientation.BottomLeft || corner == Map.Orientation.BottomRight) ? 0 : Land.LAND_HEIGHT / 2; int yMax = (corner == Map.Orientation.BottomLeft || corner == Map.Orientation.BottomRight) ? Land.LAND_HEIGHT / 2 : Land.LAND_HEIGHT; for (int x = xStart; x < xMax; x++) { for (int y = yStart; y < yMax; y++) { if (!isTileToChange(corner, x, y)) { continue; } int index = _random.Next(0, replacementCount - 1); _game.SetMapLandTile(landX, landY, x, y, replacement[index].Type, replacement[index].Icon); } } }
private static bool isTileToChange(Map.Orientation corner, int x, int y) { bool isOnSide = false; bool isInSide = false; if (corner == Map.Orientation.BottomLeft) { isOnSide = (x == 0 && y < 6) || (y == 0 && x < 6); isInSide = (x < 2 && y < 3) || (x < 3 && y < 2); } if (corner == Map.Orientation.BottomRight) { isOnSide = (x == Land.LAND_WIDTH - 1 && y < 6) || (y == 0 && Land.LAND_WIDTH - x - 1 < 6); isInSide = (Land.LAND_WIDTH - 1 - x < 2 && y < 3) || (Land.LAND_WIDTH - 1 - x < 3 && y < 2); } if (corner == Map.Orientation.TopLeft) { isOnSide = (x == 0 && Land.LAND_HEIGHT - y - 1 < 6) || (y == Land.LAND_HEIGHT - 1 && x < 6); isInSide = (x < 2 && Land.LAND_HEIGHT - y - 1 < 3) || (x < 3 && Land.LAND_HEIGHT - y - 1 < 2); } if (corner == Map.Orientation.TopRight) { isOnSide = (x == Land.LAND_WIDTH - 1 && Land.LAND_HEIGHT - y - 1 < 6) || (y == Land.LAND_HEIGHT - 1 && Land.LAND_WIDTH - x - 1 < 6); isInSide = (Land.LAND_WIDTH - x - 1 < 2 && Land.LAND_HEIGHT - y - 1 < 3) || (Land.LAND_WIDTH - x - 1 < 3 && Land.LAND_HEIGHT - y - 1 < 2); } return(isOnSide || isInSide); }
private Border[] getCoastBorder(int thickness, Map.Orientation orientation, bool isCoastEnd) { switch (orientation) { case Map.Orientation.Top: return(getTopBorders(isCoastEnd, thickness)); case Map.Orientation.Bottom: return(getBottomBorders(isCoastEnd, thickness)); case Map.Orientation.Left: return(getLeftBorders(isCoastEnd, thickness)); case Map.Orientation.Right: return(getRightBorders(isCoastEnd, thickness)); case Map.Orientation.TopLeft: return(getBorders(thickness, Map.Orientation.Top, Map.Orientation.Left)); case Map.Orientation.TopRight: return(getBorders(thickness, Map.Orientation.Top, Map.Orientation.Right)); case Map.Orientation.BottomLeft: return(getBorders(thickness, Map.Orientation.Bottom, Map.Orientation.Left)); case Map.Orientation.BottomRight: return(getBorders(thickness, Map.Orientation.Bottom, Map.Orientation.Right)); default: return(getBorders(thickness, Map.Orientation.Default)); } }
protected sealed override void Generate(Random random) { Border[] mountainZones = generateMountainLayers(random); for (int x = 0; x < LAND_WIDTH; x++) { for (int y = 0; y < LAND_HEIGHT; y++) { Tile.TileType type = Tile.TileType.DEFAULT; if (mountainZones.Any(border => border.IsPositionOnBorder(x, y))) { type = Tile.TileType.MOUNTAIN_FACE; } else if (mountainZones.Any(border => border.IsPositionWithinBorder(x, y))) { type = Tile.TileType.MOUNTAIN_TOP; } else if (random.Next(0, 100) < 40) { type = Tile.TileType.ROCK; } SetLandPiece(x, y, Tile.TileType.GRASS, type); } } foreach (Border layer in mountainZones) { for (int x = (int)layer.Left; x <= layer.Right; x++) { for (int y = (int)layer.Bottom; y <= layer.Top; y++) { Map.Orientation orientation = getMountainFaceOrientation(x, y, layer); Tile.TileType type = map.IsOrientationCorner(orientation) ? Tile.TileType.MOUNTAIN_CORNER : land[x, y].Icon; land[x, y].Icon = type; land[x, y].Orientation = type == Tile.TileType.MOUNTAIN_TOP ? Map.Orientation.Default : orientation; } } } }
/// <summary> /// Gives a vector for an orientation value. /// </summary> /// <param name="orientation">The orientation value. </param> /// <returns>A vector for the orientation value. </returns> public static Vector3 OrientationToVector(Map.Orientation orientation) { switch (orientation) { case Map.Orientation.Bottom: case Map.Orientation.BottomLeft: return(new Vector3(0, 0, 90)); case Map.Orientation.Right: case Map.Orientation.BottomRight: return(new Vector3(0, 0, 180)); case Map.Orientation.Top: case Map.Orientation.TopRight: return(new Vector3(0, 0, -90)); default: return(new Vector3(0, 0, 0)); } }
private Border getBorder(int thickness, Map.Orientation orientation) { switch (orientation) { case Map.Orientation.Bottom: return(new Border(thickness, 0, 0, LAND_WIDTH - 1)); case Map.Orientation.Top: return(new Border(LAND_HEIGHT - 1, LAND_HEIGHT - thickness - 1, 0, LAND_WIDTH - 1)); case Map.Orientation.Left: return(new Border(LAND_HEIGHT - 1, 0, 0, thickness)); case Map.Orientation.Right: return(new Border(LAND_HEIGHT - 1, 0, LAND_WIDTH - thickness - 1, LAND_WIDTH - 1)); default: return(null); } }