diff options
author | Aki <please@ignore.pl> | 2023-01-08 15:38:00 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-01-08 15:38:00 +0100 |
commit | 209648a39c98ccddc622703554912a21c2471531 (patch) | |
tree | 3e322af8eefd566cdf2b5d6f997431c6d6a184b4 /sim/src | |
parent | 088f57155c79c5ee41e667496e2cd657af91a605 (diff) | |
download | kurator-209648a39c98ccddc622703554912a21c2471531.zip kurator-209648a39c98ccddc622703554912a21c2471531.tar.gz kurator-209648a39c98ccddc622703554912a21c2471531.tar.bz2 |
Implemented naive armour and shield without parametrized resits
Diffstat (limited to 'sim/src')
-rw-r--r-- | sim/src/Builder.cpp | 6 | ||||
-rw-r--r-- | sim/src/HitPoints.cpp | 29 |
2 files changed, 29 insertions, 6 deletions
diff --git a/sim/src/Builder.cpp b/sim/src/Builder.cpp index f1e4762..e6984fe 100644 --- a/sim/src/Builder.cpp +++ b/sim/src/Builder.cpp @@ -39,7 +39,11 @@ 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, 6000.0, Point{0.0, 0.0}); - registry.emplace<HitPoints>(entity, ship_type.base_structure_points); + registry.emplace<HitPoints>( + entity, + ship_type.base_shield_points, + ship_type.base_armour_points, + ship_type.base_structure_points); return entity; } diff --git a/sim/src/HitPoints.cpp b/sim/src/HitPoints.cpp index d83c369..a214f42 100644 --- a/sim/src/HitPoints.cpp +++ b/sim/src/HitPoints.cpp @@ -7,26 +7,45 @@ namespace sim { +HitPoints::HitPoints(double base_shield, double base_armour, double base_structure) : + structure {base_structure}, + armour {base_armour}, + shield {base_shield} +{ +} + + +double +HitPoints::Layer::consume(double& damage) +{ + if (damage <= 0.0) + return 0.0; + const double left_to_deal = damage - points; + const double actual_damage = damage * resists; + points -= damage * resists; + damage = left_to_deal; + return actual_damage; +} + + double HitPoints::deal(double damage) { - damage *= structure_resists; - structure -= damage; - return damage; + return shield.consume(damage) + armour.consume(damage) + structure.consume(damage); } bool HitPoints::is_alive() const { - return structure > 0.0; + return structure.points > 0.0; } double HitPoints::total() const { - return structure; + return shield.points + armour.points + structure.points; } |