Esempio n. 1
0
DWORD CTeleportPath::FindTeleportPath(POINT ptStart, POINT ptEnd, LPPOINT lpBuffer, DWORD dwMaxCount)
{
	if (lpBuffer == NULL || dwMaxCount == 0 || m_nCX <= 0 || m_nCY <= 0 || m_ppTable == NULL)
		return 0;
	
	memset(lpBuffer, 0, sizeof(POINT) * dwMaxCount);
	m_ptStart = ptStart;
	m_ptEnd = ptEnd;

	//GameInfof("start %d %d End %d %d", ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);

	MakeDistanceTable();
	 
	lpBuffer[0] = ptStart; // start point
	DWORD dwFound = 0;

	POINT pos = ptStart;

	BOOL bOK = FALSE;
	int nRes = GetBestMove(pos);
	while (nRes != PATH_FAIL && dwFound < dwMaxCount)
	{
		// Reached?
		if (nRes == PATH_REACHED)
		{
			bOK = TRUE;
			lpBuffer[dwFound] = ptEnd;
			dwFound++;
			break; // Finished
		}

		// Perform a redundancy check
		int nRedundancy = GetRedundancy(lpBuffer, dwFound, pos);
		if (nRedundancy == -1)
		{
			// no redundancy
			lpBuffer[dwFound] = pos;
			dwFound++;
		}
		else
		{
			// redundancy found, discard all redundant steps
			dwFound = nRedundancy + 1;
			lpBuffer[dwFound] = pos;
		}	

		nRes = GetBestMove(pos);
	}	

	if (!bOK)
		dwFound = 0;

	return dwFound;
}
Esempio n. 2
0
BYTE CPathFinder::CalculatePathTo(WORD x, WORD y, LPPATH lpBuffer, int nAdjust)
{
	if (lpBuffer == NULL || x == 0 || y == 0 || !VerifyMemory())
		return 0;

	memset(lpBuffer, 0, sizeof(PATH));
	lpBuffer->posStart = GetPosition();
	if (lpBuffer->posStart.x == 0 || lpBuffer->posStart.y == 0)
		return 0;
	
	if (!Search())
		return 0;

	//GameInfof("Mapsize %d, %d", m_rightBottom.x - m_lefttTop.x, m_rightBottom.y - m_lefttTop.y);

	m_ptAbsDest.x = x;
	m_ptAbsDest.y = y;

	m_ptRelDest = m_ptAbsDest;
	MapToGraph(m_ptRelDest);

	//GameInfof("des %d, %d", m_ptRelDest.x, m_ptRelDest.y);

	// verify destination, see if it's in our map
	if (!IsValidPos(m_ptRelDest))
		return 0;

	MakeMap2();	
	//DumpMap2();

	POINT pos;
	pos.x = (short)lpBuffer->posStart.x;
	pos.y = (short)lpBuffer->posStart.y;

	lpBuffer->iNodeCount = 0;

	BOOL bOK = FALSE;
	int nRes = GetBestMove(pos, nAdjust);
	while (nRes != PATH_FAIL && lpBuffer->iNodeCount < 255)
	{
		// Reached?
		if (nRes == PATH_REACHED)
		{
			bOK = TRUE;
			lpBuffer->aPathNodes[lpBuffer->iNodeCount].x = x;
			lpBuffer->aPathNodes[lpBuffer->iNodeCount].y = y;
			lpBuffer->iNodeCount++;
			break; // Finished
		}

		// Perform a redundancy check
		int nRedundancy = GetRedundancy(lpBuffer, pos);
		if (nRedundancy == -1)
		{
			// no redundancy
			lpBuffer->aPathNodes[lpBuffer->iNodeCount].x = (WORD)pos.x;
			lpBuffer->aPathNodes[lpBuffer->iNodeCount].y = (WORD)pos.y;
			lpBuffer->iNodeCount++;
		}
		else
		{
			// redundancy found, discard all redundant steps
			lpBuffer->iNodeCount = nRedundancy + 1;
			lpBuffer->aPathNodes[lpBuffer->iNodeCount].x = (WORD)pos.x;
			lpBuffer->aPathNodes[lpBuffer->iNodeCount].y = (WORD)pos.y;
		}	

		nRes = GetBestMove(pos, nAdjust);
	}	

	if (!bOK)
	{
		lpBuffer->iNodeCount = 0;
	}
	else
	{
		lpBuffer->posEnd.x = x;
		lpBuffer->posEnd.y = y;
	}
	
	//DumpMap1(lpBuffer);	// debug pictures
	return lpBuffer->iNodeCount;	
}