forked from NetHack/NetHack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pager.c
2663 lines (2479 loc) · 98.1 KB
/
pager.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.7 pager.c $NHDT-Date: 1655120486 2022/06/13 11:41:26 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.225 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2018. */
/* NetHack may be freely redistributed. See license for details. */
/* This file contains the command routines dowhatis() and dohelp() and */
/* a few other help related facilities */
#include "hack.h"
#include "dlb.h"
static boolean is_swallow_sym(int);
static int append_str(char *, const char *);
static void trap_description(char *, int, coordxy, coordxy);
static void look_at_object(char *, coordxy, coordxy, int);
static void look_at_monster(char *, char *, struct monst *, coordxy, coordxy);
static struct permonst *lookat(coordxy, coordxy, char *, char *);
static void checkfile(char *, struct permonst *, unsigned, char *);
static int add_cmap_descr(int, int, int, int, coord,
const char *, const char *,
boolean *, const char **, char *);
static void look_region_nearby(coordxy *, coordxy *, coordxy *, coordxy *,
boolean);
static void look_all(boolean, boolean);
static void look_traps(boolean);
static void do_supplemental_info(char *, struct permonst *, boolean);
static void whatdoes_help(void);
static void docontact(void);
static void dispfile_help(void);
static void dispfile_shelp(void);
static void dispfile_optionfile(void);
static void dispfile_optmenu(void);
static void dispfile_license(void);
static void dispfile_debughelp(void);
static void dispfile_usagehelp(void);
static void hmenu_doextversion(void);
static void hmenu_dohistory(void);
static void hmenu_dowhatis(void);
static void hmenu_dowhatdoes(void);
static void hmenu_doextlist(void);
static void domenucontrols(void);
#ifdef PORT_HELP
extern void port_help(void);
#endif
static char *setopt_cmd(char *);
static boolean add_quoted_engraving(coordxy, coordxy, char *);
enum checkfileflags {
chkfilNone = 0,
chkfilUsrTyped = 1,
chkfilDontAsk = 2,
chkfilIaCheck = 4,
};
/* checkfile() sets this in lieu of a return value if given IaCheck flag */
static char checkfile_hack; /* once set, always 'F' or 'T' */
static const char invisexplain[] = "remembered, unseen, creature",
altinvisexplain[] = "unseen creature"; /* for clairvoyance */
/* Returns "true" for characters that could represent a monster's stomach. */
static boolean
is_swallow_sym(int c)
{
int i;
for (i = S_sw_tl; i <= S_sw_br; i++)
if ((int) gs.showsyms[i] == c)
return TRUE;
return FALSE;
}
/* Append " or "+new_str to the end of buf if new_str doesn't already exist
as a substring of buf. Return 1 if the string was appended, 0 otherwise.
It is expected that buf is of size BUFSZ. */
static int
append_str(char *buf, const char *new_str)
{
static const char sep[] = " or ";
size_t oldlen, space_left;
if (strstri(buf, new_str))
return 0; /* already present */
oldlen = strlen(buf);
if (oldlen >= BUFSZ - 1) {
if (oldlen > BUFSZ - 1)
impossible("append_str: 'buf' contains %lu characters.",
(unsigned long) oldlen);
return 0; /* no space available */
}
/* some space available, but not necessarily enough for full append */
space_left = BUFSZ - 1 - oldlen; /* space remaining in buf */
(void) strncat(buf, sep, space_left);
if (space_left > sizeof sep - 1)
(void) strncat(buf, new_str, space_left - (sizeof sep - 1));
return 1; /* something was appended, possibly just part of " or " */
}
/* shared by monster probing (via query_objlist!) as well as lookat() */
char *
self_lookat(char *outbuf)
{
char race[QBUFSZ], trapbuf[QBUFSZ];
/* include race with role unless polymorphed */
race[0] = '\0';
if (!Upolyd)
Sprintf(race, "%s ", gu.urace.adj);
Sprintf(outbuf, "%s%s%s called %s",
/* being blinded may hide invisibility from self */
(Invis && (senseself() || !Blind)) ? "invisible " : "", race,
pmname(&mons[u.umonnum], Ugender), gp.plname);
if (u.usteed)
Sprintf(eos(outbuf), ", mounted on %s", y_monnam(u.usteed));
if (u.uundetected || (Upolyd && U_AP_TYPE))
mhidden_description(&gy.youmonst, FALSE, eos(outbuf));
if (Punished)
Sprintf(eos(outbuf), ", chained to %s",
uball ? ansimpleoname(uball) : "nothing?");
if (u.utrap) /* bear trap, pit, web, in-floor, in-lava, tethered */
Sprintf(eos(outbuf), ", %s", trap_predicament(trapbuf, 0, FALSE));
return outbuf;
}
/* format a description of 'mon's health for look_at_monster(), done_in_by();
result isn't Healer-specific (not trained for arbitrary creatures) */
char *
monhealthdescr(struct monst *mon, boolean addspace, char *outbuf)
{
#if 0 /* [disable this for the time being] */
int mhp_max = max(mon->mhpmax, 1), /* bullet proofing */
pct = (mon->mhp * 100) / mhp_max;
if (mon->mhp >= mhp_max)
Strcpy(outbuf, "uninjured");
else if (mon->mhp <= 1 || pct < 5)
Sprintf(outbuf, "%s%s", (mon->mhp > 0) ? "nearly " : "",
!nonliving(mon->data) ? "deceased" : "defunct");
else
Sprintf(outbuf, "%swounded",
(pct >= 95) ? "barely "
: (pct >= 80) ? "slightly "
: (pct < 20) ? "heavily "
: "");
if (addspace)
(void) strkitten(outbuf, ' ');
#else
nhUse(mon);
nhUse(addspace);
*outbuf = '\0';
#endif
return outbuf;
}
/* copy a trap's description into outbuf[] */
static void
trap_description(char *outbuf, int tnum, coordxy x, coordxy y)
{
/*
* Trap detection used to display a bear trap at locations having
* a trapped door or trapped container or both. They're semi-real
* traps now (defined trap types but not part of ftrap chain).
*/
if (trapped_chest_at(tnum, x, y))
Strcpy(outbuf, "trapped chest"); /* might actually be a large box */
else if (trapped_door_at(tnum, x, y))
Strcpy(outbuf, "trapped door"); /* not "trap door"... */
else
Strcpy(outbuf, trapname(tnum, FALSE));
return;
}
/* describe a hidden monster; used for look_at during extended monster
detection and for probing; also when looking at self */
void
mhidden_description(
struct monst *mon,
boolean altmon, /* for probing: if mimicking a monster, say so */
char *outbuf)
{
struct obj *otmp;
boolean fakeobj, isyou = (mon == &gy.youmonst);
coordxy x = isyou ? u.ux : mon->mx, y = isyou ? u.uy : mon->my;
int glyph = (gl.level.flags.hero_memory && !isyou) ? levl[x][y].glyph
: glyph_at(x, y);
*outbuf = '\0';
if (M_AP_TYPE(mon) == M_AP_FURNITURE
|| M_AP_TYPE(mon) == M_AP_OBJECT) {
Strcpy(outbuf, ", mimicking ");
if (M_AP_TYPE(mon) == M_AP_FURNITURE) {
Strcat(outbuf, an(defsyms[mon->mappearance].explanation));
} else if (M_AP_TYPE(mon) == M_AP_OBJECT
/* remembered glyph, not glyph_at() which is 'mon' */
&& glyph_is_object(glyph)) {
objfrommap:
otmp = (struct obj *) 0;
fakeobj = object_from_map(glyph, x, y, &otmp);
Strcat(outbuf, (otmp && otmp->otyp != STRANGE_OBJECT)
? ansimpleoname(otmp)
: an(obj_descr[STRANGE_OBJECT].oc_name));
if (fakeobj) {
otmp->where = OBJ_FREE; /* object_from_map set to OBJ_FLOOR */
dealloc_obj(otmp);
}
} else {
Strcat(outbuf, something);
}
} else if (M_AP_TYPE(mon) == M_AP_MONSTER) {
if (altmon)
Sprintf(outbuf, ", masquerading as %s",
an(pmname(&mons[mon->mappearance], Mgender(mon))));
} else if (isyou ? u.uundetected : mon->mundetected) {
Strcpy(outbuf, ", hiding");
if (hides_under(mon->data)) {
Strcat(outbuf, " under ");
/* remembered glyph, not glyph_at() which is 'mon' */
if (glyph_is_object(glyph))
goto objfrommap;
Strcat(outbuf, something);
} else if (is_hider(mon->data)) {
Sprintf(eos(outbuf), " on the %s",
ceiling_hider(mon->data) ? "ceiling"
: surface(x, y)); /* trapper */
} else {
if (mon->data->mlet == S_EEL && is_pool(x, y))
Strcat(outbuf, " in murky water");
}
}
}
/* extracted from lookat(); also used by namefloorobj() */
boolean
object_from_map(int glyph, coordxy x, coordxy y, struct obj **obj_p)
{
boolean fakeobj = FALSE, mimic_obj = FALSE;
struct monst *mtmp;
struct obj *otmp;
int glyphotyp = glyph_to_obj(glyph);
*obj_p = (struct obj *) 0;
/* TODO: check inside containers in case glyph came from detection */
if ((otmp = sobj_at(glyphotyp, x, y)) == 0)
for (otmp = gl.level.buriedobjlist; otmp; otmp = otmp->nobj)
if (otmp->ox == x && otmp->oy == y && otmp->otyp == glyphotyp)
break;
/* there might be a mimic here posing as an object */
mtmp = m_at(x, y);
if (mtmp && is_obj_mappear(mtmp, (unsigned) glyphotyp)) {
otmp = 0;
mimic_obj = TRUE;
} else
mtmp = 0;
if (!otmp || otmp->otyp != glyphotyp) {
/* this used to exclude STRANGE_OBJECT; now caller deals with it */
otmp = mksobj(glyphotyp, FALSE, FALSE);
if (!otmp)
return FALSE;
fakeobj = TRUE;
if (otmp->oclass == COIN_CLASS)
otmp->quan = 2L; /* to force pluralization */
else if (otmp->otyp == SLIME_MOLD)
otmp->spe = gc.context.current_fruit; /* give it a type */
if (mtmp && has_mcorpsenm(mtmp)) { /* mimic as corpse/statue */
if (otmp->otyp == SLIME_MOLD)
/* override gc.context.current_fruit to avoid
look, use 'O' to make new named fruit, look again
giving different results when current_fruit changes */
otmp->spe = MCORPSENM(mtmp);
else
otmp->corpsenm = MCORPSENM(mtmp);
} else if (otmp->otyp == CORPSE && glyph_is_body(glyph)) {
otmp->corpsenm = glyph_to_body_corpsenm(glyph);
} else if (otmp->otyp == STATUE && glyph_is_statue(glyph)) {
otmp->corpsenm = glyph_to_statue_corpsenm(glyph);
}
if (otmp->otyp == LEASH)
otmp->leashmon = 0;
/* extra fields needed for shop price with doname() formatting */
otmp->where = OBJ_FLOOR;
otmp->ox = x, otmp->oy = y;
otmp->no_charge = (otmp->otyp == STRANGE_OBJECT && costly_spot(x, y));
}
/* if located at adjacent spot, mark it as having been seen up close
(corpse type will be known even if dknown is 0, so we don't need a
touch check for cockatrice corpse--we're looking without touching) */
if (otmp && next2u(x, y) && !Blind && !Hallucination
/* redundant: we only look for an object which matches current
glyph among floor and buried objects; when !Blind, any buried
object's glyph will have been replaced by whatever is present
on the surface as soon as we moved next to its spot */
&& (fakeobj || otmp->where == OBJ_FLOOR) /* not buried */
/* terrain mode views what's already known, doesn't learn new stuff */
&& !iflags.terrainmode) /* so don't set dknown when in terrain mode */
otmp->dknown = 1; /* if a pile, clearly see the top item only */
if (fakeobj && mtmp && mimic_obj
&& (otmp->dknown || (M_AP_FLAG(mtmp) & M_AP_F_DKNOWN))) {
mtmp->m_ap_type |= M_AP_F_DKNOWN;
otmp->dknown = 1;
}
*obj_p = otmp;
return fakeobj; /* when True, caller needs to dealloc *obj_p */
}
static void
look_at_object(
char *buf, /* output buffer */
coordxy x, coordxy y,
int glyph)
{
struct obj *otmp = 0;
boolean fakeobj = object_from_map(glyph, x, y, &otmp);
if (otmp) {
Strcpy(buf, (otmp->otyp != STRANGE_OBJECT)
? distant_name(otmp, otmp->dknown ? doname_with_price
: doname_vague_quan)
: obj_descr[STRANGE_OBJECT].oc_name);
if (fakeobj) {
otmp->where = OBJ_FREE; /* object_from_map set it to OBJ_FLOOR */
dealloc_obj(otmp), otmp = 0;
}
} else
Strcpy(buf, something); /* sanity precaution */
if (otmp && otmp->where == OBJ_BURIED)
Strcat(buf, " (buried)");
else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR)
Strcat(buf, " embedded in stone");
else if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR)
Strcat(buf, " embedded in a wall");
else if (closed_door(x, y))
Strcat(buf, " embedded in a door");
else if (is_pool(x, y))
Strcat(buf, " in water");
else if (is_lava(x, y))
Strcat(buf, " in molten lava"); /* [can this ever happen?] */
return;
}
static void
look_at_monster(
char *buf,
char *monbuf, /* buf: output, monbuf: optional output */
struct monst *mtmp,
coordxy x, coordxy y)
{
char *name, monnambuf[BUFSZ], healthbuf[BUFSZ];
boolean accurate = !Hallucination;
name = (mtmp->data == &mons[PM_COYOTE] && accurate)
? coyotename(mtmp, monnambuf)
: distant_monnam(mtmp, ARTICLE_NONE, monnambuf);
Sprintf(buf, "%s%s%s%s",
(mtmp->mx != x || mtmp->my != y)
? ((mtmp->isshk && accurate) ? "tail of " : "tail of a ")
: "",
accurate ? monhealthdescr(mtmp, TRUE, healthbuf) : "",
(mtmp->mtame && accurate)
? "tame "
: (mtmp->mpeaceful && accurate)
? "peaceful "
: "",
name);
if (u.ustuck == mtmp) {
if (u.uswallow || iflags.save_uswallow) /* monster detection */
Strcat(buf, digests(mtmp->data) ? ", swallowing you"
: ", engulfing you");
else
Strcat(buf, (Upolyd && sticks(gy.youmonst.data))
? ", being held" : ", holding you");
}
/* if mtmp isn't able to move (other than because it is a type of
monster that never moves), say so [excerpt from mstatusline() for
stethoscope or wand of probing] */
if (mtmp->mfrozen)
/* unfortunately mfrozen covers temporary sleep and being busy
(donning armor, for instance) as well as paralysis */
Strcat(buf, ", can't move (paralyzed or sleeping or busy)");
else if (mtmp->msleeping)
/* sleeping for an indeterminate duration */
Strcat(buf, ", asleep");
else if ((mtmp->mstrategy & STRAT_WAITMASK) != 0)
/* arbitrary reason why it isn't moving */
Strcat(buf, ", meditating");
if (mtmp->mleashed)
Strcat(buf, ", leashed to you");
if (mtmp->mtrapped && cansee(mtmp->mx, mtmp->my)) {
struct trap *t = t_at(mtmp->mx, mtmp->my);
int tt = t ? t->ttyp : NO_TRAP;
/* newsym lets you know of the trap, so mention it here */
if (tt == BEAR_TRAP || is_pit(tt) || tt == WEB) {
Sprintf(eos(buf), ", trapped in %s", an(trapname(tt, FALSE)));
t->tseen = 1;
}
}
/* we know the hero sees a monster at this location, but if it's shown
due to persistent monster detection he might remember something else */
if (mtmp->mundetected || M_AP_TYPE(mtmp))
mhidden_description(mtmp, FALSE, eos(buf));
if (monbuf) {
unsigned how_seen = howmonseen(mtmp);
monbuf[0] = '\0';
if (how_seen != 0 && how_seen != MONSEEN_NORMAL) {
if (how_seen & MONSEEN_NORMAL) {
Strcat(monbuf, "normal vision");
how_seen &= ~MONSEEN_NORMAL;
/* how_seen can't be 0 yet... */
if (how_seen)
Strcat(monbuf, ", ");
}
if (how_seen & MONSEEN_SEEINVIS) {
Strcat(monbuf, "see invisible");
how_seen &= ~MONSEEN_SEEINVIS;
if (how_seen)
Strcat(monbuf, ", ");
}
if (how_seen & MONSEEN_INFRAVIS) {
Strcat(monbuf, "infravision");
how_seen &= ~MONSEEN_INFRAVIS;
if (how_seen)
Strcat(monbuf, ", ");
}
if (how_seen & MONSEEN_TELEPAT) {
Strcat(monbuf, "telepathy");
how_seen &= ~MONSEEN_TELEPAT;
if (how_seen)
Strcat(monbuf, ", ");
}
if (how_seen & MONSEEN_XRAYVIS) {
/* Eyes of the Overworld */
Strcat(monbuf, "astral vision");
how_seen &= ~MONSEEN_XRAYVIS;
if (how_seen)
Strcat(monbuf, ", ");
}
if (how_seen & MONSEEN_DETECT) {
Strcat(monbuf, "monster detection");
how_seen &= ~MONSEEN_DETECT;
if (how_seen)
Strcat(monbuf, ", ");
}
if (how_seen & MONSEEN_WARNMON) {
if (Hallucination) {
Strcat(monbuf, "paranoid delusion");
} else {
unsigned long mW = (gc.context.warntype.obj
| gc.context.warntype.polyd),
m2 = mtmp->data->mflags2;
const char *whom = ((mW & M2_HUMAN & m2) ? "human"
: (mW & M2_ELF & m2) ? "elf"
: (mW & M2_ORC & m2) ? "orc"
: (mW & M2_DEMON & m2) ? "demon"
: pmname(mtmp->data,
Mgender(mtmp)));
Sprintf(eos(monbuf), "warned of %s", makeplural(whom));
}
how_seen &= ~MONSEEN_WARNMON;
if (how_seen)
Strcat(monbuf, ", ");
}
/* should have used up all the how_seen bits by now */
if (how_seen) {
impossible("lookat: unknown method of seeing monster");
Sprintf(eos(monbuf), "(%u)", how_seen);
}
} /* seen by something other than normal vision */
} /* monbuf is non-null */
}
/* describe a pool location's contents; might return a static buffer so
caller should use it or copy it before calling waterbody_name() again
[3.7: moved here from mkmaze.c] */
const char *
waterbody_name(coordxy x, coordxy y)
{
static char pooltype[40];
struct rm *lev;
schar ltyp;
boolean hallucinate = Hallucination && !gp.program_state.gameover;
if (!isok(x, y))
return "drink"; /* should never happen */
lev = &levl[x][y];
ltyp = lev->typ;
if (ltyp == DRAWBRIDGE_UP)
ltyp = db_under_typ(lev->drawbridgemask);
if (ltyp == LAVAPOOL) {
Snprintf(pooltype, sizeof pooltype, "molten %s", hliquid("lava"));
return pooltype;
} else if (ltyp == ICE) {
if (!hallucinate)
return "ice";
Snprintf(pooltype, sizeof pooltype, "frozen %s", hliquid("water"));
return pooltype;
} else if (ltyp == POOL) {
Snprintf(pooltype, sizeof pooltype, "pool of %s", hliquid("water"));
return pooltype;
} else if (ltyp == MOAT) {
/* a bit of extra flavor over general moat */
if (hallucinate) {
Snprintf(pooltype, sizeof pooltype, "deep %s", hliquid("water"));
return pooltype;
} else if (Is_medusa_level(&u.uz)) {
/* somewhat iffy since ordinary stairs can take you beneath,
but previous generic "water" was rather anti-climactic */
return "shallow sea";
} else if (Is_juiblex_level(&u.uz)) {
return "swamp";
} else if (Role_if(PM_SAMURAI) && Is_qstart(&u.uz)) {
/* samurai quest home level has two isolated moat spots;
they sound silly if farlook describes them as such */
return "pond";
} else {
return "moat";
}
} else if (IS_WATERWALL(ltyp)) {
if (Is_waterlevel(&u.uz))
return "limitless water"; /* even if hallucinating */
Snprintf(pooltype, sizeof pooltype, "wall of %s", hliquid("water"));
return pooltype;
} else if (ltyp == LAVAWALL) {
Snprintf(pooltype, sizeof pooltype, "wall of %s", hliquid("lava"));
return pooltype;
}
/* default; should be unreachable */
return "water"; /* don't hallucinate this as some other liquid */
}
/*
* Return the name of the glyph found at (x,y).
* If not hallucinating and the glyph is a monster, also monster data.
*/
static struct permonst *
lookat(coordxy x, coordxy y, char *buf, char *monbuf)
{
struct monst *mtmp = (struct monst *) 0;
struct permonst *pm = (struct permonst *) 0;
int glyph;
buf[0] = monbuf[0] = '\0';
glyph = glyph_at(x, y);
if (u_at(x, y) && canspotself()
&& !(iflags.save_uswallow
&& glyph == mon_to_glyph(u.ustuck, rn2_on_display_rng))
&& (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0)) {
/* fill in buf[] */
(void) self_lookat(buf);
/* file lookup can't distinguish between "gnomish wizard" monster
and correspondingly named player character, always picking the
former; force it to find the general "wizard" entry instead */
if (Role_if(PM_WIZARD) && Race_if(PM_GNOME) && !Upolyd)
pm = &mons[PM_WIZARD];
/* When you see yourself normally, no explanation is appended
(even if you could also see yourself via other means).
Sensing self while blind or swallowed is treated as if it
were by normal vision (cf canseeself()). */
if ((Invisible || u.uundetected) && !Blind
&& !(u.uswallow || iflags.save_uswallow)) {
unsigned how = 0;
if (Infravision)
how |= 1;
if (Unblind_telepat)
how |= 2;
if (Detect_monsters)
how |= 4;
if (how)
Sprintf(eos(buf), " [seen: %s%s%s%s%s]",
(how & 1) ? "infravision" : "",
/* add comma if telep and infrav */
((how & 3) > 2) ? ", " : "",
(how & 2) ? "telepathy" : "",
/* add comma if detect and (infrav or telep or both) */
((how & 7) > 4) ? ", " : "",
(how & 4) ? "monster detection" : "");
}
} else if (u.uswallow) {
/* when swallowed, we're only called for spots adjacent to hero,
and blindness doesn't prevent hero from feeling what holds him */
Sprintf(buf, "interior of %s", a_monnam(u.ustuck));
pm = u.ustuck->data;
} else if (glyph_is_monster(glyph)) {
gb.bhitpos.x = x;
gb.bhitpos.y = y;
if ((mtmp = m_at(x, y)) != 0) {
look_at_monster(buf, monbuf, mtmp, x, y);
pm = mtmp->data;
} else if (Hallucination) {
/* 'monster' must actually be a statue */
Strcpy(buf, rndmonnam((char *) 0));
}
} else if (glyph_is_object(glyph)) {
look_at_object(buf, x, y, glyph); /* fill in buf[] */
} else if (glyph_is_trap(glyph)) {
int tnum = glyph_to_trap(glyph);
trap_description(buf, tnum, x, y);
} else if (glyph_is_warning(glyph)) {
int warnindx = glyph_to_warning(glyph);
Strcpy(buf, def_warnsyms[warnindx].explanation);
} else if (glyph_is_nothing(glyph)) {
Strcpy(buf, "dark part of a room");
} else if (glyph_is_unexplored(glyph)) {
if (Underwater && !Is_waterlevel(&u.uz)) {
/* "unknown" == previously mapped but not visible when
submerged; better terminology appreciated... */
Strcpy(buf, (next2u(x, y)) ? "land" : "unknown");
} else {
Strcpy(buf, "unexplored area");
}
} else if (glyph_is_invisible(glyph)) {
/* already handled */
} else if (!glyph_is_cmap(glyph)) {
Strcpy(buf, "unexplored area");
} else {
int amsk;
aligntyp algn;
short symidx = glyph_to_cmap(glyph);
switch (symidx) {
case S_altar:
amsk = altarmask_at(x, y);
algn = Amask2align(amsk & AM_MASK);
Sprintf(buf, "%s %saltar",
/* like endgame high priests, endgame high altars
are only recognizable when immediately adjacent */
(Is_astralevel(&u.uz) && !next2u(x, y)
&& (amsk & AM_SANCTUM))
? "aligned"
: align_str(algn),
(amsk & AM_SANCTUM) ? "high " : "");
break;
case S_ndoor:
if (is_drawbridge_wall(x, y) >= 0)
Strcpy(buf, "open drawbridge portcullis");
else if ((levl[x][y].doormask & ~D_TRAPPED) == D_BROKEN)
Strcpy(buf, "broken door");
else
Strcpy(buf, "doorway");
break;
case S_cloud:
Strcpy(buf,
Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud");
break;
case S_pool:
case S_water:
case S_lava:
case S_ice: /* for hallucination; otherwise defsyms[] would be fine */
Strcpy(buf, waterbody_name(x, y));
break;
case S_engroom:
case S_engrcorr:
Strcpy(buf, "engraving");
break;
case S_stone:
if (!levl[x][y].seenv) {
Strcpy(buf, "unexplored");
break;
} else if (Underwater && !Is_waterlevel(&u.uz)) {
/* "unknown" == previously mapped but not visible when
submerged; better terminology appreciated... */
Strcpy(buf, (next2u(x, y)) ? "land" : "unknown");
break;
} else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR) {
Strcpy(buf, "stone");
break;
}
/*FALLTHRU*/
default:
Strcpy(buf, defsyms[symidx].explanation);
break;
}
}
return (pm && !Hallucination) ? pm : (struct permonst *) 0;
}
/* used to decide whether the context-sensitive inventory action menu for
item 'otmp' should include the "/ - look up this item" choice */
boolean
ia_checkfile(struct obj *otmp)
{
char itemnam[BUFSZ];
checkfile_hack = 'F'; /* checkfile() might change it */
/* singular() of xname() of otmp is what "/i" looks up */
Strcpy(itemnam, singular(otmp, xname));
checkfile(itemnam, (struct permonst *) 0,
chkfilIaCheck | chkfilDontAsk, (char *) 0);
return (checkfile_hack == 'T');
}
/*
* Look in the "data" file for more info. Called if the user typed in the
* whole name (user_typed_name == TRUE), or we've found a possible match
* with a character/glyph and flags.help is TRUE.
*
* NOTE: when (user_typed_name == FALSE), inp is considered read-only and
* must not be changed directly, e.g. via lcase(). We want to force
* lcase() for data.base lookup so that we can have a clean key.
* Therefore, we create a copy of inp _just_ for data.base lookup.
*/
static void
checkfile(
char *inp, /* string to look up */
struct permonst *pm, /* monster type to look up (overrides 'inp') */
unsigned chkflags,
char *supplemental_name)
{
dlb *fp;
char buf[BUFSZ], newstr[BUFSZ], givenname[BUFSZ];
char *ep, *dbase_str;
boolean user_typed_name = (chkflags & chkfilUsrTyped) != 0,
without_asking = (chkflags & chkfilDontAsk) != 0,
ia_checking = (chkflags & chkfilIaCheck) != 0;
unsigned long txt_offset = 0L;
winid datawin = WIN_ERR;
fp = dlb_fopen(DATAFILE, "r");
if (!fp) {
pline("Cannot open 'data' file!");
return;
}
/* If someone passed us garbage, prevent fault. */
if (!inp || strlen(inp) > (BUFSZ - 1)) {
impossible("bad do_look buffer passed (%s)!",
!inp ? "null" : "too long");
goto checkfile_done;
}
/* To prevent the need for entries in data.base like *ngel to account
* for Angel and angel, make the lookup string the same for both
* user_typed_name and picked name.
*/
if (pm != (struct permonst *) 0 && !user_typed_name)
dbase_str = strcpy(newstr, pm->pmnames[NEUTRAL]);
else
dbase_str = strcpy(newstr, inp);
(void) lcase(dbase_str);
/*
* TODO:
* The switch from xname() to doname_vague_quan() in look_at_obj()
* had the unintended side-effect of making names picked from
* pointing at map objects become harder to simplify for lookup.
* We should split the prefix and suffix handling used by wish
* parsing and also wizmode monster generation out into separate
* routines and use those routines here. This currently lacks
* erosion handling and probably lots of other bits and pieces
* that wishing already understands and most of this duplicates
* stuff already done for wish handling or monster generation.
*/
if (!strncmp(dbase_str, "interior of ", 12))
dbase_str += 12;
if (!strncmp(dbase_str, "a ", 2))
dbase_str += 2;
else if (!strncmp(dbase_str, "an ", 3))
dbase_str += 3;
else if (!strncmp(dbase_str, "the ", 4))
dbase_str += 4;
else if (!strncmp(dbase_str, "some ", 5))
dbase_str += 5;
else if (digit(*dbase_str)) {
/* remove count prefix ("2 ya") which can come from looking at map */
while (digit(*dbase_str))
++dbase_str;
if (*dbase_str == ' ')
++dbase_str;
}
if (!strncmp(dbase_str, "pair of ", 8))
dbase_str += 8;
if (!strncmp(dbase_str, "tame ", 5))
dbase_str += 5;
else if (!strncmp(dbase_str, "peaceful ", 9))
dbase_str += 9;
if (!strncmp(dbase_str, "invisible ", 10))
dbase_str += 10;
if (!strncmp(dbase_str, "saddled ", 8))
dbase_str += 8;
if (!strncmp(dbase_str, "blessed ", 8))
dbase_str += 8;
else if (!strncmp(dbase_str, "uncursed ", 9))
dbase_str += 9;
else if (!strncmp(dbase_str, "cursed ", 7))
dbase_str += 7;
if (!strncmp(dbase_str, "empty ", 6))
dbase_str += 6;
if (!strncmp(dbase_str, "partly used ", 12))
dbase_str += 12;
else if (!strncmp(dbase_str, "partly eaten ", 13))
dbase_str += 13;
if (!strncmp(dbase_str, "statue of ", 10))
dbase_str[6] = '\0';
else if (!strncmp(dbase_str, "figurine of ", 12))
dbase_str[8] = '\0';
/* remove enchantment ("+0 aklys"); [for 3.6.0 and earlier, this wasn't
needed because looking at items on the map used xname() rather than
doname() hence known enchantment was implicitly suppressed] */
if (*dbase_str && strchr("+-", dbase_str[0]) && digit(dbase_str[1])) {
++dbase_str; /* skip sign */
while (digit(*dbase_str))
++dbase_str;
if (*dbase_str == ' ')
++dbase_str;
}
/* "towel", "wet towel", and "moist towel" share one data.base entry;
for "wet towel", we keep prefix so that the prompt will ask about
"wet towel"; for "moist towel", we also want to ask about "wet towel".
(note: strncpy() only terminates output string if the specified
count is bigger than the length of the substring being copied) */
if (!strncmp(dbase_str, "moist towel", 11))
memcpy(dbase_str += 2, "wet", 3); /* skip "mo" replace "ist" */
/* Make sure the name is non-empty. */
if (*dbase_str) {
long pass1offset = -1L;
int chk_skip, pass = 1;
boolean yes_to_moreinfo, found_in_file, pass1found_in_file,
skipping_entry;
char *sp, *ap, *alt = 0; /* alternate description */
/* adjust the input to remove "named " and "called " */
if ((ep = strstri(dbase_str, " named ")) != 0) {
alt = ep + 7;
if ((ap = strstri(dbase_str, " called ")) != 0 && ap < ep)
ep = ap; /* "named" is alt but truncate at "called" */
} else if ((ep = strstri(dbase_str, " called ")) != 0) {
copynchars(givenname, ep + 8, BUFSZ - 1);
alt = givenname;
if (supplemental_name && (sp = strstri(inp, " called ")) != 0)
copynchars(supplemental_name, sp + 8, BUFSZ - 1);
} else
ep = strstri(dbase_str, ", ");
if (ep && ep > dbase_str)
*ep = '\0';
/* remove article from 'alt' name ("a pair of lenses named
The Eyes of the Overworld" simplified above to "lenses named
The Eyes of the Overworld", now reduced to "The Eyes of the
Overworld", skip "The" as with base name processing) */
if (alt && (!strncmpi(alt, "a ", 2)
|| !strncmpi(alt, "an ", 3)
|| !strncmpi(alt, "the ", 4)))
alt = strchr(alt, ' ') + 1;
/* remove charges or "(lit)" or wizmode "(N aum)" */
if ((ep = strstri(dbase_str, " (")) != 0 && ep > dbase_str)
*ep = '\0';
if (alt && (ap = strstri(alt, " (")) != 0 && ap > alt)
*ap = '\0';
/* If the object's name matches the player-specified fruitname,
then "fruit" is the alternate description. We do this here so that
if the fruit name is an extant object, looking at the fruit yields
that object's description. */
if (!alt && !strncmpi(dbase_str, gp.pl_fruit, PL_FSIZ))
alt = strcpy(newstr, obj_descr[SLIME_MOLD].oc_name);
/*
* If the object is named, then the name is the alternate description;
* otherwise, the result of makesingular() applied to the name is.
* This isn't strictly optimal, but named objects of interest to the
* user will usually be found under their name, rather than under
* their object type, so looking for a singular form is pointless.
*/
else if (!alt)
alt = makesingular(dbase_str);
pass1found_in_file = FALSE;
for (pass = !strcmp(alt, dbase_str) ? 0 : 1; pass >= 0; --pass) {
found_in_file = skipping_entry = FALSE;
txt_offset = 0L;
if (dlb_fseek(fp, txt_offset, SEEK_SET) < 0 ) {
impossible("can't get to start of 'data' file");
goto checkfile_done;
}
/* skip first record; read second */
if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) {
impossible("can't read 'data' file");
goto checkfile_done;
} else if (sscanf(buf, "%8lx\n", &txt_offset) < 1
|| txt_offset == 0L)
goto bad_data_file;
/* look for the appropriate entry */
while (dlb_fgets(buf, BUFSZ, fp)) {
if (*buf == '.')
break; /* we passed last entry without success */
if (digit(*buf)) {
/* a number indicates the end of current entry */
skipping_entry = FALSE;
} else if (!skipping_entry) {
if (!(ep = strchr(buf, '\n')))
goto bad_data_file;
(void) strip_newline((ep > buf) ? ep - 1 : ep);
/* if we match a key that begins with "~", skip
this entry */
chk_skip = (*buf == '~') ? 1 : 0;
if ((pass == 0 && pmatch(&buf[chk_skip], dbase_str))
|| (pass == 1 && alt && pmatch(&buf[chk_skip], alt))) {
if (chk_skip) {
skipping_entry = TRUE;
continue;
} else {
found_in_file = TRUE;
if (pass == 1)
pass1found_in_file = TRUE;
break;
}
}
}
}
if (found_in_file) {
long entry_offset, fseekoffset;
int entry_count;
int i;
/* skip over other possible matches for the info */
do {
if (!dlb_fgets(buf, BUFSZ, fp))
goto bad_data_file;
} while (!digit(*buf));
if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2)
goto bad_data_file;
fseekoffset = (long) txt_offset + entry_offset;
if (pass == 1)
pass1offset = fseekoffset;
else if (fseekoffset == pass1offset)
goto checkfile_done;
yes_to_moreinfo = FALSE;
if (!user_typed_name && !without_asking) {
char *entrytext = pass ? alt : dbase_str;
char question[QBUFSZ];
Strcpy(question, "More info about \"");
/* +2 => length of "\"?" */
copynchars(eos(question), entrytext,
(int) (sizeof question - 1
- (strlen(question) + 2)));
Strcat(question, "\"?");
if (y_n(question) == 'y')
yes_to_moreinfo = TRUE;
}
if (user_typed_name || without_asking || yes_to_moreinfo) {
if (dlb_fseek(fp, fseekoffset, SEEK_SET) < 0) {
pline("? Seek error on 'data' file!");
goto checkfile_done;
}
if (ia_checking) {
checkfile_hack = 'T';
goto checkfile_done;
}
datawin = create_nhwindow(NHW_MENU);
for (i = 0; i < entry_count; i++) {
/* room for 1-tab or 8-space prefix + BUFSZ-1 + \0 */
char tabbuf[BUFSZ + 8], *tp;
if (!dlb_fgets(tabbuf, BUFSZ, fp))
goto bad_data_file;
tp = tabbuf;
if (!strchr(tp, '\n'))
goto bad_data_file;
(void) strip_newline(tp);
/* text in this file is indented with one tab but
someone modifying it might use spaces instead */
if (*tp == '\t') {
++tp;
} else if (*tp == ' ') {
/* remove up to 8 spaces (we expect 8-column
tab stops but user might have them set at
something else so we don't require it) */
do {
++tp;
} while (tp < &tabbuf[8] && *tp == ' ');
} else if (*tp) { /* empty lines are ok */
goto bad_data_file;
}
/* if a tab after the leading one is found,
convert tabs into spaces; the attributions
at the end of quotes typically have them */
if (strchr(tp, '\t') != 0)
(void) tabexpand(tp);
putstr(datawin, 0, tp);
}
display_nhwindow(datawin, FALSE);