summaryrefslogtreecommitdiff
path: root/kurator/src/Battle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kurator/src/Battle.cpp')
-rw-r--r--kurator/src/Battle.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 3d0ac72..d7232ff 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -44,6 +44,7 @@ Battle::Battle(std::shared_ptr<Session> _session, campaign::Scenario scenario, B
{
battle->dispatcher().sink<sim::End>().connect<&Battle::on_end>(*this);
battle->dispatcher().sink<sim::Hit>().connect<&Battle::on_hit>(*this);
+ battle->dispatcher().sink<sim::Destroyed>().connect<&Battle::on_destroyed>(*this);
battle->dispatcher().sink<stats::ShipLeft>().connect<&Battle::on_ship_left>(*this);
auto& registry = battle->registry();
auto ships = registry.view<sim::Team, universe::ShipType, universe::UniqueIdentifier>();
@@ -58,6 +59,7 @@ Battle::~Battle()
{
battle->dispatcher().sink<sim::End>().disconnect(*this);
battle->dispatcher().sink<sim::Hit>().disconnect(*this);
+ battle->dispatcher().sink<sim::Destroyed>().disconnect(*this);
battle->dispatcher().sink<stats::ShipLeft>().disconnect(*this);
}
@@ -84,6 +86,13 @@ Battle::update(const float dt)
pop.speed.x -= damp.x;
pop.speed.y -= damp.y;
}
+ auto crosses = registry.view<Cross>();
+ for (auto&& [entity, cross] : crosses.each()) {
+ cross.timer += dt;
+ const auto dphase = cross.phase * 2;
+ if (cross.timer > dphase)
+ cross.timer -= dphase;
+ }
auto lines = registry.view<Line>();
for (auto&& [entity, line] : lines.each())
line.position += (1.0 + line.hlength) / line.duration * dt * time_factor;
@@ -115,6 +124,25 @@ Battle::draw() const
const int hheight = GetScreenHeight() / 2;
const double scale = std::min(hwidth/15000.0, hheight/15000.0);
auto& registry = battle->registry();
+ auto crosses = registry.view<sim::Transform, Cross>();
+ for (const auto& [entity, transform, cross] : crosses.each()) {
+ if (cross.timer > cross.phase)
+ continue;
+ const int x = hwidth + transform.position.x*scale;
+ const int y = hheight + transform.position.y*scale;
+ DrawLine(
+ x - cross.hlength,
+ y - cross.hlength,
+ x + cross.hlength,
+ y + cross.hlength,
+ cross.color);
+ DrawLine(
+ x + cross.hlength,
+ y - cross.hlength,
+ x - cross.hlength,
+ y + cross.hlength,
+ cross.color);
+ }
auto lines = registry.view<Line>();
for (const auto& [entity, line] : lines.each()) {
const auto diff = line.end - line.start;
@@ -189,6 +217,20 @@ Battle::on_hit(const sim::Hit& hit)
void
+Battle::on_destroyed(const sim::Destroyed& event)
+{
+ auto& registry = battle->registry();
+ if (!registry.valid(event.victim))
+ return;
+ const auto& victim = registry.get<sim::Transform>(event.victim);
+ const auto cross = registry.create();
+ registry.emplace<Timed>(cross, 1.6);
+ registry.emplace<Cross>(cross, 0.2, 6.0);
+ registry.emplace<sim::Transform>(cross, victim.position, 0.0);
+}
+
+
+void
Battle::on_ship_left(const stats::ShipLeft& event)
{
log.push_back(event);