bool CheckPrecondition(eFindMode mode, TileCell nextTileCell, TileCell targetTileCell) { //if ((null != nextTileCell) && (true == nextTileCell.IsPathfindable() && false == nextTileCell.IsVisit() || // (nextTileCell.GetTileX() == _targetTileCell.GetTileX() && nextTileCell.GetTileY() == _targetTileCell.GetTileY()))) // return true; bool condition = false; if (false == nextTileCell.IsVisit()) { condition = true; } if (eFindMode.VIEW_MOVERANGE == mode || eFindMode.FIND_PATH == mode) { if (condition) { condition = nextTileCell.CanMove(); } } if (eMapType.DUNGEON == GameManager.Instance.GetMapType()) { return(condition); } else if (eMapType.TOWN == GameManager.Instance.GetMapType()) { //해당 타일이 목표 타일 if (nextTileCell.GetTileX() == targetTileCell.GetTileX() && nextTileCell.GetTileY() == targetTileCell.GetTileY()) { condition = true; } } return(condition); }
void FindPath() { TileSystem tileSystem = TileSystem.Instance; while (0 != _pathfindingQueue.Count) { //제일 앞 타일을 하나 꺼낸다. sPathCommand command = _pathfindingQueue[0]; _pathfindingQueue.RemoveAt(0); //방문한 타일인가? if (false == command.tileCell.IsVisit()) { command.tileCell.Visit(); if (_targetTileCell.GetTilePosition().Equals(command.tileCell.GetTilePosition())) { _reverseTileCell = _targetTileCell; return; } for (int direction = 0; direction < (int)eDirection.MAX; direction++) { sTilePosition nextTilePos = new sTilePosition(command.tileCell.GetTileX(), command.tileCell.GetTileY()); TileHelper.GetNextTilePosByDirection((eDirection)direction, ref nextTilePos); TileCell nextTileCell = tileSystem.GetTileCell(nextTilePos); if (((true == tileSystem.CanMoveTileCell(nextTilePos.tileX, nextTilePos.tileY)) && false == nextTileCell.IsVisit()) || (nextTilePos.tileX == _targetTileCell.GetTileX() && nextTilePos.tileY == _targetTileCell.GetTileY())) { float newDistanceFromStart = command.tileCell.GetDistanceFromStart() + command.tileCell.GetDistanceWeight(); float newHeuristic = CalcAstarHeuristic(newDistanceFromStart, nextTileCell, _targetTileCell); if (null == nextTileCell.GetPrevCell()) { nextTileCell.SetDistanceFromStart(newDistanceFromStart); nextTileCell.SetPrevCell(command.tileCell); //이전 타일 기억 sPathCommand newCommand = new sPathCommand(); newCommand.heuristic = newHeuristic; newCommand.tileCell = nextTileCell; PushCommand(newCommand); } } } } } }