summaryrefslogtreecommitdiff
path: root/sim/src
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-13 23:29:03 +0100
committerAki <please@ignore.pl>2022-12-13 23:29:03 +0100
commitd599de1ffc38f8c7f17b454fdf6eb3aaf320c89e (patch)
treeacf50099e165ac5caa8a92057a274f559f30721c /sim/src
parent867393652a1199d4803c5707902f215f36c45350 (diff)
downloadkurator-d599de1ffc38f8c7f17b454fdf6eb3aaf320c89e.zip
kurator-d599de1ffc38f8c7f17b454fdf6eb3aaf320c89e.tar.gz
kurator-d599de1ffc38f8c7f17b454fdf6eb3aaf320c89e.tar.bz2
Added naive events for ship destruction
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;