예제 #1
0
 public Connection(Cell innerFrom, Cell innerTo, OuterGridCell outerFrom, OuterGridCell outerTo)
 {
     InnerFrom = innerFrom;
     InnerTo   = innerTo;
     OuterFrom = outerFrom;
     OuterTo   = outerTo;
 }
예제 #2
0
 public void AddOuterCell(OuterGridCell cell, ICollection <OuterGridCell> list)
 {
     if (cell != null)
     {
         list.Add(cell);
     }
 }
예제 #3
0
        private bool CanConnectDiagonally(OuterGridCell nw, OuterGridCell ne, OuterGridCell sw, OuterGridCell se)
        {
            if (nw == null || ne == null || sw == null || se == null)
            {
                return(false);
            }

            return(nw.GetCorner(Dir.NW).Passable&&
                   ne.GetCorner(Dir.NE).Passable&&
                   sw.GetCorner(Dir.SW).Passable&&
                   se.GetCorner(Dir.SE).Passable);
        }
예제 #4
0
        public void UpdateGridConnectionsForNeighbours(OuterGridCell current)
        {
            Point cellIndex = OuterCellIndexAt(current.Mid);

            for (int col = cellIndex.Col() - 1; col <= cellIndex.Col() + 1; col++)
            {
                for (int row = cellIndex.Row() - 1; row <= cellIndex.Row() + 1; row++)
                {
                    CalculateGridConnectionsForCell(this[col, row], col, row);
                }
            }
        }
예제 #5
0
        public void CalculateGridConnectionsForCell(OuterGridCell current, int col, int row)
        {
            if (current == null)
            {
                return;
            }

            // Clear connections to prevent duplicates.
            current.Connections = new List <Connection>();

            // Orthogonal neighbours.
            OuterGridCell north = this[col, row - 1];
            OuterGridCell south = this[col, row + 1];
            OuterGridCell east  = this[col + 1, row];
            OuterGridCell west  = this[col - 1, row];

            // Diagonal neighbours.
            OuterGridCell northWest = this[col - 1, row - 1];
            OuterGridCell northEast = this[col + 1, row - 1];
            OuterGridCell southWest = this[col - 1, row + 1];
            OuterGridCell southEast = this[col + 1, row + 1];

            // North -> From[Top] To[Bot]
            // South -> From[Bot] To[Top]
            // East -> From[Right] To[Left]
            // West -> From[Left] To[Right]

            // Calculate orthogonal edge connections
            if (north != null)
            {
                current.Connections.AddRange(CalculateEdgeConnections(this[col, row].GetEdge(Dir.N), north.GetEdge(Dir.S), current, north));
            }
            if (south != null)
            {
                current.Connections.AddRange(CalculateEdgeConnections(this[col, row].GetEdge(Dir.S), south.GetEdge(Dir.N), current, south));
            }
            if (east != null)
            {
                current.Connections.AddRange(CalculateEdgeConnections(this[col, row].GetEdge(Dir.E), east.GetEdge(Dir.W), current, east));
            }
            if (west != null)
            {
                current.Connections.AddRange(CalculateEdgeConnections(this[col, row].GetEdge(Dir.W), west.GetEdge(Dir.E), current, west));
            }

            // Calculate diagonal edge connections
            if (CanConnectDiagonally(current, west, north, northWest)) // North West
            {
                current.Connections.Add(new Connection(current.GetCorner(Dir.NW), northWest.GetCorner(Dir.SE), current, northWest));
            }
            if (CanConnectDiagonally(east, current, northEast, north)) // North East
            {
                current.Connections.Add(new Connection(current.GetCorner(Dir.NE), northEast.GetCorner(Dir.SW), current, northEast));
            }
            if (CanConnectDiagonally(south, southWest, current, west)) // South West
            {
                current.Connections.Add(new Connection(current.GetCorner(Dir.SW), southWest.GetCorner(Dir.NE), current, southWest));
            }
            if (CanConnectDiagonally(southEast, south, east, current)) // South East
            {
                current.Connections.Add(new Connection(current.GetCorner(Dir.SE), southEast.GetCorner(Dir.NW), current, southEast));
            }

            // Calculate internal edge connections
            current.CalculateInternalConnections();
        }
예제 #6
0
        public List <Connection> CalculateEdgeConnections(List <Cell> fromCells, List <Cell> toCells, OuterGridCell outerFrom, OuterGridCell outerTo)
        {
            var connections = new List <Connection>();

            for (int i = 0; i < scale; i++)
            {
                if (fromCells[i].Passable && toCells[i].Passable)
                {
                    connections.Add(new Connection(fromCells[i], toCells[i], outerFrom, outerTo));
                }
            }

            return(connections);
        }