summaryrefslogtreecommitdiff
path: root/battles/src/TeamManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'battles/src/TeamManager.cpp')
-rw-r--r--battles/src/TeamManager.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/battles/src/TeamManager.cpp b/battles/src/TeamManager.cpp
new file mode 100644
index 0000000..e4afeb3
--- /dev/null
+++ b/battles/src/TeamManager.cpp
@@ -0,0 +1,60 @@
+#include "TeamManager.h"
+
+#include <algorithm>
+#include <random>
+#include <utility>
+#include <vector>
+
+#include <entt/entity/registry.hpp>
+
+
+namespace kurator
+{
+namespace battles
+{
+
+
+TeamManager::TeamManager() :
+ teams {},
+ generator {std::random_device{}()}
+{
+}
+
+
+void
+TeamManager::add(int team, entt::entity entity)
+{
+ for (int i = teams.size(); i < team + 1; ++i)
+ teams.emplace_back();
+ teams.at(team).push_back(std::move(entity));
+}
+
+
+TeamManager::Team
+TeamManager::get(int team) const
+{
+ return teams.at(team);
+}
+
+
+entt::entity
+TeamManager::random(int team)
+{
+ auto& members = teams.at(team);
+ std::uniform_int_distribution<Team::size_type> uniform{0, members.size() - 1};
+ return members.at(uniform(generator));
+}
+
+
+void
+TeamManager::clear(entt::registry& registry)
+{
+ for (auto& members : teams) {
+ auto is_valid = [&registry](entt::entity entity){ return !registry.valid(entity); };
+ members.erase(std::remove_if(members.begin(), members.end(), is_valid), members.end());
+ }
+}
+
+
+} // namespace battles
+} // namespace kurator