/// <summary> /// Sets this cell's neighbor in the given direction to the given tile. /// Also reciprocates and sets the opposite neighbor of the given tile /// to this tile. /// </summary> /// <param name="direction">The direction `tile` is in.</param> /// <param name="tile">The new neighbor! Howdy!</param> public void SetNeighbor(TileEdge direction, Tile tile) { neighbors[( int )direction] = tile; // avoid NRE if (tile == null) { return; } tile.neighbors[( int )direction.Opposite()] = this; // update it for that tile as well }
/// <summary> /// Creates a mountain range starting at the given type and spreading out the /// given range. /// </summary> /// <param name="tile"></param> /// <param name="range"></param> /// <returns></returns> private static int CreateMountainRangeAt(Tile tile, int range, TileEdge direction) { // if the tile doesn't exist, isn't land, or already is a mountain, end the chain if (tile == null || !tile.type.isLand || tile.type == TileType.MOUNTAIN) { return(0); } // set the type to mountains tile.type = TileType.MOUNTAIN; int sum = 1; if (range >= random.Next(0, 5)) { // expand in the given direction CreateMountainRangeAt(tile.GetNeighbor(direction), range - random.Next(0, 5), direction); // expand backwards too CreateMountainRangeAt(tile.GetNeighbor(direction.Opposite()), range - random.Next(0, 5), direction); // create mountains in the given directions for (int i = 0; i < 6; i++) { // expand mostly in the given direction and the opposite direction if (i == ( int )direction || i == ( int )direction.Opposite()) { CreateMountainRangeAt(tile.GetNeighbor(( TileEdge )i), range - random.Next(0, 5), direction); } // 70% chance that it will branch off in another direction, but will suffer massive hits to the range else if (random.Next(1, 10) <= 7) { CreateMountainRangeAt(tile.GetNeighbor(( TileEdge )i), range - random.Next(5, 15), direction); } } } return(sum); }