summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
Diffstat (limited to 'sim')
-rw-r--r--sim/include/kurator/sim/HitPoints.h14
-rw-r--r--sim/src/Builder.cpp6
-rw-r--r--sim/src/HitPoints.cpp29
3 files changed, 41 insertions, 8 deletions
diff --git a/sim/include/kurator/sim/HitPoints.h b/sim/include/kurator/sim/HitPoints.h
index b9a8523..0004999 100644
--- a/sim/include/kurator/sim/HitPoints.h
+++ b/sim/include/kurator/sim/HitPoints.h
@@ -9,8 +9,18 @@ namespace sim
struct HitPoints
{
- double structure;
- double structure_resists = 0.7;
+ HitPoints(double base_shield, double base_armour, double base_structure);
+
+ struct Layer
+ {
+ double points;
+ double resists = 0.7;
+ double consume(double& damage);
+ };
+
+ Layer structure;
+ Layer armour;
+ Layer shield;
double deal(double damage);
bool is_alive() const;
double total() const;
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;
}