예제 #1
0
bool IBActionDef_FindPath::Finish(IBAction* pAction)
{
	IBVector2* pStart = pAction->FindVariables<IBVector2>("Start");
	ASSERT(pStart != NULL);
	IBVector2* pTarget = pAction->FindVariables<IBVector2>("Target");
	ASSERT(pTarget != NULL);
	IBPath* pPath = pAction->FindVariables<IBPath>("Path");
	ASSERT(pPath != NULL);
	//IBInt* pDist = pAction->FindVariables<IBInt>("Dist");
	//ASSERT(pDist != NULL);

	void* pOwner = m_pPlanner->GetOwner();
	ASSERT(pOwner != NULL);
	BLBot* pBot = static_cast<BLBot*>(pOwner);
	const BLWorld& oWorld = pBot->GetWorld();

	for (uint i=0 ; i<pPath->GetLength() ; ++i)
	{
		const BLSquare& sq = oWorld.GetGrid().GetCase((*pPath)[i]);
		if (sq.GetProp() != NULL && sq.GetProp()->IsBlock())
		{
			m_pPlanner->AddPreCond(pAction, "IBFactDef_PropIsUnblock", (IBObject*)sq.GetProp());
		}
	}

	if (pAction->GetUserData() != NULL)
	{
		delete (Navigation<BLSquare>*)pAction->GetUserData();
		pAction->SetUserData(NULL);
	}

	return oWorld.TestPath(*pPath);
}
예제 #2
0
void BLWorld::DrawDebugPath(const IBPath& oPath) const
{
	if (oPath.GetLength() > 0)
	{
		int x1 = oPath.GetList()[0].x * GetGridSize() + GetGridSize()/2;
		int y1 = oPath.GetList()[0].y * GetGridSize() + GetGridSize()/2;
		//int x2 = m_pBot->GetPos().x * GetGridSize() + GetGridSize()/2;
		//int y2 = m_pBot->GetPos().y * GetGridSize() + GetGridSize()/2;
		//GetCanvas().CanvasBase::DrawLine(x1, y1, x2, y2, Color(0, 255, 0));
		GetCanvas().CanvasBase::DrawRect(x1-5, y1-5, 10, 10, Color(0, 255, 0));
	}

	for (uint i=1 ; i<oPath.GetLength() ; ++i)
	{
		int x1 = oPath.GetList()[i-1].x * GetGridSize() + GetGridSize()/2;
		int y1 = oPath.GetList()[i-1].y * GetGridSize() + GetGridSize()/2;
		int x2 = oPath.GetList()[i].x * GetGridSize() + GetGridSize()/2;
		int y2 = oPath.GetList()[i].y * GetGridSize() + GetGridSize()/2;

		GetCanvas().CanvasBase::DrawLine(x1, y1, x2, y2, Color(0, 255, 0));
	}
}