#include "systems.h" #include #include #include #include #include #include namespace kurator { namespace sim { void pick_random_targets(State& ctx, TeamManager& manager) { auto view = ctx.registry.view(); for (auto&& [entity, team, ai] : view.each()) { if (!ctx.registry.valid(ai.target)) ai.target = manager.random(team.id); } } void keep_at_range(State& 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(State& 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