forked from crawl/crawl
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbeam.cc
6596 lines (5652 loc) · 189 KB
/
beam.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 related to ranged attacks.
**/
#include "AppHdr.h"
#include "beam.h"
#include <algorithm>
#include <cmath>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <set>
#include "act-iter.h"
#include "areas.h"
#include "attitude-change.h"
#include "bloodspatter.h"
#include "branch.h"
#include "cloud.h"
#include "colour.h"
#include "coordit.h"
#include "delay.h"
#include "directn.h"
#include "dungeon.h"
#include "english.h"
#include "exercise.h"
#include "fight.h"
#include "godabil.h"
#include "godconduct.h"
#include "item_use.h"
#include "itemprop.h"
#include "items.h"
#include "libutil.h"
#include "losglobal.h"
#include "los.h"
#include "message.h"
#include "misc.h"
#include "mon-behv.h"
#include "mon-death.h"
#include "mon-place.h"
#include "mon-poly.h"
#include "mutation.h"
#include "potion.h"
#include "prompt.h"
#include "ranged_attack.h"
#include "religion.h"
#include "shout.h"
#include "spl-clouds.h"
#include "spl-damage.h"
#include "spl-goditem.h"
#include "spl-monench.h"
#include "spl-other.h"
#include "spl-summoning.h"
#include "spl-transloc.h"
#include "spl-util.h"
#include "spl-zap.h"
#include "state.h"
#include "stepdown.h"
#include "stringutil.h"
#include "target.h"
#include "teleport.h"
#include "terrain.h"
#include "throw.h"
#ifdef USE_TILE
#include "tilepick.h"
#endif
#include "transform.h"
#include "traps.h"
#include "viewchar.h"
#include "view.h"
#include "xom.h"
#define SAP_MAGIC_CHANCE() x_chance_in_y(7, 10)
// Helper functions (some of these should probably be public).
static void _ench_animation(int flavour, const monster* mon = nullptr,
bool force = false);
static beam_type _chaos_beam_flavour(bolt* beam);
static string _beam_type_name(beam_type type);
tracer_info::tracer_info()
{
reset();
}
void tracer_info::reset()
{
count = power = hurt = helped = 0;
dont_stop = false;
}
const tracer_info& tracer_info::operator+=(const tracer_info &other)
{
count += other.count;
power += other.power;
hurt += other.hurt;
helped += other.helped;
dont_stop = dont_stop || other.dont_stop;
return *this;
}
bool bolt::is_blockable() const
{
// BEAM_ELECTRICITY is added here because chain lightning is not
// a true beam (stops at the first target it gets to and redirects
// from there)... but we don't want it shield blockable.
return !pierce && !is_explosion && flavour != BEAM_ELECTRICITY
&& hit != AUTOMATIC_HIT && flavour != BEAM_VISUAL;
}
void bolt::emit_message(const char* m)
{
const string message = m;
if (!message_cache.count(message))
mpr(m);
message_cache.insert(message);
}
kill_category bolt::whose_kill() const
{
if (YOU_KILL(thrower) || source_id == MID_YOU_FAULTLESS)
return KC_YOU;
else if (MON_KILL(thrower))
{
if (source_id == MID_ANON_FRIEND)
return KC_FRIENDLY;
const monster* mon = monster_by_mid(source_id);
if (mon && mon->friendly())
return KC_FRIENDLY;
}
return KC_OTHER;
}
// A simple animated flash from Rupert Smith (expanded to be more
// generic).
static void _zap_animation(int colour, const monster* mon = nullptr,
bool force = false)
{
coord_def p = you.pos();
if (mon)
{
if (!force && !mon->visible_to(&you))
return;
p = mon->pos();
}
if (!you.see_cell(p))
return;
const coord_def drawp = grid2view(p);
if (in_los_bounds_v(drawp))
{
#ifdef USE_TILE
tiles.add_overlay(p, tileidx_zap(colour));
#endif
#ifndef USE_TILE_LOCAL
view_update();
cgotoxy(drawp.x, drawp.y, GOTO_DNGN);
put_colour_ch(colour, dchar_glyph(DCHAR_FIRED_ZAP));
#endif
update_screen();
scaled_delay(50);
}
}
// Special front function for zap_animation to interpret enchantment flavours.
static void _ench_animation(int flavour, const monster* mon, bool force)
{
element_type elem;
switch (flavour)
{
case BEAM_HEALING:
elem = ETC_HEAL;
break;
case BEAM_PAIN:
elem = ETC_UNHOLY;
break;
case BEAM_DISPEL_UNDEAD:
elem = ETC_HOLY;
break;
case BEAM_POLYMORPH:
case BEAM_MALMUTATE:
case BEAM_CORRUPT_BODY:
elem = ETC_MUTAGENIC;
break;
case BEAM_CHAOS:
case BEAM_CHAOTIC_REFLECTION:
elem = ETC_RANDOM;
break;
case BEAM_TELEPORT:
case BEAM_BANISH:
case BEAM_BLINK:
case BEAM_BLINK_CLOSE:
elem = ETC_WARP;
break;
case BEAM_MAGIC:
elem = ETC_MAGIC;
break;
default:
elem = ETC_ENCHANT;
break;
}
_zap_animation(element_colour(elem), mon, force);
}
// If needs_tracer is true, we need to check the beam path for friendly
// monsters.
spret_type zapping(zap_type ztype, int power, bolt &pbolt,
bool needs_tracer, const char* msg, bool fail)
{
dprf(DIAG_BEAM, "zapping: power=%d", power);
pbolt.thrower = KILL_YOU_MISSILE;
// Check whether tracer goes through friendlies.
// NOTE: Whenever zapping() is called with a randomised value for power
// (or effect), player_tracer should be called directly with the highest
// power possible respecting current skill, experience level, etc.
if (needs_tracer && !player_tracer(ztype, power, pbolt))
return SPRET_ABORT;
fail_check();
// Fill in the bolt structure.
zappy(ztype, power, pbolt);
if (msg)
mpr(msg);
if (ztype == ZAP_LIGHTNING_BOLT)
{
noisy(spell_effect_noise(SPELL_LIGHTNING_BOLT),
you.pos(), "You hear a mighty clap of thunder!");
pbolt.heard = true;
}
if (ztype == ZAP_DIG)
pbolt.aimed_at_spot = false;
pbolt.fire();
return SPRET_SUCCESS;
}
// Returns true if the path is considered "safe", and false if there are
// monsters in the way the player doesn't want to hit.
bool player_tracer(zap_type ztype, int power, bolt &pbolt, int range)
{
// Non-controlleable during confusion.
// (We'll shoot in a different direction anyway.)
if (you.confused())
return true;
zappy(ztype, power, pbolt);
pbolt.is_tracer = true;
pbolt.source = you.pos();
pbolt.source_id = MID_PLAYER;
pbolt.attitude = ATT_FRIENDLY;
pbolt.thrower = KILL_YOU_MISSILE;
// Init tracer variables.
pbolt.friend_info.reset();
pbolt.foe_info.reset();
pbolt.foe_ratio = 100;
pbolt.beam_cancelled = false;
pbolt.dont_stop_player = false;
// Clear misc
pbolt.seen = false;
pbolt.heard = false;
pbolt.reflections = 0;
pbolt.bounces = 0;
// Save range before overriding it
const int old_range = pbolt.range;
if (range)
pbolt.range = range;
pbolt.fire();
if (range)
pbolt.range = old_range;
// Should only happen if the player answered 'n' to one of those
// "Fire through friendly?" prompts.
if (pbolt.beam_cancelled)
{
dprf(DIAG_BEAM, "Beam cancelled.");
you.turn_is_over = false;
return false;
}
// Set to non-tracing for actual firing.
pbolt.is_tracer = false;
return true;
}
// Returns true if the player wants / needs to abort based on god displeasure
// with targeting this target with this spell. Returns false otherwise.
static bool _stop_because_god_hates_target_prompt(monster* mon, spell_type spell)
{
// This is just a hasty stub for the one case I'm aware of right now.
if (spell == SPELL_TUKIMAS_DANCE)
{
item_def* wpn = mon->weapon();
brand_type brand = !is_range_weapon(*wpn) ?
static_cast<brand_type>(get_weapon_brand(*wpn))
: SPWPN_NORMAL;
if (god_hates_brand(brand)
&& !yesno("Animating this weapon would put you into penance. "
" Really cast this spell?", false, 'n'))
{
return true;
}
}
return false;
}
template<typename T>
class power_deducer
{
public:
virtual T operator()(int pow) const = 0;
virtual ~power_deducer() {}
};
typedef power_deducer<int> tohit_deducer;
template<int adder, int mult_num = 0, int mult_denom = 1>
class tohit_calculator : public tohit_deducer
{
public:
int operator()(int pow) const override
{
return adder + pow * mult_num / mult_denom;
}
};
typedef power_deducer<dice_def> dam_deducer;
template<int numdice, int adder, int mult_num, int mult_denom>
class dicedef_calculator : public dam_deducer
{
public:
dice_def operator()(int pow) const override
{
return dice_def(numdice, adder + pow * mult_num / mult_denom);
}
};
template<int numdice, int adder, int mult_num, int mult_denom>
class calcdice_calculator : public dam_deducer
{
public:
dice_def operator()(int pow) const override
{
return calc_dice(numdice, adder + pow * mult_num / mult_denom);
}
};
struct zap_info
{
zap_type ztype;
const char* name; // nullptr means handled specially
int power_cap;
dam_deducer* damage;
tohit_deducer* tohit; // Enchantments have power modifier here
colour_t colour;
bool is_enchantment;
beam_type flavour;
dungeon_char_type glyph;
bool always_obvious;
bool can_beam;
bool is_explosion;
int hit_loudness;
};
#include "zap-data.h"
static int zap_index[NUM_ZAPS];
void init_zap_index()
{
for (int i = 0; i < NUM_ZAPS; ++i)
zap_index[i] = -1;
for (unsigned int i = 0; i < ARRAYSZ(zap_data); ++i)
zap_index[zap_data[i].ztype] = i;
}
static const zap_info* _seek_zap(zap_type z_type)
{
ASSERT_RANGE(z_type, 0, NUM_ZAPS);
if (zap_index[z_type] == -1)
return nullptr;
else
return &zap_data[zap_index[z_type]];
}
int zap_power_cap(zap_type z_type)
{
const zap_info* zinfo = _seek_zap(z_type);
return zinfo ? zinfo->power_cap : 0;
}
int zap_ench_power(zap_type z_type, int pow)
{
const zap_info* zinfo = _seek_zap(z_type);
if (!zinfo)
return pow;
if (zinfo->power_cap > 0)
pow = min(zinfo->power_cap, pow);
if (zinfo->is_enchantment && zinfo->tohit)
return (*zinfo->tohit)(pow);
else
return pow;
}
void zappy(zap_type z_type, int power, bolt &pbolt)
{
const zap_info* zinfo = _seek_zap(z_type);
// None found?
if (zinfo == nullptr)
{
dprf("Couldn't find zap type %d", z_type);
return;
}
// Fill
pbolt.name = zinfo->name;
pbolt.flavour = zinfo->flavour;
pbolt.real_flavour = zinfo->flavour;
pbolt.colour = zinfo->colour;
pbolt.glyph = dchar_glyph(zinfo->glyph);
pbolt.obvious_effect = zinfo->always_obvious;
pbolt.pierce = zinfo->can_beam;
pbolt.is_explosion = zinfo->is_explosion;
if (zinfo->power_cap > 0)
power = min(zinfo->power_cap, power);
ASSERT(zinfo->is_enchantment == pbolt.is_enchantment());
pbolt.ench_power = zap_ench_power(z_type, power);
if (zinfo->is_enchantment)
pbolt.hit = AUTOMATIC_HIT;
else
{
pbolt.hit = (*zinfo->tohit)(power);
if (pbolt.hit != AUTOMATIC_HIT)
pbolt.hit = max(0, pbolt.hit - 5 * you.inaccuracy());
}
if (zinfo->damage)
pbolt.damage = (*zinfo->damage)(power);
pbolt.origin_spell = zap_to_spell(z_type);
if (z_type == ZAP_BREATHE_FIRE && you.species == SP_RED_DRACONIAN)
pbolt.origin_spell = SPELL_SEARING_BREATH;
if (pbolt.loudness == 0)
pbolt.loudness = zinfo->hit_loudness;
}
bool bolt::can_affect_actor(const actor *act) const
{
// Blinkbolt doesn't hit its caster, since they are the bolt.
if (origin_spell == SPELL_BLINKBOLT && act->mid == source_id)
return false;
auto cnt = hit_count.find(act->mid);
if (cnt != hit_count.end() && cnt->second >= 2)
{
// Note: this is done for balance, even if it hurts realism a bit.
// It is arcane knowledge which wall patterns will cause lightning
// to bounce thrice, double damage for ordinary bounces is enough.
#ifdef DEBUG_DIAGNOSTICS
if (!quiet_debug)
dprf(DIAG_BEAM, "skipping beam hit, affected them twice already");
#endif
return false;
}
return !act->submerged();
}
static beam_type _chaos_beam_flavour(bolt* beam)
{
beam_type flavour;
do
{
flavour = random_choose_weighted(
10, BEAM_FIRE,
10, BEAM_COLD,
10, BEAM_ELECTRICITY,
10, BEAM_POISON,
10, BEAM_NEG,
10, BEAM_ACID,
10, BEAM_HELLFIRE,
10, BEAM_STICKY_FLAME,
10, BEAM_SLOW,
10, BEAM_HASTE,
10, BEAM_MIGHT,
10, BEAM_BERSERK,
10, BEAM_HEALING,
10, BEAM_PARALYSIS,
10, BEAM_CONFUSION,
10, BEAM_INVISIBILITY,
10, BEAM_POLYMORPH,
10, BEAM_BANISH,
10, BEAM_DISINTEGRATION,
10, BEAM_PETRIFY,
10, BEAM_AGILITY,
2, BEAM_ENSNARE,
0);
}
while (beam->origin_spell == SPELL_CHAIN_OF_CHAOS
&& (flavour == BEAM_BANISH
|| flavour == BEAM_POLYMORPH));
return flavour;
}
static beam_type _chaotic_reflection_flavour(bolt* beam)
{
return random_choose_weighted(
10, BEAM_SLOW,
10, BEAM_HASTE,
10, BEAM_MIGHT,
10, BEAM_BERSERK,
10, BEAM_PARALYSIS,
10, BEAM_CONFUSION,
10, BEAM_DISINTEGRATION,
10, BEAM_PETRIFY,
10, BEAM_AGILITY,
10, BEAM_BLINK,
10, BEAM_SLEEP,
10, BEAM_VULNERABILITY,
10, BEAM_RESISTANCE,
2, BEAM_ENSNARE,
0);
}
bool bolt::visible() const
{
return !is_tracer && glyph != 0 && !is_enchantment();
}
void bolt::initialise_fire()
{
// Fix some things which the tracer might have set.
extra_range_used = 0;
in_explosion_phase = false;
use_target_as_pos = false;
hit_count.clear();
if (special_explosion != nullptr)
{
ASSERT(!is_explosion);
ASSERT(special_explosion->is_explosion);
ASSERT(special_explosion->special_explosion == nullptr);
special_explosion->in_explosion_phase = false;
special_explosion->use_target_as_pos = false;
}
if (chose_ray)
{
ASSERT_IN_BOUNDS(ray.pos());
if (source == coord_def())
source = ray.pos();
}
if (target == source)
{
range = 0;
aimed_at_feet = true;
auto_hit = true;
aimed_at_spot = true;
use_target_as_pos = true;
}
ASSERT_IN_BOUNDS(source);
ASSERT_RANGE(flavour, BEAM_NONE + 1, BEAM_FIRST_PSEUDO);
ASSERT(!drop_item || item && item->defined());
ASSERTM(range >= 0, "beam '%s', source '%s', item '%s'; has range -1",
name.c_str(),
(source_id == MID_PLAYER ? "player" :
monster_by_mid(source_id) ?
monster_by_mid(source_id)->name(DESC_PLAIN, true) :
"unknown").c_str(),
(item ? item->name(DESC_PLAIN, false, true) : "none").c_str());
ASSERT(!aimed_at_feet || source == target);
real_flavour = flavour;
message_cache.clear();
// seen might be set by caller to suppress this.
if (!seen && you.see_cell(source) && range > 0 && visible())
{
seen = true;
const monster* mon = monster_at(source);
if (flavour != BEAM_VISUAL
&& !YOU_KILL(thrower)
&& !crawl_state.is_god_acting()
&& (!mon || !mon->observable()))
{
mprf("%s appears from out of thin air!",
article_a(name, false).c_str());
}
}
// Visible self-targeted beams are always seen, even though they don't
// leave a path.
if (you.see_cell(source) && target == source && visible())
seen = true;
// The agent may die during the beam's firing, need to save these now.
// If the beam was reflected, assume it can "see" anything, since neither
// the reflector nor the original source was particularly aiming for this
// target. WARNING: if you change this logic, keep in mind that
// menv[YOU_FAULTLESS] cannot be safely queried for properties like
// can_see_invisible.
if (reflections > 0)
nightvision = can_see_invis = true;
else
{
// XXX: Should non-agents count as seeing invisible?
nightvision = agent() && agent()->nightvision();
can_see_invis = agent() && agent()->can_see_invisible();
}
#ifdef DEBUG_DIAGNOSTICS
// Not a "real" tracer, merely a range/reachability check.
if (quiet_debug)
return;
dprf(DIAG_BEAM, "%s%s%s [%s] (%d,%d) to (%d,%d): "
"gl=%d col=%d flav=%d hit=%d dam=%dd%d range=%d",
(pierce) ? "beam" : "missile",
(is_explosion) ? "*" :
(is_big_cloud()) ? "+" : "",
(is_tracer) ? " tracer" : "",
name.c_str(),
source.x, source.y,
target.x, target.y,
glyph, colour, flavour,
hit, damage.num, damage.size,
range);
#endif
}
// Catch the bolt part of explosive bolt.
static bool _is_explosive_bolt(const bolt *beam)
{
return beam->origin_spell == SPELL_EXPLOSIVE_BOLT
&& !beam->in_explosion_phase;
}
void bolt::apply_beam_conducts()
{
if (!is_tracer && YOU_KILL(thrower))
{
switch (flavour)
{
case BEAM_HELLFIRE:
did_god_conduct(DID_UNHOLY, 2 + random2(3), god_cares());
did_god_conduct(DID_FIRE, 10 + random2(5), god_cares());
break;
case BEAM_FIRE:
case BEAM_HOLY_FLAME:
case BEAM_STICKY_FLAME:
did_god_conduct(DID_FIRE,
pierce || is_explosion ? 6 + random2(3)
: 2 + random2(3),
god_cares());
break;
default:
// Fire comes from a side-effect of the beam, not the beam itself.
if (_is_explosive_bolt(this))
did_god_conduct(DID_FIRE, 6 + random2(3), god_cares());
break;
}
}
}
void bolt::choose_ray()
{
if ((!chose_ray || reflections > 0)
&& !find_ray(source, target, ray, opc_solid_see)
// If fire is blocked, at least try a visible path so the
// error message is better.
&& !find_ray(source, target, ray, opc_default))
{
fallback_ray(source, target, ray);
}
}
// Draw the bolt at p if needed.
void bolt::draw(const coord_def& p)
{
if (is_tracer || is_enchantment() || !you.see_cell(p))
return;
// We don't clean up the old position.
// First, most people like to see the full path,
// and second, it is hard to do it right with
// respect to killed monsters, cloud trails, etc.
const coord_def drawpos = grid2view(p);
if (!in_los_bounds_v(drawpos))
return;
#ifdef USE_TILE
if (tile_beam == -1)
tile_beam = tileidx_bolt(*this);
if (tile_beam != -1)
{
int dist = (p - source).rdist();
tiles.add_overlay(p, vary_bolt_tile(tile_beam, dist));
}
#endif
#ifndef USE_TILE_LOCAL
cgotoxy(drawpos.x, drawpos.y, GOTO_DNGN);
put_colour_ch(colour == BLACK ? random_colour(true)
: element_colour(colour),
glyph);
// Get curses to update the screen so we can see the beam.
update_screen();
#endif
scaled_delay(draw_delay);
}
// Bounce a bolt off a solid feature.
// The ray is assumed to have just been advanced into
// the feature.
void bolt::bounce()
{
// Don't bounce player tracers off unknown cells, or cells that we
// incorrectly thought were non-bouncy.
if (is_tracer && agent() == &you)
{
const dungeon_feature_type feat = env.map_knowledge(ray.pos()).feat();
if (feat == DNGN_UNSEEN || !feat_is_solid(feat) || !is_bouncy(feat))
{
ray.regress();
finish_beam();
return;
}
}
do
{
ray.regress();
}
while (cell_is_solid(ray.pos()));
extra_range_used += range_used(true);
bounce_pos = ray.pos();
bounces++;
reflect_grid rg;
for (adjacent_iterator ai(ray.pos(), false); ai; ++ai)
rg(*ai - ray.pos()) = cell_is_solid(*ai);
ray.bounce(rg);
extra_range_used += 2;
ASSERT(!cell_is_solid(ray.pos()));
}
void bolt::fake_flavour()
{
if (real_flavour == BEAM_RANDOM)
flavour = static_cast<beam_type>(random_range(BEAM_FIRE, BEAM_ACID));
else if (real_flavour == BEAM_CHAOS)
flavour = _chaos_beam_flavour(this);
else if (real_flavour == BEAM_CHAOTIC_REFLECTION)
flavour = _chaotic_reflection_flavour(this);
else if (real_flavour == BEAM_CRYSTAL && flavour == BEAM_CRYSTAL)
{
flavour = coinflip() ? BEAM_FIRE : BEAM_COLD;
hit_verb = (flavour == BEAM_FIRE) ? "burns" :
(flavour == BEAM_COLD) ? "freezes"
: "bugs";
}
}
void bolt::digging_wall_effect()
{
const dungeon_feature_type feat = grd(pos());
switch (feat)
{
case DNGN_ROCK_WALL:
case DNGN_CLEAR_ROCK_WALL:
case DNGN_SLIMY_WALL:
case DNGN_GRATE:
destroy_wall(pos());
if (!msg_generated)
{
if (!you.see_cell(pos()))
{
if (!silenced(you.pos()))
{
mprf(MSGCH_SOUND, "You hear a grinding noise.");
obvious_effect = true; // You may still see the caster.
msg_generated = true;
}
break;
}
obvious_effect = true;
msg_generated = true;
string wall;
if (feat == DNGN_GRATE)
{
// XXX: should this change for monsters?
mpr("The damaged grate falls apart.");
return;
}
else if (feat == DNGN_SLIMY_WALL)
wall = "slime";
else if (player_in_branch(BRANCH_PANDEMONIUM))
wall = "weird stuff";
else
wall = "rock";
mprf("%s %s shatters into small pieces.",
agent() && agent()->is_player() ? "The" : "Some",
wall.c_str());
}
break;
default:
if (feat_is_wall(feat))
finish_beam();
}
}
void bolt::burn_wall_effect()
{
dungeon_feature_type feat = grd(pos());
// Fire only affects trees.
if (!feat_is_tree(feat)
|| env.markers.property_at(pos(), MAT_ANY, "veto_fire") == "veto"
|| !is_superhot())
{
finish_beam();
return;
}
// Destroy the wall.
destroy_wall(pos());
if (you.see_cell(pos()))
{
if (player_in_branch(BRANCH_SWAMP))
emit_message("The tree smolders and burns.");
else
emit_message("The tree burns like a torch!");
}
else if (you.can_smell())
emit_message("You smell burning wood.");
if (whose_kill() == KC_YOU)
{
did_god_conduct(DID_KILL_PLANT, 1, god_cares());
did_god_conduct(DID_FIRE, 6, god_cares()); // guaranteed penance
}
else if (whose_kill() == KC_FRIENDLY && !crawl_state.game_is_arena())
did_god_conduct(DID_KILL_PLANT, 1, god_cares());
// Trees do not burn so readily in a wet environment.
if (player_in_branch(BRANCH_SWAMP))
place_cloud(CLOUD_FIRE, pos(), random2(12)+5, agent());
else
place_cloud(CLOUD_FOREST_FIRE, pos(), random2(30)+25, agent());
obvious_effect = true;
finish_beam();
}
static bool _destroy_wall_msg(dungeon_feature_type feat, const coord_def& p)
{
const char *msg = nullptr;
msg_channel_type chan = MSGCH_PLAIN;
bool hear = player_can_hear(p);
bool see = you.see_cell(p);
switch (feat)
{
case DNGN_ROCK_WALL:
case DNGN_SLIMY_WALL:
case DNGN_CLEAR_ROCK_WALL:
case DNGN_GRANITE_STATUE:
case DNGN_CLOSED_DOOR:
case DNGN_RUNED_DOOR:
case DNGN_SEALED_DOOR:
if (see)
{
msg = (feature_description_at(p, false, DESC_THE, false)
+ " explodes into countless fragments.").c_str();
}
else if (hear)
{
msg = "You hear a grinding noise.";
chan = MSGCH_SOUND;
}
break;
case DNGN_GRATE:
if (hear)
{
if (see)
msg = "The grate screeches as it bends and collapses.";
else
msg = "You hear the screech of bent metal.";
chan = MSGCH_SOUND;
}
else if (see)
msg = "The grate bends and collapses.";
break;
case DNGN_ORCISH_IDOL:
if (hear)
{
if (see)
msg = "The idol screams as its substance crumbles away!";
else
msg = "You hear a hideous screaming!";
chan = MSGCH_SOUND;
}
else if (see)
msg = "The idol twists and shakes as its substance crumbles away!";
break;
case DNGN_TREE:
if (see)
msg = "The tree breaks and falls down!";
else if (hear)
{
msg = "You hear timber falling.";
chan = MSGCH_SOUND;
}
break;
default:
break;
}
if (msg)
{
mprf(chan, "%s", msg);
return true;
}
else
return false;
}
void bolt::destroy_wall_effect()
{
if (env.markers.property_at(pos(), MAT_ANY, "veto_disintegrate") == "veto")
{
finish_beam();
return;
}
const dungeon_feature_type feat = grd(pos());
switch (feat)
{
case DNGN_ROCK_WALL:
case DNGN_SLIMY_WALL:
case DNGN_CLEAR_ROCK_WALL:
case DNGN_GRATE:
case DNGN_GRANITE_STATUE: