diff options
Diffstat (limited to 'sim/src/BaseBattle.cpp')
-rw-r--r-- | sim/src/BaseBattle.cpp | 40 |
1 files changed, 2 insertions, 38 deletions
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index 1b27c2e..8ec603a 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -10,6 +10,7 @@ #include <kurator/sim/components.h> #include <kurator/sim/events.h> #include <kurator/sim/FloatingMovement.h> +#include <kurator/sim/TurretControl.h> #include <kurator/stats/events.h> #include <kurator/universe.h> @@ -64,7 +65,7 @@ BaseBattle::update(const float dt) pick_random_targets(); keep_at_range(); FloatingMovement::update(_registry, _dispatcher, dt); - turrets(dt); + TurretControl::update(_registry, _dispatcher, dt); kill_off_dead(); manager.clear(_registry); // registry supports on destructions events manager.update(_dispatcher); @@ -97,43 +98,6 @@ BaseBattle::keep_at_range() void -BaseBattle::turrets(const float dt) -{ - auto view = _registry.view<TurretControl, universe::TurretType>(); - for (auto&& [entity, control, def] : view.each()) { - if (!_registry.valid(control.owner)) { - _registry.destroy(entity); - continue; - } - const auto& [state, transform] = _registry.get<AIState, Transform>(control.owner); // no checks - if (!_registry.valid(state.target)) - continue; - if (control.reload > 0.0) - control.reload -= dt; - if (control.rounds < 1 && control.reload <= 0.0) - control.rounds = def.rounds; - if (control.delay > 0.0) - control.delay -= dt; - if (control.rounds > 0 && control.delay <= 0.0) { - auto& target_points = _registry.get<HitPoints>(state.target); - const auto& target = _registry.get<Transform>(state.target); - const auto distance = transform.position.distance(target.position); - if (distance > def.optimal_range * 2.5) - continue; - const auto damage = def.effective_damage(distance); - if (damage > 0.0) { - target_points.health -= damage; - _dispatcher.trigger(Hit{damage, control.owner, state.target}); - } - control.delay = def.rate_of_fire; - if (--control.rounds < 1) - control.reload = def.reload; - } - } -} - - -void BaseBattle::kill_off_dead() { auto view = _registry.view<HitPoints>(); |