-
Notifications
You must be signed in to change notification settings - Fork 5
/
read.c
2729 lines (2566 loc) · 95.2 KB
/
read.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 read.c $NHDT-Date: 1561485713 2019/06/25 18:01:53 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.172 $ */
/* 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"
#define Your_Own_Role(mndx) \
((mndx) == urole.malenum \
|| (urole.femalenum != NON_PM && (mndx) == urole.femalenum))
#define Your_Own_Race(mndx) \
((mndx) == urace.malenum \
|| (urace.femalenum != NON_PM && (mndx) == urace.femalenum))
boolean known;
static NEARDATA const char readable[] = { ALL_CLASSES, SCROLL_CLASS,
SPBOOK_CLASS, 0 };
static const char all_count[] = { ALLOW_COUNT, ALL_CLASSES, 0 };
STATIC_DCL boolean FDECL(learnscrolltyp, (SHORT_P));
STATIC_DCL char *FDECL(erode_obj_text, (struct obj *, char *));
STATIC_DCL char *FDECL(apron_text, (struct obj *, char *buf));
STATIC_DCL void FDECL(stripspe, (struct obj *));
STATIC_DCL void FDECL(p_glow1, (struct obj *));
STATIC_DCL void FDECL(p_glow2, (struct obj *, const char *));
STATIC_DCL void FDECL(forget_single_object, (int));
#if 0 /* not used */
STATIC_DCL void FDECL(forget_objclass, (int));
#endif
STATIC_DCL void FDECL(randomize, (int *, int));
STATIC_DCL void FDECL(forget, (int));
STATIC_DCL int FDECL(maybe_tame, (struct monst *, struct obj *));
STATIC_DCL boolean FDECL(get_valid_stinking_cloud_pos, (int, int));
STATIC_DCL boolean FDECL(is_valid_stinking_cloud_pos, (int, int, BOOLEAN_P));
STATIC_PTR void FDECL(display_stinking_cloud_positions, (int));
STATIC_PTR void FDECL(set_lit, (int, int, genericptr));
STATIC_DCL void NDECL(do_class_genocide);
STATIC_OVL boolean
learnscrolltyp(scrolltyp)
short scrolltyp;
{
if (!objects[scrolltyp].oc_name_known) {
makeknown(scrolltyp);
more_experienced(0, 10);
return TRUE;
} else
return FALSE;
}
/* also called from teleport.c for scroll of teleportation */
void
learnscroll(sobj)
struct obj *sobj;
{
/* it's implied that sobj->dknown is set;
we couldn't be reading this scroll otherwise */
if (sobj->oclass != SPBOOK_CLASS)
(void) learnscrolltyp(sobj->otyp);
}
STATIC_OVL char *
erode_obj_text(otmp, buf)
struct obj *otmp;
char *buf;
{
int erosion = greatest_erosion(otmp);
if (erosion)
wipeout_text(buf, (int) (strlen(buf) * erosion / (2 * MAX_ERODE)),
otmp->o_id ^ (unsigned) ubirthday);
return buf;
}
char *
tshirt_text(tshirt, buf)
struct obj *tshirt;
char *buf;
{
static const char *shirt_msgs[] = {
/* Scott Bigham */
"I explored the Dungeons of Doom and all I got was this lousy T-shirt!",
"Is that Mjollnir in your pocket or are you just happy to see me?",
"It's not the size of your sword, it's how #enhance'd you are with it.",
"Madame Elvira's House O' Succubi Lifetime Customer",
"Madame Elvira's House O' Succubi Employee of the Month",
"Ludios Vault Guards Do It In Small, Dark Rooms",
"Yendor Military Soldiers Do It In Large Groups",
"I survived Yendor Military Boot Camp",
"Ludios Accounting School Intra-Mural Lacrosse Team",
"Oracle(TM) Fountains 10th Annual Wet T-Shirt Contest",
"Hey, black dragon! Disintegrate THIS!",
"I'm With Stupid -->",
"Don't blame me, I voted for Izchak!",
"Don't Panic", /* HHGTTG */
"Furinkan High School Athletic Dept.", /* Ranma 1/2 */
"Hel-LOOO, Nurse!", /* Animaniacs */
"=^.^=",
"100% goblin hair - do not wash",
"Aberzombie and Fitch",
"cK -- Cockatrice touches the Kop",
"Don't ask me, I only adventure here",
"Down with pants!",
"d, your dog or a killer?",
"FREE PUG AND NEWT!",
"Go team ant!",
"Got newt?",
"Hello, my darlings!", /* Charlie Drake */
"Hey! Nymphs! Steal This T-Shirt!",
"I <3 Dungeon of Doom",
"I <3 Maud",
"I am a Valkyrie. If you see me running, try to keep up.",
"I am not a pack rat - I am a collector",
"I bounced off a rubber tree", /* Monkey Island */
"Plunder Island Brimstone Beach Club", /* Monkey Island */
"If you can read this, I can hit you with my polearm",
"I'm confused!",
"I scored with the princess",
"I want to live forever or die in the attempt.",
"Lichen Park",
"LOST IN THOUGHT - please send search party",
"Meat is Mordor",
"Minetown Better Business Bureau",
"Minetown Watch",
"Ms. Palm's House of Negotiable Affection -- A Very Reputable House Of Disrepute",
"Protection Racketeer",
"Real men love Crom",
"Somebody stole my Mojo!",
"The Hellhound Gang",
"The Werewolves",
"They Might Be Storm Giants",
"Weapons don't kill people, I kill people",
"White Zombie",
"You're killing me!",
"Anhur State University - Home of the Fighting Fire Ants!",
"FREE HUGS",
"Serial Ascender",
"Real men are valkyries",
"Young Men's Cavedigging Association",
"Occupy Fort Ludios",
"I couldn't afford this T-shirt so I stole it!",
"Mind flayers suck",
"I'm not wearing any pants",
"Down with the living!",
"Pudding farmer",
"Vegetarian",
"Hello, I'm War!",
"It is better to light a candle than to curse the darkness",
"It is easier to curse the darkness than to light a candle",
/* expanded "rock--paper--scissors" featured in TV show "Big Bang
Theory" although they didn't create it (and an actual T-shirt
with pentagonal diagram showing which choices defeat which) */
"rock--paper--scissors--lizard--Spock!",
/* "All men must die -- all men must serve" challange and response
from book series _A_Song_of_Ice_and_Fire_ by George R.R. Martin,
TV show "Game of Thrones" (probably an actual T-shirt too...) */
"/Valar morghulis/ -- /Valar dohaeris/",
};
/* TNNT - The Really Cool Shirt has ever-shifting text */
const char* rumor;
if (tshirt->oartifact == ART_REALLY_COOL_SHIRT && rn2(50)
&& (rumor = getrumor(bcsign(tshirt), buf, TRUE)) && *rumor)
; // actually do nothing here
else
Strcpy(buf, shirt_msgs[tshirt->o_id % SIZE(shirt_msgs)]);
return erode_obj_text(tshirt, buf);
}
STATIC_OVL char *
apron_text(apron, buf)
struct obj *apron;
char *buf;
{
static const char *apron_msgs[] = {
"Kiss the cook",
"I'm making SCIENCE!",
"Don't mess with the chef",
"Don't make me poison you",
"Gehennom's Kitchen",
"Rat: The other white meat",
"If you can't stand the heat, get out of Gehennom!",
"If we weren't meant to eat animals, why are they made out of meat?",
"If you don't like the food, I'll stab you",
};
Strcpy(buf, apron_msgs[apron->o_id % SIZE(apron_msgs)]);
return erode_obj_text(apron, buf);
}
int
doread()
{
register struct obj *scroll;
boolean confused, nodisappear;
known = FALSE;
if (check_capacity((char *) 0))
return 0;
scroll = getobj(readable, "read");
if (!scroll)
return 0;
/* outrumor has its own blindness check */
if (scroll->otyp == FORTUNE_COOKIE) {
if (flags.verbose)
You("break up the cookie and throw away the pieces.");
outrumor(bcsign(scroll), BY_COOKIE);
if (!Blind) {
if(!u.uconduct.literate++)
livelog_write_string(LL_CONDUCT,
"became literate by reading a fortune cookie");
tnnt_read(RDBL_COOKIE);
tnnt_achieve(A_READ_FORTUNE_FOODLESS);
}
useup(scroll);
return 1;
} else if (scroll->otyp == T_SHIRT || scroll->otyp == ALCHEMY_SMOCK) {
char buf[BUFSZ], *mesg;
const char *endpunct;
if (Blind) {
You_cant("feel any Braille writing.");
return 0;
}
/* can't read shirt worn under suit (under cloak is ok though) */
if (scroll->otyp == T_SHIRT && uarm && scroll == uarmu) {
pline("%s shirt is obscured by %s%s.",
scroll->unpaid ? "That" : "Your", shk_your(buf, uarm),
suit_simple_name(uarm));
return 0;
}
if(!u.uconduct.literate++)
livelog_printf(LL_CONDUCT, "became literate by reading %s",
(scroll->otyp == T_SHIRT) ? "a T-shirt" : "an apron");
tnnt_read(scroll->otyp == T_SHIRT ? RDBL_SHIRT : RDBL_APRON);
/* populate 'buf[]' */
mesg = (scroll->otyp == T_SHIRT) ? tshirt_text(scroll, buf)
: apron_text(scroll, buf);
endpunct = "";
if (flags.verbose) {
int ln = (int) strlen(mesg);
/* we will be displaying a sentence; need ending punctuation */
if (ln > 0 && !index(".!?", mesg[ln - 1]))
endpunct = ".";
pline("It reads:");
}
pline("\"%s\"%s", mesg, endpunct);
return 1;
} else if (scroll->otyp == CREDIT_CARD) {
static const char *card_msgs[] = {
"Leprechaun Gold Tru$t - Shamrock Card",
"Magic Memory Vault Charge Card",
"Larn National Bank", /* Larn */
"First Bank of Omega", /* Omega */
"Bank of Zork - Frobozz Magic Card", /* Zork */
"Ankh-Morpork Merchant's Guild Barter Card",
"Ankh-Morpork Thieves' Guild Unlimited Transaction Card",
"Ransmannsby Moneylenders Association",
"Bank of Gehennom - 99% Interest Card",
"Yendorian Express - Copper Card",
"Yendorian Express - Silver Card",
"Yendorian Express - Gold Card",
"Yendorian Express - Mithril Card",
"Yendorian Express - Platinum Card", /* must be last */
};
if (Blind) {
You("feel the embossed numbers:");
} else {
if (flags.verbose)
pline("It reads:");
pline("\"%s\"",
scroll->oartifact
? card_msgs[SIZE(card_msgs) - 1]
: card_msgs[scroll->o_id % (SIZE(card_msgs) - 1)]);
}
/* Make a credit card number */
pline("\"%d0%d %ld%d1 0%d%d0\"%s",
(((int) scroll->o_id % 89) + 10),
((int) scroll->o_id % 4),
((((long) scroll->o_id * 499L) % 899999L) + 100000L),
((int) scroll->o_id % 10),
(!((int) scroll->o_id % 3)),
(((int) scroll->o_id * 7) % 10),
(flags.verbose || Blind) ? "." : "");
if(!u.uconduct.literate++)
livelog_write_string(LL_CONDUCT,
"became literate by reading a credit card");
tnnt_read(RDBL_CARD);
return 1;
} else if (scroll->otyp == CAN_OF_GREASE) {
pline("This %s has no label.", singular(scroll, xname));
return 0;
} else if (scroll->otyp == MAGIC_MARKER) {
if (Blind) {
You_cant("feel any Braille writing.");
return 0;
}
if (flags.verbose)
pline("It reads:");
pline("\"Magic Marker(TM) Red Ink Marker Pen. Water Soluble.\"");
if(!u.uconduct.literate++)
livelog_write_string(LL_CONDUCT,
"became literate by reading a magic marker");
tnnt_read(RDBL_MARKER);
return 1;
} else if (scroll->oclass == COIN_CLASS) {
if (Blind)
You("feel the embossed words:");
else if (flags.verbose)
You("read:");
pline("\"1 Zorkmid. 857 GUE. In Frobs We Trust.\"");
if(!u.uconduct.literate++)
livelog_write_string(LL_CONDUCT,
"became literate by reading a coin's engravings");
tnnt_read(RDBL_COIN);
return 1;
} else if (scroll->oartifact == ART_ORB_OF_FATE) {
if (Blind)
You("feel the engraved signature:");
else
pline("It is signed:");
pline("\"Odin.\"");
if(!u.uconduct.literate++)
livelog_write_string(LL_CONDUCT,
"became literate by reading the divine signature of Odin");
return 1;
} else if (scroll->otyp == CANDY_BAR) {
static const char *wrapper_msgs[] = {
"Apollo", /* Lost */
"Moon Crunchy", /* South Park */
"Snacky Cake", "Chocolate Nuggie", "The Small Bar",
"Crispy Yum Yum", "Nilla Crunchie", "Berry Bar",
"Choco Nummer", "Om-nom", /* Cat Macro */
"Fruity Oaty", /* Serenity */
"Wonka Bar" /* Charlie and the Chocolate Factory */
};
if (Blind) {
You_cant("feel any Braille writing.");
return 0;
}
pline("The wrapper reads: \"%s\".",
wrapper_msgs[scroll->o_id % SIZE(wrapper_msgs)]);
if(!u.uconduct.literate++)
livelog_write_string(LL_CONDUCT,
"became literate by reading a candy bar wrapper");
tnnt_read(RDBL_CANDY);
return 1;
} else if (scroll->oclass != SCROLL_CLASS
&& scroll->oclass != SPBOOK_CLASS) {
pline(silly_thing_to, "read");
return 0;
} else if (Blind && (scroll->otyp != SPE_BOOK_OF_THE_DEAD)) {
const char *what = 0;
if (scroll->oclass == SPBOOK_CLASS)
what = "mystic runes";
else if (!scroll->dknown)
what = "formula on the scroll";
if (what) {
pline("Being blind, you cannot read the %s.", what);
return 0;
}
}
confused = (Confusion != 0);
#ifdef MAIL
if (scroll->otyp == SCR_MAIL) {
confused = FALSE; /* override */
/* reading mail is a convenience for the player and takes
place outside the game, so shouldn't affect gameplay;
on the other hand, it starts by explicitly making the
hero actively read something, which is pretty hard
to simply ignore; as a compromise, if the player has
maintained illiterate conduct so far, and this mail
scroll didn't come from bones, ask for confirmation */
if (!u.uconduct.literate) {
if (!scroll->spe && yn(
"Reading mail will violate \"illiterate\" conduct. Read anyway?"
) != 'y')
return 0;
}
}
#endif
/* Actions required to win the game aren't counted towards conduct */
/* Novel conduct is handled in read_tribute so exclude it too*/
if (scroll->otyp != SPE_BOOK_OF_THE_DEAD
&& scroll->otyp != SPE_BLANK_PAPER && scroll->otyp != SCR_BLANK_PAPER
&& scroll->otyp != SPE_NOVEL) {
if(!u.uconduct.literate++)
livelog_printf(LL_CONDUCT, "became literate by reading %s",
scroll->oclass == SPBOOK_CLASS ? "a book" :
scroll->oclass == SCROLL_CLASS ? "a scroll" : "something");
tnnt_read(scroll->oclass == SPBOOK_CLASS ? RDBL_BOOK : RDBL_SCROLL);
}
if (scroll->oclass == SPBOOK_CLASS) {
return study_book(scroll);
}
scroll->in_use = TRUE; /* scroll, not spellbook, now being read */
if (scroll->otyp != SCR_BLANK_PAPER) {
boolean silently = !can_chant(&youmonst);
/* a few scroll feedback messages describe something happening
to the scroll itself, so avoid "it disappears" for those */
nodisappear = (scroll->otyp == SCR_FIRE
|| scroll->otyp == SCR_MISSING_CODE
|| (scroll->otyp == SCR_REMOVE_CURSE
&& scroll->cursed));
if (Blind)
pline(nodisappear
? "You %s the formula on the scroll."
: "As you %s the formula on it, the scroll disappears.",
silently ? "cogitate" : "pronounce");
else
pline(nodisappear ? "You read the scroll."
: "As you read the scroll, it disappears.");
if (confused) {
if (Hallucination)
pline("Being so trippy, you screw up...");
else
pline("Being confused, you %s the magic words...",
silently ? "misunderstand" : "mispronounce");
}
}
if (!seffects(scroll)) {
if (!objects[scroll->otyp].oc_name_known) {
if (known)
learnscroll(scroll);
else if (!objects[scroll->otyp].oc_uname)
docall(scroll);
}
scroll->in_use = FALSE;
if (scroll->otyp != SCR_BLANK_PAPER && scroll->otyp != SCR_MISSING_CODE)
useup(scroll);
}
return 1;
}
STATIC_OVL void
stripspe(obj)
register struct obj *obj;
{
if (obj->blessed || obj->spe <= 0) {
pline1(nothing_happens);
} else {
/* order matters: message, shop handling, actual transformation */
pline("%s briefly.", Yobjnam2(obj, "vibrate"));
costly_alteration(obj, COST_UNCHRG);
obj->spe = 0;
if (obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN)
obj->age = 0;
}
}
STATIC_OVL void
p_glow1(otmp)
register struct obj *otmp;
{
pline("%s briefly.", Yobjnam2(otmp, Blind ? "vibrate" : "glow"));
}
STATIC_OVL void
p_glow2(otmp, color)
register struct obj *otmp;
register const char *color;
{
pline("%s%s%s for a moment.", Yobjnam2(otmp, Blind ? "vibrate" : "glow"),
Blind ? "" : " ", Blind ? "" : hcolor(color));
}
/* Is the object chargeable? For purposes of inventory display; it is
possible to be able to charge things for which this returns FALSE. */
boolean
is_chargeable(obj)
struct obj *obj;
{
if (obj->oclass == WAND_CLASS)
return TRUE;
/* known && !oc_name_known is possible after amnesia/mind flayer */
if (obj->oclass == RING_CLASS)
return (boolean) (objects[obj->otyp].oc_charged
&& (obj->known
|| (obj->dknown
&& objects[obj->otyp].oc_name_known)));
if (is_weptool(obj)) /* specific check before general tools */
return FALSE;
if (obj->oclass == TOOL_CLASS)
return (boolean) objects[obj->otyp].oc_charged;
return FALSE; /* why are weapons/armor considered charged anyway? */
}
/* recharge an object; curse_bless is -1 if the recharging implement
was cursed, +1 if blessed, 0 otherwise. */
void
recharge(obj, curse_bless)
struct obj *obj;
int curse_bless;
{
register int n;
boolean is_cursed, is_blessed;
is_cursed = curse_bless < 0;
is_blessed = curse_bless > 0;
tnnt_achieve(A_CHARGED_AN_OBJECT);
if (obj->oclass == WAND_CLASS) {
int lim = (obj->otyp == WAN_WISHING)
? 3
: (objects[obj->otyp].oc_dir != NODIR) ? 8 : 15;
/* undo any prior cancellation, even when is_cursed */
if (obj->spe == -1)
obj->spe = 0;
/*
* Recharging might cause wands to explode.
* v = number of previous recharges
* v = percentage chance to explode on this attempt
* v = cumulative odds for exploding
* 0 : 0 0
* 1 : 0.29 0.29
* 2 : 2.33 2.62
* 3 : 7.87 10.28
* 4 : 18.66 27.02
* 5 : 36.44 53.62
* 6 : 62.97 82.83
* 7 : 100 100
*/
n = (int) obj->recharged;
if (n > 0 && (obj->otyp == WAN_WISHING
|| (n * n * n > rn2(7 * 7 * 7)))) { /* recharge_limit */
wand_explode(obj, rnd(lim));
return;
}
/* didn't explode, so increment the recharge count */
obj->recharged = (unsigned) (n + 1);
/* now handle the actual recharging */
if (is_cursed) {
stripspe(obj);
} else {
n = (lim == 3) ? 3 : rn1(5, lim + 1 - 5);
if (!is_blessed)
n = rnd(n);
if (obj->spe < n)
obj->spe = n;
else
obj->spe++;
if (obj->otyp == WAN_WISHING && obj->spe > 3) {
wand_explode(obj, 1);
return;
}
if (obj->spe >= lim)
p_glow2(obj, NH_BLUE);
else
p_glow1(obj);
#if 0 /*[shop price doesn't vary by charge count]*/
/* update shop bill to reflect new higher price */
if (obj->unpaid)
alter_cost(obj, 0L);
#endif
}
} else if (obj->oclass == RING_CLASS && objects[obj->otyp].oc_charged) {
/* charging does not affect ring's curse/bless status */
int s = is_blessed ? rnd(3) : is_cursed ? -rnd(2) : 1;
boolean is_on = (obj == uleft || obj == uright);
/* destruction depends on current state, not adjustment */
if (obj->spe > rn2(7) || obj->spe <= -5) {
pline("%s momentarily, then %s!", Yobjnam2(obj, "pulsate"),
otense(obj, "explode"));
if (is_on)
Ring_gone(obj);
s = rnd(3 * abs(obj->spe)); /* amount of damage */
useup(obj);
losehp(Maybe_Half_Phys(s), "exploding ring", KILLED_BY_AN);
} else {
long mask = is_on ? (obj == uleft ? LEFT_RING : RIGHT_RING) : 0L;
pline("%s spins %sclockwise for a moment.", Yname2(obj),
s < 0 ? "counter" : "");
if (s < 0)
costly_alteration(obj, COST_DECHNT);
/* cause attributes and/or properties to be updated */
if (is_on)
Ring_off(obj);
obj->spe += s; /* update the ring while it's off */
if (is_on)
setworn(obj, mask), Ring_on(obj);
/* oartifact: if a touch-sensitive artifact ring is
ever created the above will need to be revised */
/* update shop bill to reflect new higher price */
if (s > 0 && obj->unpaid)
alter_cost(obj, 0L);
}
} else if (obj->oclass == TOOL_CLASS) {
int rechrg = (int) obj->recharged;
if (objects[obj->otyp].oc_charged) {
/* tools don't have a limit, but the counter used does */
if (rechrg < 7) /* recharge_limit */
obj->recharged++;
}
switch (obj->otyp) {
case BELL_OF_OPENING:
if (is_cursed)
stripspe(obj);
else if (is_blessed)
obj->spe += rnd(3);
else
obj->spe += 1;
if (obj->spe > 5)
obj->spe = 5;
break;
case MAGIC_MARKER:
case TINNING_KIT:
case EXPENSIVE_CAMERA:
if (is_cursed)
stripspe(obj);
else if (rechrg
&& obj->otyp
== MAGIC_MARKER) { /* previously recharged */
obj->recharged = 1; /* override increment done above */
if (obj->spe < 3)
Your("marker seems permanently dried out.");
else
pline1(nothing_happens);
} else if (is_blessed) {
n = rn1(16, 15); /* 15..30 */
if (obj->spe + n <= 50)
obj->spe = 50;
else if (obj->spe + n <= 75)
obj->spe = 75;
else {
int chrg = (int) obj->spe;
if ((chrg + n) > 127)
obj->spe = 127;
else
obj->spe += n;
}
p_glow2(obj, NH_BLUE);
} else {
n = rn1(11, 10); /* 10..20 */
if (obj->spe + n <= 50)
obj->spe = 50;
else {
int chrg = (int) obj->spe;
if ((chrg + n) > 127)
obj->spe = 127;
else
obj->spe += n;
}
p_glow2(obj, NH_WHITE);
}
break;
case OIL_LAMP:
case BRASS_LANTERN:
if (is_cursed) {
stripspe(obj);
if (obj->lamplit) {
if (!Blind)
pline("%s out!", Tobjnam(obj, "go"));
end_burn(obj, TRUE);
}
} else if (is_blessed) {
obj->spe = 1;
obj->age = 1500;
p_glow2(obj, NH_BLUE);
} else {
obj->spe = 1;
obj->age += 750;
if (obj->age > 1500)
obj->age = 1500;
p_glow1(obj);
}
break;
case CRYSTAL_BALL:
if (is_cursed) {
stripspe(obj);
} else if (is_blessed) {
obj->spe = 6;
p_glow2(obj, NH_BLUE);
} else {
if (obj->spe < 5) {
obj->spe++;
p_glow1(obj);
} else
pline1(nothing_happens);
}
break;
case HORN_OF_PLENTY:
case BAG_OF_TRICKS:
case CAN_OF_GREASE:
if (is_cursed) {
stripspe(obj);
} else if (is_blessed) {
if (obj->spe <= 10)
obj->spe += rn1(10, 6);
else
obj->spe += rn1(5, 6);
if (obj->spe > 50)
obj->spe = 50;
p_glow2(obj, NH_BLUE);
} else {
obj->spe += rnd(5);
if (obj->spe > 50)
obj->spe = 50;
p_glow1(obj);
}
break;
case MAGIC_FLUTE:
case MAGIC_HARP:
case FROST_HORN:
case FIRE_HORN:
case DRUM_OF_EARTHQUAKE:
if (is_cursed) {
stripspe(obj);
} else if (is_blessed) {
obj->spe += d(2, 4);
if (obj->spe > 20)
obj->spe = 20;
p_glow2(obj, NH_BLUE);
} else {
obj->spe += rnd(4);
if (obj->spe > 20)
obj->spe = 20;
p_glow1(obj);
}
break;
default:
goto not_chargable;
/*NOTREACHED*/
break;
} /* switch */
} else {
not_chargable:
You("have a feeling of loss.");
}
}
/* Forget known information about this object type. */
STATIC_OVL void
forget_single_object(obj_id)
int obj_id;
{
objects[obj_id].oc_name_known = 0;
objects[obj_id].oc_pre_discovered = 0; /* a discovery when relearned */
if (objects[obj_id].oc_uname) {
free((genericptr_t) objects[obj_id].oc_uname);
objects[obj_id].oc_uname = 0;
}
undiscover_object(obj_id); /* after clearing oc_name_known */
/* clear & free object names from matching inventory items too? */
}
#if 0 /* here if anyone wants it.... */
/* Forget everything known about a particular object class. */
STATIC_OVL void
forget_objclass(oclass)
int oclass;
{
int i;
for (i = bases[oclass];
i < NUM_OBJECTS && objects[i].oc_class == oclass; i++)
forget_single_object(i);
}
#endif
/* randomize the given list of numbers 0 <= i < count */
STATIC_OVL void
randomize(indices, count)
int *indices;
int count;
{
int i, iswap, temp;
for (i = count - 1; i > 0; i--) {
if ((iswap = rn2(i + 1)) == i)
continue;
temp = indices[i];
indices[i] = indices[iswap];
indices[iswap] = temp;
}
}
/* Forget % of known objects. */
void
forget_objects(percent)
int percent;
{
int i, count;
int indices[NUM_OBJECTS];
if (percent == 0)
return;
if (percent <= 0 || percent > 100) {
impossible("forget_objects: bad percent %d", percent);
return;
}
indices[0] = 0; /* lint suppression */
for (count = 0, i = 1; i < NUM_OBJECTS; i++)
if (OBJ_DESCR(objects[i])
&& (objects[i].oc_name_known || objects[i].oc_uname))
indices[count++] = i;
if (count > 0) {
randomize(indices, count);
/* forget first % of randomized indices */
count = ((count * percent) + rn2(100)) / 100;
for (i = 0; i < count; i++)
forget_single_object(indices[i]);
}
}
/* Forget some or all of map (depends on parameters). */
void
forget_map(howmuch)
int howmuch;
{
register int zx, zy;
if (Sokoban)
return;
known = TRUE;
for (zx = 0; zx < COLNO; zx++)
for (zy = 0; zy < ROWNO; zy++)
if (howmuch & ALL_MAP || rn2(7)) {
/* Zonk all memory of this location. */
levl[zx][zy].seenv = 0;
levl[zx][zy].waslit = 0;
levl[zx][zy].glyph = cmap_to_glyph(S_stone);
lastseentyp[zx][zy] = STONE;
}
/* forget overview data for this level */
forget_mapseen(ledger_no(&u.uz));
}
/* Forget all traps on the level. */
void
forget_traps()
{
register struct trap *trap;
/* forget all traps (except the one the hero is in :-) */
for (trap = ftrap; trap; trap = trap->ntrap)
if ((trap->tx != u.ux || trap->ty != u.uy) && (trap->ttyp != HOLE))
trap->tseen = 0;
}
/*
* Forget given % of all levels that the hero has visited and not forgotten,
* except this one.
*/
void
forget_levels(percent)
int percent;
{
int i, count;
xchar maxl, this_lev;
int indices[MAXLINFO];
if (percent == 0)
return;
if (percent <= 0 || percent > 100) {
impossible("forget_levels: bad percent %d", percent);
return;
}
this_lev = ledger_no(&u.uz);
maxl = maxledgerno();
/* count & save indices of non-forgotten visited levels */
/* Sokoban levels are pre-mapped for the player, and should stay
* so, or they become nearly impossible to solve. But try to
* shift the forgetting elsewhere by fiddling with percent
* instead of forgetting fewer levels.
*/
indices[0] = 0; /* lint suppression */
for (count = 0, i = 0; i <= maxl; i++)
if ((level_info[i].flags & VISITED)
&& !(level_info[i].flags & FORGOTTEN) && i != this_lev) {
if (ledger_to_dnum(i) == sokoban_dnum)
percent += 2;
else
indices[count++] = i;
}
if (percent > 100)
percent = 100;
if (count > 0) {
randomize(indices, count);
/* forget first % of randomized indices */
count = ((count * percent) + 50) / 100;
for (i = 0; i < count; i++) {
level_info[indices[i]].flags |= FORGOTTEN;
forget_mapseen(indices[i]);
}
}
}
/*
* Forget some things (e.g. after reading a scroll of amnesia). When called,
* the following are always forgotten:
* - felt ball & chain
* - traps
* - part (6 out of 7) of the map
*
* Other things are subject to flags:
* howmuch & ALL_MAP = forget whole map
* howmuch & ALL_SPELLS = forget all spells
*/
STATIC_OVL void
forget(howmuch)
int howmuch;
{
if (Punished)
u.bc_felt = 0; /* forget felt ball&chain */
forget_map(howmuch);
forget_traps();
/* 1 in 3 chance of forgetting some levels */
if (!rn2(3))
forget_levels(rn2(25));
/* 1 in 3 chance of forgetting some objects */
if (!rn2(3))
forget_objects(rn2(25));
if (howmuch & ALL_SPELLS)
losespells();
/*
* Make sure that what was seen is restored correctly. To do this,
* we need to go blind for an instant --- turn off the display,
* then restart it. All this work is needed to correctly handle
* walls which are stone on one side and wall on the other. Turning
* off the seen bits above will make the wall revert to stone, but
* there are cases where we don't want this to happen. The easiest
* thing to do is to run it through the vision system again, which
* is always correct.
*/
docrt(); /* this correctly will reset vision */
}
/* monster is hit by scroll of taming's effect */
STATIC_OVL int
maybe_tame(mtmp, sobj)
struct monst *mtmp;
struct obj *sobj;
{
int was_tame = mtmp->mtame;
unsigned was_peaceful = mtmp->mpeaceful;
if (sobj->cursed) {
setmangry(mtmp, FALSE);
if (was_peaceful && !mtmp->mpeaceful)
return -1;
} else {
if (mtmp->isshk)
make_happy_shk(mtmp, FALSE);
else if (!resist(mtmp, sobj->oclass, 0, NOTELL))
(void) tamedog(mtmp, (struct obj *) 0);
if ((!was_peaceful && mtmp->mpeaceful) || (!was_tame && mtmp->mtame))
return 1;
}
return 0;
}
STATIC_OVL boolean
get_valid_stinking_cloud_pos(x,y)
int x,y;
{
return (!(!isok(x,y) || !cansee(x, y)
|| !ACCESSIBLE(levl[x][y].typ)
|| distu(x, y) >= 32));
}
STATIC_OVL boolean
is_valid_stinking_cloud_pos(x, y, showmsg)
int x, y;
boolean showmsg;
{