Example #1
0
        protected void RebuildEdges(Tile t)
        {
            // Firstly create the edges from the tile to neighbouring tiles
            PathfindingNode <Tile>         n     = Nodes[t];
            List <PathfindingEdge <Tile> > edges = new List <PathfindingEdge <Tile> >();

            Tile[] neighbours = t.GetNeighbours(false);

            for (int i = 0; i < neighbours.Length; i++)
            {
                if (neighbours[i] != null && neighbours[i].GetMovementCost() > 0 && IsClippingCorner(t, neighbours[i]) == false)
                {
                    PathfindingEdge <Tile> e = new PathfindingEdge <Tile>();
                    e.Cost = neighbours[i].GetMovementCost();
                    Nodes.TryGetValue(neighbours[i], out e.PathNode);
                    if (e.PathNode != null)
                    {
                        edges.Add(e);
                    }
                }
            }

            n.Edges = edges;

            Tile north = t.GetNeighbour(Compass.N);

            if (north != null)
            {
                AddEdgeBetween(north, t);
            }

            Tile east = t.GetNeighbour(Compass.E);

            if (east != null)
            {
                AddEdgeBetween(east, t);
            }

            Tile south = t.GetNeighbour(Compass.S);

            if (south != null)
            {
                AddEdgeBetween(south, t);
            }

            Tile west = t.GetNeighbour(Compass.W);

            if (west != null)
            {
                AddEdgeBetween(west, t);
            }
        }
Example #2
0
        private void AddEdgeBetween(Tile tileFrom, Tile tileTo)
        {
            PathfindingNode <Tile> tileFromNode;

            Nodes.TryGetValue(tileFrom, out tileFromNode);
            PathfindingNode <Tile> tileToNode;

            Nodes.TryGetValue(tileTo, out tileToNode);

            if (tileFromNode == null || tileToNode == null)
            {
                return;
            }

            PathfindingEdge <Tile> e = new PathfindingEdge <Tile>();

            e.Cost     = tileTo.GetMovementCost();
            e.PathNode = tileToNode;
            tileFromNode.Edges.addIfNotPresent(e);
        }