{{ message }}
Repository navigation
Expand file tree
/
Copy pathdo.c
More file actions
2507 lines (2306 loc) · 88.8 KB
/
Copy pathdo.c
File metadata and controls
2507 lines (2306 loc) · 88.8 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 5.0 do.c $NHDT-Date: 1781973045 2026/06/20 16:30:45 $ $NHDT-Branch: NetHack-5.0 $:$NHDT-Revision: 1.411 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
/* Contains code for 'd', 'D' (drop), '>', '<' (up, down) */
#include "hack.h"
staticfn boolean teleport_sink(void);
staticfn void dosinkring(struct obj *);
staticfn int drop(struct obj *);
staticfn int menudrop_split(struct obj *, long);
staticfn boolean engulfer_digests_food(struct obj *);
staticfn boolean danger_uprops(void);
staticfn int wipeoff(void);
staticfn int menu_drop(int);
staticfn boolean u_stuck_cannot_go(const char *);
staticfn NHFILE *currentlevel_rewrite(void);
staticfn void familiar_level_msg(void);
staticfn void final_level(void);
staticfn void temperature_change_msg(schar);
staticfn boolean better_not_try_to_drop_that(struct obj *);
/* static boolean badspot(coordxy,coordxy); */
/* the #drop command: drop one inventory item */
int
dodrop(void)
{
int result;
if (*u.ushops)
sellobj_state(SELL_DELIBERATE);
result = drop(getobj("drop", any_obj_ok,
GETOBJ_PROMPT | GETOBJ_ALLOWCNT));
if (*u.ushops)
sellobj_state(SELL_NORMAL);
if (result)
reset_occupations();
return result;
}
/* Called when a boulder is dropped, thrown, or pushed. If it ends up
* in a pool, it either fills the pool up or sinks away. In either case,
* it's gone for good... If the destination is not a pool, returns FALSE.
*/
boolean
boulder_hits_pool(
struct obj *otmp, /* the object falling into a pool or water or lava */
coordxy rx, coordxy ry, /* coordinates of the pool */
boolean pushing) /* for a boulder, whether or not it is being pushed */
{
if (!otmp || otmp->otyp != BOULDER) {
impossible("Not a boulder?");
} else if (is_pool_or_lava(rx, ry)) {
boolean lava = is_lava(rx, ry), fills_up;
const char *what = waterbody_name(rx, ry);
schar ltyp = levl[rx][ry].typ;
int chance = rn2(10); /* water: 90%; lava: 10% */
struct monst *mtmp;
/* chance for boulder to fill pool: Plane of Water==0%,
lava 10%, wall of water==50%, other water==90% */
fills_up = Is_waterlevel(&u.uz) ? FALSE
: IS_WATERWALL(ltyp) ? (chance < 5)
: lava ? (chance == 0) : (chance != 0);
if (fills_up) {
struct trap *ttmp = t_at(rx, ry);
if (ltyp == DRAWBRIDGE_UP) {
levl[rx][ry].drawbridgemask &= ~DB_UNDER; /* clear lava */
levl[rx][ry].drawbridgemask |= DB_FLOOR;
} else {
levl[rx][ry].typ = ROOM, levl[rx][ry].flags = 0;
recalc_block_point(rx, ry);
}
/* 5.0: normally DEADMONSTER() is used when traversing the fmon
list--dead monsters usually aren't still at specific map
locations; however, if ice melts causing a giant to drown,
that giant would still be on the map when it drops inventory;
if it was carrying a boulder which now fills the pool, 'mtmp'
will be dead here; killing it again would yield impossible
"dmonsfree: N removed doesn't match N+1 pending" when other
monsters have finished their current turn */
if ((mtmp = m_at(rx, ry)) != 0 && !DEADMONSTER(mtmp)
&& !m_in_air(mtmp))
mondied(mtmp);
if (ttmp)
(void) delfloortrap(ttmp);
bury_objs(rx, ry);
newsym(rx, ry);
if (pushing) {
char whobuf[BUFSZ];
Strcpy(whobuf, "you");
if (u.usteed)
Strcpy(whobuf, y_monnam(u.usteed));
pline("%s %s %s into the %s.", upstart(whobuf),
vtense(whobuf, "push"), the(xname(otmp)), what);
if (flags.verbose && !Blind)
pline("Now you can cross it!");
/* no splashing in this case */
}
}
if (!fills_up || !pushing) { /* splashing occurs */
if (!u.uinwater) {
if (pushing ? !Blind : cansee(rx, ry)) {
There("is a large splash as %s %s the %s.",
the(xname(otmp)), fills_up ? "fills" : "falls into",
what);
} else if (!Deaf) {
if (lava) {
Soundeffect(se_sizzling, 100);
} else {
Soundeffect(se_splash, 100);
}
You_hear("a%s splash.", lava ? " sizzling" : "");
}
wake_nearto(rx, ry, 40);
}
if (fills_up && u.uinwater && distu(rx, ry) == 0) {
set_uinwater(0); /* u.uinwater = 0 */
docrt();
gv.vision_full_recalc = 1;
You("find yourself on dry land again!");
} else if (lava && next2u(rx, ry)) {
int dmg;
You("are hit by molten %s%c",
hliquid("lava"), Fire_resistance ? '.' : '!');
burn_away_slime();
dmg = d((Fire_resistance ? 1 : 3), 6);
losehp(Maybe_Half_Phys(dmg), /* lava damage */
"molten lava", KILLED_BY);
} else if (!fills_up && flags.verbose
&& (pushing ? !Blind : cansee(rx, ry))) {
pline("It sinks without a trace!");
}
}
/* boulder is now gone */
if (pushing)
useupf(otmp, otmp->quan);
else
obfree(otmp, (struct obj *) 0);
return TRUE;
}
return FALSE;
}
/* Used for objects which sometimes do special things when dropped; must be
* called with the object not in any chain. Returns TRUE if the object goes
* away.
*/
boolean
flooreffects(
struct obj *obj, /* the object landing on the floor */
coordxy x, coordxy y, /* map coordinates for spot where it is landing */
const char *verb) /* "fall", "drop", "land", &c */
{
struct trap *t;
struct monst *mtmp;
struct obj *otmp;
coord save_bhitpos;
boolean tseen;
int ttyp = NO_TRAP, res = FALSE;
if (obj->where != OBJ_FREE)
panic("flooreffects: obj not free");
/* make sure things like water_damage() have no pointers to follow */
obj->nobj = obj->nexthere = (struct obj *) 0;
/* erode_obj() (called from water_damage() or lava_damage()) needs
bhitpos, but that was screwing up wand zapping that called us from
rloco(), so we now restore bhitpos before we return */
save_bhitpos = gb.bhitpos;
gb.bhitpos.x = x, gb.bhitpos.y = y;
if (obj->otyp == BOULDER && boulder_hits_pool(obj, x, y, FALSE)) {
res = TRUE;
} else if (obj->otyp == BOULDER && (t = t_at(x, y)) != 0
&& (is_pit(t->ttyp) || is_hole(t->ttyp))) {
ttyp = t->ttyp;
tseen = t->tseen ? TRUE : FALSE;
if (((mtmp = m_at(x, y)) && mtmp->mtrapped)
|| (u.utrap && u_at(x,y))) {
if (*verb && (cansee(x, y) || distu(x, y) == 0))
pline("%s boulder %s into the pit%s.",
Blind ? "A" : "The",
vtense((const char *) 0, verb),
mtmp ? "" : " with you");
if (mtmp) {
if (!passes_walls(mtmp->data) && !throws_rocks(mtmp->data)) {
/* dieroll was rnd(20); 1: maximum chance to hit
since trapped target is a sitting duck */
int damage, dieroll = 1;
/* As of 3.6.2: this was calling hmon() unconditionally
so always credited/blamed the hero but the boulder
might have been thrown by a giant or launched by
a rolling boulder trap triggered by a monster or
dropped by a scroll of earth read by a monster */
if (svc.context.mon_moving) {
/* normally we'd use ohitmon() but it can call
drop_throw() which calls flooreffects() */
damage = dmgval(obj, mtmp);
mtmp->mhp -= damage;
if (DEADMONSTER(mtmp)) {
if (canspotmon(mtmp))
pline("%s is %s!", Monnam(mtmp),
(nonliving(mtmp->data)
|| is_vampshifter(mtmp))
? "destroyed" : "killed");
mondied(mtmp);
}
} else {
(void) hmon(mtmp, obj, HMON_THROWN, dieroll);
}
if (!DEADMONSTER(mtmp) && !is_whirly(mtmp->data))
res = FALSE; /* still alive, boulder still intact */
nhUse(res);
}
mtmp->mtrapped = 0;
} else {
if (!Passes_walls && !throws_rocks(gy.youmonst.data)) {
losehp(Maybe_Half_Phys(rnd(15)),
"squished under a boulder", NO_KILLER_PREFIX);
goto deletedwithboulder;
} else
reset_utrap(TRUE);
}
}
if (*verb) {
if (Blind && u_at(x, y)) {
Soundeffect(se_crashing_boulder, 100);
You_hear("a CRASH! beneath you.");
} else if (!Blind && cansee(x, y)) {
pline_The("boulder %s%s.",
(ttyp == TRAPDOOR && !tseen) ? "triggers and " : "",
(ttyp == TRAPDOOR) ? "plugs a trap door"
: (ttyp == HOLE) ? "plugs a hole"
: "fills a pit");
} else {
Soundeffect(se_boulder_drop, 100);
You_hear("a boulder %s.", verb);
}
}
/*
* Note: trap might have gone away via ((hmon -> killed -> xkilled)
* || mondied) -> mondead -> m_detach -> fill_pit.
*/
deletedwithboulder:
/* creating a pit in ice results in that ice being turned into
floor so we shouldn't need any special ice handing here */
if ((t = t_at(x, y)) != 0) {
(void) delfloortrap(t);
if (u.utrap && u_at(x, y))
reset_utrap(FALSE);
}
useupf(obj, 1L);
bury_objs(x, y);
newsym(x, y);
res = TRUE;
} else if (is_lava(x, y)) {
res = lava_damage(obj, x, y);
} else if (is_pool(x, y)) {
/* Reasonably bulky objects (arbitrary) splash when dropped.
* If you're floating above the water even small things make
* noise. Stuff dropped near fountains always misses */
if ((Blind || (Levitation || Flying)) && !Deaf && u_at(x, y)) {
if (!Underwater) {
if (weight(obj) > WT_SPLASH_THRESHOLD) {
pline("Splash!");
} else if (Levitation || Flying) {
pline("Plop!");
}
}
map_background(x, y, 0);
newsym(x, y);
}
res = water_damage(obj, NULL, FALSE) == ER_DESTROYED;
} else if (u_at(x, y) && (t = t_at(x, y)) != 0
&& (uteetering_at_seen_pit(t) || uescaped_shaft(t))) {
if (is_pit(t->ttyp)) {
if (Blind && !Deaf) {
Soundeffect(se_item_tumble_downwards, 50);
You_hear("%s tumble downwards.", the(xname(obj)));
} else {
pline("%s into %s pit.", Tobjnam(obj, "tumble"),
the_your[t->madeby_u]);
}
} else if (ship_object(obj, x, y, FALSE)) {
/* ship_object will print an appropriate "the item falls
* through the hole" message, so no need to do it here. */
res = TRUE;
}
} else if (obj->globby) {
struct obj *globbyobj = obj; /* allow obj to be nonnull arg */
/* Globby things like puddings might stick together */
while (globbyobj
&& (otmp = obj_nexto_xy(globbyobj, x, y, TRUE)) != 0) {
pudding_merge_message(globbyobj, otmp);
/* intentionally not getting the melded object; obj_meld may set
* obj to null. */
(void) obj_meld(&globbyobj, &otmp);
}
res = (boolean) !globbyobj;
} else if (svc.context.mon_moving && IS_ALTAR(levl[x][y].typ)
&& cansee(x,y)) {
doaltarobj(obj);
} else if (obj->oclass == POTION_CLASS && svl.level.flags.temperature > 0
&& (levl[x][y].typ == ROOM || levl[x][y].typ == CORR)) {
/* Potions are sometimes destroyed when landing on very hot
ground. The basic odds are 50% for nonblessed potions and
30% for blessed potions; if you have handled the object
(i.e. it is or was yours), these odds are adjusted by Luck
(each Luck point affects them by 2%). Artifact potions
would not be affected, if any existed.
Oil is not affected because its boiling point (and flash
point) are higher than that of water. For example, whale
oil, one of the substances traditionally used in oil lamps,
can survive over 100 degrees Centigrade more heat than
water can.*/
if (cansee(x,y)) {
/* unconditional "ground" is safe as this only runs for
room and corridor tiles */
pline("%s up as %s the hot ground.", Tobjnam(obj, "heat"),
is_plural(obj) ? "they hit" : "it hits");
}
int survival_chance = obj->blessed ? 70 : 50;
if (obj->invlet)
survival_chance += Luck * 2;
if (obj->otyp == POT_OIL)
survival_chance = 100;
if (!obj_resists(obj, survival_chance, 100)) {
if (cansee(x,y)) {
pline("%s from the heat!",
is_plural(obj) ? "They shatter" : "It shatters");
} else {
You_hear("a shattering noise.");
}
breakobj(obj, x, y, FALSE, FALSE);
res = TRUE;
}
}
gb.bhitpos = save_bhitpos;
return res;
}
/* obj is an object dropped on an altar */
void
doaltarobj(struct obj *obj)
{
if (Blind)
return;
if (obj->oclass != COIN_CLASS) {
/* KMH, conduct */
if (!svc.context.mon_moving && !u.uconduct.gnostic++)
livelog_printf(LL_CONDUCT,
"eschewed atheism, by dropping %s on an altar",
doname(obj));
} else {
/* coins don't have bless/curse status */
obj->blessed = obj->cursed = 0;
}
if (obj->blessed || obj->cursed) {
There("is %s flash as %s %s the altar.",
an(hcolor(obj->blessed ? NH_AMBER : NH_BLACK)), doname(obj),
otense(obj, "hit"));
if (!Hallucination)
obj->bknown = 1; /* ok to bypass set_bknown() */
} else {
pline("%s %s on the altar.", Doname2(obj), otense(obj, "land"));
if (obj->oclass != COIN_CLASS)
obj->bknown = 1; /* ok to bypass set_bknown() */
}
}
/* If obj is neither formally identified nor informally called something
* already, prompt the player to call its object type. */
void
trycall(struct obj *obj)
{
if (!objects[obj->otyp].oc_name_known && !objects[obj->otyp].oc_uname)
docall(obj);
}
/* Transforms the sink at the player's position into
a fountain, throne, altar or grave. */
void
polymorph_sink(void)
{
uchar sym = S_sink;
boolean sinklooted;
int algn;
if (levl[u.ux][u.uy].typ != SINK)
return;
sinklooted = levl[u.ux][u.uy].looted != 0;
/* svl.level.flags.nsinks--; // set_levltyp() will update this */
levl[u.ux][u.uy].flags = 0;
switch (rn2(4)) {
default:
case 0:
sym = S_fountain;
set_levltyp(u.ux, u.uy, FOUNTAIN); /* updates level.flags.nfountains */
levl[u.ux][u.uy].blessedftn = 0;
if (sinklooted)
SET_FOUNTAIN_LOOTED(u.ux, u.uy);
break;
case 1:
sym = S_throne;
set_levltyp(u.ux, u.uy, THRONE);
if (sinklooted)
levl[u.ux][u.uy].looted = T_LOOTED;
break;
case 2:
sym = S_altar;
set_levltyp(u.ux, u.uy, ALTAR);
/* 3.6.3: this used to pass 'rn2(A_LAWFUL + 2) - 1' to
Align2amask() but that evaluates its argument more than once */
algn = rn2(3) - 1; /* -1 (A_Cha) or 0 (A_Neu) or +1 (A_Law) */
levl[u.ux][u.uy].altarmask = ((Inhell && rn2(3)) ? AM_NONE
: Align2amask(algn));
break;
case 3:
sym = S_room;
set_levltyp(u.ux, u.uy, ROOM);
make_grave(u.ux, u.uy, (char *) 0);
if (levl[u.ux][u.uy].typ == GRAVE)
sym = S_grave;
break;
}
/* give message even if blind; we know we're not levitating,
so can feel the outcome even if we can't directly see it */
if (levl[u.ux][u.uy].typ != ROOM)
pline_The("sink transforms into %s!", an(defsyms[sym].explanation));
else
pline_The("sink vanishes.");
newsym(u.ux, u.uy);
}
/* Teleports the sink at the player's position;
return True if sink teleported. */
staticfn boolean
teleport_sink(void)
{
coordxy cx, cy;
unsigned alreadylooted;
int trycnt = 0;
do {
#if 0 /* this isn't incorrect but it is extremely unlikely that spots
* on the level's edge will be ROOM so picking such wastes tries */
cx = rnd(COLNO - 1); /* 1..COLNO-1 */
cy = rn2(ROWNO); /* 0..ROWNO-1 */
#else /* use this instead */
cx = 1 + rnd((COLNO - 1) - 2); /* 2..COLNO-2 */
cy = 1 + rn2(ROWNO - 2); /* 1..ROWNO-2 */
#endif
if (levl[cx][cy].typ == ROOM
&& !t_at(cx, cy) && !engr_at(cx, cy)
&& (!cansee(cx, cy) || distu(cx, cy) > 3 * 3)) {
/* this ends up having set_levltyp() count all sinks and
fountains on the level twice but that is not a problem */
alreadylooted = levl[u.ux][u.uy].looted;
/* remove old sink */
set_levltyp(u.ux, u.uy, ROOM); /* was SINK so updates nsinks */
levl[u.ux][u.uy].looted = 0;
newsym(u.ux, u.uy);
/* create sink at new position */
set_levltyp(cx, cy, SINK); /* now SINK so also updates nsinks */
levl[cx][cy].looted = alreadylooted ? 1 : 0;
newsym(cx, cy);
return TRUE;
}
} while (++trycnt < 200);
return FALSE;
}
/* obj is a ring being dropped over a kitchen sink */
staticfn void
dosinkring(struct obj *obj)
{
struct obj *otmp, *otmp2;
boolean ideed = TRUE;
boolean nosink = FALSE;
You("drop %s down the drain.", doname(obj));
obj->in_use = TRUE; /* block free identification via interrupt */
switch (obj->otyp) { /* effects that can be noticed without eyes */
case RIN_SEARCHING:
You("thought %s got lost in the sink, but there it is!", yname(obj));
goto giveback;
case RIN_SLOW_DIGESTION:
pline_The("ring is regurgitated!");
giveback:
obj->in_use = FALSE;
dropx(obj);
trycall(obj);
return;
case RIN_LEVITATION:
pline_The("sink quivers upward for a moment.");
break;
case RIN_POISON_RESISTANCE:
You("smell rotten %s.", makeplural(fruitname(FALSE)));
break;
case RIN_AGGRAVATE_MONSTER:
pline("Several %s buzz angrily around the sink.",
Hallucination ? makeplural(rndmonnam(NULL)) : "flies");
break;
case RIN_SHOCK_RESISTANCE:
pline("Static electricity surrounds the sink.");
break;
case RIN_CONFLICT:
Soundeffect(se_drain_noises, 50);
You_hear("loud noises coming from the drain.");
break;
case RIN_SUSTAIN_ABILITY: /* KMH */
pline_The("%s flow seems fixed.", hliquid("water"));
break;
case RIN_GAIN_STRENGTH:
pline_The("%s flow seems %ser now.",
hliquid("water"),
(obj->spe < 0) ? "weak" : "strong");
break;
case RIN_GAIN_CONSTITUTION:
pline_The("%s flow seems %ser now.",
hliquid("water"),
(obj->spe < 0) ? "less" : "great");
break;
case RIN_INCREASE_ACCURACY: /* KMH */
pline_The("%s flow %s the drain.",
hliquid("water"),
(obj->spe < 0) ? "misses" : "hits");
break;
case RIN_INCREASE_DAMAGE:
pline_The("water's force seems %ser now.",
(obj->spe < 0) ? "small" : "great");
break;
case RIN_HUNGER:
ideed = FALSE;
for (otmp = svl.level.objects[u.ux][u.uy]; otmp; otmp = otmp2) {
otmp2 = otmp->nexthere;
if (otmp != uball && otmp != uchain
&& !obj_resists(otmp, 1, 99)) {
if (!Blind) {
pline("Suddenly, %s %s from the sink!", doname(otmp),
otense(otmp, "vanish"));
ideed = TRUE;
}
delobj(otmp);
}
}
break;
case MEAT_RING:
/* Not the same as aggravate monster; besides, it's obvious. */
pline("Several flies buzz around the sink.");
break;
case RIN_TELEPORTATION:
nosink = teleport_sink();
/* give message even if blind; we know we're not levitating,
so can feel the outcome even if we can't directly see it */
pline_The("sink %svanishes.", nosink ? "" : "momentarily ");
ideed = FALSE;
break;
case RIN_POLYMORPH:
polymorph_sink();
nosink = TRUE;
/* for S_room case, same message as for teleportation is given */
ideed = (levl[u.ux][u.uy].typ != ROOM);
break;
default:
ideed = FALSE;
break;
}
if (!Blind && !ideed) {
ideed = TRUE;
switch (obj->otyp) { /* effects that need eyes */
case RIN_ADORNMENT:
pline_The("faucets flash brightly for a moment.");
break;
case RIN_REGENERATION:
pline_The("sink looks as good as new.");
break;
case RIN_INVISIBILITY:
You("don't see anything happen to the sink.");
break;
case RIN_FREE_ACTION:
You_see("the ring slide right down the drain!");
break;
case RIN_SEE_INVISIBLE:
You_see("some %s in the sink.",
Hallucination ? "oxygen molecules" : "air");
break;
case RIN_STEALTH:
pline_The("sink seems to blend into the floor for a moment.");
break;
case RIN_FIRE_RESISTANCE:
pline_The("hot %s faucet flashes brightly for a moment.",
hliquid("water"));
break;
case RIN_COLD_RESISTANCE:
pline_The("cold %s faucet flashes brightly for a moment.",
hliquid("water"));
break;
case RIN_PROTECTION_FROM_SHAPE_CHAN:
pline_The("sink looks nothing like a fountain.");
break;
case RIN_PROTECTION:
pline_The("sink glows %s for a moment.",
hcolor((obj->spe < 0) ? NH_BLACK : NH_SILVER));
break;
case RIN_WARNING:
pline_The("sink glows %s for a moment.", hcolor(NH_WHITE));
break;
case RIN_TELEPORT_CONTROL:
pline_The("sink looks like it is being beamed aboard somewhere.");
break;
case RIN_POLYMORPH_CONTROL:
pline_The(
"sink momentarily looks like a regularly erupting geyser.");
break;
default:
break;
}
}
if (ideed) {
trycall(obj);
} else if (!nosink) {
Soundeffect(se_ring_in_drain, 50);
You_hear("the ring bouncing down the drainpipe.");
}
if (!rn2(20) && !nosink) {
pline_The("sink backs up, leaving %s.", doname(obj));
obj->in_use = FALSE;
dropx(obj);
} else if (!rn2(5)) {
freeinv(obj);
obj->in_use = FALSE;
obj->ox = u.ux;
obj->oy = u.uy;
add_to_buried(obj);
} else
useup(obj);
}
/* some common tests when trying to drop or throw items */
boolean
canletgo(struct obj *obj, const char *word)
{
if (obj->owornmask & (W_ARMOR | W_ACCESSORY)) {
if (*word)
Norep("You cannot %s %s you are wearing.", word, something);
return FALSE;
}
if (obj == uwep && welded(uwep)) {
/* no weldmsg(), so uwep->bknown might become set silently
if word is "" */
if (*word) {
const char *hand = body_part(HAND);
if (bimanual(uwep))
hand = makeplural(hand);
Norep("You cannot %s %s welded to your %s.", word, something,
hand);
}
return FALSE;
}
if (obj->otyp == LOADSTONE && obj->cursed) {
/* getobj() kludge sets corpsenm to user's specified count
when refusing to split a stack of cursed loadstones */
if (*word) {
/* getobj() ignores a count for throwing since that is
implicitly forced to be 1; replicate its kludge... */
if (!strcmp(word, "throw") && obj->quan > 1L)
obj->corpsenm = 1;
pline("For some reason, you cannot %s%s the stone%s!", word,
obj->corpsenm ? " any of" : "", plur(obj->quan));
}
obj->corpsenm = 0; /* reset */
set_bknown(obj, 1);
return FALSE;
}
if (obj->otyp == LEASH && obj->leashmon != 0) {
if (*word)
pline_The("leash is tied around your %s.", body_part(HAND));
return FALSE;
}
if (obj->owornmask & W_SADDLE) {
if (*word)
You("cannot %s %s you are sitting on.", word, something);
return FALSE;
}
return TRUE;
}
staticfn int
drop(struct obj *obj)
{
if (!obj)
return ECMD_FAIL;
if (!canletgo(obj, "drop"))
return ECMD_FAIL;
if (obj->otyp == CORPSE && better_not_try_to_drop_that(obj))
return ECMD_FAIL;
if (obj == uwep) {
if (welded(uwep)) {
weldmsg(obj);
return ECMD_FAIL;
}
setuwep((struct obj *) 0);
}
if (obj == uquiver) {
setuqwep((struct obj *) 0);
}
if (obj == uswapwep) {
setuswapwep((struct obj *) 0);
}
if (u.uswallow) {
/* barrier between you and the floor */
if (flags.verbose) {
char *onam_p, *mnam_p, monbuf[BUFSZ];
mnam_p = mon_nam(u.ustuck);
/* doname can call s_suffix, reusing its buffer */
if (digests(u.ustuck->data)) {
Sprintf(monbuf, "%s %s", s_suffix(mnam_p),
mbodypart(u.ustuck, STOMACH));
mnam_p = monbuf;
}
onam_p = is_unpaid(obj) ? yobjnam(obj, (char *) 0) : doname(obj);
You("drop %s into %s.", onam_p, mnam_p);
}
} else {
if ((obj->oclass == RING_CLASS || obj->otyp == MEAT_RING)
&& IS_SINK(levl[u.ux][u.uy].typ)) {
dosinkring(obj);
return ECMD_TIME;
}
if (!can_reach_floor(TRUE)) {
/* we might be levitating due to #invoke Heart of Ahriman;
if so, levitation would end during call to freeinv()
and we want hitfloor() to happen before float_down() */
boolean levhack = finesse_ahriman(obj);
if (levhack)
ELevitation = W_ART; /* other than W_ARTI */
if (flags.verbose)
You("drop %s.", doname(obj));
freeinv(obj);
hitfloor(obj, TRUE);
if (levhack)
float_down(I_SPECIAL | TIMEOUT, W_ARTI | W_ART);
return ECMD_TIME;
}
if (!IS_ALTAR(levl[u.ux][u.uy].typ) && flags.verbose)
You("drop %s.", doname(obj));
}
obj->how_lost = LOST_DROPPED;
dropx(obj);
return ECMD_TIME;
}
/* dropx - take dropped item out of inventory;
called in several places - may produce output
(eg ship_object() and dropy() -> sellobj() both produce output) */
void
dropx(struct obj *obj)
{
freeinv(obj);
if (!u.uswallow) {
if (ship_object(obj, u.ux, u.uy, FALSE))
return;
if (IS_ALTAR(levl[u.ux][u.uy].typ))
doaltarobj(obj); /* set bknown */
}
dropy(obj);
}
/* dropy - put dropped object at destination; called from lots of places */
void
dropy(struct obj *obj)
{
dropz(obj, FALSE);
}
/* dropz - really put dropped object at its destination... */
void
dropz(struct obj *obj, boolean with_impact)
{
if (obj == uwep)
setuwep((struct obj *) 0);
if (obj == uquiver)
setuqwep((struct obj *) 0);
if (obj == uswapwep)
setuswapwep((struct obj *) 0);
if (u.uswallow) {
/* hero has dropped an item while inside an engulfer */
if (obj != uball) { /* mon doesn't pick up ball */
/* moving shop item into engulfer's inventory treated as theft */
if (is_unpaid(obj))
(void) stolen_value(obj, u.ux, u.uy, TRUE, FALSE);
/* add to engulfer's inventory if not immediately eaten */
if (!engulfer_digests_food(obj))
(void) mpickobj(u.ustuck, obj);
}
} else {
if (flooreffects(obj, u.ux, u.uy, "drop"))
return;
place_object(obj, u.ux, u.uy);
if (with_impact)
container_impact_dmg(obj, u.ux, u.uy);
impact_disturbs_zombies(obj, with_impact);
if (obj == uball)
drop_ball(u.ux, u.uy);
else if (svl.level.flags.has_shop)
sellobj(obj, u.ux, u.uy);
stackobj(obj);
if (Blind && Levitation)
map_object(obj, 0);
newsym(u.ux, u.uy); /* remap location under self */
}
encumber_msg();
}
/* when swallowed, move dropped object from OBJ_FREE to u.ustuck's inventory;
for purple worm, immediately eat any corpse, glob, or special meat item
from object polymorph; return True if object is used up, False otherwise */
staticfn boolean
engulfer_digests_food(struct obj *obj)
{
/* animal swallower (purple worn) eats any
corpse, glob, or meat <item> but not other types of food */
if (digests(u.ustuck->data)
&& (obj->otyp == CORPSE || obj->globby
|| obj->otyp == MEATBALL || obj->otyp == ENORMOUS_MEATBALL
|| obj->otyp == MEAT_RING || obj->otyp == MEAT_STICK)) {
boolean could_petrify = FALSE,
could_poly = FALSE, could_slime = FALSE,
could_grow = FALSE, could_heal = FALSE;
if (obj->otyp == CORPSE) {
could_petrify = touch_petrifies(&mons[obj->corpsenm]);
could_poly = polyfood(obj);
could_grow = (obj->corpsenm == PM_WRAITH);
could_heal = (obj->corpsenm == PM_NURSE);
} else if (obj->otyp == GLOB_OF_GREEN_SLIME) {
could_slime = TRUE;
}
/* see or feel the effect */
pline("%s instantly digested!", Tobjnam(obj, "are"));
if (could_poly || could_slime) {
(void) newcham(u.ustuck, could_slime ? &mons[PM_GREEN_SLIME] : 0,
could_slime ? NC_SHOW_MSG : NO_NC_FLAGS);
} else if (could_petrify) {
minstapetrify(u.ustuck, TRUE);
} else if (could_grow) {
(void) grow_up(u.ustuck, (struct monst *) 0);
} else if (could_heal) {
healmon(u.ustuck, u.ustuck->mhpmax, 0);
/* False: don't realize that sight is cured from inside */
mcureblindness(u.ustuck, FALSE);
}
delobj(obj); /* always used up */
return TRUE;
}
return FALSE;
}
/* things that must change when not held; recurse into containers.
Called for both player and monsters */
void
obj_no_longer_held(struct obj *obj)
{
if (!obj) {
return;
} else if (Has_contents(obj)) {
struct obj *contents;
for (contents = obj->cobj; contents; contents = contents->nobj)
obj_no_longer_held(contents);
}
switch (obj->otyp) {
case CRYSKNIFE:
/* Normal crysknife reverts to worm tooth when not held by hero
* or monster; fixed crysknife has only 10% chance of reverting.
* When a stack of the latter is involved, it could be worthwhile
* to give each individual crysknife its own separate 10% chance,
* but we aren't in any position to handle stack splitting here.
*/
if (!obj->oerodeproof || !rn2(10)) {
/* if monsters aren't moving, assume player is responsible */
if (!svc.context.mon_moving && !program_state.gameover)
costly_alteration(obj, COST_DEGRD);
obj->otyp = WORM_TOOTH;
obj->oerodeproof = 0;
}
break;
}
}
/* the #droptype command: drop several things */
int
doddrop(void)
{
int result = ECMD_OK;
if (!gi.invent) {
You("have nothing to drop.");
return ECMD_OK;
}
add_valid_menu_class(0); /* clear any classes already there */
if (*u.ushops)
sellobj_state(SELL_DELIBERATE);
if (flags.menu_style != MENU_TRADITIONAL
|| (result = ggetobj("drop", drop, 0, FALSE, (unsigned *) 0)) < -1)
result = menu_drop(result);
if (*u.ushops)
sellobj_state(SELL_NORMAL);
if (result)
reset_occupations();
return result;
}
staticfn boolean
better_not_try_to_drop_that(struct obj *otmp)
{
char buf[BUFSZ];
/* u_safe_from_fatal_corpse() with st_all checks for gloves and stoning
* resistance before bothering to prompt you.
*/
if (otmp->otyp == CORPSE && !u_safe_from_fatal_corpse(otmp, st_all)) {
Snprintf(
buf, sizeof buf,
"Drop the %s corpse without %s protection on?",
obj_pmname(otmp), body_part(HAND));
return (paranoid_ynq(TRUE, buf, FALSE) != 'y');
}
return FALSE;
}
staticfn int /* check callers */
menudrop_split(struct obj *otmp, long cnt)
{
if (cnt && cnt < otmp->quan) {
if (welded(otmp)) {
; /* don't split */
} else if (otmp->otyp == LOADSTONE && otmp->cursed) {
/* same kludge as getobj(), for canletgo()'s use */
otmp->corpsenm = (int) cnt; /* don't split */
} else {
otmp = splitobj(otmp, cnt);
}
}
return drop(otmp);
}
/* Drop things from the hero's inventory, using a menu. */
staticfn int
menu_drop(int retry)
{
int n, i, n_dropped = 0;
struct obj *otmp, *otmp2;
menu_item *pick_list;
boolean all_categories = TRUE, drop_everything = FALSE, autopick = FALSE;
boolean drop_justpicked = FALSE;
long justpicked_quan = 0;
if (retry) {
all_categories = (retry == -2);
} else if (flags.menu_style == MENU_FULL) {
all_categories = FALSE;
n = query_category("Drop what type of items?", gi.invent,
(UNPAID_TYPES | ALL_TYPES | CHOOSE_ALL
| BUC_BLESSED | BUC_CURSED | BUC_UNCURSED
| BUC_UNKNOWN | JUSTPICKED | INCLUDE_VENOM),
&pick_list, PICK_ANY);
/* when paranoid_confirm:A is set, 'A' by itself implies
'A'+'a' which will be followed by a confirmation prompt;
You can’t perform that action at this time.
