Ejemplo n.º 1
0
void COptimizePath::_AddPathPortion(CLine& line, const A3DPOINT2& dest, const int newCount)
{
	int index;
	int old_count = 0;
	for (index = m_CurIndex +1; index < (int)m_Path.size(); index++)
	{
		old_count++;
		//clear  the old footprint
		int x, y;
		x = (int)m_Path[index].x;
		y = (int)m_Path[index].y;
		SetFootprint(x, y, 0);
		if (x == dest.x && y == dest.y)
		{
			break;
		}
	}

	assert(index < (int)m_Path.size() );

	//adjust the path space between current to dest,  have old_count, need newCount 
	if (old_count > newCount)
	{
		//erase 
		abase::vector<APointF>::iterator it1, it2;
		it1 = &m_Path[m_CurIndex+1];
		it2 = it1 + old_count - newCount;
		m_Path.erase(it1, it2);
	}
	else if (old_count < newCount)
	{
		//insert
		abase::vector<APointF>::iterator it1;
		it1 = &m_Path[m_CurIndex+1];
		m_Path.insert(it1, newCount - old_count, APointF());
	}
	
	//replace the old path portion
	index = m_CurIndex+1;
	while (line.GetCount() < newCount)
	{
		m_Path[index] = line.Next();
		index++;
	}

}
Ejemplo n.º 2
0
bool COptimizePath::_LineTo(CLine& line, APointF& to)
{

#define  LOCAL_STRICT_LINE
	A3DPOINT2 to_pt((int)to.x, (int)to.y);
	A3DPOINT2 cur_pt((int)line.GetFrom().x, (int)line.GetFrom().y);

	CMoveMap * pMoveMap = g_MoveAgentManager.GetMoveMap();
	assert(pMoveMap);

#ifdef LOCAL_STRICT_LINE
	A3DPOINT2  last_pt(cur_pt);

#endif
	while (cur_pt != to_pt )
	{
		
		APointF cur(line.Next());
		cur_pt.x = (int)cur.x;
		cur_pt.y = (int)cur.y;

		if (!pMoveMap->IsPosReachable(cur_pt))
		{
			return false;
		}

#ifdef LOCAL_STRICT_LINE
		if ((cur_pt.x != last_pt.x && cur_pt.y != last_pt.y) 
			&&(!pMoveMap->IsPosReachable(last_pt.x, cur_pt.y)
			  || !pMoveMap->IsPosReachable(cur_pt.x, last_pt.y)) )
		{
			return false;
		}
		last_pt = cur_pt;
#endif

	}
	
#undef  LOCAL_STRICT_LINE
	return true;
}