blob: f23cafde01f39e57ff797464cd21b387a07c008e (
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
54
55
56
57
58
59
|
#include <kurator/sim/HitPoints.h>
#include <algorithm>
#include <kurator/universe/ShipType.h>
namespace kurator
{
namespace sim
{
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}
{
}
double
HitPoints::Layer::consume(double& damage)
{
if (damage <= 0.0 || points <= 0.0)
return 0.0;
const double modifier = 1.0 - resists;
const double potential_damage = damage * modifier;
const double taken_damage = std::min(potential_damage, points);
const double left_to_deal = (potential_damage - taken_damage) / modifier;
points -= taken_damage;
damage = left_to_deal;
return taken_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
|