summaryrefslogtreecommitdiff
path: root/sim/src
diff options
context:
space:
mode:
Diffstat (limited to 'sim/src')
-rw-r--r--sim/src/BaseBattle.cpp12
-rw-r--r--sim/src/BaseBattle.h1
2 files changed, 11 insertions, 2 deletions
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index 87b2096..449cddb 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -7,6 +7,7 @@
#include <kurator/campaign/UniqueIdentifier.h>
#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
+#include <kurator/stats/events.h>
#include <kurator/universe.h>
#include "Builder.h"
@@ -19,6 +20,7 @@ namespace sim
BaseBattle::BaseBattle(const campaign::Scenario& scenario) :
+ time {0.0},
_registry {},
spawner {scenario.total_teams(), scenario.radius, 0.1}
{
@@ -51,6 +53,7 @@ BaseBattle::dispatcher()
void
BaseBattle::update(const float dt)
{
+ time += dt;
pick_random_targets();
keep_at_range();
floating_movement(dt);
@@ -144,8 +147,13 @@ BaseBattle::kill_off_dead()
{
auto view = _registry.view<HitPoints>();
for (auto&& [entity, points] : view.each()) {
- if (points.health <= 0.0)
- _registry.destroy(entity);
+ if (points.health > 0.0)
+ continue;
+ if (_registry.all_of<campaign::UniqueIdentifier, Team>(entity)) {
+ const auto& [identifier, team] = _registry.get<campaign::UniqueIdentifier, Team>(entity);
+ _dispatcher.trigger(stats::ShipLeft{time, identifier, team.id, true});
+ }
+ _registry.destroy(entity);
}
}
diff --git a/sim/src/BaseBattle.h b/sim/src/BaseBattle.h
index b0980fe..d2f7d19 100644
--- a/sim/src/BaseBattle.h
+++ b/sim/src/BaseBattle.h
@@ -24,6 +24,7 @@ public:
entt::dispatcher& dispatcher() override;
void update(float dt) override;
private:
+ double time;
entt::registry _registry;
entt::dispatcher _dispatcher;
RandomSpawner spawner;