summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-04 02:33:18 +0100
committerAki <please@ignore.pl>2023-02-04 02:33:18 +0100
commit9a456b0e0d2f5505ced3751a0bbfc10c2dd1d233 (patch)
treea04ee380db847328e20361fffae461a8a4467a69
parentfb1d3eda51cd9d89083130cf9932c7bde758756c (diff)
downloadkurator-9a456b0e0d2f5505ced3751a0bbfc10c2dd1d233.zip
kurator-9a456b0e0d2f5505ced3751a0bbfc10c2dd1d233.tar.gz
kurator-9a456b0e0d2f5505ced3751a0bbfc10c2dd1d233.tar.bz2
Ship types JSON now support base_*_resists entries
-rw-r--r--sim/include/kurator/sim/HitPoints.h6
-rw-r--r--sim/src/Builder.cpp6
-rw-r--r--sim/src/HitPoints.cpp15
-rw-r--r--universe/include/kurator/universe/ShipType.h3
-rw-r--r--universe/src/JsonRepository.cpp33
5 files changed, 36 insertions, 27 deletions
diff --git a/sim/include/kurator/sim/HitPoints.h b/sim/include/kurator/sim/HitPoints.h
index 0004999..7cd82f3 100644
--- a/sim/include/kurator/sim/HitPoints.h
+++ b/sim/include/kurator/sim/HitPoints.h
@@ -1,5 +1,7 @@
#pragma once
+#include <kurator/universe/ShipType.h>
+
namespace kurator
{
@@ -9,12 +11,12 @@ namespace sim
struct HitPoints
{
- HitPoints(double base_shield, double base_armour, double base_structure);
+ HitPoints(const universe::ShipType& def);
struct Layer
{
double points;
- double resists = 0.7;
+ double resists = 0.3;
double consume(double& damage);
};
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;
diff --git a/universe/include/kurator/universe/ShipType.h b/universe/include/kurator/universe/ShipType.h
index c98a865..164dd9b 100644
--- a/universe/include/kurator/universe/ShipType.h
+++ b/universe/include/kurator/universe/ShipType.h
@@ -16,6 +16,9 @@ struct ShipType
double base_armour_points;
double base_shield_points;
double max_speed;
+ double base_structure_resists = 0.3;
+ double base_armour_resists = 0.3;
+ double base_shield_resists = 0.3;
};
diff --git a/universe/src/JsonRepository.cpp b/universe/src/JsonRepository.cpp
index 0100eb6..5d15646 100644
--- a/universe/src/JsonRepository.cpp
+++ b/universe/src/JsonRepository.cpp
@@ -22,6 +22,15 @@ namespace universe
{
+template <typename Type>
+void
+maybe_to(const json& item, const char* member, Type& output)
+{
+ if (item.contains(member))
+ item.at(member).get_to(output);
+}
+
+
void
from_json(const json& item, ShipType& ship)
{
@@ -30,6 +39,9 @@ from_json(const json& item, ShipType& ship)
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);
+ maybe_to(item, "base_structure_resists", ship.base_structure_resists);
+ maybe_to(item, "base_armour_resists", ship.base_armour_resists);
+ maybe_to(item, "base_shield_resists", ship.base_shield_resists);
}
@@ -37,20 +49,13 @@ void
from_json(const json& item, TurretType& turret)
{
item.at("name").get_to(turret.name);
- if (item.contains("base_damage"))
- item.at("base_damage").get_to(turret.base_damage);
- if (item.contains("rounds"))
- item.at("rounds").get_to(turret.rounds);
- if (item.contains("rate_of_fire"))
- item.at("rate_of_fire").get_to(turret.rate_of_fire);
- if (item.contains("reload"))
- item.at("reload").get_to(turret.reload);
- if (item.contains("optimal_range"))
- item.at("optimal_range").get_to(turret.optimal_range);
- if (item.contains("falloff_modifier"))
- item.at("falloff_modifier").get_to(turret.falloff_modifier);
- if (item.contains("falloff_intensity"))
- item.at("falloff_intensity").get_to(turret.falloff_intensity);
+ maybe_to(item, "base_damage", turret.base_damage);
+ maybe_to(item, "rounds", turret.rounds);
+ maybe_to(item, "rate_of_fire", turret.rate_of_fire);
+ maybe_to(item, "reload", turret.reload);
+ maybe_to(item, "optimal_range", turret.optimal_range);
+ maybe_to(item, "falloff_modifier", turret.falloff_modifier);
+ maybe_to(item, "falloff_intensity", turret.falloff_intensity);
}