-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerClass.h
61 lines (53 loc) · 1.3 KB
/
PlayerClass.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
#ifndef PLAYERCLASS_H
#define PLAYERCLASS_H
#include <string>
#include <unordered_map>
#define STR(x) #x
#define PCLASS(cls) uint8_t cls=addNewClass(STR(cls))
class PlayerClass {
private:
static std::unordered_map<uint8_t, std::string> classLookup;
uint8_t pclass_inc;
uint8_t addNewClass(std::string className) {
for (auto&& pair : classLookup) {
if (pair.second == className) {
return pair.first;
}
}
classLookup.insert({pclass_inc, className});
return pclass_inc++;
}
public:
PlayerClass(){}
~PlayerClass() {
}
PCLASS(WARRIOR);
PCLASS(PALADIN);
PCLASS(SHAMAN);
PCLASS(ROGUE);
PCLASS(MAGE);
PCLASS(WARLOCK);
PCLASS(PRIEST);
PCLASS(HUNTER);
PCLASS(DRUID);
uint8_t cls;
static PlayerClass getClassByName(std::string name) {
PlayerClass pc;
pc.cls = 0;
for (auto& it : classLookup) {
if (it.second == name) {
pc.cls = it.first;
break;
}
}
return pc;
}
std::string getClassName() {
auto&& it = classLookup.find(this->cls);
if (it != classLookup.end()) {
return it->second;
}
return "";
}
};
#endif // PLAYERCLASS_H