-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
evoke.cc
1293 lines (1111 loc) · 35.7 KB
/
evoke.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 Functions for using some of the wackier inventory items.
**/
#include "AppHdr.h"
#include "evoke.h"
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include "act-iter.h"
#include "areas.h"
#include "artefact.h"
#include "branch.h"
#include "chardump.h"
#include "cloud.h"
#include "coordit.h"
#include "delay.h"
#include "directn.h"
#include "dungeon.h"
#include "english.h"
#include "env.h"
#include "exercise.h"
#include "fight.h"
#include "god-abil.h"
#include "god-conduct.h"
#include "god-passive.h"
#include "invent.h"
#include "item-prop.h"
#include "items.h"
#include "level-state-type.h"
#include "libutil.h"
#include "losglobal.h"
#include "message.h"
#include "mgen-data.h"
#include "misc.h"
#include "mon-behv.h"
#include "mon-clone.h"
#include "mon-pick.h"
#include "mon-place.h"
#include "mutant-beast.h"
#include "place.h"
#include "player.h"
#include "player-stats.h"
#include "prompt.h"
#include "religion.h"
#include "shout.h"
#include "skills.h"
#include "spl-book.h"
#include "spl-cast.h"
#include "spl-clouds.h"
#include "spl-damage.h"
#include "spl-util.h"
#include "state.h"
#include "stepdown.h"
#include "stringutil.h"
#include "tag-version.h"
#include "target.h"
#include "terrain.h"
#include "throw.h"
#ifdef USE_TILE
#include "tilepick.h"
#endif
#include "transform.h"
#include "traps.h"
#include "unicode.h"
#include "view.h"
static bool _evoke_horn_of_geryon()
{
bool created = false;
if (silenced(you.pos()))
{
mpr("You can't produce a sound!");
return false;
}
mprf(MSGCH_SOUND, "You produce a hideous howling noise!");
did_god_conduct(DID_EVIL, 3);
int num = 1;
const int adjusted_power =
player_adjust_evoc_power(you.skill(SK_EVOCATIONS, 10));
if (adjusted_power + random2(90) > 130)
++num;
if (adjusted_power + random2(90) > 180)
++num;
if (adjusted_power + random2(90) > 230)
++num;
for (int n = 0; n < num; ++n)
{
monster* mon;
beh_type beh = BEH_HOSTILE;
if (random2(adjusted_power) > 7)
beh = BEH_FRIENDLY;
mgen_data mg(MONS_HELL_BEAST, beh, you.pos(), MHITYOU, MG_FORCE_BEH);
mg.set_summoned(&you, 3, SPELL_NO_SPELL);
mg.set_prox(PROX_CLOSE_TO_PLAYER);
mon = create_monster(mg);
if (mon)
created = true;
}
if (!created)
mpr("Nothing answers your call.");
return true;
}
/**
* Spray lightning in all directions. (Randomly lightning bolt or OoE.)
*
* @param range The range of the beams. (As with all beams, eventually
* capped at LOS.)
* @param power The power of the beams. (Affects damage.)
*/
static void _spray_lightning(int range, int power)
{
const zap_type zap = random_choose_weighted(3, ZAP_LIGHTNING_BOLT,
2, ZAP_ORB_OF_ELECTRICITY);
bolt beam;
// range has no tracer, so randomness is ok
beam.range = range;
beam.source = you.pos();
beam.target = you.pos();
beam.target.x += random2(13) - 6;
beam.target.y += random2(13) - 6;
// Non-controlleable, so no player tracer.
zapping(zap, power, beam);
}
/**
* Evoke a lightning rod, creating an arc of lightning that can be sustained
* by continuing to evoke.
*
* @return Whether anything happened.
*/
static bool _lightning_rod(dist *preselect)
{
const int power =
player_adjust_evoc_power(5 + you.skill(SK_EVOCATIONS, 3));
const spret ret = your_spells(SPELL_THUNDERBOLT, power, false,
nullptr, preselect);
if (ret == spret::abort)
return false;
return true;
}
/**
* Spray lightning in all directions around the player.
*
* Quantity, range & power increase with level.
*/
void black_drac_breath()
{
const int num_shots = roll_dice(2, 1 + you.experience_level / 7);
const int range = you.experience_level / 3 + 5; // 5-14
const int power = 25 + (you.form == transformation::dragon
? 2 * you.experience_level : you.experience_level);
for (int i = 0; i < num_shots; ++i)
_spray_lightning(range, power);
}
/**
* Returns the MP cost of zapping a wand, depending on the player's MP-powered wands
* level and their available MP (or HP, if they're a djinn).
*/
int wand_mp_cost()
{
const int cost = you.get_mutation_level(MUT_MP_WANDS) * 3;
if (you.has_mutation(MUT_HP_CASTING))
return min(you.hp - 1, cost);
// Update mutation-data.h when updating this value.
return min(you.magic_points, cost);
}
int wand_power()
{
const int mp_cost = wand_mp_cost();
return (15 + you.skill(SK_EVOCATIONS, 7) / 2) * (mp_cost + 9) / 9;
}
void zap_wand(int slot, dist *_target)
{
if (inv_count() < 1)
{
canned_msg(MSG_NOTHING_CARRIED); // why is this handled here??
return;
}
if (!evoke_check(slot))
return;
int item_slot;
if (slot != -1)
item_slot = slot;
else
{
item_slot = prompt_invent_item("Zap which item?",
menu_type::invlist,
OBJ_WANDS,
OPER_ZAP);
}
if (prompt_failed(item_slot))
return;
item_def& wand = you.inv[item_slot];
if (wand.base_type != OBJ_WANDS)
{
mpr("You can't zap that!");
return;
}
if (!evoke_check(slot))
return;
// If you happen to be wielding the wand, its display might change.
if (you.equip[EQ_WEAPON] == item_slot)
you.wield_change = true;
const int mp_cost = wand_mp_cost();
const int power = wand_power();
pay_mp(mp_cost);
const spell_type spell =
spell_in_wand(static_cast<wand_type>(wand.sub_type));
spret ret = your_spells(spell, power, false, &wand, _target);
if (ret == spret::abort)
{
refund_mp(mp_cost);
return;
}
else if (ret == spret::fail)
{
refund_mp(mp_cost);
canned_msg(MSG_NOTHING_HAPPENS);
you.turn_is_over = true;
return;
}
// Spend MP.
if (mp_cost)
finalize_mp_cost();
// Take off a charge.
wand.charges--;
if (wand.charges == 0)
{
ASSERT(in_inventory(wand));
mpr("The now-empty wand crumbles to dust.");
dec_inv_item_quantity(wand.link, 1);
}
practise_evoking(1);
count_action(CACT_EVOKE, EVOC_WAND);
alert_nearby_monsters();
you.turn_is_over = true;
}
string manual_skill_names(bool short_text)
{
skill_set skills;
for (skill_type sk = SK_FIRST_SKILL; sk < NUM_SKILLS; sk++)
if (you.skill_manual_points[sk])
skills.insert(sk);
if (short_text && skills.size() > 1)
{
char buf[40];
sprintf(buf, "%lu skills", (unsigned long) skills.size());
return string(buf);
}
else
return skill_names(skills);
}
static bool _box_of_beasts()
{
mpr("You open the lid...");
// two rolls to reduce std deviation - +-6 so can get < max even at 27 sk
int rnd_factor = random2(7);
rnd_factor -= random2(7);
const int hd_min = min(27,
player_adjust_evoc_power(you.skill(SK_EVOCATIONS)
+ rnd_factor));
const int tier = mutant_beast_tier(hd_min);
ASSERT(tier < NUM_BEAST_TIERS);
mgen_data mg(MONS_MUTANT_BEAST, BEH_FRIENDLY, you.pos(), MHITYOU,
MG_AUTOFOE);
mg.set_summoned(&you, 3 + random2(3), 0);
mg.hd = beast_tiers[tier];
dprf("hd %d (min %d, tier %d)", mg.hd, hd_min, tier);
const monster* mons = create_monster(mg);
if (!mons)
{
// Failed to create monster for some reason
mpr("...but nothing happens.");
return false;
}
mprf("...and %s %s out!",
mons->name(DESC_A).c_str(), mons->airborne() ? "flies" : "leaps");
did_god_conduct(DID_CHAOS, random_range(5,10));
return true;
}
static bool _make_zig(item_def &zig)
{
if (feat_is_critical(env.grid(you.pos()))
|| player_in_branch(BRANCH_ARENA))
{
mpr("You can't place a gateway to a ziggurat here.");
return false;
}
for (int lev = 1; lev <= brdepth[BRANCH_ZIGGURAT]; lev++)
{
if (is_level_on_stack(level_id(BRANCH_ZIGGURAT, lev))
|| you.where_are_you == BRANCH_ZIGGURAT)
{
mpr("Finish your current ziggurat first!");
return false;
}
}
ASSERT(in_inventory(zig));
dec_inv_item_quantity(zig.link, 1);
dungeon_terrain_changed(you.pos(), DNGN_ENTER_ZIGGURAT);
mpr("You set the figurine down, and a mystic portal to a ziggurat forms.");
return true;
}
static int _gale_push_dist(const actor* agent, const actor* victim, int pow)
{
int dist = 1 + random2(pow / 20);
if (victim->body_size(PSIZE_BODY) < SIZE_MEDIUM)
dist++;
else if (victim->body_size(PSIZE_BODY) > SIZE_LARGE)
dist /= 2;
else if (victim->body_size(PSIZE_BODY) > SIZE_MEDIUM)
dist -= 1;
int range = victim->pos().distance_from(agent->pos());
if (range > 5)
dist -= 2;
else if (range > 2)
dist--;
if (dist < 0)
return 0;
else
return dist;
}
static double _angle_between(coord_def origin, coord_def p1, coord_def p2)
{
double ang0 = atan2(p1.x - origin.x, p1.y - origin.y);
double ang = atan2(p2.x - origin.x, p2.y - origin.y);
return min(fabs(ang - ang0), fabs(ang - ang0 + 2 * PI));
}
void wind_blast(actor* agent, int pow, coord_def target)
{
vector<actor *> act_list;
int radius = min(5, 4 + div_rand_round(pow, 60));
for (actor_near_iterator ai(agent->pos(), LOS_SOLID); ai; ++ai)
{
if (ai->is_stationary()
|| ai->pos().distance_from(agent->pos()) > radius
|| ai->pos() == agent->pos() // so it's never aimed_at_feet
|| !target.origin()
&& _angle_between(agent->pos(), target, ai->pos()) > PI/4.0)
{
continue;
}
act_list.push_back(*ai);
}
far_to_near_sorter sorter = {agent->pos()};
sort(act_list.begin(), act_list.end(), sorter);
bolt wind_beam;
wind_beam.hit = AUTOMATIC_HIT;
wind_beam.pierce = true;
wind_beam.affects_nothing = true;
wind_beam.source = agent->pos();
wind_beam.range = LOS_RADIUS;
wind_beam.is_tracer = true;
map<actor *, coord_def> collisions;
bool player_affected = false;
vector<monster *> affected_monsters;
for (actor *act : act_list)
{
wind_beam.target = act->pos();
wind_beam.fire();
int push = _gale_push_dist(agent, act, pow);
bool pushed = false;
for (unsigned int j = 0; j < wind_beam.path_taken.size() - 1 && push;
++j)
{
if (wind_beam.path_taken[j] == act->pos())
{
coord_def newpos = wind_beam.path_taken[j+1];
if (!actor_at(newpos) && !cell_is_solid(newpos)
&& act->can_pass_through(newpos)
&& act->is_habitable(newpos))
{
act->move_to_pos(newpos);
if (act->is_player())
stop_delay(true);
--push;
pushed = true;
}
else //Try to find an alternate route to push
{
bool success = false;
for (adjacent_iterator di(newpos); di; ++di)
{
if (adjacent(*di, act->pos())
&& di->distance_from(agent->pos())
== newpos.distance_from(agent->pos())
&& !actor_at(*di) && !cell_is_solid(*di)
&& act->can_pass_through(*di)
&& act->is_habitable(*di))
{
act->move_to_pos(*di);
if (act->is_player())
stop_delay(true);
--push;
pushed = true;
// Adjust wind path for moved monster
wind_beam.target = *di;
wind_beam.fire();
success = true;
break;
}
}
// If no luck, they slam into something.
if (!success)
collisions.insert(make_pair(act, newpos));
}
}
}
if (pushed)
{
if (act->is_monster())
{
act->as_monster()->speed_increment -= random2(6) + 4;
if (you.can_see(*act))
affected_monsters.push_back(act->as_monster());
}
else
player_affected = true;
}
}
// Now move clouds
vector<coord_def> cloud_list;
for (distance_iterator di(agent->pos(), true, false, radius + 2); di; ++di)
{
if (cloud_at(*di)
&& cell_see_cell(agent->pos(), *di, LOS_SOLID)
&& (target.origin()
|| _angle_between(agent->pos(), target, *di) <= PI/4.0))
{
cloud_list.push_back(*di);
}
}
for (int i = cloud_list.size() - 1; i >= 0; --i)
{
wind_beam.target = cloud_list[i];
wind_beam.fire();
int dist = cloud_list[i].distance_from(agent->pos());
int push = (dist > 5 ? 2 : dist > 2 ? 3 : 4);
if (dist == 0 && agent->is_player())
{
delete_cloud(agent->pos());
break;
}
for (unsigned int j = 0;
j < wind_beam.path_taken.size() - 1 && push;
++j)
{
if (wind_beam.path_taken[j] == cloud_list[i])
{
coord_def newpos = wind_beam.path_taken[j+1];
if (!cell_is_solid(newpos)
&& !cloud_at(newpos))
{
swap_clouds(newpos, wind_beam.path_taken[j]);
--push;
}
else //Try to find an alternate route to push
{
for (distance_iterator di(wind_beam.path_taken[j],
false, true, 1); di; ++di)
{
if (di->distance_from(agent->pos())
== newpos.distance_from(agent->pos())
&& *di != agent->pos() // never aimed_at_feet
&& !cell_is_solid(*di)
&& !cloud_at(*di))
{
swap_clouds(*di, wind_beam.path_taken[j]);
--push;
wind_beam.target = *di;
wind_beam.fire();
j--;
break;
}
}
}
}
}
}
if (agent->is_player())
{
// Nemelex card only.
if (pow > 120)
mpr("A mighty gale blasts forth from the card!");
else
mpr("A fierce wind blows from the card.");
}
noisy(8, agent->pos());
if (player_affected)
mpr("You are blown backwards!");
if (!affected_monsters.empty())
{
counted_monster_list affected = counted_monster_list(affected_monsters);
const string message =
make_stringf("%s %s blown away by the wind.",
affected.describe().c_str(),
conjugate_verb("be", affected.count() > 1).c_str());
if (strwidth(message) < get_number_of_cols() - 2)
mpr(message);
else
mpr("The monsters around you are blown away!");
}
for (auto it : collisions)
if (it.first->alive())
it.first->collide(it.second, agent, pow);
bool did_disperse = false;
// Handle trap triggering, finally. A dispersal before we finish
// would lead to weird crashes and behavior in the preceeding.
for (auto m : affected_monsters)
{
if (!m->alive())
continue;
coord_def landing = m->pos();
// XXX: this doesn't properly fire lua position triggers
m->apply_location_effects(landing);
// Dispersal will fire the location effects for everything dispersed;
// it's still possible for something to get blown somewhere it needs
// a location effect and not subsequently dispersed but handling that
// is more trouble than this headache already is.
if (m->pos() != landing)
{
did_disperse = true;
break;
}
}
if (player_affected && !did_disperse)
you.apply_location_effects(you.pos());
}
static bool _phial_of_floods(dist *target)
{
dist target_local;
if (!target)
target = &target_local;
bolt beam;
const int base_pow = 10 + you.skill(SK_EVOCATIONS, 4); // placeholder?
zappy(ZAP_PRIMAL_WAVE, base_pow, false, beam);
beam.range = LOS_RADIUS;
beam.aimed_at_spot = true;
// TODO: this needs a custom targeter
direction_chooser_args args;
args.mode = TARG_HOSTILE;
args.top_prompt = "Aim the phial where?";
if (spell_direction(*target, beam, &args)
&& player_tracer(ZAP_PRIMAL_WAVE, base_pow, beam))
{
const int power = player_adjust_evoc_power(base_pow);
// use real power to recalc hit/dam
zappy(ZAP_PRIMAL_WAVE, power, false, beam);
beam.fire();
return true;
}
return false;
}
static spret _phantom_mirror(dist *target)
{
bolt beam;
monster* victim = nullptr;
dist target_local;
if (!target)
target = &target_local;
targeter_smite tgt(&you, LOS_RADIUS, 0, 0);
direction_chooser_args args;
args.restricts = DIR_TARGET;
args.needs_path = false;
args.self = confirm_prompt_type::cancel;
args.top_prompt = "Aiming: <white>Phantom Mirror</white>";
args.hitfunc = &tgt;
if (!spell_direction(*target, beam, &args))
return spret::abort;
victim = monster_at(beam.target);
if (!victim || !you.can_see(*victim))
{
if (beam.target == you.pos())
mpr("You can't use the mirror on yourself.");
else
mpr("You can't see anything there to clone.");
return spret::abort;
}
// Mirrored monsters (including by Mara, rakshasas) can still be
// re-reflected.
if (!actor_is_illusion_cloneable(victim)
&& !victim->has_ench(ENCH_PHANTOM_MIRROR))
{
mpr("The mirror can't reflect that.");
return spret::abort;
}
monster* mon = clone_mons(victim, true, nullptr, ATT_FRIENDLY);
if (!mon)
{
canned_msg(MSG_NOTHING_HAPPENS);
return spret::fail;
}
const int power = player_adjust_evoc_power(5 + you.skill(SK_EVOCATIONS, 3));
int dur = min(6, max(1,
player_adjust_evoc_power(
you.skill(SK_EVOCATIONS, 1) / 4 + 1)
* (100 - victim->check_willpower(&you, power)) / 100));
mon->mark_summoned(dur, true, SPELL_PHANTOM_MIRROR);
mon->summoner = MID_PLAYER;
mons_add_blame(mon, "mirrored by the player character");
mon->add_ench(ENCH_PHANTOM_MIRROR);
mon->add_ench(mon_enchant(ENCH_DRAINED,
div_rand_round(mon->get_experience_level(), 3),
&you, INFINITE_DURATION));
mon->behaviour = BEH_SEEK;
set_nearest_monster_foe(mon);
mprf("You reflect %s with the mirror!",
victim->name(DESC_THE).c_str());
return spret::success;
}
static bool _valid_tremorstone_target(const monster &m)
{
return !mons_is_firewood(m)
&& !god_protects(&m)
&& !always_shoot_through_monster(&you, m);
}
/**
* Find the cell at range 3 closest to the center of mass of monsters in range,
* or a random range 3 cell if there are none.
*
* @param see_targets a boolean parameter indicating if the user can see any of
* the targets
* @return The cell in question.
*/
static coord_def _find_tremorstone_target(bool& see_targets)
{
coord_def com = {0, 0};
see_targets = false;
int num = 0;
for (radius_iterator ri(you.pos(), LOS_NO_TRANS); ri; ++ri)
{
if (monster_at(*ri) && _valid_tremorstone_target(*monster_at(*ri)))
{
com += *ri;
see_targets = see_targets || you.can_see(*monster_at(*ri));
++num;
}
}
coord_def target = {0, 0};
int distance = LOS_RADIUS * num;
int ties = 0;
for (radius_iterator ri(you.pos(), 3, C_SQUARE, LOS_NO_TRANS, true); ri; ++ri)
{
if (ri->distance_from(you.pos()) != 3 || cell_is_solid(*ri))
continue;
if (num > 0)
{
if (com.distance_from((*ri) * num) < distance)
{
ties = 1;
target = *ri;
distance = com.distance_from((*ri) * num);
}
else if (com.distance_from((*ri) * num) == distance
&& one_chance_in(++ties))
{
target = *ri;
}
}
else if (one_chance_in(++ties))
target = *ri;
}
return target;
}
/**
* Find an adjacent tile for a tremorstone explosion to go off in.
*
* @param center The original target of the stone.
* @return The new, final origin of the stone's explosion.
*/
static coord_def _fuzz_tremorstone_target(coord_def center)
{
coord_def chosen = center;
int seen = 1;
for (adjacent_iterator ai(center); ai; ++ai)
if (!cell_is_solid(*ai) && one_chance_in(++seen))
chosen = *ai;
return chosen;
}
/**
* Number of explosions, scales up from 1 at 0 evo to 6 at 27 evo,
* via a stepdown.
*
* Currently pow is just evo + 15, but the abstraction is kept around in
* case an evocable enhancer returns to the game so that 0 evo with enhancer
* gets some amount of enhancement.
*/
static int _tremorstone_count(int pow)
{
return 1 + stepdown((pow - 15) / 3, 2, ROUND_CLOSE);
}
/**
* Evokes a tremorstone, blasting something in the general area of a
* chosen target.
*
* @return spret::abort if the player cancels, spret::fail if they
* try to evoke but fail, and spret::success otherwise.
*/
static spret _tremorstone()
{
bool see_target;
bolt beam;
static const int RADIUS = 2;
static const int SPREAD = 1;
static const int RANGE = RADIUS + SPREAD;
const int pow = 15 + you.skill(SK_EVOCATIONS);
const int adjust_pow = player_adjust_evoc_power(pow);
const int num_explosions = _tremorstone_count(adjust_pow);
beam.source_id = MID_PLAYER;
beam.thrower = KILL_YOU;
zappy(ZAP_TREMORSTONE, pow, false, beam);
beam.range = RANGE;
beam.ex_size = RADIUS;
beam.target = _find_tremorstone_target(see_target);
targeter_radius hitfunc(&you, LOS_NO_TRANS);
auto vulnerable = [](const actor *act) -> bool
{
return act && _valid_tremorstone_target(*act->as_monster());
};
if ((!see_target
&& !yesno("You can't see anything, release a tremorstone anyway?",
true, 'n'))
|| stop_attack_prompt(hitfunc, "release a tremorstone", vulnerable))
{
return spret::abort;
}
mpr("The tremorstone explodes into fragments!");
const coord_def center = beam.target;
for (int i = 0; i < num_explosions; i++)
{
bolt explosion = beam;
explosion.target = _fuzz_tremorstone_target(center);
explosion.explode(i == num_explosions - 1);
}
return spret::success;
}
static const vector<random_pick_entry<cloud_type>> condenser_clouds =
{
{ 0, 50, 200, FALL, CLOUD_MEPHITIC },
{ 0, 100, 125, PEAK, CLOUD_FIRE },
{ 0, 100, 125, PEAK, CLOUD_COLD },
{ 0, 100, 125, PEAK, CLOUD_POISON },
{ 0, 110, 50, RISE, CLOUD_NEGATIVE_ENERGY },
{ 0, 110, 50, RISE, CLOUD_STORM },
{ 0, 110, 50, RISE, CLOUD_ACID },
};
static spret _condenser()
{
if (env.level_state & LSTATE_STILL_WINDS)
{
mpr("The air is too still to form clouds.");
return spret::abort;
}
const int pow = 15 + you.skill(SK_EVOCATIONS, 7) / 2;
const int adjust_pow = min(110,player_adjust_evoc_power(pow));
random_picker<cloud_type, NUM_CLOUD_TYPES> cloud_picker;
cloud_type cloud = cloud_picker.pick(condenser_clouds, adjust_pow, CLOUD_NONE);
vector<coord_def> target_cells;
bool see_targets = false;
for (radius_iterator di(you.pos(), LOS_NO_TRANS); di; ++di)
{
monster *mons = monster_at(*di);
if (!mons || mons->wont_attack() || !mons_is_threatening(*mons))
continue;
if (you.can_see(*mons))
see_targets = true;
for (adjacent_iterator ai(mons->pos(), false); ai; ++ai)
{
actor * act = actor_at(*ai);
if (!cell_is_solid(*ai) && you.see_cell(*ai) && !cloud_at(*ai)
&& !(act && act->wont_attack()))
{
target_cells.push_back(*ai);
}
}
}
if (!see_targets
&& !yesno("You can't see anything. Try to condense clouds anyway?",
true, 'n'))
{
canned_msg(MSG_OK);
return spret::abort;
}
if (target_cells.empty())
{
canned_msg(MSG_NOTHING_HAPPENS);
return spret::fail;
}
for (auto p : target_cells)
{
const int cloud_power = 5
+ random2avg(12 + div_rand_round(adjust_pow * 3, 4), 3);
place_cloud(cloud, p, cloud_power, &you);
}
mprf("Clouds of %s condense around you!", cloud_type_name(cloud).c_str());
return spret::success;
}
static bool _xoms_chessboard()
{
vector<monster *> targets;
bool see_target = false;
for (monster_near_iterator mi(&you, LOS_NO_TRANS); mi; ++mi)
{
if (mi->friendly() || mi->neutral())
continue;
if (mons_is_firewood(**mi))
continue;
if (you.can_see(**mi))
see_target = true;
targets.emplace_back(*mi);
}
if (!see_target
&& !yesno("You can't see anything. Try to make a move anyway?",
true, 'n'))
{
canned_msg(MSG_OK);
return false;
}
const int power =
player_adjust_evoc_power(15 + you.skill(SK_EVOCATIONS, 7) / 2);
mpr("You make a move on Xom's chessboard...");
if (targets.empty())
{
canned_msg(MSG_NOTHING_HAPPENS);
return true;
}
bolt beam;
const monster * target = *random_iterator(targets);
beam.source = target->pos();
beam.target = target->pos();
beam.set_agent(&you);
// List of possible effects. Mostly debuffs, a few buffs to keep it
// exciting
zap_type zap = random_choose_weighted(5, ZAP_HASTE,
5, ZAP_INVISIBILITY,
5, ZAP_MIGHT,
10, ZAP_CORONA,
15, ZAP_SLOW,
15, ZAP_MALMUTATE,
15, ZAP_PETRIFY,
10, ZAP_PARALYSE,
10, ZAP_CONFUSE,
10, ZAP_SLEEP);
beam.origin_spell = SPELL_NO_SPELL; // let zapping reset this
return zapping(zap, power, beam, false) == spret::success;
}
// Is there anything that would prevent a player from evoking?
// If slot == -1, it asks this question in general.
// If slot is a particular item, it asks this question for that item. This
// wierdly does not check whether an item is actually evokable! (TODO)
bool evoke_check(int slot, bool quiet)
{
item_def *i = nullptr;
if (slot >= 0 && slot < ENDOFPACK && you.inv[slot].defined())
i = &you.inv[slot];
if (i && item_type_removed(i->base_type, i->sub_type))
{
if (!quiet)
mpr("Sorry, this item was removed!");
return false;
}