Esempio n. 1
0
s16 Battle::AIAttackPosition(Arena & arena, const Unit & b, const Indexes & positions)
{
    s16 res = -1;

    if(b.isMultiCellAttack())
    {
        res = AIMaxQualityPosition(positions);
    }
    else
    if(b.isDoubleCellAttack())
    {
        Indexes results;
        results.reserve(12);

	const Units enemies(arena.GetForce(b.GetColor(), true), true);

	if(1 < enemies.size())
	{
	    for(Units::const_iterator
		it1 = enemies.begin(); it1 != enemies.end(); ++it1)
	    {
		const Indexes around = Board::GetAroundIndexes(**it1);

		for(Indexes::const_iterator
		    it2 = around.begin(); it2 != around.end(); ++it2)
		{
		    const Unit* unit = Board::GetCell(*it2)->GetUnit();
		    if(unit && enemies.end() != std::find(enemies.begin(), enemies.end(), unit))
			results.push_back(*it2);
		}
	    }

    	    if(results.size())
    	    {
        	// find passable results
        	Indexes passable = Arena::GetBoard()->GetPassableQualityPositions(b);
        	Indexes::iterator it2 = results.begin();

        	for(Indexes::const_iterator
		    it = results.begin(); it != results.end(); ++it)
            	    if(passable.end() != std::find(passable.begin(), passable.end(), *it))
                	*it2++ = *it;

        	if(it2 != results.end())
            	    results.resize(std::distance(results.begin(), it2));

        	// get max quality
        	if(results.size())
            	    res = AIMaxQualityPosition(results);
    	    }
	}
    }

    return 0 > res ? AIShortDistance(b.GetHeadIndex(), positions) : res;
}
Esempio n. 2
0
FourTree::Indexes FourTree::getIndexes(const sf::Vector2f& centerRectPos,
		const sf::FloatRect& rect)
{
	Indexes indexes;
	indexes.resize(0);
	sf::FloatRect updatedBounds = mBounds;
	updatedBounds.top += mWorldLocation.y;
	updatedBounds.left += mWorldLocation.x;

	float verticalMidPoint = updatedBounds.left + (updatedBounds.width / 2);
	float horizontalMidPoint = updatedBounds.top + (updatedBounds.height / 2);

	/*TransformableComponent* transformableComp = ptr->comp<TransformableComponent>();
	BoxCollisionComponent* boxCollisionComp = ptr->comp<BoxCollisionComponent>();

	sf::FloatRect boundingRect = boxCollisionComp->getTransfromedRect();

	sf::Vector2f ptrPosition = transformableComp->getWorldPosition(true);*/

	sf::FloatRect boundingRect = rect;

	sf::Vector2f ptrPosition = centerRectPos;



	float topEntityY = ptrPosition.y - boundingRect.height / 2;
	float bottomEntityY = ptrPosition.y + boundingRect.height / 2;
	float leftEntityX = ptrPosition.x - boundingRect.width / 2;
	float rightEntityX = ptrPosition.x + boundingRect.width / 2;

	bool topQuardrant = (topEntityY < horizontalMidPoint);
	bool bottomQuardrant = (bottomEntityY > horizontalMidPoint);
	bool leftQuardrant = (leftEntityX < verticalMidPoint);
	bool rightQuardrant = (rightEntityX > verticalMidPoint);

	if (topQuardrant && leftQuardrant)
		indexes.push_back(1);
	if (topQuardrant && rightQuardrant)
		indexes.push_back(0);
	if (bottomQuardrant && leftQuardrant)
		indexes.push_back(2);
	if (bottomQuardrant && rightQuardrant)
		indexes.push_back(3);

	return indexes;
}
Esempio n. 3
0
FourTree::Indexes FourTree::getIndexes(const RotatedRect& rotatedRect)
{
	Indexes indexes;
	indexes.resize(0);
	
	int i = 0;
	for (auto& index : mNodes){
		sf::FloatRect rect1 = index->mBounds;
		rect1.top += mWorldLocation.y;
		rect1.left += mWorldLocation.x;

		RotatedRect rotateRect1(rect1);
		if (Utility::rotatedCollision(rotatedRect, rotateRect1))
			indexes.push_back(i);
		i++;
	}
	return indexes;
}