Exemple #1
0
    public void FixOverlap()
    {
        for (int i = 0; i < Rooms.Count - 1; i++)
        {
            for (int j = i + 1; j < Rooms.Count; j++)
            {
                GenRoom a = Rooms[i];
                GenRoom b = Rooms[j];

                if (a.Outer.Overlaps(b.Outer))
                {
                    GenRect rA = a.Outer;
                    GenRect rB = b.Outer;
                    // find the union of both
                    int     uLeft  = Mathf.Max(rA.MinX, rB.MinX);
                    int     uTop   = Mathf.Max(rA.MinY, rB.MinY);
                    int     uRight = Mathf.Min(rA.MaxX, rB.MaxX);
                    int     uBot   = Mathf.Min(rA.MaxY, rB.MaxY);
                    GenRect union  =
                        new GenRect(uLeft, uRight, uTop, uBot);

                    GenRoom dominant = a.SpacePriority > b.SpacePriority ? a : b;
                    GenRoom weaker   = a.SpacePriority > b.SpacePriority ? b : a;

                    HashSet <GenPositionTile> dominantEdge = dominant.GetEdge();

                    for (int x = union.MinX; x <= union.MaxX; x++)
                    {
                        for (int y = union.MinY; y <= union.MaxY; y++)
                        {
                            // check if on the edge
                            if (dominantEdge.Any(e => e.Tile == dominant.GetAtWorldspaceG(x, y)))
                            {
                                // this Tile is on the Edge and should be shared
                                weaker.SetTileAtG(x, y, dominant.GetAtWorldspaceG(x, y));
                            }
                            else
                            {
                                // remove the tile from weaker one
                                weaker.RemoveTileAtG(x, y);
                            }
                        }
                    }
                }
            }
        }
    }