summaryrefslogtreecommitdiff
path: root/battles
diff options
context:
space:
mode:
Diffstat (limited to 'battles')
-rw-r--r--battles/src/BaseBattle.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp
index 8a3dc37..87f450a 100644
--- a/battles/src/BaseBattle.cpp
+++ b/battles/src/BaseBattle.cpp
@@ -83,14 +83,17 @@ BaseBattle::update(const float dt)
_registry.destroy(entity);
continue;
}
- const auto& state = _registry.get<AIState>(control.owner); // no checks
+ 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.reload <= 0.0) {
auto& target_points = _registry.get<HitPoints>(state.target);
- target_points.health -= def.base_damage;
+ const auto& target = _registry.get<Transform>(state.target);
+ const auto distance = transform.position - target.position;
+ if (def.range > distance.magnitude())
+ target_points.health -= def.base_damage;
control.reload = def.rate_of_fire;
}
}