From d599de1ffc38f8c7f17b454fdf6eb3aaf320c89e Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 13 Dec 2022 23:29:03 +0100 Subject: Added naive events for ship destruction --- sim/src/BaseBattle.cpp | 12 ++++++++++-- sim/src/BaseBattle.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'sim/src') 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 #include #include +#include #include #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(); for (auto&& [entity, points] : view.each()) { - if (points.health <= 0.0) - _registry.destroy(entity); + if (points.health > 0.0) + continue; + if (_registry.all_of(entity)) { + const auto& [identifier, team] = _registry.get(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; -- cgit v1.1