public Map GenerateVillage(UInt16 width, UInt16 height) { // We need a reasonable amount of space to construct the map if ((width < 20) || (height < 20)) { return(null); } // Initializes map (currently to an all-grass space); Map canvas = new Map(width, height, (Int32)_randomator.NSidedDice(1000, 1)); // Initializes a double array where we keep track of which areas of the map are complete //BitArray[,] painted = new BitArray[width, height]; BitArray[] painted = new BitArray[width]; for (int i = 0; i < width; ++i) { painted[i] = new BitArray(height); } // Put roads through the middle of the map; later we'll improve the algo UInt16 halfwidth = (UInt16)(width * 0.5); FillRectangleWithTiles(canvas, new Coords(CoordsType.Tile, halfwidth, 0), new Coords(CoordsType.Tile, halfwidth, height - 1), Constants.TileGeneratorRoadPaved); for (int i = 0; i < height; ++i) { painted[halfwidth][i] = true; } UInt16 halfheight = (UInt16)(height * 0.5); FillRectangleWithTiles(canvas, new Coords(CoordsType.Tile, 0, halfheight), new Coords(CoordsType.Tile, width - 1, halfheight), Constants.TileGeneratorRoadPaved); for (int i = 0; i < width; ++i) { painted[i][halfheight] = true; } // Put a house or two GenerateRectangularRoom(canvas, new Coords(CoordsType.Tile, halfwidth + 1, 10), new Coords(CoordsType.Tile, halfwidth + 5, 15)); FurnishRectangularLivingRoom(canvas, new Coords(CoordsType.Tile, halfwidth + 1, 10), new Coords(CoordsType.Tile, halfwidth + 5, 15)); GenerateRectangularRoom(canvas, new Coords(CoordsType.Tile, 6, halfheight - 5), new Coords(CoordsType.Tile, 12, halfheight - 1)); FurnishRectangularWorkshop(canvas, new Coords(CoordsType.Tile, 6, halfheight - 5), new Coords(CoordsType.Tile, 12, halfheight - 1)); // put a well somewhere canvas.CreateItem(new Coords(CoordsType.Tile, 20, 20), Constants.ItemGeneratorWell); // Apple tree! canvas.CreateItem(new Coords(CoordsType.Tile, 30, 5), Constants.ItemGeneratorTreeApple); canvas.AnalyzeTileAccessibility(); return(canvas); }
public Map GenerateVillage(UInt16 width, UInt16 height) { // We need a reasonable amount of space to construct the map if ((width < 20) || (height < 20)) { return null; } // Initializes map (currently to an all-grass space); Map canvas = new Map(width, height, (Int32)_randomator.NSidedDice(1000, 1)); // Initializes a double array where we keep track of which areas of the map are complete //BitArray[,] painted = new BitArray[width, height]; BitArray[] painted = new BitArray[width]; for (int i = 0; i < width; ++i) { painted[i] = new BitArray(height); } // Put roads through the middle of the map; later we'll improve the algo UInt16 halfwidth = (UInt16)(width * 0.5); FillRectangleWithTiles(canvas, new Coords(CoordsType.Tile, halfwidth, 0), new Coords(CoordsType.Tile, halfwidth, height - 1), Constants.TileGeneratorRoadPaved); for (int i = 0; i < height; ++i) { painted[halfwidth][i] = true; } UInt16 halfheight = (UInt16)(height * 0.5); FillRectangleWithTiles(canvas, new Coords(CoordsType.Tile, 0, halfheight), new Coords(CoordsType.Tile, width - 1, halfheight), Constants.TileGeneratorRoadPaved); for (int i = 0; i < width; ++i) { painted[i][halfheight] = true; } // Put a house or two GenerateRectangularRoom(canvas, new Coords(CoordsType.Tile, halfwidth + 1, 10), new Coords(CoordsType.Tile, halfwidth + 5, 15)); FurnishRectangularLivingRoom(canvas, new Coords(CoordsType.Tile, halfwidth + 1, 10), new Coords(CoordsType.Tile, halfwidth + 5, 15)); GenerateRectangularRoom(canvas, new Coords(CoordsType.Tile, 6, halfheight - 5), new Coords(CoordsType.Tile, 12, halfheight - 1)); FurnishRectangularWorkshop(canvas, new Coords(CoordsType.Tile, 6, halfheight - 5), new Coords(CoordsType.Tile, 12, halfheight - 1)); // put a well somewhere canvas.CreateItem(new Coords(CoordsType.Tile, 20, 20), Constants.ItemGeneratorWell); // Apple tree! canvas.CreateItem(new Coords(CoordsType.Tile, 30, 5), Constants.ItemGeneratorTreeApple); canvas.AnalyzeTileAccessibility(); return canvas; }
// Furnishes a rectangular room with appropriate furniture private void FurnishRectangularWorkshop(Map homeMap, Coords topLeft, Coords bottomRight) { // put a bed in the middle of it Coords toolTableLocation = new Coords(CoordsType.Tile, (Int32)((bottomRight.X + topLeft.X) * 0.5), (Int32)((bottomRight.Y + topLeft.Y) * 0.5)); homeMap.CreateItem(toolTableLocation, Constants.ItemGeneratorToolTable); }
// Furnishes a rectangular room with appropriate furniture private void FurnishRectangularLivingRoom(Map homeMap, Coords topLeft, Coords bottomRight) { // put a bed in the middle of it Coords bedLocation = new Coords(CoordsType.Tile, (Int32)((bottomRight.X + topLeft.X) * 0.5), (Int32)((bottomRight.Y + topLeft.Y) * 0.5)); homeMap.CreateItem(bedLocation, Constants.ItemGeneratorBed); }