Added function to get nearby characters.
This commit is contained in:
parent
7c55643da4
commit
8e65b94667
4 changed files with 25 additions and 0 deletions
|
@ -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).
|
||||
*/
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Reference in a new issue