summaryrefslogtreecommitdiff
path: root/sim/src
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-24 01:56:28 +0100
committerAki <please@ignore.pl>2022-12-24 01:56:28 +0100
commite732f10d32f96837f5787ab946bdbe6ba6bf6f2a (patch)
tree672ca21f5b4a419a9f290dfb212728e9cf1e57ca /sim/src
parent84e0e1e45f908f93d0a6a60632e0ff177addfb77 (diff)
downloadkurator-e732f10d32f96837f5787ab946bdbe6ba6bf6f2a.zip
kurator-e732f10d32f96837f5787ab946bdbe6ba6bf6f2a.tar.gz
kurator-e732f10d32f96837f5787ab946bdbe6ba6bf6f2a.tar.bz2
Added end event to mark end of a battle
Diffstat (limited to 'sim/src')
-rw-r--r--sim/src/BaseBattle.cpp1
-rw-r--r--sim/src/TeamManager.cpp12
-rw-r--r--sim/src/TeamManager.h2
3 files changed, 15 insertions, 0 deletions
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;