예제 #1
0
IBF_Result IBFactDef_PropIsPickable::Test(const class IBFact* pFact) const
{
	BLProp* pProp = pFact->GetVariable<BLProp>();

	if (pProp == nullptr)
		return IBF_UNKNOW;

	return (pProp->IsPickable() ? IBF_OK : IBF_FAIL);
}
예제 #2
0
IBF_Result IBFactDef_PropIsMovable::Test(const vector<IBObject*>& aUserData)
{
	ASSERT(aUserData.size() == GetDegree());

	BLProp* pProp = reinterpret_cast<BLProp*>(aUserData[0]);
	
	if (pProp == NULL)
		return IBF_UNKNOW;

	return (pProp->IsMovable() ? IBF_OK : IBF_FAIL);
}
예제 #3
0
void IBFactDef_ObjectAtPos::ResolveVariable(vector<IBObject*>& aUserData)
{
	ASSERT(aUserData.size() == GetDegree());
	void* pOwner = m_pPlanner->GetOwner();
	ASSERT(pOwner != NULL);
	BLBot* pBot = static_cast<BLBot*>(pOwner);
	ASSERT(pBot != NULL);
	BLWorld& oWorld = pBot->GetWorld();

	BLProp* pProp = ((BLProp*)aUserData[0]);
	IBVector2* pPos = ((IBVector2*)aUserData[1]);

	if (pPos == NULL && pProp != NULL)
	{
		pPos = &pProp->GetPos();
		aUserData[1] = pPos;
	}
	else if (pPos != NULL && pProp == NULL)
	{
		pProp = (BLProp*)oWorld.GetGrid().GetCase(*pPos).GetProp();
		aUserData[0] = pProp;
	}
}
예제 #4
0
bool IBActionDef_PushProp::Init(IBAction* pAction)
{
	void* pOwner = m_pPlanner->GetOwner();
	ASSERT(pOwner != NULL);
	BLBot* pBot = static_cast<BLBot*>(pOwner);
	ASSERT(pBot != NULL);
	const BLWorld& oWorld = pBot->GetWorld();

	BLProp* pObj = reinterpret_cast<BLProp*>(pAction->FindVariables("Obj"));
	IBVector2* pObjPos = reinterpret_cast<IBVector2*>(pAction->FindVariables("ObjPos"));
	IBVector2* pDestPos = reinterpret_cast<IBVector2*>(pAction->FindVariables("DestPos"));
	IBVector2* pPushPos = reinterpret_cast<IBVector2*>(pAction->FindVariables("PushPos"));
	IBInt* pDist = reinterpret_cast<IBInt*>(pAction->FindVariables("Dist"));

	if (pObj == NULL && pObjPos == NULL)
		return false;

	if (pObj == NULL)
	{
		pObj = (BLProp*)(oWorld.GetGrid().GetCase(*pObjPos).GetProp());
		pAction->SetVariable("Obj", pObj);
	}

	if (pDestPos == NULL)
	{
		pObjPos = &(pObj->GetPos());
		pAction->SetVariable("ObjPos", pObjPos);

		for (uint i=0 ; i<4 ; ++i)
		{
			Vector2 oDestPos = *pObjPos + dir[i];
			Vector2 pushpos = *pObjPos - dir[i];
			if (oWorld.GetGrid().IsCoordValid(oDestPos) && !oWorld.GetGrid().GetCase(oDestPos).IsPermBlock(pObj)
				&& oWorld.GetGrid().IsCoordValid(pushpos) && !oWorld.GetGrid().GetCase(pushpos).IsPermBlock(pObj))
			{
				pDestPos = new IBVector2("Dest", oDestPos, true);
				pPushPos = new IBVector2("Push", pushpos, true);
				pAction->SetVariable("DestPos", pDestPos);
				pAction->SetVariable("PushPos", pPushPos);
				break;
			}
		}
	}

	if (pObjPos == NULL && pDestPos != NULL)
	{
		BLProp& oObj = *pObj;
		IBVector2& oDestPos = *pDestPos;
		Vector2 pushpos_test = pObj->GetPos() - (oDestPos - pObj->GetPos());
		
		if (oWorld.GetGrid().Distance(oDestPos, pObj->GetPos(), false) == 1
		 && oWorld.GetGrid().IsCoordValid(pushpos_test) && oWorld.GetGrid().GetCase(pushpos_test).IsFree(pObj))
		{
			pObjPos = &pObj->GetPos();
		}
		else
		{
			int iBestDist = -1;
			Vector2 oBestPos;
			for (uint i=0 ; i<4 ; ++i)
			{
				Vector2 pos = oDestPos + dir[i];
				Vector2 pushpos = pos + dir[i];
				if (oWorld.GetGrid().IsCoordValid(pos) && !oWorld.GetGrid().GetCase(pos).IsPermBlock(pObj)
				 && oWorld.GetGrid().IsCoordValid(pushpos) && !oWorld.GetGrid().GetCase(pushpos).IsPermBlock(pObj))
				{
					int iDist = oWorld.GetGrid().Distance(pObj->GetPos(), pos, false);
					if (iBestDist == -1 || iDist < iBestDist)
					{
						iBestDist = iDist;
						oBestPos = pos;
					}
				}
			}

			if (iBestDist > 0)
			{
				pObjPos = new IBVector2("Obj Pos", oBestPos, true);
			}
		}

		pAction->SetVariable("ObjPos", pObjPos);
	}

	if (pPushPos == NULL && pDestPos != NULL && pObjPos != NULL)
	{
		Vector2 offset = *pDestPos - *pObjPos;
		pPushPos = new IBVector2("Push Pos", 0, 0, true);
		*pPushPos = *pObjPos - offset;
		pAction->SetVariable("PushPos", pPushPos);
	}

	if (pDist == NULL)
	{
		pDist = new IBInt("Dist", 0, true);
		pAction->SetVariable("Dist", pDist);
	}

	ASSERT(pObjPos == NULL || pDestPos == NULL || (pObjPos != pDestPos && *pObjPos != *pDestPos));
	ASSERT(pObjPos == NULL || pPushPos == NULL || (pObjPos != pPushPos && *pObjPos != *pPushPos));

	return (pObj != NULL && pObjPos != NULL && pDestPos != NULL && pPushPos != NULL && pDist != NULL);
}