-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
spl-cast.cc
2195 lines (1805 loc) · 63.8 KB
/
spl-cast.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 Spell casting and miscast functions.
**/
#include "AppHdr.h"
#include "spl-cast.h"
#include <iomanip>
#include <sstream>
#include "areas.h"
#include "art-enum.h"
#include "beam.h"
#include "branch.h"
#include "cloud.h"
#include "colour.h"
#include "describe.h"
#include "directn.h"
#include "effects.h"
#include "english.h"
#include "env.h"
#include "exercise.h"
#include "food.h"
#include "format.h"
#include "godabil.h"
#include "godconduct.h"
#include "goditem.h"
#include "hints.h"
#include "item_use.h"
#include "libutil.h"
#include "macro.h"
#include "menu.h"
#include "message.h"
#include "misc.h"
#include "mon-behv.h"
#include "mon-book.h"
#include "mon-cast.h"
#include "mon-place.h"
#include "mon-project.h"
#include "mon-util.h"
#include "mutation.h"
#include "options.h"
#include "ouch.h"
#include "output.h"
#include "player.h"
#include "prompt.h"
#include "religion.h"
#include "shout.h"
#include "skills.h"
#include "spl-book.h"
#include "spl-clouds.h"
#include "spl-damage.h"
#include "spl-goditem.h"
#include "spl-miscast.h"
#include "spl-monench.h"
#include "spl-other.h"
#include "spl-selfench.h"
#include "spl-summoning.h"
#include "spl-transloc.h"
#include "spl-wpnench.h"
#include "spl-zap.h"
#include "state.h"
#include "stepdown.h"
#include "stringutil.h"
#include "target.h"
#include "terrain.h"
#ifdef USE_TILE
#include "tilepick.h"
#endif
#include "transform.h"
#include "unicode.h"
#include "unwind.h"
#include "view.h"
#include "viewchar.h" // stringize_glyph
static int _spell_enhancement(spell_type spell);
static int _apply_enhancement(spell_type spell, const int initial_power);
static void _surge_power(spell_type spell)
{
int enhanced = _spell_enhancement(spell);
if (enhanced) // one way or the other {dlb}
{
const string modifier = (enhanced < -2) ? "extraordinarily" :
(enhanced == -2) ? "extremely" :
(enhanced == 2) ? "strong" :
(enhanced > 2) ? "huge"
: "";
mprf("You feel %s %s",
!modifier.length() ? "a"
: article_a(modifier).c_str(),
(enhanced < 0) ? "numb sensation."
: "surge of power!");
}
}
static string _spell_base_description(spell_type spell, bool viewing)
{
ostringstream desc;
int highlight = spell_highlight_by_utility(spell, COL_UNKNOWN, !viewing);
desc << "<" << colour_to_str(highlight) << ">" << left;
// spell name
desc << chop_string(spell_title(spell), 30);
// spell schools
desc << spell_schools_string(spell);
const int so_far = strwidth(desc.str()) - (strwidth(colour_to_str(highlight))+2);
if (so_far < 60)
desc << string(60 - so_far, ' ');
desc << "</" << colour_to_str(highlight) <<">";
// spell fail rate, level
highlight = failure_rate_colour(spell);
desc << "<" << colour_to_str(highlight) << ">";
char* failure = failure_rate_to_string(spell_fail(spell));
desc << chop_string(failure, 12);
free(failure);
desc << "</" << colour_to_str(highlight) << ">";
desc << spell_difficulty(spell);
return desc.str();
}
static string _spell_extra_description(spell_type spell, bool viewing)
{
ostringstream desc;
int highlight = spell_highlight_by_utility(spell, COL_UNKNOWN, !viewing);
desc << "<" << colour_to_str(highlight) << ">" << left;
// spell name
desc << chop_string(spell_title(spell), 30);
// spell power, spell range, hunger level, level
const string rangestring = spell_range_string(spell);
desc << chop_string(spell_power_string(spell), 14)
<< chop_string(rangestring, 16 + tagged_string_tag_length(rangestring))
<< chop_string(spell_hunger_string(spell), 12)
<< spell_difficulty(spell);
desc << "</" << colour_to_str(highlight) <<">";
return desc.str();
}
// selector is a boolean function that filters spells according
// to certain criteria. Currently used for Tiles to distinguish
// spells targeted on player vs. spells targeted on monsters.
int list_spells(bool toggle_with_I, bool viewing, bool allow_preselect,
const string &title, spell_selector selector)
{
if (toggle_with_I && get_spell_by_letter('I') != SPELL_NO_SPELL)
toggle_with_I = false;
#ifdef USE_TILE_LOCAL
const bool text_only = false;
#else
const bool text_only = true;
#endif
ToggleableMenu spell_menu(MF_SINGLESELECT | MF_ANYPRINTABLE
| MF_ALWAYS_SHOW_MORE | MF_ALLOW_FORMATTING,
text_only);
string titlestring = make_stringf("%-25.25s", title.c_str());
#ifdef USE_TILE_LOCAL
{
// [enne] - Hack. Make title an item so that it's aligned.
ToggleableMenuEntry* me =
new ToggleableMenuEntry(
" " + titlestring + " Type "
" Failure Level",
" " + titlestring + " Power "
"Range " + "Hunger" + " Level",
MEL_ITEM);
me->colour = BLUE;
spell_menu.add_entry(me);
}
#else
spell_menu.set_title(
new ToggleableMenuEntry(
" " + titlestring + " Type "
" Failure Level",
" " + titlestring + " Power "
"Range " + "Hunger" + " Level",
MEL_TITLE));
#endif
spell_menu.set_highlighter(nullptr);
spell_menu.set_tag("spell");
spell_menu.add_toggle_key('!');
string more_str = "Press '<w>!</w>' ";
if (toggle_with_I)
{
spell_menu.add_toggle_key('I');
more_str += "or '<w>I</w>' ";
}
if (!viewing)
spell_menu.menu_action = Menu::ACT_EXECUTE;
more_str += "to toggle spell view.";
spell_menu.set_more(formatted_string::parse_string(more_str));
// If there's only a single spell in the offered spell list,
// taking the selector function into account, preselect that one.
bool preselect_first = false;
if (allow_preselect)
{
int count = 0;
if (you.spell_no == 1)
count = 1;
else if (selector)
{
for (int i = 0; i < 52; ++i)
{
const char letter = index_to_letter(i);
const spell_type spell = get_spell_by_letter(letter);
if (!is_valid_spell(spell) || !(*selector)(spell))
continue;
// Break out early if we've got > 1 spells.
if (++count > 1)
break;
}
}
// Preselect the first spell if it's only spell applicable.
preselect_first = (count == 1);
}
if (allow_preselect || preselect_first
&& you.last_cast_spell != SPELL_NO_SPELL)
{
spell_menu.set_flags(spell_menu.get_flags() | MF_PRESELECTED);
}
for (int i = 0; i < 52; ++i)
{
const char letter = index_to_letter(i);
const spell_type spell = get_spell_by_letter(letter);
if (!is_valid_spell(spell))
continue;
if (selector && !(*selector)(spell))
continue;
bool preselect = (preselect_first
|| allow_preselect && you.last_cast_spell == spell);
ToggleableMenuEntry* me =
new ToggleableMenuEntry(_spell_base_description(spell, viewing),
_spell_extra_description(spell, viewing),
MEL_ITEM, 1, letter, preselect);
#ifdef USE_TILE
me->add_tile(tile_def(tileidx_spell(spell), TEX_GUI));
#endif
spell_menu.add_entry(me);
}
while (true)
{
vector<MenuEntry*> sel = spell_menu.show();
if (!crawl_state.doing_prev_cmd_again)
redraw_screen();
if (sel.empty())
return 0;
ASSERT(sel.size() == 1);
ASSERT(sel[0]->hotkeys.size() == 1);
if (spell_menu.menu_action == Menu::ACT_EXAMINE)
{
describe_spell(get_spell_by_letter(sel[0]->hotkeys[0]), nullptr);
redraw_screen();
}
else
return sel[0]->hotkeys[0];
}
}
static int _apply_spellcasting_success_boosts(spell_type spell, int chance)
{
int fail_reduce = 100;
if (in_good_standing(GOD_VEHUMET, 2) && vehumet_supports_spell(spell))
{
// [dshaligram] Fail rate multiplier used to be .5, scaled
// back to 67%.
fail_reduce = fail_reduce * 2 / 3;
}
const int wizardry = player_wizardry(spell);
if (wizardry > 0)
fail_reduce = fail_reduce * 6 / (7 + wizardry);
if (you.duration[DUR_BRILLIANCE])
fail_reduce = fail_reduce / 2;
// Hard cap on fail rate reduction.
if (fail_reduce < 50)
fail_reduce = 50;
return chance * fail_reduce / 100;
}
int spell_fail(spell_type spell)
{
int chance = 60;
// Don't cap power for failure rate purposes.
chance -= 6 * calc_spell_power(spell, false, true, false);
chance -= (you.intel() * 2);
const int armour_shield_penalty = player_armour_shield_spell_penalty();
dprf("Armour+Shield spell failure penalty: %d", armour_shield_penalty);
chance += armour_shield_penalty;
switch (spell_difficulty(spell))
{
case 1: chance += 3; break;
case 2: chance += 15; break;
case 3: chance += 35; break;
case 4: chance += 70; break;
case 5: chance += 100; break;
case 6: chance += 150; break;
case 7: chance += 200; break;
case 8: chance += 260; break;
case 9: chance += 330; break;
case 10: chance += 420; break;
case 11: chance += 500; break;
case 12: chance += 600; break;
default: chance += 750; break;
}
#if TAG_MAJOR_VERSION == 34
// Only apply this penalty to Dj because other species lose nutrition
// rather than gaining contamination when casting spells.
// Also, this penalty gives fairly precise information about contam
// level, and only Dj already has such information (on the contam bar).
// Other species would have to check their failure rates all the time
// when at yellow glow.
if (you.species == SP_DJINNI)
{
int64_t contam = you.magic_contamination;
// Just +25 on the edge of yellow glow, +200 in the middle of yellow,
// forget casting when in orange.
chance += contam * contam * contam / 5000000000LL;
}
#endif
int chance2 = chance;
const int chance_breaks[][2] =
{
{45, 45}, {42, 43}, {38, 41}, {35, 40}, {32, 38}, {28, 36},
{22, 34}, {16, 32}, {10, 30}, {2, 28}, {-7, 26}, {-12, 24},
{-18, 22}, {-24, 20}, {-30, 18}, {-38, 16}, {-46, 14},
{-60, 12}, {-80, 10}, {-100, 8}, {-120, 6}, {-140, 4},
{-160, 2}, {-180, 0}
};
for (const int (&cbrk)[2] : chance_breaks)
if (chance < cbrk[0])
chance2 = cbrk[1];
chance2 += get_form()->spellcasting_penalty;
chance2 -= 7 * player_mutation_level(MUT_PLACID_MAGIC);
chance2 += 7 * player_mutation_level(MUT_WILD_MAGIC);
chance2 += 4 * player_mutation_level(MUT_ANTI_WIZARDRY);
if (player_equip_unrand(UNRAND_HIGH_COUNCIL))
chance2 += 7;
chance2 += you.duration[DUR_MAGIC_SAPPED] / BASELINE_DELAY;
// Apply the effects of Vehumet and items of wizardry.
chance2 = _apply_spellcasting_success_boosts(spell, chance2);
if (chance2 > 100)
chance2 = 100;
return chance2;
}
int calc_spell_power(spell_type spell, bool apply_intel, bool fail_rate_check,
bool cap_power, bool rod)
{
int power = 0;
if (rod)
power = 5 + you.skill(SK_EVOCATIONS, 3);
else
{
unsigned int disciplines = get_spell_disciplines(spell);
int skillcount = count_bits(disciplines);
if (skillcount)
{
for (int ndx = 0; ndx <= SPTYP_LAST_EXPONENT; ndx++)
{
unsigned int bit = (1 << ndx);
if (disciplines & bit)
power += you.skill(spell_type2skill(bit), 200);
}
power /= skillcount;
}
power += you.skill(SK_SPELLCASTING, 50);
// Brilliance boosts spell power a bit (equivalent to three
// spell school levels).
if (!fail_rate_check && you.duration[DUR_BRILLIANCE])
power += 600;
if (apply_intel)
power = (power * you.intel()) / 10;
// [dshaligram] Enhancers don't affect fail rates any more, only spell
// power. Note that this does not affect Vehumet's boost in castability.
if (!fail_rate_check)
power = _apply_enhancement(spell, power);
// Wild magic boosts spell power but decreases success rate.
if (!fail_rate_check)
{
power *= (10 + 5 * player_mutation_level(MUT_WILD_MAGIC));
power /= (10 + 5 * player_mutation_level(MUT_PLACID_MAGIC));
}
// Augmentation boosts spell power at high HP.
if (!fail_rate_check)
{
power *= 10 + 4 * augmentation_amount();
power /= 10;
}
// Each level of horror reduces spellpower by 10%
if (you.duration[DUR_HORROR] && !fail_rate_check)
{
power *= 10;
power /= 10 + (you.props[HORROR_PENALTY_KEY].get_int() * 3) / 2;
}
power = stepdown_value(power / 100, 50, 50, 150, 200);
}
const int cap = spell_power_cap(spell);
if (cap > 0 && cap_power)
power = min(power, cap);
return power;
}
static int _spell_enhancement(spell_type spell)
{
const spschools_type typeflags = get_spell_disciplines(spell);
int enhanced = 0;
if (typeflags & SPTYP_CONJURATION)
enhanced += player_spec_conj();
if (typeflags & SPTYP_HEXES)
enhanced += player_spec_hex();
if (typeflags & SPTYP_CHARMS)
enhanced += player_spec_charm();
if (typeflags & SPTYP_SUMMONING)
enhanced += player_spec_summ();
if (typeflags & SPTYP_POISON)
enhanced += player_spec_poison();
if (typeflags & SPTYP_NECROMANCY)
enhanced += player_spec_death();
if (typeflags & SPTYP_FIRE)
enhanced += player_spec_fire() - player_spec_cold();
if (typeflags & SPTYP_ICE)
enhanced += player_spec_cold() - player_spec_fire();
if (typeflags & SPTYP_EARTH)
enhanced += player_spec_earth() - player_spec_air();
if (typeflags & SPTYP_AIR)
enhanced += player_spec_air() - player_spec_earth();
if (you.attribute[ATTR_SHADOWS])
enhanced -= 2;
if (you.form == TRAN_SHADOW)
enhanced -= 2;
enhanced += you.archmagi();
enhanced += player_equip_unrand(UNRAND_MAJIN);
#if TAG_MAJOR_VERSION == 34
if (you.species == SP_LAVA_ORC && temperature_effect(LORC_LAVA_BOOST)
&& (typeflags & SPTYP_FIRE) && (typeflags & SPTYP_EARTH))
{
enhanced++;
}
#endif
// These are used in an exponential way, so we'll limit them a bit. -- bwr
if (enhanced > 3)
enhanced = 3;
else if (enhanced < -3)
enhanced = -3;
return enhanced;
}
/**
* Apply the effects of spell enhancers (and de-enhancers) on spellpower.
*
* @param spell The spell in question.
* @param initial_power The power of the spell before enhancers are added.
* @return The power of the spell with enhancers considered.
*/
static int _apply_enhancement(spell_type spell, const int initial_power)
{
const int enhancer_levels = _spell_enhancement(spell);
int power = initial_power;
if (enhancer_levels > 0)
{
for (int i = 0; i < enhancer_levels; i++)
{
power *= 15;
power /= 10;
}
}
else if (enhancer_levels < 0)
{
for (int i = enhancer_levels; i < 0; i++)
power /= 2;
}
return power;
}
void inspect_spells()
{
if (!you.spell_no)
{
canned_msg(MSG_NO_SPELLS);
return;
}
list_spells(true, true);
}
static bool _can_cast()
{
if (!get_form()->can_cast)
{
canned_msg(MSG_PRESENT_FORM);
return false;
}
if (you.duration[DUR_WATER_HOLD] && !you.res_water_drowning())
{
mpr("You cannot cast spells while unable to breathe!");
return false;
}
if (you.stat_zero[STAT_INT])
{
mpr("You lack the mental capacity to cast spells.");
return false;
}
// Randart weapons.
if (you.no_cast())
{
mpr("Something interferes with your magic!");
return false;
}
if (!you.spell_no)
{
canned_msg(MSG_NO_SPELLS);
return false;
}
if (you.berserk())
{
canned_msg(MSG_TOO_BERSERK);
return false;
}
if (you.confused())
{
mpr("You're too confused to cast spells.");
return false;
}
if (silenced(you.pos()))
{
mpr("You cannot cast spells when silenced!");
more();
return false;
}
if (!you.undead_state() && !you_foodless()
&& you.hunger_state == HS_STARVING)
{
canned_msg(MSG_NO_ENERGY);
more();
return false;
}
return true;
}
void do_cast_spell_cmd(bool force)
{
if (!cast_a_spell(!force))
flush_input_buffer(FLUSH_ON_FAILURE);
}
/**
* Cast a spell.
*
* Handles general preconditions & costs.
*
* @param check_range If true, abort if no targets are in range. (z vs Z)
* @param spell The type of spell to be cast.
* @return Whether the spell was successfully cast.
**/
bool cast_a_spell(bool check_range, spell_type spell)
{
if (!_can_cast())
{
crawl_state.zero_turns_taken();
return false;
}
if (crawl_state.game_is_hints())
Hints.hints_spell_counter++;
if (spell == SPELL_NO_SPELL)
{
int keyin = 0;
while (true)
{
#ifdef TOUCH_UI
keyin = list_spells(true, false);
if (!keyin)
keyin = ESCAPE;
if (!crawl_state.doing_prev_cmd_again)
redraw_screen();
if (isaalpha(keyin) || key_is_escape(keyin))
break;
else
clear_messages();
keyin = 0;
#else
if (keyin == 0)
{
if (you.spell_no == 1)
{
// Set last_cast_spell to the current only spell.
for (int i = 0; i < 52; ++i)
{
const char letter = index_to_letter(i);
const spell_type spl = get_spell_by_letter(letter);
if (!is_valid_spell(spl))
continue;
you.last_cast_spell = spl;
break;
}
}
if (you.last_cast_spell == SPELL_NO_SPELL)
mprf(MSGCH_PROMPT, "Cast which spell? (? or * to list) ");
else
{
mprf(MSGCH_PROMPT, "Casting: <w>%s</w>",
spell_title(you.last_cast_spell));
mprf(MSGCH_PROMPT, "Confirm with . or Enter, or press ? or * to list all spells.");
}
keyin = get_ch();
}
if (keyin == '?' || keyin == '*')
{
keyin = list_spells(true, false);
if (!keyin)
keyin = ESCAPE;
if (!crawl_state.doing_prev_cmd_again)
redraw_screen();
if (isaalpha(keyin) || key_is_escape(keyin))
break;
else
clear_messages();
keyin = 0;
}
else
break;
#endif
}
if (key_is_escape(keyin))
{
canned_msg(MSG_OK);
crawl_state.zero_turns_taken();
return false;
}
else if (keyin == '.' || keyin == CK_ENTER)
spell = you.last_cast_spell;
else if (!isaalpha(keyin))
{
mpr("You don't know that spell.");
crawl_state.zero_turns_taken();
return false;
}
else
spell = get_spell_by_letter(keyin);
}
if (spell == SPELL_NO_SPELL)
{
mpr("You don't know that spell.");
crawl_state.zero_turns_taken();
return false;
}
const int cost = spell_mana(spell);
if (!enough_mp(cost, true))
{
mpr("You don't have enough magic to cast that spell.");
crawl_state.zero_turns_taken();
return false;
}
if (check_range && spell_no_hostile_in_range(spell))
{
// Abort if there are no hostiles within range, but flash the range
// markers for a short while.
mpr("You can't see any susceptible monsters within range! "
"(Use <w>Z</w> to cast anyway.)");
if (Options.use_animations & UA_RANGE)
{
targetter_smite range(&you, calc_spell_range(spell), 0, 0, true);
range_view_annotator show_range(&range);
delay(50);
}
crawl_state.zero_turns_taken();
return false;
}
if (you.undead_state() == US_ALIVE && !you_foodless()
&& you.hunger <= spell_hunger(spell))
{
canned_msg(MSG_NO_ENERGY);
crawl_state.zero_turns_taken();
return false;
}
// This needs more work: there are spells which are hated but allowed if
// they don't have a certain effect. You may use Poison Arrow on those
// immune, use Mephitic Cloud to shield yourself from other clouds.
// There are also spells which god_hates_spell() doesn't recognize.
//
// I'm disabling this code for now except for excommunication, please
// re-enable if you can fix it.
if (/*god_hates_spell*/god_loathes_spell(spell, you.religion))
{
// None currently dock just piety, right?
if (!yesno(god_loathes_spell(spell, you.religion) ?
"<lightred>Casting this spell will cause instant excommunication!"
"</lightred> Really cast?" :
"Casting this spell will put you into penance. Really cast?",
true, 'n'))
{
canned_msg(MSG_OK);
crawl_state.zero_turns_taken();
return false;
}
}
const bool staff_energy = player_energy();
you.last_cast_spell = spell;
// Silently take MP before the spell.
dec_mp(cost, true);
const spret_type cast_result = your_spells(spell, 0, true);
if (cast_result == SPRET_ABORT)
{
crawl_state.zero_turns_taken();
// Return the MP since the spell is aborted.
inc_mp(cost, true);
return false;
}
// XXX: the message order here might not be the best
zin_recite_interrupt();
if (cast_result == SPRET_SUCCESS)
{
practise(EX_DID_CAST, spell);
did_god_conduct(DID_SPELL_CASTING, 1 + random2(5));
count_action(CACT_CAST, spell);
}
else
practise(EX_DID_MISCAST, spell);
#if TAG_MAJOR_VERSION == 34
// Nasty special cases.
if (you.species == SP_DJINNI && cast_result == SPRET_SUCCESS
&& (spell == SPELL_BORGNJORS_REVIVIFICATION
|| spell == SPELL_SUBLIMATION_OF_BLOOD && you.hp == you.hp_max))
{
// These spells have replenished essence to full.
inc_mp(cost, true);
}
else // Redraw MP
#endif
flush_mp();
if (!staff_energy && you.undead_state() != US_UNDEAD)
{
const int spellh = spell_hunger(spell);
if (calc_hunger(spellh) > 0)
{
make_hungry(spellh, true, true);
learned_something_new(HINT_SPELL_HUNGER);
}
}
you.turn_is_over = true;
alert_nearby_monsters();
return true;
}
/**
* Handles divine response to spellcasting.
*
* @param spell The type of spell just cast.
*/
static void _spellcasting_god_conduct(spell_type spell)
{
// If you are casting while a god is acting, then don't do conducts.
// (Presumably Xom is forcing you to cast a spell.)
if (crawl_state.is_god_acting())
return;
const int conduct_level = 10 + spell_difficulty(spell);
if (is_unholy_spell(spell) || you.spellcasting_unholy())
did_god_conduct(DID_UNHOLY, conduct_level);
if (is_unclean_spell(spell))
did_god_conduct(DID_UNCLEAN, conduct_level);
if (is_chaotic_spell(spell))
did_god_conduct(DID_CHAOS, conduct_level);
if (is_corpse_violating_spell(spell))
did_god_conduct(DID_CORPSE_VIOLATION, conduct_level);
if (spell_typematch(spell, SPTYP_NECROMANCY))
{
did_god_conduct(DID_NECROMANCY, conduct_level);
if (spell == SPELL_NECROMUTATION && is_good_god(you.religion))
excommunication();
}
if (spell == SPELL_STATUE_FORM && you_worship(GOD_YREDELEMNUL))
excommunication();
}
/**
* Handles side effects of successfully casting a spell.
*
* Spell noise, magic 'sap' effects, and god conducts.
*
* @param spell The type of spell just cast.
* @param god Which god is casting the spell; NO_GOD if it's you.
* @param real_spell An actual spellcast, vs. spell-like effects (rods?)
*/
static void _spellcasting_side_effects(spell_type spell, god_type god,
bool real_spell)
{
_spellcasting_god_conduct(spell);
if (god == GOD_NO_GOD)
{
if (you.duration[DUR_SAP_MAGIC] && real_spell)
{
mprf(MSGCH_WARN, "Your control over your magic is sapped.");
you.increase_duration(DUR_MAGIC_SAPPED,
spell_difficulty(spell),
100);
}
// Make some noise if it's actually the player casting.
noisy(spell_noise(spell), you.pos());
}
alert_nearby_monsters();
}
/**
* Is the player currently unable to cast the given spell?
*
* @param[in] spell The spell to check.
* @param[out] msg A string set to the (or a) reason that the spell is
* uncastable, if it is.
* @param[in] temp Include checks for volatile or temporary states
* (status effects, mana, gods, items, etc.).
* @param[in] evoke Was this spell 'cast' through item evocation?
* @return True if the spell is uncastable, false otherwise.
*/
bool spell_is_uncastable(spell_type spell, string &msg, bool temp, bool evoked)
{
msg = spell_uselessness_reason(spell, temp, true, evoked);
return msg != "";
}
#ifdef WIZARD
static void _try_monster_cast(spell_type spell, int powc,
dist &spd, bolt &beam)
{
if (monster_at(you.pos()))
{
mpr("Couldn't try casting monster spell because you're "
"on top of a monster.");
return;
}
monster* mon = get_free_monster();
if (!mon)
{
mpr("Couldn't try casting monster spell because there is "
"no empty monster slot.");
return;
}
mpr("Invalid player spell, attempting to cast it as monster spell.");
mon->mname = "Dummy Monster";
mon->type = MONS_HUMAN;
mon->behaviour = BEH_SEEK;
mon->attitude = ATT_FRIENDLY;
mon->flags = (MF_NO_REWARD | MF_JUST_SUMMONED | MF_SEEN
| MF_WAS_IN_VIEW | MF_HARD_RESET);
mon->hit_points = you.hp;
mon->set_hit_dice(you.experience_level);
mon->set_position(you.pos());
mon->target = spd.target;
mon->mid = MID_PLAYER;
if (!spd.isTarget)
mon->foe = MHITNOT;
else if (!monster_at(spd.target))
{
if (spd.isMe())
mon->foe = MHITYOU;
else
mon->foe = MHITNOT;
}
else
mon->foe = mgrd(spd.target);
mgrd(you.pos()) = mon->mindex();
mons_cast(mon, beam, spell, MON_SPELL_NO_FLAGS);
mon->reset();
}
#endif // WIZARD
static void _maybe_cancel_repeat(spell_type spell)
{
switch (spell)
{
case SPELL_DELAYED_FIREBALL: crawl_state.cant_cmd_repeat(make_stringf("You can't repeat %s.",
spell_title(spell)));