コード例 #1
0
    public void RemakePath(RoomConnectorCreating checkedNodes)      //going backwards and getting the path that led to this node, then on that node im getting the path that led to that and going further back
    {
        if (checkedNodes == _StartRoom [0])
        {
            return;
        }
        else
        {
            _ThePath [_TheSize - (++_RemakeIndex)] = checkedNodes;
        }

        if (checkedNodes.RoomNode.GetParent() == null)
        {
            return;
        }
        else
        {
            _CurrentRoom = checkedNodes.RoomNode.GetParent().GetRooms();
        }

        while (true)
        {
            if (_CurrentRoom.RoomNode.GetParent() != null)
            {
                _ThePath [_TheSize - (++_RemakeIndex)] = _CurrentRoom;
                _CurrentRoom = _CurrentRoom.RoomNode.GetParent().GetRooms();
            }
            else
            {
                if (_StartRoom.Count != 1)
                {
                    _ThePath [_TheSize - (++_RemakeIndex)] = _CurrentRoom;
                }
                return;
            }
        }
    }
コード例 #2
0
    void PathCheck()     //Checking If Something Needs Updating And Setting NodePath
    {
        if (_MyObject.GotPushed == true)
        {
            if (_TargetNeighbourGroups != _MyObject._TheTarget.NeighbourGroups)              //If Target Changed "Room" Do A Room Path Search
            {
                _TargetNeighbourGroups = _MyObject._TheTarget.NeighbourGroups;
                _ObjectNeighbourGroups = _MyObject._TheObject.NeighbourGroups;
                _MyObject._CreateThePath.SetEndRoom(_TargetNeighbourGroups);
                _MyObject._CreateThePath.CreatePath();
                _Roomindex    = _Roomsindex [0];             //Index Refrence For Where I'm Starting From In The List
                _PreviourRoom = _CurrentRoom;
                _CurrentRoom  = _TheRoomPath [_Roomindex];

                NodePathCheck();
            }
            else if (_ObjectNeighbourGroups != _MyObject._TheObject.NeighbourGroups)                //If I Changed "Room" Do A Room Path Search
            {
                _ObjectNeighbourGroups = _MyObject._TheObject.NeighbourGroups;
                _MyObject._CreateThePath.CreatePath();
                _Roomindex    = _Roomsindex [0];             //Index Refrence For Where I'm Starting From In The List
                _PreviourRoom = _CurrentRoom;
                _CurrentRoom  = _TheRoomPath [_Roomindex];

                NodePathCheck();
            }
            else
            {
                NodePathCheck();
            }
        }
        else
        {
            if (_TargetNeighbourGroups != _MyObject._TheTarget.NeighbourGroups)              //If Target Changed "Room" Do A Room Path Search
            {
                _TargetNeighbourGroups = _MyObject._TheTarget.NeighbourGroups;
                _ObjectNeighbourGroups = _MyObject._TheObject.NeighbourGroups;
                _MyObject._CreateThePath.SetEndRoom(_TargetNeighbourGroups);
                _MyObject._CreateThePath.CreatePath();
                _Roomindex = _Roomsindex [0];                //Index Refrence For Where I'm Starting From In The List

                NodePathCheck();
            }
            else if (_ObjectNeighbourGroups != _MyObject._TheObject.NeighbourGroups)                //If I Changed "Room" Do A Room Path Search
            {
                _ObjectNeighbourGroups = _MyObject._TheObject.NeighbourGroups;
                _MyObject._CreateThePath.CreatePath();
                _Roomindex = _Roomsindex [0];                //Index Refrence For Where I'm Starting From In The List

                NodePathCheck();
            }

            if (_Nodeindex >= _Nodesindex [0] + ReSearch)              //If The Object Have Walked For X Amount Of Nodes Start The Node A* Again
            {
                if (_Nodeindex < _TheNodePath.Length - 1)              //No Need To Check If Im At The End
                {
                    NodePathCheck();
                }
            }
        }
    }
