Ejemplo n.º 1
0
void CPathFinding::ContinuePath()
{
	if (m_openList.empty())
	{
		return;
	}

	CSearchCell* currentCell = GetNextCell();

	if (currentCell->m_id == m_goalCell->m_id)
	{
		m_goalCell->parent = currentCell->parent;

		CSearchCell* getPath;

		for (getPath = m_goalCell; getPath != NULL; getPath = getPath->parent)	// Checks through m_goalCell to find shortest path & push to m_pathToGoal list
		{
			m_pathToGoal.push_back(new Vector3(getPath->m_xCoord, 0, getPath->m_zCoord));
		}

		m_foundGoal = true;
		return;
	}
	else 
	{
		// Right Side
		PathOpened(currentCell->m_xCoord + 1, currentCell->m_zCoord, currentCell->G + 1, currentCell);

		// Left Side
		PathOpened(currentCell->m_xCoord - 1, currentCell->m_zCoord, currentCell->G + 1, currentCell);

		// Top
		PathOpened(currentCell->m_xCoord, currentCell->m_zCoord + 1, currentCell->G + 1, currentCell);

		// Bottom
		PathOpened(currentCell->m_xCoord, currentCell->m_zCoord - 1, currentCell->G + 1, currentCell);

		// Diagonals (if needed, remove otherwise)
		// Left-Top Diagonal
		PathOpened(currentCell->m_xCoord - 1, currentCell->m_zCoord + 1, currentCell->G + 1.414f, currentCell);

		// Right-Top Diagonal
		PathOpened(currentCell->m_xCoord + 1, currentCell->m_zCoord + 1, currentCell->G + 1.414f, currentCell);

		// Left-Bottom Diagonal
		PathOpened(currentCell->m_xCoord - 1, currentCell->m_zCoord - 1, currentCell->G + 1.414f, currentCell);

		// Right-Bottom Diagonal
		PathOpened(currentCell->m_xCoord + 1, currentCell->m_zCoord - 1, currentCell->G + 1.414f, currentCell);

		for (int i = 0; i < m_openList.size(); i++)
		{
			if (currentCell->m_id == m_openList[i]->m_id)
			{
				m_openList.erase(m_openList.begin() + 1);
			}
		}
	}
}
Ejemplo n.º 2
0
/**
	@brief	FindName을 찾는다.

	@author KHS	

	@date 2009-05-26 오후 3:18:13	

	@param	

	@return		
**/
bool CGridCtrlEx::FindWhatYouNeed(CString FindName, bool bMatchCase, bool bMatchWholeWord, bool bSearchDown)
{
	if(bMatchCase == false)
		FindName.MakeUpper();

	bool bContinueSearch = true;
	
	CCellID startCell = GetFocusCell();
	CCellID actCell = startCell;

	if(IsValid(actCell))
	{
		goto L_SEARCH;
	}

	do
	{
		actCell.col = 1;
		actCell.row = 1;
		for(actCell = bSearchDown ? actCell
			: GetPrevCell(actCell);
			bContinueSearch && IsValid(actCell);)
		{
			if(actCell == startCell)
			{
				bContinueSearch = false;
				break;
			}
			{
				CString rName = CGridCtrlEx::GetItemText(actCell.row, actCell.col);
				if(bMatchCase == false) rName.MakeUpper();

				if((bMatchWholeWord && rName == FindName) || (!bMatchWholeWord && (rName.Find(FindName) >= 0)))
				{
					SetSelectedRange(actCell.row, actCell.col,actCell.row, actCell.col);
					SetFocusCell(actCell);
					//!SCROL BAR MOVE
					ScrollMove(startCell, actCell);

					return true;
				}
			}

L_SEARCH:
			actCell = bSearchDown ? GetNextCell(actCell) : GetPrevCell(actCell);
		}
		if(!IsValid(actCell))
		{
			bContinueSearch = false;
		}
	}while(bContinueSearch);

	return false;	// not found
}
Ejemplo n.º 3
0
void PathFinding::ContinuePath() {
	if(m_openList.empty()) {
		return;
	}

	SearchCell* currentCell = GetNextCell();

	if(currentCell->m_id == m_goalCell->m_id) {
		m_goalCell->mp_parent = currentCell->mp_parent;

		SearchCell* getPath;

		for(getPath = m_goalCell; getPath != NULL; getPath = getPath->mp_parent) {
			m_pathToGoal.push_back(new sf::Vector2f(getPath->m_xcoord, getPath->m_ycoord));
		}

		m_foundGoal = true;
		return;
	}
	else {
		//right
		PathOpened(currentCell->m_xcoord + 1, currentCell->m_ycoord, currentCell->m_g + 10, currentCell);
		//left
		PathOpened(currentCell->m_xcoord - 1, currentCell->m_ycoord, currentCell->m_g + 10, currentCell);
		//down
		PathOpened(currentCell->m_xcoord, currentCell->m_ycoord + 1, currentCell->m_g + 10, currentCell);
		//up
		PathOpened(currentCell->m_xcoord, currentCell->m_ycoord - 1, currentCell->m_g + 10, currentCell);
		/*//left_down diagonal
		PathOpened(currentCell->m_xcoord - 1, currentCell->m_ycoord + 1, currentCell->m_g + 14, currentCell);
		//right_down diagonal
		PathOpened(currentCell->m_xcoord + 1, currentCell->m_ycoord + 1, currentCell->m_g + 14, currentCell);
		//left_up diagonal
		PathOpened(currentCell->m_xcoord - 1, currentCell->m_ycoord - 1, currentCell->m_g + 14, currentCell);
		//right_up diagonal
		PathOpened(currentCell->m_xcoord + 1, currentCell->m_ycoord - 1, currentCell->m_g + 14, currentCell);
		*/
		for(int i = 0; i < m_openList.size(); i++) {
			if(currentCell->m_id == m_openList.at(i)->m_id) {
				m_openList.erase(m_openList.begin() + i);
			}
		}
	}
}
Ejemplo n.º 4
0
void PathFinding::ContinuePath() {
	for (int i = 0; i < 50; i++) {
		if (m_openList.empty()) return;
		SearchCell *currentCell = GetNextCell();
		if (currentCell->m_id == m_goalCell->m_id) {
			m_goalCell->parent = currentCell->parent;
			SearchCell *getPath;
			for (getPath = m_goalCell; getPath != NULL; getPath = getPath->parent) m_pathToGoal.push_back(new Vector3((float)(getPath->m_x_coord * CELL_SIZE), (float)(getPath->m_y_coord * CELL_SIZE), 0));
			m_foundGoal = true;
			return;
		}
		else {
			// right side
			PathOpened(currentCell->m_x_coord + 1, currentCell->m_y_coord, currentCell->g + 1, currentCell);
			// left side
			PathOpened(currentCell->m_x_coord - 1, currentCell->m_y_coord, currentCell->g + 1, currentCell);
			// up
			PathOpened(currentCell->m_x_coord, currentCell->m_y_coord + 1, currentCell->g + 1, currentCell);
			// down
			PathOpened(currentCell->m_x_coord, currentCell->m_y_coord - 1, currentCell->g + 1, currentCell);

			// left-up diagonal
			PathOpened(currentCell->m_x_coord - 1, currentCell->m_y_coord + 1, currentCell->g + 1.414f, currentCell);
			// left down diagonal
			PathOpened(currentCell->m_x_coord - 1, currentCell->m_y_coord - 1, currentCell->g + 1.414f, currentCell);

			// right up diagonal
			PathOpened(currentCell->m_x_coord + 1, currentCell->m_y_coord + 1, currentCell->g + 1.414f, currentCell);
			// right down diagonal
			PathOpened(currentCell->m_x_coord + 1, currentCell->m_y_coord - 1, currentCell->g + 1.414f, currentCell);

			for (unsigned int i = 0; i < m_openList.size(); i++) {
				if (currentCell->m_id == m_openList[i]->m_id) {
					m_openList.erase(m_openList.begin() + 1);
				}
			}
		}
	}
}