Source:NetHack 3.6.2/src/pager.c
Jump to navigation
Jump to search
Below is the full text to pager.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/pager.c#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* NetHack 3.6 pager.c $NHDT-Date: 1555627307 2019/04/18 22:41:47 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.151 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2018. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. /* This file contains the command routines dowhatis() and dohelp() and */ 7. /* a few other help related facilities */ 8. 9. #include "hack.h" 10. #include "dlb.h" 11. 12. STATIC_DCL boolean FDECL(is_swallow_sym, (int)); 13. STATIC_DCL int FDECL(append_str, (char *, const char *)); 14. STATIC_DCL void FDECL(look_at_object, (char *, int, int, int)); 15. STATIC_DCL void FDECL(look_at_monster, (char *, char *, 16. struct monst *, int, int)); 17. STATIC_DCL struct permonst *FDECL(lookat, (int, int, char *, char *)); 18. STATIC_DCL void FDECL(checkfile, (char *, struct permonst *, 19. BOOLEAN_P, BOOLEAN_P, char *)); 20. STATIC_DCL void FDECL(look_all, (BOOLEAN_P,BOOLEAN_P)); 21. STATIC_DCL void FDECL(do_supplemental_info, (char *, struct permonst *, 22. BOOLEAN_P)); 23. STATIC_DCL void NDECL(whatdoes_help); 24. STATIC_DCL void NDECL(docontact); 25. STATIC_DCL void NDECL(dispfile_help); 26. STATIC_DCL void NDECL(dispfile_shelp); 27. STATIC_DCL void NDECL(dispfile_optionfile); 28. STATIC_DCL void NDECL(dispfile_license); 29. STATIC_DCL void NDECL(dispfile_debughelp); 30. STATIC_DCL void NDECL(hmenu_doextversion); 31. STATIC_DCL void NDECL(hmenu_dohistory); 32. STATIC_DCL void NDECL(hmenu_dowhatis); 33. STATIC_DCL void NDECL(hmenu_dowhatdoes); 34. STATIC_DCL void NDECL(hmenu_doextlist); 35. #ifdef PORT_HELP 36. extern void NDECL(port_help); 37. #endif 38. 39. /* Returns "true" for characters that could represent a monster's stomach. */ 40. STATIC_OVL boolean 41. is_swallow_sym(c) 42. int c; 43. { 44. int i; 45. 46. for (i = S_sw_tl; i <= S_sw_br; i++) 47. if ((int) showsyms[i] == c) 48. return TRUE; 49. return FALSE; 50. } 51. 52. /* 53. * Append new_str to the end of buf if new_str doesn't already exist as 54. * a substring of buf. Return 1 if the string was appended, 0 otherwise. 55. * It is expected that buf is of size BUFSZ. 56. */ 57. STATIC_OVL int 58. append_str(buf, new_str) 59. char *buf; 60. const char *new_str; 61. { 62. int space_left; /* space remaining in buf */ 63. 64. if (strstri(buf, new_str)) 65. return 0; 66. 67. space_left = BUFSZ - strlen(buf) - 1; 68. if (space_left < 1) 69. return 0; 70. (void) strncat(buf, " or ", space_left); 71. (void) strncat(buf, new_str, space_left - 4); 72. return 1; 73. } 74. 75. /* shared by monster probing (via query_objlist!) as well as lookat() */ 76. char * 77. self_lookat(outbuf) 78. char *outbuf; 79. { 80. char race[QBUFSZ]; 81. 82. /* include race with role unless polymorphed */ 83. race[0] = '\0'; 84. if (!Upolyd) 85. Sprintf(race, "%s ", urace.adj); 86. Sprintf(outbuf, "%s%s%s called %s", 87. /* being blinded may hide invisibility from self */ 88. (Invis && (senseself() || !Blind)) ? "invisible " : "", race, 89. mons[u.umonnum].mname, plname); 90. if (u.usteed) 91. Sprintf(eos(outbuf), ", mounted on %s", y_monnam(u.usteed)); 92. if (u.uundetected || (Upolyd && U_AP_TYPE)) 93. mhidden_description(&youmonst, FALSE, eos(outbuf)); 94. return outbuf; 95. } 96. 97. /* describe a hidden monster; used for look_at during extended monster 98. detection and for probing; also when looking at self */ 99. void 100. mhidden_description(mon, altmon, outbuf) 101. struct monst *mon; 102. boolean altmon; /* for probing: if mimicking a monster, say so */ 103. char *outbuf; 104. { 105. struct obj *otmp; 106. boolean fakeobj, isyou = (mon == &youmonst); 107. int x = isyou ? u.ux : mon->mx, y = isyou ? u.uy : mon->my, 108. glyph = (level.flags.hero_memory && !isyou) ? levl[x][y].glyph 109. : glyph_at(x, y); 110. 111. *outbuf = '\0'; 112. if (M_AP_TYPE(mon) == M_AP_FURNITURE 113. || M_AP_TYPE(mon) == M_AP_OBJECT) { 114. Strcpy(outbuf, ", mimicking "); 115. if (M_AP_TYPE(mon) == M_AP_FURNITURE) { 116. Strcat(outbuf, an(defsyms[mon->mappearance].explanation)); 117. } else if (M_AP_TYPE(mon) == M_AP_OBJECT 118. /* remembered glyph, not glyph_at() which is 'mon' */ 119. && glyph_is_object(glyph)) { 120. objfrommap: 121. otmp = (struct obj *) 0; 122. fakeobj = object_from_map(glyph, x, y, &otmp); 123. Strcat(outbuf, (otmp && otmp->otyp != STRANGE_OBJECT) 124. ? ansimpleoname(otmp) 125. : an(obj_descr[STRANGE_OBJECT].oc_name)); 126. if (fakeobj) { 127. otmp->where = OBJ_FREE; /* object_from_map set to OBJ_FLOOR */ 128. dealloc_obj(otmp); 129. } 130. } else { 131. Strcat(outbuf, something); 132. } 133. } else if (M_AP_TYPE(mon) == M_AP_MONSTER) { 134. if (altmon) 135. Sprintf(outbuf, ", masquerading as %s", 136. an(mons[mon->mappearance].mname)); 137. } else if (isyou ? u.uundetected : mon->mundetected) { 138. Strcpy(outbuf, ", hiding"); 139. if (hides_under(mon->data)) { 140. Strcat(outbuf, " under "); 141. /* remembered glyph, not glyph_at() which is 'mon' */ 142. if (glyph_is_object(glyph)) 143. goto objfrommap; 144. Strcat(outbuf, something); 145. } else if (is_hider(mon->data)) { 146. Sprintf(eos(outbuf), " on the %s", 147. (is_flyer(mon->data) || mon->data->mlet == S_PIERCER) 148. ? "ceiling" 149. : surface(x, y)); /* trapper */ 150. } else { 151. if (mon->data->mlet == S_EEL && is_pool(x, y)) 152. Strcat(outbuf, " in murky water"); 153. } 154. } 155. } 156. 157. /* extracted from lookat(); also used by namefloorobj() */ 158. boolean 159. object_from_map(glyph, x, y, obj_p) 160. int glyph, x, y; 161. struct obj **obj_p; 162. { 163. boolean fakeobj = FALSE, mimic_obj = FALSE; 164. struct monst *mtmp; 165. struct obj *otmp; 166. int glyphotyp = glyph_to_obj(glyph); 167. 168. *obj_p = (struct obj *) 0; 169. /* TODO: check inside containers in case glyph came from detection */ 170. if ((otmp = sobj_at(glyphotyp, x, y)) == 0) 171. for (otmp = level.buriedobjlist; otmp; otmp = otmp->nobj) 172. if (otmp->ox == x && otmp->oy == y && otmp->otyp == glyphotyp) 173. break; 174. 175. /* there might be a mimic here posing as an object */ 176. mtmp = m_at(x, y); 177. if (mtmp && is_obj_mappear(mtmp, (unsigned) glyphotyp)) { 178. otmp = 0; 179. mimic_obj = TRUE; 180. } else 181. mtmp = 0; 182. 183. if (!otmp || otmp->otyp != glyphotyp) { 184. /* this used to exclude STRANGE_OBJECT; now caller deals with it */ 185. otmp = mksobj(glyphotyp, FALSE, FALSE); 186. if (!otmp) 187. return FALSE; 188. fakeobj = TRUE; 189. if (otmp->oclass == COIN_CLASS) 190. otmp->quan = 2L; /* to force pluralization */ 191. else if (otmp->otyp == SLIME_MOLD) 192. otmp->spe = context.current_fruit; /* give it a type */ 193. if (mtmp && has_mcorpsenm(mtmp)) /* mimic as corpse/statue */ 194. otmp->corpsenm = MCORPSENM(mtmp); 195. else if (otmp->otyp == CORPSE && glyph_is_body(glyph)) 196. otmp->corpsenm = glyph - GLYPH_BODY_OFF; 197. else if (otmp->otyp == STATUE && glyph_is_statue(glyph)) 198. otmp->corpsenm = glyph - GLYPH_STATUE_OFF; 199. if (otmp->otyp == LEASH) 200. otmp->leashmon = 0; 201. /* extra fields needed for shop price with doname() formatting */ 202. otmp->where = OBJ_FLOOR; 203. otmp->ox = x, otmp->oy = y; 204. otmp->no_charge = (otmp->otyp == STRANGE_OBJECT && costly_spot(x, y)); 205. } 206. /* if located at adjacent spot, mark it as having been seen up close 207. (corpse type will be known even if dknown is 0, so we don't need a 208. touch check for cockatrice corpse--we're looking without touching) */ 209. if (otmp && distu(x, y) <= 2 && !Blind && !Hallucination 210. /* redundant: we only look for an object which matches current 211. glyph among floor and buried objects; when !Blind, any buried 212. object's glyph will have been replaced by whatever is present 213. on the surface as soon as we moved next to its spot */ 214. && (fakeobj || otmp->where == OBJ_FLOOR) /* not buried */ 215. /* terrain mode views what's already known, doesn't learn new stuff */ 216. && !iflags.terrainmode) /* so don't set dknown when in terrain mode */ 217. otmp->dknown = 1; /* if a pile, clearly see the top item only */ 218. if (fakeobj && mtmp && mimic_obj && 219. (otmp->dknown || (M_AP_FLAG(mtmp) & M_AP_F_DKNOWN))) { 220. mtmp->m_ap_type |= M_AP_F_DKNOWN; 221. otmp->dknown = 1; 222. } 223. *obj_p = otmp; 224. return fakeobj; /* when True, caller needs to dealloc *obj_p */ 225. } 226. 227. STATIC_OVL void 228. look_at_object(buf, x, y, glyph) 229. char *buf; /* output buffer */ 230. int x, y, glyph; 231. { 232. struct obj *otmp = 0; 233. boolean fakeobj = object_from_map(glyph, x, y, &otmp); 234. 235. if (otmp) { 236. Strcpy(buf, (otmp->otyp != STRANGE_OBJECT) 237. ? distant_name(otmp, otmp->dknown ? doname_with_price 238. : doname_vague_quan) 239. : obj_descr[STRANGE_OBJECT].oc_name); 240. if (fakeobj) { 241. otmp->where = OBJ_FREE; /* object_from_map set it to OBJ_FLOOR */ 242. dealloc_obj(otmp), otmp = 0; 243. } 244. } else 245. Strcpy(buf, something); /* sanity precaution */ 246. 247. if (otmp && otmp->where == OBJ_BURIED) 248. Strcat(buf, " (buried)"); 249. else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR) 250. Strcat(buf, " embedded in stone"); 251. else if (IS_WALL(levl[x][y].typ) || levl[x][y].typ == SDOOR) 252. Strcat(buf, " embedded in a wall"); 253. else if (closed_door(x, y)) 254. Strcat(buf, " embedded in a door"); 255. else if (is_pool(x, y)) 256. Strcat(buf, " in water"); 257. else if (is_lava(x, y)) 258. Strcat(buf, " in molten lava"); /* [can this ever happen?] */ 259. return; 260. } 261. 262. STATIC_OVL void 263. look_at_monster(buf, monbuf, mtmp, x, y) 264. char *buf, *monbuf; /* buf: output, monbuf: optional output */ 265. struct monst *mtmp; 266. int x, y; 267. { 268. char *name, monnambuf[BUFSZ]; 269. boolean accurate = !Hallucination; 270. 271. name = (mtmp->data == &mons[PM_COYOTE] && accurate) 272. ? coyotename(mtmp, monnambuf) 273. : distant_monnam(mtmp, ARTICLE_NONE, monnambuf); 274. Sprintf(buf, "%s%s%s", 275. (mtmp->mx != x || mtmp->my != y) 276. ? ((mtmp->isshk && accurate) ? "tail of " : "tail of a ") 277. : "", 278. (mtmp->mtame && accurate) 279. ? "tame " 280. : (mtmp->mpeaceful && accurate) 281. ? "peaceful " 282. : "", 283. name); 284. if (u.ustuck == mtmp) { 285. if (u.uswallow || iflags.save_uswallow) /* monster detection */ 286. Strcat(buf, is_animal(mtmp->data) 287. ? ", swallowing you" : ", engulfing you"); 288. else 289. Strcat(buf, (Upolyd && sticks(youmonst.data)) 290. ? ", being held" : ", holding you"); 291. } 292. if (mtmp->mleashed) 293. Strcat(buf, ", leashed to you"); 294. 295. if (mtmp->mtrapped && cansee(mtmp->mx, mtmp->my)) { 296. struct trap *t = t_at(mtmp->mx, mtmp->my); 297. int tt = t ? t->ttyp : NO_TRAP; 298. 299. /* newsym lets you know of the trap, so mention it here */ 300. if (tt == BEAR_TRAP || is_pit(tt) || tt == WEB) 301. Sprintf(eos(buf), ", trapped in %s", 302. an(defsyms[trap_to_defsym(tt)].explanation)); 303. } 304. 305. /* we know the hero sees a monster at this location, but if it's shown 306. due to persistant monster detection he might remember something else */ 307. if (mtmp->mundetected || M_AP_TYPE(mtmp)) 308. mhidden_description(mtmp, FALSE, eos(buf)); 309. 310. if (monbuf) { 311. unsigned how_seen = howmonseen(mtmp); 312. 313. monbuf[0] = '\0'; 314. if (how_seen != 0 && how_seen != MONSEEN_NORMAL) { 315. if (how_seen & MONSEEN_NORMAL) { 316. Strcat(monbuf, "normal vision"); 317. how_seen &= ~MONSEEN_NORMAL; 318. /* how_seen can't be 0 yet... */ 319. if (how_seen) 320. Strcat(monbuf, ", "); 321. } 322. if (how_seen & MONSEEN_SEEINVIS) { 323. Strcat(monbuf, "see invisible"); 324. how_seen &= ~MONSEEN_SEEINVIS; 325. if (how_seen) 326. Strcat(monbuf, ", "); 327. } 328. if (how_seen & MONSEEN_INFRAVIS) { 329. Strcat(monbuf, "infravision"); 330. how_seen &= ~MONSEEN_INFRAVIS; 331. if (how_seen) 332. Strcat(monbuf, ", "); 333. } 334. if (how_seen & MONSEEN_TELEPAT) { 335. Strcat(monbuf, "telepathy"); 336. how_seen &= ~MONSEEN_TELEPAT; 337. if (how_seen) 338. Strcat(monbuf, ", "); 339. } 340. if (how_seen & MONSEEN_XRAYVIS) { 341. /* Eyes of the Overworld */ 342. Strcat(monbuf, "astral vision"); 343. how_seen &= ~MONSEEN_XRAYVIS; 344. if (how_seen) 345. Strcat(monbuf, ", "); 346. } 347. if (how_seen & MONSEEN_DETECT) { 348. Strcat(monbuf, "monster detection"); 349. how_seen &= ~MONSEEN_DETECT; 350. if (how_seen) 351. Strcat(monbuf, ", "); 352. } 353. if (how_seen & MONSEEN_WARNMON) { 354. if (Hallucination) { 355. Strcat(monbuf, "paranoid delusion"); 356. } else { 357. unsigned long mW = (context.warntype.obj 358. | context.warntype.polyd), 359. m2 = mtmp->data->mflags2; 360. const char *whom = ((mW & M2_HUMAN & m2) ? "human" 361. : (mW & M2_ELF & m2) ? "elf" 362. : (mW & M2_ORC & m2) ? "orc" 363. : (mW & M2_DEMON & m2) ? "demon" 364. : mtmp->data->mname); 365. 366. Sprintf(eos(monbuf), "warned of %s", makeplural(whom)); 367. } 368. how_seen &= ~MONSEEN_WARNMON; 369. if (how_seen) 370. Strcat(monbuf, ", "); 371. } 372. /* should have used up all the how_seen bits by now */ 373. if (how_seen) { 374. impossible("lookat: unknown method of seeing monster"); 375. Sprintf(eos(monbuf), "(%u)", how_seen); 376. } 377. } /* seen by something other than normal vision */ 378. } /* monbuf is non-null */ 379. } 380. 381. /* 382. * Return the name of the glyph found at (x,y). 383. * If not hallucinating and the glyph is a monster, also monster data. 384. */ 385. STATIC_OVL struct permonst * 386. lookat(x, y, buf, monbuf) 387. int x, y; 388. char *buf, *monbuf; 389. { 390. struct monst *mtmp = (struct monst *) 0; 391. struct permonst *pm = (struct permonst *) 0; 392. int glyph; 393. 394. buf[0] = monbuf[0] = '\0'; 395. glyph = glyph_at(x, y); 396. if (u.ux == x && u.uy == y && canspotself() 397. && !(iflags.save_uswallow && 398. glyph == mon_to_glyph(u.ustuck, rn2_on_display_rng)) 399. && (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0)) { 400. /* fill in buf[] */ 401. (void) self_lookat(buf); 402. 403. /* file lookup can't distinguish between "gnomish wizard" monster 404. and correspondingly named player character, always picking the 405. former; force it to find the general "wizard" entry instead */ 406. if (Role_if(PM_WIZARD) && Race_if(PM_GNOME) && !Upolyd) 407. pm = &mons[PM_WIZARD]; 408. 409. /* When you see yourself normally, no explanation is appended 410. (even if you could also see yourself via other means). 411. Sensing self while blind or swallowed is treated as if it 412. were by normal vision (cf canseeself()). */ 413. if ((Invisible || u.uundetected) && !Blind 414. && !(u.uswallow || iflags.save_uswallow)) { 415. unsigned how = 0; 416. 417. if (Infravision) 418. how |= 1; 419. if (Unblind_telepat) 420. how |= 2; 421. if (Detect_monsters) 422. how |= 4; 423. 424. if (how) 425. Sprintf(eos(buf), " [seen: %s%s%s%s%s]", 426. (how & 1) ? "infravision" : "", 427. /* add comma if telep and infrav */ 428. ((how & 3) > 2) ? ", " : "", 429. (how & 2) ? "telepathy" : "", 430. /* add comma if detect and (infrav or telep or both) */ 431. ((how & 7) > 4) ? ", " : "", 432. (how & 4) ? "monster detection" : ""); 433. } 434. } else if (u.uswallow) { 435. /* when swallowed, we're only called for spots adjacent to hero, 436. and blindness doesn't prevent hero from feeling what holds him */ 437. Sprintf(buf, "interior of %s", a_monnam(u.ustuck)); 438. pm = u.ustuck->data; 439. } else if (glyph_is_monster(glyph)) { 440. bhitpos.x = x; 441. bhitpos.y = y; 442. if ((mtmp = m_at(x, y)) != 0) { 443. look_at_monster(buf, monbuf, mtmp, x, y); 444. pm = mtmp->data; 445. } else if (Hallucination) { 446. /* 'monster' must actually be a statue */ 447. Strcpy(buf, rndmonnam((char *) 0)); 448. } 449. } else if (glyph_is_object(glyph)) { 450. look_at_object(buf, x, y, glyph); /* fill in buf[] */ 451. } else if (glyph_is_trap(glyph)) { 452. int tnum = what_trap(glyph_to_trap(glyph), rn2_on_display_rng); 453. 454. /* Trap detection displays a bear trap at locations having 455. * a trapped door or trapped container or both. 456. * TODO: we should create actual trap types for doors and 457. * chests so that they can have their own glyphs and tiles. 458. */ 459. if (trapped_chest_at(tnum, x, y)) 460. Strcpy(buf, "trapped chest"); /* might actually be a large box */ 461. else if (trapped_door_at(tnum, x, y)) 462. Strcpy(buf, "trapped door"); /* not "trap door"... */ 463. else 464. Strcpy(buf, defsyms[trap_to_defsym(tnum)].explanation); 465. } else if (glyph_is_warning(glyph)) { 466. int warnindx = glyph_to_warning(glyph); 467. 468. Strcpy(buf, def_warnsyms[warnindx].explanation); 469. } else if (!glyph_is_cmap(glyph)) { 470. Strcpy(buf, "unexplored area"); 471. } else 472. switch (glyph_to_cmap(glyph)) { 473. case S_altar: 474. Sprintf(buf, "%s %saltar", 475. /* like endgame high priests, endgame high altars 476. are only recognizable when immediately adjacent */ 477. (Is_astralevel(&u.uz) && distu(x, y) > 2) 478. ? "aligned" 479. : align_str( 480. Amask2align(levl[x][y].altarmask & ~AM_SHRINE)), 481. ((levl[x][y].altarmask & AM_SHRINE) 482. && (Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) 483. ? "high " 484. : ""); 485. break; 486. case S_ndoor: 487. if (is_drawbridge_wall(x, y) >= 0) 488. Strcpy(buf, "open drawbridge portcullis"); 489. else if ((levl[x][y].doormask & ~D_TRAPPED) == D_BROKEN) 490. Strcpy(buf, "broken door"); 491. else 492. Strcpy(buf, "doorway"); 493. break; 494. case S_cloud: 495. Strcpy(buf, 496. Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud"); 497. break; 498. case S_stone: 499. if (!levl[x][y].seenv) { 500. Strcpy(buf, "unexplored"); 501. break; 502. } else if (Underwater && !Is_waterlevel(&u.uz)) { 503. /* "unknown" == previously mapped but not visible when 504. submerged; better terminology appreciated... */ 505. Strcpy(buf, (distu(x, y) <= 2) ? "land" : "unknown"); 506. break; 507. } else if (levl[x][y].typ == STONE || levl[x][y].typ == SCORR) { 508. Strcpy(buf, "stone"); 509. break; 510. } 511. /*FALLTHRU*/ 512. default: 513. Strcpy(buf, defsyms[glyph_to_cmap(glyph)].explanation); 514. break; 515. } 516. 517. return (pm && !Hallucination) ? pm : (struct permonst *) 0; 518. } 519. 520. /* 521. * Look in the "data" file for more info. Called if the user typed in the 522. * whole name (user_typed_name == TRUE), or we've found a possible match 523. * with a character/glyph and flags.help is TRUE. 524. * 525. * NOTE: when (user_typed_name == FALSE), inp is considered read-only and 526. * must not be changed directly, e.g. via lcase(). We want to force 527. * lcase() for data.base lookup so that we can have a clean key. 528. * Therefore, we create a copy of inp _just_ for data.base lookup. 529. */ 530. STATIC_OVL void 531. checkfile(inp, pm, user_typed_name, without_asking, supplemental_name) 532. char *inp; 533. struct permonst *pm; 534. boolean user_typed_name, without_asking; 535. char *supplemental_name; 536. { 537. dlb *fp; 538. char buf[BUFSZ], newstr[BUFSZ], givenname[BUFSZ]; 539. char *ep, *dbase_str; 540. unsigned long txt_offset = 0L; 541. winid datawin = WIN_ERR; 542. 543. fp = dlb_fopen(DATAFILE, "r"); 544. if (!fp) { 545. pline("Cannot open 'data' file!"); 546. return; 547. } 548. /* If someone passed us garbage, prevent fault. */ 549. if (!inp || strlen(inp) > (BUFSZ - 1)) { 550. impossible("bad do_look buffer passed (%s)!", 551. !inp ? "null" : "too long"); 552. goto checkfile_done; 553. } 554. 555. /* To prevent the need for entries in data.base like *ngel to account 556. * for Angel and angel, make the lookup string the same for both 557. * user_typed_name and picked name. 558. */ 559. if (pm != (struct permonst *) 0 && !user_typed_name) 560. dbase_str = strcpy(newstr, pm->mname); 561. else 562. dbase_str = strcpy(newstr, inp); 563. (void) lcase(dbase_str); 564. 565. /* 566. * TODO: 567. * The switch from xname() to doname_vague_quan() in look_at_obj() 568. * had the unintendded side-effect of making names picked from 569. * pointing at map objects become harder to simplify for lookup. 570. * We should split the prefix and suffix handling used by wish 571. * parsing and also wizmode monster generation out into separate 572. * routines and use those routines here. This currently lacks 573. * erosion handling and probably lots of other bits and pieces 574. * that wishing already understands and most of this duplicates 575. * stuff already done for wish handling or monster generation. 576. */ 577. if (!strncmp(dbase_str, "interior of ", 12)) 578. dbase_str += 12; 579. if (!strncmp(dbase_str, "a ", 2)) 580. dbase_str += 2; 581. else if (!strncmp(dbase_str, "an ", 3)) 582. dbase_str += 3; 583. else if (!strncmp(dbase_str, "the ", 4)) 584. dbase_str += 4; 585. else if (!strncmp(dbase_str, "some ", 5)) 586. dbase_str += 5; 587. else if (digit(*dbase_str)) { 588. /* remove count prefix ("2 ya") which can come from looking at map */ 589. while (digit(*dbase_str)) 590. ++dbase_str; 591. if (*dbase_str == ' ') 592. ++dbase_str; 593. } 594. if (!strncmp(dbase_str, "pair of ", 8)) 595. dbase_str += 8; 596. if (!strncmp(dbase_str, "tame ", 5)) 597. dbase_str += 5; 598. else if (!strncmp(dbase_str, "peaceful ", 9)) 599. dbase_str += 9; 600. if (!strncmp(dbase_str, "invisible ", 10)) 601. dbase_str += 10; 602. if (!strncmp(dbase_str, "saddled ", 8)) 603. dbase_str += 8; 604. if (!strncmp(dbase_str, "blessed ", 8)) 605. dbase_str += 8; 606. else if (!strncmp(dbase_str, "uncursed ", 9)) 607. dbase_str += 9; 608. else if (!strncmp(dbase_str, "cursed ", 7)) 609. dbase_str += 7; 610. if (!strncmp(dbase_str, "empty ", 6)) 611. dbase_str += 6; 612. if (!strncmp(dbase_str, "partly used ", 12)) 613. dbase_str += 12; 614. else if (!strncmp(dbase_str, "partly eaten ", 13)) 615. dbase_str += 13; 616. if (!strncmp(dbase_str, "statue of ", 10)) 617. dbase_str[6] = '\0'; 618. else if (!strncmp(dbase_str, "figurine of ", 12)) 619. dbase_str[8] = '\0'; 620. /* remove enchantment ("+0 aklys"); [for 3.6.0 and earlier, this wasn't 621. needed because looking at items on the map used xname() rather than 622. doname() hence known enchantment was implicitly suppressed] */ 623. if (*dbase_str && index("+-", dbase_str[0]) && digit(dbase_str[1])) { 624. ++dbase_str; /* skip sign */ 625. while (digit(*dbase_str)) 626. ++dbase_str; 627. if (*dbase_str == ' ') 628. ++dbase_str; 629. } 630. /* "towel", "wet towel", and "moist towel" share one data.base entry; 631. for "wet towel", we keep prefix so that the prompt will ask about 632. "wet towel"; for "moist towel", we also want to ask about "wet towel". 633. (note: strncpy() only terminates output string if the specified 634. count is bigger than the length of the substring being copied) */ 635. if (!strncmp(dbase_str, "moist towel", 11)) 636. (void) strncpy(dbase_str += 2, "wet", 3); /* skip "mo" replace "ist" */ 637. 638. /* Make sure the name is non-empty. */ 639. if (*dbase_str) { 640. long pass1offset = -1L; 641. int chk_skip, pass = 1; 642. boolean yes_to_moreinfo, found_in_file, pass1found_in_file, 643. skipping_entry; 644. char *sp, *ap, *alt = 0; /* alternate description */ 645. 646. /* adjust the input to remove "named " and "called " */ 647. if ((ep = strstri(dbase_str, " named ")) != 0) { 648. alt = ep + 7; 649. if ((ap = strstri(dbase_str, " called ")) != 0 && ap < ep) 650. ep = ap; /* "named" is alt but truncate at "called" */ 651. } else if ((ep = strstri(dbase_str, " called ")) != 0) { 652. copynchars(givenname, ep + 8, BUFSZ - 1); 653. alt = givenname; 654. if (supplemental_name && (sp = strstri(inp, " called ")) != 0) 655. copynchars(supplemental_name, sp + 8, BUFSZ - 1); 656. } else 657. ep = strstri(dbase_str, ", "); 658. if (ep && ep > dbase_str) 659. *ep = '\0'; 660. /* remove article from 'alt' name ("a pair of lenses named 661. The Eyes of the Overworld" simplified above to "lenses named 662. The Eyes of the Overworld", now reduced to "The Eyes of the 663. Overworld", skip "The" as with base name processing) */ 664. if (alt && (!strncmpi(alt, "a ", 2) 665. || !strncmpi(alt, "an ", 3) 666. || !strncmpi(alt, "the ", 4))) 667. alt = index(alt, ' ') + 1; 668. /* remove charges or "(lit)" or wizmode "(N aum)" */ 669. if ((ep = strstri(dbase_str, " (")) != 0 && ep > dbase_str) 670. *ep = '\0'; 671. if (alt && (ap = strstri(alt, " (")) != 0 && ap > alt) 672. *ap = '\0'; 673. 674. /* 675. * If the object is named, then the name is the alternate description; 676. * otherwise, the result of makesingular() applied to the name is. 677. * This isn't strictly optimal, but named objects of interest to the 678. * user will usually be found under their name, rather than under 679. * their object type, so looking for a singular form is pointless. 680. */ 681. if (!alt) 682. alt = makesingular(dbase_str); 683. 684. pass1found_in_file = FALSE; 685. for (pass = !strcmp(alt, dbase_str) ? 0 : 1; pass >= 0; --pass) { 686. found_in_file = skipping_entry = FALSE; 687. txt_offset = 0L; 688. if (dlb_fseek(fp, txt_offset, SEEK_SET) < 0 ) { 689. impossible("can't get to start of 'data' file"); 690. goto checkfile_done; 691. } 692. /* skip first record; read second */ 693. if (!dlb_fgets(buf, BUFSZ, fp) || !dlb_fgets(buf, BUFSZ, fp)) { 694. impossible("can't read 'data' file"); 695. goto checkfile_done; 696. } else if (sscanf(buf, "%8lx\n", &txt_offset) < 1 697. || txt_offset == 0L) 698. goto bad_data_file; 699. 700. /* look for the appropriate entry */ 701. while (dlb_fgets(buf, BUFSZ, fp)) { 702. if (*buf == '.') 703. break; /* we passed last entry without success */ 704. 705. if (digit(*buf)) { 706. /* a number indicates the end of current entry */ 707. skipping_entry = FALSE; 708. } else if (!skipping_entry) { 709. if (!(ep = index(buf, '\n'))) 710. goto bad_data_file; 711. (void) strip_newline((ep > buf) ? ep - 1 : ep); 712. /* if we match a key that begins with "~", skip 713. this entry */ 714. chk_skip = (*buf == '~') ? 1 : 0; 715. if ((pass == 0 && pmatch(&buf[chk_skip], dbase_str)) 716. || (pass == 1 && alt && pmatch(&buf[chk_skip], alt))) { 717. if (chk_skip) { 718. skipping_entry = TRUE; 719. continue; 720. } else { 721. found_in_file = TRUE; 722. if (pass == 1) 723. pass1found_in_file = TRUE; 724. break; 725. } 726. } 727. } 728. } 729. if (found_in_file) { 730. long entry_offset, fseekoffset; 731. int entry_count; 732. int i; 733. 734. /* skip over other possible matches for the info */ 735. do { 736. if (!dlb_fgets(buf, BUFSZ, fp)) 737. goto bad_data_file; 738. } while (!digit(*buf)); 739. if (sscanf(buf, "%ld,%d\n", &entry_offset, &entry_count) < 2) 740. goto bad_data_file; 741. fseekoffset = (long) txt_offset + entry_offset; 742. if (pass == 1) 743. pass1offset = fseekoffset; 744. else if (fseekoffset == pass1offset) 745. goto checkfile_done; 746. 747. yes_to_moreinfo = FALSE; 748. if (!user_typed_name && !without_asking) { 749. char *entrytext = pass ? alt : dbase_str; 750. char question[QBUFSZ]; 751. 752. Strcpy(question, "More info about \""); 753. /* +2 => length of "\"?" */ 754. copynchars(eos(question), entrytext, 755. (int) (sizeof question - 1 756. - (strlen(question) + 2))); 757. Strcat(question, "\"?"); 758. if (yn(question) == 'y') 759. yes_to_moreinfo = TRUE; 760. } 761. 762. if (user_typed_name || without_asking || yes_to_moreinfo) { 763. if (dlb_fseek(fp, fseekoffset, SEEK_SET) < 0) { 764. pline("? Seek error on 'data' file!"); 765. goto checkfile_done; 766. } 767. datawin = create_nhwindow(NHW_MENU); 768. for (i = 0; i < entry_count; i++) { 769. if (!dlb_fgets(buf, BUFSZ, fp)) 770. goto bad_data_file; 771. (void) strip_newline(buf); 772. if (index(buf + 1, '\t') != 0) 773. (void) tabexpand(buf + 1); 774. putstr(datawin, 0, buf + 1); 775. } 776. display_nhwindow(datawin, FALSE); 777. destroy_nhwindow(datawin), datawin = WIN_ERR; 778. } 779. } else if (user_typed_name && pass == 0 && !pass1found_in_file) 780. pline("I don't have any information on those things."); 781. } 782. } 783. goto checkfile_done; /* skip error feedback */ 784. 785. bad_data_file: 786. impossible("'data' file in wrong format or corrupted"); 787. checkfile_done: 788. if (datawin != WIN_ERR) 789. destroy_nhwindow(datawin); 790. (void) dlb_fclose(fp); 791. return; 792. } 793. 794. int 795. do_screen_description(cc, looked, sym, out_str, firstmatch, for_supplement) 796. coord cc; 797. boolean looked; 798. int sym; 799. char *out_str; 800. const char **firstmatch; 801. struct permonst **for_supplement; 802. { 803. static const char mon_interior[] = "the interior of a monster", 804. unreconnoitered[] = "unreconnoitered"; 805. static char look_buf[BUFSZ]; 806. char prefix[BUFSZ]; 807. int i, alt_i, glyph = NO_GLYPH, 808. skipped_venom = 0, found = 0; /* count of matching syms found */ 809. boolean hit_trap, need_to_look = FALSE, 810. submerged = (Underwater && !Is_waterlevel(&u.uz)); 811. const char *x_str; 812. 813. if (looked) { 814. int oc; 815. unsigned os; 816. 817. glyph = glyph_at(cc.x, cc.y); 818. /* Convert glyph at selected position to a symbol for use below. */ 819. (void) mapglyph(glyph, &sym, &oc, &os, cc.x, cc.y); 820. 821. Sprintf(prefix, "%s ", encglyph(glyph)); 822. } else 823. Sprintf(prefix, "%c ", sym); 824. 825. /* 826. * Check all the possibilities, saving all explanations in a buffer. 827. * When all have been checked then the string is printed. 828. */ 829. 830. /* 831. * Handle restricted vision range (limited to adjacent spots when 832. * swallowed or underwater) cases first. 833. * 834. * 3.6.0 listed anywhere on map, other than self, as "interior 835. * of a monster" when swallowed, and non-adjacent water or 836. * non-water anywhere as "dark part of a room" when underwater. 837. * "unreconnoitered" is an attempt to convey "even if you knew 838. * what was there earlier, you don't know what is there in the 839. * current circumstance". 840. * 841. * (Note: 'self' will always be visible when swallowed so we don't 842. * need special swallow handling for <ux,uy>. 843. * Another note: for '#terrain' without monsters, u.uswallow and 844. * submerged will always both be False and skip this code.) 845. */ 846. x_str = 0; 847. if (!looked) { 848. ; /* skip special handling */ 849. } else if (((u.uswallow || submerged) && distu(cc.x, cc.y) > 2) 850. /* detection showing some category, so mostly background */ 851. || ((iflags.terrainmode & (TER_DETECT | TER_MAP)) == TER_DETECT 852. && glyph == cmap_to_glyph(S_stone))) { 853. x_str = unreconnoitered; 854. need_to_look = FALSE; 855. } else if (is_swallow_sym(sym)) { 856. x_str = mon_interior; 857. need_to_look = TRUE; /* for specific monster type */ 858. } 859. if (x_str) { 860. /* we know 'found' is zero here, but guard against some other 861. special case being inserted ahead of us someday */ 862. if (!found) { 863. Sprintf(out_str, "%s%s", prefix, x_str); 864. *firstmatch = x_str; 865. found++; 866. } else { 867. found += append_str(out_str, x_str); /* not 'an(x_str)' */ 868. } 869. /* for is_swallow_sym(), we want to list the current symbol's 870. other possibilities (wand for '/', throne for '\\', &c) so 871. don't jump to the end for the x_str==mon_interior case */ 872. if (x_str == unreconnoitered) 873. goto didlook; 874. } 875. 876. /* Check for monsters */ 877. if (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0) { 878. for (i = 1; i < MAXMCLASSES; i++) { 879. if (sym == (looked ? showsyms[i + SYM_OFF_M] : def_monsyms[i].sym) 880. && def_monsyms[i].explain && *def_monsyms[i].explain) { 881. need_to_look = TRUE; 882. if (!found) { 883. Sprintf(out_str, "%s%s", 884. prefix, an(def_monsyms[i].explain)); 885. *firstmatch = def_monsyms[i].explain; 886. found++; 887. } else { 888. found += append_str(out_str, an(def_monsyms[i].explain)); 889. } 890. } 891. } 892. /* handle '@' as a special case if it refers to you and you're 893. playing a character which isn't normally displayed by that 894. symbol; firstmatch is assumed to already be set for '@' */ 895. if ((looked ? (sym == showsyms[S_HUMAN + SYM_OFF_M] 896. && cc.x == u.ux && cc.y == u.uy) 897. : (sym == def_monsyms[S_HUMAN].sym && !flags.showrace)) 898. && !(Race_if(PM_HUMAN) || Race_if(PM_ELF)) && !Upolyd) 899. found += append_str(out_str, "you"); /* tack on "or you" */ 900. } 901. 902. /* Now check for objects */ 903. if (!iflags.terrainmode || (iflags.terrainmode & TER_OBJ) != 0) { 904. for (i = 1; i < MAXOCLASSES; i++) { 905. if (sym == (looked ? showsyms[i + SYM_OFF_O] 906. : def_oc_syms[i].sym) 907. || (looked && i == ROCK_CLASS && glyph_is_statue(glyph))) { 908. need_to_look = TRUE; 909. if (looked && i == VENOM_CLASS) { 910. skipped_venom++; 911. continue; 912. } 913. if (!found) { 914. Sprintf(out_str, "%s%s", 915. prefix, an(def_oc_syms[i].explain)); 916. *firstmatch = def_oc_syms[i].explain; 917. found++; 918. } else { 919. found += append_str(out_str, an(def_oc_syms[i].explain)); 920. } 921. } 922. } 923. } 924. 925. if (sym == DEF_INVISIBLE) { 926. extern const char altinvisexplain[]; /* drawing.c */ 927. /* for active clairvoyance, use alternate "unseen creature" */ 928. boolean usealt = (EDetect_monsters & I_SPECIAL) != 0L; 929. const char *unseen_explain = !usealt ? invisexplain : altinvisexplain; 930. 931. if (!found) { 932. Sprintf(out_str, "%s%s", prefix, an(unseen_explain)); 933. *firstmatch = unseen_explain; 934. found++; 935. } else { 936. found += append_str(out_str, an(unseen_explain)); 937. } 938. } 939. 940. /* Now check for graphics symbols */ 941. alt_i = (sym == (looked ? showsyms[0] : defsyms[0].sym)) ? 0 : (2 + 1); 942. for (hit_trap = FALSE, i = 0; i < MAXPCHARS; i++) { 943. /* when sym is the default background character, we process 944. i == 0 three times: unexplored, stone, dark part of a room */ 945. if (alt_i < 2) { 946. x_str = !alt_i++ ? "unexplored" : submerged ? "unknown" : "stone"; 947. i = 0; /* for second iteration, undo loop increment */ 948. /* alt_i is now 1 or 2 */ 949. } else { 950. if (alt_i++ == 2) 951. i = 0; /* undo loop increment */ 952. x_str = defsyms[i].explanation; 953. if (submerged && !strcmp(x_str, defsyms[0].explanation)) 954. x_str = "land"; /* replace "dark part of a room" */ 955. /* alt_i is now 3 or more and no longer of interest */ 956. } 957. if (sym == (looked ? showsyms[i] : defsyms[i].sym) && *x_str) { 958. /* avoid "an unexplored", "an stone", "an air", "a water", 959. "a floor of a room", "a dark part of a room"; 960. article==2 => "the", 1 => "an", 0 => (none) */ 961. int article = strstri(x_str, " of a room") ? 2 962. : !(alt_i <= 2 963. || strcmp(x_str, "air") == 0 964. || strcmp(x_str, "land") == 0 965. || strcmp(x_str, "water") == 0); 966. 967. if (!found) { 968. if (is_cmap_trap(i)) { 969. Sprintf(out_str, "%sa trap", prefix); 970. hit_trap = TRUE; 971. } else { 972. Sprintf(out_str, "%s%s", prefix, 973. article == 2 ? the(x_str) 974. : article == 1 ? an(x_str) : x_str); 975. } 976. *firstmatch = x_str; 977. found++; 978. } else if (!(hit_trap && is_cmap_trap(i)) 979. && !(found >= 3 && is_cmap_drawbridge(i)) 980. /* don't mention vibrating square outside of Gehennom 981. unless this happens to be one (hallucination?) */ 982. && (i != S_vibrating_square || Inhell 983. || (looked && glyph_is_trap(glyph) 984. && glyph_to_trap(glyph) == VIBRATING_SQUARE))) { 985. found += append_str(out_str, (article == 2) ? the(x_str) 986. : (article == 1) ? an(x_str) 987. : x_str); 988. if (is_cmap_trap(i)) 989. hit_trap = TRUE; 990. } 991. 992. if (i == S_altar || is_cmap_trap(i)) 993. need_to_look = TRUE; 994. } 995. } 996. 997. /* Now check for warning symbols */ 998. for (i = 1; i < WARNCOUNT; i++) { 999. x_str = def_warnsyms[i].explanation; 1000. if (sym == (looked ? warnsyms[i] : def_warnsyms[i].sym)) { 1001. if (!found) { 1002. Sprintf(out_str, "%s%s", prefix, def_warnsyms[i].explanation); 1003. *firstmatch = def_warnsyms[i].explanation; 1004. found++; 1005. } else { 1006. found += append_str(out_str, def_warnsyms[i].explanation); 1007. } 1008. /* Kludge: warning trumps boulders on the display. 1009. Reveal the boulder too or player can get confused */ 1010. if (looked && sobj_at(BOULDER, cc.x, cc.y)) 1011. Strcat(out_str, " co-located with a boulder"); 1012. break; /* out of for loop*/ 1013. } 1014. } 1015. 1016. /* if we ignored venom and list turned out to be short, put it back */ 1017. if (skipped_venom && found < 2) { 1018. x_str = def_oc_syms[VENOM_CLASS].explain; 1019. if (!found) { 1020. Sprintf(out_str, "%s%s", prefix, an(x_str)); 1021. *firstmatch = x_str; 1022. found++; 1023. } else { 1024. found += append_str(out_str, an(x_str)); 1025. } 1026. } 1027. 1028. /* handle optional boulder symbol as a special case */ 1029. if (iflags.bouldersym && sym == iflags.bouldersym) { 1030. if (!found) { 1031. *firstmatch = "boulder"; 1032. Sprintf(out_str, "%s%s", prefix, an(*firstmatch)); 1033. found++; 1034. } else { 1035. found += append_str(out_str, "boulder"); 1036. } 1037. } 1038. 1039. /* 1040. * If we are looking at the screen, follow multiple possibilities or 1041. * an ambiguous explanation by something more detailed. 1042. */ 1043. 1044. if (found > 4) 1045. Sprintf(out_str, "%s", "That can be many things"); 1046. 1047. didlook: 1048. if (looked) { 1049. struct permonst *pm = (struct permonst *)0; 1050. 1051. if (found > 1 || need_to_look) { 1052. char monbuf[BUFSZ]; 1053. char temp_buf[BUFSZ]; 1054. 1055. pm = lookat(cc.x, cc.y, look_buf, monbuf); 1056. if (pm && for_supplement) 1057. *for_supplement = pm; 1058. *firstmatch = look_buf; 1059. if (*(*firstmatch)) { 1060. Sprintf(temp_buf, " (%s)", *firstmatch); 1061. (void) strncat(out_str, temp_buf, 1062. BUFSZ - strlen(out_str) - 1); 1063. found = 1; /* we have something to look up */ 1064. } 1065. if (monbuf[0]) { 1066. Sprintf(temp_buf, " [seen: %s]", monbuf); 1067. (void) strncat(out_str, temp_buf, 1068. BUFSZ - strlen(out_str) - 1); 1069. } 1070. } 1071. } 1072. 1073. return found; 1074. } 1075. 1076. /* also used by getpos hack in do_name.c */ 1077. const char what_is_an_unknown_object[] = "an unknown object"; 1078. 1079. int 1080. do_look(mode, click_cc) 1081. int mode; 1082. coord *click_cc; 1083. { 1084. boolean quick = (mode == 1); /* use cursor; don't search for "more info" */ 1085. boolean clicklook = (mode == 2); /* right mouse-click method */ 1086. char out_str[BUFSZ] = DUMMY; 1087. const char *firstmatch = 0; 1088. struct permonst *pm = 0, *supplemental_pm = 0; 1089. int i = '\0', ans = 0; 1090. int sym; /* typed symbol or converted glyph */ 1091. int found; /* count of matching syms found */ 1092. coord cc; /* screen pos of unknown glyph */ 1093. boolean save_verbose; /* saved value of flags.verbose */ 1094. boolean from_screen; /* question from the screen */ 1095. 1096. cc.x = 0; 1097. cc.y = 0; 1098. 1099. if (!clicklook) { 1100. if (quick) { 1101. from_screen = TRUE; /* yes, we want to use the cursor */ 1102. i = 'y'; 1103. } else { 1104. menu_item *pick_list = (menu_item *) 0; 1105. winid win; 1106. anything any; 1107. 1108. any = zeroany; 1109. win = create_nhwindow(NHW_MENU); 1110. start_menu(win); 1111. any.a_char = '/'; 1112. /* 'y' and 'n' to keep backwards compatibility with previous 1113. versions: "Specify unknown object by cursor?" */ 1114. add_menu(win, NO_GLYPH, &any, 1115. flags.lootabc ? 0 : any.a_char, 'y', ATR_NONE, 1116. "something on the map", MENU_UNSELECTED); 1117. any.a_char = 'i'; 1118. add_menu(win, NO_GLYPH, &any, 1119. flags.lootabc ? 0 : any.a_char, 0, ATR_NONE, 1120. "something you're carrying", MENU_UNSELECTED); 1121. any.a_char = '?'; 1122. add_menu(win, NO_GLYPH, &any, 1123. flags.lootabc ? 0 : any.a_char, 'n', ATR_NONE, 1124. "something else (by symbol or name)", MENU_UNSELECTED); 1125. if (!u.uswallow && !Hallucination) { 1126. any = zeroany; 1127. add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, 1128. "", MENU_UNSELECTED); 1129. /* these options work sensibly for the swallowed case, 1130. but there's no reason for the player to use them then; 1131. objects work fine when hallucinating, but screen 1132. symbol/monster class letter doesn't match up with 1133. bogus monster type, so suppress when hallucinating */ 1134. any.a_char = 'm'; 1135. add_menu(win, NO_GLYPH, &any, 1136. flags.lootabc ? 0 : any.a_char, 0, ATR_NONE, 1137. "nearby monsters", MENU_UNSELECTED); 1138. any.a_char = 'M'; 1139. add_menu(win, NO_GLYPH, &any, 1140. flags.lootabc ? 0 : any.a_char, 0, ATR_NONE, 1141. "all monsters shown on map", MENU_UNSELECTED); 1142. any.a_char = 'o'; 1143. add_menu(win, NO_GLYPH, &any, 1144. flags.lootabc ? 0 : any.a_char, 0, ATR_NONE, 1145. "nearby objects", MENU_UNSELECTED); 1146. any.a_char = 'O'; 1147. add_menu(win, NO_GLYPH, &any, 1148. flags.lootabc ? 0 : any.a_char, 0, ATR_NONE, 1149. "all objects shown on map", MENU_UNSELECTED); 1150. } 1151. end_menu(win, "What do you want to look at:"); 1152. if (select_menu(win, PICK_ONE, &pick_list) > 0) { 1153. i = pick_list->item.a_char; 1154. free((genericptr_t) pick_list); 1155. } 1156. destroy_nhwindow(win); 1157. } 1158. 1159. switch (i) { 1160. default: 1161. case 'q': 1162. return 0; 1163. case 'y': 1164. case '/': 1165. from_screen = TRUE; 1166. sym = 0; 1167. cc.x = u.ux; 1168. cc.y = u.uy; 1169. break; 1170. case 'i': 1171. { 1172. char invlet; 1173. struct obj *invobj; 1174. 1175. invlet = display_inventory((const char *) 0, TRUE); 1176. if (!invlet || invlet == '\033') 1177. return 0; 1178. *out_str = '\0'; 1179. for (invobj = invent; invobj; invobj = invobj->nobj) 1180. if (invobj->invlet == invlet) { 1181. strcpy(out_str, singular(invobj, xname)); 1182. break; 1183. } 1184. if (*out_str) 1185. checkfile(out_str, pm, TRUE, TRUE, (char *) 0); 1186. return 0; 1187. } 1188. case '?': 1189. from_screen = FALSE; 1190. getlin("Specify what? (type the word)", out_str); 1191. if (strcmp(out_str, " ")) /* keep single space as-is */ 1192. /* remove leading and trailing whitespace and 1193. condense consecutive internal whitespace */ 1194. mungspaces(out_str); 1195. if (out_str[0] == '\0' || out_str[0] == '\033') 1196. return 0; 1197. 1198. if (out_str[1]) { /* user typed in a complete string */ 1199. checkfile(out_str, pm, TRUE, TRUE, (char *) 0); 1200. return 0; 1201. } 1202. sym = out_str[0]; 1203. break; 1204. case 'm': 1205. look_all(TRUE, TRUE); /* list nearby monsters */ 1206. return 0; 1207. case 'M': 1208. look_all(FALSE, TRUE); /* list all monsters */ 1209. return 0; 1210. case 'o': 1211. look_all(TRUE, FALSE); /* list nearby objects */ 1212. return 0; 1213. case 'O': 1214. look_all(FALSE, FALSE); /* list all objects */ 1215. return 0; 1216. } 1217. } else { /* clicklook */ 1218. cc.x = click_cc->x; 1219. cc.y = click_cc->y; 1220. sym = 0; 1221. from_screen = FALSE; 1222. } 1223. 1224. /* Save the verbose flag, we change it later. */ 1225. save_verbose = flags.verbose; 1226. flags.verbose = flags.verbose && !quick; 1227. /* 1228. * The user typed one letter, or we're identifying from the screen. 1229. */ 1230. do { 1231. /* Reset some variables. */ 1232. pm = (struct permonst *) 0; 1233. found = 0; 1234. out_str[0] = '\0'; 1235. 1236. if (from_screen || clicklook) { 1237. if (from_screen) { 1238. if (flags.verbose) 1239. pline("Please move the cursor to %s.", 1240. what_is_an_unknown_object); 1241. else 1242. pline("Pick an object."); 1243. 1244. ans = getpos(&cc, quick, what_is_an_unknown_object); 1245. if (ans < 0 || cc.x < 0) 1246. break; /* done */ 1247. flags.verbose = FALSE; /* only print long question once */ 1248. } 1249. } 1250. 1251. found = do_screen_description(cc, (from_screen || clicklook), sym, 1252. out_str, &firstmatch, &supplemental_pm); 1253. 1254. /* Finally, print out our explanation. */ 1255. if (found) { 1256. /* use putmixed() because there may be an encoded glyph present */ 1257. putmixed(WIN_MESSAGE, 0, out_str); 1258. #ifdef DUMPLOG 1259. { 1260. char dmpbuf[BUFSZ]; 1261. 1262. /* putmixed() bypasses pline() so doesn't write to DUMPLOG; 1263. tty puts it into ^P recall, so it ought to be there; 1264. DUMPLOG is plain text, so override graphics character; 1265. at present, force space, but we ought to use defsyms[] 1266. value for the glyph the graphics character came from */ 1267. (void) decode_mixed(dmpbuf, out_str); 1268. if (dmpbuf[0] < ' ' || dmpbuf[0] >= 127) /* ASCII isprint() */ 1269. dmpbuf[0] = ' '; 1270. dumplogmsg(dmpbuf); 1271. } 1272. #endif 1273. 1274. /* check the data file for information about this thing */ 1275. if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE 1276. && (ans == LOOK_VERBOSE || (flags.help && !quick)) 1277. && !clicklook) { 1278. char temp_buf[BUFSZ], supplemental_name[BUFSZ]; 1279. 1280. supplemental_name[0] = '\0'; 1281. Strcpy(temp_buf, firstmatch); 1282. checkfile(temp_buf, pm, FALSE, 1283. (boolean) (ans == LOOK_VERBOSE), supplemental_name); 1284. if (supplemental_pm) 1285. do_supplemental_info(supplemental_name, supplemental_pm, 1286. (boolean) (ans == LOOK_VERBOSE)); 1287. } 1288. } else { 1289. pline("I've never heard of such things."); 1290. } 1291. } while (from_screen && !quick && ans != LOOK_ONCE && !clicklook); 1292. 1293. flags.verbose = save_verbose; 1294. return 0; 1295. } 1296. 1297. STATIC_OVL void 1298. look_all(nearby, do_mons) 1299. boolean nearby; /* True => within BOLTLIM, False => entire map */ 1300. boolean do_mons; /* True => monsters, False => objects */ 1301. { 1302. winid win; 1303. int x, y, lo_x, lo_y, hi_x, hi_y, glyph, count = 0; 1304. char lookbuf[BUFSZ], outbuf[BUFSZ]; 1305. 1306. win = create_nhwindow(NHW_TEXT); 1307. lo_y = nearby ? max(u.uy - BOLT_LIM, 0) : 0; 1308. lo_x = nearby ? max(u.ux - BOLT_LIM, 1) : 1; 1309. hi_y = nearby ? min(u.uy + BOLT_LIM, ROWNO - 1) : ROWNO - 1; 1310. hi_x = nearby ? min(u.ux + BOLT_LIM, COLNO - 1) : COLNO - 1; 1311. for (y = lo_y; y <= hi_y; y++) { 1312. for (x = lo_x; x <= hi_x; x++) { 1313. lookbuf[0] = '\0'; 1314. glyph = glyph_at(x, y); 1315. if (do_mons) { 1316. if (glyph_is_monster(glyph)) { 1317. struct monst *mtmp; 1318. 1319. bhitpos.x = x; /* [is this actually necessary?] */ 1320. bhitpos.y = y; 1321. if (x == u.ux && y == u.uy && canspotself()) { 1322. (void) self_lookat(lookbuf); 1323. ++count; 1324. } else if ((mtmp = m_at(x, y)) != 0) { 1325. look_at_monster(lookbuf, (char *) 0, mtmp, x, y); 1326. ++count; 1327. } 1328. } else if (glyph_is_invisible(glyph)) { 1329. /* remembered, unseen, creature */ 1330. Strcpy(lookbuf, invisexplain); 1331. ++count; 1332. } else if (glyph_is_warning(glyph)) { 1333. int warnindx = glyph_to_warning(glyph); 1334. 1335. Strcpy(lookbuf, def_warnsyms[warnindx].explanation); 1336. ++count; 1337. } 1338. } else { /* !do_mons */ 1339. if (glyph_is_object(glyph)) { 1340. look_at_object(lookbuf, x, y, glyph); 1341. ++count; 1342. } 1343. } 1344. if (*lookbuf) { 1345. char coordbuf[20], which[12], cmode; 1346. 1347. cmode = (iflags.getpos_coords != GPCOORDS_NONE) 1348. ? iflags.getpos_coords : GPCOORDS_MAP; 1349. if (count == 1) { 1350. Strcpy(which, do_mons ? "monsters" : "objects"); 1351. if (nearby) 1352. Sprintf(outbuf, "%s currently shown near %s:", 1353. upstart(which), 1354. (cmode != GPCOORDS_COMPASS) 1355. ? coord_desc(u.ux, u.uy, coordbuf, cmode) 1356. : !canspotself() ? "your position" : "you"); 1357. else 1358. Sprintf(outbuf, "All %s currently shown on the map:", 1359. which); 1360. putstr(win, 0, outbuf); 1361. putstr(win, 0, ""); 1362. } 1363. /* prefix: "coords C " where 'C' is mon or obj symbol */ 1364. Sprintf(outbuf, (cmode == GPCOORDS_SCREEN) ? "%s " 1365. : (cmode == GPCOORDS_MAP) ? "%8s " 1366. : "%12s ", 1367. coord_desc(x, y, coordbuf, cmode)); 1368. Sprintf(eos(outbuf), "%s ", encglyph(glyph)); 1369. /* guard against potential overflow */ 1370. lookbuf[sizeof lookbuf - 1 - strlen(outbuf)] = '\0'; 1371. Strcat(outbuf, lookbuf); 1372. putmixed(win, 0, outbuf); 1373. } 1374. } 1375. } 1376. if (count) 1377. display_nhwindow(win, TRUE); 1378. else 1379. pline("No %s are currently shown %s.", 1380. do_mons ? "monsters" : "objects", 1381. nearby ? "nearby" : "on the map"); 1382. destroy_nhwindow(win); 1383. } 1384. 1385. static const char *suptext1[] = { 1386. "%s is a member of a marauding horde of orcs", 1387. "rumored to have brutally attacked and plundered", 1388. "the ordinarily sheltered town that is located ", 1389. "deep within The Gnomish Mines.", 1390. "", 1391. "The members of that vicious horde proudly and ", 1392. "defiantly acclaim their allegiance to their", 1393. "leader %s in their names.", 1394. (char *) 0, 1395. }; 1396. 1397. static const char *suptext2[] = { 1398. "\"%s\" is the common dungeon name of", 1399. "a nefarious orc who is known to acquire property", 1400. "from thieves and sell it off for profit.", 1401. "", 1402. "The perpetrator was last seen hanging around the", 1403. "stairs leading to the Gnomish Mines.", 1404. (char *) 0, 1405. }; 1406. 1407. void 1408. do_supplemental_info(name, pm, without_asking) 1409. char *name; 1410. struct permonst *pm; 1411. boolean without_asking; 1412. { 1413. const char **textp; 1414. winid datawin = WIN_ERR; 1415. char *entrytext = name, *bp = (char *) 0, *bp2 = (char *) 0; 1416. char question[QBUFSZ]; 1417. boolean yes_to_moreinfo = FALSE; 1418. boolean is_marauder = (name && pm && is_orc(pm)); 1419. 1420. /* 1421. * Provide some info on some specific things 1422. * meant to support in-game mythology, and not 1423. * available from data.base or other sources. 1424. */ 1425. if (is_marauder && (strlen(name) < (BUFSZ - 1))) { 1426. char fullname[BUFSZ]; 1427. 1428. bp = strstri(name, " of "); 1429. bp2 = strstri(name, " the Fence"); 1430. 1431. if (bp || bp2) { 1432. Strcpy(fullname, name); 1433. if (!without_asking) { 1434. Strcpy(question, "More info about \""); 1435. /* +2 => length of "\"?" */ 1436. copynchars(eos(question), entrytext, 1437. (int) (sizeof question - 1 - (strlen(question) + 2))); 1438. Strcat(question, "\"?"); 1439. if (yn(question) == 'y') 1440. yes_to_moreinfo = TRUE; 1441. } 1442. if (yes_to_moreinfo) { 1443. int i, subs = 0; 1444. const char *gang = (char *) 0; 1445. 1446. if (bp) { 1447. textp = suptext1; 1448. gang = bp + 4; 1449. *bp = '\0'; 1450. } else { 1451. textp = suptext2; 1452. gang = ""; 1453. } 1454. datawin = create_nhwindow(NHW_MENU); 1455. for (i = 0; textp[i]; i++) { 1456. char buf[BUFSZ]; 1457. const char *txt; 1458. 1459. if (strstri(textp[i], "%s") != 0) { 1460. Sprintf(buf, textp[i], subs++ ? gang : fullname); 1461. txt = buf; 1462. } else 1463. txt = textp[i]; 1464. putstr(datawin, 0, txt); 1465. } 1466. display_nhwindow(datawin, FALSE); 1467. destroy_nhwindow(datawin), datawin = WIN_ERR; 1468. } 1469. } 1470. } 1471. } 1472. 1473. /* the '/' command */ 1474. int 1475. dowhatis() 1476. { 1477. return do_look(0, (coord *) 0); 1478. } 1479. 1480. /* the ';' command */ 1481. int 1482. doquickwhatis() 1483. { 1484. return do_look(1, (coord *) 0); 1485. } 1486. 1487. /* the '^' command */ 1488. int 1489. doidtrap() 1490. { 1491. register struct trap *trap; 1492. int x, y, tt, glyph; 1493. 1494. if (!getdir("^")) 1495. return 0; 1496. x = u.ux + u.dx; 1497. y = u.uy + u.dy; 1498. 1499. /* check fake bear trap from confused gold detection */ 1500. glyph = glyph_at(x, y); 1501. if (glyph_is_trap(glyph) && (tt = glyph_to_trap(glyph)) == BEAR_TRAP) { 1502. boolean chesttrap = trapped_chest_at(tt, x, y); 1503. 1504. if (chesttrap || trapped_door_at(tt, x, y)) { 1505. pline("That is a trapped %s.", chesttrap ? "chest" : "door"); 1506. return 0; /* trap ID'd, but no time elapses */ 1507. } 1508. } 1509. 1510. for (trap = ftrap; trap; trap = trap->ntrap) 1511. if (trap->tx == x && trap->ty == y) { 1512. if (!trap->tseen) 1513. break; 1514. tt = trap->ttyp; 1515. if (u.dz) { 1516. if (u.dz < 0 ? is_hole(tt) : tt == ROCKTRAP) 1517. break; 1518. } 1519. tt = what_trap(tt, rn2_on_display_rng); 1520. pline("That is %s%s%s.", 1521. an(defsyms[trap_to_defsym(tt)].explanation), 1522. !trap->madeby_u 1523. ? "" 1524. : (tt == WEB) 1525. ? " woven" 1526. /* trap doors & spiked pits can't be made by 1527. player, and should be considered at least 1528. as much "set" as "dug" anyway */ 1529. : (tt == HOLE || tt == PIT) 1530. ? " dug" 1531. : " set", 1532. !trap->madeby_u ? "" : " by you"); 1533. return 0; 1534. } 1535. pline("I can't see a trap there."); 1536. return 0; 1537. } 1538. 1539. /* 1540. Implements a rudimentary if/elif/else/endif interpretor and use 1541. conditionals in dat/cmdhelp to describe what command each keystroke 1542. currently invokes, so that there isn't a lot of "(debug mode only)" 1543. and "(if number_pad is off)" cluttering the feedback that the user 1544. sees. (The conditionals add quite a bit of clutter to the raw data 1545. but users don't see that. number_pad produces a lot of conditional 1546. commands: basic letters vs digits, 'g' vs 'G' for '5', phone 1547. keypad vs normal layout of digits, and QWERTZ keyboard swap between 1548. y/Y/^Y/M-y/M-Y/M-^Y and z/Z/^Z/M-z/M-Z/M-^Z.) 1549. 1550. The interpretor understands 1551. '&#' for comment, 1552. '&? option' for 'if' (also '&? !option' 1553. or '&? option=value[,value2,...]' 1554. or '&? !option=value[,value2,...]'), 1555. '&: option' for 'elif' (with argument variations same as 'if'; 1556. any number of instances for each 'if'), 1557. '&:' for 'else' (also '&: #comment'; 1558. 0 or 1 instance for a given 'if'), and 1559. '&.' for 'endif' (also '&. #comment'; required for each 'if'). 1560. 1561. The option handling is a bit of a mess, with no generality for 1562. which options to deal with and only a comma separated list of 1563. integer values for the '=value' part. number_pad is the only 1564. supported option that has a value; the few others (wizard/debug, 1565. rest_on_space, #if SHELL, #if SUSPEND) are booleans. 1566. */ 1567. 1568. STATIC_DCL void 1569. whatdoes_help() 1570. { 1571. dlb *fp; 1572. char *p, buf[BUFSZ]; 1573. winid tmpwin = create_nhwindow(NHW_TEXT); 1574. 1575. fp = dlb_fopen(KEYHELP, "r"); 1576. if (!fp) { 1577. pline("Cannot open \"%s\" data file!", KEYHELP); 1578. display_nhwindow(WIN_MESSAGE, TRUE); 1579. return; 1580. } 1581. while (dlb_fgets(buf, (int) sizeof buf, fp)) { 1582. if (*buf == '#') 1583. continue; 1584. for (p = buf; *p; p++) 1585. if (*p != ' ' && *p != '\t') 1586. break; 1587. putstr(tmpwin, 0, p); 1588. } 1589. (void) dlb_fclose(fp); 1590. display_nhwindow(tmpwin, TRUE); 1591. destroy_nhwindow(tmpwin); 1592. } 1593. 1594. #if 0 1595. #define WD_STACKLIMIT 5 1596. struct wd_stack_frame { 1597. Bitfield(active, 1); 1598. Bitfield(been_true, 1); 1599. Bitfield(else_seen, 1); 1600. }; 1601. 1602. STATIC_DCL boolean FDECL(whatdoes_cond, (char *, struct wd_stack_frame *, 1603. int *, int)); 1604. 1605. STATIC_OVL boolean 1606. whatdoes_cond(buf, stack, depth, lnum) 1607. char *buf; 1608. struct wd_stack_frame *stack; 1609. int *depth, lnum; 1610. { 1611. const char badstackfmt[] = "cmdhlp: too many &%c directives at line %d."; 1612. boolean newcond, neg, gotopt; 1613. char *p, *q, act = buf[1]; 1614. int np = 0; 1615. 1616. newcond = (act == '?' || !stack[*depth].been_true); 1617. buf += 2; 1618. mungspaces(buf); 1619. if (act == '#' || *buf == '#' || !*buf || !newcond) { 1620. gotopt = (*buf && *buf != '#'); 1621. *buf = '\0'; 1622. neg = FALSE; /* lint suppression */ 1623. p = q = (char *) 0; 1624. } else { 1625. gotopt = TRUE; 1626. if ((neg = (*buf == '!')) != 0) 1627. if (*++buf == ' ') 1628. ++buf; 1629. p = index(buf, '='), q = index(buf, ':'); 1630. if (!p || (q && q < p)) 1631. p = q; 1632. if (p) { /* we have a value specified */ 1633. /* handle a space before or after (or both) '=' (or ':') */ 1634. if (p > buf && p[-1] == ' ') 1635. p[-1] = '\0'; /* end of keyword in buf[] */ 1636. *p++ = '\0'; /* terminate keyword, advance to start of value */ 1637. if (*p == ' ') 1638. p++; 1639. } 1640. } 1641. if (*buf && (act == '?' || act == ':')) { 1642. if (!strcmpi(buf, "number_pad")) { 1643. if (!p) { 1644. newcond = iflags.num_pad; 1645. } else { 1646. /* convert internal encoding (separate yes/no and 0..3) 1647. back to user-visible one (-1..4) */ 1648. np = iflags.num_pad ? (1 + iflags.num_pad_mode) /* 1..4 */ 1649. : (-1 * iflags.num_pad_mode); /* -1..0 */ 1650. newcond = FALSE; 1651. for (; p; p = q) { 1652. q = index(p, ','); 1653. if (q) 1654. *q++ = '\0'; 1655. if (atoi(p) == np) { 1656. newcond = TRUE; 1657. break; 1658. } 1659. } 1660. } 1661. } else if (!strcmpi(buf, "rest_on_space")) { 1662. newcond = flags.rest_on_space; 1663. } else if (!strcmpi(buf, "debug") || !strcmpi(buf, "wizard")) { 1664. newcond = flags.debug; /* == wizard */ 1665. } else if (!strcmpi(buf, "shell")) { 1666. #ifdef SHELL 1667. /* should we also check sysopt.shellers? */ 1668. newcond = TRUE; 1669. #else 1670. newcond = FALSE; 1671. #endif 1672. } else if (!strcmpi(buf, "suspend")) { 1673. #ifdef SUSPEND 1674. /* sysopt.shellers is also used for dosuspend()... */ 1675. newcond = TRUE; 1676. #else 1677. newcond = FALSE; 1678. #endif 1679. } else { 1680. impossible( 1681. "cmdhelp: unrecognized &%c conditional at line %d: \"%.20s\"", 1682. act, lnum, buf); 1683. neg = FALSE; 1684. } 1685. /* this works for number_pad too: &? !number_pad:-1,0 1686. would be true for 1..4 after negation */ 1687. if (neg) 1688. newcond = !newcond; 1689. } 1690. switch (act) { 1691. default: 1692. case '#': /* comment */ 1693. break; 1694. case '.': /* endif */ 1695. if (--*depth < 0) { 1696. impossible(badstackfmt, '.', lnum); 1697. *depth = 0; 1698. } 1699. break; 1700. case ':': /* else or elif */ 1701. if (*depth == 0 || stack[*depth].else_seen) { 1702. impossible(badstackfmt, ':', lnum); 1703. *depth = 1; /* so that stack[*depth - 1] is a valid access */ 1704. } 1705. if (stack[*depth].active || stack[*depth].been_true 1706. || !stack[*depth - 1].active) 1707. stack[*depth].active = 0; 1708. else if (newcond) 1709. stack[*depth].active = stack[*depth].been_true = 1; 1710. if (!gotopt) 1711. stack[*depth].else_seen = 1; 1712. break; 1713. case '?': /* if */ 1714. if (++*depth >= WD_STACKLIMIT) { 1715. impossible(badstackfmt, '?', lnum); 1716. *depth = WD_STACKLIMIT - 1; 1717. } 1718. stack[*depth].active = (newcond && stack[*depth - 1].active) ? 1 : 0; 1719. stack[*depth].been_true = stack[*depth].active; 1720. stack[*depth].else_seen = 0; 1721. break; 1722. } 1723. return stack[*depth].active ? TRUE : FALSE; 1724. } 1725. #endif /* 0 */ 1726. 1727. char * 1728. dowhatdoes_core(q, cbuf) 1729. char q; 1730. char *cbuf; 1731. { 1732. char buf[BUFSZ]; 1733. #if 0 1734. dlb *fp; 1735. struct wd_stack_frame stack[WD_STACKLIMIT]; 1736. boolean cond; 1737. int ctrl, meta, depth = 0, lnum = 0; 1738. #endif /* 0 */ 1739. const char *ec_desc; 1740. 1741. if ((ec_desc = key2extcmddesc(q)) != NULL) { 1742. char keybuf[QBUFSZ]; 1743. 1744. Sprintf(buf, "%-8s%s.", key2txt(q, keybuf), ec_desc); 1745. Strcpy(cbuf, buf); 1746. return cbuf; 1747. } 1748. return 0; 1749. #if 0 1750. fp = dlb_fopen(CMDHELPFILE, "r"); 1751. if (!fp) { 1752. pline("Cannot open \"%s\" data file!", CMDHELPFILE); 1753. return 0; 1754. } 1755. 1756. meta = (0x80 & (uchar) q) != 0; 1757. if (meta) 1758. q &= 0x7f; 1759. ctrl = (0x1f & (uchar) q) == (uchar) q; 1760. if (ctrl) 1761. q |= 0x40; /* NUL -> '@', ^A -> 'A', ... ^Z -> 'Z', ^[ -> '[', ... */ 1762. else if (q == 0x7f) 1763. ctrl = 1, q = '?'; 1764. 1765. (void) memset((genericptr_t) stack, 0, sizeof stack); 1766. cond = stack[0].active = 1; 1767. while (dlb_fgets(buf, sizeof buf, fp)) { 1768. ++lnum; 1769. if (buf[0] == '&' && buf[1] && index("?:.#", buf[1])) { 1770. cond = whatdoes_cond(buf, stack, &depth, lnum); 1771. continue; 1772. } 1773. if (!cond) 1774. continue; 1775. if (meta ? (buf[0] == 'M' && buf[1] == '-' 1776. && (ctrl ? buf[2] == '^' && highc(buf[3]) == q 1777. : buf[2] == q)) 1778. : (ctrl ? buf[0] == '^' && highc(buf[1]) == q 1779. : buf[0] == q)) { 1780. (void) strip_newline(buf); 1781. if (index(buf, '\t')) 1782. (void) tabexpand(buf); 1783. if (meta && ctrl && buf[4] == ' ') { 1784. (void) strncpy(buf, "M-^? ", 8); 1785. buf[3] = q; 1786. } else if (meta && buf[3] == ' ') { 1787. (void) strncpy(buf, "M-? ", 8); 1788. buf[2] = q; 1789. } else if (ctrl && buf[2] == ' ') { 1790. (void) strncpy(buf, "^? ", 8); 1791. buf[1] = q; 1792. } else if (buf[1] == ' ') { 1793. (void) strncpy(buf, "? ", 8); 1794. buf[0] = q; 1795. } 1796. (void) dlb_fclose(fp); 1797. Strcpy(cbuf, buf); 1798. return cbuf; 1799. } 1800. } 1801. (void) dlb_fclose(fp); 1802. if (depth != 0) 1803. impossible("cmdhelp: mismatched &? &: &. conditionals."); 1804. return (char *) 0; 1805. #endif /* 0 */ 1806. } 1807. 1808. int 1809. dowhatdoes() 1810. { 1811. static boolean once = FALSE; 1812. char bufr[BUFSZ]; 1813. char q, *reslt; 1814. 1815. if (!once) { 1816. pline("Ask about '&' or '?' to get more info.%s", 1817. #ifdef ALTMETA 1818. iflags.altmeta ? " (For ESC, type it twice.)" : 1819. #endif 1820. ""); 1821. once = TRUE; 1822. } 1823. #if defined(UNIX) || defined(VMS) 1824. introff(); /* disables ^C but not ^\ */ 1825. #endif 1826. q = yn_function("What command?", (char *) 0, '\0'); 1827. #ifdef ALTMETA 1828. if (q == '\033' && iflags.altmeta) { 1829. /* in an ideal world, we would know whether another keystroke 1830. was already pending, but this is not an ideal world... 1831. if user typed ESC, we'll essentially hang until another 1832. character is typed */ 1833. q = yn_function("]", (char *) 0, '\0'); 1834. if (q != '\033') 1835. q = (char) ((uchar) q | 0200); 1836. } 1837. #endif /*ALTMETA*/ 1838. #if defined(UNIX) || defined(VMS) 1839. intron(); /* reenables ^C */ 1840. #endif 1841. reslt = dowhatdoes_core(q, bufr); 1842. if (reslt) { 1843. if (q == '&' || q == '?') 1844. whatdoes_help(); 1845. pline("%s", reslt); 1846. } else { 1847. pline("No such command '%s', char code %d (0%03o or 0x%02x).", 1848. visctrl(q), (uchar) q, (uchar) q, (uchar) q); 1849. } 1850. return 0; 1851. } 1852. 1853. STATIC_OVL void 1854. docontact(VOID_ARGS) 1855. { 1856. winid cwin = create_nhwindow(NHW_TEXT); 1857. char buf[BUFSZ]; 1858. 1859. if (sysopt.support) { 1860. /*XXX overflow possibilities*/ 1861. Sprintf(buf, "To contact local support, %s", sysopt.support); 1862. putstr(cwin, 0, buf); 1863. putstr(cwin, 0, ""); 1864. } else if (sysopt.fmtd_wizard_list) { /* formatted SYSCF WIZARDS */ 1865. Sprintf(buf, "To contact local support, contact %s.", 1866. sysopt.fmtd_wizard_list); 1867. putstr(cwin, 0, buf); 1868. putstr(cwin, 0, ""); 1869. } 1870. putstr(cwin, 0, "To contact the NetHack development team directly,"); 1871. /*XXX overflow possibilities*/ 1872. Sprintf(buf, "see the 'Contact' form on our website or email <%s>.", 1873. DEVTEAM_EMAIL); 1874. putstr(cwin, 0, buf); 1875. putstr(cwin, 0, ""); 1876. putstr(cwin, 0, "For more information on NetHack, or to report a bug,"); 1877. Sprintf(buf, "visit our website \"%s\".", DEVTEAM_URL); 1878. putstr(cwin, 0, buf); 1879. display_nhwindow(cwin, FALSE); 1880. destroy_nhwindow(cwin); 1881. } 1882. 1883. void 1884. dispfile_help(VOID_ARGS) 1885. { 1886. display_file(HELP, TRUE); 1887. } 1888. 1889. void 1890. dispfile_shelp(VOID_ARGS) 1891. { 1892. display_file(SHELP, TRUE); 1893. } 1894. 1895. void 1896. dispfile_optionfile(VOID_ARGS) 1897. { 1898. display_file(OPTIONFILE, TRUE); 1899. } 1900. 1901. void 1902. dispfile_license(VOID_ARGS) 1903. { 1904. display_file(LICENSE, TRUE); 1905. } 1906. 1907. void 1908. dispfile_debughelp(VOID_ARGS) 1909. { 1910. display_file(DEBUGHELP, TRUE); 1911. } 1912. 1913. void 1914. hmenu_doextversion(VOID_ARGS) 1915. { 1916. (void) doextversion(); 1917. } 1918. 1919. void 1920. hmenu_dohistory(VOID_ARGS) 1921. { 1922. (void) dohistory(); 1923. } 1924. 1925. void 1926. hmenu_dowhatis(VOID_ARGS) 1927. { 1928. (void) dowhatis(); 1929. } 1930. 1931. void 1932. hmenu_dowhatdoes(VOID_ARGS) 1933. { 1934. (void) dowhatdoes(); 1935. } 1936. 1937. void 1938. hmenu_doextlist(VOID_ARGS) 1939. { 1940. (void) doextlist(); 1941. } 1942. 1943. void 1944. domenucontrols(VOID_ARGS) 1945. { 1946. winid cwin = create_nhwindow(NHW_TEXT); 1947. show_menu_controls(cwin, FALSE); 1948. display_nhwindow(cwin, FALSE); 1949. destroy_nhwindow(cwin); 1950. } 1951. 1952. /* data for dohelp() */ 1953. static struct { 1954. void NDECL((*f)); 1955. const char *text; 1956. } help_menu_items[] = { 1957. { hmenu_doextversion, "About NetHack (version information)." }, 1958. { dispfile_help, "Long description of the game and commands." }, 1959. { dispfile_shelp, "List of game commands." }, 1960. { hmenu_dohistory, "Concise history of NetHack." }, 1961. { hmenu_dowhatis, "Info on a character in the game display." }, 1962. { hmenu_dowhatdoes, "Info on what a given key does." }, 1963. { option_help, "List of game options." }, 1964. { dispfile_optionfile, "Longer explanation of game options." }, 1965. { dokeylist, "Full list of keyboard commands" }, 1966. { hmenu_doextlist, "List of extended commands." }, 1967. { domenucontrols, "List menu control keys" }, 1968. { dispfile_license, "The NetHack license." }, 1969. { docontact, "Support information." }, 1970. #ifdef PORT_HELP 1971. { port_help, "%s-specific help and commands." }, 1972. #endif 1973. { dispfile_debughelp, "List of wizard-mode commands." }, 1974. { (void NDECL((*))) 0, (char *) 0 } 1975. }; 1976. 1977. /* the '?' command */ 1978. int 1979. dohelp() 1980. { 1981. winid tmpwin = create_nhwindow(NHW_MENU); 1982. char helpbuf[QBUFSZ]; 1983. int i, n; 1984. menu_item *selected; 1985. anything any; 1986. int sel; 1987. 1988. any = zeroany; /* zero all bits */ 1989. start_menu(tmpwin); 1990. 1991. for (i = 0; help_menu_items[i].text; i++) { 1992. if (!wizard && help_menu_items[i].f == dispfile_debughelp) 1993. continue; 1994. if (help_menu_items[i].text[0] == '%') { 1995. Sprintf(helpbuf, help_menu_items[i].text, PORT_ID); 1996. } else { 1997. Strcpy(helpbuf, help_menu_items[i].text); 1998. } 1999. any.a_int = i + 1; 2000. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 2001. helpbuf, MENU_UNSELECTED); 2002. } 2003. end_menu(tmpwin, "Select one item:"); 2004. n = select_menu(tmpwin, PICK_ONE, &selected); 2005. destroy_nhwindow(tmpwin); 2006. if (n > 0) { 2007. sel = selected[0].item.a_int - 1; 2008. free((genericptr_t) selected); 2009. (void) (*help_menu_items[sel].f)(); 2010. } 2011. return 0; 2012. } 2013. 2014. /* the 'V' command; also a choice for '?' */ 2015. int 2016. dohistory() 2017. { 2018. display_file(HISTORY, TRUE); 2019. return 0; 2020. } 2021. 2022. /*pager.c*/