forked from crawl/crawl
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbehold.cc
274 lines (246 loc) · 7.39 KB
/
behold.cc
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/**
* @file
* @brief player methods dealing with mesmerisation.
**/
#include "AppHdr.h"
#include "player.h"
#include "areas.h"
#include "art-enum.h"
#include "coord.h"
#include "env.h"
#include "fprop.h"
#include "state.h"
// Add a monster to the list of beholders.
void player::add_beholder(const monster* mon, bool axe)
{
if (is_sanctuary(pos()) && !axe)
{
if (mons_is_siren_beholder(mon))
{
if (can_see(*mon))
{
mprf("%s's singing sounds muted, and has no effect on you.",
mon->name(DESC_THE).c_str());
}
else
mpr("The melody is strangely muted, and has no effect on you.");
}
else
{
if (can_see(*mon))
mprf("%s's is no longer quite as mesmerising!", mon->name(DESC_THE).c_str());
else
mpr("Your mesmeriser suddenly seems less interesting!");
}
return;
}
if (!duration[DUR_MESMERISED])
{
set_duration(DUR_MESMERISED, random_range(7, 15), 15);
beholders.push_back(mon->mid);
if (!axe)
{
mprf(MSGCH_WARN, "You are mesmerised by %s!",
mon->name(DESC_THE).c_str());
}
}
else
{
increase_duration(DUR_MESMERISED, random_range(5, 8), 15);
if (!beheld_by(mon))
beholders.push_back(mon->mid);
}
}
// Whether player is mesmerised.
bool player::beheld() const
{
ASSERT((duration[DUR_MESMERISED] > 0) == !beholders.empty());
return duration[DUR_MESMERISED] > 0;
}
// Whether player is mesmerised by the given monster.
bool player::beheld_by(const monster* mon) const
{
return find(begin(beholders), end(beholders), mon->mid) != end(beholders);
}
// Checks whether a beholder keeps you from moving to
// target, and returns one if it exists.
monster* player::get_beholder(const coord_def &target) const
{
for (mid_t beh : beholders)
{
monster* mon = monster_by_mid(beh);
// The monster may have died.
if (!mon)
continue;
const int olddist = grid_distance(pos(), mon->pos());
const int newdist = grid_distance(target, mon->pos());
if (olddist < newdist)
return mon;
}
return nullptr;
}
monster* player::get_any_beholder() const
{
if (!beholders.empty())
return monster_by_mid(beholders[0]);
else
return nullptr;
}
// Removes a monster from the list of beholders if present.
void player::remove_beholder(const monster* mon)
{
for (unsigned int i = 0; i < beholders.size(); i++)
if (beholders[i] == mon->mid)
{
beholders.erase(beholders.begin() + i);
_removed_beholder();
return;
}
}
// Clear the list of beholders. Doesn't message.
void player::clear_beholders()
{
beholders.clear();
duration[DUR_MESMERISED] = 0;
you.duration[DUR_MESMERISE_IMMUNE] = random_range(21, 40);
}
// Possibly end mesmerisation if a loud noise happened.
void player::beholders_check_noise(int loudness, bool axe)
{
if (axe)
return;
if (loudness >= 20 && beheld())
{
mpr("For a moment, your mind becomes perfectly clear!");
clear_beholders();
_removed_beholder();
}
}
static void _removed_beholder_msg(const monster* mon)
{
if (!mon || !mon->alive() || !mons_is_siren_beholder(mon)
|| mon->submerged() || !you.see_cell(mon->pos()))
{
return;
}
if (is_sanctuary(you.pos()) && !mons_is_fleeing(mon))
{
if (mons_is_siren_beholder(mon))
{
if (you.can_see(*mon))
{
mprf("%s's singing becomes strangely muted.",
mon->name(DESC_THE).c_str());
}
else
mpr("Something's singing becomes strangely muted.");
}
else
{
if (you.can_see(*mon))
mprf("%s's is no longer quite as mesmerising!", mon->name(DESC_THE).c_str());
else
mpr("Your mesmeriser suddenly seems less interesting!");
}
return;
}
if (you.can_see(*mon))
{
if (silenced(you.pos()) || silenced(mon->pos()))
{
if (mons_is_siren_beholder(mon))
{
mprf("You can no longer hear %s's singing!",
mon->name(DESC_THE).c_str());
}
else
mpr("The silence clears your mind.");
return;
}
if (mons_is_siren_beholder(mon))
mprf("%s stops singing.", mon->name(DESC_THE).c_str());
else
mprf("%s is no longer quite as mesmerising!", mon->name(DESC_THE).c_str());
return;
}
if (mons_is_siren_beholder(mon))
mpr("Something stops singing.");
else
mpr("Your mesmeriser is now quite boring!");
}
// Update all beholders' status after changes.
void player::update_beholders()
{
if (!beheld())
return;
bool removed = false;
for (int i = beholders.size() - 1; i >= 0; i--)
{
const monster* mon = monster_by_mid(beholders[i]);
if (!possible_beholder(mon))
{
beholders.erase(beholders.begin() + i);
removed = true;
// If that was the last one, clear the duration before
// printing any subsequent messages, or a --more-- can
// crash (#6547).
_removed_beholder(true);
_removed_beholder_msg(mon);
}
}
if (removed)
_removed_beholder();
}
// Update a single beholder.
void player::update_beholder(const monster* mon)
{
if (possible_beholder(mon))
return;
for (unsigned int i = 0; i < beholders.size(); i++)
if (beholders[i] == mon->mid)
{
beholders.erase(beholders.begin() + i);
// Do this dance to clear the duration before printing messages
// (#8844), but still print all messages in the right order.
_removed_beholder(true);
_removed_beholder_msg(mon);
_removed_beholder();
return;
}
}
// Helper function that resets the duration and messages if the player
// is no longer mesmerised.
void player::_removed_beholder(bool quiet)
{
if (beholders.empty())
{
duration[DUR_MESMERISED] = 0;
you.duration[DUR_MESMERISE_IMMUNE] = random_range(21, 40);
if (!quiet)
{
mprf(MSGCH_DURATION,
coinflip() ? "You break out of your daze!"
: "You are no longer entranced.");
}
}
}
// Helper function that checks whether the given monster is a possible
// beholder.
bool player::possible_beholder(const monster* mon) const
{
if (crawl_state.game_is_arena())
return false;
return mon && mon->alive() && !mon->submerged()
&& see_cell_no_trans(mon->pos()) && mon->see_cell_no_trans(pos())
&& !mon->wont_attack() && !mon->pacified()
&& ((mons_is_siren_beholder(mon->type)
|| mon->has_spell(SPELL_MESMERISE))
&& !silenced(pos()) && !silenced(mon->pos())
&& !mon->has_ench(ENCH_MUTE)
&& !mon->confused()
&& !mon->asleep() && !mon->cannot_move()
&& !mon->berserk_or_insane()
&& !mons_is_fleeing(mon)
&& !is_sanctuary(pos())
|| player_equip_unrand(UNRAND_DEMON_AXE));
}