Esempio n. 1
0
        public void RemoveNode(int NodeIndex)
        {
            if (Graph == null)
            {
                return;
            }

            Graph.RemoveNode(NodeIndex);
        }
Esempio n. 2
0
        //--------------------------- UpdateGraphFromBrush ----------------------------
        //
        //  given a brush and a node index, this method updates the graph appropriately
        //  (by removing/adding nodes or changing the costs of the node's edges)
        //-----------------------------------------------------------------------------
        public void UpdateGraphFromBrush(int brush, int CellIndex)
        {
            //set the terrain type in the terrain index
            m_TerrainType[CellIndex] = brush;

            //if current brush is an obstacle then this node must be removed
            //from the graph
            if (brush == (int)brush_type.obstacle)
            {
                m_Graph.RemoveNode(CellIndex);
            }

            else
            {
                //make the node active again if it is currently inactive
                if (!m_Graph.isNodePresent(CellIndex))
                {
                    int y = CellIndex / m_iCellsY;
                    int x = CellIndex - (y * m_iCellsY);

                    m_Graph.AddNode(new NavGraphNode(CellIndex, new Vector2D(x * m_dCellWidth + m_dCellWidth / 2.0,
                                                                             y * m_dCellHeight + m_dCellHeight / 2.0)));

                    SparseGraph.Helper_AddAllNeighboursToGridNode(m_Graph, y, x, m_iCellsX, m_iCellsY);
                }

                //set the edge costs in the graph
                SparseGraph.Helper_WeightNavGraphNodeEdges(m_Graph, CellIndex, GetTerrainCost((brush_type)brush));
            }
        }