forked from NetHack/NetHack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrap.c
5221 lines (4879 loc) · 175 KB
/
trap.c
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.6 trap.c $NHDT-Date: 1494107206 2017/05/06 21:46:46 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.278 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
extern const char *const destroy_strings[][3]; /* from zap.c */
STATIC_DCL void FDECL(dofiretrap, (struct obj *));
STATIC_DCL void NDECL(domagictrap);
STATIC_DCL boolean FDECL(emergency_disrobe, (boolean *));
STATIC_DCL int FDECL(untrap_prob, (struct trap *));
STATIC_DCL void FDECL(move_into_trap, (struct trap *));
STATIC_DCL int FDECL(try_disarm, (struct trap *, BOOLEAN_P));
STATIC_DCL void FDECL(reward_untrap, (struct trap *, struct monst *));
STATIC_DCL int FDECL(disarm_holdingtrap, (struct trap *));
STATIC_DCL int FDECL(disarm_landmine, (struct trap *));
STATIC_DCL int FDECL(disarm_squeaky_board, (struct trap *));
STATIC_DCL int FDECL(disarm_shooting_trap, (struct trap *, int));
STATIC_DCL int FDECL(try_lift, (struct monst *, struct trap *, int,
BOOLEAN_P));
STATIC_DCL int FDECL(help_monster_out, (struct monst *, struct trap *));
STATIC_DCL boolean FDECL(thitm, (int, struct monst *, struct obj *, int,
BOOLEAN_P));
STATIC_DCL void FDECL(launch_drop_spot, (struct obj *, XCHAR_P, XCHAR_P));
STATIC_DCL int FDECL(mkroll_launch, (struct trap *, XCHAR_P, XCHAR_P,
SHORT_P, long));
STATIC_DCL boolean FDECL(isclearpath, (coord *, int, SCHAR_P, SCHAR_P));
STATIC_DCL char *FDECL(trapnote, (struct trap *, BOOLEAN_P));
#if 0
STATIC_DCL void FDECL(join_adjacent_pits, (struct trap *));
#endif
STATIC_DCL void FDECL(clear_conjoined_pits, (struct trap *));
STATIC_DCL int FDECL(steedintrap, (struct trap *, struct obj *));
STATIC_DCL boolean FDECL(keep_saddle_with_steedcorpse, (unsigned,
struct obj *,
struct obj *));
STATIC_DCL void NDECL(maybe_finish_sokoban);
/* mintrap() should take a flags argument, but for time being we use this */
STATIC_VAR int force_mintrap = 0;
STATIC_VAR const char *const a_your[2] = { "a", "your" };
STATIC_VAR const char *const A_Your[2] = { "A", "Your" };
STATIC_VAR const char tower_of_flame[] = "tower of flame";
STATIC_VAR const char *const A_gush_of_water_hits = "A gush of water hits";
STATIC_VAR const char *const blindgas[6] = { "humid", "odorless",
"pungent", "chilling",
"acrid", "biting" };
/* called when you're hit by fire (dofiretrap,buzz,zapyourself,explode);
returns TRUE if hit on torso */
boolean
burnarmor(victim)
struct monst *victim;
{
struct obj *item;
char buf[BUFSZ];
int mat_idx, oldspe;
boolean hitting_u;
if (!victim)
return 0;
hitting_u = (victim == &youmonst);
/* burning damage may dry wet towel */
item = hitting_u ? carrying(TOWEL) : m_carrying(victim, TOWEL);
while (item) {
if (is_wet_towel(item)) {
oldspe = item->spe;
dry_a_towel(item, rn2(oldspe + 1), TRUE);
if (item->spe != oldspe)
break; /* stop once one towel has been affected */
}
item = item->nobj;
}
#define burn_dmg(obj, descr) erode_obj(obj, descr, ERODE_BURN, EF_GREASE)
while (1) {
switch (rn2(5)) {
case 0:
item = hitting_u ? uarmh : which_armor(victim, W_ARMH);
if (item) {
mat_idx = objects[item->otyp].oc_material;
Sprintf(buf, "%s %s", materialnm[mat_idx],
helm_simple_name(item));
}
if (!burn_dmg(item, item ? buf : "helmet"))
continue;
break;
case 1:
item = hitting_u ? uarmc : which_armor(victim, W_ARMC);
if (item) {
(void) burn_dmg(item, cloak_simple_name(item));
return TRUE;
}
item = hitting_u ? uarm : which_armor(victim, W_ARM);
if (item) {
(void) burn_dmg(item, xname(item));
return TRUE;
}
item = hitting_u ? uarmu : which_armor(victim, W_ARMU);
if (item)
(void) burn_dmg(item, "shirt");
return TRUE;
case 2:
item = hitting_u ? uarms : which_armor(victim, W_ARMS);
if (!burn_dmg(item, "wooden shield"))
continue;
break;
case 3:
item = hitting_u ? uarmg : which_armor(victim, W_ARMG);
if (!burn_dmg(item, "gloves"))
continue;
break;
case 4:
item = hitting_u ? uarmf : which_armor(victim, W_ARMF);
if (!burn_dmg(item, "boots"))
continue;
break;
}
break; /* Out of while loop */
}
#undef burn_dmg
return FALSE;
}
/* Generic erode-item function.
* "ostr", if non-null, is an alternate string to print instead of the
* object's name.
* "type" is an ERODE_* value for the erosion type
* "flags" is an or-ed list of EF_* flags
*
* Returns an erosion return value (ER_*)
*/
int
erode_obj(otmp, ostr, type, ef_flags)
register struct obj *otmp;
const char *ostr;
int type;
int ef_flags;
{
static NEARDATA const char
*const action[] = { "smoulder", "rust", "rot", "corrode" },
*const msg[] = { "burnt", "rusted", "rotten", "corroded" },
*const bythe[] = { "heat", "oxidation", "decay", "corrosion" };
boolean vulnerable = FALSE, is_primary = TRUE,
check_grease = (ef_flags & EF_GREASE) ? TRUE : FALSE,
print = (ef_flags & EF_VERBOSE) ? TRUE : FALSE,
uvictim, vismon, visobj;
int erosion, cost_type;
struct monst *victim;
if (!otmp)
return ER_NOTHING;
victim = carried(otmp) ? &youmonst : mcarried(otmp) ? otmp->ocarry : NULL;
uvictim = (victim == &youmonst);
vismon = victim && (victim != &youmonst) && canseemon(victim);
/* Is bhitpos correct here? Ugh. */
visobj = !victim && cansee(bhitpos.x, bhitpos.y);
switch (type) {
case ERODE_BURN:
vulnerable = is_flammable(otmp);
check_grease = FALSE;
cost_type = COST_BURN;
break;
case ERODE_RUST:
vulnerable = is_rustprone(otmp);
cost_type = COST_RUST;
break;
case ERODE_ROT:
vulnerable = is_rottable(otmp);
check_grease = FALSE;
is_primary = FALSE;
cost_type = COST_ROT;
break;
case ERODE_CORRODE:
vulnerable = is_corrodeable(otmp);
is_primary = FALSE;
cost_type = COST_CORRODE;
break;
default:
impossible("Invalid erosion type in erode_obj");
return ER_NOTHING;
}
erosion = is_primary ? otmp->oeroded : otmp->oeroded2;
if (!ostr)
ostr = cxname(otmp);
/* 'visobj' messages insert "the"; probably ought to switch to the() */
if (visobj && !(uvictim || vismon) && !strncmpi(ostr, "the ", 4))
ostr += 4;
if (check_grease && otmp->greased) {
grease_protect(otmp, ostr, victim);
return ER_GREASED;
} else if (!erosion_matters(otmp)) {
return ER_NOTHING;
} else if (!vulnerable || (otmp->oerodeproof && otmp->rknown)) {
if (flags.verbose && print && (uvictim || vismon))
pline("%s %s %s not affected by %s.",
uvictim ? "Your" : s_suffix(Monnam(victim)),
ostr, vtense(ostr, "are"), bythe[type]);
return ER_NOTHING;
} else if (otmp->oerodeproof || (otmp->blessed && !rnl(4))) {
if (flags.verbose && (print || otmp->oerodeproof)
&& (uvictim || vismon || visobj))
pline("Somehow, %s %s %s not affected by the %s.",
uvictim ? "your"
: !vismon ? "the" /* visobj */
: s_suffix(mon_nam(victim)),
ostr, vtense(ostr, "are"), bythe[type]);
/* We assume here that if the object is protected because it
* is blessed, it still shows some minor signs of wear, and
* the hero can distinguish this from an object that is
* actually proof against damage.
*/
if (otmp->oerodeproof) {
otmp->rknown = TRUE;
if (victim == &youmonst)
update_inventory();
}
return ER_NOTHING;
} else if (erosion < MAX_ERODE) {
const char *adverb = (erosion + 1 == MAX_ERODE)
? " completely"
: erosion ? " further" : "";
if (uvictim || vismon || visobj)
pline("%s %s %s%s!",
uvictim ? "Your"
: !vismon ? "The" /* visobj */
: s_suffix(Monnam(victim)),
ostr, vtense(ostr, action[type]), adverb);
if (ef_flags & EF_PAY)
costly_alteration(otmp, cost_type);
if (is_primary)
otmp->oeroded++;
else
otmp->oeroded2++;
if (victim == &youmonst)
update_inventory();
return ER_DAMAGED;
} else if (ef_flags & EF_DESTROY) {
if (uvictim || vismon || visobj)
pline("%s %s %s away!",
uvictim ? "Your"
: !vismon ? "The" /* visobj */
: s_suffix(Monnam(victim)),
ostr, vtense(ostr, action[type]));
if (ef_flags & EF_PAY)
costly_alteration(otmp, cost_type);
setnotworn(otmp);
delobj(otmp);
return ER_DESTROYED;
} else {
if (flags.verbose && print) {
if (uvictim)
Your("%s %s completely %s.",
ostr, vtense(ostr, Blind ? "feel" : "look"), msg[type]);
else if (vismon || visobj)
pline("%s %s %s completely %s.",
!vismon ? "The" : s_suffix(Monnam(victim)),
ostr, vtense(ostr, "look"), msg[type]);
}
return ER_NOTHING;
}
}
/* Protect an item from erosion with grease. Returns TRUE if the grease
* wears off.
*/
boolean
grease_protect(otmp, ostr, victim)
register struct obj *otmp;
const char *ostr;
struct monst *victim;
{
static const char txt[] = "protected by the layer of grease!";
boolean vismon = victim && (victim != &youmonst) && canseemon(victim);
if (ostr) {
if (victim == &youmonst)
Your("%s %s %s", ostr, vtense(ostr, "are"), txt);
else if (vismon)
pline("%s's %s %s %s", Monnam(victim),
ostr, vtense(ostr, "are"), txt);
} else if (victim == &youmonst || vismon) {
pline("%s %s", Yobjnam2(otmp, "are"), txt);
}
if (!rn2(2)) {
otmp->greased = 0;
if (carried(otmp)) {
pline_The("grease dissolves.");
update_inventory();
}
return TRUE;
}
return FALSE;
}
struct trap *
maketrap(x, y, typ)
int x, y, typ;
{
static union vlaunchinfo zero_vl;
boolean oldplace;
struct trap *ttmp;
struct rm *lev = &levl[x][y];
if ((ttmp = t_at(x, y)) != 0) {
if (ttmp->ttyp == MAGIC_PORTAL || ttmp->ttyp == VIBRATING_SQUARE)
return (struct trap *) 0;
oldplace = TRUE;
if (u.utrap && x == u.ux && y == u.uy
&& ((u.utraptype == TT_BEARTRAP && typ != BEAR_TRAP)
|| (u.utraptype == TT_WEB && typ != WEB)
|| (u.utraptype == TT_PIT && typ != PIT
&& typ != SPIKED_PIT)))
u.utrap = 0;
/* old <tx,ty> remain valid */
} else if (IS_FURNITURE(lev->typ)
&& (!IS_GRAVE(lev->typ) || (typ != PIT && typ != HOLE))) {
/* no trap on top of furniture (caller usually screens the
location to inhibit this, but wizard mode wishing doesn't) */
return (struct trap *) 0;
} else {
oldplace = FALSE;
ttmp = newtrap();
(void) memset((genericptr_t)ttmp, 0, sizeof(struct trap));
ttmp->ntrap = 0;
ttmp->tx = x;
ttmp->ty = y;
}
/* [re-]initialize all fields except ntrap (handled below) and <tx,ty> */
ttmp->vl = zero_vl;
ttmp->launch.x = ttmp->launch.y = -1; /* force error if used before set */
ttmp->dst.dnum = ttmp->dst.dlevel = -1;
ttmp->madeby_u = 0;
ttmp->once = 0;
ttmp->tseen = (typ == HOLE); /* hide non-holes */
ttmp->ttyp = typ;
switch (typ) {
case SQKY_BOARD: {
int tavail[12], tpick[12], tcnt = 0, k;
struct trap *t;
for (k = 0; k < 12; ++k)
tavail[k] = tpick[k] = 0;
for (t = ftrap; t; t = t->ntrap)
if (t->ttyp == SQKY_BOARD && t != ttmp)
tavail[t->tnote] = 1;
/* now populate tpick[] with the available indices */
for (k = 0; k < 12; ++k)
if (tavail[k] == 0)
tpick[tcnt++] = k;
/* choose an unused note; if all are in use, pick a random one */
ttmp->tnote = (short) ((tcnt > 0) ? tpick[rn2(tcnt)] : rn2(12));
break;
}
case STATUE_TRAP: { /* create a "living" statue */
struct monst *mtmp;
struct obj *otmp, *statue;
struct permonst *mptr;
int trycount = 10;
do { /* avoid ultimately hostile co-aligned unicorn */
mptr = &mons[rndmonnum()];
} while (--trycount > 0 && is_unicorn(mptr)
&& sgn(u.ualign.type) == sgn(mptr->maligntyp));
statue = mkcorpstat(STATUE, (struct monst *) 0, mptr, x, y,
CORPSTAT_NONE);
mtmp = makemon(&mons[statue->corpsenm], 0, 0, MM_NOCOUNTBIRTH);
if (!mtmp)
break; /* should never happen */
while (mtmp->minvent) {
otmp = mtmp->minvent;
otmp->owornmask = 0;
obj_extract_self(otmp);
(void) add_to_container(statue, otmp);
}
statue->owt = weight(statue);
mongone(mtmp);
break;
}
case ROLLING_BOULDER_TRAP: /* boulder will roll towards trigger */
(void) mkroll_launch(ttmp, x, y, BOULDER, 1L);
break;
case PIT:
case SPIKED_PIT:
ttmp->conjoined = 0;
/*FALLTHRU*/
case HOLE:
case TRAPDOOR:
if (*in_rooms(x, y, SHOPBASE)
&& (typ == HOLE || typ == TRAPDOOR
|| IS_DOOR(lev->typ) || IS_WALL(lev->typ)))
add_damage(x, y, /* schedule repair */
((IS_DOOR(lev->typ) || IS_WALL(lev->typ))
&& !context.mon_moving)
? 200L
: 0L);
lev->doormask = 0; /* subsumes altarmask, icedpool... */
if (IS_ROOM(lev->typ)) /* && !IS_AIR(lev->typ) */
lev->typ = ROOM;
/*
* some cases which can happen when digging
* down while phazing thru solid areas
*/
else if (lev->typ == STONE || lev->typ == SCORR)
lev->typ = CORR;
else if (IS_WALL(lev->typ) || lev->typ == SDOOR)
lev->typ = level.flags.is_maze_lev
? ROOM
: level.flags.is_cavernous_lev ? CORR : DOOR;
unearth_objs(x, y);
break;
}
if (!oldplace) {
ttmp->ntrap = ftrap;
ftrap = ttmp;
} else {
/* oldplace;
it shouldn't be possible to override a sokoban pit or hole
with some other trap, but we'll check just to be safe */
if (Sokoban)
maybe_finish_sokoban();
}
return ttmp;
}
void
fall_through(td)
boolean td; /* td == TRUE : trap door or hole */
{
d_level dtmp;
char msgbuf[BUFSZ];
const char *dont_fall = 0;
int newlevel, bottom;
/* we'll fall even while levitating in Sokoban; otherwise, if we
won't fall and won't be told that we aren't falling, give up now */
if (Blind && Levitation && !Sokoban)
return;
bottom = dunlevs_in_dungeon(&u.uz);
/* when in the upper half of the quest, don't fall past the
middle "quest locate" level if hero hasn't been there yet */
if (In_quest(&u.uz)) {
int qlocate_depth = qlocate_level.dlevel;
/* deepest reached < qlocate implies current < qlocate */
if (dunlev_reached(&u.uz) < qlocate_depth)
bottom = qlocate_depth; /* early cut-off */
}
newlevel = dunlev(&u.uz); /* current level */
do {
newlevel++;
} while (!rn2(4) && newlevel < bottom);
if (td) {
struct trap *t = t_at(u.ux, u.uy);
feeltrap(t);
if (!Sokoban) {
if (t->ttyp == TRAPDOOR)
pline("A trap door opens up under you!");
else
pline("There's a gaping hole under you!");
}
} else
pline_The("%s opens up under you!", surface(u.ux, u.uy));
if (Sokoban && Can_fall_thru(&u.uz))
; /* KMH -- You can't escape the Sokoban level traps */
else if (Levitation || u.ustuck
|| (!Can_fall_thru(&u.uz) && !levl[u.ux][u.uy].candig) || Flying
|| is_clinger(youmonst.data)
|| (Inhell && !u.uevent.invoked && newlevel == bottom)) {
dont_fall = "don't fall in.";
} else if (youmonst.data->msize >= MZ_HUGE) {
dont_fall = "don't fit through.";
} else if (!next_to_u()) {
dont_fall = "are jerked back by your pet!";
}
if (dont_fall) {
You1(dont_fall);
/* hero didn't fall through, but any objects here might */
impact_drop((struct obj *) 0, u.ux, u.uy, 0);
if (!td) {
display_nhwindow(WIN_MESSAGE, FALSE);
pline_The("opening under you closes up.");
}
return;
}
if (*u.ushops)
shopdig(1);
if (Is_stronghold(&u.uz)) {
find_hell(&dtmp);
} else {
int dist = newlevel - dunlev(&u.uz);
dtmp.dnum = u.uz.dnum;
dtmp.dlevel = newlevel;
if (dist > 1)
You("fall down a %s%sshaft!", dist > 3 ? "very " : "",
dist > 2 ? "deep " : "");
}
if (!td)
Sprintf(msgbuf, "The hole in the %s above you closes up.",
ceiling(u.ux, u.uy));
schedule_goto(&dtmp, FALSE, TRUE, 0, (char *) 0,
!td ? msgbuf : (char *) 0);
}
/*
* Animate the given statue. May have been via shatter attempt, trap,
* or stone to flesh spell. Return a monster if successfully animated.
* If the monster is animated, the object is deleted. If fail_reason
* is non-null, then fill in the reason for failure (or success).
*
* The cause of animation is:
*
* ANIMATE_NORMAL - hero "finds" the monster
* ANIMATE_SHATTER - hero tries to destroy the statue
* ANIMATE_SPELL - stone to flesh spell hits the statue
*
* Perhaps x, y is not needed if we can use get_obj_location() to find
* the statue's location... ???
*
* Sequencing matters:
* create monster; if it fails, give up with statue intact;
* give "statue comes to life" message;
* if statue belongs to shop, have shk give "you owe" message;
* transfer statue contents to monster (after stolen_value());
* delete statue.
* [This ordering means that if the statue ends up wearing a cloak of
* invisibility or a mummy wrapping, the visibility checks might be
* wrong, but to avoid that we'd have to clone the statue contents
* first in order to give them to the monster before checking their
* shop status--it's not worth the hassle.]
*/
struct monst *
animate_statue(statue, x, y, cause, fail_reason)
struct obj *statue;
xchar x, y;
int cause;
int *fail_reason;
{
int mnum = statue->corpsenm;
struct permonst *mptr = &mons[mnum];
struct monst *mon = 0, *shkp;
struct obj *item;
coord cc;
boolean historic = (Role_if(PM_ARCHEOLOGIST)
&& (statue->spe & STATUE_HISTORIC) != 0),
golem_xform = FALSE, use_saved_traits;
const char *comes_to_life;
char statuename[BUFSZ], tmpbuf[BUFSZ];
static const char historic_statue_is_gone[] =
"that the historic statue is now gone";
if (cant_revive(&mnum, TRUE, statue)) {
/* mnum has changed; we won't be animating this statue as itself */
if (mnum != PM_DOPPELGANGER)
mptr = &mons[mnum];
use_saved_traits = FALSE;
} else if (is_golem(mptr) && cause == ANIMATE_SPELL) {
/* statue of any golem hit by stone-to-flesh becomes flesh golem */
golem_xform = (mptr != &mons[PM_FLESH_GOLEM]);
mnum = PM_FLESH_GOLEM;
mptr = &mons[PM_FLESH_GOLEM];
use_saved_traits = (has_omonst(statue) && !golem_xform);
} else {
use_saved_traits = has_omonst(statue);
}
if (use_saved_traits) {
/* restore a petrified monster */
cc.x = x, cc.y = y;
mon = montraits(statue, &cc);
if (mon && mon->mtame && !mon->isminion)
wary_dog(mon, TRUE);
} else {
/* statues of unique monsters from bones or wishing end
up here (cant_revive() sets mnum to be doppelganger;
mptr reflects the original form for use by newcham()) */
if ((mnum == PM_DOPPELGANGER && mptr != &mons[PM_DOPPELGANGER])
/* block quest guards from other roles */
|| (mptr->msound == MS_GUARDIAN
&& quest_info(MS_GUARDIAN) != mnum)) {
mon = makemon(&mons[PM_DOPPELGANGER], x, y,
NO_MINVENT | MM_NOCOUNTBIRTH | MM_ADJACENTOK);
/* if hero has protection from shape changers, cham field will
be NON_PM; otherwise, set form to match the statue */
if (mon && mon->cham >= LOW_PM)
(void) newcham(mon, mptr, FALSE, FALSE);
} else
mon = makemon(mptr, x, y, (cause == ANIMATE_SPELL)
? (NO_MINVENT | MM_ADJACENTOK)
: NO_MINVENT);
}
if (!mon) {
if (fail_reason)
*fail_reason = unique_corpstat(&mons[statue->corpsenm])
? AS_MON_IS_UNIQUE
: AS_NO_MON;
return (struct monst *) 0;
}
/* a non-montraits() statue might specify gender */
if (statue->spe & STATUE_MALE)
mon->female = FALSE;
else if (statue->spe & STATUE_FEMALE)
mon->female = TRUE;
/* if statue has been named, give same name to the monster */
if (has_oname(statue) && !unique_corpstat(mon->data))
mon = christen_monst(mon, ONAME(statue));
/* mimic statue becomes seen mimic; other hiders won't be hidden */
if (mon->m_ap_type)
seemimic(mon);
else
mon->mundetected = FALSE;
mon->msleeping = 0;
if (cause == ANIMATE_NORMAL || cause == ANIMATE_SHATTER) {
/* trap always releases hostile monster */
mon->mtame = 0; /* (might be petrified pet tossed onto trap) */
mon->mpeaceful = 0;
set_malign(mon);
}
comes_to_life = !canspotmon(mon)
? "disappears"
: golem_xform
? "turns into flesh"
: (nonliving(mon->data) || is_vampshifter(mon))
? "moves"
: "comes to life";
if ((x == u.ux && y == u.uy) || cause == ANIMATE_SPELL) {
/* "the|your|Manlobbi's statue [of a wombat]" */
shkp = shop_keeper(*in_rooms(mon->mx, mon->my, SHOPBASE));
Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue),
(cause == ANIMATE_SPELL
/* avoid "of a shopkeeper" if it's Manlobbi himself
(if carried, it can't be unpaid--hence won't be
described as "Manlobbi's statue"--because there
wasn't any living shk when statue was picked up) */
&& (mon != shkp || carried(statue)))
? xname(statue)
: "statue");
pline("%s %s!", upstart(statuename), comes_to_life);
} else if (Hallucination) { /* They don't know it's a statue */
pline_The("%s suddenly seems more animated.", rndmonnam((char *) 0));
} else if (cause == ANIMATE_SHATTER) {
if (cansee(x, y))
Sprintf(statuename, "%s%s", shk_your(tmpbuf, statue),
xname(statue));
else
Strcpy(statuename, "a statue");
pline("Instead of shattering, %s suddenly %s!", statuename,
comes_to_life);
} else { /* cause == ANIMATE_NORMAL */
You("find %s posing as a statue.",
canspotmon(mon) ? a_monnam(mon) : something);
if (!canspotmon(mon) && Blind)
map_invisible(x, y);
stop_occupation();
}
/* if this isn't caused by a monster using a wand of striking,
there might be consequences for the hero */
if (!context.mon_moving) {
/* if statue is owned by a shop, hero will have to pay for it;
stolen_value gives a message (about debt or use of credit)
which refers to "it" so needs to follow a message describing
the object ("the statue comes to life" one above) */
if (cause != ANIMATE_NORMAL && costly_spot(x, y)
&& (carried(statue) ? statue->unpaid : !statue->no_charge)
&& (shkp = shop_keeper(*in_rooms(x, y, SHOPBASE))) != 0
/* avoid charging for Manlobbi's statue of Manlobbi
if stone-to-flesh is used on petrified shopkeep */
&& mon != shkp)
(void) stolen_value(statue, x, y, (boolean) shkp->mpeaceful,
FALSE);
if (historic) {
You_feel("guilty %s.", historic_statue_is_gone);
adjalign(-1);
}
} else {
if (historic && cansee(x, y))
You_feel("regret %s.", historic_statue_is_gone);
/* no alignment penalty */
}
/* transfer any statue contents to monster's inventory */
while ((item = statue->cobj) != 0) {
obj_extract_self(item);
(void) mpickobj(mon, item);
}
m_dowear(mon, TRUE);
/* in case statue is wielded and hero zaps stone-to-flesh at self */
if (statue->owornmask)
remove_worn_item(statue, TRUE);
/* statue no longer exists */
delobj(statue);
/* avoid hiding under nothing */
if (x == u.ux && y == u.uy && Upolyd && hides_under(youmonst.data)
&& !OBJ_AT(x, y))
u.uundetected = 0;
if (fail_reason)
*fail_reason = AS_OK;
return mon;
}
/*
* You've either stepped onto a statue trap's location or you've triggered a
* statue trap by searching next to it or by trying to break it with a wand
* or pick-axe.
*/
struct monst *
activate_statue_trap(trap, x, y, shatter)
struct trap *trap;
xchar x, y;
boolean shatter;
{
struct monst *mtmp = (struct monst *) 0;
struct obj *otmp = sobj_at(STATUE, x, y);
int fail_reason;
/*
* Try to animate the first valid statue. Stop the loop when we
* actually create something or the failure cause is not because
* the mon was unique.
*/
deltrap(trap);
while (otmp) {
mtmp = animate_statue(otmp, x, y,
shatter ? ANIMATE_SHATTER : ANIMATE_NORMAL,
&fail_reason);
if (mtmp || fail_reason != AS_MON_IS_UNIQUE)
break;
otmp = nxtobj(otmp, STATUE, TRUE);
}
feel_newsym(x, y);
return mtmp;
}
STATIC_OVL boolean
keep_saddle_with_steedcorpse(steed_mid, objchn, saddle)
unsigned steed_mid;
struct obj *objchn, *saddle;
{
if (!saddle)
return FALSE;
while (objchn) {
if (objchn->otyp == CORPSE && has_omonst(objchn)) {
struct monst *mtmp = OMONST(objchn);
if (mtmp->m_id == steed_mid) {
/* move saddle */
xchar x, y;
if (get_obj_location(objchn, &x, &y, 0)) {
obj_extract_self(saddle);
place_object(saddle, x, y);
stackobj(saddle);
}
return TRUE;
}
}
if (Has_contents(objchn)
&& keep_saddle_with_steedcorpse(steed_mid, objchn->cobj, saddle))
return TRUE;
objchn = objchn->nobj;
}
return FALSE;
}
/* monster or you go through and possibly destroy a web.
return TRUE if could go through. */
boolean
mu_maybe_destroy_web(mtmp, domsg, trap)
struct monst *mtmp;
boolean domsg;
struct trap *trap;
{
boolean isyou = (mtmp == &youmonst);
struct permonst *mptr = mtmp->data;
if (amorphous(mptr) || is_whirly(mptr) || flaming(mptr)
|| unsolid(mptr) || mptr == &mons[PM_GELATINOUS_CUBE]) {
xchar x = trap->tx;
xchar y = trap->ty;
if (flaming(mptr) || acidic(mptr)) {
if (domsg) {
if (isyou)
You("%s %s spider web!",
(flaming(mptr)) ? "burn" : "dissolve",
a_your[trap->madeby_u]);
else
pline("%s %s %s spider web!", Monnam(mtmp),
(flaming(mptr)) ? "burns" : "dissolves",
a_your[trap->madeby_u]);
}
deltrap(trap);
newsym(x, y);
return TRUE;
}
if (domsg) {
if (isyou)
You("flow through %s spider web.", a_your[trap->madeby_u]);
else {
pline("%s flows through %s spider web.", Monnam(mtmp),
a_your[trap->madeby_u]);
seetrap(trap);
}
}
return TRUE;
}
return FALSE;
}
void
dotrap(trap, trflags)
register struct trap *trap;
unsigned trflags;
{
register int ttype = trap->ttyp;
register struct obj *otmp;
boolean already_seen = trap->tseen,
forcetrap = (trflags & FORCETRAP) != 0,
webmsgok = (trflags & NOWEBMSG) == 0,
forcebungle = (trflags & FORCEBUNGLE) != 0,
plunged = (trflags & TOOKPLUNGE) != 0,
viasitting = (trflags & VIASITTING) != 0,
adj_pit = conjoined_pits(trap, t_at(u.ux0, u.uy0), TRUE);
int oldumort;
int steed_article = ARTICLE_THE;
nomul(0);
/* KMH -- You can't escape the Sokoban level traps */
if (Sokoban && (ttype == PIT || ttype == SPIKED_PIT
|| ttype == HOLE || ttype == TRAPDOOR)) {
/* The "air currents" message is still appropriate -- even when
* the hero isn't flying or levitating -- because it conveys the
* reason why the player cannot escape the trap with a dexterity
* check, clinging to the ceiling, etc.
*/
pline("Air currents pull you down into %s %s!",
a_your[trap->madeby_u],
defsyms[trap_to_defsym(ttype)].explanation);
/* then proceed to normal trap effect */
} else if (already_seen && !forcetrap) {
if ((Levitation || (Flying && !plunged))
&& (ttype == PIT || ttype == SPIKED_PIT || ttype == HOLE
|| ttype == BEAR_TRAP)) {
You("%s over %s %s.", Levitation ? "float" : "fly",
a_your[trap->madeby_u],
defsyms[trap_to_defsym(ttype)].explanation);
return;
}
if (!Fumbling && ttype != MAGIC_PORTAL && ttype != VIBRATING_SQUARE
&& ttype != ANTI_MAGIC && !forcebungle && !plunged && !adj_pit
&& (!rn2(5) || ((ttype == PIT || ttype == SPIKED_PIT)
&& is_clinger(youmonst.data)))) {
You("escape %s %s.", (ttype == ARROW_TRAP && !trap->madeby_u)
? "an"
: a_your[trap->madeby_u],
defsyms[trap_to_defsym(ttype)].explanation);
return;
}
}
if (u.usteed) {
u.usteed->mtrapseen |= (1 << (ttype - 1));
/* suppress article in various steed messages when using its
name (which won't occur when hallucinating) */
if (has_mname(u.usteed) && !Hallucination)
steed_article = ARTICLE_NONE;
}
switch (ttype) {
case ARROW_TRAP:
if (trap->once && trap->tseen && !rn2(15)) {
You_hear("a loud click!");
deltrap(trap);
newsym(u.ux, u.uy);
break;
}
trap->once = 1;
seetrap(trap);
pline("An arrow shoots out at you!");
otmp = mksobj(ARROW, TRUE, FALSE);
otmp->quan = 1L;
otmp->owt = weight(otmp);
otmp->opoisoned = 0;
if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) { /* nothing */
;
} else if (thitu(8, dmgval(otmp, &youmonst), otmp, "arrow")) {
obfree(otmp, (struct obj *) 0);
} else {
place_object(otmp, u.ux, u.uy);
if (!Blind)
otmp->dknown = 1;
stackobj(otmp);
newsym(u.ux, u.uy);
}
break;
case DART_TRAP:
if (trap->once && trap->tseen && !rn2(15)) {
You_hear("a soft click.");
deltrap(trap);
newsym(u.ux, u.uy);
break;
}
trap->once = 1;
seetrap(trap);
pline("A little dart shoots out at you!");
otmp = mksobj(DART, TRUE, FALSE);
otmp->quan = 1L;
otmp->owt = weight(otmp);
if (!rn2(6))
otmp->opoisoned = 1;
oldumort = u.umortality;
if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) { /* nothing */
;
} else if (thitu(7, dmgval(otmp, &youmonst), otmp, "little dart")) {
if (otmp->opoisoned)
poisoned("dart", A_CON, "little dart",
/* if damage triggered life-saving,
poison is limited to attrib loss */
(u.umortality > oldumort) ? 0 : 10, TRUE);
obfree(otmp, (struct obj *) 0);
} else {
place_object(otmp, u.ux, u.uy);
if (!Blind)
otmp->dknown = 1;
stackobj(otmp);
newsym(u.ux, u.uy);
}
break;
case ROCKTRAP:
if (trap->once && trap->tseen && !rn2(15)) {
pline("A trap door in %s opens, but nothing falls out!",
the(ceiling(u.ux, u.uy)));
deltrap(trap);
newsym(u.ux, u.uy);
} else {
int dmg = d(2, 6); /* should be std ROCK dmg? */
trap->once = 1;
feeltrap(trap);
otmp = mksobj_at(ROCK, u.ux, u.uy, TRUE, FALSE);
otmp->quan = 1L;
otmp->owt = weight(otmp);
pline("A trap door in %s opens and %s falls on your %s!",
the(ceiling(u.ux, u.uy)), an(xname(otmp)), body_part(HEAD));
if (uarmh) {
if (is_metallic(uarmh)) {
pline("Fortunately, you are wearing a hard helmet.");
dmg = 2;
} else if (flags.verbose) {
pline("%s does not protect you.", Yname2(uarmh));
}
}
if (!Blind)
otmp->dknown = 1;
stackobj(otmp);
newsym(u.ux, u.uy); /* map the rock */
losehp(Maybe_Half_Phys(dmg), "falling rock", KILLED_BY_AN);
exercise(A_STR, FALSE);
}
break;
case SQKY_BOARD: /* stepped on a squeaky board */