forked from Whales/Cataclysm2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus_effect.cpp
More file actions
230 lines (200 loc) · 5.28 KB
/
Copy pathstatus_effect.cpp
File metadata and controls
230 lines (200 loc) · 5.28 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include "status_effect.h"
#include "stringfunc.h" // For no_caps and trim
#include "window.h" // For debugmsg
#include "entity.h" // For Stats
Status_effect::Status_effect()
{
type = STATUS_NULL;
duration = 0;
level = 1;
}
Status_effect::Status_effect(Status_effect_type _type, int _duration, int _level)
{
type = _type;
duration = _duration;
level = _level;
}
Status_effect::~Status_effect()
{
}
Status_effect& Status_effect::operator=(const Status_effect& rhs)
{
type = rhs.type;
duration = rhs.duration;
level = rhs.level;
step_down.clear();
for (int i = 0; i < rhs.step_down.size(); i++) {
step_down.push_back(rhs.step_down[i]);
}
return *this;
}
bool Status_effect::load_data(std::istream& data, std::string owner_name)
{
std::string ident, junk;
while (ident != "done" && !data.eof()) {
if ( ! (data >> ident) ) {
return false;
}
ident = no_caps(ident);
if (!ident.empty() && ident[0] == '#') {
// It's a comment
std::getline(data, junk);
} else if (ident == "type:" || ident == "type:") {
std::string typestr;
std::getline(data, typestr);
typestr = no_caps(typestr);
typestr = trim(typestr);
type = lookup_status_effect(typestr);
if (type == STATUS_NULL) {
debugmsg("Unknown Status_effect_type '%s' (%s)", typestr.c_str(),
owner_name.c_str());
return false;
}
} else if (ident == "duration:") {
data >> duration;
std::getline(data, junk);
} else if (ident == "level:") {
data >> level;
std::getline(data, junk);
} else if (ident != "done") {
debugmsg("Unknown Status_effect property '%s' (%s)", ident.c_str(),
owner_name.c_str());
return false;
}
}
return true;
}
std::string Status_effect::get_name()
{
return status_effect_name(type);
}
void Status_effect::boost(int dur, int lev)
{
int old_dur = duration;
duration += dur;
level += lev;
/* Set many step_down points; first when we hit our current duration, more
* evenly spaced between the current duration and the new duration.
*/
if (lev > 0) {
int gap = dur / lev;
for (int i = 0; i < lev; i++) {
step_down.push_back(old_dur);
old_dur += gap;
}
}
}
void Status_effect::boost(const Status_effect& rhs)
{
boost(rhs.duration, rhs.level);
}
bool Status_effect::decrement()
{
duration--;
if (!step_down.empty() && duration <= step_down.back()) {
step_down.pop_back();
if (level > 1) {
level--;
}
}
return (duration <= 0);
}
int Status_effect::speed_mod()
{
switch (type) {
case STATUS_CAFFEINE:
return 3;
case STATUS_STIMULANT:
if (level >= 5) {
return 15;
} else if (level >= 3) {
return 10;
} else {
return 5;
}
break;
}
return 0;
}
Stats Status_effect::stats_mod()
{
Stats ret(0, 0, 0, 0);
switch (type) {
case STATUS_CAFFEINE:
ret.intelligence++;
ret.perception++;
break;
case STATUS_NICOTINE:
if (level <= 2) {
ret.dexterity++;
ret.intelligence++;
ret.perception++;
}
break;
case STATUS_STIMULANT:
ret.dexterity++;
ret.intelligence += (level > 3 ? 3 : level);
ret.perception += (level > 2 ? 2 : level);
break;
case STATUS_PAINKILL_MED:
ret.strength--;
ret.dexterity--;
ret.perception--;
if (level > 2) {
ret.strength--;
ret.dexterity--;
}
break;
case STATUS_PAINKILL_HEAVY:
ret.strength--;
ret.dexterity--;
ret.perception--;
ret.strength -= (level - 1) / 2;
ret.dexterity -= (level + 1) / 3;
ret.perception -= level / 4;
break;
case STATUS_DRUNK:
if (level == 1) {
// Is this just silly? I mean, in my experience it kinda makes sense...
ret.strength++;
} else {
ret.strength -= level / 3; // 0, 0, 1, 1, 1, 2, ...
}
ret.dexterity -= level / 3 + 1; // 1, 1, 2, 2, 2, 3, ...
ret.intelligence -= level; // 1, 2, 3, 4, 5, 6, ...
ret.perception -= level / 2 + 1; // 1, 2, 2, 3, 3, 4, ...
break;
}
return ret;
}
Status_effect_type lookup_status_effect(std::string name)
{
name = no_caps(name);
name = trim(name);
for (int i = 0; i < STATUS_MAX; i++) {
Status_effect_type ret = Status_effect_type(i);
if (name == no_caps( status_effect_name(ret) ) ) {
return ret;
}
}
return STATUS_NULL;
}
std::string status_effect_name(Status_effect_type type)
{
switch (type) {
case STATUS_NULL: return "NULL";
case STATUS_BLIND: return "blind";
case STATUS_CAFFEINE: return "caffeine";
case STATUS_NICOTINE: return "nicotine";
case STATUS_STIMULANT: return "stimulant";
case STATUS_SLEEP_AID: return "sleep_aid";
case STATUS_PAINKILL_MILD: return "painkill_mild";
case STATUS_PAINKILL_MED: return "painkill_med";
case STATUS_PAINKILL_LONG: return "painkill_long";
case STATUS_PAINKILL_HEAVY: return "painkill_heavy";
case STATUS_DRUNK: return "drunk";
case STATUS_MAX: return "BUG - STATUS_MAX";
default: return "BUG - Unnamed Status_effect_type";
}
return "BUG - Escaped status_effect_name() switch";
}