diff options
author | Aki <please@ignore.pl> | 2023-02-28 00:06:05 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-02-28 00:06:32 +0100 |
commit | 4e1f59b5c6689e38023f12daee7d5c6f3d4715e5 (patch) | |
tree | 38a06dbd1bfb596cb1cc1d1fceb9ec28e5b8f534 /universe | |
parent | 5f59cc347bcfd2236f01532511974078aacde980 (diff) | |
download | kurator-4e1f59b5c6689e38023f12daee7d5c6f3d4715e5.zip kurator-4e1f59b5c6689e38023f12daee7d5c6f3d4715e5.tar.gz kurator-4e1f59b5c6689e38023f12daee7d5c6f3d4715e5.tar.bz2 |
Turrets will now start shooting when they can deal 1 dmg point
Previously they were shooting at 1% base damage range, meaning higher
damage turrets were cut off earlier.
Diffstat (limited to 'universe')
-rw-r--r-- | universe/CMakeLists.txt | 10 | ||||
-rw-r--r-- | universe/src/TurretType.cpp | 7 | ||||
-rw-r--r-- | universe/tests/TurretType.cpp | 49 |
3 files changed, 63 insertions, 3 deletions
diff --git a/universe/CMakeLists.txt b/universe/CMakeLists.txt index 1728f1c..c3d56f8 100644 --- a/universe/CMakeLists.txt +++ b/universe/CMakeLists.txt @@ -15,3 +15,13 @@ add_resources( resources/universe/ship_types.json resources/universe/turret_types.json ) +add_executable( + ${PROJECT_NAME}_test + tests/TurretType.cpp +) +target_link_libraries( + ${PROJECT_NAME}_test + PRIVATE ${PROJECT_NAME} + PRIVATE GTest::gtest_main +) +gtest_discover_tests(${PROJECT_NAME}_test) diff --git a/universe/src/TurretType.cpp b/universe/src/TurretType.cpp index 0dc6be6..b64efd4 100644 --- a/universe/src/TurretType.cpp +++ b/universe/src/TurretType.cpp @@ -29,9 +29,10 @@ TurretType::range_modifier(const double distance) const double TurretType::effective_range() const { - const double target_falloff = std::sqrt(std::log2(0.01) / std::log2(falloff_intensity)); - const double one_percent_overflow = target_falloff * falloff_modifier * optimal_range; - return one_percent_overflow + optimal_range; + const double one_point = 1.0 / base_damage; + const double target_falloff = std::sqrt(std::log2(one_point) / std::log2(falloff_intensity)); + const double one_point_overflow = target_falloff * falloff_modifier * optimal_range; + return one_point_overflow + optimal_range; } diff --git a/universe/tests/TurretType.cpp b/universe/tests/TurretType.cpp new file mode 100644 index 0000000..7ce70c0 --- /dev/null +++ b/universe/tests/TurretType.cpp @@ -0,0 +1,49 @@ +#include <gtest/gtest.h> + +#include <kurator/universe/TurretType.h> + + +namespace kurator +{ +namespace tests +{ + + +const universe::TurretType LOW { + "", + 1, + 10.0, + 1.0, + 0.0, + 1000.0, + 0.05, + 0.2, +}; + + +const universe::TurretType HIGH { + "", + 1, + 1000.0, + 1.0, + 0.0, + 1000.0, + 0.05, + 0.2, +}; + + + +TEST(TurretType, effective_range) +{ + const auto low = LOW.effective_range(); + EXPECT_LE(1.0, LOW.range_modifier(low - 1.0) * LOW.base_damage); + EXPECT_GE(1.0, LOW.range_modifier(low + 1.0) * LOW.base_damage); + const auto high = HIGH.effective_range(); + EXPECT_LE(1.0, HIGH.range_modifier(high - 1.0) * HIGH.base_damage); + EXPECT_GE(1.0, HIGH.range_modifier(high + 1.0) * HIGH.base_damage); +} + + +} // namespace tests +} // namespace kurator |