public void SetBounds(int dx, int dy, int dz) { if (matrix == null) { matrix = new RoomPoint[dx, dy, dz]; this.dx = dx; this.dy = dy; this.dz = dz; return; } var newMatrix = new RoomPoint[dx, dy, dz]; for (var x = 0; x < this.dx; x++) { for (var y = 0; y < this.dy; y++) { for (var z = 0; z < this.dz; z++) { if (x < dx && y < dy && z < dz) { newMatrix[x, y, z] = matrix[x, y, z]; } } } } this.dx = dx; this.dy = dy; this.dz = dz; matrix = newMatrix; }
private void SetBlock(List <RoomPoint> points, int x, int y, int z, string block, int order = 0) { var point = new RoomPoint { X = x + OffsetX, Z = z + OffsetZ, Y = y + OffsetY, BlockName = block, Order = order, RoomIndex = RoomIndex }; points.Add(point); }
public void GetPointRange(RoomPoint currentPoint, int?dx, int?dz, out int lower, out int higher) { lower = -1; higher = -1; for (var pos = 0; pos < (dx ?? dz); pos++) { if (matrix[dz.HasValue ? currentPoint.X : pos, 0, dx.HasValue ? currentPoint.Z : pos] == null) { continue; } if (lower == -1) { lower = pos; } higher = pos; } }
public void GetZPointRange(RoomPoint currentPoint, out int lower, out int higher, int?dz = null) { GetPointRange(currentPoint, null, dz ?? this.dz, out lower, out higher); }
public void GetXPointRange(RoomPoint currentPoint, out int lower, out int higher, int?dx = null) { GetPointRange(currentPoint, dx ?? this.dx, null, out lower, out higher); }
public int GetPointHeight(RoomPoint p) { return(rooms[p.RoomIndex].Height); }
//public enum WindowStyles //{ // Windows4x4, // WindowsSpan //} //public WindowStyles WindowStyle { get; set; } public List <RoomPoint> RenderPoints() { /* * int rooms, int floors, string WALL, List<RoomPoint> points, string AIR, * string EMPTY, string INSIDE, * string ABOVEDOOR, string GLASS) */ Structure rc = new Structure(NumberOfRooms) { CeilingBlock = CeilingBlock, RoofBlock = "dark_oak_stairs", SlabBlock = "wooden_slab 5", WallBlock = WallBlock, AirBlock = AirBlock, InsideBlock = InsideBlock, GlassBlock = GlassBlock, EmptyBlock = EmptyBlock, InnerDoor = "spruce_door", Floors = Floors }; rc.JoinRooms(); var rnd = new Random(); //WindowStyle = rnd.NextEnum<WindowStyles>(); // add doors and windows RoomPoint outerdoor = null; for (int floor = 0; floor < rc.Floors; floor++) { var y = floor * 6 + 2; for (var x = 0; x < rc.dx; x++) { for (var z = 0; z < rc.dz; z++) { if (rc.GetPoint(x, y, z)?.BlockName != WallBlock) { continue; } var emptyLeft = x <= 0 || rc.GetPoint(x - 1, y, z) == null || rc.GetPoint(x - 1, y, z).BlockName.StartsWith(AirBlock); var emptyBack = z <= 0 || rc.GetPoint(x, y, z - 1) == null || rc.GetPoint(x, y, z - 1).BlockName.StartsWith(AirBlock); var emptyRight = x >= rc.dx - 1 || rc.GetPoint(x + 1, y, z) == null || rc.GetPoint(x + 1, y, z).BlockName.StartsWith(AirBlock); var emptyFront = z >= rc.dz - 1 || rc.GetPoint(x, y, z + 1) == null || rc.GetPoint(x, y, z + 1).BlockName.StartsWith(AirBlock); var left = emptyLeft ? EmptyBlock : rc.GetPoint(x - 1, y, z).BlockName; var right = emptyRight ? EmptyBlock : rc.GetPoint(x + 1, y, z).BlockName; var front = emptyFront ? EmptyBlock : rc.GetPoint(x, y, z + 1).BlockName; var back = emptyBack ? EmptyBlock : rc.GetPoint(x, y, z - 1).BlockName; if (emptyLeft && right.Equals(InsideBlock) || emptyRight && left.Equals(InsideBlock)) { if (outerdoor == null && y == 2 && front == WallBlock && back == WallBlock) { rc.GetZPointRange(rc.GetPoint(x, y - 1, z), out var lower, out var higher); var doorZ = rnd.Next(lower + 2, lower + 3); outerdoor = rc.GetPoint(x, y - 1, doorZ); outerdoor.BlockName = $"birch_door {(emptyLeft ? 0 : 2)}"; rc.GetPoint(x, y, doorZ).BlockName = $"birch_door {(emptyLeft ? 0 + 8 : 2 + 8)}"; rc.GetPoint(x, y + 1, doorZ).BlockName = ABOVEDOOR; //rc.GetPoint(x, y - 1,doorZ+1).BlockName = ABOVEDOOR; //rc.GetPoint(x, y, doorZ + 1).BlockName = ABOVEDOOR; //rc.GetPoint(x, y + 1, doorZ + 1).BlockName = ABOVEDOOR; //rc.GetPoint(x, y - 1, doorZ - 1).BlockName = ABOVEDOOR; //rc.GetPoint(x, y, doorZ - 1).BlockName = ABOVEDOOR; //rc.GetPoint(x, y + 1, doorZ - 1).BlockName = ABOVEDOOR; continue; } // front to back if ((front == GlassBlock || front == WallBlock) && (back == GlassBlock || back == WallBlock) && z < rc.dz - 2 && z > 1) { var front2 = rc.GetPoint(x, y, z + 2)?.BlockName ?? EmptyBlock; var back2 = rc.GetPoint(x, y, z - 2)?.BlockName ?? EmptyBlock; ApplyWindowStyle(rc, x, y, z, front2, back2); } } else if (emptyFront && back.Equals(InsideBlock) || emptyBack && front.Equals(InsideBlock)) { if (outerdoor == null && y == 2 && right == WallBlock && left == WallBlock) { rc.GetXPointRange(rc.GetPoint(x, y - 1, z), out var lower, out var higher); var doorX = rnd.Next(lower + 2, lower + 3); outerdoor = rc.GetPoint(x, y - 1, z); outerdoor.BlockName = $"birch_door {(emptyLeft ? 1 : 3)}"; rc.GetPoint(doorX, y, z).BlockName = $"birch_door {(emptyLeft ? 1 + 8 : 3 + 8)}"; rc.GetPoint(doorX, y + 1, z).BlockName = ABOVEDOOR; //rc.GetPoint(doorX + 1, y - 1, z).BlockName = ABOVEDOOR; //rc.GetPoint(doorX + 1, y, z).BlockName = ABOVEDOOR; //rc.GetPoint(doorX + 1, y + 1, z).BlockName = ABOVEDOOR; //rc.GetPoint(doorX - 1, y - 1, z).BlockName = ABOVEDOOR; //rc.GetPoint(doorX - 1, y, z).BlockName = ABOVEDOOR; //rc.GetPoint(doorX - 1, y + 1, z).BlockName = ABOVEDOOR; continue; } // left to right if ((left == GlassBlock || left == WallBlock) && (right == GlassBlock || right == WallBlock) && x < rc.dx - 2 && x > 1) { var left2 = rc.GetPoint(x + 2, y, z)?.BlockName ?? EmptyBlock; var right2 = rc.GetPoint(x - 2, y, z)?.BlockName ?? EmptyBlock; ApplyWindowStyle(rc, x, y, z, left2, right2); } } } } } rc.ReplaceBlocksByName(ABOVEDOOR, WallBlock); var points = rc.ToRoomPoints(); // add roof var roof = new Roof(rc) { RoofBlock = "dark_oak_stairs", SlabBlock = "wooden_slab 5", WallBlock = WallBlock, OuterDoor = outerdoor }; points = roof.RenderPoints(); points.AddRange(rc.ToRoomPoints()); rc.AddPoints(points); return(rc.ToRoomPoints()); }