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; }
KuhnMunkres::Indexes KuhnMunkres::calculate(const Grid &grid) { grid_ = grid; const Dimensions dimensions = ensure_grid_is_square(); size = static_cast<int>(grid_.size()); #ifdef USE_STL row_covered.resize(size, false); column_covered.resize(size, false); #else row_covered.fill(false, size); column_covered.fill(false, size); #endif z0_row = 0; z0_column = 0; path = make_grid(size * 2, static_cast<int>(ZERO)); marked = make_grid(size, static_cast<int>(ZERO)); int step = 1; while (step) { switch (step) { case 1: step = step1(); break; case 2: step = step2(); break; case 3: step = step3(); break; case 4: step = step4(); break; case 5: step = step5(); break; case 6: step = step6(); break; default: break; } } Indexes indexes; for (int row = 0; row < size; ++row) { for (int column = 0; column < size; ++column) { if ((row < dimensions.first) && (column < dimensions.second) && marked.at(row).at(column) == STAR) #ifdef USE_STL indexes.push_back(std::make_pair(row, column)); #else indexes.push_back(qMakePair(row, column)); #endif } } return indexes; }
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; }
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; }