summaryrefslogtreecommitdiff
path: root/battles/src
diff options
context:
space:
mode:
Diffstat (limited to 'battles/src')
-rw-r--r--battles/src/BaseBattle.cpp13
-rw-r--r--battles/src/BaseBattle.h3
2 files changed, 15 insertions, 1 deletions
diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp
index e7d70c2..4088936 100644
--- a/battles/src/BaseBattle.cpp
+++ b/battles/src/BaseBattle.cpp
@@ -1,8 +1,10 @@
#include "BaseBattle.h"
#include <entt/entity/registry.hpp>
+#include <entt/signal/dispatcher.hpp>
#include <kurator/battles/components.h>
+#include <kurator/battles/events.h>
#include <kurator/battles/Scenario.h>
#include <kurator/universe.h>
@@ -37,6 +39,13 @@ BaseBattle::registry()
}
+entt::dispatcher&
+BaseBattle::dispatcher()
+{
+ return _dispatcher;
+}
+
+
void
BaseBattle::update(const float dt)
{
@@ -108,8 +117,10 @@ BaseBattle::turrets(const float dt)
auto& target_points = _registry.get<HitPoints>(state.target);
const auto& target = _registry.get<Transform>(state.target);
const auto distance = transform.position - target.position;
- if (def.range > distance.magnitude())
+ if (def.range > distance.magnitude()) {
target_points.health -= def.base_damage;
+ _dispatcher.trigger(Hit{def.base_damage, entity, state.target});
+ }
control.reload = def.rate_of_fire;
}
}
diff --git a/battles/src/BaseBattle.h b/battles/src/BaseBattle.h
index 02cc024..8240fd2 100644
--- a/battles/src/BaseBattle.h
+++ b/battles/src/BaseBattle.h
@@ -1,6 +1,7 @@
#pragma once
#include <entt/entity/registry.hpp>
+#include <entt/signal/dispatcher.hpp>
#include <kurator/battles/Battle.h>
#include <kurator/battles/Scenario.h>
@@ -20,9 +21,11 @@ class BaseBattle : public Battle
public:
BaseBattle(const Scenario& scenario);
entt::registry& registry() override;
+ entt::dispatcher& dispatcher() override;
void update(float dt) override;
private:
entt::registry _registry;
+ entt::dispatcher _dispatcher;
RandomSpawner spawner;
TeamManager manager;
void pick_random_targets();