Exemple #1
0
 private Vector2Int GetRandomBoxCoord(BoxInfo box)
 {
     return(new Vector2Int(
                Random.Range(box.GetOrigin().x, box.GetOrigin().x + box.GetWidth()),
                Random.Range(box.GetOrigin().y, box.GetOrigin().y + box.GetHeight())
                ));
 }
Exemple #2
0
        private Vector2Int GetCoordInSection0(RoomInfo roomInfo, int nbrTry = c_mandatoryTry)
        {
            int width  = (m_boundariesMap.x / 3) - 2 * c_extraWidth;
            int height = (m_boundariesMap.y / 3) - 2 * c_extraWidth;

            if (width - roomInfo.Width < 1 || height - roomInfo.Height < 1)
            {
                if (nbrTry == c_mandatoryTry)
                {
                    Debug.Log("MAP CREATION ALERT : SECTION0 to small for mandatory room, look your sizing");
                }
                return(new Vector2Int(-1, -1));
            }
            BoxInfo box = new BoxInfo(m_boundariesMap.x / 3 + m_wallThickness,
                                      m_boundariesMap.y / 3 + m_wallThickness,
                                      width - 2 * m_wallThickness - roomInfo.Width,
                                      height - 2 * m_wallThickness - roomInfo.Height);
            Vector2Int coordTry;

            for (int i = 0; i < nbrTry; i++)
            {
                coordTry = GetRandomBoxCoord(box);
                if (SpaceIsFree(roomInfo, coordTry))
                {
                    return(coordTry);
                }
            }
            if (nbrTry == c_mandatoryTry)
            {
                Debug.Log("MAP CREATION ALERT : Was not able to fit in SECTION0 mandatory room, look your sizing");
            }
            return(new Vector2Int(-1, -1));
        }
Exemple #3
0
 private Vector2Int GetCoordInSection(BoxInfo bigBox, BoxInfo smallBox)
 {
     if (Random.Range(0, (bigBox.GetArea() + smallBox.GetArea())) < bigBox.GetArea())
     {
         return(GetRandomBoxCoord(bigBox));
     }
     else
     {
         return(GetRandomBoxCoord(smallBox));
     }
 }
Exemple #4
0
        private Vector2Int TryGetCoord(RoomInfo roomInfo, BoxInfo bigBox, BoxInfo smallBox, int nbrTry)
        {
            Vector2Int coordTry;

            for (int i = 0; i < nbrTry; i++)
            {
                coordTry = GetCoordInSection(bigBox, smallBox);
                if (SpaceIsFree(roomInfo, coordTry))
                {
                    return(coordTry);
                }
            }
            return(new Vector2Int(-1, -1));
        }
Exemple #5
0
        private Vector2Int GetCoordInBottomRight(RoomInfo roomInfo, int nbrTry = c_mandatoryTry)
        {
            int bigWidth  = (m_boundariesMap.x / 3) - roomInfo.Width - c_extraWidth;
            int bigHeigth = (m_boundariesMap.y / 2) - roomInfo.Height - c_extraWidth;

            if (bigWidth - roomInfo.Width < 1 || bigHeigth - roomInfo.Height < 1)
            {
                if (nbrTry == c_mandatoryTry)
                {
                    Debug.Log("MAP CREATION ALERT : BottomRight to small for mandatory room, look your sizing");
                }
                return(new Vector2Int(-1, -1));
            }
            int     SB_x   = m_boundariesMap.x / 6 + m_wallThickness;
            int     SB_y   = m_boundariesMap.y / 3 - m_wallThickness - roomInfo.Height;
            int     BB_x   = m_boundariesMap.x / 2 - m_wallThickness - roomInfo.Width - SB_x;
            int     BB_y   = m_boundariesMap.y / 2 - m_wallThickness - roomInfo.Height;
            BoxInfo bigBox = new BoxInfo(m_boundariesMap.x / 2 + SB_x + c_SectionDoorWidth,
                                         0,
                                         BB_x,
                                         BB_y);
            BoxInfo smallBox = new BoxInfo(m_boundariesMap.x / 2 + c_SectionDoorWidth,
                                           0,
                                           SB_x,
                                           SB_y);
            Vector2Int coord = TryGetCoord(roomInfo, bigBox, smallBox, nbrTry);

            if (coord.x != -1)
            {
                return(coord);
            }
            else if (nbrTry == c_mandatoryTry)
            {
                Debug.Log("MAP CREATION ALERT : Was not able to fit in BOTTOMRIGHT mandatory room, look your sizing");
            }
            return(new Vector2Int(-1, -1));
        }
Exemple #6
0
        private Vector2Int GetCoordInTopLeft(RoomInfo roomInfo, int nbrTry = c_mandatoryTry)
        {
            int bigWidth  = (m_boundariesMap.x / 3) - 2 * c_extraWidth;
            int bigHeigth = (m_boundariesMap.y / 2) - 2 * c_extraWidth;

            if (bigWidth - roomInfo.Width < 1 || bigHeigth - roomInfo.Height < 1)
            {
                if (nbrTry == c_mandatoryTry)
                {
                    Debug.Log("MAP CREATION ALERT : TopLeft to small for mandatory room, look your sizing");
                }
                return(new Vector2Int(-1, -1));
            }
            int     SB_w   = m_boundariesMap.x / 3 - m_wallThickness - roomInfo.Width;
            int     SB_h   = m_boundariesMap.y / 6 + m_wallThickness;
            int     BB_w   = m_boundariesMap.x / 2 - m_wallThickness - roomInfo.Width;
            int     BB_h   = m_boundariesMap.y / 2 - m_wallThickness - roomInfo.Height - SB_h;
            BoxInfo bigBox = new BoxInfo(0,
                                         m_boundariesMap.y / 2 + SB_h + c_SectionDoorWidth,
                                         BB_w,
                                         BB_h);
            BoxInfo smallBox = new BoxInfo(0,
                                           m_boundariesMap.y / 2 + c_SectionDoorWidth,
                                           SB_w,
                                           SB_h);
            Vector2Int coord = TryGetCoord(roomInfo, bigBox, smallBox, nbrTry);

            if (coord.x != -1)
            {
                return(coord);
            }
            else if (nbrTry == c_mandatoryTry)
            {
                Debug.Log("MAP CREATION ALERT : Was not able to fit in TOPLEFT mandatory room, look your sizing");
            }
            return(new Vector2Int(-1, -1));
        }