#include #include #include #include #include #include #include namespace kurator { namespace sim { void keep_at_range(engine::Context& ctx) { auto view = ctx.registry.view(); for (auto&& [entity, self, ai] : view.each()) { if (!ctx.registry.valid(ai.target)) continue; const auto target = ctx.registry.get(ai.target); const auto offset = target.position - self.position; ai.destination = target.position - offset.normalized().scale(ai.keep_at_range); } } void kill_off_dead(engine::Context& ctx) { auto view = ctx.registry.view(); for (auto&& [entity, points] : view.each()) { if (points.is_alive()) continue; if (ctx.registry.all_of(entity)) { const auto& [identifier, team] = ctx.registry.get(entity); ctx.dispatcher.trigger(stats::ShipLeft{ctx.clock.game, identifier, team.id, true}); ctx.dispatcher.trigger(Destroyed{entity}); } ctx.registry.destroy(entity); } } } // namespace sim } // namespace kurator