-
Notifications
You must be signed in to change notification settings - Fork 635
Expand file tree
/
Copy pathdo_wear.c
More file actions
3504 lines (3251 loc) · 115 KB
/
Copy pathdo_wear.c
File metadata and controls
3504 lines (3251 loc) · 115 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_wear.c $NHDT-Date: 1781973047 2026/06/20 16:30:47 $ $NHDT-Branch: NetHack-5.0 $:$NHDT-Revision: 1.212 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
static NEARDATA const char see_yourself[] = "see yourself";
static NEARDATA const char unknown_type[] = "Unknown type of %s (%d)";
static NEARDATA const char c_armor[] = "armor", c_suit[] = "suit",
c_shirt[] = "shirt", c_cloak[] = "cloak",
c_gloves[] = "gloves", c_boots[] = "boots",
c_helmet[] = "helmet", c_shield[] = "shield",
c_weapon[] = "weapon", c_sword[] = "sword",
c_axe[] = "axe", c_that_[] = "that";
static NEARDATA const long takeoff_order[] = {
WORN_BLINDF, W_WEP, WORN_SHIELD, WORN_GLOVES, LEFT_RING,
RIGHT_RING, WORN_CLOAK, WORN_HELMET, WORN_AMUL, WORN_ARMOR,
WORN_SHIRT, WORN_BOOTS, W_SWAPWEP, W_QUIVER, 0L
};
staticfn void on_msg(struct obj *);
staticfn void toggle_stealth(struct obj *, long, boolean);
staticfn int Armor_on(void);
/* int Boots_on(void); -- moved to extern.h */
staticfn int Cloak_on(void);
staticfn int Helmet_on(void);
staticfn int Gloves_on(void);
staticfn int Shield_on(void);
staticfn int Shirt_on(void);
staticfn void dragon_armor_handling(struct obj *, boolean, boolean);
staticfn void Amulet_on(struct obj *) NONNULLARG1;
staticfn void learnring(struct obj *, boolean);
staticfn void adjust_attrib(struct obj *, int, int);
staticfn void Ring_off_or_gone(struct obj *, boolean);
staticfn int select_off(struct obj *);
staticfn struct obj *do_takeoff(void);
staticfn int take_off(void);
staticfn int menu_remarm(int);
staticfn void wornarm_destroyed(struct obj *);
staticfn void count_worn_stuff(struct obj **, boolean);
staticfn int armor_or_accessory_off(struct obj *);
staticfn int accessory_or_armor_on(struct obj *);
staticfn void already_wearing(const char *);
staticfn void already_wearing2(const char *, const char *);
staticfn int equip_ok(struct obj *, boolean, boolean);
staticfn int puton_ok(struct obj *);
staticfn int remove_ok(struct obj *);
staticfn int wear_ok(struct obj *);
staticfn int takeoff_ok(struct obj *);
/* maybe_destroy_armor() may return NULL */
staticfn struct obj *maybe_destroy_armor(struct obj *, struct obj *,
boolean *) NONNULLARG3;
staticfn int obj_erode_type(struct obj *) NONNULLARG1;
staticfn boolean better_not_take_that_off(struct obj *) NONNULLARG1;
/* plural "fingers" or optionally "gloves" */
const char *
fingers_or_gloves(boolean check_gloves)
{
return ((check_gloves && uarmg)
? gloves_simple_name(uarmg) /* "gloves" or "gauntlets" */
: makeplural(body_part(FINGER))); /* "fingers" */
}
void
off_msg(struct obj *otmp)
{
if (flags.verbose)
You("were wearing %s.", doname(otmp));
}
/* for items that involve no delay */
staticfn void
on_msg(struct obj *otmp)
{
/* on_msg() for rings and amulets just shows add-to-invent feedback
[after caller calls setworn(), for suffix: "(on {left|right} hand)"
or "(being worn)"]; eyewear too unless giving verbose message below */
if ((otmp->owornmask & (W_RING | W_AMUL)) != 0L
|| ((otmp->owornmask & W_TOOL) != 0L && !flags.verbose)) {
prinv((char *) NULL, otmp, 0L);
return;
}
if (flags.verbose) {
char how[BUFSZ];
/* call xname() before obj_is_pname(); formatting obj's name
might set obj->dknown and that affects the pname test */
const char *otmp_name = xname(otmp);
how[0] = '\0';
if (otmp->otyp == TOWEL)
Sprintf(how, " around your %s", body_part(HEAD));
You("are now wearing %s%s.",
obj_is_pname(otmp) ? the(otmp_name) : an(otmp_name), how);
}
}
/* putting on or taking off an item which confers stealth;
give feedback and discover it iff stealth state is changing;
stealth is blocked by riding unless hero+steed fly (handled with
BStealth by mount and dismount routines) */
staticfn
void
toggle_stealth(
struct obj *obj,
long oldprop, /* prop[].extrinsic, with obj->owornmask pre-stripped */
boolean on)
{
if (on ? gi.initial_don : svc.context.takeoff.cancelled_don)
return;
if (!oldprop /* extrinsic stealth from something else */
&& !HStealth /* intrinsic stealth */
&& !BStealth) { /* stealth blocked by something */
if (obj->otyp == RIN_STEALTH)
learnring(obj, TRUE);
else /* discover elven cloak or elven boots */
makeknown(obj->otyp);
if (on) {
if (!is_boots(obj))
You("move very quietly.");
else if (Levitation || Flying)
You("float imperceptibly.");
else
You("walk very quietly.");
} else {
boolean riding = (u.usteed != NULL);
You("%s%s are noisy.", riding ? "and " : "sure",
riding ? x_monnam(u.usteed, ARTICLE_YOUR, (char *) NULL,
(SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION),
FALSE)
: "");
}
}
}
/* putting on or taking off an item which confers displacement, or gaining
or losing timed displacement after eating a displacer beast corpse or tin;
give feedback and discover it iff displacement state is changing *and*
hero is able to see self (or sense monsters); for timed, 'obj' is Null
and this is only called for the message */
void
toggle_displacement(
struct obj *obj,
long oldprop, /* prop[].extrinsic, with obj->owornmask
stripped by caller */
boolean on)
{
if (on ? gi.initial_don : svc.context.takeoff.cancelled_don)
return;
if (!oldprop /* extrinsic displacement from something else */
&& !(u.uprops[DISPLACED].intrinsic) /* timed, from eating */
&& !(u.uprops[DISPLACED].blocked) /* (theoretical) */
/* we don't use canseeself() here because it augments vision
with touch, which isn't appropriate for deciding whether
we'll notice that monsters have trouble spotting the hero */
&& ((!Blind /* see anything */
&& !u.uswallow /* see surroundings */
&& !Invisible) /* see self */
/* actively sensing nearby monsters via telepathy or extended
monster detection overrides vision considerations because
hero also senses self in this situation */
|| (Unblind_telepat
|| (Blind_telepat && Blind)
|| Detect_monsters))) {
if (obj)
makeknown(obj->otyp);
You_feel("that monsters%s have difficulty pinpointing your location.",
on ? "" : " no longer");
}
}
/*
* The Type_on() functions should be called *after* setworn().
* The Type_off() functions call setworn() themselves.
* [Blindf_on() is an exception and calls setworn() itself.]
*/
int
Boots_on(void)
{
long oldprop =
u.uprops[objects[uarmf->otyp].oc_oprop].extrinsic & ~WORN_BOOTS;
switch (uarmf->otyp) {
case LOW_BOOTS:
case IRON_SHOES:
case HIGH_BOOTS:
case JUMPING_BOOTS:
case KICKING_BOOTS:
break;
case WATER_WALKING_BOOTS:
/*
* Sequencing issue? If underwater (perhaps via magical breathing),
* putting on water walking boots produces "you slowly rise above
* the surface" then "you finish your dressing maneuver".
*/
/* spoteffects() doesn't get called here; pooleffects() is called
during movement and u.uinwater is already False after setworn() */
if (u.uinwater)
spoteffects(TRUE);
/* init'd in accessory_or_armor_on() and only used here */
if (gw.wasinwater) {
if (!u.uinwater)
makeknown(WATER_WALKING_BOOTS);
gw.wasinwater = 0U;
}
/* (we don't need a lava check here since boots can't be
put on while feet are stuck) */
break;
case SPEED_BOOTS:
/* Speed boots are still better than intrinsic speed, */
/* though not better than potion speed */
if (!oldprop && !(HFast & TIMEOUT)) {
makeknown(uarmf->otyp);
You_feel("yourself speed up%s.",
(oldprop || HFast) ? " a bit more" : "");
}
break;
case ELVEN_BOOTS:
toggle_stealth(uarmf, oldprop, TRUE);
break;
case FUMBLE_BOOTS:
if (!oldprop && !(HFumbling & ~TIMEOUT))
incr_itimeout(&HFumbling, rnd(20));
break;
case LEVITATION_BOOTS:
if (!oldprop && !HLevitation && !(BLevitation & FROMOUTSIDE)) {
uarmf->known = 1; /* might come off if putting on over a sink,
* so uarmf could be Null below; status line
* gets updated during brief interval they're
* worn so hero and player learn enchantment */
disp.botl = TRUE; /* status hilites might mark AC changed */
makeknown(uarmf->otyp);
float_up();
if (Levitation)
spoteffects(FALSE); /* for sink effect */
} else {
float_vs_flight(); /* maybe toggle BFlying's I_SPECIAL */
}
break;
default:
impossible(unknown_type, c_boots, uarmf->otyp);
}
/* uarmf could be Null here (levitation boots put on over a sink) */
if (uarmf && !uarmf->known) {
uarmf->known = 1; /* boots' +/- evident because of status line AC */
update_inventory();
}
return 0;
}
int
Boots_off(void)
{
struct obj *otmp = uarmf;
int otyp = otmp->otyp;
long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_BOOTS;
svc.context.takeoff.mask &= ~W_ARMF;
/* For levitation, float_down() returns if Levitation, so we
* must do a setworn() _before_ the levitation case.
*/
setworn((struct obj *) 0, W_ARMF);
switch (otyp) {
case SPEED_BOOTS:
if (!Very_fast && !svc.context.takeoff.cancelled_don) {
makeknown(otyp);
You_feel("yourself slow down%s.", Fast ? " a bit" : "");
}
break;
case WATER_WALKING_BOOTS:
/* check for lava since fireproofed boots make it viable */
if ((is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy))
&& !Levitation && !Flying
&& !(is_clinger(gy.youmonst.data) && has_ceiling(&u.uz))
&& !svc.context.takeoff.cancelled_don
/* avoid recursive call to lava_effects() */
&& !iflags.in_lava_effects) {
/* make boots known in case you survive the drowning */
makeknown(otyp);
spoteffects(TRUE);
}
break;
case ELVEN_BOOTS:
toggle_stealth(otmp, oldprop, FALSE);
break;
case FUMBLE_BOOTS:
if (!oldprop && !(HFumbling & ~TIMEOUT))
HFumbling = EFumbling = 0;
break;
case LEVITATION_BOOTS:
if (!oldprop && !HLevitation && !(BLevitation & FROMOUTSIDE)
&& !svc.context.takeoff.cancelled_don) {
/* lava_effects() sets in_lava_effects and calls Boots_off()
so hero is already in midst of floating down */
if (!iflags.in_lava_effects)
(void) float_down(0L, 0L);
makeknown(otyp);
} else {
float_vs_flight(); /* maybe toggle (BFlying & I_SPECIAL) */
}
break;
case LOW_BOOTS:
case IRON_SHOES:
case HIGH_BOOTS:
case JUMPING_BOOTS:
case KICKING_BOOTS:
break;
default:
impossible(unknown_type, c_boots, otyp);
}
svc.context.takeoff.cancelled_don = FALSE;
return 0;
}
staticfn int
Cloak_on(void)
{
long oldprop =
u.uprops[objects[uarmc->otyp].oc_oprop].extrinsic & ~WORN_CLOAK;
switch (uarmc->otyp) {
case ORCISH_CLOAK:
case DWARVISH_CLOAK:
case CLOAK_OF_MAGIC_RESISTANCE:
case ROBE:
case LEATHER_CLOAK:
break;
case CLOAK_OF_PROTECTION:
makeknown(uarmc->otyp);
break;
case ELVEN_CLOAK:
toggle_stealth(uarmc, oldprop, TRUE);
break;
case CLOAK_OF_DISPLACEMENT:
toggle_displacement(uarmc, oldprop, TRUE);
break;
case MUMMY_WRAPPING:
/* Note: it's already being worn, so we have to cheat here. */
if ((HInvis || EInvis) && !Blind) {
newsym(u.ux, u.uy);
You("can %s!", See_invisible ? "no longer see through yourself"
: see_yourself);
}
break;
case CLOAK_OF_INVISIBILITY:
/* since cloak of invisibility was worn, we know mummy wrapping
wasn't, so no need to check `oldprop' against blocked */
if (!oldprop && !HInvis && !Blind) {
makeknown(uarmc->otyp);
newsym(u.ux, u.uy);
pline("Suddenly you can%s yourself.",
See_invisible ? " see through" : "not see");
}
break;
case OILSKIN_CLOAK:
pline("%s very tightly.", Tobjnam(uarmc, "fit"));
break;
/* Alchemy smock gives poison _and_ acid resistance */
case ALCHEMY_SMOCK:
EAcid_resistance |= WORN_CLOAK;
break;
default:
impossible(unknown_type, c_cloak, uarmc->otyp);
}
if (uarmc && !uarmc->known) { /* no known instance of !uarmc here */
uarmc->known = 1; /* cloak's +/- evident because of status line AC */
update_inventory();
}
return 0;
}
int
Cloak_off(void)
{
struct obj *otmp = uarmc;
int otyp = otmp->otyp;
long oldprop = u.uprops[objects[otyp].oc_oprop].extrinsic & ~WORN_CLOAK;
svc.context.takeoff.mask &= ~W_ARMC;
/* For mummy wrapping, taking it off first resets `Invisible'. */
setworn((struct obj *) 0, W_ARMC);
switch (otyp) {
case ORCISH_CLOAK:
case DWARVISH_CLOAK:
case CLOAK_OF_PROTECTION:
case CLOAK_OF_MAGIC_RESISTANCE:
case OILSKIN_CLOAK:
case ROBE:
case LEATHER_CLOAK:
break;
case ELVEN_CLOAK:
toggle_stealth(otmp, oldprop, FALSE);
break;
case CLOAK_OF_DISPLACEMENT:
toggle_displacement(otmp, oldprop, FALSE);
break;
case MUMMY_WRAPPING:
if (Invis && !Blind) {
newsym(u.ux, u.uy);
You("can %s.", See_invisible ? "see through yourself"
: "no longer see yourself");
}
break;
case CLOAK_OF_INVISIBILITY:
if (!oldprop && !HInvis && !Blind) {
makeknown(CLOAK_OF_INVISIBILITY);
newsym(u.ux, u.uy);
pline("Suddenly you can %s.",
See_invisible ? "no longer see through yourself"
: see_yourself);
}
break;
/* Alchemy smock gives poison _and_ acid resistance */
case ALCHEMY_SMOCK:
EAcid_resistance &= ~WORN_CLOAK;
break;
default:
impossible(unknown_type, c_cloak, otyp);
}
return 0;
}
staticfn int
Helmet_on(void)
{
switch (uarmh->otyp) {
case FEDORA:
if (Role_if(PM_ARCHEOLOGIST))
change_luck(1);
break;
case HELMET:
case DENTED_POT:
case ELVEN_LEATHER_HELM:
case DWARVISH_IRON_HELM:
case ORCISH_HELM:
case HELM_OF_TELEPATHY:
break;
case HELM_OF_CAUTION:
see_monsters();
break;
case HELM_OF_BRILLIANCE:
adj_abon(uarmh, uarmh->spe);
break;
case CORNUTHAUM:
/* people think marked wizards know what they're talking about,
but it takes trained arrogance to pull it off, and the actual
enchantment of the hat is irrelevant */
ABON(A_CHA) += (Role_if(PM_WIZARD) ? 1 : -1);
disp.botl = TRUE;
makeknown(uarmh->otyp);
break;
case HELM_OF_OPPOSITE_ALIGNMENT:
uarmh->known = 1; /* do this here because uarmh could get cleared */
/* changing alignment can toggle off active artifact properties,
including levitation; uarmh could get dropped or destroyed here
by hero falling onto a polymorph trap or into water (emergency
disrobe) or maybe lava (probably not, helm isn't 'organic') */
uchangealign((u.ualign.type != A_NEUTRAL)
? -u.ualign.type
: (uarmh->o_id % 2) ? A_CHAOTIC : A_LAWFUL,
A_CG_HELM_ON);
/* makeknown(HELM_OF_OPPOSITE_ALIGNMENT); -- below, after Tobjnam() */
FALLTHROUGH;
/*FALLTHRU*/
case DUNCE_CAP:
if (uarmh && !uarmh->cursed) {
if (Blind)
pline("%s for a moment.", Tobjnam(uarmh, "vibrate"));
else
pline("%s %s for a moment.", Tobjnam(uarmh, "glow"),
hcolor(NH_BLACK));
curse(uarmh);
/* curse() doesn't touch bknown so doesn't update persistent
inventory; do so now [set_bknown() calls update_inventory()] */
if (Blind)
set_bknown(uarmh, 0); /* lose bknown if previously set */
else if (Role_if(PM_CLERIC))
set_bknown(uarmh, 1); /* (bknown should already be set) */
else if (uarmh->bknown)
update_inventory(); /* keep bknown as-is; display the curse */
}
disp.botl = TRUE; /* reveal new alignment or INT & WIS */
if (Hallucination) {
pline("My brain hurts!"); /* Monty Python's Flying Circus */
} else if (uarmh && uarmh->otyp == DUNCE_CAP) {
You_feel("%s.", /* track INT change; ignore WIS */
ACURR(A_INT)
<= (ABASE(A_INT) + ABON(A_INT) + ATEMP(A_INT))
? "like sitting in a corner"
: "giddy");
} else {
/* [message formerly given here moved to uchangealign()] */
makeknown(HELM_OF_OPPOSITE_ALIGNMENT);
}
break;
default:
impossible(unknown_type, c_helmet, uarmh->otyp);
}
/* uarmh could be Null due to uchangealign() */
if (uarmh && !uarmh->known) {
uarmh->known = 1; /* helmet's +/- evident because of status line AC */
update_inventory();
}
return 0;
}
int
Helmet_off(void)
{
svc.context.takeoff.mask &= ~W_ARMH;
switch (uarmh->otyp) {
case FEDORA:
if (Role_if(PM_ARCHEOLOGIST))
change_luck(-1);
break;
case HELMET:
case DENTED_POT:
case ELVEN_LEATHER_HELM:
case DWARVISH_IRON_HELM:
case ORCISH_HELM:
break;
case DUNCE_CAP:
disp.botl = TRUE;
break;
case CORNUTHAUM:
if (!svc.context.takeoff.cancelled_don) {
ABON(A_CHA) += (Role_if(PM_WIZARD) ? -1 : 1);
disp.botl = TRUE;
}
break;
case HELM_OF_TELEPATHY:
case HELM_OF_CAUTION:
/* need to update ability before calling see_monsters() */
setworn((struct obj *) 0, W_ARMH);
see_monsters();
return 0;
case HELM_OF_BRILLIANCE:
if (!svc.context.takeoff.cancelled_don)
adj_abon(uarmh, -uarmh->spe);
break;
case HELM_OF_OPPOSITE_ALIGNMENT:
/* changing alignment can toggle off active artifact
properties, including levitation; uarmh could get
dropped or destroyed here */
uchangealign(u.ualignbase[A_CURRENT], A_CG_HELM_OFF);
break;
default:
impossible(unknown_type, c_helmet, uarmh->otyp);
}
setworn((struct obj *) 0, W_ARMH);
svc.context.takeoff.cancelled_don = FALSE;
return 0;
}
/* hard helms provide better protection against falling rocks */
boolean
hard_helmet(struct obj *obj)
{
if (!obj || !is_helmet(obj))
return FALSE;
return (is_metallic(obj) || is_crackable(obj)) ? TRUE : FALSE;
}
staticfn int
Gloves_on(void)
{
long oldprop =
u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES;
switch (uarmg->otyp) {
case LEATHER_GLOVES:
break;
case GAUNTLETS_OF_FUMBLING:
if (!oldprop && !(HFumbling & ~TIMEOUT))
incr_itimeout(&HFumbling, rnd(20));
break;
case GAUNTLETS_OF_POWER:
makeknown(uarmg->otyp);
disp.botl = TRUE; /* taken care of in attrib.c */
break;
case GAUNTLETS_OF_DEXTERITY:
adj_abon(uarmg, uarmg->spe);
break;
default:
impossible(unknown_type, c_gloves, uarmg->otyp);
}
if (!uarmg->known) {
uarmg->known = 1; /* gloves' +/- evident because of status line AC */
update_inventory();
}
return 0;
}
/* check for wielding cockatrice corpse after taking off gloves or yellow
dragon scales/mail or having temporary stoning resistance time out */
void
wielding_corpse(
struct obj *obj, /* uwep, potentially a wielded cockatrice corpse */
struct obj *how, /* gloves or dragon armor or Null (resist timeout) */
boolean voluntary) /* True: taking protective armor off on purpose */
{
if (!obj || obj->otyp != CORPSE || uarmg)
return;
/* note: can't dual-wield with non-weapons/weapon-tools so u.twoweap
will always be false if uswapwep happens to be a corpse */
if (obj != uwep && (obj != uswapwep || !u.twoweap))
return;
if (touch_petrifies(&mons[obj->corpsenm]) && !Stone_resistance) {
char kbuf[BUFSZ], hbuf[BUFSZ];
You("%s %s in your bare %s.",
(how && is_gloves(how)) ? "now wield" : "are wielding",
corpse_xname(obj, (const char *) 0, CXN_ARTICLE),
makeplural(body_part(HAND)));
/* "removing" ought to be "taking off" but that makes the
tombstone text more likely to be truncated */
if (how)
Sprintf(hbuf, "%s %s", voluntary ? "removing" : "losing",
is_gloves(how) ? gloves_simple_name(how)
: strsubst(simpleonames(how), "set of ", ""));
else
Strcpy(hbuf, "resistance timing out");
Snprintf(kbuf, sizeof kbuf, "%s while wielding %s",
hbuf, killer_xname(obj));
instapetrify(kbuf);
/* life-saved or got poly'd into a stone golem; can't continue
wielding cockatrice corpse unless have now become resistant */
if (!Stone_resistance)
remove_worn_item(obj, FALSE);
}
}
int
Gloves_off(void)
{
struct obj *gloves = uarmg; /* needed after uarmg has been set to Null */
long oldprop =
u.uprops[objects[uarmg->otyp].oc_oprop].extrinsic & ~WORN_GLOVES;
boolean on_purpose = !svc.context.mon_moving && !uarmg->in_use;
svc.context.takeoff.mask &= ~W_ARMG;
switch (uarmg->otyp) {
case LEATHER_GLOVES:
break;
case GAUNTLETS_OF_FUMBLING:
if (!oldprop && !(HFumbling & ~TIMEOUT))
HFumbling = EFumbling = 0;
break;
case GAUNTLETS_OF_POWER:
makeknown(uarmg->otyp);
disp.botl = TRUE; /* taken care of in attrib.c */
break;
case GAUNTLETS_OF_DEXTERITY:
if (!svc.context.takeoff.cancelled_don)
adj_abon(uarmg, -uarmg->spe);
break;
default:
impossible(unknown_type, c_gloves, uarmg->otyp);
}
setworn((struct obj *) 0, W_ARMG);
svc.context.takeoff.cancelled_don = FALSE;
encumber_msg(); /* immediate feedback for GoP */
/* usually can't remove gloves when they're slippery but it can
be done by having them fall off (polymorph), stolen, or
destroyed (scroll, overenchantment, monster spell); if that
happens, 'cure' slippery fingers so that it doesn't transfer
from gloves to bare hands */
if (Glib)
make_glib(0); /* for update_inventory() */
/* prevent wielding cockatrice when not wearing gloves */
if (uwep && uwep->otyp == CORPSE)
wielding_corpse(uwep, gloves, on_purpose);
/* KMH -- ...or your secondary weapon when you're wielding it
[This case can't actually happen; twoweapon mode won't engage
if a corpse has been set up as either the primary or alternate
weapon. If it could happen and /both/ uwep and uswapwep could
be cockatrice corpses, life-saving for the first would need to
prevent the second from being fatal since conceptually they'd
be being touched simultaneously.] */
if (u.twoweap && uswapwep && uswapwep->otyp == CORPSE)
wielding_corpse(uswapwep, gloves, on_purpose);
if (condtests[bl_bareh].enabled)
disp.botl = TRUE;
return 0;
}
staticfn int
Shield_on(void)
{
/* no shield currently requires special handling when put on, but we
keep this uncommented in case somebody adds a new one which does
[the magical shields are handled by setting u.uprops[*].extrinsic
in setworn() called by armor_or_accessory_on() before Shield_on()] */
switch (uarms->otyp) {
case SMALL_SHIELD:
case SHIELD_OF_DRAIN_RESISTANCE:
case SHIELD_OF_SHOCK_RESISTANCE:
case ELVEN_SHIELD:
case URUK_HAI_SHIELD:
case ORCISH_SHIELD:
case DWARVISH_ROUNDSHIELD:
case LARGE_SHIELD:
case SHIELD_OF_REFLECTION:
break;
default:
impossible(unknown_type, c_shield, uarms->otyp);
}
if (!uarms->known) {
uarms->known = 1; /* shield's +/- evident because of status line AC */
update_inventory();
}
return 0;
}
int
Shield_off(void)
{
svc.context.takeoff.mask &= ~W_ARMS;
/* no shield currently requires special handling when taken off, but we
keep this uncommented in case somebody adds a new one which does */
switch (uarms->otyp) {
case SMALL_SHIELD:
case SHIELD_OF_DRAIN_RESISTANCE:
case SHIELD_OF_SHOCK_RESISTANCE:
case ELVEN_SHIELD:
case URUK_HAI_SHIELD:
case ORCISH_SHIELD:
case DWARVISH_ROUNDSHIELD:
case LARGE_SHIELD:
case SHIELD_OF_REFLECTION:
break;
default:
impossible(unknown_type, c_shield, uarms->otyp);
}
setworn((struct obj *) 0, W_ARMS);
return 0;
}
staticfn int
Shirt_on(void)
{
/* no shirt currently requires special handling when put on, but we
keep this uncommented in case somebody adds a new one which does */
switch (uarmu->otyp) {
case HAWAIIAN_SHIRT:
case T_SHIRT:
break;
default:
impossible(unknown_type, c_shirt, uarmu->otyp);
}
if (!uarmu->known) {
uarmu->known = 1; /* shirt's +/- evident because of status line AC */
update_inventory();
}
return 0;
}
int
Shirt_off(void)
{
svc.context.takeoff.mask &= ~W_ARMU;
/* no shirt currently requires special handling when taken off, but we
keep this uncommented in case somebody adds a new one which does */
switch (uarmu->otyp) {
case HAWAIIAN_SHIRT:
case T_SHIRT:
break;
default:
impossible(unknown_type, c_shirt, uarmu->otyp);
}
setworn((struct obj *) 0, W_ARMU);
return 0;
}
/* handle extra abilities for hero wearing dragon scale armor */
staticfn void
dragon_armor_handling(
struct obj *otmp, /* armor being put on or taken off */
boolean puton, /* True: on, False: off */
boolean on_purpose) /* voluntary removal; not applicable for putting on */
{
if (!otmp)
return;
switch (otmp->otyp) {
/* grey: no extra effect */
/* silver: no extra effect */
case BLACK_DRAGON_SCALES:
case BLACK_DRAGON_SCALE_MAIL:
if (puton) {
EDrain_resistance |= W_ARM;
} else {
EDrain_resistance &= ~W_ARM;
}
break;
case BLUE_DRAGON_SCALES:
case BLUE_DRAGON_SCALE_MAIL:
if (puton) {
if (!Very_fast)
You("speed up%s.", Fast ? " a bit more" : "");
EFast |= W_ARM;
} else {
EFast &= ~W_ARM;
if (!Very_fast && !svc.context.takeoff.cancelled_don)
You("slow down.");
}
break;
case GREEN_DRAGON_SCALES:
case GREEN_DRAGON_SCALE_MAIL:
if (puton) {
ESick_resistance |= W_ARM;
} else {
ESick_resistance &= ~W_ARM;
}
break;
case RED_DRAGON_SCALES:
case RED_DRAGON_SCALE_MAIL:
if (puton) {
EInfravision |= W_ARM;
} else {
EInfravision &= ~W_ARM;
}
see_monsters();
break;
case GOLD_DRAGON_SCALES:
case GOLD_DRAGON_SCALE_MAIL:
(void) make_hallucinated((long) !puton,
program_state.restoring ? FALSE : TRUE,
W_ARM);
break;
case ORANGE_DRAGON_SCALES:
case ORANGE_DRAGON_SCALE_MAIL:
if (puton) {
Free_action |= W_ARM;
} else {
Free_action &= ~W_ARM;
}
break;
case YELLOW_DRAGON_SCALES:
case YELLOW_DRAGON_SCALE_MAIL:
if (puton) {
EStone_resistance |= W_ARM;
} else {
EStone_resistance &= ~W_ARM;
/* prevent wielding cockatrice after losing stoning resistance
when not wearing gloves; the uswapwep case is always a no-op */
wielding_corpse(uwep, otmp, on_purpose);
wielding_corpse(uswapwep, otmp, on_purpose);
}
break;
case WHITE_DRAGON_SCALES:
case WHITE_DRAGON_SCALE_MAIL:
if (puton) {
ESlow_digestion |= W_ARM;
} else {
ESlow_digestion &= ~W_ARM;
}
break;
default:
break;
}
}
staticfn int
Armor_on(void)
{
if (!uarm) /* no known instances of !uarm here but play it safe */
return 0;
if (!uarm->known) {
uarm->known = 1; /* suit's +/- evident because of status line AC */
update_inventory();
}
dragon_armor_handling(uarm, TRUE, TRUE);
/* gold DSM requires extra handling since it emits light when worn;
do that after the special armor handling */
if (artifact_light(uarm) && !uarm->lamplit) {
begin_burn(uarm, FALSE);
if (!Blind)
pline("%s %s to shine %s!",
Yname2(uarm), otense(uarm, "begin"),
arti_light_description(uarm));
}
return 0;
}
int
Armor_off(void)
{
struct obj *otmp = uarm;
boolean was_arti_light = otmp && otmp->lamplit && artifact_light(otmp);
svc.context.takeoff.mask &= ~W_ARM;
setworn((struct obj *) 0, W_ARM);
svc.context.takeoff.cancelled_don = FALSE;
/* taking off yellow dragon scales/mail might be fatal; arti_light
comes from gold dragon scales/mail so they don't overlap, but
conceptually the non-fatal change should be done before the
potentially fatal change in case the latter results in bones */
if (was_arti_light && !artifact_light(otmp)) {
end_burn(otmp, FALSE);
if (!Blind)
pline("%s shining.", Tobjnam(otmp, "stop"));
}
dragon_armor_handling(otmp, FALSE, TRUE);
return 0;
}
/* The gone functions differ from the off functions in that if you die from
* taking it off and have life saving, you still die. [Obsolete reference
* to lack of fire resistance being fatal in hell (nethack 3.0) and life
* saving putting a removed item back on to prevent that from immediately
* repeating.]
*/
int
Armor_gone(void)
{
struct obj *otmp = uarm;
boolean was_arti_light = otmp && otmp->lamplit && artifact_light(otmp);
svc.context.takeoff.mask &= ~W_ARM;
setnotworn(uarm);
svc.context.takeoff.cancelled_don = FALSE;
/* losing yellow dragon scales/mail might be fatal; arti_light
comes from gold dragon scales/mail so they don't overlap, but
conceptually the non-fatal change should be done before the
potentially fatal change in case the latter results in bones */
if (was_arti_light && !artifact_light(otmp)) {
end_burn(otmp, FALSE);
if (!Blind)
pline("%s shining.", Tobjnam(otmp, "stop"));
}
dragon_armor_handling(otmp, FALSE, FALSE);
return 0;
}
staticfn void
Amulet_on(struct obj *amul)
{
boolean on_msg_done = FALSE;
/* make sure amulet isn't wielded/alt-wielded/quivered, before wearing */
remove_worn_item(amul, FALSE);
setworn(amul, W_AMUL);
switch (uamul->otyp) {
case AMULET_OF_ESP:
case AMULET_OF_LIFE_SAVING:
case AMULET_VERSUS_POISON:
case AMULET_OF_REFLECTION:
case FAKE_AMULET_OF_YENDOR:
break;
case AMULET_OF_MAGICAL_BREATHING: {
boolean was_in_poison_gas;
/* amulet is already on; we need to check hero's gas-cloud status
when it was off */
EMagical_breathing &= ~W_AMUL;
was_in_poison_gas = region_danger();
EMagical_breathing |= W_AMUL;
if (was_in_poison_gas) {
makeknown(AMULET_OF_MAGICAL_BREATHING);
on_msg(uamul);
on_msg_done = TRUE;
You("are no longer bothered by the poison gas.");
}
/* no need to check for becoming able to breathe underwater;
if we are underwater, we already can or we would have drowned */
break;
}
case AMULET_OF_UNCHANGING:
if (Slimed)
make_slimed(0L, (char *) 0);
break;
case AMULET_OF_CHANGE: {