Esempio n. 1
0
 protected override void Generate(District district, TileBuilder[,] tiles,
     int borderLeft, int borderTop,
     int borderRight, int borderBottom, Random rand)
 {
     GenHelper.BuildFloor(tiles, borderLeft, borderTop,
         district.Width - borderLeft - borderRight,
         district.Height - borderTop - borderBottom,
         0, (x, y) => rand.NextTexture("floor/concrete", 4));
 }
Esempio n. 2
0
        public override void Generate(District district, TileBuilder[,] tiles, Random rand)
        {
            Face entryFaces = Face.None;

            for (int i = 0; i < 4; ++i)
                entryFaces |= rand.NextFace();

            int fenceHeight = rand.NextDouble() < 0.8 ? 2 : 1;

            Func <int, int, Face, bool, ResourceLocator> wallFunc = (horzPos, level, face, isInterior) => {
                if ((entryFaces & face) != Face.None) {
                    if (face == Face.North || face == Face.South) {
                        if (Math.Abs(horzPos * 2 - SizeX + 1) < 3)
                            return "";
                    } else {
                        if (Math.Abs(horzPos * 2 - SizeY + 1) < 3)
                            return "";
                    }
                }

                if (level < fenceHeight - 1)
                    return "wall/brick0/0";
                return "wall/fence/0";
            };
            Func <int, int, ResourceLocator> floorFunc = (horzPos, vertPos) => {
                return rand.NextTexture("floor/grass", 4);
            };
            GenHelper.BuildFloor(tiles, X, Y, SizeX, SizeY, 0, floorFunc);

            if (Fence) {
                GenHelper.BuildWall(tiles, X, Y, Face.North, SizeX, fenceHeight, wallFunc);
                GenHelper.BuildWall(tiles, X + SizeX - 1, Y, Face.East, SizeY, fenceHeight, wallFunc);
                GenHelper.BuildWall(tiles, X, Y + SizeY - 1, Face.South, SizeX, fenceHeight, wallFunc);
                GenHelper.BuildWall(tiles, X, Y, Face.West, SizeY, fenceHeight, wallFunc);
            }
        }
Esempio n. 3
0
        public override void Generate(District district, TileBuilder[,] tiles, Random rand)
        {
            if (EntranceFaces != Face.None) {
                int rheight = rand.Next(3) + 4;

                ResourceLocator wallGroup = "wall/brick" + rand.Next(2);

                GenHelper.BuildRoof(tiles, X, Y, SizeX, SizeY, rheight, "floor/roof/0");

                Func<int,int,Face,bool,ResourceLocator> texFunc = (horzpos, level, face, isInterior) => {
                    if (level < rheight)
                        return rand.NextTexture(wallGroup, 4);

                    return wallGroup["7"];
                };

                GenHelper.BuildWall(tiles, X, Y, Face.North, SizeX, rheight + 1, texFunc);
                GenHelper.BuildWall(tiles, X, Y, Face.West, SizeY, rheight + 1, texFunc);
                GenHelper.BuildWall(tiles, X, Y + SizeY - 1, Face.South, SizeX, rheight + 1, texFunc);
                GenHelper.BuildWall(tiles, X + SizeX - 1, Y, Face.East, SizeY, rheight + 1, texFunc);
                
                var entrFace = rand.NextFace(EntranceFaces);
                var doorway = new GarageDoor {
                    Direction = entrFace,
                    LeftBorderTile = wallGroup["8"],
                    RightBorderTile = wallGroup["9"],
                    BothBorderTile = wallGroup["a"],
                    Width = rand.Next(2, 4),
                    Height = 3,
                    DoorTile = "wall/garage/0"
                };

                switch (entrFace) {
                    case Face.North:
                        doorway.X = X + 1;
                        doorway.Y = Y;
                        break;
                    case Face.South:
                        doorway.X = X + 1;
                        doorway.Y = Y + SizeY - 1;
                        break;
                    case Face.East:
                        doorway.X = X + SizeX - 1;
                        doorway.Y = Y + 1;
                        break;
                    case Face.West:
                        doorway.X = X;
                        doorway.Y = Y + 1;
                        break;
                }

                var dx = 1 - Math.Abs(entrFace.GetNormalX());
                var dy = 1 - dx;

                int count = 1;
                if (dx == 1) {
                    count = (SizeX - 1) / (doorway.Width + 1);
                } else {
                    count = (SizeY - 1) / (doorway.Width + 1);
                }

                int closed = rand.Next(0, count);
                var indices = Enumerable.Range(0, count).ToList();

                while (closed-- > 0) indices.RemoveAt(rand.Next(indices.Count));

                for (int i = 0; i < count; ++i) {
                    if (indices.Contains(i)) {
                        doorway.DoorPosition = 2;
                    } else {
                        doorway.DoorPosition = 0;
                    }

                    doorway.Generate(district, tiles, rand);
                    doorway.GenerateOpposite(district, tiles, rand);
                    doorway.X += dx * (doorway.Width + 1);
                    doorway.Y += dy * (doorway.Width + 1);
                }

                new Rooms.Warehouse {
                    X = X, Y = Y, SizeX = SizeX, SizeY = SizeY, Height = rheight
                }.Generate(district, tiles, rand);
            }
        }
