Ejemplo n.º 1
0
        public override void Generate(District district, TileBuilder[,] tiles, Random rand)
        {
            var dirX = ((int) Direction & 0x5) == 0 ? 1 : 0;
            var dirY = 1 - dirX;

            var left = Direction == Face.North || Direction == Face.East ? LeftBorderTile : RightBorderTile;
            var right = Direction == Face.North || Direction == Face.East ? RightBorderTile : LeftBorderTile;

            int conflict = GetConflict(tiles, X - dirX * 2, Y - dirY * 2);
            GenHelper.BuildWall(tiles, X - dirX, Y - dirY, Direction, 1, conflict, BothBorderTile);
            GenHelper.BuildWall(tiles, X - dirX, Y - dirY, Direction, 1, conflict, Height - conflict, left);

            GenHelper.BuildWall(tiles, X, Y, Direction, Width, Height, ResourceLocator.None);

            conflict = GetConflict(tiles, X + dirX * (Width + 1), Y - dirY * (Width + 1));
            GenHelper.BuildWall(tiles, X + dirX * Width, Y + dirY * Width, Direction, 1, conflict, BothBorderTile);
            GenHelper.BuildWall(tiles, X + dirX * Width, Y + dirY * Width, Direction, 1, conflict, Height - conflict, right);

            for (int i = 0; i < Width; ++i) {
                var doorway = Tuple.Create(tiles[X + dirX * i, Y + dirY * i], Direction, Height);
                if (_doorways.Any(x => x.Item2 == Direction && x.Item1 == doorway.Item1)) {
                    var existing = _doorways.First(x => x.Item2 == Direction && x.Item1 == doorway.Item1);
                    if (existing.Item3 >= doorway.Item3) continue;
                }
                _doorways.Add(doorway);
            }
        }
Ejemplo n.º 2
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));
 }
Ejemplo n.º 3
0
 private int GetConflict(TileBuilder[,] tiles, int x, int y)
 {
     var tile = _doorways.FirstOrDefault(d => d.Item2 == Direction && d.Item1 == tiles[x, y]);
     if (tile != null) {
         return Math.Min(tile.Item3, Height);
     } else {
         return 0;
     }
 }
Ejemplo n.º 4
0
        protected override void Generate(District district, TileBuilder[,] tiles,
            int borderLeft, int borderTop,
            int borderRight, int borderBottom, Random rand)
        {
            _parkGen.Fence = rand.NextDouble() < 0.75;
            _parkGen.X = borderLeft;
            _parkGen.Y = borderTop;
            _parkGen.SizeX = district.Width - borderLeft - borderRight;
            _parkGen.SizeY = district.Height - borderTop - borderBottom;

            _parkGen.Generate(district, tiles, rand);
        }
Ejemplo n.º 5
0
        public void GenerateOpposite(District district, TileBuilder[,] tiles, Random rand)
        {
            Direction = Direction.GetOpposite();
            X -= Direction.GetNormalX();
            Y -= Direction.GetNormalY();

            Generate(district, tiles, rand);

            Direction = Direction.GetOpposite();
            X -= Direction.GetNormalX();
            Y -= Direction.GetNormalY();
        }
Ejemplo n.º 6
0
 public override void Generate(District district, TileBuilder[,] tiles, Random rand)
 {
     for (int x = 0; x < SizeX; ++x) {
         for (int y = 0; y < SizeY; ++y) {
             if (rand.NextDouble() <= CrateFrequency) {
                 var crateClass = rand.NextDouble() < 2.0 / 3.0
                     ? "small crate"
                     : "large crate";
                 var crate = Entity.Create(district.World, crateClass);
                 crate.Position2D = new Vector2(district.X + X + x + 0.5f, district.Y + Y + y + 0.5f);
                 district.PlaceEntity(crate);
             }
         }
     }
 }
Ejemplo n.º 7
0
        protected override void Generate(District district, TileBuilder[,] tiles,
            int borderLeft, int borderTop,
            int borderRight, int borderBottom, Random rand)
        {
            _buildingGen.EntranceFaces =
                (borderLeft > 1 ? Face.West : Face.None) |
                (borderTop > 1 ? Face.North : Face.None) |
                (borderRight > 1 ? Face.East : Face.None) |
                (borderBottom > 1 ? Face.South : Face.None);

            _buildingGen.X = borderLeft;
            _buildingGen.Y = borderTop;
            _buildingGen.SizeX = district.Width - borderLeft - borderRight;
            _buildingGen.SizeY = district.Height - borderTop - borderBottom;

            _buildingGen.Generate(district, tiles, rand);
        }
Ejemplo n.º 8
0
        public Tile(int x, int y, TileBuilder builder)
        {
            _staticEnts = new HashSet<Entity>();
            _neighbours = new Tile[4];

            X = x;
            Y = y;

            WallHeight = builder.WallHeight;
            FloorHeight = builder.FloorHeight;
            RoofHeight = builder.RoofHeight;

            RoofSlant = builder.RoofSlant;

            FloorTileIndex = builder.FloorTileIndex;
            RoofTileIndex = builder.RoofTileIndex;
            WallTileIndices = builder.GetWallTileIndices();
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
        public override void Generate(District district, TileBuilder[,] tiles, Random rand)
        {
            base.Generate(district, tiles, rand);

            GenHelper.BuildWall(tiles, X, Y, Direction, Width, DoorPosition, Height - DoorPosition, DoorTile);
        }
Ejemplo n.º 11
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);
            }
        }