summaryrefslogtreecommitdiff
path: root/sim/src/BaseBattle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sim/src/BaseBattle.cpp')
-rw-r--r--sim/src/BaseBattle.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index e34af76..6182fec 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -25,7 +25,6 @@ namespace sim
BaseBattle::BaseBattle(const campaign::Scenario& scenario) :
- time {0.0},
_registry {},
spawner {scenario.last_team(), scenario.radius, 0.1}
{
@@ -57,17 +56,19 @@ BaseBattle::dispatcher()
}
+static void keep_at_range(engine::Context& ctx);
+static void kill_off_dead(engine::Context& ctx);
+
+
void
BaseBattle::update(engine::Context& ctx)
{
- time = ctx.clock.game;
pick_random_targets();
- keep_at_range();
+ keep_at_range(ctx);
FloatingMovement::update(ctx);
TurretControl::update(ctx);
- kill_off_dead();
- manager.clear(_registry); // registry supports on destructions events
- manager.update(_dispatcher);
+ kill_off_dead(ctx);
+ manager.update(ctx);
}
@@ -83,13 +84,13 @@ BaseBattle::pick_random_targets()
void
-BaseBattle::keep_at_range()
+keep_at_range(engine::Context& ctx)
{
- auto view = _registry.view<Transform, AIState>();
+ auto view = ctx.registry.view<Transform, AIState>();
for (auto&& [entity, self, ai] : view.each()) {
- if (!_registry.valid(ai.target))
+ if (!ctx.registry.valid(ai.target))
continue;
- const auto target = _registry.get<Transform>(ai.target);
+ const auto target = ctx.registry.get<Transform>(ai.target);
const auto offset = target.position - self.position;
ai.destination = target.position - offset.normalized().scale(ai.keep_at_range);
}
@@ -97,18 +98,18 @@ BaseBattle::keep_at_range()
void
-BaseBattle::kill_off_dead()
+kill_off_dead(engine::Context& ctx)
{
- auto view = _registry.view<HitPoints>();
+ auto view = ctx.registry.view<HitPoints>();
for (auto&& [entity, points] : view.each()) {
if (points.is_alive())
continue;
- if (_registry.all_of<universe::UniqueIdentifier, Team>(entity)) {
- const auto& [identifier, team] = _registry.get<universe::UniqueIdentifier, Team>(entity);
- _dispatcher.trigger(stats::ShipLeft{time, identifier, team.id, true});
- _dispatcher.trigger(Destroyed{entity});
+ if (ctx.registry.all_of<universe::UniqueIdentifier, Team>(entity)) {
+ const auto& [identifier, team] = ctx.registry.get<universe::UniqueIdentifier, Team>(entity);
+ ctx.dispatcher.trigger(stats::ShipLeft{ctx.clock.game, identifier, team.id, true});
+ ctx.dispatcher.trigger(Destroyed{entity});
}
- _registry.destroy(entity);
+ ctx.registry.destroy(entity);
}
}