Beispiel #1
0
void CStageDynamic::Astar_start( const D3DXVECTOR3& vDestPos, const D3DXVECTOR3& vSourPos )
{
	int nStartId = GetTileIndex(vDestPos);

	if (nStartId < 0)
	{
		return;
	}

	int nGoalIdx = GetTileIndex(vSourPos);

	if (nGoalIdx < 0)
	{
		return;
	}
	
	GET_SINGLE(CAstar)->AstarStart(nStartId,nGoalIdx);
}
Beispiel #2
0
ATile* ATileManager::GetTileAtLocation(FVector Location)
{
  ATileManager::TileIndexPair iPair = GetTileIndex(Location);
  // If out of bounds return null
  if (iPair.indexX == -1 || iPair.indexY == -1)
    return nullptr;

  int32 tileIndex = iPair.indexY * TilesWide + iPair.indexX;
  if (tileIndex > Tiles.Num() || tileIndex < 0)
    return nullptr;
  
  return Tiles[tileIndex];
}
Beispiel #3
0
//현재 Path.front에 저장되어 있는 타일 인덱스로 이동한다. 만약 Path가 비어있으면 false를 반환한다.
bool Unit::MoveToPathFront(int CurrentPacket) {
    //해당 유닛의 패스를 가져온다.
    auto& Path = GetPathPlanner()->GetPath();
    auto pMap = m_pGameWorld->GetMap();
    auto& Graph = pMap->GetNavGraph();

    LogMgr->Log("Path Size : %d",Path.size());

    if(Path.empty()) {
        LogMgr->Log("취소");
        m_pFSM->ChangeState(State_Idle::Instance());
        return false;
    }

    //움직일 다음 칸 인덱스를 가져온다.
    int MoveIndex = Path.front();
    Path.pop_front();

    //MoveIndex의 타일이 비어있는지 확인한다.
    //비어 있지 않으면 새로 AStar알고리즘을 실행하여 움직인다.
    //TODO : 나중에 최적화 할 것
    if(!Graph.GetNode(MoveIndex).IsEmpty()) {
        m_pPathPlanner->CreatePathToPosition(m_pPathPlanner->GetDestination());

        if(Path.empty()) {
            GetFSM()->ChangeState(State_Idle::Instance());
            return false;
        }

        MoveIndex = Path.front();
        Path.pop_front();
    }

    //이동시킨다.
    int PrevIndex = GetTileIndex();
    SetTileIndex(MoveIndex);
    Vec2 MyPosition = m_pGameWorld->GetMap()->GetNavGraph().GetNode(PrevIndex).getPosition();
    Vec2 PathFrontPosition = m_pGameWorld->GetMap()->GetNavGraph().GetNode(MoveIndex).getPosition();

    //Heading 설정
    SetHeading(PathFrontPosition - getPosition());

    //Move 액션 생성 과정 : 타일 간의 거리와 유닛의 이동속도를 고려하여 만든다.

    //다음 AutoTask를 먼저 등록한다.
    //본래 속도보다 TweakPacket 정도 더 빠르게 실행시킨다.

    float Distance = Vec2Distance(PathFrontPosition, MyPosition) / (DIVIDE_NODE ? 32.0f : 64.0f);
    float Duration = Distance / GetSpeed();

    int TweakPacket = 1;
    int NextPacket = (int)(NETWORK_FPS * Duration) - TweakPacket;
    printf("NextPacket : %d\n",NextPacket);
    //만일 NextPacket이 0보다 작거나 같다면 다음 타일을 가져온다.
    if(NextPacket <= 0) {
        printf("AAaaaaaaaaaaaa\n");
        return MoveToPathFront(CurrentPacket);
    }

    NetMgr->PushAutoTask(new AutoTaskMove(CurrentPacket + NextPacket, m_iID));
    SetAutoTaskPacket(CurrentPacket+NextPacket);

    auto pMove = MoveTo::create(Duration,PathFrontPosition);

    //액션을 실행한다.
    stopAllActions();
    runAction(pMove);

    return true;
}
Beispiel #4
0
int CMap::GetTileIndexAt(int xPos, int yPos)
{
	int row = yPos/mTileHeight;
	int col = xPos/mTileWidth;	
	return GetTileIndex(row, col);
}