/
spl-transloc.cc
1911 lines (1639 loc) · 56 KB
/
spl-transloc.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 Translocation spells.
**/
#include "AppHdr.h"
#include "spl-transloc.h"
#include <algorithm>
#include <cmath>
#include <vector>
#include "abyss.h"
#include "act-iter.h"
#include "areas.h"
#include "art-enum.h"
#include "artefact.h"
#include "cloud.h"
#include "coordit.h"
#include "delay.h"
#include "directn.h"
#include "dungeon.h"
#include "english.h"
#include "god-abil.h" // fedhas_passthrough for armataur charge
#include "item-prop.h"
#include "items.h"
#include "level-state-type.h"
#include "libutil.h"
#include "los.h"
#include "losglobal.h"
#include "losparam.h"
#include "melee-attack.h" // armataur charge
#include "message.h"
#include "mon-behv.h"
#include "mon-death.h"
#include "mon-tentacle.h"
#include "mon-util.h"
#include "movement.h" // armataur charge
#include "nearby-danger.h"
#include "orb.h"
#include "output.h"
#include "prompt.h"
#include "religion.h"
#include "shout.h"
#include "spl-damage.h" // cancel_polar_vortex
#include "spl-monench.h"
#include "spl-util.h"
#include "stash.h"
#include "state.h"
#include "stringutil.h"
#include "target.h"
#include "teleport.h"
#include "terrain.h"
#include "tiledoll.h"
#ifdef USE_TILE
#include "tilepick.h"
#endif
#include "traps.h"
#include "view.h"
#include "viewmap.h"
#include "xom.h"
/**
* Place a cloud of translocational energy at a player's previous location,
* to make it easier for players to tell what just happened.
*
* @param origin The player's previous location.
*/
static void _place_tloc_cloud(const coord_def &origin)
{
if (!cell_is_solid(origin))
place_cloud(CLOUD_TLOC_ENERGY, origin, 1 + random2(3), &you);
}
spret cast_disjunction(int pow, bool fail)
{
fail_check();
int rand = random_range(35, 45) + random2(div_rand_round(pow, 12));
you.duration[DUR_DISJUNCTION] = min(90 + div_rand_round(pow, 12),
max(you.duration[DUR_DISJUNCTION] + rand,
30 + rand));
disjunction_spell();
return spret::success;
}
void disjunction_spell()
{
int steps = you.time_taken;
invalidate_agrid(true);
for (int step = 0; step < steps; ++step)
{
vector<monster*> mvec;
for (radius_iterator ri(you.pos(), LOS_RADIUS, C_SQUARE); ri; ++ri)
{
monster* mons = monster_at(*ri);
if (!mons || !you.see_cell(*ri))
continue;
mvec.push_back(mons);
}
if (mvec.empty())
return;
// blink should be isotropic
shuffle_array(mvec);
for (auto mons : mvec)
{
if (!mons->alive() || mons->no_tele())
continue;
coord_def p = mons->pos();
if (!disjunction_haloed(p))
continue;
int dist = grid_distance(you.pos(), p);
int decay = max(1, (dist - 1) * (dist + 1));
int chance = pow(0.8, 1.0 / decay) * 1000;
if (!x_chance_in_y(chance, 1000))
blink_away(mons, &you, false);
}
}
}
/**
* Attempt to blink the player to a random nearby tile.
*
* @param override_stasis Whether to blink even if the player is under
* stasis (& thus normally unable to).
*/
void uncontrolled_blink(bool override_stasis)
{
if (you.no_tele(true) && !override_stasis)
{
canned_msg(MSG_STRANGE_STASIS);
return;
}
coord_def target;
// First try to find a random square not adjacent to the player,
// then one adjacent if that fails.
if (!random_near_space(&you, you.pos(), target)
&& !random_near_space(&you, you.pos(), target, true))
{
mpr("You feel jittery for a moment.");
return;
}
if (!you.attempt_escape(2)) // prints its own messages
return;
canned_msg(MSG_YOU_BLINK);
const coord_def origin = you.pos();
move_player_to_grid(target, false);
_place_tloc_cloud(origin);
}
/**
* Let the player choose a destination for their controlled blink or similar
* effect.
*
* @param target[out] The target found, if any.
* @param safe_cancel Whether it's OK to let the player cancel the control
* of the blink (or whether there should be a prompt -
* for e.g. read-identified ?blink)
* @param verb What kind of movement is this, exactly?
* (E.g. 'blink', 'hop'.)
* @param hitfunc A hitfunc passed to the direction_chooser.
* @return True if a target was found; false if the player aborted.
*/
static bool _find_cblink_target(dist &target, bool safe_cancel,
string verb, targeter *hitfunc = nullptr, bool physical = false)
{
while (true)
{
// query for location {dlb}:
direction_chooser_args args;
args.restricts = DIR_TARGET;
args.needs_path = false;
args.top_prompt = uppercase_first(verb) + " to where?";
args.hitfunc = hitfunc;
direction(target, args);
if (crawl_state.seen_hups)
{
mprf("Cancelling %s due to HUP.", verb.c_str());
return false;
}
if (!target.isValid || target.target == you.pos())
{
const string prompt =
"Are you sure you want to cancel this " + verb + "?";
if (!safe_cancel && !yesno(prompt.c_str(), false, 'n'))
{
clear_messages();
continue;
}
canned_msg(MSG_OK);
return false;
}
const monster* beholder = you.get_beholder(target.target);
if (beholder)
{
mprf("You cannot %s away from %s!",
verb.c_str(),
beholder->name(DESC_THE, true).c_str());
continue;
}
const monster* fearmonger = you.get_fearmonger(target.target);
if (fearmonger)
{
mprf("You cannot %s closer to %s!",
verb.c_str(),
fearmonger->name(DESC_THE, true).c_str());
continue;
}
if (cell_is_solid(target.target))
{
clear_messages();
mprf("You can't %s into that!", verb.c_str());
continue;
}
monster* target_mons = monster_at(target.target);
if (target_mons && you.can_see(*target_mons))
{
mprf("You can't %s onto %s!", verb.c_str(),
target_mons->name(DESC_THE).c_str());
continue;
}
if (!check_moveto(target.target, verb, false))
{
continue;
// try again (messages handled by check_moveto)
}
if (!you.see_cell_no_trans(target.target))
{
clear_messages();
if (you.trans_wall_blocking(target.target))
canned_msg(MSG_SOMETHING_IN_WAY);
else
canned_msg(MSG_CANNOT_SEE);
continue;
}
if (cancel_harmful_move(physical))
{
clear_messages();
continue;
}
return true;
}
}
void wizard_blink()
{
// query for location {dlb}:
direction_chooser_args args;
args.restricts = DIR_TARGET;
args.needs_path = false;
targeter_smite tgt(&you, LOS_RADIUS);
tgt.obeys_mesmerise = false;
args.hitfunc = &tgt;
args.top_prompt = "Blink to where?";
dist beam;
direction(beam, args);
if (!beam.isValid || beam.target == you.pos())
{
canned_msg(MSG_OK);
return;
}
if (!in_bounds(beam.target))
{
clear_messages();
mpr("Please don't blink into the map border.");
return wizard_blink();
}
if (monster_at(beam.target))
{
clear_messages();
mpr("Please don't try to blink into monsters.");
return wizard_blink();
}
if (!check_moveto(beam.target, "blink", false))
{
return wizard_blink();
// try again (messages handled by check_moveto)
}
// Allow wizard blink to send player into walls, in case the
// user wants to alter that grid to something else.
if (cell_is_solid(beam.target))
env.grid(beam.target) = DNGN_FLOOR;
move_player_to_grid(beam.target, false);
}
static const int HOP_FUZZ_RADIUS = 2;
class targeter_hop : public targeter_smite
{
public:
targeter_hop(actor *a, int hop_range)
: targeter_smite(a, hop_range, 0, HOP_FUZZ_RADIUS, false)
{
ASSERT(agent);
obeys_mesmerise = true;
}
aff_type is_affected(coord_def p) override
{
if (!valid_aim(aim))
return AFF_NO;
if (is_feat_dangerous(env.grid(p), true))
return AFF_NO; // XX is this handled by the valid blink check?
const actor* p_act = actor_at(p);
if (p_act && agent && !agent->can_see(*p_act))
return AFF_NO;
// terrain details are cached in exp_map_max by set_aim
return targeter_smite::is_affected(p);
}
bool set_aim(coord_def a) override
{
if (!targeter::set_aim(a))
return false;
// targeter_smite works by filling the explosion map. Here we fill just
// the max explosion map leading to AFF_MAYBE for possible hop targets.
exp_map_min.init(INT_MAX);
exp_map_max.init(INT_MAX);
// somewhat magical value for centre that I have copied from elsewhere
const coord_def centre(9,9);
for (radius_iterator ri(a, exp_range_max, C_SQUARE, LOS_NO_TRANS);
ri; ++ri)
{
if (valid_blink_destination(agent, *ri))
exp_map_max(*ri - a + centre) = 1;
}
return true;
}
};
/**
* Randomly choose one of the spaces near the given target for the player's hop
* to land on.
*
* @param target The tile the player wants to land on.
* @return A nearby, unoccupied, inhabitable tile.
*/
static coord_def _fuzz_hop_destination(coord_def target)
{
coord_def chosen;
int seen = 0;
targeter_hop tgt(&you, frog_hop_range());
tgt.set_aim(target); // XX could reuse tgt from the calling function?
for (auto ti = tgt.affected_iterator(AFF_MAYBE); ti; ++ti)
if (one_chance_in(++seen))
chosen = *ti;
return chosen;
}
int frog_hop_range()
{
return 2 + you.get_mutation_level(MUT_HOP) * 2; // 4-6
}
/**
* Attempt to hop the player to a space near a tile of their choosing.
*
* @param fail Whether this came from a mis-invoked ability (& should
* therefore fail after selecting a target)
* @return Whether the hop succeeded, aborted, or was miscast.
*/
spret frog_hop(bool fail, dist *target)
{
dist empty;
if (!target)
target = ∅ // XX just convert some of these fn signatures to take dist &
const int hop_range = frog_hop_range();
targeter_hop tgt(&you, hop_range);
while (true)
{
if (!_find_cblink_target(*target, true, "hop", &tgt, true))
return spret::abort;
if (grid_distance(you.pos(), target->target) > hop_range)
{
mpr("That's out of range!"); // ! targeting
continue;
}
break;
}
target->target = _fuzz_hop_destination(target->target);
fail_check();
if (!you.attempt_escape(2)) // XXX: 1?
return spret::success; // of a sort
// invisible monster that the targeter didn't know to avoid, or similar
if (target->target.origin())
{
mpr("You tried to hop, but there was no room to land!");
// TODO: what to do here?
return spret::success; // of a sort
}
if (!cell_is_solid(you.pos())) // should be safe.....
place_cloud(CLOUD_DUST, you.pos(), 2 + random2(3), &you);
move_player_to_grid(target->target, false);
crawl_state.cancel_cmd_again();
crawl_state.cancel_cmd_repeat();
mpr("Boing!");
you.increase_duration(DUR_NO_HOP, 12 + random2(13));
player_did_deliberate_movement();
return spret::success; // TODO
}
static vector<string> _desc_electric_charge_hit_chance(const monster_info& mi)
{
melee_attack attk(&you, nullptr);
attk.charge_pow = 1; // to give the accuracy bonus
const int acc_pct = to_hit_pct(mi, attk, true);
return vector<string>{make_stringf("%d%% to hit", acc_pct)};
}
bool find_charge_target(vector<coord_def> &target_path, int max_range,
targeter *hitfunc, dist &target)
{
// Check for unholy weapons, breadswinging, etc
if (!wielded_weapon_check(you.weapon(), "charge"))
return false;
// TODO: move into generic spell targeting somehow?
// TODO: can't this all be done within a single direction call?
while (true)
{
// query for location {dlb}:
direction_chooser_args args;
args.restricts = DIR_TARGET;
args.mode = TARG_HOSTILE;
args.prefer_farthest = true;
args.top_prompt = "Charge where?";
args.hitfunc = hitfunc;
args.get_desc_func = bind(_desc_electric_charge_hit_chance, placeholders::_1);
direction(target, args);
// TODO: deduplicate with _find_cblink_target
if (crawl_state.seen_hups)
{
mpr("Cancelling electric charge due to HUP.");
return false;
}
if (!target.isValid || target.target == you.pos())
{
canned_msg(MSG_OK);
return false;
}
const monster* beholder = you.get_beholder(target.target);
if (beholder)
{
mprf("You cannot charge away from %s!",
beholder->name(DESC_THE, true).c_str());
if (target.interactive)
continue;
else
return false;
}
const monster* fearmonger = you.get_fearmonger(target.target);
if (fearmonger)
{
mprf("You cannot charge closer to %s!",
fearmonger->name(DESC_THE, true).c_str());
if (target.interactive)
continue;
else
return false;
}
if (!you.see_cell_no_trans(target.target))
{
clear_messages();
if (you.trans_wall_blocking(target.target))
canned_msg(MSG_SOMETHING_IN_WAY);
else
canned_msg(MSG_CANNOT_SEE);
if (target.interactive)
continue;
else
return false;
}
if (grid_distance(you.pos(), target.target) > max_range)
{
mpr("That's out of range!"); // ! targeting
if (target.interactive)
continue;
else
return false;
}
ray_def ray;
if (!find_ray(you.pos(), target.target, ray, opc_solid))
{
mpr("You can't charge through that!");
if (target.interactive)
continue;
else
return false;
}
// done with hard vetos; now we're on a mix of prompts and vetos.
// (Ideally we'd like to split these up and do all the vetos before
// the prompts, but...)
target_path.clear();
while (ray.advance())
{
target_path.push_back(ray.pos());
if (ray.pos() == target.target)
break;
}
// DON'T use beam.target here - we might have used ! targeting to
// target something behind another known monster
const monster* target_mons = monster_at(ray.pos());
const string bad_charge = bad_charge_target(ray.pos());
if (bad_charge != "")
{
mpr(bad_charge.c_str());
return false;
}
if (adjacent(you.pos(), ray.pos()))
{
mprf("You're already next to %s!",
target_mons->name(DESC_THE).c_str());
return false;
}
// adjacency check should ensure this...
ASSERT(target_path.size() >= 2);
const coord_def dest_pos = target_path.at(target_path.size() - 2);
monster* dest_mon = monster_at(dest_pos);
const bool invalid_dest = dest_mon && mons_class_is_stationary(dest_mon->type);
if (invalid_dest && you.can_see(*dest_mon))
{
mprf("%s is immovably fixed there.", dest_mon->name(DESC_THE).c_str());
return false;
}
// prompt to make sure the player really wants to attack the monster
// (if extant and not hostile)
// Intentionally don't use the real attack position here - that's only
// used for sanctuary,
// so it's more accurate if we use our current pos, since sanctuary
// should move with us.
if (stop_attack_prompt(target_mons, false, target_mons->pos()))
return false;
ray.regress();
// confirm movement for the final square only
if (!check_moveto(ray.pos(), "charge"))
return false;
return true;
}
}
static void _charge_cloud_trail(const coord_def pos)
{
if (!cell_is_solid(pos) && !apply_cloud_trail(pos))
place_cloud(CLOUD_ELECTRICITY, pos, 2 + random2(3), &you);
}
string electric_charge_impossible_reason(bool allow_safe_monsters)
{
// General movement checks are handled elsewhere.
targeter_charge tgt(&you, spell_range(SPELL_ELECTRIC_CHARGE, 0));
int nearby_mons = 0;
string example_reason = "";
for (monster_near_iterator mi(&you); mi; ++mi)
{
++nearby_mons;
if (!tgt.valid_aim(mi->pos()))
{
example_reason = make_stringf("you can't charge at %s because %s",
mi->name(DESC_THE).c_str(),
tgt.why_not.c_str());
}
else if (allow_safe_monsters
|| !mons_is_safe(*mi, false)
|| mons_class_is_test(mi->type))
{
return "";
}
}
if (!nearby_mons)
return "you can't see anything to charge at.";
if (nearby_mons == 1)
return lowercase_string(example_reason);
return "there's one issue or another keeping you from charging at any nearby foe.";
}
string movement_impossible_reason()
{
if (you.attribute[ATTR_HELD])
return make_stringf("You cannot do that while %s.", held_status());
if (!you.is_motile())
return "You cannot move."; // MSG_CANNOT_MOVE
return "";
}
static void _displace_charge_blocker(monster &mon)
{
const coord_def orig = mon.pos();
coord_def targ;
if (random_near_space(&mon, mon.pos(), targ, true)
&& mon.blink_to(targ, true, false)) // XXX: should ignore constrict
{
return;
}
monster_teleport(&mon, true);
if (mon.pos() != orig)
return;
mon.banish(&you, "electric charge", -1, true);
if (!mon.alive())
return;
monster_die(mon, KILL_BANISHED, NON_MONSTER);
}
/**
* Attempt to charge the player to a target of their choosing.
*
* @param fail Whether this came from a miscast spell (& should
* therefore fail after selecting a target)
* @return Whether the charge succeeded, aborted, or was miscast.
*/
spret electric_charge(int powc, bool fail, const coord_def &target)
{
const coord_def initial_pos = you.pos();
vector<coord_def> target_path;
const int range = spell_range(SPELL_ELECTRIC_CHARGE, powc);
targeter_charge tgt(&you, range);
dist targ;
ASSERT(in_bounds(target));
targ.target = target;
targ.interactive = false; // target should already be provided
// re-run target finding non-interactively in order to get the full path
// again (ugh)
if (!find_charge_target(target_path, range, &tgt, targ))
return spret::abort;
const coord_def dest_pos = target_path.at(target_path.size() - 2);
monster* dest_mon = monster_at(dest_pos);
fail_check();
// at this point it should be an invisible monster; visible monsters get
// filtered at the targeting stage
const bool invalid_dest = dest_mon && mons_class_is_stationary(dest_mon->type);
if (invalid_dest)
{
mprf("%s is immovably fixed there.", dest_mon->name(DESC_THE).c_str());
return spret::success;
}
if (!you.attempt_escape(1)) // prints its own messages
return spret::success;
const coord_def target_pos = target_path.back();
monster* target_mons = monster_at(target_pos);
if (fedhas_passthrough(target_mons))
target_mons = nullptr;
ASSERT(target_mons != nullptr);
crawl_state.cancel_cmd_again();
crawl_state.cancel_cmd_repeat();
const coord_def orig_pos = you.pos();
if (silenced(dest_pos))
mpr("You charge forward in eerie silence!");
else
mpr("You charge forward with an electric crackle!");
if (dest_mon)
_displace_charge_blocker(*dest_mon);
move_player_to_grid(dest_pos, true);
noisy(4, you.pos());
player_did_deliberate_movement();
you.clear_far_engulf(false, true);
_charge_cloud_trail(orig_pos);
for (auto it = target_path.begin(); it != target_path.end() - 2; ++it)
_charge_cloud_trail(*it);
if (you.pos() != dest_pos) // polar vortex and trap nonsense
return spret::success; // of a sort
// Maybe we hit a trap and something weird happened.
if (!target_mons->alive() || !adjacent(you.pos(), target_mons->pos()))
return spret::success;
// manually apply noise
// this silence check feels kludgy - perhaps could check along the whole route..?
if (!silenced(target_pos))
behaviour_event(target_mons, ME_ALERT, &you, you.pos()); // shout + set you as foe
// We got webbed/netted at the destination, bail on the attack.
if (you.attribute[ATTR_HELD])
return spret::success;
const int base_delay =
div_rand_round(you.time_taken * player_movement_speed(), 10);
melee_attack charge_atk(&you, target_mons);
charge_atk.charge_pow = powc + 50 * grid_distance(initial_pos, you.pos());
charge_atk.attack();
// Normally this is 10 aut (times haste, chei etc), but slow weapons
// take longer. Most relevant for low-skill players and Dark Maul.
you.time_taken = max(you.time_taken, base_delay);
return spret::success;
}
/**
* Attempt to blink the player to a nearby tile of their choosing. Doesn't
* handle you.no_tele().
*
* @param safe_cancel Whether it's OK to let the player cancel the control
* of the blink (or whether there should be a prompt -
* for e.g. read-identified ?blink)
* @return Whether the blink succeeded, aborted, or was miscast.
*/
spret controlled_blink(bool safe_cancel, dist *target)
{
if (crawl_state.is_replaying_keys())
{
crawl_state.cancel_cmd_all("You can't repeat controlled blinks.");
return spret::abort;
}
dist empty;
if (!target)
target = ∅
targeter_smite tgt(&you, LOS_RADIUS);
tgt.obeys_mesmerise = true;
if (!_find_cblink_target(*target, safe_cancel, "blink", &tgt))
return spret::abort;
if (!you.attempt_escape(2))
return spret::success; // of a sort
// invisible monster that the targeter didn't know to avoid
if (monster_at(target->target))
{
mpr("Oops! There was something there already!");
uncontrolled_blink();
return spret::success; // of a sort
}
_place_tloc_cloud(you.pos());
move_player_to_grid(target->target, false);
crawl_state.cancel_cmd_again();
crawl_state.cancel_cmd_repeat();
return spret::success;
}
/**
* Cast the player spell Blink.
*
* @param fail Whether the player miscast the spell.
* @return Whether the spell was successfully cast, aborted,
* or miscast.
*/
spret cast_blink(int pow, bool fail)
{
// effects that cast the spell through the player, I guess (e.g. xom)
if (you.no_tele(true))
return fail ? spret::fail : spret::success; // probably always SUCCESS
if (cancel_harmful_move(false))
return spret::abort;
fail_check();
uncontrolled_blink();
you.increase_duration(DUR_BLINK_COOLDOWN,
2 + random2(3) + div_rand_round(50 - pow, 10));
return spret::success;
}
void you_teleport()
{
// [Cha] here we block teleportation, which will save the player from
// death from read-id'ing scrolls (in sprint)
if (you.no_tele())
canned_msg(MSG_STRANGE_STASIS);
else if (you.duration[DUR_TELEPORT])
{
mpr("You feel strangely stable.");
you.duration[DUR_TELEPORT] = 0;
}
else
{
mpr("You feel strangely unstable.");
int teleport_delay = 3 + random2(3);
if (player_in_branch(BRANCH_ABYSS))
{
mpr("You feel the power of the Abyss delaying your translocation!");
teleport_delay += 5 + random2(10);
}
else if (orb_limits_translocation())
{
mprf(MSGCH_ORB, "You feel the Orb delaying your translocation!");
teleport_delay += 5 + random2(5);
}
you.set_duration(DUR_TELEPORT, teleport_delay);
}
}
// Should return true if we don't want anyone to teleport here.
bool cell_vetoes_teleport(const coord_def cell, bool check_monsters,
bool wizard_tele)
{
// Monsters always veto teleport.
if (monster_at(cell) && check_monsters)
return true;
// As do all clouds; this may change.
if (cloud_at(cell) && !wizard_tele)
return true;
if (cell_is_solid(cell))
return true;
return is_feat_dangerous(env.grid(cell), true) && !wizard_tele;
}
static void _handle_teleport_update(bool large_change, const coord_def old_pos)
{
if (large_change)
{
viewwindow();
update_screen();
for (monster_iterator mi; mi; ++mi)
{
const bool see_cell = you.see_cell(mi->pos());
if (mi->foe == MHITYOU && !see_cell && !you.penance[GOD_ASHENZARI])
{
mi->foe_memory = 0;
behaviour_event(*mi, ME_EVAL);
}
else if (see_cell)
behaviour_event(*mi, ME_EVAL);
}
}
#ifdef USE_TILE
if (you.has_innate_mutation(MUT_MERTAIL))
{
const dungeon_feature_type new_grid = env.grid(you.pos());
const dungeon_feature_type old_grid = env.grid(old_pos);
if (feat_is_water(old_grid) && !feat_is_water(new_grid)
|| !feat_is_water(old_grid) && feat_is_water(new_grid))
{
init_player_doll();
}
}
#else
UNUSED(old_pos);
#endif
you.clear_far_engulf();
}
static bool _teleport_player(bool wizard_tele, bool teleportitis,
string reason="")
{
if (!wizard_tele && !teleportitis
&& (crawl_state.game_is_sprint() || you.no_tele())
&& !player_in_branch(BRANCH_ABYSS))
{
if (!reason.empty())
mpr(reason);
canned_msg(MSG_STRANGE_STASIS);
return false;
}
// After this point, we're guaranteed to teleport. Kill the appropriate
// delays. Teleportitis needs to check the target square first, though.
if (!teleportitis)
interrupt_activity(activity_interrupt::teleport);
// Update what we can see at the current location as well as its stash,
// in case something happened in the exact turn that we teleported
// (like picking up/dropping an item).
viewwindow();
update_screen();
StashTrack.update_stash(you.pos());
if (player_in_branch(BRANCH_ABYSS) && !wizard_tele)
{
if (!reason.empty())
mpr(reason);
abyss_teleport();
if (you.pet_target != MHITYOU)
you.pet_target = MHITNOT;
return true;
}
coord_def pos(1, 0);
const coord_def old_pos = you.pos();
bool large_change = false;
if (wizard_tele)
{
while (true)
{
level_pos lpos;
bool chose = show_map(lpos, false, false);
pos = lpos.pos;
redraw_screen();
update_screen();
// If we've received a HUP signal then the user can't choose a
// location, so cancel the teleport.
if (crawl_state.seen_hups)
{
mprf(MSGCH_ERROR, "Controlled teleport interrupted by HUP signal, "
"cancelling teleport.");
return false;
}
dprf("Target square (%d,%d)", pos.x, pos.y);
if (!chose || pos == you.pos())
return false;
break;
}
if (!you.see_cell(pos))
large_change = true;
if (cell_vetoes_teleport(pos, true, wizard_tele))
{
mprf(MSGCH_WARN, "Even you can't go there right now. Sorry!");
return false;
}
else
move_player_to_grid(pos, false);
}
else
{
coord_def newpos;
int tries = 500;
do
{
newpos = random_in_bounds();
}
while (--tries > 0
&& (cell_vetoes_teleport(newpos)
|| testbits(env.pgrid(newpos), FPROP_NO_TELE_INTO)));