summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--battles/src/BaseBattle.cpp19
-rw-r--r--universe/include/kurator/universe/TurretType.h4
-rw-r--r--universe/src/SampleRepository.cpp2
3 files changed, 20 insertions, 5 deletions
diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp
index e102d79..604a607 100644
--- a/battles/src/BaseBattle.cpp
+++ b/battles/src/BaseBattle.cpp
@@ -1,5 +1,8 @@
#include "BaseBattle.h"
+#include <algorithm>
+#include <cmath>
+
#include <entt/entity/registry.hpp>
#include <entt/signal/dispatcher.hpp>
@@ -105,6 +108,15 @@ BaseBattle::floating_movement(const float dt)
}
+double
+effective_damage(const universe::TurretType& def, const double distance)
+{
+ const auto overflow = distance - def.optimal_range;
+ const auto falloff = std::max(0.0, overflow / def.optimal_range / def.falloff_modifier);
+ return def.base_damage * std::pow(def.falloff_intensity, std::pow(falloff, 2));
+}
+
+
void
BaseBattle::turrets(const float dt)
{
@@ -123,9 +135,10 @@ BaseBattle::turrets(const float dt)
auto& target_points = _registry.get<HitPoints>(state.target);
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;
- _dispatcher.trigger(Hit{def.base_damage, entity, state.target});
+ const auto damage = effective_damage(def, distance.magnitude());
+ if (damage > 0.0) {
+ target_points.health -= damage;
+ _dispatcher.trigger(Hit{damage, entity, state.target});
}
control.reload = def.rate_of_fire;
}
diff --git a/universe/include/kurator/universe/TurretType.h b/universe/include/kurator/universe/TurretType.h
index b3a6eb2..7723d88 100644
--- a/universe/include/kurator/universe/TurretType.h
+++ b/universe/include/kurator/universe/TurretType.h
@@ -14,7 +14,9 @@ struct TurretType
std::string name;
double base_damage;
double rate_of_fire;
- double range;
+ double optimal_range;
+ double falloff_modifier;
+ double falloff_intensity;
};
diff --git a/universe/src/SampleRepository.cpp b/universe/src/SampleRepository.cpp
index 1d875e7..2886e3d 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, 1.2}},
+ {"cannon", {"Cannon", 1.0, 1.0, 1.5, 0.5, 0.2}},
};