-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
fineff.cc
565 lines (488 loc) · 16.1 KB
/
fineff.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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
/**
* @file
* @brief Brand/ench/etc effects that might alter something in an
* unexpected way.
**/
#include "AppHdr.h"
#include "fineff.h"
#include "act-iter.h"
#include "bloodspatter.h"
#include "coordit.h"
#include "dactions.h"
#include "directn.h"
#include "english.h"
#include "env.h"
#include "god-abil.h"
#include "libutil.h"
#include "message.h"
#include "mon-abil.h"
#include "mon-act.h"
#include "mon-behv.h"
#include "mon-cast.h"
#include "mon-death.h"
#include "mon-place.h"
#include "ouch.h"
#include "religion.h"
#include "state.h"
#include "terrain.h"
#include "transform.h"
#include "view.h"
#include "viewchar.h"
/*static*/ void final_effect::schedule(final_effect *eff)
{
for (auto fe : env.final_effects)
{
if (fe->mergeable(*eff))
{
fe->merge(*eff);
delete eff;
return;
}
}
env.final_effects.push_back(eff);
}
bool mirror_damage_fineff::mergeable(const final_effect &fe) const
{
const mirror_damage_fineff *o =
dynamic_cast<const mirror_damage_fineff *>(&fe);
return o && att == o->att && def == o->def;
}
bool ru_retribution_fineff::mergeable(const final_effect &fe) const
{
const ru_retribution_fineff *o =
dynamic_cast<const ru_retribution_fineff *>(&fe);
return o && att == o->att && def == o->def;
}
bool trample_follow_fineff::mergeable(const final_effect &fe) const
{
const trample_follow_fineff *o =
dynamic_cast<const trample_follow_fineff *>(&fe);
return o && att == o->att && posn == o->posn;
}
bool blink_fineff::mergeable(const final_effect &fe) const
{
const blink_fineff *o = dynamic_cast<const blink_fineff *>(&fe);
return o && def == o->def;
}
bool teleport_fineff::mergeable(const final_effect &fe) const
{
const teleport_fineff *o =
dynamic_cast<const teleport_fineff *>(&fe);
return o && def == o->def;
}
bool trj_spawn_fineff::mergeable(const final_effect &fe) const
{
const trj_spawn_fineff *o = dynamic_cast<const trj_spawn_fineff *>(&fe);
return o && att == o->att && def == o->def && posn == o->posn;
}
bool blood_fineff::mergeable(const final_effect &fe) const
{
const blood_fineff *o = dynamic_cast<const blood_fineff *>(&fe);
return o && posn == o->posn && mtype == o->mtype;
}
bool deferred_damage_fineff::mergeable(const final_effect &fe) const
{
const deferred_damage_fineff *o = dynamic_cast<const deferred_damage_fineff *>(&fe);
return o && att == o->att && def == o->def
&& attacker_effects == o->attacker_effects && fatal == o->fatal;
}
bool starcursed_merge_fineff::mergeable(const final_effect &fe) const
{
const starcursed_merge_fineff *o = dynamic_cast<const starcursed_merge_fineff *>(&fe);
return o && def == o->def;
}
bool shock_serpent_discharge_fineff::mergeable(const final_effect &fe) const
{
const shock_serpent_discharge_fineff *o = dynamic_cast<const shock_serpent_discharge_fineff *>(&fe);
return o && def == o->def;
}
bool delayed_action_fineff::mergeable(const final_effect &fe) const
{
return false;
}
bool rakshasa_clone_fineff::mergeable(const final_effect &fe) const
{
const rakshasa_clone_fineff *o =
dynamic_cast<const rakshasa_clone_fineff *>(&fe);
return o && att == o->att && def == o->def && posn == o->posn;
}
void mirror_damage_fineff::merge(const final_effect &fe)
{
const mirror_damage_fineff *mdfe =
dynamic_cast<const mirror_damage_fineff *>(&fe);
ASSERT(mdfe);
ASSERT(mergeable(*mdfe));
damage += mdfe->damage;
}
void ru_retribution_fineff::merge(const final_effect &fe)
{
const ru_retribution_fineff *mdfe =
dynamic_cast<const ru_retribution_fineff *>(&fe);
ASSERT(mdfe);
ASSERT(mergeable(*mdfe));
}
void trj_spawn_fineff::merge(const final_effect &fe)
{
const trj_spawn_fineff *trjfe =
dynamic_cast<const trj_spawn_fineff *>(&fe);
ASSERT(trjfe);
ASSERT(mergeable(*trjfe));
damage += trjfe->damage;
}
void blood_fineff::merge(const final_effect &fe)
{
const blood_fineff *bfe = dynamic_cast<const blood_fineff *>(&fe);
ASSERT(bfe);
ASSERT(mergeable(*bfe));
blood += bfe->blood;
}
void deferred_damage_fineff::merge(const final_effect &fe)
{
const deferred_damage_fineff *ddamfe =
dynamic_cast<const deferred_damage_fineff *>(&fe);
ASSERT(ddamfe);
ASSERT(mergeable(*ddamfe));
damage += ddamfe->damage;
}
void shock_serpent_discharge_fineff::merge(const final_effect &fe)
{
const shock_serpent_discharge_fineff *ssdfe =
dynamic_cast<const shock_serpent_discharge_fineff *>(&fe);
power += ssdfe->power;
}
void mirror_damage_fineff::fire()
{
actor *attack = attacker();
if (!attack || attack == defender() || !attack->alive())
return;
// defender being dead is ok, if we killed them we still suffer
god_acting gdact(GOD_YREDELEMNUL);
if (att == MID_PLAYER)
{
const monster* reflector = defender() ?
defender()->as_monster() : nullptr;
if (reflector)
{
mprf("%s reflects your damage back at you!",
reflector->name(DESC_THE).c_str());
}
else
mpr("Your damage is reflected back at you!");
ouch(damage, KILLED_BY_MIRROR_DAMAGE);
}
else if (def == MID_PLAYER)
{
simple_god_message(" mirrors your injury!");
#ifndef USE_TILE_LOCAL
flash_monster_colour(monster_by_mid(att), RED, 200);
#endif
attack->hurt(&you, damage);
if (attack->alive())
print_wounds(*monster_by_mid(att));
lose_piety(isqrt_ceil(damage));
}
else
{
simple_monster_message(*monster_by_mid(att), " suffers a backlash!");
attack->hurt(defender(), damage);
}
}
void ru_retribution_fineff::fire()
{
actor *attack = attacker();
if (!attack || attack == defender() || !attack->alive())
return;
if (def == MID_PLAYER)
ru_do_retribution(monster_by_mid(att), damage);
}
void trample_follow_fineff::fire()
{
actor *attack = attacker();
if (attack
&& attack->pos() != posn
&& adjacent(attack->pos(), posn)
&& attack->is_habitable(posn))
{
const coord_def old_pos = attack->pos();
attack->move_to_pos(posn);
attack->apply_location_effects(old_pos);
}
}
void blink_fineff::fire()
{
actor *defend = defender();
if (defend && defend->alive() && !defend->no_tele(true, false))
defend->blink();
}
void teleport_fineff::fire()
{
actor *defend = defender();
if (defend && defend->alive() && !defend->no_tele(true, false))
defend->teleport(true);
}
void trj_spawn_fineff::fire()
{
const actor *attack = attacker();
actor *trj = defender();
int tospawn = div_rand_round(damage, 12);
if (tospawn <= 0)
return;
dprf("Trying to spawn %d jellies.", tospawn);
unsigned short foe = attack && attack->alive() ? attack->mindex() : MHITNOT;
// may be ANON_FRIENDLY_MONSTER
if (invalid_monster_index(foe) && foe != MHITYOU)
foe = MHITNOT;
// Give spawns the same attitude as TRJ; if TRJ is now dead, make them
// hostile.
const beh_type spawn_beh = trj
? attitude_creation_behavior(trj->as_monster()->attitude)
: BEH_HOSTILE;
// No permanent friendly jellies from an enslaved TRJ.
if (spawn_beh == BEH_FRIENDLY && !crawl_state.game_is_arena())
return;
int spawned = 0;
for (int i = 0; i < tospawn; ++i)
{
const monster_type jelly = royal_jelly_ejectable_monster();
coord_def jpos = find_newmons_square_contiguous(jelly, posn);
if (!in_bounds(jpos))
continue;
if (monster *mons = mons_place(
mgen_data(jelly, spawn_beh, jpos, foe,
MG_DONT_COME, GOD_JIYVA)
.set_summoned(trj, 0, 0)))
{
// Don't allow milking the Royal Jelly.
mons->flags |= MF_NO_REWARD;
spawned++;
}
}
if (!spawned || !you.see_cell(posn))
return;
if (trj)
{
const string monnam = trj->name(DESC_THE);
mprf("%s shudders%s.", monnam.c_str(),
spawned >= 5 ? " alarmingly" :
spawned >= 3 ? " violently" :
spawned > 1 ? " vigorously" : "");
if (spawned == 1)
mprf("%s spits out another jelly.", monnam.c_str());
else
{
mprf("%s spits out %s more jellies.",
monnam.c_str(),
number_in_words(spawned).c_str());
}
}
else if (spawned == 1)
mpr("One of the Royal Jelly's fragments survives.");
else
{
mprf("The dying Royal Jelly spits out %s more jellies.",
number_in_words(spawned).c_str());
}
}
void blood_fineff::fire()
{
bleed_onto_floor(posn, mtype, blood, true);
}
void deferred_damage_fineff::fire()
{
if (actor *df = defender())
{
if (!fatal)
{
// Cap non-fatal damage by the defender's hit points
// FIXME: Consider adding a 'fatal' parameter to ::hurt
// to better interact with damage reduction/boosts
// which may be applied later.
int df_hp = df->is_player() ? you.hp
: df->as_monster()->hit_points;
damage = min(damage, df_hp - 1);
}
df->hurt(attacker(), damage, BEAM_MISSILE, KILLED_BY_MONSTER, "", "",
true, attacker_effects);
}
}
static void _do_merge_masses(monster* initial_mass, monster* merge_to)
{
// Combine enchantment durations.
merge_ench_durations(*initial_mass, *merge_to);
merge_to->blob_size += initial_mass->blob_size;
merge_to->max_hit_points += initial_mass->max_hit_points;
merge_to->hit_points += initial_mass->hit_points;
// Merge monster flags (mostly so that MF_CREATED_NEUTRAL, etc. are
// passed on if the merged slime subsequently splits. Hopefully
// this won't do anything weird.
merge_to->flags |= initial_mass->flags;
// Overwrite the state of the slime getting merged into, because it
// might have been resting or something.
merge_to->behaviour = initial_mass->behaviour;
merge_to->foe = initial_mass->foe;
behaviour_event(merge_to, ME_EVAL);
// Have to 'kill' the slime doing the merging.
monster_die(*initial_mass, KILL_DISMISSED, NON_MONSTER, true);
}
void starcursed_merge_fineff::fire()
{
actor *defend = defender();
if (!defend || !defend->alive())
return;
monster *mon = defend->as_monster();
// Find a random adjacent starcursed mass and merge with it.
for (fair_adjacent_iterator ai(mon->pos()); ai; ++ai)
{
monster* mergee = monster_at(*ai);
if (mergee && mergee->alive() && mergee->type == MONS_STARCURSED_MASS)
{
simple_monster_message(*mon,
" shudders and is absorbed by its neighbour.");
_do_merge_masses(mon, mergee);
return;
}
}
// If there was nothing adjacent to merge with, at least try to move toward
// another starcursed mass
for (distance_iterator di(mon->pos(), true, true, LOS_RADIUS); di; ++di)
{
monster* ally = monster_at(*di);
if (ally && ally->alive() && ally->type == MONS_STARCURSED_MASS
&& mon->can_see(*ally))
{
bool moved = false;
coord_def sgn = (*di - mon->pos()).sgn();
if (mon_can_move_to_pos(mon, sgn))
{
mon->move_to_pos(mon->pos()+sgn, false);
moved = true;
}
else if (abs(sgn.x) != 0)
{
coord_def dx(sgn.x, 0);
if (mon_can_move_to_pos(mon, dx))
{
mon->move_to_pos(mon->pos()+dx, false);
moved = true;
}
}
else if (abs(sgn.y) != 0)
{
coord_def dy(0, sgn.y);
if (mon_can_move_to_pos(mon, dy))
{
mon->move_to_pos(mon->pos()+dy, false);
moved = true;
}
}
if (moved)
{
simple_monster_message(*mon, " shudders and withdraws towards its neighbour.");
mon->speed_increment -= 10;
}
}
}
}
void shock_serpent_discharge_fineff::fire()
{
if (!oppressor.alive())
return;
const int max_range = 3; // v0v
if (grid_distance(oppressor.pos(), position) > max_range)
return;
const monster* serpent = defender() ? defender()->as_monster() : nullptr;
if (serpent && you.can_see(*serpent))
{
mprf("%s electric aura discharges%s, shocking %s!",
serpent->name(DESC_ITS).c_str(),
power < 4 ? "" : " violently",
oppressor.name(DESC_THE).c_str());
}
else if (you.can_see(oppressor))
{
mprf("The air sparks with electricity, shocking %s!",
oppressor.name(DESC_THE).c_str());
}
bolt beam;
beam.flavour = BEAM_ELECTRICITY;
int amount = roll_dice(3, 4 + power * 3 / 2);
amount = oppressor.apply_ac(oppressor.beam_resists(beam, amount, true),
0, AC_HALF);
oppressor.hurt(serpent, amount, beam.flavour, KILLED_BY_BEAM,
"a shock serpent", "electric aura");
if (amount)
oppressor.expose_to_element(beam.flavour, amount);
}
void delayed_action_fineff::fire()
{
if (!final_msg.empty())
mpr(final_msg);
add_daction(action);
}
void kirke_death_fineff::fire()
{
delayed_action_fineff::fire();
// Revert the player last
if (you.form == transformation::pig)
untransform();
}
void rakshasa_clone_fineff::fire()
{
actor *defend = defender();
if (!defend)
return;
monster *rakshasa = defend->as_monster();
ASSERT(rakshasa);
// Using SPELL_NO_SPELL to prevent overwriting normal clones
cast_phantom_mirror(rakshasa, rakshasa, 50, SPELL_NO_SPELL);
cast_phantom_mirror(rakshasa, rakshasa, 50, SPELL_NO_SPELL);
rakshasa->lose_energy(EUT_SPELL);
if (you.can_see(*rakshasa))
{
mprf(MSGCH_MONSTER_SPELL,
"The injured %s weaves a defensive illusion!",
rakshasa->name(DESC_PLAIN).c_str());
}
}
void bennu_revive_fineff::fire()
{
// Bennu only resurrect once and immediately in the same spot,
// so this is rather abbreviated compared to felids.
// XXX: Maybe generalize felid_revives and merge the two anyway?
bool res_visible = you.see_cell(posn);
monster *newmons = create_monster(mgen_data(MONS_BENNU, attitude, posn, foe,
res_visible ? MG_DONT_COME
: MG_NONE));
if (newmons)
newmons->props["bennu_revives"].get_byte() = revives + 1;
}
void infestation_death_fineff::fire()
{
if (monster *scarab = create_monster(mgen_data(MONS_DEATH_SCARAB,
BEH_FRIENDLY, posn,
MHITYOU, MG_AUTOFOE)
.set_summoned(&you, 0,
SPELL_INFESTATION),
false))
{
scarab->add_ench(mon_enchant(ENCH_FAKE_ABJURATION, 6));
if (you.see_cell(posn) || you.can_see(*scarab))
{
mprf("%s bursts from %s!", scarab->name(DESC_A, true).c_str(),
name.c_str());
}
}
}
// Effects that occur after all other effects, even if the monster is dead.
// For example, explosions that would hit other creatures, but we want
// to deal with only one creature at a time, so that's handled last.
void fire_final_effects()
{
while (!env.final_effects.empty())
{
// Remove it first so nothing can merge with it.
unique_ptr<final_effect> eff(env.final_effects.back());
env.final_effects.pop_back();
eff->fire();
}
}