diff options
Diffstat (limited to 'universe/src')
-rw-r--r-- | universe/src/JsonRepository.cpp | 3 | ||||
-rw-r--r-- | universe/src/TurretType.cpp | 28 |
2 files changed, 26 insertions, 5 deletions
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; } |