/
terrain.cc
2181 lines (1886 loc) · 58.2 KB
/
terrain.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 Terrain related functions.
**/
#include "AppHdr.h"
#include "terrain.h"
#include <algorithm>
#include <sstream>
#include "areas.h"
#include "branch.h"
#include "cloud.h"
#include "coord.h"
#include "coordit.h"
#include "dgn-event.h"
#include "dgn-overview.h"
#include "directn.h"
#include "dungeon.h"
#include "env.h"
#include "fight.h"
#include "feature.h"
#include "fprop.h"
#include "god-abil.h"
#include "item-prop.h"
#include "items.h"
#include "libutil.h"
#include "map-knowledge.h"
#include "mapmark.h"
#include "message.h"
#include "misc.h"
#include "mon-place.h"
#include "mon-poly.h"
#include "mon-util.h"
#include "ouch.h"
#include "player.h"
#include "random.h"
#include "religion.h"
#include "species.h"
#include "spl-transloc.h"
#include "state.h"
#include "stringutil.h"
#include "tileview.h"
#include "transform.h"
#include "traps.h"
#include "travel.h"
#include "viewchar.h"
#include "view.h"
static bool _revert_terrain_to_floor(coord_def pos);
actor* actor_at(const coord_def& c)
{
if (!in_bounds(c))
return nullptr;
if (c == you.pos())
return &you;
return monster_at(c);
}
/** Can a malign gateway be placed on this feature?
*/
bool feat_is_malign_gateway_suitable(dungeon_feature_type feat)
{
return feat == DNGN_FLOOR || feat == DNGN_SHALLOW_WATER;
}
/** Is this feature a type of wall?
*/
bool feat_is_wall(dungeon_feature_type feat)
{
return get_feature_def(feat).flags & FFT_WALL;
}
/** Is this feature one of the main stone downstairs of a level?
*/
bool feat_is_stone_stair_down(dungeon_feature_type feat)
{
return feat == DNGN_STONE_STAIRS_DOWN_I
|| feat == DNGN_STONE_STAIRS_DOWN_II
|| feat == DNGN_STONE_STAIRS_DOWN_III;
}
/** Is this feature one of the main stone upstairs of a level?
*/
bool feat_is_stone_stair_up(dungeon_feature_type feat)
{
return feat == DNGN_STONE_STAIRS_UP_I
|| feat == DNGN_STONE_STAIRS_UP_II
|| feat == DNGN_STONE_STAIRS_UP_III;
}
/** Is this feature one of the main stone stairs of a level?
*/
bool feat_is_stone_stair(dungeon_feature_type feat)
{
return feat_is_stone_stair_up(feat) || feat_is_stone_stair_down(feat);
}
/** Is it possible to call this feature a staircase? (purely cosmetic)
*/
bool feat_is_staircase(dungeon_feature_type feat)
{
if (feat_is_stone_stair(feat))
return true;
// All branch entries/exits are staircases, except for Zot and Vaults entry.
if (feat == DNGN_ENTER_VAULTS
|| feat == DNGN_EXIT_VAULTS
|| feat == DNGN_ENTER_ZOT
|| feat == DNGN_EXIT_ZOT)
{
return false;
}
return feat_is_branch_entrance(feat)
|| feat_is_branch_exit(feat)
|| feat == DNGN_ABYSSAL_STAIR;
}
/**
* Define a memoized function from dungeon_feature_type to bool.
* This macro should be followed by the non-memoized version of the
* function body: see feat_is_branch_entrance below for an example.
*
* @param funcname The name of the function to define.
* @param paramname The name under which the function's single parameter,
* of type dungeon_feature_type, is visible in the function body.
*/
#define FEATFN_MEMOIZED(funcname, paramname) \
static bool _raw_ ## funcname (dungeon_feature_type); \
bool funcname (dungeon_feature_type feat) \
{ \
static int cached[NUM_FEATURES+1] = { 0 }; \
if (!cached[feat]) cached[feat] = _raw_ ## funcname (feat) ? 1 : -1; \
return cached[feat] > 0; \
} \
static bool _raw_ ## funcname (dungeon_feature_type paramname)
/** Is this feature a branch entrance that should show up on ^O?
*/
FEATFN_MEMOIZED(feat_is_branch_entrance, feat)
{
if (feat == DNGN_ENTER_HELL)
return false;
for (branch_iterator it; it; ++it)
{
if (it->entry_stairs == feat
&& is_connected_branch(it->id))
{
return true;
}
}
return false;
}
/** Counterpart to feat_is_branch_entrance.
*/
FEATFN_MEMOIZED(feat_is_branch_exit, feat)
{
if (feat == DNGN_ENTER_HELL || feat == DNGN_EXIT_HELL)
return false;
for (branch_iterator it; it; ++it)
{
if (it->exit_stairs == feat
&& is_connected_branch(it->id))
{
return true;
}
}
return false;
}
/** Is this feature an entrance to a portal branch?
*/
FEATFN_MEMOIZED(feat_is_portal_entrance, feat)
{
// These are have different rules from normal connected branches, but they
// also have different rules from "portal vaults," and are more similar to
// real branches in some respects.
if (feat == DNGN_ENTER_ABYSS || feat == DNGN_ENTER_PANDEMONIUM)
return false;
for (branch_iterator it; it; ++it)
{
if (it->entry_stairs == feat
&& !is_connected_branch(it->id))
{
return true;
}
}
#if TAG_MAJOR_VERSION == 34
if (feat == DNGN_ENTER_PORTAL_VAULT)
return true;
#endif
return false;
}
/** Counterpart to feat_is_portal_entrance.
*/
FEATFN_MEMOIZED(feat_is_portal_exit, feat)
{
if (feat == DNGN_EXIT_ABYSS || feat == DNGN_EXIT_PANDEMONIUM)
return false;
for (branch_iterator it; it; ++it)
{
if (it->exit_stairs == feat
&& !is_connected_branch(it->id))
{
return true;
}
}
#if TAG_MAJOR_VERSION == 34
if (feat == DNGN_EXIT_PORTAL_VAULT)
return true;
#endif
return false;
}
/** Is this feature a kind of portal?
*/
bool feat_is_portal(dungeon_feature_type feat)
{
return feat == DNGN_MALIGN_GATEWAY
|| feat_is_portal_entrance(feat)
|| feat_is_portal_exit(feat);
}
/** Is this feature a kind of level exit?
*/
bool feat_is_stair(dungeon_feature_type gridc)
{
return feat_is_travelable_stair(gridc) || feat_is_gate(gridc);
}
/** Is this feature a level exit stair with a consistent endpoint?
*/
bool feat_is_travelable_stair(dungeon_feature_type feat)
{
return feat_is_stone_stair(feat)
|| feat_is_escape_hatch(feat)
|| feat_is_branch_entrance(feat)
|| feat_is_branch_exit(feat)
|| feat == DNGN_ENTER_HELL
|| feat == DNGN_EXIT_HELL;
}
/** Is this feature an escape hatch?
*/
bool feat_is_escape_hatch(dungeon_feature_type feat)
{
return feat == DNGN_ESCAPE_HATCH_DOWN
|| feat == DNGN_ESCAPE_HATCH_UP;
}
/** Is this feature a gate?
* XXX: Why does this matter??
*/
bool feat_is_gate(dungeon_feature_type feat)
{
if (feat_is_portal_entrance(feat)
|| feat_is_portal_exit(feat))
{
return true;
}
switch (feat)
{
case DNGN_ENTER_ABYSS:
case DNGN_EXIT_THROUGH_ABYSS:
case DNGN_EXIT_ABYSS:
case DNGN_ABYSSAL_STAIR:
case DNGN_ENTER_PANDEMONIUM:
case DNGN_EXIT_PANDEMONIUM:
case DNGN_TRANSIT_PANDEMONIUM:
case DNGN_ENTER_VAULTS:
case DNGN_EXIT_VAULTS:
case DNGN_ENTER_ZOT:
case DNGN_EXIT_ZOT:
case DNGN_ENTER_HELL:
case DNGN_EXIT_HELL:
case DNGN_ENTER_DIS:
case DNGN_ENTER_GEHENNA:
case DNGN_ENTER_COCYTUS:
case DNGN_ENTER_TARTARUS:
return true;
default:
return false;
}
}
/** What command do you use to traverse this feature?
*
* @param feat the feature.
* @returns CMD_GO_UPSTAIRS if it's a stair up, CMD_GO_DOWNSTAIRS if it's a
* stair down, and CMD_NO_CMD if it can't be used to move.
*/
command_type feat_stair_direction(dungeon_feature_type feat)
{
if (feat_is_portal_entrance(feat)
|| feat_is_branch_entrance(feat))
{
return CMD_GO_DOWNSTAIRS;
}
if (feat_is_portal_exit(feat)
|| feat_is_branch_exit(feat))
{
return CMD_GO_UPSTAIRS;
}
if (feat_is_altar(feat))
return CMD_GO_UPSTAIRS; // arbitrary; consistent with shops
switch (feat)
{
case DNGN_ENTER_HELL:
return player_in_hell() ? CMD_GO_UPSTAIRS : CMD_GO_DOWNSTAIRS;
case DNGN_STONE_STAIRS_UP_I:
case DNGN_STONE_STAIRS_UP_II:
case DNGN_STONE_STAIRS_UP_III:
case DNGN_ESCAPE_HATCH_UP:
case DNGN_ENTER_SHOP:
case DNGN_EXIT_HELL:
return CMD_GO_UPSTAIRS;
case DNGN_STONE_STAIRS_DOWN_I:
case DNGN_STONE_STAIRS_DOWN_II:
case DNGN_STONE_STAIRS_DOWN_III:
case DNGN_ESCAPE_HATCH_DOWN:
case DNGN_ENTER_ABYSS:
case DNGN_EXIT_THROUGH_ABYSS:
case DNGN_EXIT_ABYSS:
case DNGN_ABYSSAL_STAIR:
case DNGN_ENTER_PANDEMONIUM:
case DNGN_EXIT_PANDEMONIUM:
case DNGN_TRANSIT_PANDEMONIUM:
return CMD_GO_DOWNSTAIRS;
default:
return CMD_NO_CMD;
}
}
/** Can you normally see through this feature?
*/
bool feat_is_opaque(dungeon_feature_type feat)
{
return get_feature_def(feat).flags & FFT_OPAQUE;
}
/** Can you move into this feature in normal play?
*/
bool feat_is_solid(dungeon_feature_type feat)
{
return get_feature_def(feat).flags & FFT_SOLID;
}
/** Can you move into this cell in normal play?
*/
bool cell_is_solid(const coord_def &c)
{
return feat_is_solid(grd(c));
}
/** Can a human stand on this feature without flying?
*/
bool feat_has_solid_floor(dungeon_feature_type feat)
{
return !feat_is_solid(feat) && feat != DNGN_DEEP_WATER
&& feat != DNGN_LAVA;
}
/** Is there enough dry floor on this feature to stand without penalty?
*/
bool feat_has_dry_floor(dungeon_feature_type feat)
{
return feat_has_solid_floor(feat) && !feat_is_water(feat);
}
/** Is this feature a variety of door?
*/
bool feat_is_door(dungeon_feature_type feat)
{
return feat == DNGN_CLOSED_DOOR || feat == DNGN_RUNED_DOOR
|| feat == DNGN_OPEN_DOOR || feat == DNGN_SEALED_DOOR;
}
/** Is this feature a variety of closed door?
*/
bool feat_is_closed_door(dungeon_feature_type feat)
{
return feat == DNGN_CLOSED_DOOR || feat == DNGN_RUNED_DOOR
|| feat == DNGN_SEALED_DOOR;
}
/** Has this feature been sealed by a vault warden?
*/
bool feat_is_sealed(dungeon_feature_type feat)
{
return feat == DNGN_SEALED_STAIRS_DOWN || feat == DNGN_SEALED_STAIRS_UP
|| feat == DNGN_SEALED_DOOR;
}
/** Is this feature a type of statue, i.e., granite or an idol?
*/
bool feat_is_statuelike(dungeon_feature_type feat)
{
return feat == DNGN_ORCISH_IDOL || feat == DNGN_GRANITE_STATUE;
}
/** Is this feature permanent, unalterable rock?
*/
bool feat_is_permarock(dungeon_feature_type feat)
{
return feat == DNGN_PERMAROCK_WALL || feat == DNGN_CLEAR_PERMAROCK_WALL;
}
/** Can this feature be dug?
*/
bool feat_is_diggable(dungeon_feature_type feat)
{
return feat == DNGN_ROCK_WALL || feat == DNGN_CLEAR_ROCK_WALL
|| feat == DNGN_SLIMY_WALL || feat == DNGN_GRATE
|| feat == DNGN_ORCISH_IDOL || DNGN_GRANITE_STATUE;
}
/** Is this feature a type of trap?
*
* @param feat the feature.
* @param undiscovered_too whether a trap not yet found counts.
* @returns true if it's a trap.
*/
bool feat_is_trap(dungeon_feature_type feat, bool undiscovered_too)
{
if (!is_valid_feature_type(feat))
return false; // ???
if (feat == DNGN_UNDISCOVERED_TRAP)
return undiscovered_too;
return get_feature_def(feat).flags & FFT_TRAP;
}
/** Is this feature a type of water, with the concomitant dangers/bonuss?
*/
bool feat_is_water(dungeon_feature_type feat)
{
return feat == DNGN_SHALLOW_WATER
|| feat == DNGN_DEEP_WATER
|| feat == DNGN_OPEN_SEA;
}
/** Does this feature have enough water to keep water-only monsters alive in it?
*/
bool feat_is_watery(dungeon_feature_type feat)
{
return feat_is_water(feat) || feat == DNGN_FOUNTAIN_BLUE;
}
/** Is this feature a kind of lava?
*/
bool feat_is_lava(dungeon_feature_type feat)
{
return feat == DNGN_LAVA || feat == DNGN_LAVA_SEA;
}
static const pair<god_type, dungeon_feature_type> _god_altars[] =
{
{ GOD_ZIN, DNGN_ALTAR_ZIN },
{ GOD_SHINING_ONE, DNGN_ALTAR_SHINING_ONE },
{ GOD_KIKUBAAQUDGHA, DNGN_ALTAR_KIKUBAAQUDGHA },
{ GOD_YREDELEMNUL, DNGN_ALTAR_YREDELEMNUL },
{ GOD_XOM, DNGN_ALTAR_XOM },
{ GOD_VEHUMET, DNGN_ALTAR_VEHUMET },
{ GOD_OKAWARU, DNGN_ALTAR_OKAWARU },
{ GOD_MAKHLEB, DNGN_ALTAR_MAKHLEB },
{ GOD_SIF_MUNA, DNGN_ALTAR_SIF_MUNA },
{ GOD_TROG, DNGN_ALTAR_TROG },
{ GOD_NEMELEX_XOBEH, DNGN_ALTAR_NEMELEX_XOBEH },
{ GOD_ELYVILON, DNGN_ALTAR_ELYVILON },
{ GOD_LUGONU, DNGN_ALTAR_LUGONU },
{ GOD_BEOGH, DNGN_ALTAR_BEOGH },
{ GOD_JIYVA, DNGN_ALTAR_JIYVA },
{ GOD_FEDHAS, DNGN_ALTAR_FEDHAS },
{ GOD_CHEIBRIADOS, DNGN_ALTAR_CHEIBRIADOS },
{ GOD_ASHENZARI, DNGN_ALTAR_ASHENZARI },
{ GOD_DITHMENOS, DNGN_ALTAR_DITHMENOS },
{ GOD_GOZAG, DNGN_ALTAR_GOZAG },
{ GOD_QAZLAL, DNGN_ALTAR_QAZLAL },
{ GOD_RU, DNGN_ALTAR_RU },
{ GOD_PAKELLAS, DNGN_ALTAR_PAKELLAS },
{ GOD_USKAYAW, DNGN_ALTAR_USKAYAW },
{ GOD_HEPLIAKLQANA, DNGN_ALTAR_HEPLIAKLQANA },
{ GOD_ECUMENICAL, DNGN_ALTAR_ECUMENICAL },
};
COMPILE_CHECK(ARRAYSZ(_god_altars) == NUM_GODS );
/** Whose altar is this feature?
*
* @param feat the feature.
* @returns GOD_NO_GOD if not an altar, otherwise the god_type of the god.
*/
god_type feat_altar_god(dungeon_feature_type feat)
{
for (const auto &altar : _god_altars)
if (altar.second == feat)
return altar.first;
return GOD_NO_GOD;
}
/** What feature is the altar of this god?
*
* @param god the god.
* @returns DNGN_FLOOR for an invalid god, the god's altar otherwise.
*/
dungeon_feature_type altar_for_god(god_type god)
{
for (const auto &altar : _god_altars)
if (altar.first == god)
return altar.second;
return DNGN_FLOOR;
}
/** Is this feature an altar to any god?
*/
bool feat_is_altar(dungeon_feature_type grid)
{
return feat_altar_god(grid) != GOD_NO_GOD;
}
/** Is this feature an altar to the player's god?
*
* @param feat the feature.
* @returns true if the player has a god and this is its altar.
*/
bool feat_is_player_altar(dungeon_feature_type grid)
{
return !you_worship(GOD_NO_GOD) && you_worship(feat_altar_god(grid));
}
/** Is this feature a tree?
*/
bool feat_is_tree(dungeon_feature_type feat)
{
return feat == DNGN_TREE;
}
/** Is this feature made of metal?
*/
bool feat_is_metal(dungeon_feature_type feat)
{
return feat == DNGN_METAL_WALL || feat == DNGN_GRATE;
}
/** Is this feature ambivalent about whether we're going up or down?
*/
bool feat_is_bidirectional_portal(dungeon_feature_type feat)
{
return get_feature_dchar(feat) == DCHAR_ARCH
&& feat_stair_direction(feat) != CMD_NO_CMD
&& feat != DNGN_ENTER_ZOT
&& feat != DNGN_EXIT_ZOT
&& feat != DNGN_ENTER_VAULTS
&& feat != DNGN_EXIT_VAULTS
&& feat != DNGN_EXIT_HELL
&& feat != DNGN_ENTER_HELL;
}
/** Is this feature a type of fountain?
*/
bool feat_is_fountain(dungeon_feature_type feat)
{
return feat == DNGN_FOUNTAIN_BLUE
|| feat == DNGN_FOUNTAIN_SPARKLING
|| feat == DNGN_FOUNTAIN_BLOOD
|| feat == DNGN_DRY_FOUNTAIN;
}
/** Is this feature non-solid enough that you can reach past it?
*/
bool feat_is_reachable_past(dungeon_feature_type feat)
{
return !feat_is_opaque(feat) && !feat_is_wall(feat) && feat != DNGN_GRATE;
}
/** Is this feature important to the game?
*
* @param feat the feature.
* @returns true for altars, stairs/portals, and malign gateways (???).
*/
bool feat_is_critical(dungeon_feature_type feat)
{
return feat_stair_direction(feat) != CMD_NO_CMD
|| feat_altar_god(feat) != GOD_NO_GOD
|| feat == DNGN_MALIGN_GATEWAY;
}
/** Can you use this feature for a map border?
*/
bool feat_is_valid_border(dungeon_feature_type feat)
{
return feat_is_wall(feat)
|| feat_is_tree(feat)
|| feat == DNGN_OPEN_SEA
|| feat == DNGN_LAVA_SEA
|| feat == DNGN_ENDLESS_SALT;
}
/** Can this feature be a mimic?
*
* @param feat the feature
* @param strict if true, disallow features for which being a mimic would be bad in
normal generation; vaults can still use such mimics.
* @returns whether this could make a valid mimic type.
*/
bool feat_is_mimicable(dungeon_feature_type feat, bool strict)
{
if (!strict && feat != DNGN_FLOOR && feat != DNGN_SHALLOW_WATER
&& feat != DNGN_DEEP_WATER)
{
return true;
}
if (feat == DNGN_ENTER_ZIGGURAT)
return false;
if (feat_is_portal_entrance(feat))
return true;
if (feat == DNGN_ENTER_SHOP)
return true;
return false;
}
/** Can creatures on this feature be shafted?
*
* @param feat The feature in question.
* @returns Whether creatures standing on this feature can be shafted (by
* magical effects, Formicid digging, etc).
*/
bool feat_is_shaftable(dungeon_feature_type feat)
{
return feat_has_dry_floor(feat)
&& !feat_is_stair(feat)
&& !feat_is_portal(feat);
}
int count_neighbours_with_func(const coord_def& c, bool (*checker)(dungeon_feature_type))
{
int count = 0;
for (adjacent_iterator ai(c); ai; ++ai)
{
if (checker(grd(*ai)))
count++;
}
return count;
}
// For internal use by find_connected_identical only.
static void _find_connected_identical(const coord_def &d,
dungeon_feature_type ft,
set<coord_def>& out)
{
if (grd(d) != ft)
return;
string prop = env.markers.property_at(d, MAT_ANY, "connected_exclude");
if (!prop.empty())
{
// Don't treat this square as connected to anything. Ignore it.
// Continue the search in other directions.
return;
}
if (out.insert(d).second)
{
_find_connected_identical(coord_def(d.x+1, d.y), ft, out);
_find_connected_identical(coord_def(d.x-1, d.y), ft, out);
_find_connected_identical(coord_def(d.x, d.y+1), ft, out);
_find_connected_identical(coord_def(d.x, d.y-1), ft, out);
}
}
// Find all connected cells containing ft, starting at d.
void find_connected_identical(const coord_def &d, set<coord_def>& out)
{
string prop = env.markers.property_at(d, MAT_ANY, "connected_exclude");
if (!prop.empty())
out.insert(d);
else
_find_connected_identical(d, grd(d), out);
}
void get_door_description(int door_size, const char** adjective, const char** noun)
{
const char* descriptions[] =
{
"miniscule " , "buggy door",
"" , "door",
"large " , "door",
"" , "gate",
"huge " , "gate",
};
int max_idx = static_cast<int>(ARRAYSZ(descriptions) - 2);
const unsigned int idx = min(door_size*2, max_idx);
*adjective = descriptions[idx];
*noun = descriptions[idx+1];
}
coord_def get_random_stair()
{
vector<coord_def> st;
for (rectangle_iterator ri(1); ri; ++ri)
{
const dungeon_feature_type feat = grd(*ri);
if (feat_is_travelable_stair(feat) && !feat_is_escape_hatch(feat)
&& feat != DNGN_EXIT_DUNGEON
&& feat != DNGN_EXIT_HELL)
{
st.push_back(*ri);
}
}
if (st.empty())
return coord_def(); // sanity check: shouldn't happen
return st[random2(st.size())];
}
static unique_ptr<map_mask_boolean> _slime_wall_precomputed_neighbour_mask;
static void _precompute_slime_wall_neighbours()
{
map_mask_boolean &mask(*_slime_wall_precomputed_neighbour_mask.get());
for (rectangle_iterator ri(1); ri; ++ri)
{
if (grd(*ri) == DNGN_SLIMY_WALL)
{
for (adjacent_iterator ai(*ri); ai; ++ai)
mask(*ai) = true;
}
}
}
unwind_slime_wall_precomputer::unwind_slime_wall_precomputer(bool docompute)
: did_compute_mask(false)
{
if (!(env.level_state & LSTATE_SLIMY_WALL))
return;
if (docompute && !_slime_wall_precomputed_neighbour_mask.get())
{
did_compute_mask = true;
_slime_wall_precomputed_neighbour_mask.reset(
new map_mask_boolean(false));
_precompute_slime_wall_neighbours();
}
}
unwind_slime_wall_precomputer::~unwind_slime_wall_precomputer()
{
if (did_compute_mask)
_slime_wall_precomputed_neighbour_mask.reset(nullptr);
}
bool slime_wall_neighbour(const coord_def& c)
{
if (!(env.level_state & LSTATE_SLIMY_WALL))
return false;
if (_slime_wall_precomputed_neighbour_mask.get())
return (*_slime_wall_precomputed_neighbour_mask)(c);
// Not using count_adjacent_slime_walls because the early return might
// be relevant for performance here. TODO: profile it and find out.
for (adjacent_iterator ai(c); ai; ++ai)
if (env.grid(*ai) == DNGN_SLIMY_WALL)
return true;
return false;
}
int count_adjacent_slime_walls(const coord_def &pos)
{
int count = 0;
for (adjacent_iterator ai(pos); ai; ++ai)
if (env.grid(*ai) == DNGN_SLIMY_WALL)
count++;
return count;
}
void slime_wall_damage(actor* act, int delay)
{
ASSERT(act);
if (actor_slime_wall_immune(act))
return;
const int walls = count_adjacent_slime_walls(act->pos());
if (!walls)
return;
const int strength = div_rand_round(3 * walls * delay, BASELINE_DELAY);
if (act->is_player())
{
you.splash_with_acid(nullptr, strength, false,
(walls > 1) ? "The walls burn you!"
: "The wall burns you!");
}
else
{
monster* mon = act->as_monster();
const int dam = resist_adjust_damage(mon, BEAM_ACID,
roll_dice(2, strength));
if (dam > 0 && you.can_see(*mon))
{
mprf((walls > 1) ? "The walls burn %s!" : "The wall burns %s!",
mon->name(DESC_THE).c_str());
}
mon->hurt(nullptr, dam, BEAM_ACID);
}
}
void feat_splash_noise(dungeon_feature_type feat)
{
switch (feat)
{
case DNGN_SHALLOW_WATER:
case DNGN_DEEP_WATER:
mprf(MSGCH_SOUND, "You hear a splash.");
return;
case DNGN_LAVA:
mprf(MSGCH_SOUND, "You hear a sizzling splash.");
return;
default:
return;
}
}
/** Does this feature destroy any items that fall into it?
*/
bool feat_destroys_items(dungeon_feature_type feat)
{
return feat == DNGN_LAVA;
}
/** Does this feature make items that fall into it permanently inaccessible?
*/
bool feat_eliminates_items(dungeon_feature_type feat)
{
return feat_destroys_items(feat)
|| feat == DNGN_DEEP_WATER && !species_likes_water(you.species);
}
static coord_def _dgn_find_nearest_square(
const coord_def &pos,
function<bool (const coord_def &)> acceptable,
function<bool (const coord_def &)> traversable = nullptr)
{
memset(travel_point_distance, 0, sizeof(travel_distance_grid_t));
vector<coord_def> points[2];
int iter = 0;
points[iter].push_back(pos);
while (!points[iter].empty())
{
// Iterate each layer of BFS in random order to avoid bias.
shuffle_array(points[iter]);
for (const auto &p : points[iter])
{
if (p != pos && acceptable(p))
return p;
travel_point_distance[p.x][p.y] = 1;
for (int yi = -1; yi <= 1; ++yi)
for (int xi = -1; xi <= 1; ++xi)
{
if (!xi && !yi)
continue;
const coord_def np = p + coord_def(xi, yi);
if (!in_bounds(np) || travel_point_distance[np.x][np.y])
continue;
if (traversable && !traversable(np))
continue;
points[!iter].push_back(np);
}
}
points[iter].clear();
iter = !iter;
}
return coord_def(0, 0); // Not found.
}
static bool _item_safe_square(const coord_def &pos)
{
const dungeon_feature_type feat = grd(pos);
return feat_is_traversable(feat) && !feat_destroys_items(feat);
}
static bool _item_traversable_square(const coord_def &pos)
{
return !cell_is_solid(pos);
}
// Moves an item on the floor to the nearest adjacent floor-space.
static bool _dgn_shift_item(const coord_def &pos, item_def &item)
{
// First try to avoid pushing things through solid features...
coord_def np = _dgn_find_nearest_square(pos, _item_safe_square,
_item_traversable_square);
// ... but if we have to, so be it.
if (!in_bounds(np) || np == pos)
np = _dgn_find_nearest_square(pos, _item_safe_square);
if (in_bounds(np) && np != pos)
{
int index = item.index();
move_item_to_grid(&index, np);
return true;
}
return false;
}
static bool _is_feature_shift_target(const coord_def &pos)
{
return grd(pos) == DNGN_FLOOR && !dungeon_events.has_listeners_at(pos)
&& !actor_at(pos);
}
// Moves everything at src to dst. This is not a swap operation: src will be
// left with the same feature it started with, and should be overwritten with
// something new. Assumes there are no actors in the destination square.
//
// Things that are moved:
// 1. Dungeon terrain (set to DNGN_UNSEEN)
// 2. Actors (including the player)
// 3. Items
// 4. Clouds
// 5. Terrain properties
// 6. Terrain colours
// 7. Vault (map) mask
// 8. Vault id mask
// 9. Map markers, dungeon listeners, shopping list
//10. Player's knowledge
void dgn_move_entities_at(coord_def src, coord_def dst,
bool move_player,
bool move_monster,
bool move_items)
{
if (!in_bounds(dst) || !in_bounds(src) || src == dst)
return;
move_notable_thing(src, dst);
dungeon_feature_type dfeat = grd(src);
if (dfeat == DNGN_ENTER_SHOP)
{
ASSERT(shop_at(src));
env.shop[dst] = env.shop[src];
env.shop[dst].pos = dst;
env.shop.erase(src);
grd(src) = DNGN_FLOOR;
}
else if (feat_is_trap(dfeat, true))
{
ASSERT(trap_at(src));
env.trap[dst] = env.trap[src];
env.trap[dst].pos = dst;
env.trap.erase(src);
grd(src) = DNGN_FLOOR;
}
grd(dst) = dfeat;
if (move_monster || move_player)
ASSERT(!actor_at(dst));