Example #1
0
bool IBActionDef_FindPath::Start(IBAction* pAction)
{
	void* pOwner = m_pPlanner->GetOwner();
	ASSERT(pOwner != NULL);
	BLBot* pBot = static_cast<BLBot*>(pOwner);
	const BLWorld& oWorld = pBot->GetWorld();

	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);

	//if (oWorld.GetGrid().GetCase(*pTarget).IsBlock())
	//	return false;

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

	Navigation<BLSquare>* pNav = new NavAStar<BLSquare>(oWorld.GetGrid());
	pNav->FindPathInit(*pStart, *pTarget, pDist->GetValue(), *pPath);

	pAction->SetUserData(pNav);

	return true;
}
Example #2
0
bool IBActionDef_FindPath::Execute(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);

	Navigation<BLSquare>* pNav = static_cast<Navigation<BLSquare>*>(pAction->GetUserData());
	Navigation<BLSquare>::State state = Navigation<BLSquare>::FP_Find;
	
	LOG("Find Path step :");
	double start = Timer::Get();
	while (Timer::Get() < start + s_fFindPathStepDelay && state == Navigation<BLSquare>::FP_Find)
	{
		state = pNav->FindPathStep(*pStart, *pTarget, pDist->GetValue(), *pPath);
		LOG(" *");
	}
	LOG("\n");

	return (state != Navigation<BLSquare>::FP_Find);
}
Example #3
0
IBF_Result IBFactDef_HasValidPath::Test(const vector<IBObject*>& aUserData)
{
	void* pOwner = m_pPlanner->GetOwner();
	ASSERT(pOwner != NULL);
	ASSERT(aUserData.size() == GetDegree());

	BLBot* pBot = static_cast<BLBot*>(pOwner);
	Path* pPath = reinterpret_cast<IBPath*>(aUserData[0]);
	Vector2* pStart = reinterpret_cast<IBVector2*>(aUserData[1]);
	Vector2* pTarget = reinterpret_cast<IBVector2*>(aUserData[2]);
	IBInt* pDist = reinterpret_cast<IBInt*>(aUserData[3]);

	if (pPath == NULL || pStart == NULL || pTarget == NULL || pDist == NULL)
		return IBF_UNKNOW;

	if (!pPath->IsValid())
		return IBF_FAIL;

	if (pPath->GetStart() != *pStart)
		return IBF_FAIL;

	if (pBot->GetWorld().GetGrid().Distance(pPath->GetTarget(), *pTarget) > pDist->GetValue())
		return IBF_FAIL;

	return (pBot->GetWorld().TestPath(*pPath) ? IBF_OK : IBF_FAIL);
}