bool User::pushMap() { //Dont send all at once int maxcount = 10; // If map in queue, push it to client while(this->mapQueue.size() > 0 && maxcount > 0) { maxcount--; // Sort by distance from center vec target(static_cast<int>(pos.x / 16), static_cast<int>(pos.y / 16), static_cast<int>(pos.z / 16)); sort(mapQueue.begin(), mapQueue.end(), DistanceComparator(target)); Map::get().sendToUser(this, mapQueue[0].x(), mapQueue[0].z()); // Add this to known list addKnown(mapQueue[0].x(), mapQueue[0].z()); // Remove from queue mapQueue.erase(mapQueue.begin()); } return true; }
Combatant* AgentCombatState::findOpponent(const Combat::CombatantSet& opponents) const { ///@todo support different search patterns (search for most dangerous, weakest, ... opponent) Combat::CombatantSet::const_iterator minIt = std::min_element(opponents.begin(), opponents.end(), DistanceComparator(this)); return *minIt; }
// Function that (recursively) fills the tree Node* buildFromPoints( int lower, int upper ) { if (upper == lower) { // indicates that we're done here! return NULL; } // Lower index is center of current node Node* node = new Node(); node->index = lower; if (upper - lower > 1) { // if we did not arrive at leaf yet // Choose an arbitrary point and move it to the start int i = (int) (tapkee::uniform_random() * (upper - lower - 1)) + lower; std::swap(_items[lower], _items[i]); // Partition around the median distance int median = (upper + lower) / 2; std::nth_element(_items.begin() + lower + 1, _items.begin() + median, _items.begin() + upper, DistanceComparator(_items[lower])); // Threshold of the new node will be the distance to the median node->threshold = distance(_items[lower], _items[median]); // Recursively build tree node->index = lower; node->left = buildFromPoints(lower + 1, median); node->right = buildFromPoints(median, upper); } // Return result return node; }