From f315fbc3406b13aef4712d391661fad6bcf4872c Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 12 Dec 2022 18:38:14 +0100 Subject: Extracted effective damage calculation to universe --- sim/src/BaseBattle.cpp | 14 +------------- universe/CMakeLists.txt | 1 + universe/include/kurator/universe/TurretType.h | 1 + universe/src/TurretType.cpp | 23 +++++++++++++++++++++++ 4 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 universe/src/TurretType.cpp diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index 17dc739..448a5d7 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -1,8 +1,5 @@ #include "BaseBattle.h" -#include -#include - #include #include @@ -109,15 +106,6 @@ 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::round(std::pow(def.falloff_intensity, std::pow(falloff, 2)) * 1000) / 1000; -} - - void BaseBattle::turrets(const float dt) { @@ -138,7 +126,7 @@ BaseBattle::turrets(const float dt) const auto distance = transform.position - target.position; if (distance.magnitude() > def.optimal_range * 2.5) continue; - const auto damage = effective_damage(def, distance.magnitude()); + const auto damage = def.effective_damage(distance.magnitude()); if (damage > 0.0) { target_points.health -= damage; _dispatcher.trigger(Hit{damage, control.owner, state.target}); diff --git a/universe/CMakeLists.txt b/universe/CMakeLists.txt index bb7253f..daf55bc 100644 --- a/universe/CMakeLists.txt +++ b/universe/CMakeLists.txt @@ -3,6 +3,7 @@ add_library( ${PROJECT_NAME} src/NotFound.cpp src/SampleRepository.cpp + src/TurretType.cpp src/universe.cpp ) target_include_directories( diff --git a/universe/include/kurator/universe/TurretType.h b/universe/include/kurator/universe/TurretType.h index 7723d88..ff67cfe 100644 --- a/universe/include/kurator/universe/TurretType.h +++ b/universe/include/kurator/universe/TurretType.h @@ -17,6 +17,7 @@ struct TurretType double optimal_range; double falloff_modifier; double falloff_intensity; + double effective_damage(double distance) const; }; diff --git a/universe/src/TurretType.cpp b/universe/src/TurretType.cpp new file mode 100644 index 0000000..d213d07 --- /dev/null +++ b/universe/src/TurretType.cpp @@ -0,0 +1,23 @@ +#include + +#include +#include + + +namespace kurator +{ +namespace universe +{ + + +double +TurretType::effective_damage(const double distance) const +{ + const auto overflow = distance - optimal_range; + const auto falloff = std::max(0.0, overflow / optimal_range / falloff_modifier); + return base_damage * std::round(std::pow(falloff_intensity, std::pow(falloff, 2)) * 1000) / 1000; +} + + +} // namespace universe +} // namespace kurator -- cgit v1.1