-
Notifications
You must be signed in to change notification settings - Fork 14
/
achievement.h
81 lines (75 loc) · 2.03 KB
/
achievement.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef ACHIEVEMENT_H_INCLUDED
#define ACHIEVEMENT_H_INCLUDED
#include <sstream>
enum Comparator
{
equal,
great_equal,
less_equal
};
class Counter
{
public:
unsigned m_target;
Comparator m_comparator;
public:
Counter(unsigned target=1, Comparator comparator=great_equal): m_target(target), m_comparator(comparator) {}
void init(unsigned target, Comparator comparator)
{
m_target = target;
m_comparator = comparator;
}
bool check(unsigned value) const
{
switch(m_comparator)
{
case equal: return value == m_target;
case great_equal: return value >= m_target;
case less_equal: return value <= m_target;
default: throw;
}
}
// predict whether the monotonic increasing counter will be met: +1: true; 0: unknown; -1: false.
int predict_monoinc(unsigned value) const
{
switch(m_comparator)
{
case equal:
case less_equal: return value <= m_target ? 0 : -1;
case great_equal: return value < m_target ? 0 : +1;
default: throw;
}
}
std::string str() const
{
std::stringstream ios;
switch(m_comparator)
{
case equal: ios << " = "; break;
case great_equal: ios << " >= "; break;
case less_equal: ios << " <= "; break;
default: throw;
}
ios << m_target;
return ios.str();
}
};
class Achievement
{
public:
unsigned id;
std::string name;
Counter mission_condition;
std::vector<Counter> req_counter;
// Following are indexes to the req_counter
std::map<unsigned, unsigned> skill_used;
std::map<unsigned, unsigned> unit_played;
std::map<unsigned, unsigned> unit_type_played;
std::map<unsigned, unsigned> unit_faction_played;
std::map<unsigned, unsigned> unit_rarity_played;
std::map<unsigned, unsigned> unit_type_killed;
std::map<unsigned, unsigned> unit_with_skill_killed;
std::map<unsigned, unsigned> misc_req;
Achievement() : id(0) {}
};
#endif