Exemplo n.º 1
0
 public Building(ContainerXXX owner, Point position, Point dimension)
     : base(owner, position, dimension)
 {
     SplitRooms();
     Interpret();
     MakeEntrances();
 }
Exemplo n.º 2
0
 public Room(Building owner, ContainerXXX container)
     : base(container)
 {
     this.owner = owner;
     AssignFloors();
     AssignWalls();
 }
Exemplo n.º 3
0
 public override void Initialize()
 {
     world = new ContainerXXX(null, Point.zero, map.dimension);
     MakeBuildings();
     MakeLights();
     MakeNucleus();
     SyncVariables();
 }
Exemplo n.º 4
0
    private ContainerXXX ToDepth(Depth depth)
    {
        ContainerXXX to_return = new ContainerXXX(this);

        while (to_return.depth > depth)
        {
            to_return = to_return.MinusDepth();
        }
        return(to_return);
    }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 /// <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))));
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
    /// <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);
    }
Exemplo n.º 9
0
 public Directional(ContainerXXX container, Direction direction)
     : base(container)
 {
     this.direction = direction;
 }
Exemplo n.º 10
0
 public Directional(ContainerXXX owner, Point relative_position, Direction direction)
     : this(new ContainerXXX(owner, relative_position, new Point(1, 1)), direction)
 {
 }
Exemplo n.º 11
0
 public ContainerXXX(ContainerXXX owner, Point relative_position, Point dimension)
     : this(owner, relative_position, Point.zero, dimension)
 {
 }
Exemplo n.º 12
0
 public ContainerXXX(ContainerXXX owner, int left, int right, int top, int bottom)
     : this(owner, new Point(left, bottom), new Point(right - left, top - bottom))
 {
 }
Exemplo n.º 13
0
 public ContainerXXX(ContainerXXX container)
     : this(container.owner, container.relative_position, container.position_at_current_depth, container.dimension)
 {
 }
Exemplo n.º 14
0
 /// <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)));
 }
Exemplo n.º 15
0
    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);
    }
Exemplo n.º 16
0
 public ContainerSplitPacket(ContainerXXX result, ContainerXXX container1, ContainerXXX container2)
 {
     this.result     = result;
     this.container1 = container1;
     this.container2 = container2;
 }