-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathcreature_name.cpp
145 lines (118 loc) · 3.21 KB
/
creature_name.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
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
#include "stdafx.h"
#include "creature_name.h"
#include "util.h"
#include "name_generator.h"
#include "t_string.h"
CreatureName::CreatureName(const TString& n) : name(n) {
CHECK(!name.empty());
}
CreatureName::CreatureName(const TString& n, const TString& p) : name(n), pluralName(p) {
CHECK(!name.empty());
CHECK(!pluralName.empty());
}
const char* CreatureName::identify() const {
return name.text.visit(
[](const TSentence& elem) { return elem.id.data(); },
[](const string& elem) { return elem.data(); }
);
}
TString CreatureName::bare() const {
if (fullTitle && firstName)
return title();
else
return name;
}
TString CreatureName::the() const {
if (fullTitle)
return title();
else
return TSentence("THE_ARTICLE", name);
}
TString CreatureName::a() const {
if (fullTitle)
return title();
else
return TSentence("A_ARTICLE", name);
}
TString CreatureName::plural() const {
return pluralName;
}
TString CreatureName::getGroupName() const {
return groupName;
}
TString CreatureName::title() const {
if (firstName)
return TSentence("CREATURE_TITLE", TString(*firstName), killTitle ? *killTitle : name);
else {
if (killTitle)
return TSentence("CREATURE_TITLE", capitalFirst(bare()), *killTitle);
else
return capitalFirst(bare());
}
}
TString CreatureName::aOrTitle() const {
if (firstName)
return TSentence("CREATURE_TITLE", TString(*firstName), killTitle ? *killTitle : name);
else {
if (killTitle)
return TSentence("CREATURE_TITLE", capitalFirst(bare()), *killTitle);
else
return a();
}
}
void CreatureName::setFirst(optional<string> s) {
firstName = s;
}
void CreatureName::generateFirst(NameGenerator* generator) {
if (firstNameGen)
firstName = generator->getNext(*firstNameGen);
}
optional<NameGeneratorId> CreatureName::getNameGenerator() const {
return firstNameGen;
}
void CreatureName::setStack(const TString& s) {
stackName = s;
}
void CreatureName::setBare(const TString& s) {
name = s;
}
void CreatureName::modifyName(TStringId id) {
name = TSentence(std::move(id), std::move(name));
}
const optional<TString>& CreatureName::stackOnly() const {
return stackName;
}
const TString& CreatureName::stack() const {
if (stackName)
return *stackName;
else
return name;
}
const optional<string>& CreatureName::first() const {
return firstName;
}
TString CreatureName::firstOrBare() const {
if (firstName)
return TString(*firstName);
else
return capitalFirst(bare());
}
void CreatureName::useFullTitle(bool b) {
fullTitle = b;
}
void CreatureName::setKillTitle(optional<TString> t) {
killTitle = std::move(t);
}
template <class Archive>
void CreatureName::serialize(Archive& ar, const unsigned int version) {
ar(name, pluralName, stackName, firstName, groupName, fullTitle, firstNameGen, killTitle);
}
SERIALIZABLE(CreatureName);
SERIALIZATION_CONSTRUCTOR_IMPL(CreatureName);
#include "pretty_archive.h"
template<>
void CreatureName::serialize(PrettyInputArchive& ar1, unsigned) {
ar1(NAMED(name), OPTION(pluralName), NAMED(stackName), NAMED(firstNameGen), NAMED(firstName), OPTION(groupName), OPTION(fullTitle), endInput());
if (pluralName.empty())
pluralName = makePlural(name);
}