/
spl-damage.cc
4687 lines (3969 loc) · 140 KB
/
spl-damage.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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file
* @brief Damage-dealing spells not already handled elsewhere.
* Other targeted spells are covered in spl-zap.cc.
**/
#include "AppHdr.h"
#include "spl-damage.h"
#include <cmath>
#include <functional>
#include "act-iter.h"
#include "areas.h"
#include "attack.h"
#include "beam.h"
#include "cloud.h"
#include "colour.h"
#include "coordit.h"
#include "directn.h"
#include "english.h"
#include "env.h"
#include "fight.h"
#include "fineff.h"
#include "fprop.h"
#include "god-conduct.h"
#include "god-passive.h"
#include "invent.h"
#include "items.h"
#include "level-state-type.h"
#include "los.h"
#include "losglobal.h"
#include "macro.h"
#include "mapmark.h"
#include "message.h"
#include "misc.h"
#include "mon-behv.h"
#include "mon-death.h"
#include "mon-tentacle.h"
#include "mutation.h"
#include "ouch.h"
#include "prompt.h"
#include "random.h"
#include "religion.h"
#include "shout.h"
#include "spl-clouds.h" // big_cloud
#include "spl-goditem.h"
#include "spl-summoning.h"
#include "spl-util.h"
#include "spl-zap.h"
#include "stepdown.h"
#include "stringutil.h"
#include "target.h"
#include "terrain.h"
#include "tilepick.h"
#include "transform.h"
#include "unicode.h"
#include "viewchar.h"
#include "view.h"
#include "xp-evoker-data.h" // for thunderbolt
#define SEARING_RAY_AIM_SPOT_KEY "searing_ray_aimed_at_spot"
#define SEARING_RAY_TARGET_KEY "searing_ray_target"
#define SEARING_RAY_MID_KEY "searing_ray_mid"
#define SEARING_RAY_POWER_KEY "searing_ray_power"
static bool _act_worth_targeting(const actor &caster, const actor &a)
{
if (!caster.see_cell_no_trans(a.pos()))
return false;
if (a.is_player())
return true;
const monster &m = *a.as_monster();
if (mons_is_firewood(m) || mons_is_conjured(m.type))
return false;
if (!caster.is_player())
return true;
return !god_protects(&you, &m, true)
&& !testbits(m.flags, MF_DEMONIC_GUARDIAN);
}
// returns the closest target to the caster, choosing randomly if there are more
// than one (see `fair` argument to distance_iterator).
static actor* _find_closest_target(const actor &caster, int radius, bool tracer)
{
for (distance_iterator di(caster.pos(), !tracer, true, radius); di; ++di)
{
actor *act = actor_at(*di);
if (act && _act_worth_targeting(caster, *act)
&& cell_see_cell(caster.pos(), *di, LOS_SOLID)
&& (!tracer || caster.can_see(*act)))
{
return act;
}
}
return nullptr;
}
void setup_fire_storm(const actor *source, int pow, bolt &beam)
{
zappy(ZAP_FIRE_STORM, pow, source->is_monster(), beam);
beam.ex_size = 2 + (random2(1000) < pow);
beam.source_id = source->mid;
// XXX: Should this be KILL_MON_MISSILE?
beam.thrower =
source->is_player() ? KILL_YOU_MISSILE : KILL_MON;
beam.aux_source.clear();
beam.is_tracer = false;
beam.origin_spell = SPELL_FIRE_STORM;
}
spret cast_fire_storm(int pow, bolt &beam, bool fail)
{
if (grid_distance(beam.target, beam.source) > beam.range)
{
mpr("That is beyond the maximum range.");
return spret::abort;
}
if (cell_is_solid(beam.target))
{
const char *feat = feat_type_name(env.grid(beam.target));
mprf("You can't place the storm on %s.", article_a(feat).c_str());
return spret::abort;
}
setup_fire_storm(&you, pow, beam);
bolt tempbeam = beam;
tempbeam.ex_size = (pow > 0) ? 3 : 2;
tempbeam.is_tracer = true;
tempbeam.explode(false);
if (tempbeam.beam_cancelled)
return spret::abort;
fail_check();
beam.apply_beam_conducts();
beam.refine_for_explosion();
beam.explode(false);
viewwindow();
update_screen();
return spret::success;
}
// No setup/cast split here as monster damnation is completely different.
// XXX make this not true
bool cast_smitey_damnation(int pow, bolt &beam)
{
beam.name = "damnation";
beam.aux_source = "damnation";
beam.ex_size = 1;
beam.flavour = BEAM_DAMNATION;
beam.real_flavour = beam.flavour;
beam.glyph = dchar_glyph(DCHAR_FIRED_BURST);
beam.colour = LIGHTRED;
beam.source_id = MID_PLAYER;
beam.thrower = KILL_YOU;
beam.obvious_effect = false;
beam.pierce = false;
beam.is_explosion = true;
beam.ench_power = pow; // used for radius
beam.hit = 20 + pow / 10;
beam.damage = calc_dice(6, 30 + pow);
beam.attitude = ATT_FRIENDLY;
beam.friend_info.count = 0;
beam.is_tracer = true;
beam.explode(false);
if (beam.beam_cancelled)
{
canned_msg(MSG_OK);
return false;
}
mpr("You call forth a pillar of damnation!");
beam.is_tracer = false;
beam.in_explosion_phase = false;
beam.explode(true);
return true;
}
struct arc_victim
{
coord_def source;
actor *victim;
};
static const int ARC_DIST = 3;
static void _chain_lightning_to(const actor &caster, int power,
vector<arc_victim> &victims,
set<actor*> &seen_set, int arcs,
int initial_range = 0)
{
bolt beam;
zappy(ZAP_CHAIN_LIGHTNING, power, caster.is_monster(), beam);
// Initial arc scales with range.
if (initial_range > 0)
{
beam.damage.size =
beam.damage.size * pow(0.6, (initial_range - 1) / 3.0);
}
// Further arcs scale a fixed amount per arc.
for (int i = 0; i < arcs; i++)
beam.damage.size = beam.damage.size * 3 / 5;
const int dam_size = beam.damage.size;
vector<arc_victim> new_victims;
for (arc_victim &arc : victims)
{
beam.source = arc.source;
beam.target = arc.victim->pos();
beam.range = grid_distance(beam.source, beam.target);
beam.source_id = caster.mid;
beam.thrower = caster.is_player() ? KILL_YOU_MISSILE : KILL_MON_MISSILE;
beam.origin_spell = SPELL_CHAIN_LIGHTNING;
beam.aux_source = "arc of chain lightning";
// Reduce damage to the caster.
beam.damage.size = dam_size / (arc.victim == &caster ? 6 : 1);
beam.draw_delay = 0;
beam.redraw_per_cell = false;
beam.obvious_effect = true;
beam.fire();
// arc!
for (distance_iterator di(beam.target, false, true, ARC_DIST); di; ++di)
{
actor *new_victim = actor_at(*di);
if (new_victim
&& seen_set.find(new_victim) == seen_set.end()
&& cell_see_cell(*di, beam.target, LOS_SOLID)
&& _act_worth_targeting(caster, *new_victim))
{
new_victims.push_back(arc_victim{beam.target, new_victim});
seen_set.insert(new_victim);
}
}
}
if (beam.animate)
animation_delay(200, true);
if (!new_victims.empty())
_chain_lightning_to(caster, power, new_victims, seen_set, arcs + 1);
}
// Assuming the player casts Chain Lightning, who *might* get hit?
// Doesn't include monsters the player can't see.
vector<coord_def> chain_lightning_targets()
{
vector<coord_def> targets;
actor *seed = _find_closest_target(you, LOS_RADIUS, true);
if (!seed)
return targets;
set<actor*> seen;
vector<coord_def> to_check;
seen.insert(seed);
to_check.push_back(seed->pos());
targets.push_back(seed->pos());
while (!to_check.empty())
{
const coord_def arc_source = to_check.back();
to_check.pop_back();
for (distance_iterator di(arc_source, true, true, ARC_DIST); di; ++di)
{
actor *new_victim = actor_at(*di);
if (new_victim
&& you.can_see(*new_victim)
&& seen.find(new_victim) == seen.end()
&& cell_see_cell(*di, you.pos(), LOS_SOLID)
&& _act_worth_targeting(you, *new_victim))
{
to_check.push_back(new_victim->pos());
targets.push_back(new_victim->pos());
seen.insert(new_victim);
}
}
}
return targets;
}
static bool _warn_about_bad_targets(spell_type spell, vector<coord_def> targets)
{
vector<const monster*> bad_targets;
for (coord_def p : targets)
{
const monster* mon = monster_at(p);
// XXX: maybe check for ioods/bspheres instead of all conjured mons..?
// feels a little bad to blow up a prism with a plasma beam, maybe?
if (!mon || god_protects(&you, mon) || mons_is_conjured(mon->type))
continue;
string adj, suffix;
bool penance;
if (bad_attack(mon, adj, suffix, penance, you.pos()))
bad_targets.push_back(mon);
}
if (bad_targets.empty())
return false;
const monster* ex_mon = bad_targets.back();
string adj, suffix;
bool penance;
bad_attack(ex_mon, adj, suffix, penance, you.pos());
const string and_more = bad_targets.size() > 1 ?
make_stringf(" (and %zu other bad targets)",
bad_targets.size() - 1) : "";
const string prompt = make_stringf("%s might hit %s%s. Cast it anyway?",
spell_title(spell),
ex_mon->name(DESC_THE).c_str(),
and_more.c_str());
if (!yesno(prompt.c_str(), false, 'n'))
{
canned_msg(MSG_OK);
return true;
}
return false;
}
spret cast_chain_lightning(int pow, const actor &caster, bool fail)
{
if (caster.is_player()
&& _warn_about_bad_targets(SPELL_CHAIN_LIGHTNING,
chain_lightning_targets()))
{
return spret::abort;
}
// NOTE: it's possible to hit something not in this list by arcing
// chain lightning through an invisible enemy through an ally. Oh well...
fail_check();
actor* act = _find_closest_target(caster, LOS_RADIUS, false);
if (!act)
{
if (caster.is_player())
canned_msg(MSG_NOTHING_HAPPENS);
return spret::success;
}
if (you.can_see(caster))
{
mprf("Lightning arcs from %s %s!",
apostrophise(caster.name(DESC_PLAIN)).c_str(),
caster.hand_name(true).c_str());
}
vector<arc_victim> victims;
victims.push_back(arc_victim{caster.pos(), act});
set<actor*> seen_set;
seen_set.insert(act);
_chain_lightning_to(caster, pow, victims, seen_set, 0,
grid_distance(caster.pos(), act->pos()));
return spret::success;
}
// XXX no friendly check
spret cast_chain_spell(spell_type spell_cast, int pow,
const actor *caster, bool fail)
{
fail_check();
bolt beam;
// initialise beam structure
beam.name = "arc of chaos";
beam.aux_source = "chain of chaos";
beam.glyph = dchar_glyph(DCHAR_FIRED_ZAP);
beam.flavour = BEAM_CHAOS;
beam.source_id = caster->mid;
beam.thrower = caster->is_player() ? KILL_YOU_MISSILE : KILL_MON_MISSILE;
beam.range = 8;
beam.hit = AUTOMATIC_HIT;
beam.obvious_effect = true;
beam.pierce = false; // since we want to stop at our target
beam.is_explosion = false;
beam.is_tracer = false;
beam.origin_spell = spell_cast;
if (const monster* mons = caster->as_monster())
beam.source_name = mons->name(DESC_PLAIN, true);
bool first = true;
coord_def source, target;
for (source = caster->pos(); pow > 0;
pow -= 8 + random2(13), source = target)
{
// infinity as far as this spell is concerned
// (Range - 1) is used because the distance is randomised and
// may be shifted by one.
int min_dist = LOS_DEFAULT_RANGE - 1;
int dist;
int count = 0;
target.x = -1;
target.y = -1;
for (monster_iterator mi; mi; ++mi)
{
if (invalid_monster(*mi))
continue;
// Don't arc to things we cannot hit.
if (beam.ignores_monster(*mi))
continue;
dist = grid_distance(source, mi->pos());
// check for the source of this arc
if (!dist)
continue;
// randomise distance (arcs don't care about a couple of feet)
dist += (random2(3) - 1);
// always ignore targets further than current one
if (dist > min_dist)
continue;
if (!cell_see_cell(source, mi->pos(), LOS_SOLID)
|| !cell_see_cell(caster->pos(), mi->pos(), LOS_SOLID_SEE))
{
continue;
}
// check for actors along the arc path
ray_def ray;
if (!find_ray(source, mi->pos(), ray, opc_solid))
continue;
while (ray.advance())
if (actor_at(ray.pos()))
break;
if (ray.pos() != mi->pos())
continue;
count++;
if (dist < min_dist)
{
// switch to looking for closer targets (but not always)
if (!one_chance_in(10))
{
min_dist = dist;
target = mi->pos();
count = 0;
}
}
else if (target.x == -1 || one_chance_in(count))
{
// either first target, or new selected target at
// min_dist == dist.
target = mi->pos();
}
}
// now check if the player is a target
dist = grid_distance(source, you.pos());
if (dist) // i.e., player was not the source
{
// distance randomised (as above)
dist += (random2(3) - 1);
// select player if only, closest, or randomly selected
if ((target.x == -1
|| dist < min_dist
|| (dist == min_dist && one_chance_in(count + 1)))
&& cell_see_cell(source, you.pos(), LOS_SOLID))
{
target = you.pos();
}
}
const bool see_source = you.see_cell(source);
const bool see_targ = you.see_cell(target);
if (target.x == -1)
{
if (see_source)
mprf("The %s grounds out.", beam.name.c_str());
break;
}
// Trying to limit message spamming here so we'll only mention
// the chaos at the start or when it's out of LoS.
if (first && see_source)
mpr("A swirling arc of seething chaos appears!");
first = false;
if (see_source && !see_targ)
mprf("The %s arcs out of your line of sight!", beam.name.c_str());
else if (!see_source && see_targ)
mprf("The %s suddenly appears!", beam.name.c_str());
beam.source = source;
beam.target = target;
beam.colour = ETC_RANDOM;
beam.ench_power = pow;
beam.damage = calc_dice(3, 5 + pow / 6);
beam.real_flavour = BEAM_CHAOS;
beam.flavour = BEAM_CHAOS;
// Be kinder to the caster.
if (target == caster->pos())
{
// This should not hit the caster, too scary as a player effect and
// too kind to the player as a monster effect.
if (spell_cast == SPELL_CHAIN_OF_CHAOS)
{
beam.real_flavour = BEAM_VISUAL;
beam.flavour = BEAM_VISUAL;
}
// Reduce damage when the spell arcs to the caster.
beam.damage.num = max(1, beam.damage.num / 2);
beam.damage.size = max(3, beam.damage.size / 2);
}
beam.fire();
}
return spret::success;
}
/*
* Handle the application of damage from a player spell that doesn't apply these
* through struct bolt. This can apply god conducts and handles any necessary
* death cleanup.
* @param mon The monster.
* @param damage The damage to apply, if any. Regardless of damage done,
* the monster will have death cleanup applied via
* monster_die() if it's now dead.
* @param flavour The beam flavour of damage.
* @param god_conducts If true, apply any god conducts, in which case the
* monster must be alive. Some callers need to apply
* effects prior to damage that might kill the monster,
* hence handle conducts on their own.
*/
static void _player_hurt_monster(monster &mon, int damage, beam_type flavour,
bool god_conducts = true, bool quiet = false)
{
ASSERT(mon.alive() || !god_conducts);
if (god_conducts && god_protects(&mon, false))
return;
god_conduct_trigger conducts[3];
if (god_conducts)
set_attack_conducts(conducts, mon, you.can_see(mon));
if (damage)
{
majin_bo_vampirism(mon, min(damage, mon.stat_hp()));
mon.hurt(&you, damage, flavour, KILLED_BY_BEAM);
}
if (mon.alive())
{
behaviour_event(&mon, ME_WHACK, &you);
if (damage && you.can_see(mon) && !quiet)
print_wounds(mon);
}
// monster::hurt() wasn't called, so we do death cleanup.
else if (!damage)
monster_die(mon, KILL_YOU, NON_MONSTER);
}
static bool _drain_lifeable(const actor* agent, const actor* act)
{
if (!actor_is_susceptible_to_vampirism(*act)
|| act->res_negative_energy() >= 3)
{
return false;
}
if (!agent)
return true;
const monster* mons = agent->as_monster();
const monster* m = act->as_monster();
return !(agent->is_player() && act->wont_attack()
|| mons && act->is_player() && mons->wont_attack()
|| mons && m && mons_atts_aligned(mons->attitude, m->attitude));
}
static int _los_spell_damage_actor(const actor* agent, actor &target,
bolt &beam, bool actual)
{
beam.thrower = (agent && agent->is_player()) ? KILL_YOU :
agent ? KILL_MON
: KILL_MISC;
// Set conducts here. The monster needs to be alive when this is done, and
// mons_adjust_flavoured() could kill it.
monster *mon_targ = target.as_monster();
god_conduct_trigger conducts[3];
if (actual && YOU_KILL(beam.thrower) && mon_targ)
set_attack_conducts(conducts, *mon_targ, you.can_see(target));
int hurted;
if (actual)
{
hurted = beam.damage.roll();
hurted = max(0, target.apply_ac(hurted));
}
else
{
// Tracers use the average for damage calculations.
hurted = (1 + beam.damage.num * beam.damage.size) / 2;
hurted = max(0, hurted - target.armour_class() / 2);
}
const bool doFlavour = actual && beam.origin_spell != SPELL_DRAIN_LIFE;
if (mon_targ)
hurted = mons_adjust_flavoured(mon_targ, beam, hurted, doFlavour);
else
hurted = check_your_resists(hurted, beam.flavour, beam.name, 0, doFlavour);
dprf("damage done: %d", hurted);
if (actual)
{
if (YOU_KILL(beam.thrower) && mon_targ)
{
_player_hurt_monster(*mon_targ, hurted, beam.flavour, false);
if (target.alive())
you.pet_target = target.mindex();
}
else if (hurted)
target.hurt(agent, hurted, beam.flavour);
// Cold-blooded creatures can be slowed.
if (beam.origin_spell == SPELL_OZOCUBUS_REFRIGERATION
&& target.alive())
{
target.expose_to_element(beam.flavour, 5);
}
}
// So that summons don't restore HP.
if (beam.origin_spell == SPELL_DRAIN_LIFE && target.is_summoned())
return 0;
return hurted;
}
/**
* Returns the number of monsters adjacent to the given position which other
* monsters can huddle against. (Reducing damage taken from Refrigeration.)
*/
int adjacent_huddlers(coord_def pos)
{
int adj_count = 0;
for (adjacent_iterator ai(pos); ai; ++ai)
{
const actor* act = actor_at(*ai);
if (!act || !act->is_monster())
continue;
const monster* mon = act->as_monster();
if (!mons_is_firewood(*mon) && !mons_is_conjured(mon->type))
++adj_count;
}
return adj_count;
}
static int _ozo_adj_dam(int base_dam, int adj_actors, bool actual)
{
switch (adj_actors)
{
case 0:
return base_dam;
case 1:
if (actual)
return div_rand_round(7 * base_dam, 10);
return 7 * base_dam / 10;
default:
if (actual)
return div_rand_round(2 * base_dam, 5);
return base_dam * 2 / 5;
}
}
static spret _cast_los_attack_spell(spell_type spell, int pow,
const actor* agent, bool actual,
bool fail, int* damage_done)
{
const bool player_caster = agent && agent->is_player();
const monster* mons = agent ? agent->as_monster() : nullptr;
const zap_type zap = spell_to_zap(spell);
if (zap == NUM_ZAPS)
return spret::abort;
bolt beam;
zappy(zap, pow, mons, beam);
beam.source_id = agent ? agent->mid : MID_NOBODY;
beam.foe_ratio = 80;
const char *player_msg = nullptr, *global_msg = nullptr,
*mons_vis_msg = nullptr, *mons_invis_msg = nullptr,
*prompt_verb = nullptr;
bool (*vulnerable)(const actor *, const actor *) = nullptr;
switch (spell)
{
case SPELL_OZOCUBUS_REFRIGERATION:
player_msg = "The heat is drained from your surroundings.";
global_msg = "Something drains the heat from around you.";
mons_vis_msg = " drains the heat from the surrounding"
" environment!";
mons_invis_msg = "The ambient heat is drained!";
prompt_verb = "refrigerate";
vulnerable = [](const actor *caster, const actor *act) {
return act != caster
// Players don't get immunity with rC+++.
&& (act->is_player() || act->res_cold() < 3)
&& !god_protects(caster, act->as_monster());
};
break;
case SPELL_DRAIN_LIFE:
player_msg = "You draw life from your surroundings.";
global_msg = "Something draws the life force from your"
" surroundings.";
mons_vis_msg = " draws from the surrounding life force!";
mons_invis_msg = "The surrounding life force dissipates!";
prompt_verb = "drain life";
vulnerable = &_drain_lifeable;
break;
case SPELL_SONIC_WAVE:
player_msg = "You send a blast of sound all around you.";
global_msg = "Something sends a blast of sound all around you.";
mons_vis_msg = " sends a blast of sound all around you!";
mons_invis_msg = "Sound blasts the surrounding area!";
// prompt_verb = "sing" The singing sword prompts in melee-attack
vulnerable = [](const actor *caster, const actor *act) {
return act != caster
&& !god_protects(caster, act->as_monster());
};
break;
default:
return spret::abort;
}
auto vul_hitfunc = [vulnerable](const actor *act) -> bool
{
return (*vulnerable)(&you, act);
};
if (actual)
{
if (player_caster)
{
targeter_radius hitfunc(&you, LOS_NO_TRANS);
// Singing Sword's spell shouldn't give a prompt at this time.
if (spell != SPELL_SONIC_WAVE)
{
if (stop_attack_prompt(hitfunc, prompt_verb, vul_hitfunc))
return spret::abort;
fail_check();
}
mpr(player_msg);
flash_view_delay(UA_PLAYER, beam.colour, 300, &hitfunc);
}
else
{
if (!agent)
mpr(global_msg);
else if (you.can_see(*agent))
simple_monster_message(*mons, mons_vis_msg);
else if (you.see_cell(agent->pos()))
mpr(mons_invis_msg);
if (!agent || you.see_cell(agent->pos()))
flash_view_delay(UA_MONSTER, beam.colour, 300);
}
}
vector<actor *> affected_actors;
map<actor*, int> ozo_adj_count;
for (actor_near_iterator ai((agent ? agent : &you)->pos(), LOS_NO_TRANS);
ai; ++ai)
{
if (!actual && !agent->can_see(**ai))
continue;
if (!(*vulnerable)(agent, *ai))
continue;
if ((*vulnerable)(agent, *ai))
affected_actors.push_back(*ai);
// For perf, don't count when running tracers.
if (spell == SPELL_OZOCUBUS_REFRIGERATION)
ozo_adj_count[*ai] = actual ? adjacent_huddlers(ai->pos()) : 0;
}
const int avg_damage = (1 + beam.damage.num * beam.damage.size) / 2;
int total_damage = 0;
const int base_dam_size = beam.damage.size;
for (auto a : affected_actors)
{
// Watch out for invalidation. Example: Ozocubu's refrigeration on
// a bunch of ballistomycete spores that blow each other up.
if (!a->alive())
continue;
if (spell == SPELL_OZOCUBUS_REFRIGERATION)
beam.damage.size = _ozo_adj_dam(base_dam_size, ozo_adj_count[a], actual);
int this_damage = _los_spell_damage_actor(agent, *a, beam, actual);
total_damage += this_damage;
if (actual || !this_damage)
continue;
if (a->is_monster() && !mons_is_threatening(*a->as_monster()))
continue;
if (!agent || !mons_aligned(a, agent))
{
beam.foe_info.count++;
beam.foe_info.power +=
(a->get_hit_dice() * this_damage / avg_damage);
}
else
{
beam.friend_info.count++;
beam.friend_info.power +=
(a->get_hit_dice() * this_damage / avg_damage);
}
}
if (damage_done)
*damage_done = total_damage;
if (actual)
return spret::success;
if (player_caster)
return beam.foe_info.count ? spret::success : spret::abort;
return mons_should_fire(beam) ? spret::success : spret::abort;
}
spret trace_los_attack_spell(spell_type spell, int pow, const actor* agent)
{
return _cast_los_attack_spell(spell, pow, agent, false, false, nullptr);
}
spret fire_los_attack_spell(spell_type spell, int pow, const actor* agent,
bool fail, int* damage_done)
{
return _cast_los_attack_spell(spell, pow, agent, true, fail, damage_done);
}
dice_def freeze_damage(int pow, bool random)
{
return dice_def(1, random ? 3 + div_rand_round(pow * 3, 10)
: 3 + pow * 3 / 10);
}
spret cast_freeze(int pow, monster* mons, bool fail)
{
pow = min(25, pow);
if (!mons || mons->submerged())
{
fail_check();
canned_msg(MSG_NOTHING_CLOSE_ENOUGH);
// If there's no monster there, you still pay the costs in
// order to prevent locating invisible/submerged monsters.
return spret::success;
}
if (stop_attack_prompt(mons, false, you.pos()))
{
canned_msg(MSG_OK);
return spret::abort;
}
fail_check();
// Set conducts here. The monster needs to be alive when this is done, and
// mons_adjust_flavoured() could kill it.
god_conduct_trigger conducts[3];
set_attack_conducts(conducts, *mons);
bolt beam;
beam.flavour = BEAM_COLD;
beam.thrower = KILL_YOU;
const int orig_hurted = freeze_damage(pow, true).roll();
// calculate the resist adjustment to punctuate
int hurted = mons_adjust_flavoured(mons, beam, orig_hurted, false);
mprf("You freeze %s%s%s",
mons->name(DESC_THE).c_str(),
hurted ? "" : " but do no damage",
attack_strength_punctuation(hurted).c_str());
// print the resist message and expose to the cold
mons_adjust_flavoured(mons, beam, orig_hurted);
_player_hurt_monster(*mons, hurted, beam.flavour, false);
if (mons->alive())
{
mons->expose_to_element(BEAM_COLD, orig_hurted);
you.pet_target = mons->mindex();
}
return spret::success;
}
// For airstrike purposes, how much empty space is there around
// the given target?
int airstrike_space_around(coord_def target, bool count_unseen)
{
int empty_space = 0;
for (adjacent_iterator ai(target); ai; ++ai)
{
if (!count_unseen && !env.map_knowledge(*ai).seen())
continue;
const auto feat = count_unseen ? env.grid(*ai)
: env.map_knowledge(*ai).feat();
if (feat_is_solid(feat))
continue;
if (count_unseen)
{
if (!actor_at(*ai))
++empty_space;
}
else if (you.pos() != *ai && !env.map_knowledge(*ai).monsterinfo())
++empty_space;
}
return empty_space;
}
spret cast_airstrike(int pow, coord_def target, bool fail)
{
if (cell_is_solid(target))
{
canned_msg(MSG_UNTHINKING_ACT);
return spret::abort;
}
monster* mons = monster_at(target);
if (!mons || mons->submerged())
{
fail_check();
canned_msg(MSG_SPELL_FIZZLES);
return spret::success; // still losing a turn
}
if (!god_protects(mons)
&& stop_attack_prompt(mons, false, you.pos()))
{
return spret::abort;
}
fail_check();
noisy(spell_effect_noise(SPELL_AIRSTRIKE), target);
bolt pbeam;
pbeam.flavour = BEAM_AIR;
const int empty_space = airstrike_space_around(target, true);
dice_def to_roll = base_airstrike_damage(pow, true);
to_roll.size += empty_space * AIRSTRIKE_PER_SPACE_BONUS;
int hurted = to_roll.roll();
#ifdef DEBUG_DIAGNOSTICS
const int preac = hurted;
#endif