summaryrefslogtreecommitdiff
path: root/sim/src
diff options
context:
space:
mode:
Diffstat (limited to 'sim/src')
-rw-r--r--sim/src/HitPoints.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/sim/src/HitPoints.cpp b/sim/src/HitPoints.cpp
index f850451..f23cafd 100644
--- a/sim/src/HitPoints.cpp
+++ b/sim/src/HitPoints.cpp
@@ -1,5 +1,7 @@
#include <kurator/sim/HitPoints.h>
+#include <algorithm>
+
#include <kurator/universe/ShipType.h>
@@ -23,11 +25,12 @@ HitPoints::Layer::consume(double& damage)
if (damage <= 0.0 || points <= 0.0)
return 0.0;
const double modifier = 1.0 - resists;
- const double actual_damage = damage * modifier;
- const double left_to_deal = (actual_damage - points) / modifier;
- points -= actual_damage;
+ const double potential_damage = damage * modifier;
+ const double taken_damage = std::min(potential_damage, points);
+ const double left_to_deal = (potential_damage - taken_damage) / modifier;
+ points -= taken_damage;
damage = left_to_deal;
- return actual_damage;
+ return taken_damage;
}