示例#1
0
        void ProcBuildings()
        {
            foreach (RMGBuilding b in buildings)
            {
                for (int xx = b.tlx; xx <= b.brx; xx += 1)
                {
                    for (int yy = b.tly; yy <= b.bry; yy += 1)
                    {
                        b.tiles.Add(GetTile(xx, yy));
                    }
                }

                for (int xx = b.tlx + 1; xx < b.brx; xx += 1)
                {
                    for (int yy = b.tly + 1; yy < b.bry; yy += 1)
                    {
                        RMTile t = GetTile(xx, yy);
                        if (t != null)
                        {
                            t.btype = BUILDING_TYPE.INSIDE;
                        }
                        else
                        {
                            Debug.LogError(b + " is invalid");
                        }
                    }
                }
            }


            for (int i = buildings.Count - 1; i >= 0; i -= 1)
            {
                RMGBuilding A = buildings[i];
                for (int j = buildings.Count - 1; j >= 0; j -= 1)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    RMGBuilding B = buildings[j];

                    if (A.yDir != 0 && B.yDir != 0)
                    {
                        RemoveEastWestWalls(A, B);
                    }
                    else if (A.xDir != 0 && B.xDir != 0)
                    {
                        RemoveNorthSouthWalls(A, B);
                    }
                }
            }
        }
示例#2
0
        private void RemoveEastWestWalls(RMGBuilding A, RMGBuilding B)
        {
            bool isWestNeighbour = false;
            bool isEastNeighbour = false;

            for (int y = A.tly + 1; y < A.bry; y += 1)
            {
                RMTile west = GetTile(A.tlx - 1, y);
                RMTile east = GetTile(A.brx + 1, y);

                if (west != null)
                {
                    if (B.tiles.Contains(west))
                    {
                        isWestNeighbour = true;
                        break;
                    }
                }
                if (east != null)
                {
                    if (B.tiles.Contains(east))
                    {
                        isEastNeighbour = true;
                        break;
                    }
                }
            }

            if (isWestNeighbour || isEastNeighbour)
            {
                RMGBuilding removeWestWall = null;
                RMGBuilding removeEastWall = null;

                if (A.area < B.area)
                {
                    if (isWestNeighbour)
                    {
                        removeWestWall = A;
                    }
                    else
                    {
                        removeEastWall = A;
                    }
                }
                else if (A.area >= B.area)
                {
                    if (isWestNeighbour)
                    {
                        removeEastWall = B;
                    }
                    else
                    {
                        removeWestWall = B;
                    }
                }
                List <RMTile> toRemove = new List <RMTile>();
                if (removeWestWall != null)
                {
                    for (int y = removeWestWall.tly + 1; y < removeWestWall.bry; y += 1)
                    {
                        RMTile t          = GetTile(removeWestWall.tlx, y);
                        int    countWalls = 0;
                        for (int xx = removeWestWall.tlx - 1; xx <= removeWestWall.tlx; xx += 1)
                        {
                            for (int yy = y - 1; yy <= y + 1; yy += 1)
                            {
                                if (xx == removeWestWall.tlx && yy == y)
                                {
                                    continue;
                                }
                                if (t.btype == BUILDING_TYPE.EDGE)
                                {
                                    countWalls += 1;
                                }
                            }
                        }

                        if (countWalls >= 5)
                        {
                            toRemove.Add(t);
                        }
                    }
                }

                if (removeEastWall != null)
                {
                    for (int y = removeEastWall.tly + 1; y < removeEastWall.bry; y += 1)
                    {
                        RMTile t          = GetTile(removeEastWall.brx, y);
                        int    countWalls = 0;
                        for (int xx = removeEastWall.tlx; xx <= removeEastWall.tlx + 1; xx += 1)
                        {
                            for (int yy = y - 1; yy <= y + 1; yy += 1)
                            {
                                if (xx == removeEastWall.tlx && yy == y)
                                {
                                    continue;
                                }
                                if (t.btype == BUILDING_TYPE.EDGE)
                                {
                                    countWalls += 1;
                                }
                            }
                        }

                        if (countWalls >= 5)
                        {
                            toRemove.Add(t);
                        }
                    }
                }

                foreach (var t in toRemove)
                {
                    t.btype = BUILDING_TYPE.INSIDE;
                }
            }
        }
示例#3
0
        private void RemoveNorthSouthWalls(RMGBuilding A, RMGBuilding B)
        {
            bool isNorthNeighbour = false;
            bool isSouthNeighbour = false;

            for (int x = A.tlx + 1; x < A.brx; x += 1)
            {
                RMTile north = GetTile(x, A.tly - 1);
                RMTile east  = GetTile(x, A.bry + 1);

                if (north != null)
                {
                    if (B.tiles.Contains(north))
                    {
                        isNorthNeighbour = true;
                        break;
                    }
                }
                if (east != null)
                {
                    if (B.tiles.Contains(east))
                    {
                        isSouthNeighbour = true;
                        break;
                    }
                }
            }

            if (isNorthNeighbour || isSouthNeighbour)
            {
                RMGBuilding removeNorthWall = null;
                RMGBuilding removeSouthWall = null;

                if (A.area < B.area)
                {
                    if (isNorthNeighbour)
                    {
                        removeNorthWall = A;
                    }
                    else
                    {
                        removeSouthWall = A;
                    }
                }
                else if (A.area >= B.area)
                {
                    if (isNorthNeighbour)
                    {
                        removeSouthWall = B;
                    }
                    else
                    {
                        removeNorthWall = B;
                    }
                }

                if (removeNorthWall != null)
                {
                    for (int x = removeNorthWall.tlx + 1; x < removeNorthWall.brx; x += 1)
                    {
                        RMTile t = GetTile(x, removeNorthWall.tly);
                        t.btype = BUILDING_TYPE.INSIDE;
                    }
                }

                if (removeSouthWall != null)
                {
                    for (int x = removeSouthWall.tlx + 1; x < removeSouthWall.brx; x += 1)
                    {
                        RMTile t = GetTile(x, removeSouthWall.bry);
                        t.btype = BUILDING_TYPE.INSIDE;
                    }
                }
            }
        }