summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-11-16 00:38:14 +0100
committerAki <please@ignore.pl>2022-11-16 00:38:14 +0100
commit67442e86f53a27ddf9014cbe843ba63b08ef52bc (patch)
treef92631ef0edbbf33d7cec61e07ef9a1710b76962
parent9a93c0866c11116bdbdaf11bc0c1693771309244 (diff)
downloadkurator-67442e86f53a27ddf9014cbe843ba63b08ef52bc.zip
kurator-67442e86f53a27ddf9014cbe843ba63b08ef52bc.tar.gz
kurator-67442e86f53a27ddf9014cbe843ba63b08ef52bc.tar.bz2
Implemented simple range limitation for turrets
-rw-r--r--battles/src/BaseBattle.cpp7
-rw-r--r--universe/src/SampleRepository.cpp2
2 files changed, 6 insertions, 3 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;
}
}
diff --git a/universe/src/SampleRepository.cpp b/universe/src/SampleRepository.cpp
index 66a3105..1d875e7 100644
--- a/universe/src/SampleRepository.cpp
+++ b/universe/src/SampleRepository.cpp
@@ -23,7 +23,7 @@ static const std::unordered_map<std::string, ShipType> ships {
static const std::unordered_map<std::string, TurretType> turrets {
- {"cannon", {"Cannon", 1.0, 1.0, 0.5}},
+ {"cannon", {"Cannon", 1.0, 1.0, 1.2}},
};