From e732f10d32f96837f5787ab946bdbe6ba6bf6f2a Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 24 Dec 2022 01:56:28 +0100 Subject: Added end event to mark end of a battle --- sim/include/kurator/sim/events.h | 5 +++++ sim/src/BaseBattle.cpp | 1 + sim/src/TeamManager.cpp | 12 ++++++++++++ sim/src/TeamManager.h | 2 ++ 4 files changed, 20 insertions(+) (limited to 'sim') 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 #include +#include + +#include 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 #include +#include 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 teams; std::mt19937 generator; -- cgit v1.1