diff options
-rw-r--r-- | kurator/src/inspect.cpp | 5 | ||||
-rw-r--r-- | sim/src/TurretControl.cpp | 4 | ||||
-rw-r--r-- | universe/CMakeLists.txt | 10 | ||||
-rw-r--r-- | universe/include/kurator/universe/TurretType.h | 7 | ||||
-rw-r--r-- | universe/resources/universe/turret_types.json | 18 | ||||
-rw-r--r-- | universe/src/JsonRepository.cpp | 3 | ||||
-rw-r--r-- | universe/src/TurretType.cpp | 28 | ||||
-rw-r--r-- | universe/tests/TurretType.cpp | 49 |
8 files changed, 110 insertions, 14 deletions
diff --git a/kurator/src/inspect.cpp b/kurator/src/inspect.cpp index fa62010..454700e 100644 --- a/kurator/src/inspect.cpp +++ b/kurator/src/inspect.cpp @@ -141,8 +141,11 @@ inspect(entt::handle&, universe::TurretType& type) slider_double("Rate of Fire", &type.rate_of_fire, 0, 60.0, "%.3f"); slider_double("Reload", &type.reload, 0, 60.0, "%.3f"); slider_double("Optimal Range", &type.optimal_range, 0, 30000.0, "%.1f"); - slider_double("Falloff Modifier", &type.falloff_modifier, 0, 1.0, "%.3f"); + slider_double("Falloff Modifier", &type.falloff_modifier, 0, 5.0, "%.3f"); slider_double("Falloff Intensity", &type.falloff_intensity, 0, 1.0, "%.3f"); + slider_double("Tracking", &type.tracking, 0, 1000.0, "%.1f"); + slider_double("Tracking Factor", &type.tracking_factor, 0, 10.0, "%.3f"); + slider_double("Tracking Exponent", &type.tracking_exponent, 0, 2.0, "%.3f"); } diff --git a/sim/src/TurretControl.cpp b/sim/src/TurretControl.cpp index ba54f3f..51f2a46 100644 --- a/sim/src/TurretControl.cpp +++ b/sim/src/TurretControl.cpp @@ -1,6 +1,7 @@ #include <kurator/sim/TurretControl.h> #include <kurator/sim/components.h> +#include <kurator/sim/FloatingMovement.h> #include <kurator/sim/HitPoints.h> #include <kurator/sim/events.h> #include <kurator/sim/State.h> @@ -40,7 +41,8 @@ TurretControl::update(State& ctx) control.rounds = def.rounds; if (control.rounds > 0 && consume(remaining_dt, control.delay)) { auto& target_points = ctx.registry.get<HitPoints>(state.target); - auto damage = def.effective_damage(distance); + const auto& movement = ctx.registry.get<FloatingMovement>(state.target); + auto damage = def.effective_damage(distance, movement.speed.magnitude()); if (damage > 0.0) { damage = target_points.deal(damage); ctx.dispatcher.trigger(Hit{damage, control.owner, state.target}); 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/include/kurator/universe/TurretType.h b/universe/include/kurator/universe/TurretType.h index c7ba5a3..7b3ebdc 100644 --- a/universe/include/kurator/universe/TurretType.h +++ b/universe/include/kurator/universe/TurretType.h @@ -19,7 +19,12 @@ struct TurretType double optimal_range = 0.0; double falloff_modifier = 0.05; double falloff_intensity = 0.2; - double effective_damage(double distance) const; + double tracking = 1000; + double tracking_factor = 3.0; + double tracking_exponent = 0.5; + double effective_damage(double distance, double speed) const; + double range_modifier(double distance) const; + double tracking_modifier(double distance, double speed) const; double effective_range() const; double damage_per_second() const; }; diff --git a/universe/resources/universe/turret_types.json b/universe/resources/universe/turret_types.json index 0b4e3ca..0004ef1 100644 --- a/universe/resources/universe/turret_types.json +++ b/universe/resources/universe/turret_types.json @@ -6,7 +6,8 @@ "rate_of_fire": 4.5, "reload": 0.0, "optimal_range": 7000.0, - "falloff_modifier": 0.05 + "falloff_modifier": 0.05, + "tracking": 150.0 }, { "name": "BurstLaser", @@ -15,7 +16,8 @@ "rate_of_fire": 0.25, "reload": 2.75, "optimal_range": 3500.0, - "falloff_modifier": 0.05 + "falloff_modifier": 0.05, + "tracking": 260.0 }, { "name": "GaussCannon", @@ -24,7 +26,8 @@ "rate_of_fire": 0.0, "reload": 5.5, "optimal_range": 12000.0, - "falloff_modifier": 0.2 + "falloff_modifier": 0.2, + "tracking": 35.0 }, { "name": "Autocannon", @@ -33,7 +36,8 @@ "rate_of_fire": 0.15, "reload": 1.5, "optimal_range": 2000, - "falloff_modifier": 0.8 + "falloff_modifier": 0.8, + "tracking": 350.0 }, { "name": "Howitzer", @@ -42,7 +46,8 @@ "rate_of_fire": 7.5, "reload": 0, "optimal_range": 5600, - "falloff_modifier": 0.5 + "falloff_modifier": 0.5, + "tracking": 60.0 }, { "name": "Blaster", @@ -51,6 +56,7 @@ "rate_of_fire": 0, "reload": 2, "optimal_range": 750, - "falloff_modifier": 0.45 + "falloff_modifier": 0.45, + "tracking": 450.0 } ] diff --git a/universe/src/JsonRepository.cpp b/universe/src/JsonRepository.cpp index 5d15646..dbfb8ea 100644 --- a/universe/src/JsonRepository.cpp +++ b/universe/src/JsonRepository.cpp @@ -56,6 +56,9 @@ from_json(const json& item, TurretType& turret) maybe_to(item, "optimal_range", turret.optimal_range); maybe_to(item, "falloff_modifier", turret.falloff_modifier); maybe_to(item, "falloff_intensity", turret.falloff_intensity); + maybe_to(item, "tracking", turret.tracking); + maybe_to(item, "tracking_factor", turret.tracking_factor); + maybe_to(item, "tracking_exponent", turret.tracking_exponent); } diff --git a/universe/src/TurretType.cpp b/universe/src/TurretType.cpp index 78887d7..4da47ef 100644 --- a/universe/src/TurretType.cpp +++ b/universe/src/TurretType.cpp @@ -11,20 +11,38 @@ namespace universe double -TurretType::effective_damage(const double distance) const +TurretType::effective_damage(const double distance, const double speed) const +{ + return base_damage * std::round(range_modifier(distance) * tracking_modifier(distance, speed) * 1000) / 1000; +} + + +double +TurretType::range_modifier(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; + return std::pow(falloff_intensity, std::pow(falloff, 2)); +} + + +double +TurretType::tracking_modifier(const double distance, const double speed) const +{ + const auto simplified_falloff = optimal_range + optimal_range * falloff_modifier; + const auto by_distance = (distance + 1.0) / simplified_falloff; + const auto by_speed = tracking / (speed + 1.0); + return std::min(1.0, std::pow(tracking_factor * by_distance * by_speed, tracking_exponent)); } 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 |