summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
Diffstat (limited to 'sim')
-rw-r--r--sim/include/kurator/sim/events.h5
-rw-r--r--sim/src/BaseBattle.cpp1
-rw-r--r--sim/src/TeamManager.cpp12
-rw-r--r--sim/src/TeamManager.h2
4 files changed, 20 insertions, 0 deletions
diff --git a/sim/include/kurator/sim/events.h b/sim/include/kurator/sim/events.h
index cacf443..71ce098 100644
--- a/sim/include/kurator/sim/events.h
+++ b/sim/include/kurator/sim/events.h
@@ -17,5 +17,10 @@ struct Hit
};
+struct End
+{
+};
+
+
} // namespace sim
} // namespace kurator
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index 449cddb..4b65139 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -60,6 +60,7 @@ BaseBattle::update(const float dt)
turrets(dt);
kill_off_dead();
manager.clear(_registry); // registry supports on destructions events
+ manager.update(_dispatcher);
}
diff --git a/sim/src/TeamManager.cpp b/sim/src/TeamManager.cpp
index b792297..d26ed67 100644
--- a/sim/src/TeamManager.cpp
+++ b/sim/src/TeamManager.cpp
@@ -6,6 +6,9 @@
#include <utility>
#include <entt/entity/registry.hpp>
+#include <entt/signal/dispatcher.hpp>
+
+#include <kurator/sim/events.h>
namespace kurator
@@ -64,5 +67,14 @@ TeamManager::clear(entt::registry& registry)
}
+void
+TeamManager::update(entt::dispatcher& dispatcher)
+{
+ const auto left = std::count_if(teams.begin(), teams.end(), [](const Team& team){ return team.size() > 0; });
+ if (left < 2)
+ dispatcher.trigger(End{});
+}
+
+
} // namespace sim
} // namespace kurator
diff --git a/sim/src/TeamManager.h b/sim/src/TeamManager.h
index 050af94..502bed2 100644
--- a/sim/src/TeamManager.h
+++ b/sim/src/TeamManager.h
@@ -4,6 +4,7 @@
#include <vector>
#include <entt/entity/registry.hpp>
+#include <entt/signal/dispatcher.hpp>
namespace kurator
@@ -21,6 +22,7 @@ public:
Team get(int team) const;
entt::entity random(int exclude);
void clear(entt::registry& registry);
+ void update(entt::dispatcher& dispatcher);
private:
std::vector<Team> teams;
std::mt19937 generator;