From 1e0cb31ec62a5895c475a52c4e0066672047416f Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 31 Dec 2022 22:50:55 +0100 Subject: Extracted method to deal damage to hit points --- sim/CMakeLists.txt | 1 + sim/include/kurator/sim/HitPoints.h | 1 + sim/src/HitPoints.cpp | 18 ++++++++++++++++++ sim/src/TurretControl.cpp | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 sim/src/HitPoints.cpp (limited to 'sim') diff --git a/sim/CMakeLists.txt b/sim/CMakeLists.txt index e10056a..b8c3a89 100644 --- a/sim/CMakeLists.txt +++ b/sim/CMakeLists.txt @@ -5,6 +5,7 @@ add_library( src/Battle.cpp src/Builder.cpp src/FloatingMovement.cpp + src/HitPoints.cpp src/Point.cpp src/RandomSpawner.cpp src/TeamManager.cpp diff --git a/sim/include/kurator/sim/HitPoints.h b/sim/include/kurator/sim/HitPoints.h index 20cffc2..feda050 100644 --- a/sim/include/kurator/sim/HitPoints.h +++ b/sim/include/kurator/sim/HitPoints.h @@ -10,6 +10,7 @@ namespace sim struct HitPoints { double health; + void deal(double damage); }; diff --git a/sim/src/HitPoints.cpp b/sim/src/HitPoints.cpp new file mode 100644 index 0000000..4f2ff81 --- /dev/null +++ b/sim/src/HitPoints.cpp @@ -0,0 +1,18 @@ +#include + + +namespace kurator +{ +namespace sim +{ + + +void +HitPoints::deal(double damage) +{ + health -= damage; +} + + +} // namespace sim +} // namespace kurator diff --git a/sim/src/TurretControl.cpp b/sim/src/TurretControl.cpp index 56083f1..6513f39 100644 --- a/sim/src/TurretControl.cpp +++ b/sim/src/TurretControl.cpp @@ -44,7 +44,7 @@ TurretControl::update(entt::registry& registry, entt::dispatcher& dispatcher, co auto& target_points = registry.get(state.target); const auto damage = def.effective_damage(distance); if (damage > 0.0) { - target_points.health -= damage; + target_points.deal(damage); dispatcher.trigger(Hit{damage, control.owner, state.target}); } control.delay = def.rate_of_fire; -- cgit v1.1