summaryrefslogtreecommitdiff
path: root/sim/src/HitPoints.cpp
blob: 251454d3baaec5519d7c7a3e855733f21dc5945d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <kurator/sim/HitPoints.h>


namespace kurator
{
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 || points <= 0.0)
		return 0.0;
	const double actual_damage = damage * resists;
	const double left_to_deal = (actual_damage - points) / resists;
	points -= actual_damage;
	damage = left_to_deal;
	return actual_damage;
}


double
HitPoints::deal(double damage)
{
	return shield.consume(damage) + armour.consume(damage) + structure.consume(damage);
}


bool
HitPoints::is_alive() const
{
	return structure.points > 0.0;
}


double
HitPoints::total() const
{
	return shield.points + armour.points + structure.points;
}


}  // namespace sim
}  // namespace kurator