public override int GetHashCode() { unchecked { var hashCode = (RoomTemplate != null ? RoomTemplate.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (RoomShape != null ? RoomShape.GetHashCode() : 0); return(hashCode); } }
private void CreateRoom(Rect2i room, RoomShape shape) { if (shape == RoomShape.Rectangle) { for (int y = room.y + 1; y < room.max.y; y++) { for (int x = room.x + 1; x < room.max.x; x++) { SetTile(C.LAYER_TERRAIN, new Vector2i(x, y), new Tile(Tile.TEMPLATE_EMPTY)); } } } else if (shape == RoomShape.Ellipse || shape == RoomShape.EllipseFuzzy) { for (int y = room.y + 1; y < room.max.y; y++) { for (int x = room.x + 1; x < room.max.x; x++) { float h = room.center.x; float k = room.center.y; float a = room.width; float b = room.height; float p = (((x - h) * (x - h)) / (a * a)) + (((y - k) * (y - k)) / (b * b)); float dist = 0.2f; if (shape == RoomShape.EllipseFuzzy) { dist += Random.Range(0, 3) * 0.05f; } if (p <= dist) { SetTile(C.LAYER_TERRAIN, new Vector2i(x, y), new Tile(Tile.TEMPLATE_EMPTY)); } } } } }
public Room(Position pos, int width, int height, RoomShape shape, Floor floor) { Nr = floor.GetNewRoomNr(); Pos = pos; Width = width; Height = height; Shape = shape; this.floor = floor; Log.Message("New Room created at " + pos + "-> Size: " + new Position(width, height) + ", " + shape.ToString()); switch (shape) { case RoomShape.Rectangle: InitRectangular(); break; case RoomShape.Diamond: InitDiamond(); break; default: Log.Error("Room shape not implemented! -> " + shape); break; } /* * string outlineString = "Outline:\n"; * foreach (var item in outline) * { * outlineString += item.ToString() + ","; * } * Log.Data(outlineString); */ }
public void SetRoomShape(List <Room> selectedRooms, RoomShape shape) { selectedRooms.ForEach(room => room.Shape = shape); }
public Vector GetCorner(CompassPoint point, RoomShape myRmShape = RoomShape.SquareCorners, CornerRadii corners = null) { bool isOctagonal = (myRmShape == RoomShape.Octagonal); bool isRounded = (myRmShape == RoomShape.RoundedCorners); bool isEllipse = (myRmShape == RoomShape.Ellipse); double angleInRadians; if (myRmShape == RoomShape.Ellipse) { angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this); return(new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(angleInRadians)), Center.Y + (float)((Height / 2.0) * Math.Sin(angleInRadians)))); } if (myRmShape == RoomShape.Ellipse) { if (point == CompassPoint.NorthEast || point == CompassPoint.NorthWest || point == CompassPoint.SouthWest || point == CompassPoint.SouthEast) { angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this); if (point == CompassPoint.NorthEast) { var rect = new Rect(X + Width, Y, (float)corners.TopRight, (float)corners.TopRight); return(new Vector((rect.Center.X - (float)(corners.TopRight / 2.0)) - (float)((corners.TopRight / 2.0) * Math.Cos(angleInRadians)), (rect.Center.Y + (float)(corners.TopLeft / 4.0)) + (float)((corners.TopRight / 2.0) * Math.Sin(angleInRadians)))); } if (point == CompassPoint.NorthWest) { var rect = new Rect(X, Y, (float)corners.TopLeft, (float)corners.TopLeft); return(new Vector((rect.Center.X - (float)(corners.TopLeft / 2.0)) - (float)((corners.TopLeft / 2.0) * Math.Cos(angleInRadians)), (rect.Center.Y + (float)(corners.TopLeft / 4.0)) + (float)((corners.TopLeft / 2.0) * Math.Sin(angleInRadians)))); } if (point == CompassPoint.SouthWest) { var rect = new Rect(X, Y + Height, (float)corners.BottomLeft, (float)corners.BottomLeft); return(new Vector((rect.Center.X - (float)(corners.BottomLeft / 2.0)) - (float)((corners.BottomLeft / 2.0) * Math.Cos(angleInRadians)), (rect.Center.Y - (float)(corners.BottomLeft / 2.0)) - (float)((corners.BottomLeft / 2.0) * Math.Sin(angleInRadians)))); } if (point == CompassPoint.SouthEast) { var rect = new Rect(X + Width, Y + Height, (float)corners.BottomRight, (float)corners.BottomRight); return(new Vector((rect.Center.X - (float)(corners.BottomRight / 2.0)) - (float)((corners.BottomRight / 2.0) * Math.Cos(angleInRadians)), (rect.Center.Y - (float)(corners.BottomRight / 2.0)) - (float)((corners.BottomRight / 2.0) * Math.Sin(angleInRadians)))); } } } switch (point) { case CompassPoint.North: return(new Vector(X + Width / 2, Y)); case CompassPoint.NorthNorthEast: return(new Vector(X + Width * 3 / 4, Y)); case CompassPoint.NorthEast: if (isOctagonal) { return(new Vector(X + Width * 7 / 8, Y + Height * 1 / 8)); } if (isRounded) { return(new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + 0.25 * corners.TopLeft))); } return(new Vector(X + Width, Y)); case CompassPoint.EastNorthEast: return(new Vector(X + Width, Y + Height / 4)); case CompassPoint.East: return(new Vector(X + Width, Y + Height / 2)); case CompassPoint.EastSouthEast: return(new Vector(X + Width, Y + Height * 3 / 4)); case CompassPoint.SouthEast: if (isOctagonal) { return(new Vector(X + Width * 7 / 8, Y + Height * 7 / 8)); } if (isRounded) { return(new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + Height - 0.25 * corners.TopLeft))); } return(new Vector(X + Width, Y + Height)); case CompassPoint.SouthSouthEast: return(new Vector(X + Width * 3 / 4, Y + Height)); case CompassPoint.South: return(new Vector(X + Width / 2, Y + Height)); case CompassPoint.SouthSouthWest: return(new Vector(X + Width / 4, Y + Height)); case CompassPoint.SouthWest: if (isOctagonal) { return(new Vector(X + Width * 1 / 8, Y + Height * 7 / 8)); } if (isRounded) { return(new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + Height - 0.3 * corners.TopLeft))); } return(new Vector(X, Y + Height)); case CompassPoint.WestSouthWest: return(new Vector(X, Y + Height * 3 / 4)); case CompassPoint.West: return(new Vector(X, Y + Height / 2)); case CompassPoint.WestNorthWest: return(new Vector(X, Y + Height / 4)); case CompassPoint.NorthWest: if (isOctagonal) { return(new Vector(X + Width * 1 / 8, Y + Height * 1 / 8)); } if (isRounded) { return(new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + 0.3 * corners.TopLeft))); } return(new Vector(X, Y)); case CompassPoint.NorthNorthWest: return(new Vector(X + Width / 4, Y)); default: throw new InvalidOperationException(); } }
private static void Annotate(XGraphics graphics, Palette palette, LineSegment lineSegment, TextBlock text, StringAlignment alignment, RoomShape? shape = RoomShape.SquareCorners) { Vector point; var delta = lineSegment.Delta; switch (alignment) { case StringAlignment.Near: default: point = lineSegment.Start; delta.Negate(); break; case StringAlignment.Center: point = lineSegment.Mid; break; case StringAlignment.Far: point = lineSegment.End; break; } var bounds = new Rect(point, Vector.Zero); bounds.Inflate(Settings.TextOffsetFromConnection); var angle = (float) -(Math.Atan2(delta.Y, delta.X)/Math.PI*180.0); var compassPoint = CompassPoint.East; if (Numeric.InRange(angle, 0, 45)) { compassPoint = CompassPoint.NorthWest; } else if (Numeric.InRange(angle, 45, 90)) { compassPoint = CompassPoint.SouthEast; } else if (Numeric.InRange(angle, 90, 135)) { compassPoint = CompassPoint.SouthWest; } else if (Numeric.InRange(angle, 135, 180)) { compassPoint = CompassPoint.NorthEast; } else if (Numeric.InRange(angle, 0, -45)) { compassPoint = CompassPoint.NorthEast; } else if (Numeric.InRange(angle, -45, -90)) { compassPoint = CompassPoint.NorthEast; } else if (Numeric.InRange(angle, -90, -135)) { compassPoint = CompassPoint.NorthWest; } else if (Numeric.InRange(angle, -135, -180)) { compassPoint = CompassPoint.SouthEast; } var pos = bounds.GetCorner(compassPoint); var format = new XStringFormat(); Drawing.SetAlignmentFromCardinalOrOrdinalDirection(format, compassPoint); if (alignment == StringAlignment.Center && Numeric.InRange(angle, -10, 10)) { // HACK: if the line segment is pretty horizontal and we're drawing mid-line text, // move text below the line to get it out of the way of any labels at the ends, // and center the text so it fits onto a line between two proximal rooms. pos = bounds.GetCorner(CompassPoint.South); format.Alignment = XStringAlignment.Center; format.LineAlignment = XLineAlignment.Near; } if (!Settings.DebugDisableTextRendering) text.Draw(graphics, Settings.LineFont, palette.LineTextBrush, pos, Vector.Zero, format); }
public void SetRoomShape(RoomShape shape) { var controller = new RoomController(); controller.SetRoomShape(canvas.SelectedRooms, shape); }
public Vector GetCorner(CompassPoint point, RoomShape myRmShape = RoomShape.SquareCorners, CornerRadii corners = null) { bool isOctagonal = (myRmShape == RoomShape.Octagonal); bool isRounded = (myRmShape == RoomShape.RoundedCorners); bool isEllipse = (myRmShape == RoomShape.Ellipse); double angleInRadians; if (myRmShape == RoomShape.Ellipse) { angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this); return new Vector(Center.X + (float)((Width/2.0) * Math.Cos(angleInRadians)), Center.Y + (float)((Height / 2.0) * Math.Sin(angleInRadians))); } if (myRmShape == RoomShape.Ellipse) { if (point == CompassPoint.NorthEast || point == CompassPoint.NorthWest || point == CompassPoint.SouthWest || point == CompassPoint.SouthEast) { angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this); if (point == CompassPoint.NorthEast) { var rect = new Rect(X + Width, Y , (float) corners.TopRight, (float) corners.TopRight); return new Vector((rect.Center.X - (float) (corners.TopRight/2.0)) - (float) ((corners.TopRight/2.0)*Math.Cos(angleInRadians)), (rect.Center.Y + (float)(corners.TopLeft / 4.0)) + (float) ((corners.TopRight/2.0)*Math.Sin(angleInRadians))); } if (point == CompassPoint.NorthWest) { var rect = new Rect(X, Y, (float) corners.TopLeft, (float) corners.TopLeft); return new Vector((rect.Center.X - (float) (corners.TopLeft/2.0)) - (float) ((corners.TopLeft/2.0)*Math.Cos(angleInRadians)), (rect.Center.Y + (float)(corners.TopLeft / 4.0)) + (float) ((corners.TopLeft/2.0)*Math.Sin(angleInRadians))); } if (point == CompassPoint.SouthWest) { var rect = new Rect(X, Y + Height, (float) corners.BottomLeft, (float) corners.BottomLeft); return new Vector((rect.Center.X - (float)(corners.BottomLeft / 2.0)) - (float)((corners.BottomLeft/2.0)*Math.Cos(angleInRadians)), (rect.Center.Y - (float)(corners.BottomLeft / 2.0)) - (float) ((corners.BottomLeft/2.0)*Math.Sin(angleInRadians))); } if (point == CompassPoint.SouthEast) { var rect = new Rect(X + Width, Y + Height, (float) corners.BottomRight, (float) corners.BottomRight); return new Vector((rect.Center.X - (float)(corners.BottomRight/2.0)) - (float) ((corners.BottomRight/2.0)*Math.Cos(angleInRadians)), (rect.Center.Y - (float)(corners.BottomRight/2.0 )) - (float) ((corners.BottomRight/2.0)*Math.Sin(angleInRadians))); } } } switch (point) { case CompassPoint.North: return new Vector(X + Width/2, Y); case CompassPoint.NorthNorthEast: return new Vector(X + Width*3/4, Y); case CompassPoint.NorthEast: if (isOctagonal) return new Vector (X + Width * 7/8, Y + Height * 1/8); if (isRounded) return new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + 0.25 * corners.TopLeft)); return new Vector(X + Width, Y); case CompassPoint.EastNorthEast: return new Vector(X + Width, Y + Height/4); case CompassPoint.East: return new Vector(X + Width, Y + Height/2); case CompassPoint.EastSouthEast: return new Vector(X + Width, Y + Height*3/4); case CompassPoint.SouthEast: if (isOctagonal) return new Vector (X + Width * 7/8, Y + Height * 7/8); if (isRounded) return new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + Height - 0.25 * corners.TopLeft)); return new Vector(X + Width, Y + Height); case CompassPoint.SouthSouthEast: return new Vector(X + Width*3/4, Y + Height); case CompassPoint.South: return new Vector(X + Width/2, Y + Height); case CompassPoint.SouthSouthWest: return new Vector(X + Width/4, Y + Height); case CompassPoint.SouthWest: if (isOctagonal) return new Vector (X + Width * 1/8, Y + Height * 7/8); if (isRounded) return new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + Height - 0.3 * corners.TopLeft)); return new Vector(X, Y + Height); case CompassPoint.WestSouthWest: return new Vector(X, Y + Height*3/4); case CompassPoint.West: return new Vector(X, Y + Height/2); case CompassPoint.WestNorthWest: return new Vector(X, Y + Height/4); case CompassPoint.NorthWest: if (isOctagonal) return new Vector (X + Width * 1/8, Y + Height * 1/8); if (isRounded) return new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + 0.3 * corners.TopLeft)); return new Vector(X, Y); case CompassPoint.NorthNorthWest: return new Vector(X + Width/4, Y); default: throw new InvalidOperationException(); } }
public static bool SetAlignmentFromCardinalOrOrdinalDirection(XStringFormat format, CompassPoint compassPoint, RoomShape? rs = null) { switch (compassPoint) { case CompassPoint.North: case CompassPoint.NorthEast: format.LineAlignment = XLineAlignment.Far; format.Alignment = XStringAlignment.Near; break; case CompassPoint.East: case CompassPoint.SouthEast: case CompassPoint.South: format.LineAlignment = XLineAlignment.Near; format.Alignment = XStringAlignment.Near; break; case CompassPoint.West: case CompassPoint.SouthWest: format.LineAlignment = XLineAlignment.Near; format.Alignment = XStringAlignment.Far; break; case CompassPoint.NorthWest: case CompassPoint.NorthNorthWest: format.LineAlignment = XLineAlignment.Far; format.Alignment = XStringAlignment.Far; break; default: return false; } return true; }