Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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();
        }