-
Notifications
You must be signed in to change notification settings - Fork 5
/
do.c
2024 lines (1870 loc) · 68.4 KB
/
do.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 do.c $NHDT-Date: 1559670603 2019/06/04 17:50:03 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.192 $ */
/* 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"
#include "lev.h"
STATIC_DCL void FDECL(trycall, (struct obj *));
STATIC_DCL void NDECL(polymorph_sink);
STATIC_DCL boolean NDECL(teleport_sink);
STATIC_DCL void FDECL(dosinkring, (struct obj *));
STATIC_PTR int FDECL(drop, (struct obj *));
STATIC_PTR int NDECL(wipeoff);
STATIC_DCL int FDECL(menu_drop, (int));
STATIC_DCL int NDECL(currentlevel_rewrite);
STATIC_DCL void NDECL(final_level);
/* static boolean FDECL(badspot, (XCHAR_P,XCHAR_P)); */
extern int n_dgns; /* number of dungeons, from dungeon.c */
static NEARDATA const char drop_types[] = { ALLOW_COUNT, COIN_CLASS,
ALL_CLASSES, 0 };
/* 'd' command: drop one inventory item */
int
dodrop()
{
int result, i = (invent) ? 0 : (SIZE(drop_types) - 1);
if (*u.ushops)
sellobj_state(SELL_DELIBERATE);
result = drop(getobj(&drop_types[i], "drop"));
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(otmp, rx, ry, pushing)
struct obj *otmp;
register int rx, ry;
boolean pushing;
{
if (!otmp || otmp->otyp != BOULDER) {
impossible("Not a boulder?");
} else if (!Is_waterlevel(&u.uz) && 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% */
fills_up = 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;
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)
You_hear("a%s splash.", lava ? " sizzling" : "");
wake_nearto(rx, ry, 40);
}
if (fills_up && u.uinwater && distu(rx, ry) == 0) {
u.uinwater = 0;
docrt();
vision_full_recalc = 1;
You("find yourself on dry land again!");
} else if (lava && distu(rx, ry) <= 2) {
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)
delobj(otmp);
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(obj, x, y, verb)
struct obj *obj;
int x, y;
const char *verb;
{
struct trap *t;
struct monst *mtmp;
struct obj *otmp;
boolean tseen;
int ttyp = NO_TRAP;
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;
if (obj->otyp == BOULDER && boulder_hits_pool(obj, x, y, FALSE)) {
return 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.ux == x && u.uy == 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;
/* 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 (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))
return FALSE; /* still alive */
}
mtmp->mtrapped = 0;
} else {
if (!Passes_walls && !throws_rocks(youmonst.data)) {
losehp(Maybe_Half_Phys(rnd(15)),
"squished under a boulder", NO_KILLER_PREFIX);
return FALSE; /* player remains trapped */
} else
reset_utrap(TRUE);
}
}
if (*verb) {
if (Blind && (x == u.ux) && (y == u.uy)) {
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 {
You_hear("a boulder %s.", verb);
}
}
/*
* Note: trap might have gone away via ((hmon -> killed -> xkilled)
* || mondied) -> mondead -> m_detach -> fill_pit.
*/
if ((t = t_at(x, y)) != 0)
deltrap(t);
useupf(obj, 1L);
bury_objs(x, y);
newsym(x, y);
return TRUE;
} else if (is_lava(x, y)) {
return 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
&& ((x == u.ux) && (y == u.uy))) {
if (!Underwater) {
if (weight(obj) > 9) {
pline("Splash!");
} else if (Levitation || Flying) {
pline("Plop!");
}
}
map_background(x, y, 0);
newsym(x, y);
}
return water_damage(obj, NULL, FALSE) == ER_DESTROYED;
} else if (u.ux == x && u.uy == y && (t = t_at(x, y)) != 0
&& uteetering_at_seen_pit(t)) {
if (Blind && !Deaf)
You_hear("%s tumble downwards.", the(xname(obj)));
else
pline("%s %s into %s pit.", The(xname(obj)),
otense(obj, "tumble"), the_your[t->madeby_u]);
} else if (obj->globby) {
/* Globby things like puddings might stick together */
while (obj && (otmp = obj_nexto_xy(obj, x, y, TRUE)) != 0) {
pudding_merge_message(obj, otmp);
/* intentionally not getting the melded object; obj_meld may set
* obj to null. */
(void) obj_meld(&obj, &otmp);
}
return (boolean) !obj;
}
return FALSE;
}
/* obj is an object dropped on an altar */
void
doaltarobj(obj)
register struct obj *obj;
{
if (Blind)
return;
if (obj->oclass != COIN_CLASS) {
/* KMH, conduct */
if(!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() */
}
}
STATIC_OVL void
trycall(obj)
register 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. */
STATIC_DCL void
polymorph_sink()
{
uchar sym = S_sink;
boolean sinklooted;
if (levl[u.ux][u.uy].typ != SINK)
return;
sinklooted = levl[u.ux][u.uy].looted != 0;
level.flags.nsinks--;
levl[u.ux][u.uy].doormask = 0; /* levl[][].flags */
switch (rn2(4)) {
default:
case 0:
sym = S_fountain;
levl[u.ux][u.uy].typ = FOUNTAIN;
levl[u.ux][u.uy].blessedftn = 0;
if (sinklooted)
SET_FOUNTAIN_LOOTED(u.ux, u.uy);
level.flags.nfountains++;
break;
case 1:
sym = S_throne;
levl[u.ux][u.uy].typ = THRONE;
if (sinklooted)
levl[u.ux][u.uy].looted = T_LOOTED;
break;
case 2:
sym = S_altar;
levl[u.ux][u.uy].typ = ALTAR;
levl[u.ux][u.uy].altarmask = Align2amask(rn2((int) A_LAWFUL + 2) - 1);
break;
case 3:
sym = S_room;
levl[u.ux][u.uy].typ = 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. */
STATIC_DCL boolean
teleport_sink()
{
int cx, cy;
int cnt = 0;
struct trap *trp;
struct engr *eng;
do {
cx = rnd(COLNO - 1);
cy = rn2(ROWNO);
trp = t_at(cx, cy);
eng = engr_at(cx, cy);
} while ((levl[cx][cy].typ != ROOM || trp || eng || cansee(cx, cy))
&& cnt++ < 200);
if (levl[cx][cy].typ == ROOM && !trp && !eng) {
/* create sink at new position */
levl[cx][cy].typ = SINK;
levl[cx][cy].looted = levl[u.ux][u.uy].looted;
newsym(cx, cy);
/* remove old sink */
levl[u.ux][u.uy].typ = ROOM;
levl[u.ux][u.uy].looted = 0;
newsym(u.ux, u.uy);
return TRUE;
}
return FALSE;
}
/* obj is a ring being dropped over a kitchen sink */
STATIC_OVL void
dosinkring(obj)
register struct obj *obj;
{
struct obj *otmp, *otmp2;
boolean ideed = TRUE;
boolean nosink = FALSE;
tnnt_achieve(A_DROPPED_RING_IN_SINK);
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:
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 = 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)
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(obj, word)
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->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;
}
STATIC_PTR int
drop(obj)
register struct obj *obj;
{
if (!obj)
return 0;
if (!canletgo(obj, "drop"))
return 0;
if (obj == uwep) {
if (welded(uwep)) {
weldmsg(obj);
return 0;
}
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, monbuf[BUFSZ];
/* doname can call s_suffix, reusing its buffer */
Strcpy(monbuf, s_suffix(mon_nam(u.ustuck)));
onam_p = is_unpaid(obj) ? yobjnam(obj, (char *) 0) : doname(obj);
You("drop %s into %s %s.", onam_p, monbuf,
mbodypart(u.ustuck, STOMACH));
}
} else {
if ((obj->oclass == RING_CLASS || obj->otyp == MEAT_RING)
&& IS_SINK(levl[u.ux][u.uy].typ)) {
dosinkring(obj);
return 1;
}
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));
/* Ensure update when we drop gold objects */
if (obj->oclass == COIN_CLASS)
context.botl = 1;
freeinv(obj);
hitfloor(obj, TRUE);
if (levhack)
float_down(I_SPECIAL | TIMEOUT, W_ARTI | W_ART);
return 1;
}
if (!IS_ALTAR(levl[u.ux][u.uy].typ) && flags.verbose)
You("drop %s.", doname(obj));
}
dropx(obj);
return 1;
}
/* 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(obj)
register struct obj *obj;
{
/* Ensure update when we drop gold objects */
if (obj->oclass == COIN_CLASS)
context.botl = 1;
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(obj)
struct obj *obj;
{
dropz(obj, FALSE);
}
/* dropz - really put dropped object at its destination... */
void
dropz(obj, with_impact)
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 && flooreffects(obj, u.ux, u.uy, "drop"))
return;
/* uswallow check done by GAN 01/29/87 */
if (u.uswallow) {
boolean could_petrify = FALSE;
boolean could_poly = FALSE;
boolean could_slime = FALSE;
boolean could_grow = FALSE;
boolean could_heal = FALSE;
if (obj != uball) { /* mon doesn't pick up ball */
if (obj->otyp == CORPSE) {
could_petrify = touch_petrifies(&mons[obj->corpsenm]);
could_poly = polyfodder(obj);
could_slime = (obj->corpsenm == PM_GREEN_SLIME);
could_grow = (obj->corpsenm == PM_WRAITH);
could_heal = (obj->corpsenm == PM_NURSE);
}
if (is_unpaid(obj))
(void) stolen_value(obj, u.ux, u.uy, TRUE, FALSE);
(void) mpickobj(u.ustuck, obj);
if (is_animal(u.ustuck->data)) {
if (could_poly || could_slime) {
(void) newcham(u.ustuck,
could_poly ? (struct permonst *) 0
: &mons[PM_GREEN_SLIME],
FALSE, could_slime);
delobj(obj); /* corpse is digested */
} else if (could_petrify) {
minstapetrify(u.ustuck, TRUE);
/* Don't leave a cockatrice corpse in a statue */
if (!u.uswallow)
delobj(obj);
} else if (could_grow) {
(void) grow_up(u.ustuck, (struct monst *) 0);
delobj(obj); /* corpse is digested */
} else if (could_heal) {
u.ustuck->mhp = u.ustuck->mhpmax;
delobj(obj); /* corpse is digested */
}
}
}
} else {
place_object(obj, u.ux, u.uy);
if (with_impact)
container_impact_dmg(obj, u.ux, u.uy);
if (obj == uball)
drop_ball(u.ux, u.uy);
else if (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 */
}
}
/* things that must change when not held; recurse into containers.
Called for both player and monsters */
void
obj_no_longer_held(obj)
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 (!context.mon_moving && !program_state.gameover)
costly_alteration(obj, COST_DEGRD);
obj->otyp = WORM_TOOTH;
obj->oerodeproof = 0;
}
break;
}
}
/* 'D' command: drop several things */
int
doddrop()
{
int result = 0;
if (!invent) {
You("have nothing to drop.");
return 0;
}
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;
}
/* Drop things from the hero's inventory, using a menu. */
STATIC_OVL int
menu_drop(retry)
int retry;
{
int n, i, n_dropped = 0;
long cnt;
struct obj *otmp, *otmp2;
menu_item *pick_list;
boolean all_categories = TRUE;
boolean drop_everything = FALSE;
if (retry) {
all_categories = (retry == -2);
} else if (flags.menu_style == MENU_FULL) {
all_categories = FALSE;
n = query_category("Drop what type of items?", invent,
UNPAID_TYPES | ALL_TYPES | CHOOSE_ALL | BUC_BLESSED
| BUC_CURSED | BUC_UNCURSED | BUC_UNKNOWN,
&pick_list, PICK_ANY);
if (!n)
goto drop_done;
for (i = 0; i < n; i++) {
if (pick_list[i].item.a_int == ALL_TYPES_SELECTED)
all_categories = TRUE;
else if (pick_list[i].item.a_int == 'A')
drop_everything = TRUE;
else
add_valid_menu_class(pick_list[i].item.a_int);
}
free((genericptr_t) pick_list);
} else if (flags.menu_style == MENU_COMBINATION) {
unsigned ggoresults = 0;
all_categories = FALSE;
/* Gather valid classes via traditional NetHack method */
i = ggetobj("drop", drop, 0, TRUE, &ggoresults);
if (i == -2)
all_categories = TRUE;
if (ggoresults & ALL_FINISHED) {
n_dropped = i;
goto drop_done;
}
}
if (drop_everything) {
/*
* Dropping a burning potion of oil while levitating can cause
* an explosion which might destroy some of hero's inventory,
* so the old code
* for (otmp = invent; otmp; otmp = otmp2) {
* otmp2 = otmp->nobj;
* n_dropped += drop(otmp);
* }
* was unreliable and could lead to an "object lost" panic.
*
* Use the bypass bit to mark items already processed (hence
* not droppable) and rescan inventory until no unbypassed
* items remain.
*/
bypass_objlist(invent, FALSE); /* clear bypass bit for invent */
while ((otmp = nxt_unbypassed_obj(invent)) != 0)
n_dropped += drop(otmp);
/* we might not have dropped everything (worn armor, welded weapon,
cursed loadstones), so reset any remaining inventory to normal */
bypass_objlist(invent, FALSE);
} else {
/* should coordinate with perm invent, maybe not show worn items */
n = query_objlist("What would you like to drop?", &invent,
(USE_INVLET | INVORDER_SORT), &pick_list, PICK_ANY,
all_categories ? allow_all : allow_category);
if (n > 0) {
/*
* picklist[] contains a set of pointers into inventory, but
* as soon as something gets dropped, they might become stale
* (see the drop_everything code above for an explanation).
* Just checking to see whether one is still in the invent
* chain is not sufficient validation since destroyed items
* will be freed and items we've split here might have already
* reused that memory and put the same pointer value back into
* invent. Ditto for using invlet to validate. So we start
* by setting bypass on all of invent, then check each pointer
* to verify that it is in invent and has that bit set.
*/
bypass_objlist(invent, TRUE);
for (i = 0; i < n; i++) {
otmp = pick_list[i].item.a_obj;
for (otmp2 = invent; otmp2; otmp2 = otmp2->nobj)
if (otmp2 == otmp)
break;
if (!otmp2 || !otmp2->bypass)
continue;
/* found next selected invent item */
cnt = pick_list[i].count;
if (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);
}
}
n_dropped += drop(otmp);
}
bypass_objlist(invent, FALSE); /* reset invent to normal */
free((genericptr_t) pick_list);
}
}
drop_done:
return n_dropped;
}
/* on a ladder, used in goto_level */
static NEARDATA boolean at_ladder = FALSE;
/* the '>' command */
int
dodown()
{
struct trap *trap = 0;
boolean stairs_down = ((u.ux == xdnstair && u.uy == ydnstair)
|| (u.ux == sstairs.sx && u.uy == sstairs.sy
&& !sstairs.up)),
ladder_down = (u.ux == xdnladder && u.uy == ydnladder);
if (u_rooted())
return 1;
if (stucksteed(TRUE)) {
return 0;
}
/* Levitation might be blocked, but player can still use '>' to
turn off controlled levitation */
if (HLevitation || ELevitation) {
if ((HLevitation & I_SPECIAL) || (ELevitation & W_ARTI)) {
/* end controlled levitation */
if (ELevitation & W_ARTI) {
struct obj *obj;
for (obj = invent; obj; obj = obj->nobj) {
if (obj->oartifact
&& artifact_has_invprop(obj, LEVITATION)) {
if (obj->age < monstermoves)
obj->age = monstermoves;
obj->age += rnz(100);
}
}
}
if (float_down(I_SPECIAL | TIMEOUT, W_ARTI)) {
return 1; /* came down, so moved */
} else if (!HLevitation && !ELevitation) {
Your("latent levitation ceases.");
return 1; /* did something, effectively moved */
}
}
if (BLevitation) {
; /* weren't actually floating after all */
} else if (Blind) {
/* Avoid alerting player to an unknown stair or ladder.
* Changes the message for a covered, known staircase
* too; staircase knowledge is not stored anywhere.
*/
if (stairs_down)
stairs_down =
(glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnstair);
else if (ladder_down)
ladder_down =
(glyph_to_cmap(levl[u.ux][u.uy].glyph) == S_dnladder);
}
if (Is_airlevel(&u.uz))
You("are floating in the %s.", surface(u.ux, u.uy));
else if (Is_waterlevel(&u.uz))
You("are floating in %s.",
is_pool(u.ux, u.uy) ? "the water" : "a bubble of air");
else
floating_above(stairs_down ? "stairs" : ladder_down
? "ladder"
: surface(u.ux, u.uy));
return 0; /* didn't move */
}