public static void FillWith(MapArrayTile[,] mapArr, MapArrayTile mapArrayTile)
 {
     for (int i = 0; i < mapArr.GetLength(0); i++)
     {
         for (int j = 0; j < mapArr.GetLength(1); j++)
         {
             mapArr[i, j] = mapArrayTile;
         }
     }
 }
 protected static void FillBoxWith(MapArrayTile[,] mapArr,
                                   int startX, int endX, int startY, int endY, MapArrayTile mapArrayTile)
 {
     for (int i = startX; i < endX; i++)
     {
         for (int j = startY; j < endY; j++)
         {
             mapArr[i, j] = mapArrayTile;
         }
     }
 }
 protected static MapArrayTile[,] AddBorderTo(MapArrayTile[,] mapArr)
 {
     MapArrayTile[,] mapArrWithBorder = new MapArrayTile[mapArr.GetLength(0) + 2, mapArr.GetLength(1) + 2];
     FillWith(mapArrWithBorder, MapArrayTile.None);
     for (int i = 0; i < mapArr.GetLength(0); i++)
     {
         for (int j = 0; j < mapArr.GetLength(1); j++)
         {
             mapArrWithBorder[i + 1, j + 1] = mapArr[i, j];
         }
     }
     return(mapArrWithBorder);
 }
    protected static int NumberOfInAround(MapArrayTile mapArrayTile, MapArrayTile[,] mapArr, int i, int j)
    {
        int sum = 0;

        for (int x = -1; x < 2; x++)
        {
            for (int y = -1; y < 2; y++)
            {
                if (mapArr[i + x, j + y] == mapArrayTile)
                {
                    sum++;
                }
            }
        }
        return(sum);
    }
 protected static MapArrayTile[,] Combine(MapArrayTile[,] mapArr1, MapArrayTile[,] mapArr2)
 {
     MapArrayTile[,] newMapArr = new MapArrayTile[mapArr1.GetLength(0), mapArr1.GetLength(1)];
     for (int i = 0; i < mapArr1.GetLength(0); i++)
     {
         for (int j = 0; j < mapArr1.GetLength(1); j++)
         {
             if (mapArr1[i, j] != MapArrayTile.None)
             {
                 newMapArr[i, j] = mapArr1[i, j];
             }
             else if (mapArr2[i, j] != MapArrayTile.None)
             {
                 newMapArr[i, j] = mapArr2[i, j];
             }
         }
     }
     return(newMapArr);
 }
    //check that it uses the right map array, arg not field
    protected void ExtendWithAt(MapArrayTile[,] extenderMapArray,
                                Vector2 regularToExtenderCoordConversion)
    {
        //dont just change map, also change rects and coord to position conversion somehow
        Vector2 mapSize         = new Vector2(mapArray.GetLength(0), mapArray.GetLength(1));
        Vector2 extenderMapSize = new Vector2(extenderMapArray.GetLength(0), extenderMapArray.GetLength(1));

        Vector2 topRightCorner   = Vector2.Max(mapSize, extenderMapSize - regularToExtenderCoordConversion);
        Vector2 bottomLeftCorner = Vector2.Min(Vector2.zero, Vector2.zero - regularToExtenderCoordConversion);

        Vector2 newMapSize = topRightCorner - bottomLeftCorner;
        Vector2 regularToNewCoordConversion  = -bottomLeftCorner;
        Vector2 extenderToNewCoordConversion = regularToNewCoordConversion - regularToExtenderCoordConversion;

        // Debug.Log(mapSize);
        // Debug.Log(extenderMapSize);
        // Debug.Log(topRightCorner);
        // Debug.Log(bottomLeftCorner);

        MapArrayTile[,] newMapArray = new MapArrayTile[(int)newMapSize.x, (int)newMapSize.y];
        FillWith(newMapArray, MapArrayTile.None);

        for (int i = 0; i < mapArray.GetLength(0); i++)
        {
            for (int j = 0; j < mapArray.GetLength(1); j++)
            {
                newMapArray[i + (int)regularToNewCoordConversion.x, j + (int)regularToNewCoordConversion.y] = mapArray[i, j];
            }
        }
        for (int i = 0; i < extenderMapArray.GetLength(0); i++)
        {
            for (int j = 0; j < extenderMapArray.GetLength(1); j++)
            {
                newMapArray[i + (int)extenderToNewCoordConversion.x, j + (int)extenderToNewCoordConversion.y] = extenderMapArray[i, j];
            }
        }

        mapArray = newMapArray;
        roomBoundingRect.position      += regularToNewCoordConversion;
        originalToFinalCoordConversion += regularToNewCoordConversion;
    }
 protected static MapArrayTile[,] MakeWalls(MapArrayTile[,] mapArr)
 {
     //Debug.Log("Making walls");
     MapArrayTile[,] mapArrWithBorder = AddBorderTo(mapArr);
     MapArrayTile[,] newMapArr        = new MapArrayTile[mapArr.GetLength(0), mapArr.GetLength(1)];
     for (int i = 0; i < mapArr.GetLength(0); i++)
     {
         for (int j = 0; j < mapArr.GetLength(1); j++)
         {
             if (mapArr[i, j] == MapArrayTile.None &&
                 NumberOfInAround(MapArrayTile.Ground, mapArrWithBorder, i + 1, j + 1) > 0)
             {
                 newMapArr[i, j] = MapArrayTile.Wall;
             }
             else
             {
                 newMapArr[i, j] = mapArr[i, j];
             }
         }
     }
     return(newMapArr);
 }
    protected override MapArrayTile[,] GeneratePathInto(int seed, Side side,
                                                        MapArrayGenerator otherMapArrayGenerator, out Vector2 connectorCoords, out Vector2 plugCoords)
    {
        System.Random random        = new System.Random(seed);
        int           hallThickness = random.Next((int)hallThicknessRange.x, (int)hallThicknessRange.y);
        int           hallYCoord    = random.Next((int)otherMapArrayGenerator.roomBoundingRect.min.y + hallThickness / 2,
                                                  (int)otherMapArrayGenerator.roomBoundingRect.max.y - (hallThickness + 1) / 2);
        int hallXCoord = random.Next((int)otherMapArrayGenerator.roomBoundingRect.min.x + hallThickness / 2,
                                     (int)otherMapArrayGenerator.roomBoundingRect.max.x - (hallThickness + 1) / 2);

        MapArrayTile[,] otherMapArray = otherMapArrayGenerator.mapArray;
        Rect otherRoomBoundingRect = otherMapArrayGenerator.roomBoundingRect;

        plugCoords      = Vector2.zero;
        connectorCoords = Vector2.zero;

        switch (side)
        {
        case Side.Left:
            connectorCoords = new Vector2(-0.5f, hallYCoord);
            plugCoords      = new Vector2((int)otherRoomBoundingRect.min.x - 0.5f, hallYCoord);
            break;

        case Side.Right:
            connectorCoords = new Vector2(otherMapArray.GetLength(0) - 0.5f, hallYCoord);
            plugCoords      = new Vector2((int)otherRoomBoundingRect.max.x - 0.5f, hallYCoord);
            break;

        case Side.Top:
            connectorCoords = new Vector2(hallXCoord, otherMapArray.GetLength(1) - 0.5f);
            plugCoords      = new Vector2(hallXCoord, (int)otherRoomBoundingRect.max.y - 0.5f);
            break;

        case Side.Bottom:
            connectorCoords = new Vector2(hallXCoord, -0.5f);
            plugCoords      = new Vector2(hallXCoord, (int)otherRoomBoundingRect.min.y - 0.5f);
            break;

        default:
            Debug.Log("Side does not exist");
            break;
        }

        MapArrayTile[,] pathArray = new MapArrayTile[otherMapArray.GetLength(0), otherMapArray.GetLength(1)];
        FillWith(pathArray, MapArrayTile.None);

        //Returns the position of the connector in map coords
        switch (side)
        {
        case Side.Left:
            FillBoxWith(pathArray, 0, (int)otherRoomBoundingRect.min.x,
                        hallYCoord - hallThickness / 2, hallYCoord + (hallThickness + 1) / 2, MapArrayTile.Ground);
            break;

        case Side.Right:
            FillBoxWith(pathArray, (int)otherRoomBoundingRect.max.x, pathArray.GetLength(0),
                        hallYCoord - hallThickness / 2, hallYCoord + (hallThickness + 1) / 2, MapArrayTile.Ground);
            break;

        case Side.Top:
            FillBoxWith(pathArray, hallXCoord - hallThickness / 2, hallXCoord + (hallThickness + 1) / 2,
                        (int)otherRoomBoundingRect.max.y, pathArray.GetLength(1), MapArrayTile.Ground);
            break;

        case Side.Bottom:
            FillBoxWith(pathArray, hallXCoord - hallThickness / 2, hallXCoord + (hallThickness + 1) / 2,
                        0, (int)otherRoomBoundingRect.min.y, MapArrayTile.Ground);
            break;

        default:
            Debug.Log("Side does not exist");
            break;
        }
        return(pathArray);
    }