forked from maxortner01/ck2-Save-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacters.cpp
More file actions
214 lines (167 loc) · 3.66 KB
/
characters.cpp
File metadata and controls
214 lines (167 loc) · 3.66 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "characters.h"
namespace ck2
{
Attributes::Attributes(std::string line)
{
// Clean up the string from the dictionary
std::string str_attr;
str_attr = remove(line, '}');
str_attr = remove(str_attr, '{');
// Delimit the string with spaces
std::vector<std::string> ts = split(str_attr, ' ');
// Clean up each object
for (std::string &str : ts)
str = strip(str, ' ');
for (int i = 0; i < 5 && i < ts.size(); i++)
_vals[i] = std::stoi(ts.at(i));
}
// Getting the values
unsigned int Attributes::diplomacy() const
{
return _dip;
}
unsigned int Attributes::marshall() const
{
return _mart;
}
unsigned int Attributes::stewardship() const
{
return _stew;
}
unsigned int Attributes::intrigue() const
{
return _int;
}
unsigned int Attributes::learning() const
{
return _learn;
}
// Functions for getting data
std::string Character::name()
{
return getStringfromDict("bn");
}
std::string Character::birthDate()
{
return getStringfromDict("b_d");
}
std::string Character::deathDate()
{
return getStringfromDict("d_d");
}
std::string Character::religion()
{
return getStringfromDict("rel");
}
std::string Character::secret_religion()
{
return getStringfromDict("secret_religion");
}
std::string Character::government()
{
return getStringfromDict("gov");
}
std::string Character::title(bool formatted)
{
std::string title = getStringfromDict("title");
if (formatted && title.length() > 0)
{
title = std::string(title.begin() + 6, title.end());
title = strip(title, '\t');
auto title_split = split(title, '_');
for (std::string &str : title_split)
str[0] = toupper(str[0]);
title = combine(title_split, ' ');
return title;
}
return title;
}
std::string Character::nickname(bool formatted)
{
std::string nickname = getStringfromDict("nick");
if (formatted && nickname.length() > 0)
{
nickname = std::string(nickname.begin() + 5, nickname.end());
nickname = strip(nickname, '\t');
auto title_split = split(nickname, '_');
for (std::string &str : title_split)
str[0] = toupper(str[0]);
nickname = combine(title_split, ' ');
return nickname;
}
return nickname;
}
Attributes Character::attributes()
{
return Attributes(*dictionary.at("att"));
}
float Character::health()
{
return getFloatFromDict("health");
}
float Character::fertility()
{
return getFloatFromDict("fer");
}
float Character::wealth()
{
return getFloatFromDict("wealth");
}
float Character::piety()
{
return getFloatFromDict("piety");
}
float Character::prestige()
{
return getFloatFromDict("prs");
}
Character* Character::lover()
{
return getFromCharacterList("lover");
}
Character* Character::father()
{
return getFromCharacterList("fat");
}
Character* Character::mother()
{
return getFromCharacterList("mot");
}
Character* Character::spouse()
{
return getFromCharacterList("spouse");
}
Character* Character::host()
{
return getFromCharacterList("host");
}
Dynasty* Character::dynasty()
{
std::string d_str = getStringfromDict("dnt");
if (d_str == "") return nullptr;
return dynastyList->at(std::stoi(d_str));
}
std::vector<Character*> Character::children()
{
try {
return *childList->at(ID);
}
catch (...)
{
return {};
}
}
Character* Character::getFromCharacterList(std::string key)
{
try
{
if (!dictionary.at(key)) return nullptr;
int id = std::stoi(*dictionary.at(key));
return characterList->at(id);
}
catch (...)
{
return nullptr;
}
}
}