Esempio n. 4
0
        public Block Generate(District district, int borderLeft, int borderTop,
            int borderRight, int borderBottom, Random rand)
        {
            int width = district.Width;
            int height = district.Height;

            TileBuilder[,] tiles = new TileBuilder[width, height];

            for (int tx = 0; tx < width; ++tx) for (int ty = 0; ty < height; ++ty)
                    tiles[tx, ty] = new TileBuilder();

            int innerLeft = borderLeft;
            int innerTop = borderTop;
            int innerRight = width - borderRight;
            int innerBottom = height - borderBottom;
            int innerWidth = width - borderLeft - borderRight;
            int innerHeight = height - borderTop - borderBottom;

            Func<int, int, ResourceLocator> roadFunc = delegate(int tx, int ty) {
                return rand.NextTexture("floor/road/", 0, 4);
            };

            GenHelper.BuildFloor(tiles, 0, 0, width, height, 0, roadFunc);
            GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, innerWidth + 2, innerHeight + 2, 0,
                (x, y) => {
                    if (Tools.Random.NextDouble() < 0.75) {
                        return "floor/concrete/0";
                    } else {
                        return Tools.Random.NextTexture("floor/concrete", 1, 4);
                    }
                });

            int texOffset = 0; bool horz = false;
            Func<int, int, ResourceLocator> pavementFunc = delegate(int tx, int ty) {
                if ((horz && tx % 8 == 4) || (!horz && ty % 8 == 4))
                    return "floor/pavement/" + (texOffset + 2).ToString("X").ToLower();

                return rand.NextTexture("floor/pavement/", texOffset, texOffset + 2);
            };

            if (borderBottom > 1) {
                texOffset = 0; horz = true;
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerBottom, innerWidth + 2, 1, 0, pavementFunc);
            }
            if (borderRight > 1) {
                texOffset = 4; horz = false;
                GenHelper.BuildFloor(tiles, innerRight, innerTop - 1, 1, innerHeight + 2, 0, pavementFunc);
            }
            if (borderTop > 1) {
                texOffset = 8; horz = true;
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, innerWidth + 2, 1, 0, pavementFunc);
            }
            if (borderLeft > 1) {
                texOffset = 12; horz = false;
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, 1, innerHeight + 2, 0, pavementFunc);
            }

            if (borderBottom > 1 && borderRight > 1)
                GenHelper.BuildFloor(tiles, innerRight, innerBottom, 1, 1, 0, "floor/pavement/3");
            if (borderTop > 1 && borderRight > 1)
                GenHelper.BuildFloor(tiles, innerRight, innerTop - 1, 1, 1, 0, "floor/pavement/7");
            if (borderTop > 1 && borderLeft > 1)
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerTop - 1, 1, 1, 0, "floor/pavement/b");
            if (borderBottom > 1 && borderLeft > 1)
                GenHelper.BuildFloor(tiles, innerLeft - 1, innerBottom, 1, 1, 0, "floor/pavement/f");

            Generate(district, tiles, borderLeft, borderTop, borderRight, borderBottom, rand);

            Block block = new Block(district);
            block.BuildTiles(tiles);
            return block;
        }