summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-01-08 15:38:00 +0100
committerAki <please@ignore.pl>2023-01-08 15:38:00 +0100
commit209648a39c98ccddc622703554912a21c2471531 (patch)
tree3e322af8eefd566cdf2b5d6f997431c6d6a184b4 /sim
parent088f57155c79c5ee41e667496e2cd657af91a605 (diff)
downloadkurator-209648a39c98ccddc622703554912a21c2471531.zip
kurator-209648a39c98ccddc622703554912a21c2471531.tar.gz
kurator-209648a39c98ccddc622703554912a21c2471531.tar.bz2
Implemented naive armour and shield without parametrized resits
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;
}