From b8d3a357428d3af09031d2ae8925e1c2e93810ba Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 31 Dec 2022 16:26:25 +0100 Subject: Added rounds and reload time to turrets to enable burst weapons --- sim/src/BaseBattle.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'sim/src/BaseBattle.cpp') diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index 46c98ed..5f72483 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -104,18 +104,24 @@ BaseBattle::turrets(const float dt) continue; if (control.reload > 0.0) control.reload -= dt; - if (control.reload <= 0.0) { + 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(state.target); const auto& target = _registry.get(state.target); - const auto distance = transform.position - target.position; - if (distance.magnitude() > def.optimal_range * 2.5) + const auto distance = transform.position.distance(target.position); + if (distance > def.optimal_range * 2.5) continue; - const auto damage = def.effective_damage(distance.magnitude()); + const auto damage = def.effective_damage(distance); if (damage > 0.0) { target_points.health -= damage; _dispatcher.trigger(Hit{damage, control.owner, state.target}); } - control.reload = def.rate_of_fire; + control.delay = def.rate_of_fire; + if (--control.rounds < 1) + control.reload = def.reload; } } } -- cgit v1.1