コード例 #3
0
    public void AStartAlgorithm()       //A*.
    {
        _ListHoler = _StartRoom;

        #region PreSearch

        if (_ListHoler.Count == 1)          //if im standing on the roomconnector, then this is true (and if im inside a room with only 1 roomconnector)
        {
            _CurrentRoom = _ListHoler [0];
            _CurrentRoom.RoomNode.NodeSearchedThrough = true;
            _OpenList [_OpenListAtIndex++]            = _CurrentRoom; //adding the only roomconnector

            _ListHoler = _CurrentRoom.ConnectorHubOne.Connectors;     //one of the rooms connectorhubs connected to this roomconnector o_O
            if (_ListHoler != null)
            {
                for (int i = 0; i < _ListHoler.Count; i++)
                {
                    _ObjectHolder = _ListHoler [i];
                    if (_ObjectHolder.RoomNode.NodeSearchedThrough == false)
                    {
                        _ObjectHolder.RoomNode.SetParentAndEndRoom(_CurrentRoom.RoomNode, _EndNode [0]);
                        _ObjectHolder.GetLeftOrRight   = _CurrentRoom.ConnectorHubOne;         //this tells me that when im going through this room im going to search on the other side of the room (1 roomconnector have 2 sides)
                        _OpenList [_OpenListAtIndex++] = _ObjectHolder;                        //adding the roomconnector to an array
                    }
                }
            }

            _ListHoler = _CurrentRoom.ConnectorHubTwo.Connectors;
            if (_ListHoler != null)
            {
                for (int i = 0; i < _ListHoler.Count; i++)
                {
                    _ObjectHolder = _ListHoler [i];
                    if (_ObjectHolder.RoomNode.NodeSearchedThrough == false)
                    {
                        _ObjectHolder.RoomNode.SetParentAndEndRoom(_CurrentRoom.RoomNode, _EndNode [0]);
                        _ObjectHolder.GetLeftOrRight   = _CurrentRoom.ConnectorHubTwo;
                        _OpenList [_OpenListAtIndex++] = _ObjectHolder;
                    }
                }
            }
        }
        else            //if true then im inside a room which means that i must add all roomconnectors connected to this room

        {
            if (_ListHoler == _ListHoler [0].ConnectorHubOne.Connectors)
            {
                _ConnectorHub = _ListHoler [0].ConnectorHubOne;
                for (int i = 0; i < _ListHoler.Count; i++)
                {
                    _ListHoler [i].RoomNode.NodeSearchedThrough = true;
                    _ListHoler [i].GetLeftOrRight  = _ConnectorHub;
                    _OpenList [_OpenListAtIndex++] = _ListHoler [i];
                }
            }
            else
            {
                _ConnectorHub = _ListHoler [0].ConnectorHubTwo;
                for (int i = 0; i < _ListHoler.Count; i++)
                {
                    _ListHoler [i].RoomNode.NodeSearchedThrough = true;
                    _ListHoler [i].GetLeftOrRight  = _ConnectorHub;
                    _OpenList [_OpenListAtIndex++] = _ListHoler [i];
                }
            }
        }

        #endregion

        while (_OpenListAtIndex > 0)          //if the loop has itterated enough times to fill the array then stop

        {
            _LowerstFScore = 100000;

            for (int i = 0; i < _OpenListAtIndex; i++)              //searching through the array to find the room closest to the end
            {
                _ObjectHolder = _OpenList[i];
                if (_ObjectHolder.RoomNode.FCost < _LowerstFScore)                  //it was faster to make fcost public and just get the variable then go through a getmethod
                {
                    _CurrentRoom    = _ObjectHolder;
                    _RoomIndexSaved = i;
                    _LowerstFScore  = _ObjectHolder.RoomNode.FCost;
                }
            }

            _ClosedList [_ClosedListAtIndex++] = _CurrentRoom;                   //adding room to list
            _OpenList [_RoomIndexSaved]        = _OpenList [--_OpenListAtIndex]; //moving the last room in openlist to the index currentroom were at

            _ListHoler = _EndRoom;
            for (int i = 0; i < _ListHoler.Count; i++)              //checking if the room im in is connected to the end room
            {
                if (_CurrentRoom != _ListHoler [i])
                {
                }
                else
                {
                    RemakePath(_CurrentRoom);
                    return;
                }
            }

            if (_CurrentRoom.GetLeftOrRight != _CurrentRoom.ConnectorHubOne)              //checking which side of the pathconnector that have been searched, then go through its neighbours and see if something is closer to the target
            {
                _ListHoler = _CurrentRoom.ConnectorHubOne.Connectors;
                for (int i = 0; i < _ListHoler.Count; i++)
                {
                    _ObjectHolder = _ListHoler [i];
                    if (_ObjectHolder.RoomNode.NodeSearchedThrough != true)                      //if true then this object have been searched through , if not set info
                    {
                        _ObjectHolder.RoomNode.SetParentAndEndRoom(_CurrentRoom.RoomNode, _EndNode [0]);
                        _ObjectHolder.GetLeftOrRight   = _CurrentRoom.ConnectorHubOne;
                        _OpenList [_OpenListAtIndex++] = _ObjectHolder;
                    }
                    else if (_ObjectHolder.RoomNode.GCost > _CurrentRoom.RoomNode.GCost + _CurrentRoom.RoomNode.GetJustWorldSpaceDistance(_ObjectHolder.RoomNode))                         //checking if currentroom is closer to the objectholder then its parent is
                    {
                        _ObjectHolder.RoomNode.SetParentRoom(_CurrentRoom.RoomNode);
                    }
                }
            }
            else                //same logic just different side of the room
            {
                _ListHoler = _CurrentRoom.ConnectorHubTwo.Connectors;
                for (int i = 0; i < _ListHoler.Count; i++)
                {
                    _ObjectHolder = _ListHoler [i];
                    if (_ObjectHolder.RoomNode.NodeSearchedThrough != true)                      //if n dont have a parent and n isnt the starting node (starts must be there else it will cause an FATAL error ;-P, your warned :D)
                    {
                        _ObjectHolder.RoomNode.SetParentAndEndRoom(_CurrentRoom.RoomNode, _EndNode [0]);
                        _ObjectHolder.GetLeftOrRight   = _CurrentRoom.ConnectorHubTwo;
                        _OpenList [_OpenListAtIndex++] = _ObjectHolder;
                    }
                    else if (_ObjectHolder.RoomNode.GCost > _CurrentRoom.RoomNode.GCost + _CurrentRoom.RoomNode.GetJustWorldSpaceDistance(_ObjectHolder.RoomNode))
                    {
                        _ObjectHolder.RoomNode.SetParentRoom(_CurrentRoom.RoomNode);
                    }
                }
            }
        }
    }
コード例 #4
0
    List <Nodes> _NeighboursRooms = new List <Nodes>();  //neighbours for the roompath  (could also be public)


    public void SetRooms(RoomConnectorCreating room)
    {
        _MyRooms = room;
    }