diff options
author | Aki <please@ignore.pl> | 2022-11-20 00:54:28 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-11-20 00:54:28 +0100 |
commit | ec2f951152cd19ce861d9ae19f0bfac67595834c (patch) | |
tree | 0a5795c00bf2bfee72d21e5c9b76179c81a32138 /battles/src | |
parent | 98982513f97f449fd200132d0f19130ab31e2c36 (diff) | |
download | kurator-ec2f951152cd19ce861d9ae19f0bfac67595834c.zip kurator-ec2f951152cd19ce861d9ae19f0bfac67595834c.tar.gz kurator-ec2f951152cd19ce861d9ae19f0bfac67595834c.tar.bz2 |
Implemented verbose damage modifier based on range
Diffstat (limited to 'battles/src')
-rw-r--r-- | battles/src/BaseBattle.cpp | 19 |
1 files changed, 16 insertions, 3 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; } |