示例#1
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);
}
示例#2
0
文件: Path.cpp 项目: dkoerner/base
	Path Path::operator + (const Path & rhs)
	{
		if(!IsValid() && !rhs.IsValid())
		{
			// return this invalid path.
			return *this;
		}
		
		if(IsValid() && !rhs.IsValid())
		{
			// return this valid path
			return *this;
		}
		
		if(!IsValid() && rhs.IsValid())
		{
			// return the rhs valid path.
			return rhs;
		}
		
		// both paths are valid...
		std::string sTmpStr[2] =
		{
	#if defined(_WINDOWS)
			m_sDrive + m_sPath,
			rhs.m_sPath,
	#else
			m_sPath,
			rhs.m_sPath
	#endif
		};
	
		// make sure sTmpStr has a / on the end.
		if(sTmpStr[0][sTmpStr[0].length() - 1] != PATH_SEPARATOR_CHAR)
		{
			sTmpStr[0] += PATH_SEPARATOR_CHAR;
		}
			
		// make sure rhs path has NOT got a / at the start.
		if(sTmpStr[1][0] == PATH_SEPARATOR_CHAR)
		{
			sTmpStr[1] = sTmpStr[1].substr(1, sTmpStr[1].length() - 1);
		}
		
		// create a new path object with the two path strings appended together.
		return Path(sTmpStr[0] + sTmpStr[1], false);
	}
示例#3
0
文件: Path.cpp 项目: dkoerner/base
	bool Path::operator == (const Path & rhs)
	{
		if(!IsValid() && !rhs.IsValid())
		{
			// both paths are invalid!
			return true;
		}
	
		if(IsValid() != rhs.IsValid())
		{
			// one of the paths is valid, whilst the other is not!
			return false;
		}
		
		std::string sTmpStr[2] =
		{
	#if defined(WIN32)
			m_sDrive + m_sPath,
			rhs.m_sDrive + rhs.m_sPath
	#else
			m_sPath,
			rhs.m_sPath
	#endif	    
		};
		
		// make sure both paths have a / on the end.
		if(sTmpStr[0][sTmpStr[0].length() - 1] != PATH_SEPARATOR_CHAR)
		{
			sTmpStr[0] += PATH_SEPARATOR_CHAR;
		}
		
		if(sTmpStr[1][sTmpStr[1].length() - 1] != PATH_SEPARATOR_CHAR)
		{
			sTmpStr[1] += PATH_SEPARATOR_CHAR;
		}
		
		return sTmpStr[0] == sTmpStr[1];
	}