forked from NetHack/NetHack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdig.c
More file actions
2164 lines (1984 loc) · 73.7 KB
/
dig.c
File metadata and controls
2164 lines (1984 loc) · 73.7 KB
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
/* NetHack 3.7 dig.c $NHDT-Date: 1596498156 2020/08/03 23:42:36 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.142 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2012. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
static boolean rm_waslit(void);
static void mkcavepos(coordxy, coordxy, int, boolean, boolean);
static void mkcavearea(boolean);
static int dig(void);
static void dig_up_grave(coord *);
static boolean watchman_canseeu(struct monst *);
static int adj_pit_checks(coord *, char *);
static void pit_flow(struct trap *, schar);
static boolean furniture_handled(coordxy, coordxy, boolean);
/* Indices returned by dig_typ() */
enum dig_types {
DIGTYP_UNDIGGABLE = 0,
DIGTYP_ROCK,
DIGTYP_STATUE,
DIGTYP_BOULDER,
DIGTYP_DOOR,
DIGTYP_TREE
};
static boolean
rm_waslit(void)
{
register coordxy x, y;
if (levl[u.ux][u.uy].typ == ROOM && levl[u.ux][u.uy].waslit)
return TRUE;
for (x = u.ux - 2; x < u.ux + 3; x++)
for (y = u.uy - 1; y < u.uy + 2; y++)
if (isok(x, y) && levl[x][y].waslit)
return TRUE;
return FALSE;
}
/* Change level topology. Messes with vision tables and ignores things like
* boulders in the name of a nice effect. Vision will get fixed up again
* immediately after the effect is complete.
*/
static void
mkcavepos(coordxy x, coordxy y, int dist, boolean waslit, boolean rockit)
{
register struct rm *lev;
if (!isok(x, y))
return;
lev = &levl[x][y];
if (rockit) {
register struct monst *mtmp;
if (IS_ROCK(lev->typ))
return;
if (t_at(x, y))
return; /* don't cover the portal */
if ((mtmp = m_at(x, y)) != 0) /* make sure crucial monsters survive */
if (!passes_walls(mtmp->data))
(void) rloc(mtmp, RLOC_NOMSG);
} else if (lev->typ == ROOM)
return;
unblock_point(x, y); /* make sure vision knows this location is open */
/* fake out saved state */
lev->seenv = 0;
lev->doormask = 0;
if (dist < 3)
lev->lit = (rockit ? FALSE : TRUE);
if (waslit)
lev->waslit = (rockit ? FALSE : TRUE);
lev->horizontal = FALSE;
/* short-circuit vision recalc */
gv.viz_array[y][x] = (dist < 3) ? (IN_SIGHT | COULD_SEE) : COULD_SEE;
lev->typ = (rockit ? STONE : ROOM); /* flags set via doormask above */
if (dist >= 3)
impossible("mkcavepos called with dist %d", dist);
feel_newsym(x, y);
}
static void
mkcavearea(boolean rockit)
{
int dist;
coordxy xmin = u.ux, xmax = u.ux;
coordxy ymin = u.uy, ymax = u.uy;
register coordxy i;
register boolean waslit = rm_waslit();
if (rockit) {
Soundeffect(se_crashing_rock, 100);
pline("Crash! The ceiling collapses around you!");
} else {
pline("A mysterious force %s cave around you!",
(levl[u.ux][u.uy].typ == CORR) ? "creates a" : "extends the");
}
display_nhwindow(WIN_MESSAGE, TRUE);
for (dist = 1; dist <= 2; dist++) {
xmin--;
xmax++;
/* top and bottom */
if (dist < 2) { /* the area is wider that it is high */
ymin--;
ymax++;
for (i = xmin + 1; i < xmax; i++) {
mkcavepos(i, ymin, dist, waslit, rockit);
mkcavepos(i, ymax, dist, waslit, rockit);
}
}
/* left and right */
for (i = ymin; i <= ymax; i++) {
mkcavepos(xmin, i, dist, waslit, rockit);
mkcavepos(xmax, i, dist, waslit, rockit);
}
flush_screen(1); /* make sure the new glyphs shows up */
nh_delay_output();
}
if (!rockit && levl[u.ux][u.uy].typ == CORR) {
levl[u.ux][u.uy].typ = ROOM; /* flags for CORR already 0 */
if (waslit)
levl[u.ux][u.uy].waslit = TRUE;
newsym(u.ux, u.uy); /* in case player is invisible */
}
gv.vision_full_recalc = 1; /* everything changed */
}
/* When digging into location <x,y>, what are you actually digging into? */
int
dig_typ(struct obj *otmp, coordxy x, coordxy y)
{
boolean ispick;
if (!otmp)
return DIGTYP_UNDIGGABLE;
ispick = is_pick(otmp);
if (!ispick && !is_axe(otmp))
return DIGTYP_UNDIGGABLE;
return ((ispick && sobj_at(STATUE, x, y))
? DIGTYP_STATUE
: (ispick && sobj_at(BOULDER, x, y))
? DIGTYP_BOULDER
: closed_door(x, y)
? DIGTYP_DOOR
: IS_TREE(levl[x][y].typ)
? (ispick ? DIGTYP_UNDIGGABLE : DIGTYP_TREE)
: (ispick && IS_ROCK(levl[x][y].typ)
&& (!gl.level.flags.arboreal
|| IS_WALL(levl[x][y].typ)))
? DIGTYP_ROCK
: DIGTYP_UNDIGGABLE);
}
boolean
is_digging(void)
{
if (go.occupation == dig) {
return TRUE;
}
return FALSE;
}
#define BY_YOU (&gy.youmonst)
#define BY_OBJECT ((struct monst *) 0)
boolean
dig_check(struct monst *madeby, boolean verbose, coordxy x, coordxy y)
{
struct trap *ttmp = t_at(x, y);
const char *verb =
(madeby == BY_YOU && uwep && is_axe(uwep)) ? "chop" : "dig in";
if (On_stairs(x, y)) {
stairway *stway = stairway_at(x, y);
if (stway->isladder) {
if (verbose)
pline_The("ladder resists your effort.");
} else if (verbose)
pline_The("stairs are too hard to %s.", verb);
return FALSE;
} else if (IS_THRONE(levl[x][y].typ) && madeby != BY_OBJECT) {
if (verbose)
pline_The("throne is too hard to break apart.");
return FALSE;
} else if (IS_ALTAR(levl[x][y].typ)
&& (madeby != BY_OBJECT || Is_astralevel(&u.uz)
|| Is_sanctum(&u.uz))) {
if (verbose)
pline_The("altar is too hard to break apart.");
return FALSE;
} else if (Is_airlevel(&u.uz)) {
if (verbose)
You("cannot %s thin air.", verb);
return FALSE;
} else if (Is_waterlevel(&u.uz)) {
if (verbose)
pline_The("%s splashes and subsides.", hliquid("water"));
return FALSE;
} else if ((IS_ROCK(levl[x][y].typ) && levl[x][y].typ != SDOOR
&& (levl[x][y].wall_info & W_NONDIGGABLE) != 0)
|| (ttmp
&& (undestroyable_trap(ttmp->ttyp)
|| (!Can_dig_down(&u.uz) && !levl[x][y].candig)))) {
if (verbose)
pline_The("%s here is too hard to %s.", surface(x, y), verb);
return FALSE;
} else if (sobj_at(BOULDER, x, y)) {
if (verbose)
There("isn't enough room to %s here.", verb);
return FALSE;
} else if (madeby == BY_OBJECT
/* the block against existing traps is mainly to
prevent broken wands from turning holes into pits */
&& (ttmp || is_pool_or_lava(x, y))) {
/* digging by player handles pools separately */
return FALSE;
}
return TRUE;
}
static int
dig(void)
{
struct rm *lev;
coordxy dpx = gc.context.digging.pos.x, dpy = gc.context.digging.pos.y;
boolean ispick = uwep && is_pick(uwep);
const char *verb = (!uwep || is_pick(uwep)) ? "dig into" : "chop through";
lev = &levl[dpx][dpy];
/* perhaps a nymph stole your pick-axe while you were busy digging */
/* or perhaps you teleported away */
if (u.uswallow || !uwep || (!ispick && !is_axe(uwep))
|| !on_level(&gc.context.digging.level, &u.uz)
|| ((gc.context.digging.down ? (dpx != u.ux || dpy != u.uy)
: !next2u(dpx, dpy))))
return 0;
if (gc.context.digging.down) {
if (!dig_check(BY_YOU, TRUE, u.ux, u.uy))
return 0;
} else { /* !gc.context.digging.down */
if (IS_TREE(lev->typ) && !may_dig(dpx, dpy)
&& dig_typ(uwep, dpx, dpy) == DIGTYP_TREE) {
pline("This tree seems to be petrified.");
return 0;
}
if (IS_ROCK(lev->typ) && !may_dig(dpx, dpy)
&& dig_typ(uwep, dpx, dpy) == DIGTYP_ROCK) {
pline("This %s is too hard to %s.",
is_db_wall(dpx, dpy) ? "drawbridge" : "wall", verb);
return 0;
}
}
if (Fumbling && !rn2(3)) {
switch (rn2(3)) {
case 0:
if (!welded(uwep)) {
You("fumble and drop %s.", yname(uwep));
dropx(uwep);
} else {
if (u.usteed)
pline("%s and %s %s!", Yobjnam2(uwep, "bounce"),
otense(uwep, "hit"), mon_nam(u.usteed));
else
pline("Ouch! %s and %s you!", Yobjnam2(uwep, "bounce"),
otense(uwep, "hit"));
set_wounded_legs(RIGHT_SIDE, 5 + rnd(5));
}
break;
case 1:
Soundeffect(se_bang_weapon_side, 100);
pline("Bang! You hit with the broad side of %s!",
the(xname(uwep)));
wake_nearby();
break;
default:
Your("swing misses its mark.");
break;
}
return 0;
}
gc.context.digging.effort +=
10 + rn2(5) + abon() + uwep->spe - greatest_erosion(uwep) + u.udaminc;
if (Race_if(PM_DWARF))
gc.context.digging.effort *= 2;
if (gc.context.digging.down) {
struct trap *ttmp = t_at(dpx, dpy);
if (gc.context.digging.effort > 250 || (ttmp && ttmp->ttyp == HOLE)) {
(void) dighole(FALSE, FALSE, (coord *) 0);
(void) memset((genericptr_t) &gc.context.digging, 0,
sizeof gc.context.digging);
return 0; /* done with digging */
}
if (gc.context.digging.effort <= 50
|| (ttmp && (ttmp->ttyp == TRAPDOOR || is_pit(ttmp->ttyp)))) {
return 1;
} else if (ttmp && (ttmp->ttyp == LANDMINE
|| (ttmp->ttyp == BEAR_TRAP && !u.utrap))) {
/* digging onto a set object trap triggers it;
hero should have used #untrap first */
dotrap(ttmp, FORCETRAP);
/* restart completely from scratch if we resume digging */
(void) memset((genericptr_t) &gc.context.digging, 0,
sizeof gc.context.digging);
return 0;
} else if (ttmp && ttmp->ttyp == BEAR_TRAP && u.utrap) {
if (rnl(7) > (Fumbling ? 1 : 4)) {
char kbuf[BUFSZ];
int dmg = dmgval(uwep, &gy.youmonst) + dbon();
if (dmg < 1)
dmg = 1;
else if (uarmf)
dmg = (dmg + 1) / 2;
You("hit yourself in the %s.", body_part(FOOT));
Sprintf(kbuf, "chopping off %s own %s", uhis(),
body_part(FOOT));
losehp(Maybe_Half_Phys(dmg), kbuf, KILLED_BY);
} else {
You("destroy the bear trap with %s.",
yobjnam(uwep, (const char *) 0));
deltrap(ttmp);
reset_utrap(TRUE); /* release from trap, maybe Lev or Fly */
}
/* we haven't made any progress toward a pit yet */
gc.context.digging.effort = 0;
return 0;
}
if (IS_ALTAR(lev->typ)) {
altar_wrath(dpx, dpy);
angry_priest();
}
/* make pit at <u.ux,u.uy> */
if (dighole(TRUE, FALSE, (coord *) 0)) {
gc.context.digging.level.dnum = 0;
gc.context.digging.level.dlevel = -1;
}
return 0;
}
if (gc.context.digging.effort > 100) {
const char *digtxt, *dmgtxt = (const char *) 0;
struct obj *obj;
boolean shopedge = *in_rooms(dpx, dpy, SHOPBASE);
if ((obj = sobj_at(STATUE, dpx, dpy)) != 0) {
if (break_statue(obj))
digtxt = "The statue shatters.";
else
/* it was a statue trap; break_statue()
* printed a message and updated the screen
*/
digtxt = (char *) 0;
} else if ((obj = sobj_at(BOULDER, dpx, dpy)) != 0) {
struct obj *bobj;
fracture_rock(obj);
if ((bobj = sobj_at(BOULDER, dpx, dpy)) != 0) {
/* another boulder here, restack it to the top */
obj_extract_self(bobj);
place_object(bobj, dpx, dpy);
}
digtxt = "The boulder falls apart.";
} else if (lev->typ == STONE || lev->typ == SCORR
|| IS_TREE(lev->typ)) {
if (Is_earthlevel(&u.uz)) {
if (uwep->blessed && !rn2(3)) {
mkcavearea(FALSE);
goto cleanup;
} else if ((uwep->cursed && !rn2(4))
|| (!uwep->blessed && !rn2(6))) {
mkcavearea(TRUE);
goto cleanup;
}
}
if (IS_TREE(lev->typ)) {
digtxt = "You cut down the tree.";
lev->typ = ROOM, lev->flags = 0;
if (!rn2(5))
(void) rnd_treefruit_at(dpx, dpy);
if (Race_if(PM_ELF) || Role_if(PM_RANGER))
adjalign(-1);
} else {
digtxt = "You succeed in cutting away some rock.";
lev->typ = CORR, lev->flags = 0;
}
} else if (IS_WALL(lev->typ)) {
if (shopedge) {
add_damage(dpx, dpy, SHOP_WALL_DMG);
dmgtxt = "damage";
}
if (gl.level.flags.is_maze_lev) {
lev->typ = ROOM, lev->flags = 0;
} else if (gl.level.flags.is_cavernous_lev && !in_town(dpx, dpy)) {
lev->typ = CORR, lev->flags = 0;
} else {
lev->typ = DOOR, lev->doormask = D_NODOOR;
}
digtxt = "You make an opening in the wall.";
} else if (lev->typ == SDOOR) {
cvt_sdoor_to_door(lev); /* ->typ = DOOR */
digtxt = "You break through a secret door!";
if (!(lev->doormask & D_TRAPPED))
lev->doormask = D_BROKEN;
} else if (closed_door(dpx, dpy)) {
digtxt = "You break through the door.";
if (shopedge) {
add_damage(dpx, dpy, SHOP_DOOR_COST);
dmgtxt = "break";
}
if (!(lev->doormask & D_TRAPPED))
lev->doormask = D_BROKEN;
} else
return 0; /* statue or boulder got taken */
if (!does_block(dpx, dpy, &levl[dpx][dpy]))
unblock_point(dpx, dpy); /* vision: can see through */
feel_newsym(dpx, dpy);
if (digtxt && !gc.context.digging.quiet)
pline1(digtxt); /* after newsym */
if (dmgtxt)
pay_for_damage(dmgtxt, FALSE);
if (Is_earthlevel(&u.uz) && !rn2(3)) {
register struct monst *mtmp;
switch (rn2(2)) {
case 0:
mtmp = makemon(&mons[PM_EARTH_ELEMENTAL], dpx, dpy,
MM_NOMSG);
break;
default:
mtmp = makemon(&mons[PM_XORN], dpx, dpy, MM_NOMSG);
break;
}
if (mtmp)
pline_The("debris from your digging comes to life!");
}
if (IS_DOOR(lev->typ) && (lev->doormask & D_TRAPPED)) {
lev->doormask = D_NODOOR;
b_trapped("door", 0);
newsym(dpx, dpy);
}
cleanup:
gc.context.digging.lastdigtime = gm.moves;
gc.context.digging.quiet = FALSE;
gc.context.digging.level.dnum = 0;
gc.context.digging.level.dlevel = -1;
return 0;
} else { /* not enough effort has been spent yet */
static const char *const d_target[6] = { "", "rock", "statue",
"boulder", "door", "tree" };
int dig_target = dig_typ(uwep, dpx, dpy);
if (IS_WALL(lev->typ) || dig_target == DIGTYP_DOOR) {
if (*in_rooms(dpx, dpy, SHOPBASE)) {
pline("This %s seems too hard to %s.",
IS_DOOR(lev->typ) ? "door" : "wall", verb);
return 0;
}
} else if (dig_target == DIGTYP_UNDIGGABLE
|| (dig_target == DIGTYP_ROCK && !IS_ROCK(lev->typ)))
return 0; /* statue or boulder got taken */
if (!gd.did_dig_msg) {
You("hit the %s with all your might.", d_target[dig_target]);
wake_nearby();
gd.did_dig_msg = TRUE;
}
}
return 1;
}
static boolean
furniture_handled(coordxy x, coordxy y, boolean madeby_u)
{
struct rm *lev = &levl[x][y];
if (IS_FOUNTAIN(lev->typ)) {
dogushforth(FALSE);
SET_FOUNTAIN_WARNED(x, y); /* force dryup */
dryup(x, y, madeby_u);
} else if (IS_SINK(lev->typ)) {
breaksink(x, y);
} else if (lev->typ == DRAWBRIDGE_DOWN
|| (is_drawbridge_wall(x, y) >= 0)) {
coordxy bx = x, by = y;
/* if under the portcullis, the bridge is adjacent */
(void) find_drawbridge(&bx, &by);
destroy_drawbridge(bx, by);
} else {
return FALSE;
}
return TRUE;
}
/* When will hole be finished? Very rough indication used by shopkeeper. */
int
holetime(void)
{
if (go.occupation != dig || !*u.ushops)
return -1;
return ((250 - gc.context.digging.effort) / 20);
}
/* Return typ of liquid to fill a hole with, or ROOM, if no liquid nearby */
schar
fillholetyp(coordxy x, coordxy y,
boolean fill_if_any) /* force filling if it exists at all */
{
coordxy x1, y1;
coordxy lo_x = max(1, x - 1), hi_x = min(x + 1, COLNO - 1),
lo_y = max(0, y - 1), hi_y = min(y + 1, ROWNO - 1);
int pool_cnt = 0, moat_cnt = 0, lava_cnt = 0;
for (x1 = lo_x; x1 <= hi_x; x1++)
for (y1 = lo_y; y1 <= hi_y; y1++)
if (is_moat(x1, y1))
moat_cnt++;
else if (is_pool(x1, y1))
/* This must come after is_moat since moats are pools
* but not vice-versa. */
pool_cnt++;
else if (is_lava(x1, y1))
lava_cnt++;
if (!fill_if_any)
pool_cnt /= 3; /* not as much liquid as the others */
if ((lava_cnt > moat_cnt + pool_cnt && rn2(lava_cnt + 1))
|| (lava_cnt && fill_if_any))
return LAVAPOOL;
else if ((moat_cnt > 0 && rn2(moat_cnt + 1)) || (moat_cnt && fill_if_any))
return MOAT;
else if ((pool_cnt > 0 && rn2(pool_cnt + 1)) || (pool_cnt && fill_if_any))
return POOL;
else
return ROOM;
}
void
digactualhole(coordxy x, coordxy y, struct monst *madeby, int ttyp)
{
struct obj *oldobjs, *newobjs;
register struct trap *ttmp;
char surface_type[BUFSZ];
struct rm *lev = &levl[x][y];
boolean shopdoor;
struct monst *mtmp = m_at(x, y); /* may be madeby */
boolean madeby_u = (madeby == BY_YOU);
boolean madeby_obj = (madeby == BY_OBJECT);
boolean at_u = u_at(x, y);
boolean wont_fall = Levitation || Flying;
if (at_u && u.utrap) {
if (u.utraptype == TT_BURIEDBALL)
buried_ball_to_punishment();
else if (u.utraptype == TT_INFLOOR)
reset_utrap(FALSE);
}
if (furniture_handled(x, y, madeby_u))
return;
if (ttyp != PIT && (!Can_dig_down(&u.uz) && !lev->candig)) {
impossible("digactualhole: can't dig %s on this level.",
trapname(ttyp, TRUE));
ttyp = PIT;
}
/* maketrap() might change it, also, in this situation,
surface() returns an inappropriate string for a grave */
if (IS_GRAVE(lev->typ))
Strcpy(surface_type, "grave");
else
Strcpy(surface_type, surface(x, y));
shopdoor = IS_DOOR(lev->typ) && *in_rooms(x, y, SHOPBASE);
oldobjs = gl.level.objects[x][y];
ttmp = maketrap(x, y, ttyp);
if (!ttmp)
return;
newobjs = gl.level.objects[x][y];
ttmp->madeby_u = madeby_u;
ttmp->tseen = 0;
if (cansee(x, y))
seetrap(ttmp);
else if (madeby_u)
feeltrap(ttmp);
if (ttyp == PIT) {
if (madeby_u) {
if (x != u.ux || y != u.uy)
You("dig an adjacent pit.");
else
You("dig a pit in the %s.", surface_type);
if (shopdoor)
pay_for_damage("ruin", FALSE);
else
add_damage(x, y, madeby_u ? SHOP_PIT_COST : 0L);
wake_nearby();
} else if (!madeby_obj && canseemon(madeby)) {
pline("%s digs a pit in the %s.", Monnam(madeby), surface_type);
} else if (cansee(x, y) && Verbose(0, digactualhole1)) {
pline("A pit appears in the %s.", surface_type);
}
/* in case we're digging down while encased in solid rock
which is blocking levitation or flight */
switch_terrain();
if (Levitation || Flying)
wont_fall = TRUE;
if (at_u) {
if (!wont_fall) {
set_utrap(rn1(4, 2), TT_PIT);
gv.vision_full_recalc = 1; /* vision limits change */
} else
reset_utrap(TRUE);
if (oldobjs != newobjs) /* something unearthed */
(void) pickup(1); /* detects pit */
} else if (mtmp) {
if (is_flyer(mtmp->data) || is_floater(mtmp->data)) {
if (canseemon(mtmp))
pline("%s %s over the pit.", Monnam(mtmp),
(is_flyer(mtmp->data)) ? "flies" : "floats");
} else if (mtmp != madeby)
(void) mintrap(mtmp, NO_TRAP_FLAGS);
}
} else { /* was TRAPDOOR now a HOLE*/
if (madeby_u)
You("dig a hole through the %s.", surface_type);
else if (!madeby_obj && canseemon(madeby))
pline("%s digs a hole through the %s.", Monnam(madeby),
surface_type);
else if (cansee(x, y) && Verbose(0, digactualhole2))
pline("A hole appears in the %s.", surface_type);
if (at_u) {
/* in case we're digging down while encased in solid rock
which is blocking levitation or flight */
switch_terrain();
if (Levitation || Flying)
wont_fall = TRUE;
/* check for leashed pet that can't fall right now */
if (!u.ustuck && !wont_fall && !next_to_u()) {
You("are jerked back by your pet!");
wont_fall = TRUE;
}
/* Floor objects get a chance of falling down. The case where
* the hero does NOT fall down is treated here. The case
* where the hero does fall down is treated in goto_level().
*/
if (u.ustuck || wont_fall) {
if (newobjs)
impact_drop((struct obj *) 0, x, y, 0);
if (oldobjs != newobjs)
(void) pickup(1);
if (shopdoor && madeby_u)
pay_for_damage("ruin", FALSE);
} else {
d_level newlevel;
if (*u.ushops && madeby_u)
shopdig(1); /* shk might snatch pack */
/* handle earlier damage, eg breaking wand of digging */
else if (!madeby_u)
pay_for_damage("dig into", TRUE);
You("fall through...");
/* Earlier checks must ensure that the destination
* level exists and is in the present dungeon.
*/
newlevel.dnum = u.uz.dnum;
newlevel.dlevel = u.uz.dlevel + 1;
goto_level(&newlevel, FALSE, TRUE, FALSE);
/* messages for arriving in special rooms */
spoteffects(FALSE);
}
} else {
if (shopdoor && madeby_u)
pay_for_damage("ruin", FALSE);
if (newobjs)
impact_drop((struct obj *) 0, x, y, 0);
if (mtmp) {
/*[don't we need special sokoban handling here?]*/
if (!grounded(mtmp->data)
|| (mtmp->wormno && count_wsegs(mtmp) > 5)
|| mtmp->data->msize >= MZ_HUGE)
return;
if (mtmp == u.ustuck) /* probably a vortex */
return; /* temporary? kludge */
if (teleport_pet(mtmp, FALSE)) {
d_level tolevel;
if (Is_stronghold(&u.uz)) {
assign_level(&tolevel, &valley_level);
} else if (Is_botlevel(&u.uz)) {
if (canseemon(mtmp))
pline("%s avoids the trap.", Monnam(mtmp));
return;
} else {
get_level(&tolevel, depth(&u.uz) + 1);
}
if (mtmp->isshk)
make_angry_shk(mtmp, 0, 0);
migrate_to_level(mtmp, ledger_no(&tolevel),
MIGR_RANDOM, (coord *) 0);
}
}
}
}
}
DISABLE_WARNING_FORMAT_NONLITERAL
/*
* Called from dighole(), but also from do_break_wand()
* in apply.c.
*/
void
liquid_flow(coordxy x, coordxy y, schar typ, struct trap *ttmp,
const char *fillmsg)
{
struct obj *objchain;
struct monst *mon;
boolean u_spot = u_at(x, y);
if (ttmp)
(void) delfloortrap(ttmp);
/* if any objects were frozen here, they're released now */
unearth_objs(x, y);
if (fillmsg)
pline(fillmsg, hliquid(typ == LAVAPOOL ? "lava" : "water"));
/* handle object damage before hero damage; affects potential bones */
if ((objchain = gl.level.objects[x][y]) != 0) {
if (typ == LAVAPOOL)
fire_damage_chain(objchain, TRUE, TRUE, x, y);
else
water_damage_chain(objchain, TRUE);
}
/* damage to the hero */
if (u_spot) {
(void) pooleffects(FALSE);
} else if ((mon = m_at(x, y)) != 0) {
(void) minliquid(mon);
}
}
RESTORE_WARNING_FORMAT_NONLITERAL
/* return TRUE if digging succeeded, FALSE otherwise */
boolean
dighole(boolean pit_only, boolean by_magic, coord *cc)
{
register struct trap *ttmp;
struct rm *lev;
struct obj *boulder_here;
schar typ, old_typ;
coordxy dig_x, dig_y;
boolean nohole, retval = FALSE;
if (!cc) {
dig_x = u.ux;
dig_y = u.uy;
} else {
dig_x = cc->x;
dig_y = cc->y;
if (!isok(dig_x, dig_y))
return FALSE;
}
ttmp = t_at(dig_x, dig_y);
lev = &levl[dig_x][dig_y];
nohole = (!Can_dig_down(&u.uz) && !lev->candig);
old_typ = lev->typ;
if ((ttmp && (undestroyable_trap(ttmp->ttyp) || nohole))
|| (IS_ROCK(old_typ) && old_typ != SDOOR
&& (lev->wall_info & W_NONDIGGABLE) != 0)) {
pline_The("%s %shere is too hard to dig in.", surface(dig_x, dig_y),
(dig_x != u.ux || dig_y != u.uy) ? "t" : "");
} else if (is_pool_or_lava(dig_x, dig_y)) {
pline_The("%s sloshes furiously for a moment, then subsides.",
hliquid(is_lava(dig_x, dig_y) ? "lava" : "water"));
wake_nearby(); /* splashing */
} else if (old_typ == DRAWBRIDGE_DOWN
|| (is_drawbridge_wall(dig_x, dig_y) >= 0)) {
/* drawbridge_down is the platform crossing the moat when the
bridge is extended; drawbridge_wall is the open "doorway" or
closed "door" where the portcullis/mechanism is located */
if (pit_only) {
pline_The("drawbridge seems too hard to dig through.");
} else {
coordxy x = dig_x, y = dig_y;
/* if under the portcullis, the bridge is adjacent */
(void) find_drawbridge(&x, &y);
destroy_drawbridge(x, y);
retval = TRUE;
}
} else if ((boulder_here = sobj_at(BOULDER, dig_x, dig_y)) != 0) {
if (ttmp && is_pit(ttmp->ttyp)
&& rn2(2)) {
pline_The("boulder settles into the %spit.",
(dig_x != u.ux || dig_y != u.uy) ? "adjacent " : "");
ttmp->ttyp = PIT; /* crush spikes */
} else {
/*
* digging makes a hole, but the boulder immediately
* fills it. Final outcome: no hole, no boulder.
*/
Soundeffect(se_kadoom_boulder_falls_in, 60);
pline("KADOOM! The boulder falls in!");
wake_nearby();
(void) delfloortrap(ttmp);
}
delobj(boulder_here);
} else if (IS_GRAVE(old_typ)) {
digactualhole(dig_x, dig_y, BY_YOU, PIT);
dig_up_grave(cc);
retval = TRUE;
} else if (old_typ == DRAWBRIDGE_UP) {
/* must be floor or ice, other cases handled above */
/* dig "pit" and let fluid flow in (if possible) */
typ = fillholetyp(dig_x, dig_y, FALSE);
if (typ == ROOM) {
/*
* We can't dig a hole here since that will destroy
* the drawbridge. The following is a cop-out. --dlc
*/
pline_The("%s %shere is too hard to dig in.",
surface(dig_x, dig_y),
(dig_x != u.ux || dig_y != u.uy) ? "t" : "");
} else {
lev->drawbridgemask &= ~DB_UNDER;
lev->drawbridgemask |= (typ == LAVAPOOL) ? DB_LAVA : DB_MOAT;
liquid_flow(dig_x, dig_y, typ, ttmp,
"As you dig, the hole fills with %s!");
retval = TRUE;
}
/* the following two are here for the wand of digging */
} else if (IS_THRONE(old_typ)) {
pline_The("throne is too hard to break apart.");
} else if (IS_ALTAR(old_typ)) {
pline_The("altar is too hard to break apart.");
} else {
typ = fillholetyp(dig_x, dig_y, FALSE);
lev->flags = 0;
if (typ != ROOM) {
if (!furniture_handled((int) dig_x, (int) dig_y, TRUE)) {
lev->typ = typ;
liquid_flow(dig_x, dig_y, typ, ttmp,
"As you dig, the hole fills with %s!");
}
retval = TRUE;
} else {
/* magical digging disarms settable traps */
if (by_magic && ttmp
&& (ttmp->ttyp == LANDMINE || ttmp->ttyp == BEAR_TRAP)) {
int otyp = (ttmp->ttyp == LANDMINE) ? LAND_MINE : BEARTRAP;
/* convert trap into buried object (deletes trap) */
cnv_trap_obj(otyp, 1, ttmp, TRUE);
}
/* finally we get to make a hole */
if (nohole || pit_only)
digactualhole(dig_x, dig_y, BY_YOU, PIT);
else
digactualhole(dig_x, dig_y, BY_YOU, HOLE);
retval = TRUE;
}
}
spot_checks(dig_x, dig_y, old_typ);
return retval;
}
static void
dig_up_grave(coord *cc)
{
struct obj *otmp;
int what_happens;
coordxy dig_x, dig_y;
if (!cc) {
dig_x = u.ux;
dig_y = u.uy;
} else {
dig_x = cc->x;
dig_y = cc->y;
if (!isok(dig_x, dig_y))
return;
}
/* Grave-robbing is frowned upon... */
exercise(A_WIS, FALSE);
if (Role_if(PM_ARCHEOLOGIST)) {
adjalign(-sgn(u.ualign.type) * 3);
You_feel("like a despicable grave-robber!");
} else if (Role_if(PM_SAMURAI)) {
adjalign(-sgn(u.ualign.type));
You("disturb the honorable dead!");
} else if (u.ualign.type == A_LAWFUL) {
if (u.ualign.record > -10)
adjalign(-1);
You("have violated the sanctity of this grave!");
}
/* -1: force default case for empty grave */
what_happens = levl[dig_x][dig_y].emptygrave ? -1 : rn2(5);
switch (what_happens) {
case 0:
case 1:
You("unearth a corpse.");
if ((otmp = mk_tt_object(CORPSE, dig_x, dig_y)) != 0)
otmp->age -= (TAINT_AGE + 1); /* this is an *OLD* corpse */
break;
case 2:
if (!Blind)
pline("%s!", Hallucination ? "Dude! The living dead"
: "The grave's owner is very upset");
(void) makemon(mkclass(S_ZOMBIE, 0), dig_x, dig_y, MM_NOMSG);
break;
case 3:
if (!Blind)
pline("%s!", Hallucination ? "I want my mummy"
: "You've disturbed a tomb");
(void) makemon(mkclass(S_MUMMY, 0), dig_x, dig_y, MM_NOMSG);
break;
default:
/* No corpse */
pline_The("grave is unoccupied. Strange...");
break;
}
levl[dig_x][dig_y].typ = ROOM;
levl[dig_x][dig_y].emptygrave = 0; /* clear 'flags' */
levl[dig_x][dig_y].disturbed = 0; /* clear 'horizontal' */
del_engr_at(dig_x, dig_y);
newsym(dig_x, dig_y);
return;
}
int
use_pick_axe(struct obj *obj)
{
const char *verb;
char *dsp, dirsyms[12], qbuf[BUFSZ];
boolean ispick;
int rx, ry, downok, res = ECMD_OK;
int dir;
/* Check tool */
if (obj != uwep) {
if (wield_tool(obj, "swing")) {
/* we're now wielding it. next turn, apply to dig. */
cmdq_add_ec(CQ_CANNED, doapply);
cmdq_add_key(CQ_CANNED, obj->invlet);
return ECMD_TIME;
}
return ECMD_OK;
}
ispick = is_pick(obj);
verb = ispick ? "dig" : "chop";
if (u.utrap && u.utraptype == TT_WEB) {
pline("%s you can't %s while entangled in a web.",
/* res==0 => no prior message;
res==1 => just got "You now wield a pick-axe." message */
!res ? "Unfortunately," : "But", verb);
return res;