summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--universe/CMakeLists.txt10
-rw-r--r--universe/src/TurretType.cpp7
-rw-r--r--universe/tests/TurretType.cpp49
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