Ejemplo n.º 1
0
    override public void Start()
    {
        base.Start();
        _eMoveState = eMoveState.START;
        TileCell pathTileCell = _character.GetTargetTileCell();

        while (null != pathTileCell.GetPrevTileCell(_character))
        {
            _pathfindingStack.Push(pathTileCell);

            pathTileCell = pathTileCell.GetPrevTileCell(_character);
        }
        _characterVector = _character.GetPosition();
        Debug.Log(_character + " : move");
    }
Ejemplo n.º 2
0
    protected void SettingMovePossibleTiles()
    {
        TileMap map = GameManager.Instance.GetMap();

        map.ResetVisit(_character);

        TileCell startTileCell = map.GetTileCell(_character.GetTileX(), _character.GetTileY());

        startTileCell.SetPrevTileCell(_character, null);
        sTileHeuristicInfo startCmd;

        startCmd.tileCell  = startTileCell;
        startCmd.heuristic = 0.0f;
        _tileInfoQueue.Add(startCmd);

        while (0 != _tileInfoQueue.Count)
        {
            sTileHeuristicInfo command = _tileInfoQueue[0];
            _tileInfoQueue.RemoveAt(0);
            //가져온 커맨드의 현재 타일셀 방문 표시
            if (false == command.tileCell.IsVisited(_character))
            {
                if (_character.GetMoveRange() == command.tileCell.GetDistanceFromStart(_character))
                {
                    _tileInfoQueue.Clear();
                    return;
                }
                command.tileCell.SetVisit(_character, true);
                _movePossibleTiles.Add(command.tileCell);

                //4방향 next타일들 검사
                for (int direction = (int)eMoveDirection.LEFT; direction < (int)eMoveDirection.DOWN + 1; direction++)
                {
                    sPosition curPosition;
                    curPosition.x = command.tileCell.GetTileX();
                    curPosition.y = command.tileCell.GetTileY();
                    sPosition nextPosition = _character.GetPositionByDirection(curPosition, direction);

                    TileCell nextTileCell = map.GetTileCell(nextPosition.x, nextPosition.y);
                    // nextTileCell 방문 안했고, 움직일수 있는 타일일때
                    if (null != nextTileCell && true == nextTileCell.IsPathfindable() && false == nextTileCell.IsVisited(_character))
                    {
                        float distanceFromStart = command.tileCell.GetDistanceFromStart(_character) + nextTileCell.GetDistanceFromWeight();
                        float heuristic         = distanceFromStart;

                        if (null == nextTileCell.GetPrevTileCell(_character) || distanceFromStart < nextTileCell.GetDistanceFromStart(_character))
                        {
                            nextTileCell.SetDistanceFromStart(_character, distanceFromStart);
                            nextTileCell.SetPrevTileCell(_character, command.tileCell);

                            sTileHeuristicInfo nextCommand;
                            nextCommand.tileCell  = nextTileCell;
                            nextCommand.heuristic = heuristic;
                            PushSortmoveRangeQueue(nextCommand);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 3
0
 public void BuildPath()
 {
     //경로를 도출
     while (null != _reverseTileCell)
     {
         _character.PushPathTileCell(_reverseTileCell);
         _reverseTileCell = _reverseTileCell.GetPrevTileCell();
     }
 }
Ejemplo n.º 4
0
    void DrawMovePath(TileCell targetTileCell)
    {
        for (int i = 0; i < _movePossibleTiles.Count; i++)
        {
            _movePossibleTiles[i].Draw(Color.blue);
        }
        TileCell pathTileCell = targetTileCell;

        while (null != pathTileCell)
        {
            pathTileCell.Draw(Color.red);
            pathTileCell = pathTileCell.GetPrevTileCell(_character);
        }
    }
Ejemplo n.º 5
0
    virtual public void UpdateBuild()
    {
        if (_reverseTileCell != null)
        {
            _character.PushPathFindingTileCell(_reverseTileCell);
            _reverseTileCell = _reverseTileCell.GetPrevTileCell();
        }

        else
        {
            //_nextState = eStateType.MOVE;
            _nextState = eStateType.IDLE;
        }
    }
    public override void Update()
    {
        if (reverseTileCell != null)
        {
            _character.PushPathFindingTileCell(reverseTileCell);
            //reverseTileCell.SetPathFindingTestMark();
            reverseTileCell = reverseTileCell.GetPrevTileCell();
            //_nextState = eStateType.BATTLE;
        }

        else
        {
            _nextState = eStateType.PATHFINDINGTESTMOVE;
        }
        //_nextState = eStateType.IDLE;
    }
Ejemplo n.º 7
0
    public void FindPath(eFindMode mode, eFindMethod method)
    {
        bool isViewRange = (eFindMode.VIEW_MOVERANGE == mode || eFindMode.VIEW_ATTACKRANGE == mode);

        while (0 != _pathfindingQueue.Count)
        {
            sPathCommand command = _pathfindingQueue[0];
            _pathfindingQueue.RemoveAt(0);

            if (false == command.tileCell.IsVisit())
            {
                command.tileCell.Visit();

                //FIND TARGET
                if (eFindMode.FIND_PATH == mode)
                {
                    if ((_targetTileCell.GetTileX() == command.tileCell.GetTileX()) &&
                        (_targetTileCell.GetTileY() == command.tileCell.GetTileY()))
                    {
                        _reverseTileCell = _targetTileCell;
                        return;
                    }
                }


                for (eMoveDirection direction = 0; direction <= eMoveDirection.DOWN; direction++)
                {
                    sPosition curPosition;
                    curPosition.x = command.tileCell.GetTileX();
                    curPosition.y = command.tileCell.GetTileY();
                    sPosition nextPosition = GlobalUtility.GetPositionByDirection(curPosition, direction);

                    TileMap  map          = GameManager.Instance.GetMap();
                    TileCell nextTileCell = map.GetTileCell(nextPosition.x, nextPosition.y);

                    if (CheckPrecondition(mode, nextTileCell, _targetTileCell))
                    {
                        float distanceFromStart = command.tileCell.GetDistanceFromStart()
                                                  + command.tileCell.GetDistanceWeight();
                        float heuristic = CalcHeuristic(method, distanceFromStart,
                                                        command.tileCell, nextTileCell, _targetTileCell);

                        if (isViewRange && (_range < distanceFromStart))
                        {
                            return;
                        }

                        if (null == nextTileCell.GetPrevTileCell())
                        {
                            nextTileCell.SetDistanceFromStart(distanceFromStart);
                            nextTileCell.SetPrevTileCell(command.tileCell);

                            sPathCommand newCommand;
                            newCommand.tileCell  = nextTileCell;
                            newCommand.heuristic = heuristic;
                            PushCommand(newCommand);

                            //검색범위를 그려준다.
                            if (isViewRange)
                            {
                                DrawSearchTile(nextTileCell);
                            }
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 8
0
    public void UpdatePathFinding()
    {
        if (_pathFindingQueue.Count != 0)
        {
            sPathCommand command = PopCommand();

            if (command.tileCell.Marked() == false)
            {
                command.tileCell.Mark();
                if (command.tileCell.CanMove() == true)
                {
                    command.tileCell.SetPathFindingTestMark(Color.blue);
                }

                else if (command.tileCell.CanMove() == false)
                {
                    command.tileCell.SetPathFindingTestMark(Color.red);
                }

                if (command.tileCell.GetDistanceFromStart() > 5)
                {
                    _reverseTileCell = command.tileCell;
                    _updateState     = eUpdateState.BUILD;
                    return;
                }

                // 목표 도달?
                if (command.tileCell.GetTileX() == _targetTileCell.GetTileX() && command.tileCell.GetTileY() == _targetTileCell.GetTileY())
                {
                    _updateState     = eUpdateState.BUILD;
                    _reverseTileCell = _targetTileCell;
                    return;
                }
                // 주변 타일 검사
                for (int direction = (int)eMoveDirection.UP; direction < (int)eMoveDirection.NONE; direction++)
                {
                    sPosition currentTilePosition;
                    currentTilePosition.x = command.tileCell.GetTileX();
                    currentTilePosition.y = command.tileCell.GetTileY();

                    sPosition nextTilePos = GetPositionByDirection(currentTilePosition, (eMoveDirection)direction);

                    TileCell nextTileCell = GameManager.Instance.GetMap().GetTileCell(nextTilePos.x, nextTilePos.y);

                    //nextTileCell.SetPathFindingTestMark(Color.red);


                    // 검사 한타일인지 && 이동 가능한 타일 인지 && 갈수 없는 노드의 타입이 혹시 몬스터? -> 리팩토링하고싶다ㅏㅏ
                    if ((nextTileCell.IsPathFindable() == true && nextTileCell.Marked() == false))
                    {
                        float distanceFromStart = command.tileCell.GetDistanceFromStart() + command.tileCell.GetDistanceWeight() + 1;
                        //float heuristic = CalcAStarHeuristic(distanceFromStart, nextTileCell, _targetTileCell);
                        float heuristic = 0;

                        switch (_character.GetPathFindingType())
                        {
                        case ePathFindingType.DISTANCE:
                            heuristic = distanceFromStart;
                            break;

                        case ePathFindingType.SIMPLE:
                            heuristic = CalcSimpleHeuristic(command.tileCell, nextTileCell, _targetTileCell);
                            break;

                        case ePathFindingType.COMPLEX:
                            heuristic = CalcComplexHeuristic(nextTileCell, _targetTileCell);
                            break;

                        case ePathFindingType.ASTAR:
                            heuristic = CalcAStarHeuristic(distanceFromStart, nextTileCell, _targetTileCell);
                            break;
                        }

                        if (nextTileCell.GetPrevTileCell() == null)
                        {
                            nextTileCell.SetDistanceFromStart(distanceFromStart);
                            nextTileCell.SetPrevTileCell(command.tileCell);

                            sPathCommand newCommand;
                            newCommand.heuristic = heuristic;
                            newCommand.tileCell  = nextTileCell;
                            PushCommand(newCommand);
                        }
                    }
                }
            }
        }
    }