/// <summary> /// /// </summary> /// <param name="room"></param> /// <param name="dir">Direction from room to hall.</param> /// <param name="tier"></param> /// <returns></returns> public virtual IntRange GetHallTouchRange(IRoomGen room, Dir4 dir, int tier) { bool vertical = dir.ToAxis() == Axis4.Vert; // The hall will touch the entire side of each room under normal circumstances. // Things get tricky for a target room that occupies more than one cell. // First, try to cover only the part of the target room that's in the cell. // If that's not possible, try to extend the hall until it covers one tile of the target room. IntRange startRange = room.Draw.GetSide(dir.ToAxis()); // factor possibletiles into this calculation int borderLength = room.GetBorderLength(dir); for (int ii = 0; ii < borderLength; ii++) { if (room.GetFulfillableBorder(dir, ii)) { startRange.Min += ii; break; } } for (int ii = 0; ii < borderLength; ii++) { if (room.GetFulfillableBorder(dir, borderLength - 1 - ii)) { startRange.Max -= ii; break; } } int tierStart = vertical ? tier * (this.WidthPerCell + this.CellWall) : tier * (this.HeightPerCell + this.CellWall); int tierLength = vertical ? this.WidthPerCell : this.HeightPerCell; IntRange newRange = new IntRange(Math.Max(startRange.Min, tierStart), Math.Min(startRange.Max, tierStart + tierLength)); if (newRange.Max <= newRange.Min) { // try to extend the hall until it covers one tile of the target room. // first, note that the current end range is covering the zone between the tier and the edge of the room (inverted) // un-invert this and inflate by 1, and you will have a zone that covers 1 tile with the room // get the intersection of this zone and the room. newRange = new IntRange(Math.Max(startRange.Min, newRange.Max - 1), Math.Min(startRange.Max, newRange.Min + 1)); } return(newRange); }
protected static bool HasBorderOpening(IRoomGen roomFrom, Rect rectTo, Dir4 expandTo) { Loc diff = roomFrom.Draw.Start - rectTo.Start; // how far ahead the start of source is to dest int offset = diff.GetScalar(expandTo.ToAxis().Orth()); // Traverse the region that both borders touch int sourceLength = roomFrom.GetBorderLength(expandTo); int destLength = rectTo.Size.GetScalar(expandTo.ToAxis().Orth()); for (int ii = Math.Max(0, offset); ii - offset < sourceLength && ii < destLength; ii++) { bool sourceFulfill = roomFrom.GetFulfillableBorder(expandTo, ii - offset); if (sourceFulfill) { return(true); } } return(false); }
public static int GetBorderMatch(IRoomGen roomFrom, IRoomGen room, Loc candLoc, Dir4 expandTo) { int totalMatch = 0; Loc diff = roomFrom.Draw.Start - candLoc; // how far ahead the start of source is to dest int offset = diff.GetScalar(expandTo.ToAxis().Orth()); // Traverse the region that both borders touch int sourceLength = roomFrom.GetBorderLength(expandTo); int destLength = room.GetBorderLength(expandTo.Reverse()); for (int ii = Math.Max(0, offset); ii - offset < sourceLength && ii < destLength; ii++) { bool sourceFulfill = roomFrom.GetFulfillableBorder(expandTo, ii - offset); bool destFulfill = room.GetFulfillableBorder(expandTo.Reverse(), ii); if (sourceFulfill && destFulfill) { totalMatch++; } } return(totalMatch); }