diff options
Diffstat (limited to 'sim/src')
-rw-r--r-- | sim/src/Builder.cpp | 6 | ||||
-rw-r--r-- | sim/src/HitPoints.cpp | 15 |
2 files changed, 10 insertions, 11 deletions
diff --git a/sim/src/Builder.cpp b/sim/src/Builder.cpp index 279cd8b..64ca874 100644 --- a/sim/src/Builder.cpp +++ b/sim/src/Builder.cpp @@ -42,11 +42,7 @@ Builder::operator()(const universe::ShipType& ship_type, const int team) const ship_type.max_speed * 2.0, ship_type.max_speed * 3.0); registry.emplace<AIState>(entity, 15000.0, Point{0.0, 0.0}); - registry.emplace<HitPoints>( - entity, - ship_type.base_shield_points, - ship_type.base_armour_points, - ship_type.base_structure_points); + registry.emplace<HitPoints>(entity, ship_type); return entity; } diff --git a/sim/src/HitPoints.cpp b/sim/src/HitPoints.cpp index 251454d..f850451 100644 --- a/sim/src/HitPoints.cpp +++ b/sim/src/HitPoints.cpp @@ -1,5 +1,7 @@ #include <kurator/sim/HitPoints.h> +#include <kurator/universe/ShipType.h> + namespace kurator { @@ -7,10 +9,10 @@ namespace sim { -HitPoints::HitPoints(double base_shield, double base_armour, double base_structure) : - structure {base_structure}, - armour {base_armour}, - shield {base_shield} +HitPoints::HitPoints(const universe::ShipType& def) : + structure {def.base_structure_points, def.base_structure_resists}, + armour {def.base_armour_points, def.base_armour_resists}, + shield {def.base_shield_points, def.base_shield_resists} { } @@ -20,8 +22,9 @@ HitPoints::Layer::consume(double& damage) { if (damage <= 0.0 || points <= 0.0) return 0.0; - const double actual_damage = damage * resists; - const double left_to_deal = (actual_damage - points) / resists; + const double modifier = 1.0 - resists; + const double actual_damage = damage * modifier; + const double left_to_deal = (actual_damage - points) / modifier; points -= actual_damage; damage = left_to_deal; return actual_damage; |