コード例 #1
0
    //check the closed list to see if the path points are within the list
    bool CheckClosedList(STR_ID currentNodeID, STR_ID NeighbourID)
    {
        bool exists = false;

        for (int i = 0; i < closed.Count; i++)
        {
            if (closed[i].ReturningParentNode() != null)
            {
                STR_ID currentPointID   = closed[i].ReturningMainNode().returnID();
                STR_ID neighbourPointID = closed[i].ReturningParentNode().returnID();

                if (currentNodeID.Compare(currentPointID) && NeighbourID.Compare(neighbourPointID))
                {
                    exists = true;
                }

                if (currentNodeID.Compare(neighbourPointID) && NeighbourID.Compare(currentPointID))
                {
                    exists = true;
                }
            }
        }

        return(exists);
    }
コード例 #2
0
    public bool Compare(STR_ID nodeID)
    {
        bool Comparison = false;

        if (nodeID.body == body)
        {
            Comparison = true;
        }

        return(Comparison);
    }
コード例 #3
0
    //will add any potential neighbouring nodes to the potential path list if they haven't already, will check to see if the path has reached the goal
    void CalculateNeighbours()
    {
        List <STR_ID> neighbours = currentNode.ReturnNeighbours();

        for (int i = 0; i < neighbours.Count; i++)
        {
            SCR_NodeClass neighbourNode      = nodeManager.ReturnNode(neighbours[i]);
            STR_ID        currentNeighbourID = neighbourNode.returnID();
            STR_ID        currentNodeID      = currentNode.returnID();
            if (currentNodeID.Compare(currentNeighbourID) == false)
            {
                if (listOfNodes.Contains(neighbourNode))
                {
                    if (neighbourNode.ReturnRoomType() != RoomType.BlockedRoute)
                    {
                        var current = new CalculatePath(neighbourNode, currentNode);

                        if (neighbourNode.ReturnRoomType() == RoomType.InitialFightRoom || neighbourNode.ReturnRoomType() == RoomType.ChallangeRoom)
                        {
                            if (!finalPathPoints.Contains(neighbourNode))
                            {
                                closed.Add(current);
                            }
                        }



                        if ((!open.Contains(current)) && (!closed.Contains(current)))
                        {
                            if (CheckOpenList(currentNodeID, currentNeighbourID) == false && CheckClosedList(currentNodeID, currentNeighbourID) == false)
                            {
                                open.Add(current);
                            }
                        }
                    }
                }
            }
        }

        closed.Add(open[currentPos]);

        Vector3 endPos          = goal.returnID().body.transform.position;
        STR_ID  currentID       = currentNode.returnID();
        Vector3 currentPosition = currentNode.returnID().body.transform.position;

        if (currentNode == goal)
        {
            pathfound = true;
            pathEnd   = closed.Count - 1;
        }
        open.Remove(open[currentPos]);
    }
コード例 #4
0
    //return a node within the map structure, requires a node ID
    public SCR_NodeClass ReturnNode(STR_ID nodeID)
    {
        SCR_NodeClass node = new SCR_NodeClass();

        for (int i = 0; i < nodes.Count; i++)
        {
            if (nodeID.Compare(nodes[i].returnID()))
            {
                node = nodes[i];
            }
        }
        return(node);
    }
コード例 #5
0
    //add a neighbouring node to the current node, requires the neighbours ID
    public void AddNeighbour(STR_ID neighbourID)
    {
        bool InList = false;

        for (int i = 0; i < nodeNeigbours.Count; i++)
        {
            if (neighbourID.Compare(nodeNeigbours[i]))
            {
                InList = true;
            }
        }

        if (InList == false)
        {
            nodeNeigbours.Add(neighbourID);
        }
    }
コード例 #6
0
    //remove a neighbour from the current node, requires the neighbours ID
    public void RemoveNeighbour(STR_ID neighbourID)
    {
        bool InList   = false;
        int  position = 0;

        for (int i = 0; i < nodeNeigbours.Count; i++)
        {
            if (neighbourID.Compare(nodeNeigbours[i]))
            {
                InList   = true;
                position = i;
            }
        }

        if (InList == true)
        {
            nodeNeigbours.RemoveAt(position);
        }
    }
コード例 #7
0
    //Will select the next point to review within the map
    void CalculatePoint()
    {
        float   Fcost    = 10000000.0f;
        Vector3 startPos = start.returnID().body.transform.position;
        Vector3 endPos   = goal.returnID().body.transform.position;

        for (int i = 0; i < open.Count; i++)
        {
            STR_ID currentID = open[i].ReturningMainNode().returnID();

            var CurrentFCost = CalculateCost(currentID.body.transform.position, startPos) + CalculateCost(currentID.body.transform.position, endPos);
            if (CurrentFCost < Fcost)
            {
                Fcost       = CurrentFCost;
                currentNode = open[i].ReturningMainNode();
                currentPos  = i;
            }
        }
    }
コード例 #8
0
    //remove a node from the list, requires a node ID
    public void RemoveNode(STR_ID nodeID)
    {
        for (int i = 0; i < nodes.Count; i++)
        {
            SCR_NodeClass currentNode       = nodes[i];
            List <STR_ID> currentNeighbours = currentNode.ReturnNeighbours();

            if (nodeID.Compare(currentNode.returnID()))
            {
                nodes.RemoveAt(i);
            }

            for (int j = 0; j < currentNeighbours.Count; j++)
            {
                if (nodeID.Compare(currentNeighbours[j]))
                {
                    nodes[i].RemoveNeighbour(j);
                }
            }
        }
    }
コード例 #9
0
 //set a nodes ID
 public void SetID(STR_ID newID)
 {
     nodeID = newID;
 }
コード例 #10
0
 //set up class
 public SCR_NodeClass()
 {
     nodeID        = new STR_ID();
     nodeNeigbours = new List <STR_ID>();
     roomType      = RoomType.SecondaryPathway;
 }
コード例 #11
0
 public SCR_NodeIDClass()
 {
     currentNodeID = new STR_ID();
 }