public Building(ContainerXXX owner, Point position, Point dimension) : base(owner, position, dimension) { SplitRooms(); Interpret(); MakeEntrances(); }
public Room(Building owner, ContainerXXX container) : base(container) { this.owner = owner; AssignFloors(); AssignWalls(); }
public override void Initialize() { world = new ContainerXXX(null, Point.zero, map.dimension); MakeBuildings(); MakeLights(); MakeNucleus(); SyncVariables(); }
private ContainerXXX ToDepth(Depth depth) { ContainerXXX to_return = new ContainerXXX(this); while (to_return.depth > depth) { to_return = to_return.MinusDepth(); } return(to_return); }
public ContainerXXX(ContainerXXX owner, Point relative_position, Point position, Point dimension) { this.owner = owner; this.depth = owner == null ? 0 : (Depth)((int)owner.depth + 1); this.relative_position = relative_position; this.left = position.x; this.right = position.x + dimension.x; this.top = position.y + dimension.y; this.bottom = position.y; this.dimension = new Point(this.right - this.left, this.top - this.bottom); }
/// <summary> /// Join two containers. /// </summary> /// <param name="other"></param> /// <returns></returns> public ContainerXXX Join(ContainerXXX other) { if (this.depth != other.depth) { Debug.LogError("Joining two Containers of different depth! " + this.depth + " and " + other.depth); } return(new ContainerXXX(this.owner, Mathf.Min(this.Left(depth - 1), other.Left(depth - 1)), Mathf.Max(this.Right(depth - 1), other.Right(depth - 1)), Mathf.Max(this.Top(depth - 1), other.Top(depth - 1)), Mathf.Min(this.Bottom(depth - 1), other.Bottom(depth - 1)))); }
public bool Touching(ContainerXXX other) // Diagonal corners don't count as touching { if (this.Right(Depth.World) == other.Left(Depth.World) || this.Left(Depth.World) == other.Right(Depth.World)) { if (this.Top(Depth.World) <= other.Bottom(Depth.World) || this.Bottom(Depth.World) >= other.Top(Depth.World)) { return(false); } return(true); } if (this.Top(Depth.World) == other.Bottom(Depth.World) || this.Bottom(Depth.World) == other.Top(Depth.World)) { if (this.Right(Depth.World) <= other.Left(Depth.World) || this.Left(Depth.World) >= other.Right(Depth.World)) { return(false); } return(true); } return(false); }
/// <summary> /// Splits containers down to a range size, and returns all created containers as a list /// </summary> /// <param name="mine"></param> /// <param name="range"></param> /// <returns></returns> public static List <ContainerXXX> RecursiveDivision(this ContainerXXX mine, IntRange range) { List <ContainerXXX> to_return = new List <ContainerXXX>(); // Get random dimensions. int size = range.Random(); Point container_dimension = new Point(size, Random.Range(size - 1, size + 1)); for (int i = 0; i < range.max; i++) { if (container_dimension.x < range.min || container_dimension.y < range.min) { return(to_return); } if (container_dimension.x > mine.dimension.x || container_dimension.y > mine.dimension.y) // If these dimensions are more than the rectangle { container_dimension -= new Point(1, 1); } else { break; } } Corner corner = CornerExtension.GetRandomCorner(); ContainerSplitPacket csp = mine.QuadSplit(container_dimension, corner); to_return.Add(csp.result); foreach (ContainerXXX container in csp.container1.RecursiveDivision(range)) { to_return.Add(container); } foreach (ContainerXXX container in csp.container2.RecursiveDivision(range)) { to_return.Add(container); } return(to_return); }
public Directional(ContainerXXX container, Direction direction) : base(container) { this.direction = direction; }
public Directional(ContainerXXX owner, Point relative_position, Direction direction) : this(new ContainerXXX(owner, relative_position, new Point(1, 1)), direction) { }
public ContainerXXX(ContainerXXX owner, Point relative_position, Point dimension) : this(owner, relative_position, Point.zero, dimension) { }
public ContainerXXX(ContainerXXX owner, int left, int right, int top, int bottom) : this(owner, new Point(left, bottom), new Point(right - left, top - bottom)) { }
public ContainerXXX(ContainerXXX container) : this(container.owner, container.relative_position, container.position_at_current_depth, container.dimension) { }
/// <summary> /// Returns true if two containers overlap. /// </summary> /// <param name="mine"></param> /// <param name="other"></param> /// <returns></returns> public bool Overlaps(ContainerXXX other) { return(!(this.Right(Depth.World) <= other.Left(Depth.World) || other.Right(Depth.World) <= this.Left(Depth.World) || this.Top(Depth.World) <= other.Bottom(Depth.World) || other.Top(Depth.World) <= this.Bottom(Depth.World))); }
private static ContainerSplitPacket QuadSplit(this ContainerXXX mine, Point dimension, Corner corner) { ContainerSplitPacket to_return = new ContainerSplitPacket(); ContainerXXX b1 = new ContainerXXX(); // [ b1 b2 ] ContainerXXX b2 = new ContainerXXX(); // [ b1 b2 ] ContainerXXX b3 = new ContainerXXX(); ContainerXXX b4 = new ContainerXXX(); switch (corner) { case Corner.TopLeft: b1 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Left(Depth.Building) + dimension.x, mine.Top(Depth.Building), mine.Top(Depth.Building) - dimension.y); b2 = new ContainerXXX(mine.owner, mine.Left(Depth.Building) + dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building), mine.Top(Depth.Building) - dimension.y); b3 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Left(Depth.Building) + dimension.x, mine.Top(Depth.Building) - dimension.y, mine.Bottom(Depth.Building)); b4 = new ContainerXXX(mine.owner, mine.Left(Depth.Building) + dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building) - dimension.y, mine.Bottom(Depth.Building)); to_return.result = b1; break; case Corner.TopRight: b1 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Right(Depth.Building) - dimension.x, mine.Top(Depth.Building), mine.Top(Depth.Building) - dimension.y); b2 = new ContainerXXX(mine.owner, mine.Right(Depth.Building) - dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building), mine.Top(Depth.Building) - dimension.y); b3 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Right(Depth.Building) - dimension.x, mine.Top(Depth.Building) - dimension.y, mine.Bottom(Depth.Building)); b4 = new ContainerXXX(mine.owner, mine.Right(Depth.Building) - dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building) - dimension.y, mine.Bottom(Depth.Building)); to_return.result = b2; break; case Corner.BottomLeft: b1 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Left(Depth.Building) + dimension.x, mine.Top(Depth.Building), mine.Bottom(Depth.Building) + dimension.y); b2 = new ContainerXXX(mine.owner, mine.Left(Depth.Building) + dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building), mine.Bottom(Depth.Building) + dimension.y); b3 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Left(Depth.Building) + dimension.x, mine.Bottom(Depth.Building) + dimension.y, mine.Bottom(Depth.Building)); b4 = new ContainerXXX(mine.owner, mine.Left(Depth.Building) + dimension.x, mine.Right(Depth.Building), mine.Bottom(Depth.Building) + dimension.y, mine.Bottom(Depth.Building)); to_return.result = b3; break; case Corner.BottomRight: b1 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Right(Depth.Building) - dimension.x, mine.Top(Depth.Building), mine.Bottom(Depth.Building) + dimension.y); b2 = new ContainerXXX(mine.owner, mine.Right(Depth.Building) - dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building), mine.Bottom(Depth.Building) + dimension.y); b3 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Right(Depth.Building) - dimension.x, mine.Bottom(Depth.Building) + dimension.y, mine.Bottom(Depth.Building)); b4 = new ContainerXXX(mine.owner, mine.Right(Depth.Building) - dimension.x, mine.Right(Depth.Building), mine.Bottom(Depth.Building) + dimension.y, mine.Bottom(Depth.Building)); to_return.result = b4; break; } if (dimension.x < dimension.y) // means it's taller than it is wide, so we do a vertical split { switch (corner) { case Corner.TopLeft: to_return.container1 = b3; to_return.container2 = b2.Join(b4); break; case Corner.TopRight: to_return.container1 = b4; to_return.container2 = b1.Join(b3); break; case Corner.BottomLeft: to_return.container1 = b1; to_return.container2 = b2.Join(b4); break; case Corner.BottomRight: to_return.container1 = b2; to_return.container2 = b1.Join(b3); break; } } else // if its wider than it is tall, we do a horizontal split { switch (corner) { case Corner.TopLeft: to_return.container1 = b2; to_return.container2 = b3.Join(b4); break; case Corner.TopRight: to_return.container1 = b1; to_return.container2 = b3.Join(b4); break; case Corner.BottomLeft: to_return.container1 = b4; to_return.container2 = b1.Join(b2); break; case Corner.BottomRight: to_return.container1 = b3; to_return.container2 = b1.Join(b2); break; } } return(to_return); }
public ContainerSplitPacket(ContainerXXX result, ContainerXXX container1, ContainerXXX container2) { this.result = result; this.container1 = container1; this.container2 = container2; }