コード例 #1
0
    float CalcHeuristic(eFindMethod eMethod, float distanceFromStart, TileCell tileCell, TileCell nextTileCell, TileCell targetTileCell)
    {
        switch (eMethod)
        {
        case eFindMethod.DISTANCE:
            return(distanceFromStart);

        case eFindMethod.SIMPLE:
            return(CalcSimpleHeuristic(tileCell, nextTileCell, targetTileCell));

        case eFindMethod.COMPLEX:
            return(CalcComplexHeuristic(nextTileCell, targetTileCell));

        case eFindMethod.ASTAR:
            return(CalcAStarHeuristic(distanceFromStart, nextTileCell, targetTileCell));

        default:
            return(0);
        }
    }
コード例 #2
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);
                            }
                        }
                    }
                }
            }
        }
    }