/
spl-other.cc
525 lines (458 loc) · 14.2 KB
/
spl-other.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
/**
* @file
* @brief Non-enchantment spells that didn't fit anywhere else.
* Mostly Transmutations.
**/
#include "AppHdr.h"
#include "spl-other.h"
#include "act-iter.h"
#include "coordit.h"
#include "delay.h"
#include "env.h"
#include "god-companions.h"
#include "libutil.h"
#include "message.h"
#include "mon-place.h"
#include "mon-util.h"
#include "movement.h" // passwall
#include "place.h"
#include "potion.h"
#include "religion.h"
#include "spl-util.h"
#include "terrain.h"
spret cast_sublimation_of_blood(int pow, bool fail)
{
bool success = false;
if (you.duration[DUR_DEATHS_DOOR])
mpr("You can't draw power from your own body while in death's door.");
else if (!you.can_bleed())
{
if (you.has_mutation(MUT_VAMPIRISM))
mpr("You don't have enough blood to draw power from your own body.");
else
mpr("Your body is bloodless.");
}
else if (!enough_hp(2, true))
mpr("Your attempt to draw power from your own body fails.");
else
{
// Take at most 90% of currhp.
const int minhp = max(div_rand_round(you.hp, 10), 1);
while (you.magic_points < you.max_magic_points && you.hp > minhp)
{
fail_check();
success = true;
inc_mp(1);
dec_hp(1, false);
for (int i = 0; i < (you.hp > minhp ? 3 : 0); ++i)
if (x_chance_in_y(6, pow))
dec_hp(1, false);
if (x_chance_in_y(6, pow))
break;
}
if (success)
mpr("You draw magical energy from your own body!");
else
mpr("Your attempt to draw power from your own body fails.");
}
return success ? spret::success : spret::abort;
}
spret cast_death_channel(int pow, god_type god, bool fail)
{
fail_check();
mpr("Malign forces permeate your being, awaiting release.");
you.increase_duration(DUR_DEATH_CHANNEL,
30 + random2(1 + div_rand_round(2 * pow, 3)), 200);
if (god != GOD_NO_GOD)
you.attribute[ATTR_DIVINE_DEATH_CHANNEL] = static_cast<int>(god);
return spret::success;
}
static bool _dismiss_dead()
{
bool found = false;
for (monster_iterator mi; mi; ++mi)
{
if (!*mi)
continue;
monster &mon = **mi;
if (!mon.alive()
|| !mon.friendly()
|| mon.type != MONS_ZOMBIE
|| mon.is_summoned()
|| is_yred_undead_slave(mon))
{
continue;
}
// crumble into dust...
mon_enchant abj(ENCH_FAKE_ABJURATION, 0, 0, 1);
mon.add_ench(abj);
abj.duration = 0;
mon.update_ench(abj);
found = true;
}
return found;
}
spret cast_animate_dead(int pow, bool fail)
{
fail_check();
if (_dismiss_dead())
mpr("You dismiss your zombies and call upon the dead to rise afresh.");
else
mpr("You call upon the dead to rise.");
you.increase_duration(DUR_ANIMATE_DEAD, 20 + random2(1 + pow), 100);
you.props[ANIMATE_DEAD_POWER_KEY] = pow;
return spret::success;
}
void start_recall(recall_t type)
{
// Assemble the recall list.
typedef pair<mid_t, int> mid_hd;
vector<mid_hd> rlist;
you.recall_list.clear();
for (monster_iterator mi; mi; ++mi)
{
if (!mons_is_recallable(&you, **mi))
continue;
if (type == recall_t::yred)
{
if (!(mi->holiness() & MH_UNDEAD))
continue;
}
else if (type == recall_t::beogh)
{
if (!is_orcish_follower(**mi))
continue;
}
mid_hd m(mi->mid, mi->get_experience_level());
rlist.push_back(m);
}
if (branch_allows_followers(you.where_are_you))
populate_offlevel_recall_list(rlist);
if (!rlist.empty())
{
// Sort the recall list roughly
for (mid_hd &entry : rlist)
entry.second += random2(10);
sort(rlist.begin(), rlist.end(), greater_second<mid_hd>());
you.recall_list.clear();
for (mid_hd &entry : rlist)
you.recall_list.push_back(entry.first);
you.attribute[ATTR_NEXT_RECALL_INDEX] = 1;
you.attribute[ATTR_NEXT_RECALL_TIME] = 0;
mpr("You begin recalling your allies.");
}
else
mpr("Nothing appears to have answered your call.");
}
// Remind a recalled ally (or one skipped due to proximity) not to run
// away or wander off.
void recall_orders(monster *mons)
{
// FIXME: is this okay for berserk monsters? We still want them to
// stick around...
// Don't patrol
mons->patrol_point = coord_def(0, 0);
// Don't wander
mons->behaviour = BEH_SEEK;
// Don't pursue distant enemies
const actor *foe = mons->get_foe();
if (foe && !you.can_see(*foe))
mons->foe = MHITYOU;
}
// Attempt to recall a single monster by mid, which might be either on or off
// our current level. Returns whether this monster was successfully recalled.
bool try_recall(mid_t mid)
{
monster* mons = monster_by_mid(mid);
// Either it's dead or off-level.
if (!mons)
return recall_offlevel_ally(mid);
if (!mons->alive())
return false;
// Don't recall monsters that are already close to the player
if (mons->pos().distance_from(you.pos()) < 3
&& mons->see_cell_no_trans(you.pos()))
{
recall_orders(mons);
return false;
}
coord_def empty;
if (!find_habitable_spot_near(you.pos(), mons->type, 3, false, empty)
|| !mons->move_to_pos(empty))
{
return false;
}
recall_orders(mons);
simple_monster_message(*mons, " is recalled.");
mons->apply_location_effects(mons->pos());
// mons may have been killed, shafted, etc,
// but they were still recalled!
return true;
}
// Attempt to recall a number of allies proportional to how much time
// has passed. Once the list has been fully processed, terminate the
// status.
void do_recall(int time)
{
while (time > you.attribute[ATTR_NEXT_RECALL_TIME])
{
// Try to recall an ally.
mid_t mid = you.recall_list[you.attribute[ATTR_NEXT_RECALL_INDEX]-1];
you.attribute[ATTR_NEXT_RECALL_INDEX]++;
if (try_recall(mid))
{
time -= you.attribute[ATTR_NEXT_RECALL_TIME];
you.attribute[ATTR_NEXT_RECALL_TIME] = 3 + random2(4);
}
if ((unsigned int)you.attribute[ATTR_NEXT_RECALL_INDEX] >
you.recall_list.size())
{
end_recall();
mpr("You finish recalling your allies.");
return;
}
}
you.attribute[ATTR_NEXT_RECALL_TIME] -= time;
return;
}
void end_recall()
{
you.attribute[ATTR_NEXT_RECALL_INDEX] = 0;
you.attribute[ATTR_NEXT_RECALL_TIME] = 0;
you.recall_list.clear();
}
static bool _feat_is_passwallable(dungeon_feature_type feat)
{
// Worked stone walls are out, they're not diggable and
// are used for impassable walls...
switch (feat)
{
case DNGN_ROCK_WALL:
case DNGN_SLIMY_WALL:
case DNGN_CLEAR_ROCK_WALL:
return true;
default:
return false;
}
}
bool passwall_simplified_check(const actor &act)
{
for (adjacent_iterator ai(act.pos(), true); ai; ++ai)
if (_feat_is_passwallable(env.grid(*ai)))
return true;
return false;
}
passwall_path::passwall_path(const actor &act, const coord_def& dir, int max_range)
: start(act.pos()), delta(dir.sgn()),
range(max_range),
dest_found(false)
{
if (delta.zero())
return;
ASSERT(range > 0);
coord_def pos;
// TODO: something better than sgn for delta?
for (pos = start + delta;
(pos - start).rdist() - 1 <= range;
pos += delta)
{
path.emplace_back(pos);
if (in_bounds(pos))
{
if (!_feat_is_passwallable(env.grid(pos)))
{
if (!dest_found)
{
actual_dest = pos;
dest_found = true;
}
if (env.map_knowledge(pos).feat() != DNGN_UNSEEN)
break;
}
}
else if (!dest_found) // no destination in bounds
{
actual_dest = pos;
dest_found = true;
break; // can't render oob rays anyways, so no point in considering
// more than one of them
}
}
// if dest_found is false, actual_dest is guaranteed to be out of bounds
}
/// max walls that there could be, given the player's knowledge and map bounds
int passwall_path::max_walls() const
{
if (path.size() == 0)
return 0;
// the in_bounds check is in case the player is standing next to bounds
return max((int) path.size() - 1, in_bounds(path.back()) ? 0 : 1);
}
/// actual walls (or max walls, if actual_dest is out of bounds)
int passwall_path::actual_walls() const
{
return !in_bounds(actual_dest) ?
max_walls() :
(actual_dest - start).rdist() - 1;
}
bool passwall_path::spell_succeeds() const
{
// this isn't really the full story -- since moveto needs to be checked
// also.
return actual_walls() > 0;
}
bool passwall_path::is_valid(string *fail_msg) const
{
// does not check moveto cases, incl lava/deep water, since these prompt.
if (delta.zero())
{
if (fail_msg)
*fail_msg = "Please select a wall.";
return false;
}
if (actual_walls() == 0)
{
if (fail_msg)
*fail_msg = "There is no adjacent passable wall in that direction.";
return false;
}
if (!dest_found)
{
if (fail_msg)
*fail_msg = "This rock feels extremely deep.";
return false;
}
if (!in_bounds(actual_dest))
{
if (fail_msg)
*fail_msg = "You sense an overwhelming volume of rock.";
return false;
}
const monster *mon = monster_at(actual_dest);
if (cell_is_solid(actual_dest) || (mon && mon->is_stationary()))
{
if (fail_msg)
*fail_msg = "Something is blocking your path through the rock.";
return false;
}
return true;
}
/// find possible destinations, given the player's map knowledge
vector <coord_def> passwall_path::possible_dests() const
{
// uses comparison to DNGN_UNSEEN so that this works sensibly with magic
// mapping etc
vector<coord_def> dests;
for (auto p : path)
if (!in_bounds(p) ||
(env.map_knowledge(p).feat() == DNGN_UNSEEN || !cell_is_solid(p)))
{
dests.push_back(p);
}
return dests;
}
bool passwall_path::check_moveto() const
{
// assumes is_valid()
string terrain_msg;
if (env.grid(actual_dest) == DNGN_DEEP_WATER)
terrain_msg = "You sense a deep body of water on the other side of the rock.";
else if (env.grid(actual_dest) == DNGN_LAVA)
terrain_msg = "You sense an intense heat on the other side of the rock.";
// Pre-confirm exclusions in unseen squares as well as the actual dest
// even if seen, so that this doesn't leak information.
// TODO: handle uncertainty in messaging for things other than exclusions
return check_moveto_terrain(actual_dest, "passwall", terrain_msg)
&& check_moveto_exclusions(possible_dests(), "passwall")
&& check_moveto_cloud(actual_dest, "passwall")
&& check_moveto_trap(actual_dest, "passwall");
}
spret cast_passwall(const coord_def& c, int pow, bool fail)
{
// prompt player to end position-based ice spells
if (cancel_harmful_move(false))
return spret::abort;
// held away from the wall
if (you.is_constricted())
return spret::abort;
coord_def delta = c - you.pos();
passwall_path p(you, delta, spell_range(SPELL_PASSWALL, pow));
string fail_msg;
bool valid = p.is_valid(&fail_msg);
if (!p.spell_succeeds())
{
if (fail_msg.size())
mpr(fail_msg);
return spret::abort;
}
fail_check();
if (!valid)
{
if (fail_msg.size())
mpr(fail_msg);
}
else if (p.check_moveto())
{
start_delay<PasswallDelay>(p.actual_walls() + 1, p.actual_dest);
return spret::success;
}
// at this point, the spell failed or was cancelled. Does it cost MP?
vector<coord_def> dests = p.possible_dests();
if (dests.size() == 0 ||
(dests.size() == 1 && (!in_bounds(dests[0]) ||
env.map_knowledge(dests[0]).feat() != DNGN_UNSEEN)))
{
// if there are no possible destinations, or only 1 that has been seen,
// the player already had full knowledge. The !in_bounds case is if they
// are standing next to the map edge, which is a leak of sorts, but
// already apparent from the targeting (and we leak this info all over
// the place, really).
return spret::abort;
}
return spret::success;
}
static int _intoxicate_monsters(coord_def where, int pow, bool tracer)
{
monster* mons = monster_at(where);
if (mons == nullptr
|| mons_intel(*mons) < I_HUMAN
|| mons->clarity()
|| mons->res_poison() >= 3)
{
return 0;
}
if (tracer && !you.can_see(*mons))
return 0;
if (!tracer && monster_resists_this_poison(*mons))
return 0;
if (!tracer && x_chance_in_y(40 + div_rand_round(pow, 3), 100))
{
mons->add_ench(mon_enchant(ENCH_CONFUSION, 0, &you));
simple_monster_message(*mons, " looks rather confused.");
return 1;
}
// Just count affectable monsters for the tracer
return tracer ? 1 : 0;
}
spret cast_intoxicate(int pow, bool fail, bool tracer)
{
if (tracer)
{
const int work = apply_area_visible([] (coord_def where) {
return _intoxicate_monsters(where, 0, true);
}, you.pos());
return work > 0 ? spret::success : spret::abort;
}
fail_check();
mpr("You attempt to intoxicate your foes!");
const int count = apply_area_visible([pow] (coord_def where) {
return _intoxicate_monsters(where, pow, false);
}, you.pos());
if (count > 0)
{
mprf(MSGCH_WARN, "The world spins around you!");
you.increase_duration(DUR_VERTIGO, 4 + count + random2(count + 1));
you.redraw_evasion = true;
}
return spret::success;
}