Exemple #1
0
int NavDijkstra::FindNearest(const Vector2& start, int type, Path& aPath, int iTurn)
{
	Init(start, iTurn);

	// Browse
	for (m_iHead = 0 ; m_iHead < m_aStep.size() && m_iHead < m_iQueue ; ++m_iHead)
	{
		uint id = m_aStep[m_iHead];

		Case& oCase = m_oPathGrid.GetCase(id);

		ASSERT(oCase.iCount != BLOCK);
		Vector2 vCoord = m_oPathGrid.GetCoord(id);
		ASSERT(m_oPathGrid.GetIndex(vCoord) == id);

		int dir_offset = rand() % CardDirCount;
		for (int dir = 0 ; dir < CardDirCount ; ++dir)
		{
			Vector2 vSideCoord = m_oPathGrid.GetCoord(vCoord, (EDirection)((dir + dir_offset)%CardDirCount));
			Case& oSideCase = m_oPathGrid.GetCase(vSideCoord);
			if (oSideCase.iCount == BLANK)
			{
				oSideCase.iCount = oCase.iCount + 1;
				oSideCase.iPreviousCase = id;
				ASSERT(m_oPathGrid.DistanceSq(m_oPathGrid.GetCoord(id), vSideCoord) == 1);
				uint iSideId = m_oPathGrid.GetIndex(vSideCoord);
				m_aStep[m_iQueue++] = iSideId;
			}

			const Square& square = m_pModelGrid->GetCase(vSideCoord);
			if (!square.IsWater())
			{
				int sqtype = None;

				if (!square.IsDiscovered(iTurn))	sqtype |= Undiscovered;
				if (!square.IsVisible())			sqtype |= Unvisible;
				if (square.IsFood())				sqtype |= Food;
				if (square.IsEnemyHill())			sqtype |= EnemyHill;
				if (square.HasEnemyAnt())			sqtype |= EnemyAnt;
				if (square.IsFriendHill())			sqtype |= FriendHill;
				if (square.HasFriendAnt())			sqtype |= FriendAnt;
				if (square.GetAntInfluence() > 0)	sqtype |= Safe;

				if (type & sqtype)
				{
					GetPath((oSideCase.iCount == BLOCK ? vCoord : vSideCoord), aPath);
					ASSERT(aPath.GetLength() > 0);
					return sqtype;
				}
			}
		}
	}

	return None;
}
Exemple #2
0
bool BLWorld::TestPath(const Path& oPath) const
{
	for (uint i=0 ; i<oPath.GetLength() ; ++i)
	{
		const BLSquare& sq = m_pMap->GetGrid()[oPath[i]];
		if (sq.GetProp() != NULL && sq.IsTempBlock())
			return false;
	}

	return true;
}