From 209648a39c98ccddc622703554912a21c2471531 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 8 Jan 2023 15:38:00 +0100 Subject: Implemented naive armour and shield without parametrized resits --- sim/include/kurator/sim/HitPoints.h | 14 ++++++++++++-- sim/src/Builder.cpp | 6 +++++- sim/src/HitPoints.cpp | 29 +++++++++++++++++++++++----- universe/include/kurator/universe/ShipType.h | 2 ++ universe/resources/universe/ship_types.json | 6 ++++++ universe/src/JsonRepository.cpp | 2 ++ 6 files changed, 51 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(entity, 6000.0, Point{0.0, 0.0}); - registry.emplace(entity, ship_type.base_structure_points); + registry.emplace( + 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; } diff --git a/universe/include/kurator/universe/ShipType.h b/universe/include/kurator/universe/ShipType.h index fdbb8af..c98a865 100644 --- a/universe/include/kurator/universe/ShipType.h +++ b/universe/include/kurator/universe/ShipType.h @@ -13,6 +13,8 @@ struct ShipType { std::string name; double base_structure_points; + double base_armour_points; + double base_shield_points; double max_speed; }; diff --git a/universe/resources/universe/ship_types.json b/universe/resources/universe/ship_types.json index cc2d892..0e7bc89 100644 --- a/universe/resources/universe/ship_types.json +++ b/universe/resources/universe/ship_types.json @@ -2,16 +2,22 @@ { "name": "Anvil", "base_structure_points": 600.0, + "base_armour_points": 400.0, + "base_shield_points": 3700.0, "max_speed": 218.0 }, { "name": "Eclipse", "base_structure_points": 600.0, + "base_armour_points": 950.0, + "base_shield_points": 200.0, "max_speed": 263.0 }, { "name": "Warbringer", "base_structure_points": 600.0, + "base_armour_points": 400.0, + "base_shield_points": 1400.0, "max_speed": 336.0 } ] diff --git a/universe/src/JsonRepository.cpp b/universe/src/JsonRepository.cpp index 40b0b70..e8c8ed3 100644 --- a/universe/src/JsonRepository.cpp +++ b/universe/src/JsonRepository.cpp @@ -27,6 +27,8 @@ from_json(const json& item, ShipType& ship) { item.at("name").get_to(ship.name); item.at("base_structure_points").get_to(ship.base_structure_points); + item.at("base_armour_points").get_to(ship.base_armour_points); + item.at("base_shield_points").get_to(ship.base_shield_points); item.at("max_speed").get_to(ship.max_speed); } -- cgit v1.1