summaryrefslogtreecommitdiff
path: root/sim/src
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-31 16:26:25 +0100
committerAki <please@ignore.pl>2022-12-31 16:26:25 +0100
commitb8d3a357428d3af09031d2ae8925e1c2e93810ba (patch)
tree2c6c78f963835143e4fb09d4e5ed424c3de99a81 /sim/src
parentbdc690d00c3c2774730dd893ddccb14efc9e0b94 (diff)
downloadkurator-b8d3a357428d3af09031d2ae8925e1c2e93810ba.zip
kurator-b8d3a357428d3af09031d2ae8925e1c2e93810ba.tar.gz
kurator-b8d3a357428d3af09031d2ae8925e1c2e93810ba.tar.bz2
Added rounds and reload time to turrets to enable burst weapons
Diffstat (limited to 'sim/src')
-rw-r--r--sim/src/BaseBattle.cpp16
-rw-r--r--sim/src/Builder.cpp2
2 files changed, 12 insertions, 6 deletions
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<HitPoints>(state.target);
const auto& target = _registry.get<Transform>(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;
}
}
}
diff --git a/sim/src/Builder.cpp b/sim/src/Builder.cpp
index e0198a1..068d012 100644
--- a/sim/src/Builder.cpp
+++ b/sim/src/Builder.cpp
@@ -47,7 +47,7 @@ Builder::operator()(const universe::TurretType& turret_type, const entt::entity&
{
const auto entity = registry.create();
registry.emplace<universe::TurretType>(entity, turret_type);
- registry.emplace<TurretControl>(entity, 0.0, owner);
+ registry.emplace<TurretControl>(entity, 0.0, 0.0, turret_type.rounds, owner);
registry.emplace<Transform>(entity, Point{0.0, 0.0}, 0.0, owner);
return entity;
}