SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Classes | Public Member Functions | List of all members
ai::GroupMgr Class Reference

Maintains the groups a AI can be in. More...

#include <GroupMgr.h>

Public Member Functions

bool add (GroupId id, const AIPtr &ai)
 Adds a new group member to the given GroupId. If the group does not yet exists, it it created and the given AI instance will be the leader of the group. More...
 
void update (int64_t deltaTime)
 
bool remove (GroupId id, const AIPtr &ai)
 Removes a group member from the given GroupId. If the member is the group leader, a new leader will be picked randomly. If after the removal of the member only one other member is left in the group, the group is destroyed. More...
 
bool removeFromAllGroups (const AIPtr &ai)
 Use this method to remove a AI instance from all the group it is part of. Useful if you e.g. destroy a AI instance. More...
 
glm::vec3 getPosition (GroupId id) const
 Returns the average position of the group. More...
 
AIPtr getLeader (GroupId id) const
 
template<typename Func >
void visit (GroupId id, Func &func) const
 Visit all the group members of the given group until the functor returns false. More...
 
int getGroupSize (GroupId id) const
 
bool isInAnyGroup (const AIPtr &ai) const
 
bool isInGroup (GroupId id, const AIPtr &ai) const
 
bool isGroupLeader (GroupId id, const AIPtr &ai) const
 

Detailed Description

Maintains the groups a AI can be in.

Note
Keep in mind that if you destroy an AI somewhere in the game, to also remove it from the groups.

Every Zone has its own GroupMgr instance. It is automatically updated with the zone. The average group position is only updated once per update() call.

Member Function Documentation

bool ai::GroupMgr::add ( GroupId  id,
const AIPtr &  ai 
)
inline

Adds a new group member to the given GroupId. If the group does not yet exists, it it created and the given AI instance will be the leader of the group.

See Also
remove()
Parameters
aiThe AI to add to the group. Keep in mind that you have to remove it manually from any group whenever you destroy the AI instance.
Returns
true if the add to the group was successful.
Note
This method performs a write lock on the group manager
int ai::GroupMgr::getGroupSize ( GroupId  id) const
inline
Returns
If the group doesn't exist, this method returns 0 - otherwise the amount of members that must be bigger than 1
Note
This method performs a read lock on the group manager
AIPtr ai::GroupMgr::getLeader ( GroupId  id) const
inline
Returns
The ICharacter object of the leader, or nullptr if no such group exists.
Note
This method performs a read lock on the group manager
glm::vec3 ai::GroupMgr::getPosition ( GroupId  id) const
inline

Returns the average position of the group.

Note
If the given group doesn't exist or some other error occurred, this method returns glm::vec3::VEC3_INFINITE
The position of a group is calculated once per update() call.
This method performs a read lock on the group manager
bool ai::GroupMgr::isGroupLeader ( GroupId  id,
const AIPtr &  ai 
) const
inline
Note
This method performs a read lock on the group manager
bool ai::GroupMgr::isInAnyGroup ( const AIPtr &  ai) const
inline
Note
This method performs a read lock on the group manager
bool ai::GroupMgr::isInGroup ( GroupId  id,
const AIPtr &  ai 
) const
inline
Note
This method performs a read lock on the group manager
bool ai::GroupMgr::remove ( GroupId  id,
const AIPtr &  ai 
)
inline

Removes a group member from the given GroupId. If the member is the group leader, a new leader will be picked randomly. If after the removal of the member only one other member is left in the group, the group is destroyed.

Parameters
aiThe AI to remove from this the group.
Returns
true if the given AI was removed from the group, false if the removal failed (e.g. the AI instance was not part of the group)
Note
This method performs a write lock on the group manager
bool ai::GroupMgr::removeFromAllGroups ( const AIPtr &  ai)
inline

Use this method to remove a AI instance from all the group it is part of. Useful if you e.g. destroy a AI instance.

Note
This method performs a write lock on the group manager
template<typename Func >
void ai::GroupMgr::visit ( GroupId  id,
Func &  func 
) const
inline

Visit all the group members of the given group until the functor returns false.

Note
This methods performs a read lock on the group manager

The documentation for this class was generated from the following file: