-
Notifications
You must be signed in to change notification settings - Fork 30
/
damage_set.cpp
67 lines (57 loc) · 1.07 KB
/
damage_set.cpp
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
60
61
62
63
64
65
66
#include "damage_set.h"
Damage_set::Damage_set()
{
for (int i = 0; i < DAMAGE_MAX; i++) {
damage[i] = 0;
}
}
Damage_set::~Damage_set()
{
}
void Damage_set::set_damage(Damage_type type, int amount)
{
damage[type] = amount;
}
void Damage_set::set_damage(int index, int amount)
{
if (index < 0 || index >= DAMAGE_MAX) {
return;
}
damage[index] = amount;
}
int Damage_set::get_damage(Damage_type type) const
{
return damage[type];
}
int Damage_set::get_damage(int index) const
{
if (index < 0 || index >= DAMAGE_MAX) {
return 0;
}
return damage[index];
}
int Damage_set::total_damage()
{
int ret = 0;
for (int i = 0; i < DAMAGE_MAX; i++) {
ret += get_damage(i);
}
return ret;
}
Damage_set& Damage_set::operator+=(const Damage_set& rhs)
{
for (int i = 0; i < DAMAGE_MAX; i++) {
damage[i] += rhs.get_damage(i);
}
return *this;
}
Damage_set& Damage_set::operator-=(const Damage_set& rhs)
{
for (int i = 0; i < DAMAGE_MAX; i++) {
damage[i] -= rhs.get_damage(i);
if (damage[i] < 0) {
damage[i] = 0;
}
}
return *this;
}