예제 #1
0
        // Generates random pixel to go to.
        private void GoSomewhere()
        {
            Map         currentMap  = this.MyCreature.InhabitedMap;
            RandomStuff randomator  = currentMap.Randomator;
            Coords      targetPixel = new Coords(CoordsType.Pixel, (Int32)randomator.NSidedDice((UInt16)currentMap.PixelBoundX, 1) - 1,
                                                 (Int32)randomator.NSidedDice((UInt16)currentMap.PixelBoundY, 1) - 1);

            //Coords targetTile = new Coords(CoordsType.Tile, targetPixel);
            List <Creature> clipCheck = _owner.MyCollider.CreatureClippingCheck(this.MyCreature, targetPixel, false);

            if (clipCheck != null && clipCheck.Count == 0)
            {
                MyNavigator      = new Navigator(this.MyCreature, targetPixel, false);
                _thinkingCounter = (int)randomator.NSidedDice(1000, 1);
            }
        }
        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);
        }