Added function to get nearby characters.

This commit is contained in:
Felix Ableitner 2013-03-29 18:48:49 +01:00
parent 7c55643da4
commit 8e65b94667
4 changed files with 25 additions and 0 deletions

View file

@ -226,6 +226,20 @@ World::getPath(const sf::Vector2f& start, const sf::Vector2f& end,
return path;
}
/**
* Returns all characters that are within maxDistance from position.
*/
std::vector<std::shared_ptr<Character> >
World::getCharacters(const sf::Vector2f& position, float maxDistance) const {
std::vector<std::shared_ptr<Character> > visible;
for (auto it : mCharacters) {
if (thor::squaredLength(position - it->getPosition()) <=
maxDistance * maxDistance) {
visible.push_back(it);
}
}
return visible;
}
/**
* Returns the linear distance between two areas (using their center).
*/

View file

@ -32,6 +32,8 @@ public:
void generateAreas();
std::vector<sf::Vector2f> getPath(const sf::Vector2f& start,
const sf::Vector2f& end, float radius) const;
std::vector<std::shared_ptr<Character> >
getCharacters(const sf::Vector2f& position, float maxDistance) const;
// Private types.
private:

View file

@ -132,3 +132,11 @@ Character::move() {
}
}
}
/**
* Calls World::getCharacters with current position.
*/
std::vector<std::shared_ptr<Character> >
Character::getCharacters(float maxDistance) const {
return mWorld.getCharacters(getPosition(), maxDistance);
}

View file

@ -34,6 +34,7 @@ protected:
void releaseTrigger();
bool setDestination(const sf::Vector2f& destination);
void move();
std::vector<std::shared_ptr<Character> > getCharacters(float maxDistance) const;
// Private variables.
private: