Source:NetHack 3.6.2/src/cmd.c
Jump to navigation
Jump to search
Below is the full text to cmd.c from the source code of NetHack 3.6.2. To link to a particular line, write [[Source:NetHack 3.6.2/src/cmd.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 cmd.c $NHDT-Date: 1557088405 2019/05/05 20:33:25 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.333 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2013. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. #include "lev.h" 8. #include "func_tab.h" 9. 10. /* Macros for meta and ctrl modifiers: 11. * M and C return the meta/ctrl code for the given character; 12. * e.g., (C('c') is ctrl-c 13. */ 14. #ifndef M 15. #ifndef NHSTDC 16. #define M(c) (0x80 | (c)) 17. #else 18. #define M(c) ((c) - 128) 19. #endif /* NHSTDC */ 20. #endif 21. 22. #ifndef C 23. #define C(c) (0x1f & (c)) 24. #endif 25. 26. #ifdef ALTMETA 27. STATIC_VAR boolean alt_esc = FALSE; 28. #endif 29. 30. struct cmd Cmd = { 0 }; /* flag.h */ 31. 32. extern const char *hu_stat[]; /* hunger status from eat.c */ 33. extern const char *enc_stat[]; /* encumbrance status from botl.c */ 34. 35. #ifdef UNIX 36. /* 37. * Some systems may have getchar() return EOF for various reasons, and 38. * we should not quit before seeing at least NR_OF_EOFS consecutive EOFs. 39. */ 40. #if defined(SYSV) || defined(DGUX) || defined(HPUX) 41. #define NR_OF_EOFS 20 42. #endif 43. #endif 44. 45. #define CMD_TRAVEL (char) 0x90 46. #define CMD_CLICKLOOK (char) 0x8F 47. 48. #ifdef DEBUG 49. extern int NDECL(wiz_debug_cmd_bury); 50. #endif 51. 52. #ifdef DUMB /* stuff commented out in extern.h, but needed here */ 53. extern int NDECL(doapply); /**/ 54. extern int NDECL(dorub); /**/ 55. extern int NDECL(dojump); /**/ 56. extern int NDECL(doextlist); /**/ 57. extern int NDECL(enter_explore_mode); /**/ 58. extern int NDECL(dodrop); /**/ 59. extern int NDECL(doddrop); /**/ 60. extern int NDECL(dodown); /**/ 61. extern int NDECL(doup); /**/ 62. extern int NDECL(donull); /**/ 63. extern int NDECL(dowipe); /**/ 64. extern int NDECL(docallcnd); /**/ 65. extern int NDECL(dotakeoff); /**/ 66. extern int NDECL(doremring); /**/ 67. extern int NDECL(dowear); /**/ 68. extern int NDECL(doputon); /**/ 69. extern int NDECL(doddoremarm); /**/ 70. extern int NDECL(dokick); /**/ 71. extern int NDECL(dofire); /**/ 72. extern int NDECL(dothrow); /**/ 73. extern int NDECL(doeat); /**/ 74. extern int NDECL(done2); /**/ 75. extern int NDECL(vanquished); /**/ 76. extern int NDECL(doengrave); /**/ 77. extern int NDECL(dopickup); /**/ 78. extern int NDECL(ddoinv); /**/ 79. extern int NDECL(dotypeinv); /**/ 80. extern int NDECL(dolook); /**/ 81. extern int NDECL(doprgold); /**/ 82. extern int NDECL(doprwep); /**/ 83. extern int NDECL(doprarm); /**/ 84. extern int NDECL(doprring); /**/ 85. extern int NDECL(dopramulet); /**/ 86. extern int NDECL(doprtool); /**/ 87. extern int NDECL(dosuspend); /**/ 88. extern int NDECL(doforce); /**/ 89. extern int NDECL(doopen); /**/ 90. extern int NDECL(doclose); /**/ 91. extern int NDECL(dosh); /**/ 92. extern int NDECL(dodiscovered); /**/ 93. extern int NDECL(doclassdisco); /**/ 94. extern int NDECL(doset); /**/ 95. extern int NDECL(dotogglepickup); /**/ 96. extern int NDECL(dowhatis); /**/ 97. extern int NDECL(doquickwhatis); /**/ 98. extern int NDECL(dowhatdoes); /**/ 99. extern int NDECL(dohelp); /**/ 100. extern int NDECL(dohistory); /**/ 101. extern int NDECL(doloot); /**/ 102. extern int NDECL(dodrink); /**/ 103. extern int NDECL(dodip); /**/ 104. extern int NDECL(dosacrifice); /**/ 105. extern int NDECL(dopray); /**/ 106. extern int NDECL(dotip); /**/ 107. extern int NDECL(doturn); /**/ 108. extern int NDECL(doredraw); /**/ 109. extern int NDECL(doread); /**/ 110. extern int NDECL(dosave); /**/ 111. extern int NDECL(dosearch); /**/ 112. extern int NDECL(doidtrap); /**/ 113. extern int NDECL(dopay); /**/ 114. extern int NDECL(dosit); /**/ 115. extern int NDECL(dotalk); /**/ 116. extern int NDECL(docast); /**/ 117. extern int NDECL(dovspell); /**/ 118. extern int NDECL(dotelecmd); /**/ 119. extern int NDECL(dountrap); /**/ 120. extern int NDECL(doversion); /**/ 121. extern int NDECL(doextversion); /**/ 122. extern int NDECL(doswapweapon); /**/ 123. extern int NDECL(dowield); /**/ 124. extern int NDECL(dowieldquiver); /**/ 125. extern int NDECL(dozap); /**/ 126. extern int NDECL(doorganize); /**/ 127. #endif /* DUMB */ 128. 129. static int NDECL((*timed_occ_fn)); 130. 131. STATIC_PTR int NDECL(dosuspend_core); 132. STATIC_PTR int NDECL(dosh_core); 133. STATIC_PTR int NDECL(doherecmdmenu); 134. STATIC_PTR int NDECL(dotherecmdmenu); 135. STATIC_PTR int NDECL(doprev_message); 136. STATIC_PTR int NDECL(timed_occupation); 137. STATIC_PTR int NDECL(doextcmd); 138. STATIC_PTR int NDECL(dotravel); 139. STATIC_PTR int NDECL(doterrain); 140. STATIC_PTR int NDECL(wiz_wish); 141. STATIC_PTR int NDECL(wiz_identify); 142. STATIC_PTR int NDECL(wiz_intrinsic); 143. STATIC_PTR int NDECL(wiz_map); 144. STATIC_PTR int NDECL(wiz_makemap); 145. STATIC_PTR int NDECL(wiz_genesis); 146. STATIC_PTR int NDECL(wiz_where); 147. STATIC_PTR int NDECL(wiz_detect); 148. STATIC_PTR int NDECL(wiz_panic); 149. STATIC_PTR int NDECL(wiz_polyself); 150. STATIC_PTR int NDECL(wiz_level_tele); 151. STATIC_PTR int NDECL(wiz_level_change); 152. STATIC_PTR int NDECL(wiz_show_seenv); 153. STATIC_PTR int NDECL(wiz_show_vision); 154. STATIC_PTR int NDECL(wiz_smell); 155. STATIC_PTR int NDECL(wiz_intrinsic); 156. STATIC_PTR int NDECL(wiz_show_wmodes); 157. STATIC_DCL void NDECL(wiz_map_levltyp); 158. STATIC_DCL void NDECL(wiz_levltyp_legend); 159. #if defined(__BORLANDC__) && !defined(_WIN32) 160. extern void FDECL(show_borlandc_stats, (winid)); 161. #endif 162. #ifdef DEBUG_MIGRATING_MONS 163. STATIC_PTR int NDECL(wiz_migrate_mons); 164. #endif 165. STATIC_DCL int FDECL(size_monst, (struct monst *, BOOLEAN_P)); 166. STATIC_DCL int FDECL(size_obj, (struct obj *)); 167. STATIC_DCL void FDECL(count_obj, (struct obj *, long *, long *, 168. BOOLEAN_P, BOOLEAN_P)); 169. STATIC_DCL void FDECL(obj_chain, (winid, const char *, struct obj *, 170. BOOLEAN_P, long *, long *)); 171. STATIC_DCL void FDECL(mon_invent_chain, (winid, const char *, struct monst *, 172. long *, long *)); 173. STATIC_DCL void FDECL(mon_chain, (winid, const char *, struct monst *, 174. BOOLEAN_P, long *, long *)); 175. STATIC_DCL void FDECL(contained_stats, (winid, const char *, long *, long *)); 176. STATIC_DCL void FDECL(misc_stats, (winid, long *, long *)); 177. STATIC_PTR int NDECL(wiz_show_stats); 178. STATIC_DCL boolean FDECL(accept_menu_prefix, (int NDECL((*)))); 179. STATIC_PTR int NDECL(wiz_rumor_check); 180. STATIC_PTR int NDECL(doattributes); 181. 182. STATIC_DCL void FDECL(enlght_out, (const char *)); 183. STATIC_DCL void FDECL(enlght_line, (const char *, const char *, const char *, 184. const char *)); 185. STATIC_DCL char *FDECL(enlght_combatinc, (const char *, int, int, char *)); 186. STATIC_DCL void FDECL(enlght_halfdmg, (int, int)); 187. STATIC_DCL boolean NDECL(walking_on_water); 188. STATIC_DCL boolean FDECL(cause_known, (int)); 189. STATIC_DCL char *FDECL(attrval, (int, int, char *)); 190. STATIC_DCL void FDECL(background_enlightenment, (int, int)); 191. STATIC_DCL void FDECL(basics_enlightenment, (int, int)); 192. STATIC_DCL void FDECL(characteristics_enlightenment, (int, int)); 193. STATIC_DCL void FDECL(one_characteristic, (int, int, int)); 194. STATIC_DCL void FDECL(status_enlightenment, (int, int)); 195. STATIC_DCL void FDECL(attributes_enlightenment, (int, int)); 196. 197. STATIC_DCL void FDECL(add_herecmd_menuitem, (winid, int NDECL((*)), 198. const char *)); 199. STATIC_DCL char FDECL(here_cmd_menu, (BOOLEAN_P)); 200. STATIC_DCL char FDECL(there_cmd_menu, (BOOLEAN_P, int, int)); 201. STATIC_DCL char *NDECL(parse); 202. STATIC_DCL void FDECL(show_direction_keys, (winid, CHAR_P, BOOLEAN_P)); 203. STATIC_DCL boolean FDECL(help_dir, (CHAR_P, int, const char *)); 204. 205. static const char *readchar_queue = ""; 206. static coord clicklook_cc; 207. /* for rejecting attempts to use wizard mode commands */ 208. static const char unavailcmd[] = "Unavailable command '%s'."; 209. /* for rejecting #if !SHELL, !SUSPEND */ 210. static const char cmdnotavail[] = "'%s' command not available."; 211. 212. STATIC_PTR int 213. doprev_message(VOID_ARGS) 214. { 215. return nh_doprev_message(); 216. } 217. 218. /* Count down by decrementing multi */ 219. STATIC_PTR int 220. timed_occupation(VOID_ARGS) 221. { 222. (*timed_occ_fn)(); 223. if (multi > 0) 224. multi--; 225. return multi > 0; 226. } 227. 228. /* If you have moved since initially setting some occupations, they 229. * now shouldn't be able to restart. 230. * 231. * The basic rule is that if you are carrying it, you can continue 232. * since it is with you. If you are acting on something at a distance, 233. * your orientation to it must have changed when you moved. 234. * 235. * The exception to this is taking off items, since they can be taken 236. * off in a number of ways in the intervening time, screwing up ordering. 237. * 238. * Currently: Take off all armor. 239. * Picking Locks / Forcing Chests. 240. * Setting traps. 241. */ 242. void 243. reset_occupations() 244. { 245. reset_remarm(); 246. reset_pick(); 247. reset_trapset(); 248. } 249. 250. /* If a time is given, use it to timeout this function, otherwise the 251. * function times out by its own means. 252. */ 253. void 254. set_occupation(fn, txt, xtime) 255. int NDECL((*fn)); 256. const char *txt; 257. int xtime; 258. { 259. if (xtime) { 260. occupation = timed_occupation; 261. timed_occ_fn = fn; 262. } else 263. occupation = fn; 264. occtxt = txt; 265. occtime = 0; 266. return; 267. } 268. 269. STATIC_DCL char NDECL(popch); 270. 271. /* Provide a means to redo the last command. The flag `in_doagain' is set 272. * to true while redoing the command. This flag is tested in commands that 273. * require additional input (like `throw' which requires a thing and a 274. * direction), and the input prompt is not shown. Also, while in_doagain is 275. * TRUE, no keystrokes can be saved into the saveq. 276. */ 277. #define BSIZE 20 278. static char pushq[BSIZE], saveq[BSIZE]; 279. static NEARDATA int phead, ptail, shead, stail; 280. 281. STATIC_OVL char 282. popch() 283. { 284. /* If occupied, return '\0', letting tgetch know a character should 285. * be read from the keyboard. If the character read is not the 286. * ABORT character (as checked in pcmain.c), that character will be 287. * pushed back on the pushq. 288. */ 289. if (occupation) 290. return '\0'; 291. if (in_doagain) 292. return (char) ((shead != stail) ? saveq[stail++] : '\0'); 293. else 294. return (char) ((phead != ptail) ? pushq[ptail++] : '\0'); 295. } 296. 297. char 298. pgetchar() /* courtesy of aeb@cwi.nl */ 299. { 300. register int ch; 301. 302. if (iflags.debug_fuzzer) 303. return randomkey(); 304. if (!(ch = popch())) 305. ch = nhgetch(); 306. return (char) ch; 307. } 308. 309. /* A ch == 0 resets the pushq */ 310. void 311. pushch(ch) 312. char ch; 313. { 314. if (!ch) 315. phead = ptail = 0; 316. if (phead < BSIZE) 317. pushq[phead++] = ch; 318. return; 319. } 320. 321. /* A ch == 0 resets the saveq. Only save keystrokes when not 322. * replaying a previous command. 323. */ 324. void 325. savech(ch) 326. char ch; 327. { 328. if (!in_doagain) { 329. if (!ch) 330. phead = ptail = shead = stail = 0; 331. else if (shead < BSIZE) 332. saveq[shead++] = ch; 333. } 334. return; 335. } 336. 337. /* here after # - now read a full-word command */ 338. STATIC_PTR int 339. doextcmd(VOID_ARGS) 340. { 341. int idx, retval; 342. int NDECL((*func)); 343. 344. /* keep repeating until we don't run help or quit */ 345. do { 346. idx = get_ext_cmd(); 347. if (idx < 0) 348. return 0; /* quit */ 349. 350. func = extcmdlist[idx].ef_funct; 351. if (!wizard && (extcmdlist[idx].flags & WIZMODECMD)) { 352. You("can't do that."); 353. return 0; 354. } 355. if (iflags.menu_requested && !accept_menu_prefix(func)) { 356. pline("'%s' prefix has no effect for the %s command.", 357. visctrl(Cmd.spkeys[NHKF_REQMENU]), 358. extcmdlist[idx].ef_txt); 359. iflags.menu_requested = FALSE; 360. } 361. retval = (*func)(); 362. } while (func == doextlist); 363. 364. return retval; 365. } 366. 367. /* here after #? - now list all full-word commands and provid 368. some navigation capability through the long list */ 369. int 370. doextlist(VOID_ARGS) 371. { 372. register const struct ext_func_tab *efp; 373. char buf[BUFSZ], searchbuf[BUFSZ], promptbuf[QBUFSZ]; 374. winid menuwin; 375. anything any; 376. menu_item *selected; 377. int n, pass; 378. int menumode = 0, menushown[2], onelist = 0; 379. boolean redisplay = TRUE, search = FALSE; 380. static const char *headings[] = { "Extended commands", 381. "Debugging Extended Commands" }; 382. 383. searchbuf[0] = '\0'; 384. menuwin = create_nhwindow(NHW_MENU); 385. 386. while (redisplay) { 387. redisplay = FALSE; 388. any = zeroany; 389. start_menu(menuwin); 390. add_menu(menuwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 391. "Extended Commands List", MENU_UNSELECTED); 392. add_menu(menuwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 393. "", MENU_UNSELECTED); 394. 395. Strcpy(buf, menumode ? "Show" : "Hide"); 396. Strcat(buf, " commands that don't autocomplete"); 397. if (!menumode) 398. Strcat(buf, " (those not marked with [A])"); 399. any.a_int = 1; 400. add_menu(menuwin, NO_GLYPH, &any, 'a', 0, ATR_NONE, buf, 401. MENU_UNSELECTED); 402. 403. if (!*searchbuf) { 404. any.a_int = 2; 405. /* was 's', but then using ':' handling within the interface 406. would only examine the two or three meta entries, not the 407. actual list of extended commands shown via separator lines; 408. having ':' as an explicit selector overrides the default 409. menu behavior for it; we retain 's' as a group accelerator */ 410. add_menu(menuwin, NO_GLYPH, &any, ':', 's', ATR_NONE, 411. "Search extended commands", MENU_UNSELECTED); 412. } else { 413. Strcpy(buf, "Show all, clear search"); 414. if (strlen(buf) + strlen(searchbuf) + strlen(" (\"\")") < QBUFSZ) 415. Sprintf(eos(buf), " (\"%s\")", searchbuf); 416. any.a_int = 3; 417. /* specifying ':' as a group accelerator here is mostly a 418. statement of intent (we'd like to accept it as a synonym but 419. also want to hide it from general menu use) because it won't 420. work for interfaces which support ':' to search; use as a 421. general menu command takes precedence over group accelerator */ 422. add_menu(menuwin, NO_GLYPH, &any, 's', ':', ATR_NONE, 423. buf, MENU_UNSELECTED); 424. } 425. if (wizard) { 426. any.a_int = 4; 427. add_menu(menuwin, NO_GLYPH, &any, 'z', 0, ATR_NONE, 428. onelist ? "Show debugging commands in separate section" 429. : "Show all alphabetically, including debugging commands", 430. MENU_UNSELECTED); 431. } 432. any = zeroany; 433. add_menu(menuwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 434. "", MENU_UNSELECTED); 435. menushown[0] = menushown[1] = 0; 436. n = 0; 437. for (pass = 0; pass <= 1; ++pass) { 438. /* skip second pass if not in wizard mode or wizard mode 439. commands are being integrated into a single list */ 440. if (pass == 1 && (onelist || !wizard)) 441. break; 442. for (efp = extcmdlist; efp->ef_txt; efp++) { 443. int wizc; 444. 445. if ((efp->flags & CMD_NOT_AVAILABLE) != 0) 446. continue; 447. /* if hiding non-autocomplete commands, skip such */ 448. if (menumode == 1 && (efp->flags & AUTOCOMPLETE) == 0) 449. continue; 450. /* if searching, skip this command if it doesn't match */ 451. if (*searchbuf 452. /* first try case-insensitive substring match */ 453. && !strstri(efp->ef_txt, searchbuf) 454. && !strstri(efp->ef_desc, searchbuf) 455. /* wildcard support; most interfaces use case-insensitve 456. pmatch rather than regexp for menu searching */ 457. && !pmatchi(searchbuf, efp->ef_txt) 458. && !pmatchi(searchbuf, efp->ef_desc)) 459. continue; 460. /* skip wizard mode commands if not in wizard mode; 461. when showing two sections, skip wizard mode commands 462. in pass==0 and skip other commands in pass==1 */ 463. wizc = (efp->flags & WIZMODECMD) != 0; 464. if (wizc && !wizard) 465. continue; 466. if (!onelist && pass != wizc) 467. continue; 468. 469. /* We're about to show an item, have we shown the menu yet? 470. Doing menu in inner loop like this on demand avoids a 471. heading with no subordinate entries on the search 472. results menu. */ 473. if (!menushown[pass]) { 474. Strcpy(buf, headings[pass]); 475. add_menu(menuwin, NO_GLYPH, &any, 0, 0, 476. iflags.menu_headings, buf, MENU_UNSELECTED); 477. menushown[pass] = 1; 478. } 479. Sprintf(buf, " %-14s %-3s %s", 480. efp->ef_txt, 481. (efp->flags & AUTOCOMPLETE) ? "[A]" : " ", 482. efp->ef_desc); 483. add_menu(menuwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 484. buf, MENU_UNSELECTED); 485. ++n; 486. } 487. if (n) 488. add_menu(menuwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 489. "", MENU_UNSELECTED); 490. } 491. if (*searchbuf && !n) 492. add_menu(menuwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 493. "no matches", MENU_UNSELECTED); 494. 495. end_menu(menuwin, (char *) 0); 496. n = select_menu(menuwin, PICK_ONE, &selected); 497. if (n > 0) { 498. switch (selected[0].item.a_int) { 499. case 1: /* 'a': toggle show/hide non-autocomplete */ 500. menumode = 1 - menumode; /* toggle 0 -> 1, 1 -> 0 */ 501. redisplay = TRUE; 502. break; 503. case 2: /* ':' when not searching yet: enable search */ 504. search = TRUE; 505. break; 506. case 3: /* 's' when already searching: disable search */ 507. search = FALSE; 508. searchbuf[0] = '\0'; 509. redisplay = TRUE; 510. break; 511. case 4: /* 'z': toggle showing wizard mode commands separately */ 512. search = FALSE; 513. searchbuf[0] = '\0'; 514. onelist = 1 - onelist; /* toggle 0 -> 1, 1 -> 0 */ 515. redisplay = TRUE; 516. break; 517. } 518. free((genericptr_t) selected); 519. } else { 520. search = FALSE; 521. searchbuf[0] = '\0'; 522. } 523. if (search) { 524. Strcpy(promptbuf, "Extended command list search phrase"); 525. Strcat(promptbuf, "?"); 526. getlin(promptbuf, searchbuf); 527. (void) mungspaces(searchbuf); 528. if (searchbuf[0] == '\033') 529. searchbuf[0] = '\0'; 530. if (*searchbuf) 531. redisplay = TRUE; 532. search = FALSE; 533. } 534. } 535. destroy_nhwindow(menuwin); 536. return 0; 537. } 538. 539. #if defined(TTY_GRAPHICS) || defined(CURSES_GRAPHICS) 540. #define MAX_EXT_CMD 200 /* Change if we ever have more ext cmds */ 541. 542. /* 543. * This is currently used only by the tty interface and is 544. * controlled via runtime option 'extmenu'. (Most other interfaces 545. * already use a menu all the time for extended commands.) 546. * 547. * ``# ? is counted towards the limit of the number of commands, 548. * so we actually support MAX_EXT_CMD-1 "real" extended commands. 549. * 550. * Here after # - now show pick-list of possible commands. 551. */ 552. int 553. extcmd_via_menu() 554. { 555. const struct ext_func_tab *efp; 556. menu_item *pick_list = (menu_item *) 0; 557. winid win; 558. anything any; 559. const struct ext_func_tab *choices[MAX_EXT_CMD + 1]; 560. char buf[BUFSZ]; 561. char cbuf[QBUFSZ], prompt[QBUFSZ], fmtstr[20]; 562. int i, n, nchoices, acount; 563. int ret, len, biggest; 564. int accelerator, prevaccelerator; 565. int matchlevel = 0; 566. boolean wastoolong, one_per_line; 567. 568. ret = 0; 569. cbuf[0] = '\0'; 570. biggest = 0; 571. while (!ret) { 572. i = n = 0; 573. any = zeroany; 574. /* populate choices */ 575. for (efp = extcmdlist; efp->ef_txt; efp++) { 576. if ((efp->flags & CMD_NOT_AVAILABLE) 577. || !(efp->flags & AUTOCOMPLETE) 578. || (!wizard && (efp->flags & WIZMODECMD))) 579. continue; 580. if (!matchlevel || !strncmp(efp->ef_txt, cbuf, matchlevel)) { 581. choices[i] = efp; 582. if ((len = (int) strlen(efp->ef_desc)) > biggest) 583. biggest = len; 584. if (++i > MAX_EXT_CMD) { 585. #if defined(BETA) 586. impossible( 587. "Exceeded %d extended commands in doextcmd() menu; 'extmenu' disabled.", 588. MAX_EXT_CMD); 589. #endif /* BETA */ 590. iflags.extmenu = 0; 591. return -1; 592. } 593. } 594. } 595. choices[i] = (struct ext_func_tab *) 0; 596. nchoices = i; 597. /* if we're down to one, we have our selection so get out of here */ 598. if (nchoices <= 1) { 599. ret = (nchoices == 1) ? (int) (choices[0] - extcmdlist) : -1; 600. break; 601. } 602. 603. /* otherwise... */ 604. win = create_nhwindow(NHW_MENU); 605. start_menu(win); 606. Sprintf(fmtstr, "%%-%ds", biggest + 15); 607. prompt[0] = '\0'; 608. wastoolong = FALSE; /* True => had to wrap due to line width 609. * ('w' in wizard mode) */ 610. /* -3: two line menu header, 1 line menu footer (for prompt) */ 611. one_per_line = (nchoices < ROWNO - 3); 612. accelerator = prevaccelerator = 0; 613. acount = 0; 614. for (i = 0; choices[i]; ++i) { 615. accelerator = choices[i]->ef_txt[matchlevel]; 616. if (accelerator != prevaccelerator || one_per_line) 617. wastoolong = FALSE; 618. if (accelerator != prevaccelerator || one_per_line 619. || (acount >= 2 620. /* +4: + sizeof " or " - sizeof "" */ 621. && (strlen(prompt) + 4 + strlen(choices[i]->ef_txt) 622. /* -6: enough room for 1 space left margin 623. * + "%c - " menu selector + 1 space right margin */ 624. >= min(sizeof prompt, COLNO - 6)))) { 625. if (acount) { 626. /* flush extended cmds for that letter already in buf */ 627. Sprintf(buf, fmtstr, prompt); 628. any.a_char = prevaccelerator; 629. add_menu(win, NO_GLYPH, &any, any.a_char, 0, ATR_NONE, 630. buf, FALSE); 631. acount = 0; 632. if (!(accelerator != prevaccelerator || one_per_line)) 633. wastoolong = TRUE; 634. } 635. } 636. prevaccelerator = accelerator; 637. if (!acount || one_per_line) { 638. Sprintf(prompt, "%s%s [%s]", wastoolong ? "or " : "", 639. choices[i]->ef_txt, choices[i]->ef_desc); 640. } else if (acount == 1) { 641. Sprintf(prompt, "%s%s or %s", wastoolong ? "or " : "", 642. choices[i - 1]->ef_txt, choices[i]->ef_txt); 643. } else { 644. Strcat(prompt, " or "); 645. Strcat(prompt, choices[i]->ef_txt); 646. } 647. ++acount; 648. } 649. if (acount) { 650. /* flush buf */ 651. Sprintf(buf, fmtstr, prompt); 652. any.a_char = prevaccelerator; 653. add_menu(win, NO_GLYPH, &any, any.a_char, 0, ATR_NONE, buf, 654. FALSE); 655. } 656. Sprintf(prompt, "Extended Command: %s", cbuf); 657. end_menu(win, prompt); 658. n = select_menu(win, PICK_ONE, &pick_list); 659. destroy_nhwindow(win); 660. if (n == 1) { 661. if (matchlevel > (QBUFSZ - 2)) { 662. free((genericptr_t) pick_list); 663. #if defined(BETA) 664. impossible("Too many chars (%d) entered in extcmd_via_menu()", 665. matchlevel); 666. #endif 667. ret = -1; 668. } else { 669. cbuf[matchlevel++] = pick_list[0].item.a_char; 670. cbuf[matchlevel] = '\0'; 671. free((genericptr_t) pick_list); 672. } 673. } else { 674. if (matchlevel) { 675. ret = 0; 676. matchlevel = 0; 677. } else 678. ret = -1; 679. } 680. } 681. return ret; 682. } 683. #endif /* TTY_GRAPHICS */ 684. 685. /* #monster command - use special monster ability while polymorphed */ 686. int 687. domonability(VOID_ARGS) 688. { 689. if (can_breathe(youmonst.data)) 690. return dobreathe(); 691. else if (attacktype(youmonst.data, AT_SPIT)) 692. return dospit(); 693. else if (youmonst.data->mlet == S_NYMPH) 694. return doremove(); 695. else if (attacktype(youmonst.data, AT_GAZE)) 696. return dogaze(); 697. else if (is_were(youmonst.data)) 698. return dosummon(); 699. else if (webmaker(youmonst.data)) 700. return dospinweb(); 701. else if (is_hider(youmonst.data)) 702. return dohide(); 703. else if (is_mind_flayer(youmonst.data)) 704. return domindblast(); 705. else if (u.umonnum == PM_GREMLIN) { 706. if (IS_FOUNTAIN(levl[u.ux][u.uy].typ)) { 707. if (split_mon(&youmonst, (struct monst *) 0)) 708. dryup(u.ux, u.uy, TRUE); 709. } else 710. There("is no fountain here."); 711. } else if (is_unicorn(youmonst.data)) { 712. use_unicorn_horn((struct obj *) 0); 713. return 1; 714. } else if (youmonst.data->msound == MS_SHRIEK) { 715. You("shriek."); 716. if (u.uburied) 717. pline("Unfortunately sound does not carry well through rock."); 718. else 719. aggravate(); 720. } else if (youmonst.data->mlet == S_VAMPIRE) 721. return dopoly(); 722. else if (Upolyd) 723. pline("Any special ability you may have is purely reflexive."); 724. else 725. You("don't have a special ability in your normal form!"); 726. return 0; 727. } 728. 729. int 730. enter_explore_mode(VOID_ARGS) 731. { 732. if (wizard) { 733. You("are in debug mode."); 734. } else if (discover) { 735. You("are already in explore mode."); 736. } else { 737. #ifdef SYSCF 738. #if defined(UNIX) 739. if (!sysopt.explorers || !sysopt.explorers[0] 740. || !check_user_string(sysopt.explorers)) { 741. You("cannot access explore mode."); 742. return 0; 743. } 744. #endif 745. #endif 746. pline( 747. "Beware! From explore mode there will be no return to normal game."); 748. if (paranoid_query(ParanoidQuit, 749. "Do you want to enter explore mode?")) { 750. clear_nhwindow(WIN_MESSAGE); 751. You("are now in non-scoring explore mode."); 752. discover = TRUE; 753. } else { 754. clear_nhwindow(WIN_MESSAGE); 755. pline("Resuming normal game."); 756. } 757. } 758. return 0; 759. } 760. 761. /* ^W command - wish for something */ 762. STATIC_PTR int 763. wiz_wish(VOID_ARGS) /* Unlimited wishes for debug mode by Paul Polderman */ 764. { 765. if (wizard) { 766. boolean save_verbose = flags.verbose; 767. 768. flags.verbose = FALSE; 769. makewish(); 770. flags.verbose = save_verbose; 771. (void) encumber_msg(); 772. } else 773. pline(unavailcmd, visctrl((int) cmd_from_func(wiz_wish))); 774. return 0; 775. } 776. 777. /* ^I command - reveal and optionally identify hero's inventory */ 778. STATIC_PTR int 779. wiz_identify(VOID_ARGS) 780. { 781. if (wizard) { 782. iflags.override_ID = (int) cmd_from_func(wiz_identify); 783. /* command remapping might leave #wizidentify as the only way 784. to invoke us, in which case cmd_from_func() will yield NUL; 785. it won't matter to display_inventory()/display_pickinv() 786. if ^I invokes some other command--what matters is that 787. display_pickinv() and xname() see override_ID as nonzero */ 788. if (!iflags.override_ID) 789. iflags.override_ID = C('I'); 790. (void) display_inventory((char *) 0, FALSE); 791. iflags.override_ID = 0; 792. } else 793. pline(unavailcmd, visctrl((int) cmd_from_func(wiz_identify))); 794. return 0; 795. } 796. 797. /* #wizmakemap - discard current dungeon level and replace with a new one */ 798. STATIC_PTR int 799. wiz_makemap(VOID_ARGS) 800. { 801. if (wizard) { 802. struct monst *mtmp; 803. boolean was_in_W_tower = In_W_tower(u.ux, u.uy, &u.uz); 804. 805. rm_mapseen(ledger_no(&u.uz)); 806. for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 807. if (mtmp->isgd) { /* vault is going away; get rid of guard */ 808. mtmp->isgd = 0; 809. mongone(mtmp); 810. } 811. if (DEADMONSTER(mtmp)) 812. continue; 813. if (mtmp->isshk) 814. setpaid(mtmp); 815. /* TODO? 816. * Reduce 'born' tally for each monster about to be discarded 817. * by savelev(), otherwise replacing heavily populated levels 818. * tends to make their inhabitants become extinct. 819. */ 820. } 821. if (Punished) { 822. ballrelease(FALSE); 823. unplacebc(); 824. } 825. /* reset lock picking unless it's for a carried container */ 826. maybe_reset_pick((struct obj *) 0); 827. /* reset interrupted digging if it was taking place on this level */ 828. if (on_level(&context.digging.level, &u.uz)) 829. (void) memset((genericptr_t) &context.digging, 0, 830. sizeof (struct dig_info)); 831. /* reset cached targets */ 832. iflags.travelcc.x = iflags.travelcc.y = 0; /* travel destination */ 833. context.polearm.hitmon = (struct monst *) 0; /* polearm target */ 834. /* escape from trap */ 835. reset_utrap(FALSE); 836. check_special_room(TRUE); /* room exit */ 837. u.ustuck = (struct monst *) 0; 838. u.uswallow = 0; 839. u.uinwater = 0; 840. u.uundetected = 0; /* not hidden, even if means are available */ 841. dmonsfree(); /* purge dead monsters from 'fmon' */ 842. /* keep steed and other adjacent pets after releasing them 843. from traps, stopping eating, &c as if hero were ascending */ 844. keepdogs(TRUE); /* (pets-only; normally we'd be using 'FALSE' here) */ 845. 846. /* discard current level; "saving" is used to release dynamic data */ 847. savelev(-1, ledger_no(&u.uz), FREE_SAVE); 848. /* create a new level; various things like bestowing a guardian 849. angel on Astral or setting off alarm on Ft.Ludios are handled 850. by goto_level(do.c) so won't occur for replacement levels */ 851. mklev(); 852. 853. vision_reset(); 854. vision_full_recalc = 1; 855. cls(); 856. /* was using safe_teleds() but that doesn't honor arrival region 857. on levels which have such; we don't force stairs, just area */ 858. u_on_rndspot((u.uhave.amulet ? 1 : 0) /* 'going up' flag */ 859. | (was_in_W_tower ? 2 : 0)); 860. losedogs(); 861. /* u_on_rndspot() might pick a spot that has a monster, or losedogs() 862. might pick the hero's spot (only if there isn't already a monster 863. there), so we might have to move hero or the co-located monster */ 864. if ((mtmp = m_at(u.ux, u.uy)) != 0) 865. u_collide_m(mtmp); 866. initrack(); 867. if (Punished) { 868. unplacebc(); 869. placebc(); 870. } 871. docrt(); 872. flush_screen(1); 873. deliver_splev_message(); /* level entry */ 874. check_special_room(FALSE); /* room entry */ 875. #ifdef INSURANCE 876. save_currentstate(); 877. #endif 878. } else { 879. pline(unavailcmd, "#wizmakemap"); 880. } 881. return 0; 882. } 883. 884. /* ^F command - reveal the level map and any traps on it */ 885. STATIC_PTR int 886. wiz_map(VOID_ARGS) 887. { 888. if (wizard) { 889. struct trap *t; 890. long save_Hconf = HConfusion, save_Hhallu = HHallucination; 891. 892. HConfusion = HHallucination = 0L; 893. for (t = ftrap; t != 0; t = t->ntrap) { 894. t->tseen = 1; 895. map_trap(t, TRUE); 896. } 897. do_mapping(); 898. HConfusion = save_Hconf; 899. HHallucination = save_Hhallu; 900. } else 901. pline(unavailcmd, visctrl((int) cmd_from_func(wiz_map))); 902. return 0; 903. } 904. 905. /* ^G command - generate monster(s); a count prefix will be honored */ 906. STATIC_PTR int 907. wiz_genesis(VOID_ARGS) 908. { 909. if (wizard) 910. (void) create_particular(); 911. else 912. pline(unavailcmd, visctrl((int) cmd_from_func(wiz_genesis))); 913. return 0; 914. } 915. 916. /* ^O command - display dungeon layout */ 917. STATIC_PTR int 918. wiz_where(VOID_ARGS) 919. { 920. if (wizard) 921. (void) print_dungeon(FALSE, (schar *) 0, (xchar *) 0); 922. else 923. pline(unavailcmd, visctrl((int) cmd_from_func(wiz_where))); 924. return 0; 925. } 926. 927. /* ^E command - detect unseen (secret doors, traps, hidden monsters) */ 928. STATIC_PTR int 929. wiz_detect(VOID_ARGS) 930. { 931. if (wizard) 932. (void) findit(); 933. else 934. pline(unavailcmd, visctrl((int) cmd_from_func(wiz_detect))); 935. return 0; 936. } 937. 938. /* ^V command - level teleport */ 939. STATIC_PTR int 940. wiz_level_tele(VOID_ARGS) 941. { 942. if (wizard) 943. level_tele(); 944. else 945. pline(unavailcmd, visctrl((int) cmd_from_func(wiz_level_tele))); 946. return 0; 947. } 948. 949. /* #levelchange command - adjust hero's experience level */ 950. STATIC_PTR int 951. wiz_level_change(VOID_ARGS) 952. { 953. char buf[BUFSZ] = DUMMY; 954. int newlevel = 0; 955. int ret; 956. 957. getlin("To what experience level do you want to be set?", buf); 958. (void) mungspaces(buf); 959. if (buf[0] == '\033' || buf[0] == '\0') 960. ret = 0; 961. else 962. ret = sscanf(buf, "%d", &newlevel); 963. 964. if (ret != 1) { 965. pline1(Never_mind); 966. return 0; 967. } 968. if (newlevel == u.ulevel) { 969. You("are already that experienced."); 970. } else if (newlevel < u.ulevel) { 971. if (u.ulevel == 1) { 972. You("are already as inexperienced as you can get."); 973. return 0; 974. } 975. if (newlevel < 1) 976. newlevel = 1; 977. while (u.ulevel > newlevel) 978. losexp("#levelchange"); 979. } else { 980. if (u.ulevel >= MAXULEV) { 981. You("are already as experienced as you can get."); 982. return 0; 983. } 984. if (newlevel > MAXULEV) 985. newlevel = MAXULEV; 986. while (u.ulevel < newlevel) 987. pluslvl(FALSE); 988. } 989. u.ulevelmax = u.ulevel; 990. return 0; 991. } 992. 993. /* #panic command - test program's panic handling */ 994. STATIC_PTR int 995. wiz_panic(VOID_ARGS) 996. { 997. if (iflags.debug_fuzzer) { 998. u.uhp = u.uhpmax = 1000; 999. u.uen = u.uenmax = 1000; 1000. return 0; 1001. } 1002. if (yn("Do you want to call panic() and end your game?") == 'y') 1003. panic("Crash test."); 1004. return 0; 1005. } 1006. 1007. /* #polyself command - change hero's form */ 1008. STATIC_PTR int 1009. wiz_polyself(VOID_ARGS) 1010. { 1011. polyself(1); 1012. return 0; 1013. } 1014. 1015. /* #seenv command */ 1016. STATIC_PTR int 1017. wiz_show_seenv(VOID_ARGS) 1018. { 1019. winid win; 1020. int x, y, v, startx, stopx, curx; 1021. char row[COLNO + 1]; 1022. 1023. win = create_nhwindow(NHW_TEXT); 1024. /* 1025. * Each seenv description takes up 2 characters, so center 1026. * the seenv display around the hero. 1027. */ 1028. startx = max(1, u.ux - (COLNO / 4)); 1029. stopx = min(startx + (COLNO / 2), COLNO); 1030. /* can't have a line exactly 80 chars long */ 1031. if (stopx - startx == COLNO / 2) 1032. startx++; 1033. 1034. for (y = 0; y < ROWNO; y++) { 1035. for (x = startx, curx = 0; x < stopx; x++, curx += 2) { 1036. if (x == u.ux && y == u.uy) { 1037. row[curx] = row[curx + 1] = '@'; 1038. } else { 1039. v = levl[x][y].seenv & 0xff; 1040. if (v == 0) 1041. row[curx] = row[curx + 1] = ' '; 1042. else 1043. Sprintf(&row[curx], "%02x", v); 1044. } 1045. } 1046. /* remove trailing spaces */ 1047. for (x = curx - 1; x >= 0; x--) 1048. if (row[x] != ' ') 1049. break; 1050. row[x + 1] = '\0'; 1051. 1052. putstr(win, 0, row); 1053. } 1054. display_nhwindow(win, TRUE); 1055. destroy_nhwindow(win); 1056. return 0; 1057. } 1058. 1059. /* #vision command */ 1060. STATIC_PTR int 1061. wiz_show_vision(VOID_ARGS) 1062. { 1063. winid win; 1064. int x, y, v; 1065. char row[COLNO + 1]; 1066. 1067. win = create_nhwindow(NHW_TEXT); 1068. Sprintf(row, "Flags: 0x%x could see, 0x%x in sight, 0x%x temp lit", 1069. COULD_SEE, IN_SIGHT, TEMP_LIT); 1070. putstr(win, 0, row); 1071. putstr(win, 0, ""); 1072. for (y = 0; y < ROWNO; y++) { 1073. for (x = 1; x < COLNO; x++) { 1074. if (x == u.ux && y == u.uy) 1075. row[x] = '@'; 1076. else { 1077. v = viz_array[y][x]; /* data access should be hidden */ 1078. if (v == 0) 1079. row[x] = ' '; 1080. else 1081. row[x] = '0' + viz_array[y][x]; 1082. } 1083. } 1084. /* remove trailing spaces */ 1085. for (x = COLNO - 1; x >= 1; x--) 1086. if (row[x] != ' ') 1087. break; 1088. row[x + 1] = '\0'; 1089. 1090. putstr(win, 0, &row[1]); 1091. } 1092. display_nhwindow(win, TRUE); 1093. destroy_nhwindow(win); 1094. return 0; 1095. } 1096. 1097. /* #wmode command */ 1098. STATIC_PTR int 1099. wiz_show_wmodes(VOID_ARGS) 1100. { 1101. winid win; 1102. int x, y; 1103. char row[COLNO + 1]; 1104. struct rm *lev; 1105. boolean istty = WINDOWPORT("tty"); 1106. 1107. win = create_nhwindow(NHW_TEXT); 1108. if (istty) 1109. putstr(win, 0, ""); /* tty only: blank top line */ 1110. for (y = 0; y < ROWNO; y++) { 1111. for (x = 0; x < COLNO; x++) { 1112. lev = &levl[x][y]; 1113. if (x == u.ux && y == u.uy) 1114. row[x] = '@'; 1115. else if (IS_WALL(lev->typ) || lev->typ == SDOOR) 1116. row[x] = '0' + (lev->wall_info & WM_MASK); 1117. else if (lev->typ == CORR) 1118. row[x] = '#'; 1119. else if (IS_ROOM(lev->typ) || IS_DOOR(lev->typ)) 1120. row[x] = '.'; 1121. else 1122. row[x] = 'x'; 1123. } 1124. row[COLNO] = '\0'; 1125. /* map column 0, levl[0][], is off the left edge of the screen */ 1126. putstr(win, 0, &row[1]); 1127. } 1128. display_nhwindow(win, TRUE); 1129. destroy_nhwindow(win); 1130. return 0; 1131. } 1132. 1133. /* wizard mode variant of #terrain; internal levl[][].typ values in base-36 */ 1134. STATIC_OVL void 1135. wiz_map_levltyp(VOID_ARGS) 1136. { 1137. winid win; 1138. int x, y, terrain; 1139. char row[COLNO + 1]; 1140. boolean istty = !strcmp(windowprocs.name, "tty"); 1141. 1142. win = create_nhwindow(NHW_TEXT); 1143. /* map row 0, levl[][0], is drawn on the second line of tty screen */ 1144. if (istty) 1145. putstr(win, 0, ""); /* tty only: blank top line */ 1146. for (y = 0; y < ROWNO; y++) { 1147. /* map column 0, levl[0][], is off the left edge of the screen; 1148. it should always have terrain type "undiggable stone" */ 1149. for (x = 1; x < COLNO; x++) { 1150. terrain = levl[x][y].typ; 1151. /* assumes there aren't more than 10+26+26 terrain types */ 1152. row[x - 1] = (char) ((terrain == STONE && !may_dig(x, y)) 1153. ? '*' 1154. : (terrain < 10) 1155. ? '0' + terrain 1156. : (terrain < 36) 1157. ? 'a' + terrain - 10 1158. : 'A' + terrain - 36); 1159. } 1160. x--; 1161. if (levl[0][y].typ != STONE || may_dig(0, y)) 1162. row[x++] = '!'; 1163. row[x] = '\0'; 1164. putstr(win, 0, row); 1165. } 1166. 1167. { 1168. char dsc[BUFSZ]; 1169. s_level *slev = Is_special(&u.uz); 1170. 1171. Sprintf(dsc, "D:%d,L:%d", u.uz.dnum, u.uz.dlevel); 1172. /* [dungeon branch features currently omitted] */ 1173. /* special level features */ 1174. if (slev) { 1175. Sprintf(eos(dsc), " \"%s\"", slev->proto); 1176. /* special level flags (note: dungeon.def doesn't set `maze' 1177. or `hell' for any specific levels so those never show up) */ 1178. if (slev->flags.maze_like) 1179. Strcat(dsc, " mazelike"); 1180. if (slev->flags.hellish) 1181. Strcat(dsc, " hellish"); 1182. if (slev->flags.town) 1183. Strcat(dsc, " town"); 1184. if (slev->flags.rogue_like) 1185. Strcat(dsc, " roguelike"); 1186. /* alignment currently omitted to save space */ 1187. } 1188. /* level features */ 1189. if (level.flags.nfountains) 1190. Sprintf(eos(dsc), " %c:%d", defsyms[S_fountain].sym, 1191. (int) level.flags.nfountains); 1192. if (level.flags.nsinks) 1193. Sprintf(eos(dsc), " %c:%d", defsyms[S_sink].sym, 1194. (int) level.flags.nsinks); 1195. if (level.flags.has_vault) 1196. Strcat(dsc, " vault"); 1197. if (level.flags.has_shop) 1198. Strcat(dsc, " shop"); 1199. if (level.flags.has_temple) 1200. Strcat(dsc, " temple"); 1201. if (level.flags.has_court) 1202. Strcat(dsc, " throne"); 1203. if (level.flags.has_zoo) 1204. Strcat(dsc, " zoo"); 1205. if (level.flags.has_morgue) 1206. Strcat(dsc, " morgue"); 1207. if (level.flags.has_barracks) 1208. Strcat(dsc, " barracks"); 1209. if (level.flags.has_beehive) 1210. Strcat(dsc, " hive"); 1211. if (level.flags.has_swamp) 1212. Strcat(dsc, " swamp"); 1213. /* level flags */ 1214. if (level.flags.noteleport) 1215. Strcat(dsc, " noTport"); 1216. if (level.flags.hardfloor) 1217. Strcat(dsc, " noDig"); 1218. if (level.flags.nommap) 1219. Strcat(dsc, " noMMap"); 1220. if (!level.flags.hero_memory) 1221. Strcat(dsc, " noMem"); 1222. if (level.flags.shortsighted) 1223. Strcat(dsc, " shortsight"); 1224. if (level.flags.graveyard) 1225. Strcat(dsc, " graveyard"); 1226. if (level.flags.is_maze_lev) 1227. Strcat(dsc, " maze"); 1228. if (level.flags.is_cavernous_lev) 1229. Strcat(dsc, " cave"); 1230. if (level.flags.arboreal) 1231. Strcat(dsc, " tree"); 1232. if (Sokoban) 1233. Strcat(dsc, " sokoban-rules"); 1234. /* non-flag info; probably should include dungeon branching 1235. checks (extra stairs and magic portals) here */ 1236. if (Invocation_lev(&u.uz)) 1237. Strcat(dsc, " invoke"); 1238. if (On_W_tower_level(&u.uz)) 1239. Strcat(dsc, " tower"); 1240. /* append a branch identifier for completeness' sake */ 1241. if (u.uz.dnum == 0) 1242. Strcat(dsc, " dungeon"); 1243. else if (u.uz.dnum == mines_dnum) 1244. Strcat(dsc, " mines"); 1245. else if (In_sokoban(&u.uz)) 1246. Strcat(dsc, " sokoban"); 1247. else if (u.uz.dnum == quest_dnum) 1248. Strcat(dsc, " quest"); 1249. else if (Is_knox(&u.uz)) 1250. Strcat(dsc, " ludios"); 1251. else if (u.uz.dnum == 1) 1252. Strcat(dsc, " gehennom"); 1253. else if (u.uz.dnum == tower_dnum) 1254. Strcat(dsc, " vlad"); 1255. else if (In_endgame(&u.uz)) 1256. Strcat(dsc, " endgame"); 1257. else { 1258. /* somebody's added a dungeon branch we're not expecting */ 1259. const char *brname = dungeons[u.uz.dnum].dname; 1260. 1261. if (!brname || !*brname) 1262. brname = "unknown"; 1263. if (!strncmpi(brname, "the ", 4)) 1264. brname += 4; 1265. Sprintf(eos(dsc), " %s", brname); 1266. } 1267. /* limit the line length to map width */ 1268. if (strlen(dsc) >= COLNO) 1269. dsc[COLNO - 1] = '\0'; /* truncate */ 1270. putstr(win, 0, dsc); 1271. } 1272. 1273. display_nhwindow(win, TRUE); 1274. destroy_nhwindow(win); 1275. return; 1276. } 1277. 1278. /* temporary? hack, since level type codes aren't the same as screen 1279. symbols and only the latter have easily accessible descriptions */ 1280. static const char *levltyp[] = { 1281. "stone", "vertical wall", "horizontal wall", "top-left corner wall", 1282. "top-right corner wall", "bottom-left corner wall", 1283. "bottom-right corner wall", "cross wall", "tee-up wall", "tee-down wall", 1284. "tee-left wall", "tee-right wall", "drawbridge wall", "tree", 1285. "secret door", "secret corridor", "pool", "moat", "water", 1286. "drawbridge up", "lava pool", "iron bars", "door", "corridor", "room", 1287. "stairs", "ladder", "fountain", "throne", "sink", "grave", "altar", "ice", 1288. "drawbridge down", "air", "cloud", 1289. /* not a real terrain type, but used for undiggable stone 1290. by wiz_map_levltyp() */ 1291. "unreachable/undiggable", 1292. /* padding in case the number of entries above is odd */ 1293. "" 1294. }; 1295. 1296. /* explanation of base-36 output from wiz_map_levltyp() */ 1297. STATIC_OVL void 1298. wiz_levltyp_legend(VOID_ARGS) 1299. { 1300. winid win; 1301. int i, j, last, c; 1302. const char *dsc, *fmt; 1303. char buf[BUFSZ]; 1304. 1305. win = create_nhwindow(NHW_TEXT); 1306. putstr(win, 0, "#terrain encodings:"); 1307. putstr(win, 0, ""); 1308. fmt = " %c - %-28s"; /* TODO: include tab-separated variant for win32 */ 1309. *buf = '\0'; 1310. /* output in pairs, left hand column holds [0],[1],...,[N/2-1] 1311. and right hand column holds [N/2],[N/2+1],...,[N-1]; 1312. N ('last') will always be even, and may or may not include 1313. the empty string entry to pad out the final pair, depending 1314. upon how many other entries are present in levltyp[] */ 1315. last = SIZE(levltyp) & ~1; 1316. for (i = 0; i < last / 2; ++i) 1317. for (j = i; j < last; j += last / 2) { 1318. dsc = levltyp[j]; 1319. c = !*dsc ? ' ' 1320. : !strncmp(dsc, "unreachable", 11) ? '*' 1321. /* same int-to-char conversion as wiz_map_levltyp() */ 1322. : (j < 10) ? '0' + j 1323. : (j < 36) ? 'a' + j - 10 1324. : 'A' + j - 36; 1325. Sprintf(eos(buf), fmt, c, dsc); 1326. if (j > i) { 1327. putstr(win, 0, buf); 1328. *buf = '\0'; 1329. } 1330. } 1331. display_nhwindow(win, TRUE); 1332. destroy_nhwindow(win); 1333. return; 1334. } 1335. 1336. /* #wizsmell command - test usmellmon(). */ 1337. STATIC_PTR int 1338. wiz_smell(VOID_ARGS) 1339. { 1340. int ans = 0; 1341. int mndx; /* monster index */ 1342. coord cc; /* screen pos of unknown glyph */ 1343. int glyph; /* glyph at selected position */ 1344. 1345. cc.x = u.ux; 1346. cc.y = u.uy; 1347. mndx = 0; /* gcc -Wall lint */ 1348. if (!olfaction(youmonst.data)) { 1349. You("are incapable of detecting odors in your present form."); 1350. return 0; 1351. } 1352. 1353. pline("You can move the cursor to a monster that you want to smell."); 1354. do { 1355. pline("Pick a monster to smell."); 1356. ans = getpos(&cc, TRUE, "a monster"); 1357. if (ans < 0 || cc.x < 0) { 1358. return 0; /* done */ 1359. } 1360. /* Convert the glyph at the selected position to a mndxbol. */ 1361. glyph = glyph_at(cc.x, cc.y); 1362. if (glyph_is_monster(glyph)) 1363. mndx = glyph_to_mon(glyph); 1364. else 1365. mndx = 0; 1366. /* Is it a monster? */ 1367. if (mndx) { 1368. if (!usmellmon(&mons[mndx])) 1369. pline("That monster seems to give off no smell."); 1370. } else 1371. pline("That is not a monster."); 1372. } while (TRUE); 1373. return 0; 1374. } 1375. 1376. /* #wizinstrinsic command to set some intrinsics for testing */ 1377. STATIC_PTR int 1378. wiz_intrinsic(VOID_ARGS) 1379. { 1380. if (wizard) { 1381. extern const struct propname { 1382. int prop_num; 1383. const char *prop_name; 1384. } propertynames[]; /* timeout.c */ 1385. static const char wizintrinsic[] = "#wizintrinsic"; 1386. static const char fmt[] = "You are%s %s."; 1387. winid win; 1388. anything any; 1389. char buf[BUFSZ]; 1390. int i, j, n, p, amt, typ; 1391. long oldtimeout, newtimeout; 1392. const char *propname; 1393. menu_item *pick_list = (menu_item *) 0; 1394. 1395. any = zeroany; 1396. win = create_nhwindow(NHW_MENU); 1397. start_menu(win); 1398. for (i = 0; (propname = propertynames[i].prop_name) != 0; ++i) { 1399. p = propertynames[i].prop_num; 1400. if (p == HALLUC_RES) { 1401. /* Grayswandir vs hallucination; ought to be redone to 1402. use u.uprops[HALLUC].blocked instead of being treated 1403. as a separate property; letting in be manually toggled 1404. even only in wizard mode would be asking for trouble... */ 1405. continue; 1406. } 1407. if (p == FIRE_RES) { 1408. any.a_int = 0; 1409. add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, "--", FALSE); 1410. } 1411. any.a_int = i + 1; /* +1: avoid 0 */ 1412. oldtimeout = u.uprops[p].intrinsic & TIMEOUT; 1413. if (oldtimeout) 1414. Sprintf(buf, "%-27s [%li]", propname, oldtimeout); 1415. else 1416. Sprintf(buf, "%s", propname); 1417. add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 1418. } 1419. end_menu(win, "Which intrinsics?"); 1420. n = select_menu(win, PICK_ANY, &pick_list); 1421. destroy_nhwindow(win); 1422. 1423. amt = 30; /* TODO: prompt for duration */ 1424. for (j = 0; j < n; ++j) { 1425. i = pick_list[j].item.a_int - 1; /* -1: reverse +1 above */ 1426. p = propertynames[i].prop_num; 1427. oldtimeout = u.uprops[p].intrinsic & TIMEOUT; 1428. newtimeout = oldtimeout + (long) amt; 1429. switch (p) { 1430. case SICK: 1431. case SLIMED: 1432. case STONED: 1433. if (oldtimeout > 0L && newtimeout > oldtimeout) 1434. newtimeout = oldtimeout; 1435. break; 1436. } 1437. 1438. switch (p) { 1439. case BLINDED: 1440. make_blinded(newtimeout, TRUE); 1441. break; 1442. #if 0 /* make_confused() only gives feedback when confusion is 1443. * ending so use the 'default' case for it instead */ 1444. case CONFUSION: 1445. make_confused(newtimeout, TRUE); 1446. break; 1447. #endif /*0*/ 1448. case DEAF: 1449. make_deaf(newtimeout, TRUE); 1450. break; 1451. case HALLUC: 1452. make_hallucinated(newtimeout, TRUE, 0L); 1453. break; 1454. case SICK: 1455. typ = !rn2(2) ? SICK_VOMITABLE : SICK_NONVOMITABLE; 1456. make_sick(newtimeout, wizintrinsic, TRUE, typ); 1457. break; 1458. case SLIMED: 1459. Sprintf(buf, fmt, 1460. !Slimed ? "" : " still", "turning into slime"); 1461. make_slimed(newtimeout, buf); 1462. break; 1463. case STONED: 1464. Sprintf(buf, fmt, 1465. !Stoned ? "" : " still", "turning into stone"); 1466. make_stoned(newtimeout, buf, KILLED_BY, wizintrinsic); 1467. break; 1468. case STUNNED: 1469. make_stunned(newtimeout, TRUE); 1470. break; 1471. case VOMITING: 1472. Sprintf(buf, fmt, !Vomiting ? "" : " still", "vomiting"); 1473. make_vomiting(newtimeout, FALSE); 1474. pline1(buf); 1475. break; 1476. case WARN_OF_MON: 1477. if (!Warn_of_mon) { 1478. context.warntype.speciesidx = PM_GRID_BUG; 1479. context.warntype.species 1480. = &mons[context.warntype.speciesidx]; 1481. } 1482. goto def_feedback; 1483. case LEVITATION: 1484. case FLYING: 1485. float_vs_flight(); 1486. /*FALLTHRU*/ 1487. default: 1488. def_feedback: 1489. pline("Timeout for %s %s %d.", propertynames[i].prop_name, 1490. oldtimeout ? "increased by" : "set to", amt); 1491. incr_itimeout(&u.uprops[p].intrinsic, amt); 1492. break; 1493. } 1494. context.botl = 1; /* probably not necessary... */ 1495. } 1496. if (n >= 1) 1497. free((genericptr_t) pick_list); 1498. doredraw(); 1499. } else 1500. pline(unavailcmd, visctrl((int) cmd_from_func(wiz_intrinsic))); 1501. return 0; 1502. } 1503. 1504. /* #wizrumorcheck command - verify each rumor access */ 1505. STATIC_PTR int 1506. wiz_rumor_check(VOID_ARGS) 1507. { 1508. rumor_check(); 1509. return 0; 1510. } 1511. 1512. /* #terrain command -- show known map, inspired by crawl's '|' command */ 1513. STATIC_PTR int 1514. doterrain(VOID_ARGS) 1515. { 1516. winid men; 1517. menu_item *sel; 1518. anything any; 1519. int n; 1520. int which; 1521. 1522. /* 1523. * normal play: choose between known map without mons, obj, and traps 1524. * (to see underlying terrain only), or 1525. * known map without mons and objs (to see traps under mons and objs), or 1526. * known map without mons (to see objects under monsters); 1527. * explore mode: normal choices plus full map (w/o mons, objs, traps); 1528. * wizard mode: normal and explore choices plus 1529. * a dump of the internal levl[][].typ codes w/ level flags, or 1530. * a legend for the levl[][].typ codes dump 1531. */ 1532. men = create_nhwindow(NHW_MENU); 1533. start_menu(men); 1534. any = zeroany; 1535. any.a_int = 1; 1536. add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, 1537. "known map without monsters, objects, and traps", 1538. MENU_SELECTED); 1539. any.a_int = 2; 1540. add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, 1541. "known map without monsters and objects", 1542. MENU_UNSELECTED); 1543. any.a_int = 3; 1544. add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, 1545. "known map without monsters", 1546. MENU_UNSELECTED); 1547. if (discover || wizard) { 1548. any.a_int = 4; 1549. add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, 1550. "full map without monsters, objects, and traps", 1551. MENU_UNSELECTED); 1552. if (wizard) { 1553. any.a_int = 5; 1554. add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, 1555. "internal levl[][].typ codes in base-36", 1556. MENU_UNSELECTED); 1557. any.a_int = 6; 1558. add_menu(men, NO_GLYPH, &any, 0, 0, ATR_NONE, 1559. "legend of base-36 levl[][].typ codes", 1560. MENU_UNSELECTED); 1561. } 1562. } 1563. end_menu(men, "View which?"); 1564. 1565. n = select_menu(men, PICK_ONE, &sel); 1566. destroy_nhwindow(men); 1567. /* 1568. * n < 0: player used ESC to cancel; 1569. * n == 0: preselected entry was explicitly chosen and got toggled off; 1570. * n == 1: preselected entry was implicitly chosen via <space>|<enter>; 1571. * n == 2: another entry was explicitly chosen, so skip preselected one. 1572. */ 1573. which = (n < 0) ? -1 : (n == 0) ? 1 : sel[0].item.a_int; 1574. if (n > 1 && which == 1) 1575. which = sel[1].item.a_int; 1576. if (n > 0) 1577. free((genericptr_t) sel); 1578. 1579. switch (which) { 1580. case 1: /* known map */ 1581. reveal_terrain(0, TER_MAP); 1582. break; 1583. case 2: /* known map with known traps */ 1584. reveal_terrain(0, TER_MAP | TER_TRP); 1585. break; 1586. case 3: /* known map with known traps and objects */ 1587. reveal_terrain(0, TER_MAP | TER_TRP | TER_OBJ); 1588. break; 1589. case 4: /* full map */ 1590. reveal_terrain(1, TER_MAP); 1591. break; 1592. case 5: /* map internals */ 1593. wiz_map_levltyp(); 1594. break; 1595. case 6: /* internal details */ 1596. wiz_levltyp_legend(); 1597. break; 1598. default: 1599. break; 1600. } 1601. return 0; /* no time elapses */ 1602. } 1603. 1604. /* -enlightenment and conduct- */ 1605. static winid en_win = WIN_ERR; 1606. static boolean en_via_menu = FALSE; 1607. static const char You_[] = "You ", are[] = "are ", were[] = "were ", 1608. have[] = "have ", had[] = "had ", can[] = "can ", 1609. could[] = "could "; 1610. static const char have_been[] = "have been ", have_never[] = "have never ", 1611. never[] = "never "; 1612. 1613. #define enl_msg(prefix, present, past, suffix, ps) \ 1614. enlght_line(prefix, final ? past : present, suffix, ps) 1615. #define you_are(attr, ps) enl_msg(You_, are, were, attr, ps) 1616. #define you_have(attr, ps) enl_msg(You_, have, had, attr, ps) 1617. #define you_can(attr, ps) enl_msg(You_, can, could, attr, ps) 1618. #define you_have_been(goodthing) enl_msg(You_, have_been, were, goodthing, "") 1619. #define you_have_never(badthing) \ 1620. enl_msg(You_, have_never, never, badthing, "") 1621. #define you_have_X(something) \ 1622. enl_msg(You_, have, (const char *) "", something, "") 1623. 1624. static void 1625. enlght_out(buf) 1626. const char *buf; 1627. { 1628. if (en_via_menu) { 1629. anything any; 1630. 1631. any = zeroany; 1632. add_menu(en_win, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 1633. } else 1634. putstr(en_win, 0, buf); 1635. } 1636. 1637. static void 1638. enlght_line(start, middle, end, ps) 1639. const char *start, *middle, *end, *ps; 1640. { 1641. char buf[BUFSZ]; 1642. 1643. Sprintf(buf, " %s%s%s%s.", start, middle, end, ps); 1644. enlght_out(buf); 1645. } 1646. 1647. /* format increased chance to hit or damage or defense (Protection) */ 1648. static char * 1649. enlght_combatinc(inctyp, incamt, final, outbuf) 1650. const char *inctyp; 1651. int incamt, final; 1652. char *outbuf; 1653. { 1654. const char *modif, *bonus; 1655. boolean invrt; 1656. int absamt; 1657. 1658. absamt = abs(incamt); 1659. /* Protection amount is typically larger than damage or to-hit; 1660. reduce magnitude by a third in order to stretch modifier ranges 1661. (small:1..5, moderate:6..10, large:11..19, huge:20+) */ 1662. if (!strcmp(inctyp, "defense")) 1663. absamt = (absamt * 2) / 3; 1664. 1665. if (absamt <= 3) 1666. modif = "small"; 1667. else if (absamt <= 6) 1668. modif = "moderate"; 1669. else if (absamt <= 12) 1670. modif = "large"; 1671. else 1672. modif = "huge"; 1673. 1674. modif = !incamt ? "no" : an(modif); /* ("no" case shouldn't happen) */ 1675. bonus = (incamt >= 0) ? "bonus" : "penalty"; 1676. /* "bonus <foo>" (to hit) vs "<bar> bonus" (damage, defense) */ 1677. invrt = strcmp(inctyp, "to hit") ? TRUE : FALSE; 1678. 1679. Sprintf(outbuf, "%s %s %s", modif, invrt ? inctyp : bonus, 1680. invrt ? bonus : inctyp); 1681. if (final || wizard) 1682. Sprintf(eos(outbuf), " (%s%d)", (incamt > 0) ? "+" : "", incamt); 1683. 1684. return outbuf; 1685. } 1686. 1687. /* report half physical or half spell damage */ 1688. STATIC_OVL void 1689. enlght_halfdmg(category, final) 1690. int category; 1691. int final; 1692. { 1693. const char *category_name; 1694. char buf[BUFSZ]; 1695. 1696. switch (category) { 1697. case HALF_PHDAM: 1698. category_name = "physical"; 1699. break; 1700. case HALF_SPDAM: 1701. category_name = "spell"; 1702. break; 1703. default: 1704. category_name = "unknown"; 1705. break; 1706. } 1707. Sprintf(buf, " %s %s damage", (final || wizard) ? "half" : "reduced", 1708. category_name); 1709. enl_msg(You_, "take", "took", buf, from_what(category)); 1710. } 1711. 1712. /* is hero actively using water walking capability on water (or lava)? */ 1713. STATIC_OVL boolean 1714. walking_on_water() 1715. { 1716. if (u.uinwater || Levitation || Flying) 1717. return FALSE; 1718. return (boolean) (Wwalking 1719. && (is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy))); 1720. } 1721. 1722. /* check whether hero is wearing something that player definitely knows 1723. confers the target property; item must have been seen and its type 1724. discovered but it doesn't necessarily have to be fully identified */ 1725. STATIC_OVL boolean 1726. cause_known(propindx) 1727. int propindx; /* index of a property which can be conveyed by worn item */ 1728. { 1729. register struct obj *o; 1730. long mask = W_ARMOR | W_AMUL | W_RING | W_TOOL; 1731. 1732. /* simpler than from_what()/what_gives(); we don't attempt to 1733. handle artifacts and we deliberately ignore wielded items */ 1734. for (o = invent; o; o = o->nobj) { 1735. if (!(o->owornmask & mask)) 1736. continue; 1737. if ((int) objects[o->otyp].oc_oprop == propindx 1738. && objects[o->otyp].oc_name_known && o->dknown) 1739. return TRUE; 1740. } 1741. return FALSE; 1742. } 1743. 1744. /* format a characteristic value, accommodating Strength's strangeness */ 1745. STATIC_OVL char * 1746. attrval(attrindx, attrvalue, resultbuf) 1747. int attrindx, attrvalue; 1748. char resultbuf[]; /* should be at least [7] to hold "18/100\0" */ 1749. { 1750. if (attrindx != A_STR || attrvalue <= 18) 1751. Sprintf(resultbuf, "%d", attrvalue); 1752. else if (attrvalue > STR18(100)) /* 19 to 25 */ 1753. Sprintf(resultbuf, "%d", attrvalue - 100); 1754. else /* simplify "18/ **" to be "18/100" */ 1755. Sprintf(resultbuf, "18/%02d", attrvalue - 18); 1756. return resultbuf; 1757. } 1758. 1759. void 1760. enlightenment(mode, final) 1761. int mode; /* BASICENLIGHTENMENT | MAGICENLIGHTENMENT (| both) */ 1762. int final; /* ENL_GAMEINPROGRESS:0, ENL_GAMEOVERALIVE, ENL_GAMEOVERDEAD */ 1763. { 1764. char buf[BUFSZ], tmpbuf[BUFSZ]; 1765. 1766. en_win = create_nhwindow(NHW_MENU); 1767. en_via_menu = !final; 1768. if (en_via_menu) 1769. start_menu(en_win); 1770. 1771. Strcpy(tmpbuf, plname); 1772. *tmpbuf = highc(*tmpbuf); /* same adjustment as bottom line */ 1773. /* as in background_enlightenment, when poly'd we need to use the saved 1774. gender in u.mfemale rather than the current you-as-monster gender */ 1775. Sprintf(buf, "%s the %s's attributes:", tmpbuf, 1776. ((Upolyd ? u.mfemale : flags.female) && urole.name.f) 1777. ? urole.name.f 1778. : urole.name.m); 1779. 1780. /* title */ 1781. enlght_out(buf); /* "Conan the Archeologist's attributes:" */ 1782. /* background and characteristics; ^X or end-of-game disclosure */ 1783. if (mode & BASICENLIGHTENMENT) { 1784. /* role, race, alignment, deities, dungeon level, time, experience */ 1785. background_enlightenment(mode, final); 1786. /* hit points, energy points, armor class, gold */ 1787. basics_enlightenment(mode, final); 1788. /* strength, dexterity, &c */ 1789. characteristics_enlightenment(mode, final); 1790. } 1791. /* expanded status line information, including things which aren't 1792. included there due to space considerations--such as obvious 1793. alternative movement indicators (riding, levitation, &c), and 1794. various troubles (turning to stone, trapped, confusion, &c); 1795. shown for both basic and magic enlightenment */ 1796. status_enlightenment(mode, final); 1797. /* remaining attributes; shown for potion,&c or wizard mode and 1798. explore mode ^X or end of game disclosure */ 1799. if (mode & MAGICENLIGHTENMENT) { 1800. /* intrinsics and other traditional enlightenment feedback */ 1801. attributes_enlightenment(mode, final); 1802. } 1803. 1804. if (!en_via_menu) { 1805. display_nhwindow(en_win, TRUE); 1806. } else { 1807. menu_item *selected = 0; 1808. 1809. end_menu(en_win, (char *) 0); 1810. if (select_menu(en_win, PICK_NONE, &selected) > 0) 1811. free((genericptr_t) selected); 1812. en_via_menu = FALSE; 1813. } 1814. destroy_nhwindow(en_win); 1815. en_win = WIN_ERR; 1816. } 1817. 1818. /*ARGSUSED*/ 1819. /* display role, race, alignment and such to en_win */ 1820. STATIC_OVL void 1821. background_enlightenment(unused_mode, final) 1822. int unused_mode UNUSED; 1823. int final; 1824. { 1825. const char *role_titl, *rank_titl; 1826. int innategend, difgend, difalgn; 1827. char buf[BUFSZ], tmpbuf[BUFSZ]; 1828. 1829. /* note that if poly'd, we need to use u.mfemale instead of flags.female 1830. to access hero's saved gender-as-human/elf/&c rather than current one */ 1831. innategend = (Upolyd ? u.mfemale : flags.female) ? 1 : 0; 1832. role_titl = (innategend && urole.name.f) ? urole.name.f : urole.name.m; 1833. rank_titl = rank_of(u.ulevel, Role_switch, innategend); 1834. 1835. enlght_out(""); /* separator after title */ 1836. enlght_out("Background:"); 1837. 1838. /* if polymorphed, report current shape before underlying role; 1839. will be repeated as first status: "you are transformed" and also 1840. among various attributes: "you are in beast form" (after being 1841. told about lycanthropy) or "you are polymorphed into <a foo>" 1842. (with countdown timer appended for wizard mode); we really want 1843. the player to know he's not a samurai at the moment... */ 1844. if (Upolyd) { 1845. struct permonst *uasmon = youmonst.data; 1846. 1847. tmpbuf[0] = '\0'; 1848. /* here we always use current gender, not saved role gender */ 1849. if (!is_male(uasmon) && !is_female(uasmon) && !is_neuter(uasmon)) 1850. Sprintf(tmpbuf, "%s ", genders[flags.female ? 1 : 0].adj); 1851. Sprintf(buf, "%sin %s%s form", !final ? "currently " : "", tmpbuf, 1852. uasmon->mname); 1853. you_are(buf, ""); 1854. } 1855. 1856. /* report role; omit gender if it's redundant (eg, "female priestess") */ 1857. tmpbuf[0] = '\0'; 1858. if (!urole.name.f 1859. && ((urole.allow & ROLE_GENDMASK) == (ROLE_MALE | ROLE_FEMALE) 1860. || innategend != flags.initgend)) 1861. Sprintf(tmpbuf, "%s ", genders[innategend].adj); 1862. buf[0] = '\0'; 1863. if (Upolyd) 1864. Strcpy(buf, "actually "); /* "You are actually a ..." */ 1865. if (!strcmpi(rank_titl, role_titl)) { 1866. /* omit role when rank title matches it */ 1867. Sprintf(eos(buf), "%s, level %d %s%s", an(rank_titl), u.ulevel, 1868. tmpbuf, urace.noun); 1869. } else { 1870. Sprintf(eos(buf), "%s, a level %d %s%s %s", an(rank_titl), u.ulevel, 1871. tmpbuf, urace.adj, role_titl); 1872. } 1873. you_are(buf, ""); 1874. 1875. /* report alignment (bypass you_are() in order to omit ending period); 1876. adverb is used to distinguish between temporary change (helm of opp. 1877. alignment), permanent change (one-time conversion), and original */ 1878. Sprintf(buf, " %s%s%s, %son a mission for %s", 1879. You_, !final ? are : were, 1880. align_str(u.ualign.type), 1881. /* helm of opposite alignment (might hide conversion) */ 1882. (u.ualign.type != u.ualignbase[A_CURRENT]) 1883. /* what's the past tense of "currently"? if we used "formerly" 1884. it would sound like a reference to the original alignment */ 1885. ? (!final ? "currently " : "temporarily ") 1886. /* permanent conversion */ 1887. : (u.ualign.type != u.ualignbase[A_ORIGINAL]) 1888. /* and what's the past tense of "now"? certainly not "then" 1889. in a context like this...; "belatedly" == weren't that 1890. way sooner (in other words, didn't start that way) */ 1891. ? (!final ? "now " : "belatedly ") 1892. /* atheist (ignored in very early game) */ 1893. : (!u.uconduct.gnostic && moves > 1000L) 1894. ? "nominally " 1895. /* lastly, normal case */ 1896. : "", 1897. u_gname()); 1898. enlght_out(buf); 1899. /* show the rest of this game's pantheon (finishes previous sentence) 1900. [appending "also Moloch" at the end would allow for straightforward 1901. trailing "and" on all three aligned entries but looks too verbose] */ 1902. Sprintf(buf, " who %s opposed by", !final ? "is" : "was"); 1903. if (u.ualign.type != A_LAWFUL) 1904. Sprintf(eos(buf), " %s (%s) and", align_gname(A_LAWFUL), 1905. align_str(A_LAWFUL)); 1906. if (u.ualign.type != A_NEUTRAL) 1907. Sprintf(eos(buf), " %s (%s)%s", align_gname(A_NEUTRAL), 1908. align_str(A_NEUTRAL), 1909. (u.ualign.type != A_CHAOTIC) ? " and" : ""); 1910. if (u.ualign.type != A_CHAOTIC) 1911. Sprintf(eos(buf), " %s (%s)", align_gname(A_CHAOTIC), 1912. align_str(A_CHAOTIC)); 1913. Strcat(buf, "."); /* terminate sentence */ 1914. enlght_out(buf); 1915. 1916. /* show original alignment,gender,race,role if any have been changed; 1917. giving separate message for temporary alignment change bypasses need 1918. for tricky phrasing otherwise necessitated by possibility of having 1919. helm of opposite alignment mask a permanent alignment conversion */ 1920. difgend = (innategend != flags.initgend); 1921. difalgn = (((u.ualign.type != u.ualignbase[A_CURRENT]) ? 1 : 0) 1922. + ((u.ualignbase[A_CURRENT] != u.ualignbase[A_ORIGINAL]) 1923. ? 2 : 0)); 1924. if (difalgn & 1) { /* have temporary alignment so report permanent one */ 1925. Sprintf(buf, "actually %s", align_str(u.ualignbase[A_CURRENT])); 1926. you_are(buf, ""); 1927. difalgn &= ~1; /* suppress helm from "started out <foo>" message */ 1928. } 1929. if (difgend || difalgn) { /* sex change or perm align change or both */ 1930. Sprintf(buf, " You started out %s%s%s.", 1931. difgend ? genders[flags.initgend].adj : "", 1932. (difgend && difalgn) ? " and " : "", 1933. difalgn ? align_str(u.ualignbase[A_ORIGINAL]) : ""); 1934. enlght_out(buf); 1935. } 1936. 1937. /* 3.6.2: dungeon level, so that ^X really has all status info as 1938. claimed by the comment below; this reveals more information than 1939. the basic status display, but that's one of the purposes of ^X; 1940. similar information is revealed by #overview; the "You died in 1941. <location>" given by really_done() is more rudimentary than this */ 1942. *buf = *tmpbuf = '\0'; 1943. if (In_endgame(&u.uz)) { 1944. int egdepth = observable_depth(&u.uz); 1945. 1946. (void) endgamelevelname(tmpbuf, egdepth); 1947. Sprintf(buf, "in the endgame, on the %s%s", 1948. !strncmp(tmpbuf, "Plane", 5) ? "Elemental " : "", tmpbuf); 1949. } else if (Is_knox(&u.uz)) { 1950. /* this gives away the fact that the knox branch is only 1 level */ 1951. Sprintf(buf, "on the %s level", dungeons[u.uz.dnum].dname); 1952. /* TODO? maybe phrase it differently when actually inside the fort, 1953. if we're able to determine that (not trivial) */ 1954. } else { 1955. char dgnbuf[QBUFSZ]; 1956. 1957. Strcpy(dgnbuf, dungeons[u.uz.dnum].dname); 1958. if (!strncmpi(dgnbuf, "The ", 4)) 1959. *dgnbuf = lowc(*dgnbuf); 1960. Sprintf(tmpbuf, "level %d", 1961. In_quest(&u.uz) ? dunlev(&u.uz) : depth(&u.uz)); 1962. /* TODO? maybe extend this bit to include various other automatic 1963. annotations from the dungeon overview code */ 1964. if (Is_rogue_level(&u.uz)) 1965. Strcat(tmpbuf, ", a primitive area"); 1966. else if (Is_bigroom(&u.uz) && !Blind) 1967. Strcat(tmpbuf, ", a very big room"); 1968. Sprintf(buf, "in %s, on %s", dgnbuf, tmpbuf); 1969. } 1970. you_are(buf, ""); 1971. 1972. /* this is shown even if the 'time' option is off */ 1973. if (moves == 1L) { 1974. you_have("just started your adventure", ""); 1975. } else { 1976. /* 'turns' grates on the nerves in this context... */ 1977. Sprintf(buf, "the dungeon %ld turn%s ago", moves, plur(moves)); 1978. /* same phrasing for current and final: "entered" is unconditional */ 1979. enlght_line(You_, "entered ", buf, ""); 1980. } 1981. if (!Upolyd) { 1982. /* flags.showexp does not matter */ 1983. /* experience level is already shown above */ 1984. Sprintf(buf, "%-1ld experience point%s", u.uexp, plur(u.uexp)); 1985. if (wizard) { 1986. if (u.ulevel < 30) { 1987. int ulvl = (int) u.ulevel; 1988. long nxtlvl = newuexp(ulvl); 1989. /* long oldlvl = (ulvl > 1) ? newuexp(ulvl - 1) : 0; */ 1990. 1991. Sprintf(eos(buf), ", %ld %s%sneeded to attain level %d", 1992. (nxtlvl - u.uexp), (u.uexp > 0) ? "more " : "", 1993. !final ? "" : "were ", (ulvl + 1)); 1994. } 1995. } 1996. you_have(buf, ""); 1997. } 1998. #ifdef SCORE_ON_BOTL 1999. if (flags.showscore) { 2000. /* describes what's shown on status line, which is an approximation; 2001. only show it here if player has the 'showscore' option enabled */ 2002. Sprintf(buf, "%ld%s", botl_score(), 2003. !final ? "" : " before end-of-game adjustments"); 2004. enl_msg("Your score ", "is ", "was ", buf, ""); 2005. } 2006. #endif 2007. } 2008. 2009. /* hit points, energy points, armor class -- essential information which 2010. doesn't fit very well in other categories */ 2011. /*ARGSUSED*/ 2012. STATIC_OVL void 2013. basics_enlightenment(mode, final) 2014. int mode UNUSED; 2015. int final; 2016. { 2017. static char Power[] = "energy points (spell power)"; 2018. char buf[BUFSZ]; 2019. int pw = u.uen, hp = (Upolyd ? u.mh : u.uhp), 2020. pwmax = u.uenmax, hpmax = (Upolyd ? u.mhmax : u.uhpmax); 2021. 2022. enlght_out(""); /* separator after background */ 2023. enlght_out("Basics:"); 2024. 2025. if (hp < 0) 2026. hp = 0; 2027. /* "1 out of 1" rather than "all" if max is only 1; should never happen */ 2028. if (hp == hpmax && hpmax > 1) 2029. Sprintf(buf, "all %d hit points", hpmax); 2030. else 2031. Sprintf(buf, "%d out of %d hit point%s", hp, hpmax, plur(hpmax)); 2032. you_have(buf, ""); 2033. 2034. /* low max energy is feasible, so handle couple of extra special cases */ 2035. if (pwmax == 0 || (pw == pwmax && pwmax == 2)) /* both: "all 2" is silly */ 2036. Sprintf(buf, "%s %s", !pwmax ? "no" : "both", Power); 2037. else if (pw == pwmax && pwmax > 2) 2038. Sprintf(buf, "all %d %s", pwmax, Power); 2039. else 2040. Sprintf(buf, "%d out of %d %s", pw, pwmax, Power); 2041. you_have(buf, ""); 2042. 2043. if (Upolyd) { 2044. switch (mons[u.umonnum].mlevel) { 2045. case 0: 2046. /* status line currently being explained shows "HD:0" */ 2047. Strcpy(buf, "0 hit dice (actually 1/2)"); 2048. break; 2049. case 1: 2050. Strcpy(buf, "1 hit die"); 2051. break; 2052. default: 2053. Sprintf(buf, "%d hit dice", mons[u.umonnum].mlevel); 2054. break; 2055. } 2056. you_have(buf, ""); 2057. } 2058. 2059. Sprintf(buf, "%d", u.uac); 2060. enl_msg("Your armor class ", "is ", "was ", buf, ""); 2061. 2062. /* gold; similar to doprgold(#seegold) but without shop billing info; 2063. same amount as shown on status line which ignores container contents */ 2064. { 2065. static const char Your_wallet[] = "Your wallet "; 2066. long umoney = money_cnt(invent); 2067. 2068. if (!umoney) { 2069. enl_msg(Your_wallet, "is ", "was ", "empty", ""); 2070. } else { 2071. Sprintf(buf, "%ld %s", umoney, currency(umoney)); 2072. enl_msg(Your_wallet, "contains ", "contained ", buf, ""); 2073. } 2074. } 2075. 2076. if (flags.pickup) { 2077. char ocl[MAXOCLASSES + 1]; 2078. 2079. Strcpy(buf, "on"); 2080. oc_to_str(flags.pickup_types, ocl); 2081. Sprintf(eos(buf), " for %s%s%s", 2082. *ocl ? "'" : "", *ocl ? ocl : "all types", *ocl ? "'" : ""); 2083. if (flags.pickup_thrown && *ocl) /* *ocl: don't show if 'all types' */ 2084. Strcat(buf, " plus thrown"); 2085. if (iflags.autopickup_exceptions[AP_GRAB] 2086. || iflags.autopickup_exceptions[AP_LEAVE]) 2087. Strcat(buf, ", with exceptions"); 2088. } else 2089. Strcpy(buf, "off"); 2090. enl_msg("Autopickup ", "is ", "was ", buf, ""); 2091. } 2092. 2093. /* characteristics: expanded version of bottom line strength, dexterity, &c */ 2094. STATIC_OVL void 2095. characteristics_enlightenment(mode, final) 2096. int mode; 2097. int final; 2098. { 2099. char buf[BUFSZ]; 2100. 2101. enlght_out(""); 2102. Sprintf(buf, "%s Characteristics:", !final ? "Current" : "Final"); 2103. enlght_out(buf); 2104. 2105. /* bottom line order */ 2106. one_characteristic(mode, final, A_STR); /* strength */ 2107. one_characteristic(mode, final, A_DEX); /* dexterity */ 2108. one_characteristic(mode, final, A_CON); /* constitution */ 2109. one_characteristic(mode, final, A_INT); /* intelligence */ 2110. one_characteristic(mode, final, A_WIS); /* wisdom */ 2111. one_characteristic(mode, final, A_CHA); /* charisma */ 2112. } 2113. 2114. /* display one attribute value for characteristics_enlightenment() */ 2115. STATIC_OVL void 2116. one_characteristic(mode, final, attrindx) 2117. int mode, final, attrindx; 2118. { 2119. extern const char *const attrname[]; /* attrib.c */ 2120. boolean hide_innate_value = FALSE, interesting_alimit; 2121. int acurrent, abase, apeak, alimit; 2122. const char *paren_pfx; 2123. char subjbuf[BUFSZ], valubuf[BUFSZ], valstring[32]; 2124. 2125. /* being polymorphed or wearing certain cursed items prevents 2126. hero from reliably tracking changes to characteristics so 2127. we don't show base & peak values then; when the items aren't 2128. cursed, hero could take them off to check underlying values 2129. and we show those in such case so that player doesn't need 2130. to actually resort to doing that */ 2131. if (Upolyd) { 2132. hide_innate_value = TRUE; 2133. } else if (Fixed_abil) { 2134. if (stuck_ring(uleft, RIN_SUSTAIN_ABILITY) 2135. || stuck_ring(uright, RIN_SUSTAIN_ABILITY)) 2136. hide_innate_value = TRUE; 2137. } 2138. switch (attrindx) { 2139. case A_STR: 2140. if (uarmg && uarmg->otyp == GAUNTLETS_OF_POWER && uarmg->cursed) 2141. hide_innate_value = TRUE; 2142. break; 2143. case A_DEX: 2144. break; 2145. case A_CON: 2146. if (uwep && uwep->oartifact == ART_OGRESMASHER && uwep->cursed) 2147. hide_innate_value = TRUE; 2148. break; 2149. case A_INT: 2150. if (uarmh && uarmh->otyp == DUNCE_CAP && uarmh->cursed) 2151. hide_innate_value = TRUE; 2152. break; 2153. case A_WIS: 2154. if (uarmh && uarmh->otyp == DUNCE_CAP && uarmh->cursed) 2155. hide_innate_value = TRUE; 2156. break; 2157. case A_CHA: 2158. break; 2159. default: 2160. return; /* impossible */ 2161. }; 2162. /* note: final disclosure includes MAGICENLIGHTENTMENT */ 2163. if ((mode & MAGICENLIGHTENMENT) && !Upolyd) 2164. hide_innate_value = FALSE; 2165. 2166. acurrent = ACURR(attrindx); 2167. (void) attrval(attrindx, acurrent, valubuf); /* Sprintf(valubuf,"%d",) */ 2168. Sprintf(subjbuf, "Your %s ", attrname[attrindx]); 2169. 2170. if (!hide_innate_value) { 2171. /* show abase, amax, and/or attrmax if acurr doesn't match abase 2172. (a magic bonus or penalty is in effect) or abase doesn't match 2173. amax (some points have been lost to poison or exercise abuse 2174. and are restorable) or attrmax is different from normal human 2175. (while game is in progress; trying to reduce dependency on 2176. spoilers to keep track of such stuff) or attrmax was different 2177. from abase (at end of game; this attribute wasn't maxed out) */ 2178. abase = ABASE(attrindx); 2179. apeak = AMAX(attrindx); 2180. alimit = ATTRMAX(attrindx); 2181. /* criterium for whether the limit is interesting varies */ 2182. interesting_alimit = 2183. final ? TRUE /* was originally `(abase != alimit)' */ 2184. : (alimit != (attrindx != A_STR ? 18 : STR18(100))); 2185. paren_pfx = final ? " (" : " (current; "; 2186. if (acurrent != abase) { 2187. Sprintf(eos(valubuf), "%sbase:%s", paren_pfx, 2188. attrval(attrindx, abase, valstring)); 2189. paren_pfx = ", "; 2190. } 2191. if (abase != apeak) { 2192. Sprintf(eos(valubuf), "%speak:%s", paren_pfx, 2193. attrval(attrindx, apeak, valstring)); 2194. paren_pfx = ", "; 2195. } 2196. if (interesting_alimit) { 2197. Sprintf(eos(valubuf), "%s%slimit:%s", paren_pfx, 2198. /* more verbose if exceeding 'limit' due to magic bonus */ 2199. (acurrent > alimit) ? "innate " : "", 2200. attrval(attrindx, alimit, valstring)); 2201. /* paren_pfx = ", "; */ 2202. } 2203. if (acurrent != abase || abase != apeak || interesting_alimit) 2204. Strcat(valubuf, ")"); 2205. } 2206. enl_msg(subjbuf, "is ", "was ", valubuf, ""); 2207. } 2208. 2209. /* status: selected obvious capabilities, assorted troubles */ 2210. STATIC_OVL void 2211. status_enlightenment(mode, final) 2212. int mode; 2213. int final; 2214. { 2215. boolean magic = (mode & MAGICENLIGHTENMENT) ? TRUE : FALSE; 2216. int cap, wtype; 2217. char buf[BUFSZ], youtoo[BUFSZ]; 2218. boolean Riding = (u.usteed 2219. /* if hero dies while dismounting, u.usteed will still 2220. be set; we want to ignore steed in that situation */ 2221. && !(final == ENL_GAMEOVERDEAD 2222. && !strcmp(killer.name, "riding accident"))); 2223. const char *steedname = (!Riding ? (char *) 0 2224. : x_monnam(u.usteed, 2225. u.usteed->mtame ? ARTICLE_YOUR : ARTICLE_THE, 2226. (char *) 0, 2227. (SUPPRESS_SADDLE | SUPPRESS_HALLUCINATION), 2228. FALSE)); 2229. 2230. /*\ 2231. * Status (many are abbreviated on bottom line; others are or 2232. * should be discernible to the hero hence to the player) 2233. \*/ 2234. enlght_out(""); /* separator after title or characteristics */ 2235. enlght_out(final ? "Final Status:" : "Current Status:"); 2236. 2237. Strcpy(youtoo, You_); 2238. /* not a traditional status but inherently obvious to player; more 2239. detail given below (attributes section) for magic enlightenment */ 2240. if (Upolyd) { 2241. Strcpy(buf, "transformed"); 2242. if (ugenocided()) 2243. Sprintf(eos(buf), " and %s %s inside", 2244. final ? "felt" : "feel", udeadinside()); 2245. you_are(buf, ""); 2246. } 2247. /* not a trouble, but we want to display riding status before maybe 2248. reporting steed as trapped or hero stuck to cursed saddle */ 2249. if (Riding) { 2250. Sprintf(buf, "riding %s", steedname); 2251. you_are(buf, ""); 2252. Sprintf(eos(youtoo), "and %s ", steedname); 2253. } 2254. /* other movement situations that hero should always know */ 2255. if (Levitation) { 2256. if (Lev_at_will && magic) 2257. you_are("levitating, at will", ""); 2258. else 2259. enl_msg(youtoo, are, were, "levitating", from_what(LEVITATION)); 2260. } else if (Flying) { /* can only fly when not levitating */ 2261. enl_msg(youtoo, are, were, "flying", from_what(FLYING)); 2262. } 2263. if (Underwater) { 2264. you_are("underwater", ""); 2265. } else if (u.uinwater) { 2266. you_are(Swimming ? "swimming" : "in water", from_what(SWIMMING)); 2267. } else if (walking_on_water()) { 2268. /* show active Wwalking here, potential Wwalking elsewhere */ 2269. Sprintf(buf, "walking on %s", 2270. is_pool(u.ux, u.uy) ? "water" 2271. : is_lava(u.ux, u.uy) ? "lava" 2272. : surface(u.ux, u.uy)); /* catchall; shouldn't happen */ 2273. you_are(buf, from_what(WWALKING)); 2274. } 2275. if (Upolyd && (u.uundetected || U_AP_TYPE != M_AP_NOTHING)) 2276. youhiding(TRUE, final); 2277. 2278. /* internal troubles, mostly in the order that prayer ranks them */ 2279. if (Stoned) 2280. you_are("turning to stone", ""); 2281. if (Slimed) 2282. you_are("turning into slime", ""); 2283. if (Strangled) { 2284. if (u.uburied) { 2285. you_are("buried", ""); 2286. } else { 2287. Strcpy(buf, "being strangled"); 2288. if (wizard) 2289. Sprintf(eos(buf), " (%ld)", (Strangled & TIMEOUT)); 2290. you_are(buf, from_what(STRANGLED)); 2291. } 2292. } 2293. if (Sick) { 2294. /* prayer lumps these together; botl puts Ill before FoodPois */ 2295. if (u.usick_type & SICK_NONVOMITABLE) 2296. you_are("terminally sick from illness", ""); 2297. if (u.usick_type & SICK_VOMITABLE) 2298. you_are("terminally sick from food poisoning", ""); 2299. } 2300. if (Vomiting) 2301. you_are("nauseated", ""); 2302. if (Stunned) 2303. you_are("stunned", ""); 2304. if (Confusion) 2305. you_are("confused", ""); 2306. if (Hallucination) 2307. you_are("hallucinating", ""); 2308. if (Blind) { 2309. /* from_what() (currently wizard-mode only) checks !haseyes() 2310. before u.uroleplay.blind, so we should too */ 2311. Sprintf(buf, "%s blind", 2312. !haseyes(youmonst.data) ? "innately" 2313. : u.uroleplay.blind ? "permanently" 2314. /* better phrasing desperately wanted... */ 2315. : Blindfolded_only ? "deliberately" 2316. : "temporarily"); 2317. if (wizard && (Blinded & TIMEOUT) != 0L 2318. && !u.uroleplay.blind && haseyes(youmonst.data)) 2319. Sprintf(eos(buf), " (%ld)", (Blinded & TIMEOUT)); 2320. /* !haseyes: avoid "you are innately blind innately" */ 2321. you_are(buf, !haseyes(youmonst.data) ? "" : from_what(BLINDED)); 2322. } 2323. if (Deaf) 2324. you_are("deaf", from_what(DEAF)); 2325. 2326. /* external troubles, more or less */ 2327. if (Punished) { 2328. if (uball) { 2329. Sprintf(buf, "chained to %s", ansimpleoname(uball)); 2330. } else { 2331. impossible("Punished without uball?"); 2332. Strcpy(buf, "punished"); 2333. } 2334. you_are(buf, ""); 2335. } 2336. if (u.utrap) { 2337. char predicament[BUFSZ]; 2338. struct trap *t; 2339. boolean anchored = (u.utraptype == TT_BURIEDBALL); 2340. 2341. if (anchored) { 2342. Strcpy(predicament, "tethered to something buried"); 2343. } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_LAVA) { 2344. Sprintf(predicament, "stuck in %s", the(surface(u.ux, u.uy))); 2345. } else { 2346. Strcpy(predicament, "trapped"); 2347. if ((t = t_at(u.ux, u.uy)) != 0) 2348. Sprintf(eos(predicament), " in %s", 2349. an(defsyms[trap_to_defsym(t->ttyp)].explanation)); 2350. } 2351. if (u.usteed) { /* not `Riding' here */ 2352. Sprintf(buf, "%s%s ", anchored ? "you and " : "", steedname); 2353. *buf = highc(*buf); 2354. enl_msg(buf, (anchored ? "are " : "is "), 2355. (anchored ? "were " : "was "), predicament, ""); 2356. } else 2357. you_are(predicament, ""); 2358. } /* (u.utrap) */ 2359. if (u.uswallow) { 2360. Sprintf(buf, "swallowed by %s", a_monnam(u.ustuck)); 2361. if (wizard) 2362. Sprintf(eos(buf), " (%u)", u.uswldtim); 2363. you_are(buf, ""); 2364. } else if (u.ustuck) { 2365. Sprintf(buf, "%s %s", 2366. (Upolyd && sticks(youmonst.data)) ? "holding" : "held by", 2367. a_monnam(u.ustuck)); 2368. you_are(buf, ""); 2369. } 2370. if (Riding) { 2371. struct obj *saddle = which_armor(u.usteed, W_SADDLE); 2372. 2373. if (saddle && saddle->cursed) { 2374. Sprintf(buf, "stuck to %s %s", s_suffix(steedname), 2375. simpleonames(saddle)); 2376. you_are(buf, ""); 2377. } 2378. } 2379. if (Wounded_legs) { 2380. /* when mounted, Wounded_legs applies to steed rather than to 2381. hero; we only report steed's wounded legs in wizard mode */ 2382. if (u.usteed) { /* not `Riding' here */ 2383. if (wizard && steedname) { 2384. Strcpy(buf, steedname); 2385. *buf = highc(*buf); 2386. enl_msg(buf, " has", " had", " wounded legs", ""); 2387. } 2388. } else { 2389. Sprintf(buf, "wounded %s", makeplural(body_part(LEG))); 2390. you_have(buf, ""); 2391. } 2392. } 2393. if (Glib) { 2394. Sprintf(buf, "slippery %s", makeplural(body_part(FINGER))); 2395. you_have(buf, ""); 2396. } 2397. if (Fumbling) { 2398. if (magic || cause_known(FUMBLING)) 2399. enl_msg(You_, "fumble", "fumbled", "", from_what(FUMBLING)); 2400. } 2401. if (Sleepy) { 2402. if (magic || cause_known(SLEEPY)) { 2403. Strcpy(buf, from_what(SLEEPY)); 2404. if (wizard) 2405. Sprintf(eos(buf), " (%ld)", (HSleepy & TIMEOUT)); 2406. enl_msg("You ", "fall", "fell", " asleep uncontrollably", buf); 2407. } 2408. } 2409. /* hunger/nutrition */ 2410. if (Hunger) { 2411. if (magic || cause_known(HUNGER)) 2412. enl_msg(You_, "hunger", "hungered", " rapidly", 2413. from_what(HUNGER)); 2414. } 2415. Strcpy(buf, hu_stat[u.uhs]); /* hunger status; omitted if "normal" */ 2416. mungspaces(buf); /* strip trailing spaces */ 2417. if (*buf) { 2418. *buf = lowc(*buf); /* override capitalization */ 2419. if (!strcmp(buf, "weak")) 2420. Strcat(buf, " from severe hunger"); 2421. else if (!strncmp(buf, "faint", 5)) /* fainting, fainted */ 2422. Strcat(buf, " due to starvation"); 2423. you_are(buf, ""); 2424. } 2425. /* encumbrance */ 2426. if ((cap = near_capacity()) > UNENCUMBERED) { 2427. const char *adj = "?_?"; /* (should always get overridden) */ 2428. 2429. Strcpy(buf, enc_stat[cap]); 2430. *buf = lowc(*buf); 2431. switch (cap) { 2432. case SLT_ENCUMBER: 2433. adj = "slightly"; 2434. break; /* burdened */ 2435. case MOD_ENCUMBER: 2436. adj = "moderately"; 2437. break; /* stressed */ 2438. case HVY_ENCUMBER: 2439. adj = "very"; 2440. break; /* strained */ 2441. case EXT_ENCUMBER: 2442. adj = "extremely"; 2443. break; /* overtaxed */ 2444. case OVERLOADED: 2445. adj = "not possible"; 2446. break; 2447. } 2448. Sprintf(eos(buf), "; movement %s %s%s", !final ? "is" : "was", adj, 2449. (cap < OVERLOADED) ? " slowed" : ""); 2450. you_are(buf, ""); 2451. } else { 2452. /* last resort entry, guarantees Status section is non-empty 2453. (no longer needed for that purpose since weapon status added; 2454. still useful though) */ 2455. you_are("unencumbered", ""); 2456. } 2457. 2458. /* report being weaponless; distinguish whether gloves are worn */ 2459. if (!uwep) { 2460. you_are(uarmg ? "empty handed" /* gloves imply hands */ 2461. : humanoid(youmonst.data) 2462. /* hands but no weapon and no gloves */ 2463. ? "bare handed" 2464. /* alternate phrasing for paws or lack of hands */ 2465. : "not wielding anything", 2466. ""); 2467. /* two-weaponing implies hands (can't be polymorphed) and 2468. a weapon or wep-tool (not other odd stuff) in each hand */ 2469. } else if (u.twoweap) { 2470. you_are("wielding two weapons at once", ""); 2471. /* report most weapons by their skill class (so a katana will be 2472. described as a long sword, for instance; mattock and hook are 2473. exceptions), or wielded non-weapon item by its object class */ 2474. } else { 2475. const char *what = weapon_descr(uwep); 2476. 2477. if (!strcmpi(what, "armor") || !strcmpi(what, "food") 2478. || !strcmpi(what, "venom")) 2479. Sprintf(buf, "wielding some %s", what); 2480. else 2481. Sprintf(buf, "wielding %s", 2482. (uwep->quan == 1L) ? an(what) : makeplural(what)); 2483. you_are(buf, ""); 2484. } 2485. /* 2486. * Skill with current weapon. Might help players who've never 2487. * noticed #enhance or decided that it was pointless. 2488. * 2489. * TODO? Maybe merge wielding line and skill line into one sentence. 2490. */ 2491. if ((wtype = uwep_skill_type()) != P_NONE) { 2492. char sklvlbuf[20]; 2493. int sklvl = P_SKILL(wtype); 2494. boolean hav = (sklvl != P_UNSKILLED && sklvl != P_SKILLED); 2495. 2496. if (sklvl == P_ISRESTRICTED) 2497. Strcpy(sklvlbuf, "no"); 2498. else 2499. (void) lcase(skill_level_name(wtype, sklvlbuf)); 2500. /* "you have no/basic/expert/master/grand-master skill with <skill>" 2501. or "you are unskilled/skilled in <skill>" */ 2502. Sprintf(buf, "%s %s %s", sklvlbuf, 2503. hav ? "skill with" : "in", skill_name(wtype)); 2504. if (can_advance(wtype, FALSE)) 2505. Sprintf(eos(buf), " and %s that", 2506. !final ? "can enhance" : "could have enhanced"); 2507. if (hav) 2508. you_have(buf, ""); 2509. else 2510. you_are(buf, ""); 2511. } 2512. /* report 'nudity' */ 2513. if (!uarm && !uarmu && !uarmc && !uarms && !uarmg && !uarmf && !uarmh) { 2514. if (u.uroleplay.nudist) 2515. enl_msg(You_, "do", "did", " not wear any armor", ""); 2516. else 2517. you_are("not wearing any armor", ""); 2518. } 2519. } 2520. 2521. /* attributes: intrinsics and the like, other non-obvious capabilities */ 2522. void 2523. attributes_enlightenment(unused_mode, final) 2524. int unused_mode UNUSED; 2525. int final; 2526. { 2527. static NEARDATA const char if_surroundings_permitted[] = 2528. " if surroundings permitted"; 2529. int ltmp, armpro; 2530. char buf[BUFSZ]; 2531. 2532. /*\ 2533. * Attributes 2534. \*/ 2535. enlght_out(""); 2536. enlght_out(final ? "Final Attributes:" : "Current Attributes:"); 2537. 2538. if (u.uevent.uhand_of_elbereth) { 2539. static const char *const hofe_titles[3] = { "the Hand of Elbereth", 2540. "the Envoy of Balance", 2541. "the Glory of Arioch" }; 2542. you_are(hofe_titles[u.uevent.uhand_of_elbereth - 1], ""); 2543. } 2544. 2545. Sprintf(buf, "%s", piousness(TRUE, "aligned")); 2546. if (u.ualign.record >= 0) 2547. you_are(buf, ""); 2548. else 2549. you_have(buf, ""); 2550. 2551. if (wizard) { 2552. Sprintf(buf, " %d", u.ualign.record); 2553. enl_msg("Your alignment ", "is", "was", buf, ""); 2554. } 2555. 2556. /*** Resistances to troubles ***/ 2557. if (Invulnerable) 2558. you_are("invulnerable", from_what(INVULNERABLE)); 2559. if (Antimagic) 2560. you_are("magic-protected", from_what(ANTIMAGIC)); 2561. if (Fire_resistance) 2562. you_are("fire resistant", from_what(FIRE_RES)); 2563. if (Cold_resistance) 2564. you_are("cold resistant", from_what(COLD_RES)); 2565. if (Sleep_resistance) 2566. you_are("sleep resistant", from_what(SLEEP_RES)); 2567. if (Disint_resistance) 2568. you_are("disintegration-resistant", from_what(DISINT_RES)); 2569. if (Shock_resistance) 2570. you_are("shock resistant", from_what(SHOCK_RES)); 2571. if (Poison_resistance) 2572. you_are("poison resistant", from_what(POISON_RES)); 2573. if (Acid_resistance) 2574. you_are("acid resistant", from_what(ACID_RES)); 2575. if (Drain_resistance) 2576. you_are("level-drain resistant", from_what(DRAIN_RES)); 2577. if (Sick_resistance) 2578. you_are("immune to sickness", from_what(SICK_RES)); 2579. if (Stone_resistance) 2580. you_are("petrification resistant", from_what(STONE_RES)); 2581. if (Halluc_resistance) 2582. enl_msg(You_, "resist", "resisted", " hallucinations", 2583. from_what(HALLUC_RES)); 2584. if (u.uedibility) 2585. you_can("recognize detrimental food", ""); 2586. 2587. /*** Vision and senses ***/ 2588. if (!Blind && (Blinded || !haseyes(youmonst.data))) 2589. you_can("see", from_what(-BLINDED)); /* Eyes of the Overworld */ 2590. if (See_invisible) { 2591. if (!Blind) 2592. enl_msg(You_, "see", "saw", " invisible", from_what(SEE_INVIS)); 2593. else 2594. enl_msg(You_, "will see", "would have seen", 2595. " invisible when not blind", from_what(SEE_INVIS)); 2596. } 2597. if (Blind_telepat) 2598. you_are("telepathic", from_what(TELEPAT)); 2599. if (Warning) 2600. you_are("warned", from_what(WARNING)); 2601. if (Warn_of_mon && context.warntype.obj) { 2602. Sprintf(buf, "aware of the presence of %s", 2603. (context.warntype.obj & M2_ORC) ? "orcs" 2604. : (context.warntype.obj & M2_ELF) ? "elves" 2605. : (context.warntype.obj & M2_DEMON) ? "demons" : something); 2606. you_are(buf, from_what(WARN_OF_MON)); 2607. } 2608. if (Warn_of_mon && context.warntype.polyd) { 2609. Sprintf(buf, "aware of the presence of %s", 2610. ((context.warntype.polyd & (M2_HUMAN | M2_ELF)) 2611. == (M2_HUMAN | M2_ELF)) 2612. ? "humans and elves" 2613. : (context.warntype.polyd & M2_HUMAN) 2614. ? "humans" 2615. : (context.warntype.polyd & M2_ELF) 2616. ? "elves" 2617. : (context.warntype.polyd & M2_ORC) 2618. ? "orcs" 2619. : (context.warntype.polyd & M2_DEMON) 2620. ? "demons" 2621. : "certain monsters"); 2622. you_are(buf, ""); 2623. } 2624. if (Warn_of_mon && context.warntype.speciesidx >= LOW_PM) { 2625. Sprintf(buf, "aware of the presence of %s", 2626. makeplural(mons[context.warntype.speciesidx].mname)); 2627. you_are(buf, from_what(WARN_OF_MON)); 2628. } 2629. if (Undead_warning) 2630. you_are("warned of undead", from_what(WARN_UNDEAD)); 2631. if (Searching) 2632. you_have("automatic searching", from_what(SEARCHING)); 2633. if (Clairvoyant) 2634. you_are("clairvoyant", from_what(CLAIRVOYANT)); 2635. else if ((HClairvoyant || EClairvoyant) && BClairvoyant) { 2636. Strcpy(buf, from_what(-CLAIRVOYANT)); 2637. if (!strncmp(buf, " because of ", 12)) 2638. /* overwrite substring; strncpy doesn't add terminator */ 2639. (void) strncpy(buf, " if not for ", 12); 2640. enl_msg(You_, "could be", "could have been", " clairvoyant", buf); 2641. } 2642. if (Infravision) 2643. you_have("infravision", from_what(INFRAVISION)); 2644. if (Detect_monsters) 2645. you_are("sensing the presence of monsters", ""); 2646. if (u.umconf) 2647. you_are("going to confuse monsters", ""); 2648. 2649. /*** Appearance and behavior ***/ 2650. if (Adornment) { 2651. int adorn = 0; 2652. 2653. if (uleft && uleft->otyp == RIN_ADORNMENT) 2654. adorn += uleft->spe; 2655. if (uright && uright->otyp == RIN_ADORNMENT) 2656. adorn += uright->spe; 2657. /* the sum might be 0 (+0 ring or two which negate each other); 2658. that yields "you are charismatic" (which isn't pointless 2659. because it potentially impacts seduction attacks) */ 2660. Sprintf(buf, "%scharismatic", 2661. (adorn > 0) ? "more " : (adorn < 0) ? "less " : ""); 2662. you_are(buf, from_what(ADORNED)); 2663. } 2664. if (Invisible) 2665. you_are("invisible", from_what(INVIS)); 2666. else if (Invis) 2667. you_are("invisible to others", from_what(INVIS)); 2668. /* ordinarily "visible" is redundant; this is a special case for 2669. the situation when invisibility would be an expected attribute */ 2670. else if ((HInvis || EInvis) && BInvis) 2671. you_are("visible", from_what(-INVIS)); 2672. if (Displaced) 2673. you_are("displaced", from_what(DISPLACED)); 2674. if (Stealth) 2675. you_are("stealthy", from_what(STEALTH)); 2676. if (Aggravate_monster) 2677. enl_msg("You aggravate", "", "d", " monsters", 2678. from_what(AGGRAVATE_MONSTER)); 2679. if (Conflict) 2680. enl_msg("You cause", "", "d", " conflict", from_what(CONFLICT)); 2681. 2682. /*** Transportation ***/ 2683. if (Jumping) 2684. you_can("jump", from_what(JUMPING)); 2685. if (Teleportation) 2686. you_can("teleport", from_what(TELEPORT)); 2687. if (Teleport_control) 2688. you_have("teleport control", from_what(TELEPORT_CONTROL)); 2689. /* actively levitating handled earlier as a status condition */ 2690. if (BLevitation) { /* levitation is blocked */ 2691. long save_BLev = BLevitation; 2692. 2693. BLevitation = 0L; 2694. if (Levitation) { 2695. /* either trapped in the floor or inside solid rock 2696. (or both if chained to buried iron ball and have 2697. moved one step into solid rock somehow) */ 2698. boolean trapped = (save_BLev & I_SPECIAL) != 0L, 2699. terrain = (save_BLev & FROMOUTSIDE) != 0L; 2700. 2701. Sprintf(buf, "%s%s%s", 2702. trapped ? " if not trapped" : "", 2703. (trapped && terrain) ? " and" : "", 2704. terrain ? if_surroundings_permitted : ""); 2705. enl_msg(You_, "would levitate", "would have levitated", buf, ""); 2706. } 2707. BLevitation = save_BLev; 2708. } 2709. /* actively flying handled earlier as a status condition */ 2710. if (BFlying) { /* flight is blocked */ 2711. long save_BFly = BFlying; 2712. 2713. BFlying = 0L; 2714. if (Flying) { 2715. enl_msg(You_, "would fly", "would have flown", 2716. /* wording quibble: for past tense, "hadn't been" 2717. would sound better than "weren't" (and 2718. "had permitted" better than "permitted"), but 2719. "weren't" and "permitted" are adequate so the 2720. extra complexity to handle that isn't worth it */ 2721. Levitation 2722. ? " if you weren't levitating" 2723. : (save_BFly == I_SPECIAL) 2724. /* this is an oversimpliction; being trapped 2725. might also be blocking levitation so flight 2726. would still be blocked after escaping trap */ 2727. ? " if you weren't trapped" 2728. : (save_BFly == FROMOUTSIDE) 2729. ? if_surroundings_permitted 2730. /* two or more of levitation, surroundings, 2731. and being trapped in the floor */ 2732. : " if circumstances permitted", 2733. ""); 2734. } 2735. BFlying = save_BFly; 2736. } 2737. /* actively walking on water handled earlier as a status condition */ 2738. if (Wwalking && !walking_on_water()) 2739. you_can("walk on water", from_what(WWALKING)); 2740. /* actively swimming (in water but not under it) handled earlier */ 2741. if (Swimming && (Underwater || !u.uinwater)) 2742. you_can("swim", from_what(SWIMMING)); 2743. if (Breathless) 2744. you_can("survive without air", from_what(MAGICAL_BREATHING)); 2745. else if (Amphibious) 2746. you_can("breathe water", from_what(MAGICAL_BREATHING)); 2747. if (Passes_walls) 2748. you_can("walk through walls", from_what(PASSES_WALLS)); 2749. 2750. /*** Physical attributes ***/ 2751. if (Regeneration) 2752. enl_msg("You regenerate", "", "d", "", from_what(REGENERATION)); 2753. if (Slow_digestion) 2754. you_have("slower digestion", from_what(SLOW_DIGESTION)); 2755. if (u.uhitinc) 2756. you_have(enlght_combatinc("to hit", u.uhitinc, final, buf), ""); 2757. if (u.udaminc) 2758. you_have(enlght_combatinc("damage", u.udaminc, final, buf), ""); 2759. if (u.uspellprot || Protection) { 2760. int prot = 0; 2761. 2762. if (uleft && uleft->otyp == RIN_PROTECTION) 2763. prot += uleft->spe; 2764. if (uright && uright->otyp == RIN_PROTECTION) 2765. prot += uright->spe; 2766. if (HProtection & INTRINSIC) 2767. prot += u.ublessed; 2768. prot += u.uspellprot; 2769. if (prot) 2770. you_have(enlght_combatinc("defense", prot, final, buf), ""); 2771. } 2772. if ((armpro = magic_negation(&youmonst)) > 0) { 2773. /* magic cancellation factor, conferred by worn armor */ 2774. static const char *const mc_types[] = { 2775. "" /*ordinary*/, "warded", "guarded", "protected", 2776. }; 2777. /* sanity check */ 2778. if (armpro >= SIZE(mc_types)) 2779. armpro = SIZE(mc_types) - 1; 2780. you_are(mc_types[armpro], ""); 2781. } 2782. if (Half_physical_damage) 2783. enlght_halfdmg(HALF_PHDAM, final); 2784. if (Half_spell_damage) 2785. enlght_halfdmg(HALF_SPDAM, final); 2786. /* polymorph and other shape change */ 2787. if (Protection_from_shape_changers) 2788. you_are("protected from shape changers", 2789. from_what(PROT_FROM_SHAPE_CHANGERS)); 2790. if (Unchanging) { 2791. const char *what = 0; 2792. 2793. if (!Upolyd) /* Upolyd handled below after current form */ 2794. you_can("not change from your current form", 2795. from_what(UNCHANGING)); 2796. /* blocked shape changes */ 2797. if (Polymorph) 2798. what = !final ? "polymorph" : "have polymorphed"; 2799. else if (u.ulycn >= LOW_PM) 2800. what = !final ? "change shape" : "have changed shape"; 2801. if (what) { 2802. Sprintf(buf, "would %s periodically", what); 2803. /* omit from_what(UNCHANGING); too verbose */ 2804. enl_msg(You_, buf, buf, " if not locked into your current form", 2805. ""); 2806. } 2807. } else if (Polymorph) { 2808. you_are("polymorphing periodically", from_what(POLYMORPH)); 2809. } 2810. if (Polymorph_control) 2811. you_have("polymorph control", from_what(POLYMORPH_CONTROL)); 2812. if (Upolyd && u.umonnum != u.ulycn 2813. /* if we've died from turning into slime, we're polymorphed 2814. right now but don't want to list it as a temporary attribute 2815. [we need a more reliable way to detect this situation] */ 2816. && !(final == ENL_GAMEOVERDEAD 2817. && u.umonnum == PM_GREEN_SLIME && !Unchanging)) { 2818. /* foreign shape (except were-form which is handled below) */ 2819. Sprintf(buf, "polymorphed into %s", an(youmonst.data->mname)); 2820. if (wizard) 2821. Sprintf(eos(buf), " (%d)", u.mtimedone); 2822. you_are(buf, ""); 2823. } 2824. if (lays_eggs(youmonst.data) && flags.female) /* Upolyd */ 2825. you_can("lay eggs", ""); 2826. if (u.ulycn >= LOW_PM) { 2827. /* "you are a werecreature [in beast form]" */ 2828. Strcpy(buf, an(mons[u.ulycn].mname)); 2829. if (u.umonnum == u.ulycn) { 2830. Strcat(buf, " in beast form"); 2831. if (wizard) 2832. Sprintf(eos(buf), " (%d)", u.mtimedone); 2833. } 2834. you_are(buf, ""); 2835. } 2836. if (Unchanging && Upolyd) /* !Upolyd handled above */ 2837. you_can("not change from your current form", from_what(UNCHANGING)); 2838. if (Hate_silver) 2839. you_are("harmed by silver", ""); 2840. /* movement and non-armor-based protection */ 2841. if (Fast) 2842. you_are(Very_fast ? "very fast" : "fast", from_what(FAST)); 2843. if (Reflecting) 2844. you_have("reflection", from_what(REFLECTING)); 2845. if (Free_action) 2846. you_have("free action", from_what(FREE_ACTION)); 2847. if (Fixed_abil) 2848. you_have("fixed abilities", from_what(FIXED_ABIL)); 2849. if (Lifesaved) 2850. enl_msg("Your life ", "will be", "would have been", " saved", ""); 2851. 2852. /*** Miscellany ***/ 2853. if (Luck) { 2854. ltmp = abs((int) Luck); 2855. Sprintf(buf, "%s%slucky", 2856. ltmp >= 10 ? "extremely " : ltmp >= 5 ? "very " : "", 2857. Luck < 0 ? "un" : ""); 2858. if (wizard) 2859. Sprintf(eos(buf), " (%d)", Luck); 2860. you_are(buf, ""); 2861. } else if (wizard) 2862. enl_msg("Your luck ", "is", "was", " zero", ""); 2863. if (u.moreluck > 0) 2864. you_have("extra luck", ""); 2865. else if (u.moreluck < 0) 2866. you_have("reduced luck", ""); 2867. if (carrying(LUCKSTONE) || stone_luck(TRUE)) { 2868. ltmp = stone_luck(FALSE); 2869. if (ltmp <= 0) 2870. enl_msg("Bad luck ", "does", "did", " not time out for you", ""); 2871. if (ltmp >= 0) 2872. enl_msg("Good luck ", "does", "did", " not time out for you", ""); 2873. } 2874. 2875. if (u.ugangr) { 2876. Sprintf(buf, " %sangry with you", 2877. u.ugangr > 6 ? "extremely " : u.ugangr > 3 ? "very " : ""); 2878. if (wizard) 2879. Sprintf(eos(buf), " (%d)", u.ugangr); 2880. enl_msg(u_gname(), " is", " was", buf, ""); 2881. } else { 2882. /* 2883. * We need to suppress this when the game is over, because death 2884. * can change the value calculated by can_pray(), potentially 2885. * resulting in a false claim that you could have prayed safely. 2886. */ 2887. if (!final) { 2888. #if 0 2889. /* "can [not] safely pray" vs "could [not] have safely prayed" */ 2890. Sprintf(buf, "%s%ssafely pray%s", can_pray(FALSE) ? "" : "not ", 2891. final ? "have " : "", final ? "ed" : ""); 2892. #else 2893. Sprintf(buf, "%ssafely pray", can_pray(FALSE) ? "" : "not "); 2894. #endif 2895. if (wizard) 2896. Sprintf(eos(buf), " (%d)", u.ublesscnt); 2897. you_can(buf, ""); 2898. } 2899. } 2900. 2901. #ifdef DEBUG 2902. /* named fruit debugging (doesn't really belong here...); to enable, 2903. include 'fruit' in DEBUGFILES list (even though it isn't a file...) */ 2904. if (wizard && explicitdebug("fruit")) { 2905. struct fruit *f; 2906. 2907. reorder_fruit(TRUE); /* sort by fruit index, from low to high; 2908. * this modifies the ffruit chain, so could 2909. * possibly mask or even introduce a problem, 2910. * but it does useful sanity checking */ 2911. for (f = ffruit; f; f = f->nextf) { 2912. Sprintf(buf, "Fruit #%d ", f->fid); 2913. enl_msg(buf, "is ", "was ", f->fname, ""); 2914. } 2915. enl_msg("The current fruit ", "is ", "was ", pl_fruit, ""); 2916. Sprintf(buf, "%d", flags.made_fruit); 2917. enl_msg("The made fruit flag ", "is ", "was ", buf, ""); 2918. } 2919. #endif 2920. 2921. { 2922. const char *p; 2923. 2924. buf[0] = '\0'; 2925. if (final < 2) { /* still in progress, or quit/escaped/ascended */ 2926. p = "survived after being killed "; 2927. switch (u.umortality) { 2928. case 0: 2929. p = !final ? (char *) 0 : "survived"; 2930. break; 2931. case 1: 2932. Strcpy(buf, "once"); 2933. break; 2934. case 2: 2935. Strcpy(buf, "twice"); 2936. break; 2937. case 3: 2938. Strcpy(buf, "thrice"); 2939. break; 2940. default: 2941. Sprintf(buf, "%d times", u.umortality); 2942. break; 2943. } 2944. } else { /* game ended in character's death */ 2945. p = "are dead"; 2946. switch (u.umortality) { 2947. case 0: 2948. impossible("dead without dying?"); 2949. case 1: 2950. break; /* just "are dead" */ 2951. default: 2952. Sprintf(buf, " (%d%s time!)", u.umortality, 2953. ordin(u.umortality)); 2954. break; 2955. } 2956. } 2957. if (p) 2958. enl_msg(You_, "have been killed ", p, buf, ""); 2959. } 2960. } 2961. 2962. #if 0 /* no longer used */ 2963. STATIC_DCL boolean NDECL(minimal_enlightenment); 2964. 2965. /* 2966. * Courtesy function for non-debug, non-explorer mode players 2967. * to help refresh them about who/what they are. 2968. * Returns FALSE if menu cancelled (dismissed with ESC), TRUE otherwise. 2969. */ 2970. STATIC_OVL boolean 2971. minimal_enlightenment() 2972. { 2973. winid tmpwin; 2974. menu_item *selected; 2975. anything any; 2976. int genidx, n; 2977. char buf[BUFSZ], buf2[BUFSZ]; 2978. static const char untabbed_fmtstr[] = "%-15s: %-12s"; 2979. static const char untabbed_deity_fmtstr[] = "%-17s%s"; 2980. static const char tabbed_fmtstr[] = "%s:\t%-12s"; 2981. static const char tabbed_deity_fmtstr[] = "%s\t%s"; 2982. static const char *fmtstr; 2983. static const char *deity_fmtstr; 2984. 2985. fmtstr = iflags.menu_tab_sep ? tabbed_fmtstr : untabbed_fmtstr; 2986. deity_fmtstr = iflags.menu_tab_sep ? tabbed_deity_fmtstr 2987. : untabbed_deity_fmtstr; 2988. any = zeroany; 2989. buf[0] = buf2[0] = '\0'; 2990. tmpwin = create_nhwindow(NHW_MENU); 2991. start_menu(tmpwin); 2992. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, 2993. "Starting", FALSE); 2994. 2995. /* Starting name, race, role, gender */ 2996. Sprintf(buf, fmtstr, "name", plname); 2997. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 2998. Sprintf(buf, fmtstr, "race", urace.noun); 2999. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3000. Sprintf(buf, fmtstr, "role", 3001. (flags.initgend && urole.name.f) ? urole.name.f : urole.name.m); 3002. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3003. Sprintf(buf, fmtstr, "gender", genders[flags.initgend].adj); 3004. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3005. 3006. /* Starting alignment */ 3007. Sprintf(buf, fmtstr, "alignment", align_str(u.ualignbase[A_ORIGINAL])); 3008. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3009. 3010. /* Current name, race, role, gender */ 3011. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", FALSE); 3012. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, 3013. "Current", FALSE); 3014. Sprintf(buf, fmtstr, "race", Upolyd ? youmonst.data->mname : urace.noun); 3015. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3016. if (Upolyd) { 3017. Sprintf(buf, fmtstr, "role (base)", 3018. (u.mfemale && urole.name.f) ? urole.name.f 3019. : urole.name.m); 3020. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3021. } else { 3022. Sprintf(buf, fmtstr, "role", 3023. (flags.female && urole.name.f) ? urole.name.f 3024. : urole.name.m); 3025. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3026. } 3027. /* don't want poly_gender() here; it forces `2' for non-humanoids */ 3028. genidx = is_neuter(youmonst.data) ? 2 : flags.female; 3029. Sprintf(buf, fmtstr, "gender", genders[genidx].adj); 3030. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3031. if (Upolyd && (int) u.mfemale != genidx) { 3032. Sprintf(buf, fmtstr, "gender (base)", genders[u.mfemale].adj); 3033. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3034. } 3035. 3036. /* Current alignment */ 3037. Sprintf(buf, fmtstr, "alignment", align_str(u.ualign.type)); 3038. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3039. 3040. /* Deity list */ 3041. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, "", FALSE); 3042. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, 3043. "Deities", FALSE); 3044. Sprintf(buf2, deity_fmtstr, align_gname(A_CHAOTIC), 3045. (u.ualignbase[A_ORIGINAL] == u.ualign.type 3046. && u.ualign.type == A_CHAOTIC) ? " (s,c)" 3047. : (u.ualignbase[A_ORIGINAL] == A_CHAOTIC) ? " (s)" 3048. : (u.ualign.type == A_CHAOTIC) ? " (c)" : ""); 3049. Sprintf(buf, fmtstr, "Chaotic", buf2); 3050. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3051. 3052. Sprintf(buf2, deity_fmtstr, align_gname(A_NEUTRAL), 3053. (u.ualignbase[A_ORIGINAL] == u.ualign.type 3054. && u.ualign.type == A_NEUTRAL) ? " (s,c)" 3055. : (u.ualignbase[A_ORIGINAL] == A_NEUTRAL) ? " (s)" 3056. : (u.ualign.type == A_NEUTRAL) ? " (c)" : ""); 3057. Sprintf(buf, fmtstr, "Neutral", buf2); 3058. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3059. 3060. Sprintf(buf2, deity_fmtstr, align_gname(A_LAWFUL), 3061. (u.ualignbase[A_ORIGINAL] == u.ualign.type 3062. && u.ualign.type == A_LAWFUL) ? " (s,c)" 3063. : (u.ualignbase[A_ORIGINAL] == A_LAWFUL) ? " (s)" 3064. : (u.ualign.type == A_LAWFUL) ? " (c)" : ""); 3065. Sprintf(buf, fmtstr, "Lawful", buf2); 3066. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, buf, FALSE); 3067. 3068. end_menu(tmpwin, "Base Attributes"); 3069. n = select_menu(tmpwin, PICK_NONE, &selected); 3070. destroy_nhwindow(tmpwin); 3071. return (boolean) (n != -1); 3072. } 3073. #endif /*0*/ 3074. 3075. /* ^X command */ 3076. STATIC_PTR int 3077. doattributes(VOID_ARGS) 3078. { 3079. int mode = BASICENLIGHTENMENT; 3080. 3081. /* show more--as if final disclosure--for wizard and explore modes */ 3082. if (wizard || discover) 3083. mode |= MAGICENLIGHTENMENT; 3084. 3085. enlightenment(mode, ENL_GAMEINPROGRESS); 3086. return 0; 3087. } 3088. 3089. void 3090. youhiding(via_enlghtmt, msgflag) 3091. boolean via_enlghtmt; /* englightment line vs topl message */ 3092. int msgflag; /* for variant message phrasing */ 3093. { 3094. char *bp, buf[BUFSZ]; 3095. 3096. Strcpy(buf, "hiding"); 3097. if (U_AP_TYPE != M_AP_NOTHING) { 3098. /* mimic; hero is only able to mimic a strange object or gold 3099. or hallucinatory alternative to gold, so we skip the details 3100. for the hypothetical furniture and monster cases */ 3101. bp = eos(strcpy(buf, "mimicking")); 3102. if (U_AP_TYPE == M_AP_OBJECT) { 3103. Sprintf(bp, " %s", an(simple_typename(youmonst.mappearance))); 3104. } else if (U_AP_TYPE == M_AP_FURNITURE) { 3105. Strcpy(bp, " something"); 3106. } else if (U_AP_TYPE == M_AP_MONSTER) { 3107. Strcpy(bp, " someone"); 3108. } else { 3109. ; /* something unexpected; leave 'buf' as-is */ 3110. } 3111. } else if (u.uundetected) { 3112. bp = eos(buf); /* points past "hiding" */ 3113. if (youmonst.data->mlet == S_EEL) { 3114. if (is_pool(u.ux, u.uy)) 3115. Sprintf(bp, " in the %s", waterbody_name(u.ux, u.uy)); 3116. } else if (hides_under(youmonst.data)) { 3117. struct obj *o = level.objects[u.ux][u.uy]; 3118. 3119. if (o) 3120. Sprintf(bp, " underneath %s", ansimpleoname(o)); 3121. } else if (is_clinger(youmonst.data) || Flying) { 3122. /* Flying: 'lurker above' hides on ceiling but doesn't cling */ 3123. Sprintf(bp, " on the %s", ceiling(u.ux, u.uy)); 3124. } else { 3125. /* on floor; is_hider() but otherwise not special: 'trapper' */ 3126. if (u.utrap && u.utraptype == TT_PIT) { 3127. struct trap *t = t_at(u.ux, u.uy); 3128. 3129. Sprintf(bp, " in a %spit", 3130. (t && t->ttyp == SPIKED_PIT) ? "spiked " : ""); 3131. } else 3132. Sprintf(bp, " on the %s", surface(u.ux, u.uy)); 3133. } 3134. } else { 3135. ; /* shouldn't happen; will result in generic "you are hiding" */ 3136. } 3137. 3138. if (via_enlghtmt) { 3139. int final = msgflag; /* 'final' is used by you_are() macro */ 3140. 3141. you_are(buf, ""); 3142. } else { 3143. /* for dohide(), when player uses '#monster' command */ 3144. You("are %s %s.", msgflag ? "already" : "now", buf); 3145. } 3146. } 3147. 3148. /* KMH, #conduct 3149. * (shares enlightenment's tense handling) 3150. */ 3151. int 3152. doconduct(VOID_ARGS) 3153. { 3154. show_conduct(0); 3155. return 0; 3156. } 3157. 3158. void 3159. show_conduct(final) 3160. int final; 3161. { 3162. char buf[BUFSZ]; 3163. int ngenocided; 3164. 3165. /* Create the conduct window */ 3166. en_win = create_nhwindow(NHW_MENU); 3167. putstr(en_win, 0, "Voluntary challenges:"); 3168. 3169. if (u.uroleplay.blind) 3170. you_have_been("blind from birth"); 3171. if (u.uroleplay.nudist) 3172. you_have_been("faithfully nudist"); 3173. 3174. if (!u.uconduct.food) 3175. enl_msg(You_, "have gone", "went", " without food", ""); 3176. /* but beverages are okay */ 3177. else if (!u.uconduct.unvegan) 3178. you_have_X("followed a strict vegan diet"); 3179. else if (!u.uconduct.unvegetarian) 3180. you_have_been("vegetarian"); 3181. 3182. if (!u.uconduct.gnostic) 3183. you_have_been("an atheist"); 3184. 3185. if (!u.uconduct.weaphit) { 3186. you_have_never("hit with a wielded weapon"); 3187. } else if (wizard) { 3188. Sprintf(buf, "used a wielded weapon %ld time%s", u.uconduct.weaphit, 3189. plur(u.uconduct.weaphit)); 3190. you_have_X(buf); 3191. } 3192. if (!u.uconduct.killer) 3193. you_have_been("a pacifist"); 3194. 3195. if (!u.uconduct.literate) { 3196. you_have_been("illiterate"); 3197. } else if (wizard) { 3198. Sprintf(buf, "read items or engraved %ld time%s", u.uconduct.literate, 3199. plur(u.uconduct.literate)); 3200. you_have_X(buf); 3201. } 3202. 3203. ngenocided = num_genocides(); 3204. if (ngenocided == 0) { 3205. you_have_never("genocided any monsters"); 3206. } else { 3207. Sprintf(buf, "genocided %d type%s of monster%s", ngenocided, 3208. plur(ngenocided), plur(ngenocided)); 3209. you_have_X(buf); 3210. } 3211. 3212. if (!u.uconduct.polypiles) { 3213. you_have_never("polymorphed an object"); 3214. } else if (wizard) { 3215. Sprintf(buf, "polymorphed %ld item%s", u.uconduct.polypiles, 3216. plur(u.uconduct.polypiles)); 3217. you_have_X(buf); 3218. } 3219. 3220. if (!u.uconduct.polyselfs) { 3221. you_have_never("changed form"); 3222. } else if (wizard) { 3223. Sprintf(buf, "changed form %ld time%s", u.uconduct.polyselfs, 3224. plur(u.uconduct.polyselfs)); 3225. you_have_X(buf); 3226. } 3227. 3228. if (!u.uconduct.wishes) { 3229. you_have_X("used no wishes"); 3230. } else { 3231. Sprintf(buf, "used %ld wish%s", u.uconduct.wishes, 3232. (u.uconduct.wishes > 1L) ? "es" : ""); 3233. if (u.uconduct.wisharti) { 3234. /* if wisharti == wishes 3235. * 1 wish (for an artifact) 3236. * 2 wishes (both for artifacts) 3237. * N wishes (all for artifacts) 3238. * else (N is at least 2 in order to get here; M < N) 3239. * N wishes (1 for an artifact) 3240. * N wishes (M for artifacts) 3241. */ 3242. if (u.uconduct.wisharti == u.uconduct.wishes) 3243. Sprintf(eos(buf), " (%s", 3244. (u.uconduct.wisharti > 2L) ? "all " 3245. : (u.uconduct.wisharti == 2L) ? "both " : ""); 3246. else 3247. Sprintf(eos(buf), " (%ld ", u.uconduct.wisharti); 3248. 3249. Sprintf(eos(buf), "for %s)", 3250. (u.uconduct.wisharti == 1L) ? "an artifact" 3251. : "artifacts"); 3252. } 3253. you_have_X(buf); 3254. 3255. if (!u.uconduct.wisharti) 3256. enl_msg(You_, "have not wished", "did not wish", 3257. " for any artifacts", ""); 3258. } 3259. 3260. /* Pop up the window and wait for a key */ 3261. display_nhwindow(en_win, TRUE); 3262. destroy_nhwindow(en_win); 3263. en_win = WIN_ERR; 3264. } 3265. 3266. /* ordered by command name */ 3267. struct ext_func_tab extcmdlist[] = { 3268. { '#', "#", "perform an extended command", 3269. doextcmd, IFBURIED | GENERALCMD }, 3270. { M('?'), "?", "list all extended commands", 3271. doextlist, IFBURIED | AUTOCOMPLETE | GENERALCMD }, 3272. { M('a'), "adjust", "adjust inventory letters", 3273. doorganize, IFBURIED | AUTOCOMPLETE }, 3274. { M('A'), "annotate", "name current level", 3275. donamelevel, IFBURIED | AUTOCOMPLETE }, 3276. { 'a', "apply", "apply (use) a tool (pick-axe, key, lamp...)", 3277. doapply }, 3278. { C('x'), "attributes", "show your attributes", 3279. doattributes, IFBURIED }, 3280. { '@', "autopickup", "toggle the pickup option on/off", 3281. dotogglepickup, IFBURIED }, 3282. { 'C', "call", "call (name) something", docallcmd, IFBURIED }, 3283. { 'Z', "cast", "zap (cast) a spell", docast, IFBURIED }, 3284. { M('c'), "chat", "talk to someone", dotalk, IFBURIED | AUTOCOMPLETE }, 3285. { 'c', "close", "close a door", doclose }, 3286. { M('C'), "conduct", "list voluntary challenges you have maintained", 3287. doconduct, IFBURIED | AUTOCOMPLETE }, 3288. { M('d'), "dip", "dip an object into something", dodip, AUTOCOMPLETE }, 3289. { '>', "down", "go down a staircase", dodown }, 3290. { 'd', "drop", "drop an item", dodrop }, 3291. { 'D', "droptype", "drop specific item types", doddrop }, 3292. { 'e', "eat", "eat something", doeat }, 3293. { 'E', "engrave", "engrave writing on the floor", doengrave }, 3294. { M('e'), "enhance", "advance or check weapon and spell skills", 3295. enhance_weapon_skill, IFBURIED | AUTOCOMPLETE }, 3296. { '\0', "exploremode", "enter explore (discovery) mode", 3297. enter_explore_mode, IFBURIED }, 3298. { 'f', "fire", "fire ammunition from quiver", dofire }, 3299. { M('f'), "force", "force a lock", doforce, AUTOCOMPLETE }, 3300. { ';', "glance", "show what type of thing a map symbol corresponds to", 3301. doquickwhatis, IFBURIED | GENERALCMD }, 3302. { '?', "help", "give a help message", dohelp, IFBURIED | GENERALCMD }, 3303. { '\0', "herecmdmenu", "show menu of commands you can do here", 3304. doherecmdmenu, IFBURIED }, 3305. { 'V', "history", "show long version and game history", 3306. dohistory, IFBURIED | GENERALCMD }, 3307. { 'i', "inventory", "show your inventory", ddoinv, IFBURIED }, 3308. { 'I', "inventtype", "inventory specific item types", 3309. dotypeinv, IFBURIED }, 3310. { M('i'), "invoke", "invoke an object's special powers", 3311. doinvoke, IFBURIED | AUTOCOMPLETE }, 3312. { M('j'), "jump", "jump to another location", dojump, AUTOCOMPLETE }, 3313. { C('d'), "kick", "kick something", dokick }, 3314. { '\\', "known", "show what object types have been discovered", 3315. dodiscovered, IFBURIED | GENERALCMD }, 3316. { '`', "knownclass", "show discovered types for one class of objects", 3317. doclassdisco, IFBURIED | GENERALCMD }, 3318. { '\0', "levelchange", "change experience level", 3319. wiz_level_change, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3320. { '\0', "lightsources", "show mobile light sources", 3321. wiz_light_sources, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3322. { ':', "look", "look at what is here", dolook, IFBURIED }, 3323. { M('l'), "loot", "loot a box on the floor", doloot, AUTOCOMPLETE }, 3324. #ifdef DEBUG_MIGRATING_MONS 3325. { '\0', "migratemons", "migrate N random monsters", 3326. wiz_migrate_mons, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3327. #endif 3328. { M('m'), "monster", "use monster's special ability", 3329. domonability, IFBURIED | AUTOCOMPLETE }, 3330. { 'N', "name", "name a monster or an object", 3331. docallcmd, IFBURIED | AUTOCOMPLETE }, 3332. { M('o'), "offer", "offer a sacrifice to the gods", 3333. dosacrifice, AUTOCOMPLETE }, 3334. { 'o', "open", "open a door", doopen }, 3335. { 'O', "options", "show option settings, possibly change them", 3336. doset, IFBURIED | GENERALCMD }, 3337. { C('o'), "overview", "show a summary of the explored dungeon", 3338. dooverview, IFBURIED | AUTOCOMPLETE }, 3339. { '\0', "panic", "test panic routine (fatal to game)", 3340. wiz_panic, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3341. { 'p', "pay", "pay your shopping bill", dopay }, 3342. { ',', "pickup", "pick up things at the current location", dopickup }, 3343. { '\0', "polyself", "polymorph self", 3344. wiz_polyself, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3345. { M('p'), "pray", "pray to the gods for help", 3346. dopray, IFBURIED | AUTOCOMPLETE }, 3347. { C('p'), "prevmsg", "view recent game messages", 3348. doprev_message, IFBURIED | GENERALCMD }, 3349. { 'P', "puton", "put on an accessory (ring, amulet, etc)", doputon }, 3350. { 'q', "quaff", "quaff (drink) something", dodrink }, 3351. { M('q'), "quit", "exit without saving current game", 3352. done2, IFBURIED | AUTOCOMPLETE | GENERALCMD }, 3353. { 'Q', "quiver", "select ammunition for quiver", dowieldquiver }, 3354. { 'r', "read", "read a scroll or spellbook", doread }, 3355. { C('r'), "redraw", "redraw screen", doredraw, IFBURIED | GENERALCMD }, 3356. { 'R', "remove", "remove an accessory (ring, amulet, etc)", doremring }, 3357. { M('R'), "ride", "mount or dismount a saddled steed", 3358. doride, AUTOCOMPLETE }, 3359. { M('r'), "rub", "rub a lamp or a stone", dorub, AUTOCOMPLETE }, 3360. { 'S', "save", "save the game and exit", dosave, IFBURIED | GENERALCMD }, 3361. { 's', "search", "search for traps and secret doors", 3362. dosearch, IFBURIED, "searching" }, 3363. { '*', "seeall", "show all equipment in use", doprinuse, IFBURIED }, 3364. { AMULET_SYM, "seeamulet", "show the amulet currently worn", 3365. dopramulet, IFBURIED }, 3366. { ARMOR_SYM, "seearmor", "show the armor currently worn", 3367. doprarm, IFBURIED }, 3368. { GOLD_SYM, "seegold", "count your gold", doprgold, IFBURIED }, 3369. { '\0', "seenv", "show seen vectors", 3370. wiz_show_seenv, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3371. { RING_SYM, "seerings", "show the ring(s) currently worn", 3372. doprring, IFBURIED }, 3373. { SPBOOK_SYM, "seespells", "list and reorder known spells", 3374. dovspell, IFBURIED }, 3375. { TOOL_SYM, "seetools", "show the tools currently in use", 3376. doprtool, IFBURIED }, 3377. { '^', "seetrap", "show the type of adjacent trap", doidtrap, IFBURIED }, 3378. { WEAPON_SYM, "seeweapon", "show the weapon currently wielded", 3379. doprwep, IFBURIED }, 3380. { '!', "shell", "do a shell escape", 3381. dosh_core, IFBURIED | GENERALCMD 3382. #ifndef SHELL 3383. | CMD_NOT_AVAILABLE 3384. #endif /* SHELL */ 3385. }, 3386. { M('s'), "sit", "sit down", dosit, AUTOCOMPLETE }, 3387. { '\0', "stats", "show memory statistics", 3388. wiz_show_stats, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3389. { C('z'), "suspend", "suspend the game", 3390. dosuspend_core, IFBURIED | GENERALCMD 3391. #ifndef SUSPEND 3392. | CMD_NOT_AVAILABLE 3393. #endif /* SUSPEND */ 3394. }, 3395. { 'x', "swap", "swap wielded and secondary weapons", doswapweapon }, 3396. { 'T', "takeoff", "take off one piece of armor", dotakeoff }, 3397. { 'A', "takeoffall", "remove all armor", doddoremarm }, 3398. { C('t'), "teleport", "teleport around the level", dotelecmd, IFBURIED }, 3399. { '\0', "terrain", "show map without obstructions", 3400. doterrain, IFBURIED | AUTOCOMPLETE }, 3401. { '\0', "therecmdmenu", 3402. "menu of commands you can do from here to adjacent spot", 3403. dotherecmdmenu }, 3404. { 't', "throw", "throw something", dothrow }, 3405. { '\0', "timeout", "look at timeout queue and hero's timed intrinsics", 3406. wiz_timeout_queue, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3407. { M('T'), "tip", "empty a container", dotip, AUTOCOMPLETE }, 3408. { '_', "travel", "travel to a specific location on the map", dotravel }, 3409. { M('t'), "turn", "turn undead away", doturn, IFBURIED | AUTOCOMPLETE }, 3410. { 'X', "twoweapon", "toggle two-weapon combat", 3411. dotwoweapon, AUTOCOMPLETE }, 3412. { M('u'), "untrap", "untrap something", dountrap, AUTOCOMPLETE }, 3413. { '<', "up", "go up a staircase", doup }, 3414. { '\0', "vanquished", "list vanquished monsters", 3415. dovanquished, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3416. { M('v'), "version", 3417. "list compile time options for this version of NetHack", 3418. doextversion, IFBURIED | AUTOCOMPLETE | GENERALCMD }, 3419. { 'v', "versionshort", "show version", doversion, IFBURIED | GENERALCMD }, 3420. { '\0', "vision", "show vision array", 3421. wiz_show_vision, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3422. { '.', "wait", "rest one move while doing nothing", 3423. donull, IFBURIED, "waiting" }, 3424. { 'W', "wear", "wear a piece of armor", dowear }, 3425. { '&', "whatdoes", "tell what a command does", dowhatdoes, IFBURIED }, 3426. { '/', "whatis", "show what type of thing a symbol corresponds to", 3427. dowhatis, IFBURIED | GENERALCMD }, 3428. { 'w', "wield", "wield (put in use) a weapon", dowield }, 3429. { M('w'), "wipe", "wipe off your face", dowipe, AUTOCOMPLETE }, 3430. #ifdef DEBUG 3431. { '\0', "wizbury", "bury objs under and around you", 3432. wiz_debug_cmd_bury, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3433. #endif 3434. { C('e'), "wizdetect", "reveal hidden things within a small radius", 3435. wiz_detect, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3436. { C('g'), "wizgenesis", "create a monster", 3437. wiz_genesis, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3438. { C('i'), "wizidentify", "identify all items in inventory", 3439. wiz_identify, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3440. { '\0', "wizintrinsic", "set an intrinsic", 3441. wiz_intrinsic, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3442. { C('v'), "wizlevelport", "teleport to another level", 3443. wiz_level_tele, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3444. { '\0', "wizmakemap", "recreate the current level", 3445. wiz_makemap, IFBURIED | WIZMODECMD }, 3446. { C('f'), "wizmap", "map the level", 3447. wiz_map, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3448. { '\0', "wizrumorcheck", "verify rumor boundaries", 3449. wiz_rumor_check, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3450. { '\0', "wizsmell", "smell monster", 3451. wiz_smell, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3452. { '\0', "wizwhere", "show locations of special levels", 3453. wiz_where, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3454. { C('w'), "wizwish", "wish for something", 3455. wiz_wish, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3456. { '\0', "wmode", "show wall modes", 3457. wiz_show_wmodes, IFBURIED | AUTOCOMPLETE | WIZMODECMD }, 3458. { 'z', "zap", "zap a wand", dozap }, 3459. { '\0', (char *) 0, (char *) 0, donull, 0, (char *) 0 } /* sentinel */ 3460. }; 3461. 3462. int extcmdlist_length = SIZE(extcmdlist) - 1; 3463. 3464. const char * 3465. key2extcmddesc(key) 3466. uchar key; 3467. { 3468. if (Cmd.commands[key] && Cmd.commands[key]->ef_txt) 3469. return Cmd.commands[key]->ef_desc; 3470. return (char *) 0; 3471. } 3472. 3473. boolean 3474. bind_key(key, command) 3475. uchar key; 3476. const char *command; 3477. { 3478. struct ext_func_tab *extcmd; 3479. 3480. /* special case: "nothing" is reserved for unbinding */ 3481. if (!strcmp(command, "nothing")) { 3482. Cmd.commands[key] = (struct ext_func_tab *) 0; 3483. return TRUE; 3484. } 3485. 3486. for (extcmd = extcmdlist; extcmd->ef_txt; extcmd++) { 3487. if (strcmp(command, extcmd->ef_txt)) 3488. continue; 3489. Cmd.commands[key] = extcmd; 3490. #if 0 /* silently accept key binding for unavailable command (!SHELL,&c) */ 3491. if ((extcmd->flags & CMD_NOT_AVAILABLE) != 0) { 3492. char buf[BUFSZ]; 3493. 3494. Sprintf(buf, cmdnotavail, extcmd->ef_txt); 3495. config_error_add("%s", buf); 3496. } 3497. #endif 3498. return TRUE; 3499. } 3500. 3501. return FALSE; 3502. } 3503. 3504. /* initialize all keyboard commands */ 3505. void 3506. commands_init() 3507. { 3508. struct ext_func_tab *extcmd; 3509. 3510. for (extcmd = extcmdlist; extcmd->ef_txt; extcmd++) 3511. if (extcmd->key) 3512. Cmd.commands[extcmd->key] = extcmd; 3513. 3514. (void) bind_key(C('l'), "redraw"); /* if number_pad is set */ 3515. /* 'b', 'B' : go sw */ 3516. /* 'F' : fight (one time) */ 3517. /* 'g', 'G' : multiple go */ 3518. /* 'h', 'H' : go west */ 3519. (void) bind_key('h', "help"); /* if number_pad is set */ 3520. (void) bind_key('j', "jump"); /* if number_pad is on */ 3521. /* 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N' move commands */ 3522. (void) bind_key('k', "kick"); /* if number_pad is on */ 3523. (void) bind_key('l', "loot"); /* if number_pad is on */ 3524. (void) bind_key(C('n'), "annotate"); /* if number_pad is on */ 3525. (void) bind_key(M('n'), "name"); 3526. (void) bind_key(M('N'), "name"); 3527. (void) bind_key('u', "untrap"); /* if number_pad is on */ 3528. 3529. /* alt keys: */ 3530. (void) bind_key(M('O'), "overview"); 3531. (void) bind_key(M('2'), "twoweapon"); 3532. 3533. /* wait_on_space */ 3534. (void) bind_key(' ', "wait"); 3535. } 3536. 3537. int 3538. dokeylist_putcmds(datawin, docount, cmdflags, exflags, keys_used) 3539. winid datawin; 3540. boolean docount; 3541. int cmdflags, exflags; 3542. boolean *keys_used; /* boolean keys_used[256] */ 3543. { 3544. int i; 3545. char buf[BUFSZ]; 3546. char buf2[QBUFSZ]; 3547. int count = 0; 3548. 3549. for (i = 0; i < 256; i++) { 3550. const struct ext_func_tab *extcmd; 3551. uchar key = (uchar) i; 3552. 3553. if (keys_used[i]) 3554. continue; 3555. if (key == ' ' && !flags.rest_on_space) 3556. continue; 3557. if ((extcmd = Cmd.commands[i]) != (struct ext_func_tab *) 0) { 3558. if ((cmdflags && !(extcmd->flags & cmdflags)) 3559. || (exflags && (extcmd->flags & exflags))) 3560. continue; 3561. if (docount) { 3562. count++; 3563. continue; 3564. } 3565. Sprintf(buf, "%-8s %-12s %s", key2txt(key, buf2), 3566. extcmd->ef_txt, 3567. extcmd->ef_desc); 3568. putstr(datawin, 0, buf); 3569. keys_used[i] = TRUE; 3570. } 3571. } 3572. return count; 3573. } 3574. 3575. /* list all keys and their bindings, like dat/hh but dynamic */ 3576. void 3577. dokeylist(VOID_ARGS) 3578. { 3579. char buf[BUFSZ], buf2[BUFSZ]; 3580. uchar key; 3581. boolean keys_used[256] = {0}; 3582. winid datawin; 3583. int i; 3584. static const char 3585. run_desc[] = "Prefix: run until something very interesting is seen", 3586. forcefight_desc[] = 3587. "Prefix: force fight even if you don't see a monster"; 3588. static const struct { 3589. int nhkf; 3590. const char *desc; 3591. boolean numpad; 3592. } misc_keys[] = { 3593. { NHKF_ESC, "escape from the current query/action", FALSE }, 3594. { NHKF_RUSH, 3595. "Prefix: rush until something interesting is seen", FALSE }, 3596. { NHKF_RUN, run_desc, FALSE }, 3597. { NHKF_RUN2, run_desc, TRUE }, 3598. { NHKF_FIGHT, forcefight_desc, FALSE }, 3599. { NHKF_FIGHT2, forcefight_desc, TRUE } , 3600. { NHKF_NOPICKUP, 3601. "Prefix: move without picking up objects/fighting", FALSE }, 3602. { NHKF_RUN_NOPICKUP, 3603. "Prefix: run without picking up objects/fighting", FALSE }, 3604. { NHKF_DOINV, "view inventory", TRUE }, 3605. { NHKF_REQMENU, "Prefix: request a menu", FALSE }, 3606. #ifdef REDO 3607. { NHKF_DOAGAIN , "re-do: perform the previous command again", FALSE }, 3608. #endif 3609. { 0, (const char *) 0, FALSE } 3610. }; 3611. 3612. datawin = create_nhwindow(NHW_TEXT); 3613. putstr(datawin, 0, ""); 3614. putstr(datawin, 0, " Full Current Key Bindings List"); 3615. 3616. /* directional keys */ 3617. putstr(datawin, 0, ""); 3618. putstr(datawin, 0, "Directional keys:"); 3619. show_direction_keys(datawin, '.', FALSE); /* '.'==self in direction grid */ 3620. 3621. keys_used[(uchar) Cmd.move_NW] = keys_used[(uchar) Cmd.move_N] 3622. = keys_used[(uchar) Cmd.move_NE] = keys_used[(uchar) Cmd.move_W] 3623. = keys_used[(uchar) Cmd.move_E] = keys_used[(uchar) Cmd.move_SW] 3624. = keys_used[(uchar) Cmd.move_S] = keys_used[(uchar) Cmd.move_SE] 3625. = TRUE; 3626. 3627. if (!iflags.num_pad) { 3628. keys_used[(uchar) highc(Cmd.move_NW)] 3629. = keys_used[(uchar) highc(Cmd.move_N)] 3630. = keys_used[(uchar) highc(Cmd.move_NE)] 3631. = keys_used[(uchar) highc(Cmd.move_W)] 3632. = keys_used[(uchar) highc(Cmd.move_E)] 3633. = keys_used[(uchar) highc(Cmd.move_SW)] 3634. = keys_used[(uchar) highc(Cmd.move_S)] 3635. = keys_used[(uchar) highc(Cmd.move_SE)] = TRUE; 3636. keys_used[(uchar) C(Cmd.move_NW)] 3637. = keys_used[(uchar) C(Cmd.move_N)] 3638. = keys_used[(uchar) C(Cmd.move_NE)] 3639. = keys_used[(uchar) C(Cmd.move_W)] 3640. = keys_used[(uchar) C(Cmd.move_E)] 3641. = keys_used[(uchar) C(Cmd.move_SW)] 3642. = keys_used[(uchar) C(Cmd.move_S)] 3643. = keys_used[(uchar) C(Cmd.move_SE)] = TRUE; 3644. putstr(datawin, 0, ""); 3645. putstr(datawin, 0, 3646. "Shift-<direction> will move in specified direction until you hit"); 3647. putstr(datawin, 0, " a wall or run into something."); 3648. putstr(datawin, 0, 3649. "Ctrl-<direction> will run in specified direction until something"); 3650. putstr(datawin, 0, " very interesting is seen."); 3651. } 3652. 3653. putstr(datawin, 0, ""); 3654. putstr(datawin, 0, "Miscellaneous keys:"); 3655. for (i = 0; misc_keys[i].desc; i++) { 3656. key = Cmd.spkeys[misc_keys[i].nhkf]; 3657. if (key && ((misc_keys[i].numpad && iflags.num_pad) 3658. || !misc_keys[i].numpad)) { 3659. keys_used[(uchar) key] = TRUE; 3660. Sprintf(buf, "%-8s %s", key2txt(key, buf2), misc_keys[i].desc); 3661. putstr(datawin, 0, buf); 3662. } 3663. } 3664. #ifndef NO_SIGNAL 3665. putstr(datawin, 0, "^c break out of NetHack (SIGINT)"); 3666. keys_used[(uchar) C('c')] = TRUE; 3667. #endif 3668. 3669. putstr(datawin, 0, ""); 3670. show_menu_controls(datawin, TRUE); 3671. 3672. if (dokeylist_putcmds(datawin, TRUE, GENERALCMD, WIZMODECMD, keys_used)) { 3673. putstr(datawin, 0, ""); 3674. putstr(datawin, 0, "General commands:"); 3675. (void) dokeylist_putcmds(datawin, FALSE, GENERALCMD, WIZMODECMD, 3676. keys_used); 3677. } 3678. 3679. if (dokeylist_putcmds(datawin, TRUE, 0, WIZMODECMD, keys_used)) { 3680. putstr(datawin, 0, ""); 3681. putstr(datawin, 0, "Game commands:"); 3682. (void) dokeylist_putcmds(datawin, FALSE, 0, WIZMODECMD, keys_used); 3683. } 3684. 3685. if (wizard 3686. && dokeylist_putcmds(datawin, TRUE, WIZMODECMD, 0, keys_used)) { 3687. putstr(datawin, 0, ""); 3688. putstr(datawin, 0, "Wizard-mode commands:"); 3689. (void) dokeylist_putcmds(datawin, FALSE, WIZMODECMD, 0, keys_used); 3690. } 3691. 3692. display_nhwindow(datawin, FALSE); 3693. destroy_nhwindow(datawin); 3694. } 3695. 3696. char 3697. cmd_from_func(fn) 3698. int NDECL((*fn)); 3699. { 3700. int i; 3701. 3702. for (i = 0; i < 256; ++i) 3703. if (Cmd.commands[i] && Cmd.commands[i]->ef_funct == fn) 3704. return (char) i; 3705. return '\0'; 3706. } 3707. 3708. /* 3709. * wizard mode sanity_check code 3710. */ 3711. 3712. static const char template[] = "%-27s %4ld %6ld"; 3713. static const char stats_hdr[] = " count bytes"; 3714. static const char stats_sep[] = "--------------------------- ----- -------"; 3715. 3716. STATIC_OVL int 3717. size_obj(otmp) 3718. struct obj *otmp; 3719. { 3720. int sz = (int) sizeof (struct obj); 3721. 3722. if (otmp->oextra) { 3723. sz += (int) sizeof (struct oextra); 3724. if (ONAME(otmp)) 3725. sz += (int) strlen(ONAME(otmp)) + 1; 3726. if (OMONST(otmp)) 3727. sz += size_monst(OMONST(otmp), FALSE); 3728. if (OMID(otmp)) 3729. sz += (int) sizeof (unsigned); 3730. if (OLONG(otmp)) 3731. sz += (int) sizeof (long); 3732. if (OMAILCMD(otmp)) 3733. sz += (int) strlen(OMAILCMD(otmp)) + 1; 3734. } 3735. return sz; 3736. } 3737. 3738. STATIC_OVL void 3739. count_obj(chain, total_count, total_size, top, recurse) 3740. struct obj *chain; 3741. long *total_count; 3742. long *total_size; 3743. boolean top; 3744. boolean recurse; 3745. { 3746. long count, size; 3747. struct obj *obj; 3748. 3749. for (count = size = 0, obj = chain; obj; obj = obj->nobj) { 3750. if (top) { 3751. count++; 3752. size += size_obj(obj); 3753. } 3754. if (recurse && obj->cobj) 3755. count_obj(obj->cobj, total_count, total_size, TRUE, TRUE); 3756. } 3757. *total_count += count; 3758. *total_size += size; 3759. } 3760. 3761. STATIC_OVL void 3762. obj_chain(win, src, chain, force, total_count, total_size) 3763. winid win; 3764. const char *src; 3765. struct obj *chain; 3766. boolean force; 3767. long *total_count; 3768. long *total_size; 3769. { 3770. char buf[BUFSZ]; 3771. long count = 0L, size = 0L; 3772. 3773. count_obj(chain, &count, &size, TRUE, FALSE); 3774. 3775. if (count || size || force) { 3776. *total_count += count; 3777. *total_size += size; 3778. Sprintf(buf, template, src, count, size); 3779. putstr(win, 0, buf); 3780. } 3781. } 3782. 3783. STATIC_OVL void 3784. mon_invent_chain(win, src, chain, total_count, total_size) 3785. winid win; 3786. const char *src; 3787. struct monst *chain; 3788. long *total_count; 3789. long *total_size; 3790. { 3791. char buf[BUFSZ]; 3792. long count = 0, size = 0; 3793. struct monst *mon; 3794. 3795. for (mon = chain; mon; mon = mon->nmon) 3796. count_obj(mon->minvent, &count, &size, TRUE, FALSE); 3797. 3798. if (count || size) { 3799. *total_count += count; 3800. *total_size += size; 3801. Sprintf(buf, template, src, count, size); 3802. putstr(win, 0, buf); 3803. } 3804. } 3805. 3806. STATIC_OVL void 3807. contained_stats(win, src, total_count, total_size) 3808. winid win; 3809. const char *src; 3810. long *total_count; 3811. long *total_size; 3812. { 3813. char buf[BUFSZ]; 3814. long count = 0, size = 0; 3815. struct monst *mon; 3816. 3817. count_obj(invent, &count, &size, FALSE, TRUE); 3818. count_obj(fobj, &count, &size, FALSE, TRUE); 3819. count_obj(level.buriedobjlist, &count, &size, FALSE, TRUE); 3820. count_obj(migrating_objs, &count, &size, FALSE, TRUE); 3821. /* DEADMONSTER check not required in this loop since they have no 3822. * inventory */ 3823. for (mon = fmon; mon; mon = mon->nmon) 3824. count_obj(mon->minvent, &count, &size, FALSE, TRUE); 3825. for (mon = migrating_mons; mon; mon = mon->nmon) 3826. count_obj(mon->minvent, &count, &size, FALSE, TRUE); 3827. 3828. if (count || size) { 3829. *total_count += count; 3830. *total_size += size; 3831. Sprintf(buf, template, src, count, size); 3832. putstr(win, 0, buf); 3833. } 3834. } 3835. 3836. STATIC_OVL int 3837. size_monst(mtmp, incl_wsegs) 3838. struct monst *mtmp; 3839. boolean incl_wsegs; 3840. { 3841. int sz = (int) sizeof (struct monst); 3842. 3843. if (mtmp->wormno && incl_wsegs) 3844. sz += size_wseg(mtmp); 3845. 3846. if (mtmp->mextra) { 3847. sz += (int) sizeof (struct mextra); 3848. if (MNAME(mtmp)) 3849. sz += (int) strlen(MNAME(mtmp)) + 1; 3850. if (EGD(mtmp)) 3851. sz += (int) sizeof (struct egd); 3852. if (EPRI(mtmp)) 3853. sz += (int) sizeof (struct epri); 3854. if (ESHK(mtmp)) 3855. sz += (int) sizeof (struct eshk); 3856. if (EMIN(mtmp)) 3857. sz += (int) sizeof (struct emin); 3858. if (EDOG(mtmp)) 3859. sz += (int) sizeof (struct edog); 3860. /* mextra->mcorpsenm doesn't point to more memory */ 3861. } 3862. return sz; 3863. } 3864. 3865. STATIC_OVL void 3866. mon_chain(win, src, chain, force, total_count, total_size) 3867. winid win; 3868. const char *src; 3869. struct monst *chain; 3870. boolean force; 3871. long *total_count; 3872. long *total_size; 3873. { 3874. char buf[BUFSZ]; 3875. long count, size; 3876. struct monst *mon; 3877. /* mon->wormno means something different for migrating_mons and mydogs */ 3878. boolean incl_wsegs = !strcmpi(src, "fmon"); 3879. 3880. count = size = 0L; 3881. for (mon = chain; mon; mon = mon->nmon) { 3882. count++; 3883. size += size_monst(mon, incl_wsegs); 3884. } 3885. if (count || size || force) { 3886. *total_count += count; 3887. *total_size += size; 3888. Sprintf(buf, template, src, count, size); 3889. putstr(win, 0, buf); 3890. } 3891. } 3892. 3893. STATIC_OVL void 3894. misc_stats(win, total_count, total_size) 3895. winid win; 3896. long *total_count; 3897. long *total_size; 3898. { 3899. char buf[BUFSZ], hdrbuf[QBUFSZ]; 3900. long count, size; 3901. int idx; 3902. struct trap *tt; 3903. struct damage *sd; /* shop damage */ 3904. struct kinfo *k; /* delayed killer */ 3905. struct cemetery *bi; /* bones info */ 3906. 3907. /* traps and engravings are output unconditionally; 3908. * others only if nonzero 3909. */ 3910. count = size = 0L; 3911. for (tt = ftrap; tt; tt = tt->ntrap) { 3912. ++count; 3913. size += (long) sizeof *tt; 3914. } 3915. *total_count += count; 3916. *total_size += size; 3917. Sprintf(hdrbuf, "traps, size %ld", (long) sizeof (struct trap)); 3918. Sprintf(buf, template, hdrbuf, count, size); 3919. putstr(win, 0, buf); 3920. 3921. count = size = 0L; 3922. engr_stats("engravings, size %ld+text", hdrbuf, &count, &size); 3923. *total_count += count; 3924. *total_size += size; 3925. Sprintf(buf, template, hdrbuf, count, size); 3926. putstr(win, 0, buf); 3927. 3928. count = size = 0L; 3929. light_stats("light sources, size %ld", hdrbuf, &count, &size); 3930. if (count || size) { 3931. *total_count += count; 3932. *total_size += size; 3933. Sprintf(buf, template, hdrbuf, count, size); 3934. putstr(win, 0, buf); 3935. } 3936. 3937. count = size = 0L; 3938. timer_stats("timers, size %ld", hdrbuf, &count, &size); 3939. if (count || size) { 3940. *total_count += count; 3941. *total_size += size; 3942. Sprintf(buf, template, hdrbuf, count, size); 3943. putstr(win, 0, buf); 3944. } 3945. 3946. count = size = 0L; 3947. for (sd = level.damagelist; sd; sd = sd->next) { 3948. ++count; 3949. size += (long) sizeof *sd; 3950. } 3951. if (count || size) { 3952. *total_count += count; 3953. *total_size += size; 3954. Sprintf(hdrbuf, "shop damage, size %ld", 3955. (long) sizeof (struct damage)); 3956. Sprintf(buf, template, hdrbuf, count, size); 3957. putstr(win, 0, buf); 3958. } 3959. 3960. count = size = 0L; 3961. region_stats("regions, size %ld+%ld*rect+N", hdrbuf, &count, &size); 3962. if (count || size) { 3963. *total_count += count; 3964. *total_size += size; 3965. Sprintf(buf, template, hdrbuf, count, size); 3966. putstr(win, 0, buf); 3967. } 3968. 3969. count = size = 0L; 3970. for (k = killer.next; k; k = k->next) { 3971. ++count; 3972. size += (long) sizeof *k; 3973. } 3974. if (count || size) { 3975. *total_count += count; 3976. *total_size += size; 3977. Sprintf(hdrbuf, "delayed killer%s, size %ld", 3978. plur(count), (long) sizeof (struct kinfo)); 3979. Sprintf(buf, template, hdrbuf, count, size); 3980. putstr(win, 0, buf); 3981. } 3982. 3983. count = size = 0L; 3984. for (bi = level.bonesinfo; bi; bi = bi->next) { 3985. ++count; 3986. size += (long) sizeof *bi; 3987. } 3988. if (count || size) { 3989. *total_count += count; 3990. *total_size += size; 3991. Sprintf(hdrbuf, "bones history, size %ld", 3992. (long) sizeof (struct cemetery)); 3993. Sprintf(buf, template, hdrbuf, count, size); 3994. putstr(win, 0, buf); 3995. } 3996. 3997. count = size = 0L; 3998. for (idx = 0; idx < NUM_OBJECTS; ++idx) 3999. if (objects[idx].oc_uname) { 4000. ++count; 4001. size += (long) (strlen(objects[idx].oc_uname) + 1); 4002. } 4003. if (count || size) { 4004. *total_count += count; 4005. *total_size += size; 4006. Strcpy(hdrbuf, "object type names, text"); 4007. Sprintf(buf, template, hdrbuf, count, size); 4008. putstr(win, 0, buf); 4009. } 4010. } 4011. 4012. /* 4013. * Display memory usage of all monsters and objects on the level. 4014. */ 4015. static int 4016. wiz_show_stats() 4017. { 4018. char buf[BUFSZ]; 4019. winid win; 4020. long total_obj_size, total_obj_count, 4021. total_mon_size, total_mon_count, 4022. total_ovr_size, total_ovr_count, 4023. total_misc_size, total_misc_count; 4024. 4025. win = create_nhwindow(NHW_TEXT); 4026. putstr(win, 0, "Current memory statistics:"); 4027. 4028. total_obj_count = total_obj_size = 0L; 4029. putstr(win, 0, stats_hdr); 4030. Sprintf(buf, " Objects, base size %ld", (long) sizeof (struct obj)); 4031. putstr(win, 0, buf); 4032. obj_chain(win, "invent", invent, TRUE, &total_obj_count, &total_obj_size); 4033. obj_chain(win, "fobj", fobj, TRUE, &total_obj_count, &total_obj_size); 4034. obj_chain(win, "buried", level.buriedobjlist, FALSE, 4035. &total_obj_count, &total_obj_size); 4036. obj_chain(win, "migrating obj", migrating_objs, FALSE, 4037. &total_obj_count, &total_obj_size); 4038. obj_chain(win, "billobjs", billobjs, FALSE, 4039. &total_obj_count, &total_obj_size); 4040. mon_invent_chain(win, "minvent", fmon, &total_obj_count, &total_obj_size); 4041. mon_invent_chain(win, "migrating minvent", migrating_mons, 4042. &total_obj_count, &total_obj_size); 4043. contained_stats(win, "contained", &total_obj_count, &total_obj_size); 4044. putstr(win, 0, stats_sep); 4045. Sprintf(buf, template, " Obj total", total_obj_count, total_obj_size); 4046. putstr(win, 0, buf); 4047. 4048. total_mon_count = total_mon_size = 0L; 4049. putstr(win, 0, ""); 4050. Sprintf(buf, " Monsters, base size %ld", (long) sizeof (struct monst)); 4051. putstr(win, 0, buf); 4052. mon_chain(win, "fmon", fmon, TRUE, &total_mon_count, &total_mon_size); 4053. mon_chain(win, "migrating", migrating_mons, FALSE, 4054. &total_mon_count, &total_mon_size); 4055. /* 'mydogs' is only valid during level change or end of game disclosure, 4056. but conceivably we've been called from within debugger at such time */ 4057. if (mydogs) /* monsters accompanying hero */ 4058. mon_chain(win, "mydogs", mydogs, FALSE, 4059. &total_mon_count, &total_mon_size); 4060. putstr(win, 0, stats_sep); 4061. Sprintf(buf, template, " Mon total", total_mon_count, total_mon_size); 4062. putstr(win, 0, buf); 4063. 4064. total_ovr_count = total_ovr_size = 0L; 4065. putstr(win, 0, ""); 4066. putstr(win, 0, " Overview"); 4067. overview_stats(win, template, &total_ovr_count, &total_ovr_size); 4068. putstr(win, 0, stats_sep); 4069. Sprintf(buf, template, " Over total", total_ovr_count, total_ovr_size); 4070. putstr(win, 0, buf); 4071. 4072. total_misc_count = total_misc_size = 0L; 4073. putstr(win, 0, ""); 4074. putstr(win, 0, " Miscellaneous"); 4075. misc_stats(win, &total_misc_count, &total_misc_size); 4076. putstr(win, 0, stats_sep); 4077. Sprintf(buf, template, " Misc total", total_misc_count, total_misc_size); 4078. putstr(win, 0, buf); 4079. 4080. putstr(win, 0, ""); 4081. putstr(win, 0, stats_sep); 4082. Sprintf(buf, template, " Grand total", 4083. (total_obj_count + total_mon_count 4084. + total_ovr_count + total_misc_count), 4085. (total_obj_size + total_mon_size 4086. + total_ovr_size + total_misc_size)); 4087. putstr(win, 0, buf); 4088. 4089. #if defined(__BORLANDC__) && !defined(_WIN32) 4090. show_borlandc_stats(win); 4091. #endif 4092. 4093. display_nhwindow(win, FALSE); 4094. destroy_nhwindow(win); 4095. return 0; 4096. } 4097. 4098. void 4099. sanity_check() 4100. { 4101. obj_sanity_check(); 4102. timer_sanity_check(); 4103. mon_sanity_check(); 4104. light_sources_sanity_check(); 4105. bc_sanity_check(); 4106. } 4107. 4108. #ifdef DEBUG_MIGRATING_MONS 4109. static int 4110. wiz_migrate_mons() 4111. { 4112. int mcount = 0; 4113. char inbuf[BUFSZ] = DUMMY; 4114. struct permonst *ptr; 4115. struct monst *mtmp; 4116. d_level tolevel; 4117. 4118. getlin("How many random monsters to migrate? [0]", inbuf); 4119. if (*inbuf == '\033') 4120. return 0; 4121. mcount = atoi(inbuf); 4122. if (mcount < 0 || mcount > (COLNO * ROWNO) || Is_botlevel(&u.uz)) 4123. return 0; 4124. while (mcount > 0) { 4125. if (Is_stronghold(&u.uz)) 4126. assign_level(&tolevel, &valley_level); 4127. else 4128. get_level(&tolevel, depth(&u.uz) + 1); 4129. ptr = rndmonst(); 4130. mtmp = makemon(ptr, 0, 0, NO_MM_FLAGS); 4131. if (mtmp) 4132. migrate_to_level(mtmp, ledger_no(&tolevel), MIGR_RANDOM, 4133. (coord *) 0); 4134. mcount--; 4135. } 4136. return 0; 4137. } 4138. #endif 4139. 4140. #define unctrl(c) ((c) <= C('z') ? (0x60 | (c)) : (c)) 4141. #define unmeta(c) (0x7f & (c)) 4142. 4143. struct { 4144. int nhkf; 4145. char key; 4146. const char *name; 4147. } const spkeys_binds[] = { 4148. { NHKF_ESC, '\033', (char *) 0 }, /* no binding */ 4149. { NHKF_DOAGAIN, DOAGAIN, "repeat" }, 4150. { NHKF_REQMENU, 'm', "reqmenu" }, 4151. { NHKF_RUN, 'G', "run" }, 4152. { NHKF_RUN2, '5', "run.numpad" }, 4153. { NHKF_RUSH, 'g', "rush" }, 4154. { NHKF_FIGHT, 'F', "fight" }, 4155. { NHKF_FIGHT2, '-', "fight.numpad" }, 4156. { NHKF_NOPICKUP, 'm', "nopickup" }, 4157. { NHKF_RUN_NOPICKUP, 'M', "run.nopickup" }, 4158. { NHKF_DOINV, '0', "doinv" }, 4159. { NHKF_TRAVEL, CMD_TRAVEL, (char *) 0 }, /* no binding */ 4160. { NHKF_CLICKLOOK, CMD_CLICKLOOK, (char *) 0 }, /* no binding */ 4161. { NHKF_REDRAW, C('r'), "redraw" }, 4162. { NHKF_REDRAW2, C('l'), "redraw.numpad" }, 4163. { NHKF_GETDIR_SELF, '.', "getdir.self" }, 4164. { NHKF_GETDIR_SELF2, 's', "getdir.self2" }, 4165. { NHKF_GETDIR_HELP, '?', "getdir.help" }, 4166. { NHKF_COUNT, 'n', "count" }, 4167. { NHKF_GETPOS_SELF, '@', "getpos.self" }, 4168. { NHKF_GETPOS_PICK, '.', "getpos.pick" }, 4169. { NHKF_GETPOS_PICK_Q, ',', "getpos.pick.quick" }, 4170. { NHKF_GETPOS_PICK_O, ';', "getpos.pick.once" }, 4171. { NHKF_GETPOS_PICK_V, ':', "getpos.pick.verbose" }, 4172. { NHKF_GETPOS_SHOWVALID, '$', "getpos.valid" }, 4173. { NHKF_GETPOS_AUTODESC, '#', "getpos.autodescribe" }, 4174. { NHKF_GETPOS_MON_NEXT, 'm', "getpos.mon.next" }, 4175. { NHKF_GETPOS_MON_PREV, 'M', "getpos.mon.prev" }, 4176. { NHKF_GETPOS_OBJ_NEXT, 'o', "getpos.obj.next" }, 4177. { NHKF_GETPOS_OBJ_PREV, 'O', "getpos.obj.prev" }, 4178. { NHKF_GETPOS_DOOR_NEXT, 'd', "getpos.door.next" }, 4179. { NHKF_GETPOS_DOOR_PREV, 'D', "getpos.door.prev" }, 4180. { NHKF_GETPOS_UNEX_NEXT, 'x', "getpos.unexplored.next" }, 4181. { NHKF_GETPOS_UNEX_PREV, 'X', "getpos.unexplored.prev" }, 4182. { NHKF_GETPOS_VALID_NEXT, 'z', "getpos.valid.next" }, 4183. { NHKF_GETPOS_VALID_PREV, 'Z', "getpos.valid.prev" }, 4184. { NHKF_GETPOS_INTERESTING_NEXT, 'a', "getpos.all.next" }, 4185. { NHKF_GETPOS_INTERESTING_PREV, 'A', "getpos.all.prev" }, 4186. { NHKF_GETPOS_HELP, '?', "getpos.help" }, 4187. { NHKF_GETPOS_LIMITVIEW, '"', "getpos.filter" }, 4188. { NHKF_GETPOS_MOVESKIP, '*', "getpos.moveskip" }, 4189. { NHKF_GETPOS_MENU, '!', "getpos.menu" } 4190. }; 4191. 4192. boolean 4193. bind_specialkey(key, command) 4194. uchar key; 4195. const char *command; 4196. { 4197. int i; 4198. for (i = 0; i < SIZE(spkeys_binds); i++) { 4199. if (!spkeys_binds[i].name || strcmp(command, spkeys_binds[i].name)) 4200. continue; 4201. Cmd.spkeys[spkeys_binds[i].nhkf] = key; 4202. return TRUE; 4203. } 4204. return FALSE; 4205. } 4206. 4207. /* returns a one-byte character from the text (it may massacre the txt 4208. * buffer) */ 4209. char 4210. txt2key(txt) 4211. char *txt; 4212. { 4213. txt = trimspaces(txt); 4214. if (!*txt) 4215. return '\0'; 4216. 4217. /* simple character */ 4218. if (!txt[1]) 4219. return txt[0]; 4220. 4221. /* a few special entries */ 4222. if (!strcmp(txt, "<enter>")) 4223. return '\n'; 4224. if (!strcmp(txt, "<space>")) 4225. return ' '; 4226. if (!strcmp(txt, "<esc>")) 4227. return '\033'; 4228. 4229. /* control and meta keys */ 4230. switch (*txt) { 4231. case 'm': /* can be mx, Mx, m-x, M-x */ 4232. case 'M': 4233. txt++; 4234. if (*txt == '-' && txt[1]) 4235. txt++; 4236. if (txt[1]) 4237. return '\0'; 4238. return M(*txt); 4239. case 'c': /* can be cx, Cx, ^x, c-x, C-x, ^-x */ 4240. case 'C': 4241. case '^': 4242. txt++; 4243. if (*txt == '-' && txt[1]) 4244. txt++; 4245. if (txt[1]) 4246. return '\0'; 4247. return C(*txt); 4248. } 4249. 4250. /* ascii codes: must be three-digit decimal */ 4251. if (*txt >= '0' && *txt <= '9') { 4252. uchar key = 0; 4253. int i; 4254. 4255. for (i = 0; i < 3; i++) { 4256. if (txt[i] < '0' || txt[i] > '9') 4257. return '\0'; 4258. key = 10 * key + txt[i] - '0'; 4259. } 4260. return key; 4261. } 4262. 4263. return '\0'; 4264. } 4265. 4266. /* returns the text for a one-byte encoding; 4267. * must be shorter than a tab for proper formatting */ 4268. char * 4269. key2txt(c, txt) 4270. uchar c; 4271. char *txt; /* sufficiently long buffer */ 4272. { 4273. /* should probably switch to "SPC", "ESC", "RET" 4274. since nethack's documentation uses ESC for <escape> */ 4275. if (c == ' ') 4276. Sprintf(txt, "<space>"); 4277. else if (c == '\033') 4278. Sprintf(txt, "<esc>"); 4279. else if (c == '\n') 4280. Sprintf(txt, "<enter>"); 4281. else if (c == '\177') 4282. Sprintf(txt, ""); /* "<delete>" won't fit */4283. else 4284. Strcpy(txt, visctrl((char) c)); 4285. return txt; 4286. } 4287. 4288. 4289. void 4290. parseautocomplete(autocomplete, condition) 4291. char *autocomplete; 4292. boolean condition; 4293. { 4294. struct ext_func_tab *efp; 4295. register char *autoc; 4296. 4297. /* break off first autocomplete from the rest; parse the rest */ 4298. if ((autoc = index(autocomplete, ',')) != 0 4299. || (autoc = index(autocomplete, ':')) != 0) { 4300. *autoc++ = '\0'; 4301. parseautocomplete(autoc, condition); 4302. } 4303. 4304. /* strip leading and trailing white space */ 4305. autocomplete = trimspaces(autocomplete); 4306. 4307. if (!*autocomplete) 4308. return; 4309. 4310. /* take off negation */ 4311. if (*autocomplete == '!') { 4312. /* unlike most options, a leading "no" might actually be a part of 4313. * the extended command. Thus you have to use ! */ 4314. autocomplete++; 4315. autocomplete = trimspaces(autocomplete); 4316. condition = !condition; 4317. } 4318. 4319. /* find and modify the extended command */ 4320. for (efp = extcmdlist; efp->ef_txt; efp++) { 4321. if (!strcmp(autocomplete, efp->ef_txt)) { 4322. if (condition) 4323. efp->flags |= AUTOCOMPLETE; 4324. else 4325. efp->flags &= ~AUTOCOMPLETE; 4326. return; 4327. } 4328. } 4329. 4330. /* not a real extended command */ 4331. raw_printf("Bad autocomplete: invalid extended command '%s'.", 4332. autocomplete); 4333. wait_synch(); 4334. } 4335. 4336. /* called at startup and after number_pad is twiddled */ 4337. void 4338. reset_commands(initial) 4339. boolean initial; 4340. { 4341. static const char sdir[] = "hykulnjb><", 4342. sdir_swap_yz[] = "hzkulnjb><", 4343. ndir[] = "47896321><", 4344. ndir_phone_layout[] = "41236987><"; 4345. static const int ylist[] = { 4346. 'y', 'Y', C('y'), M('y'), M('Y'), M(C('y')) 4347. }; 4348. static struct ext_func_tab *back_dir_cmd[8]; 4349. const struct ext_func_tab *cmdtmp; 4350. boolean flagtemp; 4351. int c, i, updated = 0; 4352. static boolean backed_dir_cmd = FALSE; 4353. 4354. if (initial) { 4355. updated = 1; 4356. Cmd.num_pad = FALSE; 4357. Cmd.pcHack_compat = Cmd.phone_layout = Cmd.swap_yz = FALSE; 4358. for (i = 0; i < SIZE(spkeys_binds); i++) 4359. Cmd.spkeys[spkeys_binds[i].nhkf] = spkeys_binds[i].key; 4360. commands_init(); 4361. } else { 4362. 4363. if (backed_dir_cmd) { 4364. for (i = 0; i < 8; i++) { 4365. Cmd.commands[(uchar) Cmd.dirchars[i]] = back_dir_cmd[i]; 4366. } 4367. } 4368. 4369. /* basic num_pad */ 4370. flagtemp = iflags.num_pad; 4371. if (flagtemp != Cmd.num_pad) { 4372. Cmd.num_pad = flagtemp; 4373. ++updated; 4374. } 4375. /* swap_yz mode (only applicable for !num_pad); intended for 4376. QWERTZ keyboard used in Central Europe, particularly Germany */ 4377. flagtemp = (iflags.num_pad_mode & 1) ? !Cmd.num_pad : FALSE; 4378. if (flagtemp != Cmd.swap_yz) { 4379. Cmd.swap_yz = flagtemp; 4380. ++updated; 4381. /* Cmd.swap_yz has been toggled; 4382. perform the swap (or reverse previous one) */ 4383. for (i = 0; i < SIZE(ylist); i++) { 4384. c = ylist[i] & 0xff; 4385. cmdtmp = Cmd.commands[c]; /* tmp = [y] */ 4386. Cmd.commands[c] = Cmd.commands[c + 1]; /* [y] = [z] */ 4387. Cmd.commands[c + 1] = cmdtmp; /* [z] = tmp */ 4388. } 4389. } 4390. /* MSDOS compatibility mode (only applicable for num_pad) */ 4391. flagtemp = (iflags.num_pad_mode & 1) ? Cmd.num_pad : FALSE; 4392. if (flagtemp != Cmd.pcHack_compat) { 4393. Cmd.pcHack_compat = flagtemp; 4394. ++updated; 4395. /* pcHack_compat has been toggled */ 4396. c = M('5') & 0xff; 4397. cmdtmp = Cmd.commands['5']; 4398. Cmd.commands['5'] = Cmd.commands[c]; 4399. Cmd.commands[c] = cmdtmp; 4400. c = M('0') & 0xff; 4401. Cmd.commands[c] = Cmd.pcHack_compat ? Cmd.commands['I'] : 0; 4402. } 4403. /* phone keypad layout (only applicable for num_pad) */ 4404. flagtemp = (iflags.num_pad_mode & 2) ? Cmd.num_pad : FALSE; 4405. if (flagtemp != Cmd.phone_layout) { 4406. Cmd.phone_layout = flagtemp; 4407. ++updated; 4408. /* phone_layout has been toggled */ 4409. for (i = 0; i < 3; i++) { 4410. c = '1' + i; /* 1,2,3 <-> 7,8,9 */ 4411. cmdtmp = Cmd.commands[c]; /* tmp = [1] */ 4412. Cmd.commands[c] = Cmd.commands[c + 6]; /* [1] = [7] */ 4413. Cmd.commands[c + 6] = cmdtmp; /* [7] = tmp */ 4414. c = (M('1') & 0xff) + i; /* M-1,M-2,M-3 <-> M-7,M-8,M-9 */ 4415. cmdtmp = Cmd.commands[c]; /* tmp = [M-1] */ 4416. Cmd.commands[c] = Cmd.commands[c + 6]; /* [M-1] = [M-7] */ 4417. Cmd.commands[c + 6] = cmdtmp; /* [M-7] = tmp */ 4418. } 4419. } 4420. } /*?initial*/ 4421. 4422. if (updated) 4423. Cmd.serialno++; 4424. Cmd.dirchars = !Cmd.num_pad 4425. ? (!Cmd.swap_yz ? sdir : sdir_swap_yz) 4426. : (!Cmd.phone_layout ? ndir : ndir_phone_layout); 4427. Cmd.alphadirchars = !Cmd.num_pad ? Cmd.dirchars : sdir; 4428. 4429. Cmd.move_W = Cmd.dirchars[0]; 4430. Cmd.move_NW = Cmd.dirchars[1]; 4431. Cmd.move_N = Cmd.dirchars[2]; 4432. Cmd.move_NE = Cmd.dirchars[3]; 4433. Cmd.move_E = Cmd.dirchars[4]; 4434. Cmd.move_SE = Cmd.dirchars[5]; 4435. Cmd.move_S = Cmd.dirchars[6]; 4436. Cmd.move_SW = Cmd.dirchars[7]; 4437. 4438. if (!initial) { 4439. for (i = 0; i < 8; i++) { 4440. back_dir_cmd[i] = 4441. (struct ext_func_tab *) Cmd.commands[(uchar) Cmd.dirchars[i]]; 4442. Cmd.commands[(uchar) Cmd.dirchars[i]] = (struct ext_func_tab *) 0; 4443. } 4444. backed_dir_cmd = TRUE; 4445. for (i = 0; i < 8; i++) 4446. (void) bind_key(Cmd.dirchars[i], "nothing"); 4447. } 4448. } 4449. 4450. /* non-movement commands which accept 'm' prefix to request menu operation */ 4451. STATIC_OVL boolean 4452. accept_menu_prefix(cmd_func) 4453. int NDECL((*cmd_func)); 4454. { 4455. if (cmd_func == dopickup || cmd_func == dotip 4456. /* eat, #offer, and apply tinning-kit all use floorfood() to pick 4457. an item on floor or in invent; 'm' skips picking from floor 4458. (ie, inventory only) rather than request use of menu operation */ 4459. || cmd_func == doeat || cmd_func == dosacrifice || cmd_func == doapply 4460. /* 'm' for removing saddle from adjacent monster without checking 4461. for containers at <u.ux,u.uy> */ 4462. || cmd_func == doloot 4463. /* travel: pop up a menu of interesting targets in view */ 4464. || cmd_func == dotravel 4465. /* wizard mode ^V and ^T */ 4466. || cmd_func == wiz_level_tele || cmd_func == dotelecmd 4467. /* 'm' prefix allowed for some extended commands */ 4468. || cmd_func == doextcmd || cmd_func == doextlist) 4469. return TRUE; 4470. return FALSE; 4471. } 4472. 4473. char 4474. randomkey() 4475. { 4476. static int i = 0; 4477. char c; 4478. 4479. switch (rn2(12)) { 4480. default: c = '\033'; break; 4481. case 0: c = '\n'; break; 4482. case 1: 4483. case 2: 4484. case 3: 4485. case 4: c = (char)(' ' + rn2((int)('~' - ' '))); break; 4486. case 5: c = '\t'; break; 4487. case 6: c = (char)('a' + rn2((int)('z' - 'a'))); break; 4488. case 7: c = (char)('A' + rn2((int)('Z' - 'A'))); break; 4489. case 8: c = extcmdlist[(i++) % SIZE(extcmdlist)].key; break; 4490. case 9: c = '#'; break; 4491. } 4492. 4493. return c; 4494. } 4495. 4496. void 4497. random_response(buf, sz) 4498. char *buf; 4499. int sz; 4500. { 4501. char c; 4502. int count = 0; 4503. 4504. for (;;) { 4505. c = randomkey(); 4506. if (c == '\n') 4507. break; 4508. if (c == '\033') { 4509. count = 0; 4510. break; 4511. } 4512. if (count < sz - 1) 4513. buf[count++] = c; 4514. } 4515. buf[count] = '\0'; 4516. } 4517. 4518. int 4519. rnd_extcmd_idx(VOID_ARGS) 4520. { 4521. return rn2(extcmdlist_length + 1) - 1; 4522. } 4523. 4524. int 4525. ch2spkeys(c, start, end) 4526. char c; 4527. int start,end; 4528. { 4529. int i; 4530. 4531. for (i = start; i <= end; i++) 4532. if (Cmd.spkeys[i] == c) 4533. return i; 4534. return NHKF_ESC; 4535. } 4536. 4537. void 4538. rhack(cmd) 4539. register char *cmd; 4540. { 4541. int spkey; 4542. boolean prefix_seen, bad_command, 4543. firsttime = (cmd == 0); 4544. 4545. iflags.menu_requested = FALSE; 4546. #ifdef SAFERHANGUP 4547. if (program_state.done_hup) 4548. end_of_input(); 4549. #endif 4550. if (firsttime) { 4551. context.nopick = 0; 4552. cmd = parse(); 4553. } 4554. if (*cmd == Cmd.spkeys[NHKF_ESC]) { 4555. context.move = FALSE; 4556. return; 4557. } 4558. if (*cmd == DOAGAIN && !in_doagain && saveq[0]) { 4559. in_doagain = TRUE; 4560. stail = 0; 4561. rhack((char *) 0); /* read and execute command */ 4562. in_doagain = FALSE; 4563. return; 4564. } 4565. /* Special case of *cmd == ' ' handled better below */ 4566. if (!*cmd || *cmd == (char) 0377) { 4567. nhbell(); 4568. context.move = FALSE; 4569. return; /* probably we just had an interrupt */ 4570. } 4571. 4572. /* handle most movement commands */ 4573. prefix_seen = FALSE; 4574. context.travel = context.travel1 = 0; 4575. spkey = ch2spkeys(*cmd, NHKF_RUN, NHKF_CLICKLOOK); 4576. 4577. switch (spkey) { 4578. case NHKF_RUSH: 4579. if (movecmd(cmd[1])) { 4580. context.run = 2; 4581. domove_attempting |= DOMOVE_RUSH; 4582. } else 4583. prefix_seen = TRUE; 4584. break; 4585. case NHKF_RUN2: 4586. if (!Cmd.num_pad) 4587. break; 4588. /*FALLTHRU*/ 4589. case NHKF_RUN: 4590. if (movecmd(lowc(cmd[1]))) { 4591. context.run = 3; 4592. domove_attempting |= DOMOVE_RUSH; 4593. } else 4594. prefix_seen = TRUE; 4595. break; 4596. case NHKF_FIGHT2: 4597. if (!Cmd.num_pad) 4598. break; 4599. /*FALLTHRU*/ 4600. /* Effects of movement commands and invisible monsters: 4601. * m: always move onto space (even if 'I' remembered) 4602. * F: always attack space (even if 'I' not remembered) 4603. * normal movement: attack if 'I', move otherwise. 4604. */ 4605. case NHKF_FIGHT: 4606. if (movecmd(cmd[1])) { 4607. context.forcefight = 1; 4608. domove_attempting |= DOMOVE_WALK; 4609. } else 4610. prefix_seen = TRUE; 4611. break; 4612. case NHKF_NOPICKUP: 4613. if (movecmd(cmd[1]) || u.dz) { 4614. context.run = 0; 4615. context.nopick = 1; 4616. if (!u.dz) 4617. domove_attempting |= DOMOVE_WALK; 4618. else 4619. cmd[0] = cmd[1]; /* "m<" or "m>" */ 4620. } else 4621. prefix_seen = TRUE; 4622. break; 4623. case NHKF_RUN_NOPICKUP: 4624. if (movecmd(lowc(cmd[1]))) { 4625. context.run = 1; 4626. context.nopick = 1; 4627. domove_attempting |= DOMOVE_RUSH; 4628. } else 4629. prefix_seen = TRUE; 4630. break; 4631. case NHKF_DOINV: 4632. if (!Cmd.num_pad) 4633. break; 4634. (void) ddoinv(); /* a convenience borrowed from the PC */ 4635. context.move = FALSE; 4636. multi = 0; 4637. return; 4638. case NHKF_CLICKLOOK: 4639. if (iflags.clicklook) { 4640. context.move = FALSE; 4641. do_look(2, &clicklook_cc); 4642. } 4643. return; 4644. case NHKF_TRAVEL: 4645. if (flags.travelcmd) { 4646. context.travel = 1; 4647. context.travel1 = 1; 4648. context.run = 8; 4649. context.nopick = 1; 4650. domove_attempting |= DOMOVE_RUSH; 4651. break; 4652. } 4653. /*FALLTHRU*/ 4654. default: 4655. if (movecmd(*cmd)) { /* ordinary movement */ 4656. context.run = 0; /* only matters here if it was 8 */ 4657. domove_attempting |= DOMOVE_WALK; 4658. } else if (movecmd(Cmd.num_pad ? unmeta(*cmd) : lowc(*cmd))) { 4659. context.run = 1; 4660. domove_attempting |= DOMOVE_RUSH; 4661. } else if (movecmd(unctrl(*cmd))) { 4662. context.run = 3; 4663. domove_attempting |= DOMOVE_RUSH; 4664. } 4665. break; 4666. } 4667. 4668. /* some special prefix handling */ 4669. /* overload 'm' prefix to mean "request a menu" */ 4670. if (prefix_seen && cmd[0] == Cmd.spkeys[NHKF_REQMENU]) { 4671. /* (for func_tab cast, see below) */ 4672. const struct ext_func_tab *ft = Cmd.commands[cmd[1] & 0xff]; 4673. int NDECL((*func)) = ft ? ((struct ext_func_tab *) ft)->ef_funct : 0; 4674. 4675. if (func && accept_menu_prefix(func)) { 4676. iflags.menu_requested = TRUE; 4677. ++cmd; 4678. } 4679. } 4680. 4681. if (((domove_attempting & (DOMOVE_RUSH | DOMOVE_WALK)) != 0L) 4682. && !context.travel && !dxdy_moveok()) { 4683. /* trying to move diagonally as a grid bug; 4684. this used to be treated by movecmd() as not being 4685. a movement attempt, but that didn't provide for any 4686. feedback and led to strangeness if the key pressed 4687. ('u' in particular) was overloaded for num_pad use */ 4688. You_cant("get there from here..."); 4689. context.run = 0; 4690. context.nopick = context.forcefight = FALSE; 4691. context.move = context.mv = FALSE; 4692. multi = 0; 4693. return; 4694. } 4695. 4696. if ((domove_attempting & DOMOVE_WALK) != 0L) { 4697. if (multi) 4698. context.mv = TRUE; 4699. domove(); 4700. context.forcefight = 0; 4701. return; 4702. } else if ((domove_attempting & DOMOVE_RUSH) != 0L) { 4703. if (firsttime) { 4704. if (!multi) 4705. multi = max(COLNO, ROWNO); 4706. u.last_str_turn = 0; 4707. } 4708. context.mv = TRUE; 4709. domove(); 4710. return; 4711. } else if (prefix_seen && cmd[1] == Cmd.spkeys[NHKF_ESC]) { 4712. /* <prefix><escape> */ 4713. /* don't report "unknown command" for change of heart... */ 4714. bad_command = FALSE; 4715. } else if (*cmd == ' ' && !flags.rest_on_space) { 4716. bad_command = TRUE; /* skip cmdlist[] loop */ 4717. 4718. /* handle all other commands */ 4719. } else { 4720. register const struct ext_func_tab *tlist; 4721. int res, NDECL((*func)); 4722. 4723. /* current - use *cmd to directly index cmdlist array */ 4724. if ((tlist = Cmd.commands[*cmd & 0xff]) != 0) { 4725. if (!wizard && (tlist->flags & WIZMODECMD)) { 4726. You_cant("do that!"); 4727. res = 0; 4728. } else if (u.uburied && !(tlist->flags & IFBURIED)) { 4729. You_cant("do that while you are buried!"); 4730. res = 0; 4731. } else { 4732. /* we discard 'const' because some compilers seem to have 4733. trouble with the pointer passed to set_occupation() */ 4734. func = ((struct ext_func_tab *) tlist)->ef_funct; 4735. if (tlist->f_text && !occupation && multi) 4736. set_occupation(func, tlist->f_text, multi); 4737. res = (*func)(); /* perform the command */ 4738. } 4739. if (!res) { 4740. context.move = FALSE; 4741. multi = 0; 4742. } 4743. return; 4744. } 4745. /* if we reach here, cmd wasn't found in cmdlist[] */ 4746. bad_command = TRUE; 4747. } 4748. 4749. if (bad_command) { 4750. char expcmd[20]; /* we expect 'cmd' to point to 1 or 2 chars */ 4751. char c, c1 = cmd[1]; 4752. 4753. expcmd[0] = '\0'; 4754. while ((c = *cmd++) != '\0') 4755. Strcat(expcmd, visctrl(c)); /* add 1..4 chars plus terminator */ 4756. 4757. if (!prefix_seen || !help_dir(c1, spkey, "Invalid direction key!")) 4758. Norep("Unknown command '%s'.", expcmd); 4759. } 4760. /* didn't move */ 4761. context.move = FALSE; 4762. multi = 0; 4763. return; 4764. } 4765. 4766. /* convert an x,y pair into a direction code */ 4767. int 4768. xytod(x, y) 4769. schar x, y; 4770. { 4771. register int dd; 4772. 4773. for (dd = 0; dd < 8; dd++) 4774. if (x == xdir[dd] && y == ydir[dd]) 4775. return dd; 4776. return -1; 4777. } 4778. 4779. /* convert a direction code into an x,y pair */ 4780. void 4781. dtoxy(cc, dd) 4782. coord *cc; 4783. register int dd; 4784. { 4785. cc->x = xdir[dd]; 4786. cc->y = ydir[dd]; 4787. return; 4788. } 4789. 4790. /* also sets u.dz, but returns false for <> */ 4791. int 4792. movecmd(sym) 4793. char sym; 4794. { 4795. register const char *dp = index(Cmd.dirchars, sym); 4796. 4797. u.dz = 0; 4798. if (!dp || !*dp) 4799. return 0; 4800. u.dx = xdir[dp - Cmd.dirchars]; 4801. u.dy = ydir[dp - Cmd.dirchars]; 4802. u.dz = zdir[dp - Cmd.dirchars]; 4803. #if 0 /* now handled elsewhere */ 4804. if (u.dx && u.dy && NODIAG(u.umonnum)) { 4805. u.dx = u.dy = 0; 4806. return 0; 4807. } 4808. #endif 4809. return !u.dz; 4810. } 4811. 4812. /* grid bug handling which used to be in movecmd() */ 4813. int 4814. dxdy_moveok() 4815. { 4816. if (u.dx && u.dy && NODIAG(u.umonnum)) 4817. u.dx = u.dy = 0; 4818. return u.dx || u.dy; 4819. } 4820. 4821. /* decide whether a character (user input keystroke) requests screen repaint */ 4822. boolean 4823. redraw_cmd(c) 4824. char c; 4825. { 4826. return (boolean) (c == Cmd.spkeys[NHKF_REDRAW] 4827. || (Cmd.num_pad && c == Cmd.spkeys[NHKF_REDRAW2])); 4828. } 4829. 4830. boolean 4831. prefix_cmd(c) 4832. char c; 4833. { 4834. return (c == Cmd.spkeys[NHKF_RUSH] 4835. || c == Cmd.spkeys[NHKF_RUN] 4836. || c == Cmd.spkeys[NHKF_NOPICKUP] 4837. || c == Cmd.spkeys[NHKF_RUN_NOPICKUP] 4838. || c == Cmd.spkeys[NHKF_FIGHT] 4839. || (Cmd.num_pad && (c == Cmd.spkeys[NHKF_RUN2] 4840. || c == Cmd.spkeys[NHKF_FIGHT2]))); 4841. } 4842. 4843. /* 4844. * uses getdir() but unlike getdir() it specifically 4845. * produces coordinates using the direction from getdir() 4846. * and verifies that those coordinates are ok. 4847. * 4848. * If the call to getdir() returns 0, Never_mind is displayed. 4849. * If the resulting coordinates are not okay, emsg is displayed. 4850. * 4851. * Returns non-zero if coordinates in cc are valid. 4852. */ 4853. int 4854. get_adjacent_loc(prompt, emsg, x, y, cc) 4855. const char *prompt, *emsg; 4856. xchar x, y; 4857. coord *cc; 4858. { 4859. xchar new_x, new_y; 4860. if (!getdir(prompt)) { 4861. pline1(Never_mind); 4862. return 0; 4863. } 4864. new_x = x + u.dx; 4865. new_y = y + u.dy; 4866. if (cc && isok(new_x, new_y)) { 4867. cc->x = new_x; 4868. cc->y = new_y; 4869. } else { 4870. if (emsg) 4871. pline1(emsg); 4872. return 0; 4873. } 4874. return 1; 4875. } 4876. 4877. int 4878. getdir(s) 4879. const char *s; 4880. { 4881. char dirsym; 4882. int is_mov; 4883. 4884. retry: 4885. if (in_doagain || *readchar_queue) 4886. dirsym = readchar(); 4887. else 4888. dirsym = yn_function((s && *s != '^') ? s : "In what direction?", 4889. (char *) 0, '\0'); 4890. /* remove the prompt string so caller won't have to */ 4891. clear_nhwindow(WIN_MESSAGE); 4892. 4893. if (redraw_cmd(dirsym)) { /* ^R */ 4894. docrt(); /* redraw */ 4895. goto retry; 4896. } 4897. savech(dirsym); 4898. 4899. if (dirsym == Cmd.spkeys[NHKF_GETDIR_SELF] 4900. || dirsym == Cmd.spkeys[NHKF_GETDIR_SELF2]) { 4901. u.dx = u.dy = u.dz = 0; 4902. } else if (!(is_mov = movecmd(dirsym)) && !u.dz) { 4903. boolean did_help = FALSE, help_requested; 4904. 4905. if (!index(quitchars, dirsym)) { 4906. help_requested = (dirsym == Cmd.spkeys[NHKF_GETDIR_HELP]); 4907. if (help_requested || iflags.cmdassist) { 4908. did_help = help_dir((s && *s == '^') ? dirsym : '\0', 4909. NHKF_ESC, 4910. help_requested ? (const char *) 0 4911. : "Invalid direction key!"); 4912. if (help_requested) 4913. goto retry; 4914. } 4915. if (!did_help) 4916. pline("What a strange direction!"); 4917. } 4918. return 0; 4919. } else if (is_mov && !dxdy_moveok()) { 4920. You_cant("orient yourself that direction."); 4921. return 0; 4922. } 4923. if (!u.dz && (Stunned || (Confusion && !rn2(5)))) 4924. confdir(); 4925. return 1; 4926. } 4927. 4928. STATIC_OVL void 4929. show_direction_keys(win, centerchar, nodiag) 4930. winid win; /* should specify a window which is using a fixed-width font... */ 4931. char centerchar; /* '.' or '@' or ' ' */ 4932. boolean nodiag; 4933. { 4934. char buf[BUFSZ]; 4935. 4936. if (!centerchar) 4937. centerchar = ' '; 4938. 4939. if (nodiag) { 4940. Sprintf(buf, " %c ", Cmd.move_N); 4941. putstr(win, 0, buf); 4942. putstr(win, 0, " | "); 4943. Sprintf(buf, " %c- %c -%c", 4944. Cmd.move_W, centerchar, Cmd.move_E); 4945. putstr(win, 0, buf); 4946. putstr(win, 0, " | "); 4947. Sprintf(buf, " %c ", Cmd.move_S); 4948. putstr(win, 0, buf); 4949. } else { 4950. Sprintf(buf, " %c %c %c", 4951. Cmd.move_NW, Cmd.move_N, Cmd.move_NE); 4952. putstr(win, 0, buf); 4953. putstr(win, 0, " \\ | / "); 4954. Sprintf(buf, " %c- %c -%c", 4955. Cmd.move_W, centerchar, Cmd.move_E); 4956. putstr(win, 0, buf); 4957. putstr(win, 0, " / | \\ "); 4958. Sprintf(buf, " %c %c %c", 4959. Cmd.move_SW, Cmd.move_S, Cmd.move_SE); 4960. putstr(win, 0, buf); 4961. }; 4962. } 4963. 4964. /* explain choices if player has asked for getdir() help or has given 4965. an invalid direction after a prefix key ('F', 'g', 'm', &c), which 4966. might be bogus but could be up, down, or self when not applicable */ 4967. STATIC_OVL boolean 4968. help_dir(sym, spkey, msg) 4969. char sym; 4970. int spkey; /* NHKF_ code for prefix key, if one was used, or for ESC */ 4971. const char *msg; 4972. { 4973. static const char wiz_only_list[] = "EFGIVW"; 4974. char ctrl; 4975. winid win; 4976. char buf[BUFSZ], buf2[BUFSZ], *explain; 4977. const char *dothat, *how; 4978. boolean prefixhandling, viawindow; 4979. 4980. /* NHKF_ESC indicates that player asked for help at getdir prompt */ 4981. viawindow = (spkey == NHKF_ESC || iflags.cmdassist); 4982. prefixhandling = (spkey != NHKF_ESC); 4983. /* 4984. * Handling for prefix keys that don't want special directions. 4985. * Delivered via pline if 'cmdassist' is off, or instead of the 4986. * general message if it's on. 4987. */ 4988. dothat = "do that"; 4989. how = " at"; /* for "<action> at yourself"; not used for up/down */ 4990. switch (spkey) { 4991. case NHKF_NOPICKUP: 4992. dothat = "move"; 4993. break; 4994. case NHKF_RUSH: 4995. dothat = "rush"; 4996. break; 4997. case NHKF_RUN2: 4998. if (!Cmd.num_pad) 4999. break; 5000. /*FALLTHRU*/ 5001. case NHKF_RUN: 5002. case NHKF_RUN_NOPICKUP: 5003. dothat = "run"; 5004. break; 5005. case NHKF_FIGHT2: 5006. if (!Cmd.num_pad) 5007. break; 5008. /*FALLTHRU*/ 5009. case NHKF_FIGHT: 5010. dothat = "fight"; 5011. how = ""; /* avoid "fight at yourself" */ 5012. break; 5013. default: 5014. prefixhandling = FALSE; 5015. break; 5016. } 5017. 5018. buf[0] = '\0'; 5019. /* for movement prefix followed by '.' or (numpad && 's') to mean 'self'; 5020. note: '-' for hands (inventory form of 'self') is not handled here */ 5021. if (prefixhandling 5022. && (sym == Cmd.spkeys[NHKF_GETDIR_SELF] 5023. || (Cmd.num_pad && sym == Cmd.spkeys[NHKF_GETDIR_SELF2]))) { 5024. Sprintf(buf, "You can't %s%s yourself.", dothat, how); 5025. /* for movement prefix followed by up or down */ 5026. } else if (prefixhandling && (sym == '<' || sym == '>')) { 5027. Sprintf(buf, "You can't %s %s.", dothat, 5028. /* was "upwards" and "downwards", but they're considered 5029. to be variants of canonical "upward" and "downward" */ 5030. (sym == '<') ? "upward" : "downward"); 5031. } 5032. 5033. /* if '!cmdassist', display via pline() and we're done (note: asking 5034. for help at getdir() prompt forces cmdassist for this operation) */ 5035. if (!viawindow) { 5036. if (prefixhandling) { 5037. if (!*buf) 5038. Sprintf(buf, "Invalid direction for '%s' prefix.", 5039. visctrl(Cmd.spkeys[spkey])); 5040. pline("%s", buf); 5041. return TRUE; 5042. } 5043. /* when 'cmdassist' is off and caller doesn't insist, do nothing */ 5044. return FALSE; 5045. } 5046. 5047. win = create_nhwindow(NHW_TEXT); 5048. if (!win) 5049. return FALSE; 5050. 5051. if (*buf) { 5052. /* show bad-prefix message instead of general invalid-direction one */ 5053. putstr(win, 0, buf); 5054. putstr(win, 0, ""); 5055. } else if (msg) { 5056. Sprintf(buf, "cmdassist: %s", msg); 5057. putstr(win, 0, buf); 5058. putstr(win, 0, ""); 5059. } 5060. 5061. if (!prefixhandling && (letter(sym) || sym == '[')) { 5062. /* '[': old 'cmdhelp' showed ESC as ^[ */ 5063. sym = highc(sym); /* @A-Z[ (note: letter() accepts '@') */ 5064. ctrl = (sym - 'A') + 1; /* 0-27 (note: 28-31 aren't applicable) */ 5065. if ((explain = dowhatdoes_core(ctrl, buf2)) != 0 5066. && (!index(wiz_only_list, sym) || wizard)) { 5067. Sprintf(buf, "Are you trying to use ^%c%s?", sym, 5068. index(wiz_only_list, sym) ? "" 5069. : " as specified in the Guidebook"); 5070. putstr(win, 0, buf); 5071. putstr(win, 0, ""); 5072. putstr(win, 0, explain); 5073. putstr(win, 0, ""); 5074. putstr(win, 0, 5075. "To use that command, hold down the <Ctrl> key as a shift"); 5076. Sprintf(buf, "and press the <%c> key.", sym); 5077. putstr(win, 0, buf); 5078. putstr(win, 0, ""); 5079. } 5080. } 5081. 5082. Sprintf(buf, "Valid direction keys%s%s%s are:", 5083. prefixhandling ? " to " : "", prefixhandling ? dothat : "", 5084. NODIAG(u.umonnum) ? " in your current form" : ""); 5085. putstr(win, 0, buf); 5086. show_direction_keys(win, !prefixhandling ? '.' : ' ', NODIAG(u.umonnum)); 5087. 5088. if (!prefixhandling || spkey == NHKF_NOPICKUP) { 5089. /* NOPICKUP: unlike the other prefix keys, 'm' allows up/down for 5090. stair traversal; we won't get here when "m<" or "m>" has been 5091. given but we include up and down for 'm'+invalid_direction; 5092. self is excluded as a viable direction for every prefix */ 5093. putstr(win, 0, ""); 5094. putstr(win, 0, " < up"); 5095. putstr(win, 0, " > down"); 5096. if (!prefixhandling) { 5097. int selfi = Cmd.num_pad ? NHKF_GETDIR_SELF2 : NHKF_GETDIR_SELF; 5098. 5099. Sprintf(buf, " %4s direct at yourself", 5100. visctrl(Cmd.spkeys[selfi])); 5101. putstr(win, 0, buf); 5102. } 5103. } 5104. 5105. if (msg) { 5106. /* non-null msg means that this wasn't an explicit user request */ 5107. putstr(win, 0, ""); 5108. putstr(win, 0, 5109. "(Suppress this message with !cmdassist in config file.)"); 5110. } 5111. display_nhwindow(win, FALSE); 5112. destroy_nhwindow(win); 5113. return TRUE; 5114. } 5115. 5116. void 5117. confdir() 5118. { 5119. register int x = NODIAG(u.umonnum) ? 2 * rn2(4) : rn2(8); 5120. 5121. u.dx = xdir[x]; 5122. u.dy = ydir[x]; 5123. return; 5124. } 5125. 5126. const char * 5127. directionname(dir) 5128. int dir; 5129. { 5130. static NEARDATA const char *const dirnames[] = { 5131. "west", "northwest", "north", "northeast", "east", 5132. "southeast", "south", "southwest", "down", "up", 5133. }; 5134. 5135. if (dir < 0 || dir >= SIZE(dirnames)) 5136. return "invalid"; 5137. return dirnames[dir]; 5138. } 5139. 5140. int 5141. isok(x, y) 5142. register int x, y; 5143. { 5144. /* x corresponds to curx, so x==1 is the first column. Ach. %% */ 5145. return x >= 1 && x <= COLNO - 1 && y >= 0 && y <= ROWNO - 1; 5146. } 5147. 5148. /* #herecmdmenu command */ 5149. STATIC_PTR int 5150. doherecmdmenu(VOID_ARGS) 5151. { 5152. char ch = here_cmd_menu(TRUE); 5153. 5154. return ch ? 1 : 0; 5155. } 5156. 5157. /* #therecmdmenu command, a way to test there_cmd_menu without mouse */ 5158. STATIC_PTR int 5159. dotherecmdmenu(VOID_ARGS) 5160. { 5161. char ch; 5162. 5163. if (!getdir((const char *) 0) || !isok(u.ux + u.dx, u.uy + u.dy)) 5164. return 0; 5165. 5166. if (u.dx || u.dy) 5167. ch = there_cmd_menu(TRUE, u.ux + u.dx, u.uy + u.dy); 5168. else 5169. ch = here_cmd_menu(TRUE); 5170. 5171. return ch ? 1 : 0; 5172. } 5173. 5174. STATIC_OVL void 5175. add_herecmd_menuitem(win, func, text) 5176. winid win; 5177. int NDECL((*func)); 5178. const char *text; 5179. { 5180. char ch; 5181. anything any; 5182. 5183. if ((ch = cmd_from_func(func)) != '\0') { 5184. any = zeroany; 5185. any.a_nfunc = func; 5186. add_menu(win, NO_GLYPH, &any, 0, 0, ATR_NONE, text, MENU_UNSELECTED); 5187. } 5188. } 5189. 5190. STATIC_OVL char 5191. there_cmd_menu(doit, x, y) 5192. boolean doit; 5193. int x, y; 5194. { 5195. winid win; 5196. char ch; 5197. char buf[BUFSZ]; 5198. schar typ = levl[x][y].typ; 5199. int npick, K = 0; 5200. menu_item *picks = (menu_item *) 0; 5201. struct trap *ttmp; 5202. struct monst *mtmp; 5203. 5204. win = create_nhwindow(NHW_MENU); 5205. start_menu(win); 5206. 5207. if (IS_DOOR(typ)) { 5208. boolean key_or_pick, card; 5209. int dm = levl[x][y].doormask; 5210. 5211. if ((dm & (D_CLOSED | D_LOCKED))) { 5212. add_herecmd_menuitem(win, doopen, "Open the door"), ++K; 5213. /* unfortunately there's no lknown flag for doors to 5214. remember the locked/unlocked state */ 5215. key_or_pick = (carrying(SKELETON_KEY) || carrying(LOCK_PICK)); 5216. card = (carrying(CREDIT_CARD) != 0); 5217. if (key_or_pick || card) { 5218. Sprintf(buf, "%sunlock the door", 5219. key_or_pick ? "lock or " : ""); 5220. add_herecmd_menuitem(win, doapply, upstart(buf)), ++K; 5221. } 5222. /* unfortunately there's no tknown flag for doors (or chests) 5223. to remember whether a trap had been found */ 5224. add_herecmd_menuitem(win, dountrap, 5225. "Search the door for a trap"), ++K; 5226. /* [what about #force?] */ 5227. add_herecmd_menuitem(win, dokick, "Kick the door"), ++K; 5228. } else if ((dm & D_ISOPEN)) { 5229. add_herecmd_menuitem(win, doclose, "Close the door"), ++K; 5230. } 5231. } 5232. 5233. if (typ <= SCORR) 5234. add_herecmd_menuitem(win, dosearch, "Search for secret doors"), ++K; 5235. 5236. if ((ttmp = t_at(x, y)) != 0 && ttmp->tseen) { 5237. add_herecmd_menuitem(win, doidtrap, "Examine trap"), ++K; 5238. if (ttmp->ttyp != VIBRATING_SQUARE) 5239. add_herecmd_menuitem(win, dountrap, "Attempt to disarm trap"), ++K; 5240. } 5241. 5242. mtmp = m_at(x, y); 5243. if (mtmp && !canspotmon(mtmp)) 5244. mtmp = 0; 5245. if (mtmp && which_armor(mtmp, W_SADDLE)) { 5246. char *mnam = x_monnam(mtmp, ARTICLE_THE, (char *) 0, 5247. SUPPRESS_SADDLE, FALSE); 5248. 5249. if (!u.usteed) { 5250. Sprintf(buf, "Ride %s", mnam); 5251. add_herecmd_menuitem(win, doride, buf), ++K; 5252. } 5253. Sprintf(buf, "Remove saddle from %s", mnam); 5254. add_herecmd_menuitem(win, doloot, buf), ++K; 5255. } 5256. if (mtmp && can_saddle(mtmp) && !which_armor(mtmp, W_SADDLE) 5257. && carrying(SADDLE)) { 5258. Sprintf(buf, "Put saddle on %s", mon_nam(mtmp)), ++K; 5259. add_herecmd_menuitem(win, doapply, buf); 5260. } 5261. #if 0 5262. if (mtmp || glyph_is_invisible(glyph_at(x, y))) { 5263. /* "Attack %s", mtmp ? mon_nam(mtmp) : "unseen creature" */ 5264. } else { 5265. /* "Move %s", direction */ 5266. } 5267. #endif 5268. 5269. if (K) { 5270. end_menu(win, "What do you want to do?"); 5271. npick = select_menu(win, PICK_ONE, &picks); 5272. } else { 5273. pline("No applicable actions."); 5274. npick = 0; 5275. } 5276. destroy_nhwindow(win); 5277. ch = '\0'; 5278. if (npick > 0) { 5279. int NDECL((*func)) = picks->item.a_nfunc; 5280. free((genericptr_t) picks); 5281. 5282. if (doit) { 5283. int ret = (*func)(); 5284. 5285. ch = (char) ret; 5286. } else { 5287. ch = cmd_from_func(func); 5288. } 5289. } 5290. return ch; 5291. } 5292. 5293. STATIC_OVL char 5294. here_cmd_menu(doit) 5295. boolean doit; 5296. { 5297. winid win; 5298. char ch; 5299. char buf[BUFSZ]; 5300. schar typ = levl[u.ux][u.uy].typ; 5301. int npick; 5302. menu_item *picks = (menu_item *) 0; 5303. 5304. win = create_nhwindow(NHW_MENU); 5305. start_menu(win); 5306. 5307. if (IS_FOUNTAIN(typ) || IS_SINK(typ)) { 5308. Sprintf(buf, "Drink from the %s", 5309. defsyms[IS_FOUNTAIN(typ) ? S_fountain : S_sink].explanation); 5310. add_herecmd_menuitem(win, dodrink, buf); 5311. } 5312. if (IS_FOUNTAIN(typ)) 5313. add_herecmd_menuitem(win, dodip, 5314. "Dip something into the fountain"); 5315. if (IS_THRONE(typ)) 5316. add_herecmd_menuitem(win, dosit, 5317. "Sit on the throne"); 5318. 5319. if ((u.ux == xupstair && u.uy == yupstair) 5320. || (u.ux == sstairs.sx && u.uy == sstairs.sy && sstairs.up) 5321. || (u.ux == xupladder && u.uy == yupladder)) { 5322. Sprintf(buf, "Go up the %s", 5323. (u.ux == xupladder && u.uy == yupladder) 5324. ? "ladder" : "stairs"); 5325. add_herecmd_menuitem(win, doup, buf); 5326. } 5327. if ((u.ux == xdnstair && u.uy == ydnstair) 5328. || (u.ux == sstairs.sx && u.uy == sstairs.sy && !sstairs.up) 5329. || (u.ux == xdnladder && u.uy == ydnladder)) { 5330. Sprintf(buf, "Go down the %s", 5331. (u.ux == xupladder && u.uy == yupladder) 5332. ? "ladder" : "stairs"); 5333. add_herecmd_menuitem(win, dodown, buf); 5334. } 5335. if (u.usteed) { /* another movement choice */ 5336. Sprintf(buf, "Dismount %s", 5337. x_monnam(u.usteed, ARTICLE_THE, (char *) 0, 5338. SUPPRESS_SADDLE, FALSE)); 5339. add_herecmd_menuitem(win, doride, buf); 5340. } 5341. 5342. #if 0 5343. if (Upolyd) { /* before objects */ 5344. Sprintf(buf, "Use %s special ability", 5345. s_suffix(mons[u.umonnum].mname)); 5346. add_herecmd_menuitem(win, domonability, buf); 5347. } 5348. #endif 5349. 5350. if (OBJ_AT(u.ux, u.uy)) { 5351. struct obj *otmp = level.objects[u.ux][u.uy]; 5352. 5353. Sprintf(buf, "Pick up %s", otmp->nexthere ? "items" : doname(otmp)); 5354. add_herecmd_menuitem(win, dopickup, buf); 5355. 5356. if (Is_container(otmp)) { 5357. Sprintf(buf, "Loot %s", doname(otmp)); 5358. add_herecmd_menuitem(win, doloot, buf); 5359. } 5360. if (otmp->oclass == FOOD_CLASS) { 5361. Sprintf(buf, "Eat %s", doname(otmp)); 5362. add_herecmd_menuitem(win, doeat, buf); 5363. } 5364. } 5365. 5366. if (invent) 5367. add_herecmd_menuitem(win, dodrop, "Drop items"); 5368. 5369. add_herecmd_menuitem(win, donull, "Rest one turn"); 5370. add_herecmd_menuitem(win, dosearch, "Search around you"); 5371. add_herecmd_menuitem(win, dolook, "Look at what is here"); 5372. 5373. end_menu(win, "What do you want to do?"); 5374. npick = select_menu(win, PICK_ONE, &picks); 5375. destroy_nhwindow(win); 5376. ch = '\0'; 5377. if (npick > 0) { 5378. int NDECL((*func)) = picks->item.a_nfunc; 5379. free((genericptr_t) picks); 5380. 5381. if (doit) { 5382. int ret = (*func)(); 5383. 5384. ch = (char) ret; 5385. } else { 5386. ch = cmd_from_func(func); 5387. } 5388. } 5389. return ch; 5390. } 5391. 5392. 5393. static NEARDATA int last_multi; 5394. 5395. /* 5396. * convert a MAP window position into a movecmd 5397. */ 5398. const char * 5399. click_to_cmd(x, y, mod) 5400. int x, y, mod; 5401. { 5402. int dir; 5403. static char cmd[4]; 5404. cmd[1] = 0; 5405. 5406. if (iflags.clicklook && mod == CLICK_2) { 5407. clicklook_cc.x = x; 5408. clicklook_cc.y = y; 5409. cmd[0] = Cmd.spkeys[NHKF_CLICKLOOK]; 5410. return cmd; 5411. } 5412. 5413. x -= u.ux; 5414. y -= u.uy; 5415. 5416. if (flags.travelcmd) { 5417. if (abs(x) <= 1 && abs(y) <= 1) { 5418. x = sgn(x), y = sgn(y); 5419. } else { 5420. u.tx = u.ux + x; 5421. u.ty = u.uy + y; 5422. cmd[0] = Cmd.spkeys[NHKF_TRAVEL]; 5423. return cmd; 5424. } 5425. 5426. if (x == 0 && y == 0) { 5427. if (iflags.herecmd_menu) { 5428. cmd[0] = here_cmd_menu(FALSE); 5429. return cmd; 5430. } 5431. 5432. /* here */ 5433. if (IS_FOUNTAIN(levl[u.ux][u.uy].typ) 5434. || IS_SINK(levl[u.ux][u.uy].typ)) { 5435. cmd[0] = cmd_from_func(mod == CLICK_1 ? dodrink : dodip); 5436. return cmd; 5437. } else if (IS_THRONE(levl[u.ux][u.uy].typ)) { 5438. cmd[0] = cmd_from_func(dosit); 5439. return cmd; 5440. } else if ((u.ux == xupstair && u.uy == yupstair) 5441. || (u.ux == sstairs.sx && u.uy == sstairs.sy 5442. && sstairs.up) 5443. || (u.ux == xupladder && u.uy == yupladder)) { 5444. cmd[0] = cmd_from_func(doup); 5445. return cmd; 5446. } else if ((u.ux == xdnstair && u.uy == ydnstair) 5447. || (u.ux == sstairs.sx && u.uy == sstairs.sy 5448. && !sstairs.up) 5449. || (u.ux == xdnladder && u.uy == ydnladder)) { 5450. cmd[0] = cmd_from_func(dodown); 5451. return cmd; 5452. } else if (OBJ_AT(u.ux, u.uy)) { 5453. cmd[0] = cmd_from_func(Is_container(level.objects[u.ux][u.uy]) 5454. ? doloot : dopickup); 5455. return cmd; 5456. } else { 5457. cmd[0] = cmd_from_func(donull); /* just rest */ 5458. return cmd; 5459. } 5460. } 5461. 5462. /* directional commands */ 5463. 5464. dir = xytod(x, y); 5465. 5466. if (!m_at(u.ux + x, u.uy + y) 5467. && !test_move(u.ux, u.uy, x, y, TEST_MOVE)) { 5468. cmd[1] = Cmd.dirchars[dir]; 5469. cmd[2] = '\0'; 5470. if (iflags.herecmd_menu) { 5471. cmd[0] = there_cmd_menu(FALSE, u.ux + x, u.uy + y); 5472. if (cmd[0] == '\0') 5473. cmd[1] = '\0'; 5474. return cmd; 5475. } 5476. 5477. if (IS_DOOR(levl[u.ux + x][u.uy + y].typ)) { 5478. /* slight assistance to the player: choose kick/open for them 5479. */ 5480. if (levl[u.ux + x][u.uy + y].doormask & D_LOCKED) { 5481. cmd[0] = cmd_from_func(dokick); 5482. return cmd; 5483. } 5484. if (levl[u.ux + x][u.uy + y].doormask & D_CLOSED) { 5485. cmd[0] = cmd_from_func(doopen); 5486. return cmd; 5487. } 5488. } 5489. if (levl[u.ux + x][u.uy + y].typ <= SCORR) { 5490. cmd[0] = cmd_from_func(dosearch); 5491. cmd[1] = 0; 5492. return cmd; 5493. } 5494. } 5495. } else { 5496. /* convert without using floating point, allowing sloppy clicking */ 5497. if (x > 2 * abs(y)) 5498. x = 1, y = 0; 5499. else if (y > 2 * abs(x)) 5500. x = 0, y = 1; 5501. else if (x < -2 * abs(y)) 5502. x = -1, y = 0; 5503. else if (y < -2 * abs(x)) 5504. x = 0, y = -1; 5505. else 5506. x = sgn(x), y = sgn(y); 5507. 5508. if (x == 0 && y == 0) { 5509. /* map click on player to "rest" command */ 5510. cmd[0] = cmd_from_func(donull); 5511. return cmd; 5512. } 5513. dir = xytod(x, y); 5514. } 5515. 5516. /* move, attack, etc. */ 5517. cmd[1] = 0; 5518. if (mod == CLICK_1) { 5519. cmd[0] = Cmd.dirchars[dir]; 5520. } else { 5521. cmd[0] = (Cmd.num_pad 5522. ? M(Cmd.dirchars[dir]) 5523. : (Cmd.dirchars[dir] - 'a' + 'A')); /* run command */ 5524. } 5525. 5526. return cmd; 5527. } 5528. 5529. char 5530. get_count(allowchars, inkey, maxcount, count, historical) 5531. char *allowchars; 5532. char inkey; 5533. long maxcount; 5534. long *count; 5535. boolean historical; /* whether to include in message history: True => yes */ 5536. { 5537. char qbuf[QBUFSZ]; 5538. int key; 5539. long cnt = 0L; 5540. boolean backspaced = FALSE; 5541. /* this should be done in port code so that we have erase_char 5542. and kill_char available; we can at least fake erase_char */ 5543. #define STANDBY_erase_char '\177' 5544. 5545. for (;;) { 5546. if (inkey) { 5547. key = inkey; 5548. inkey = '\0'; 5549. } else 5550. key = readchar(); 5551. 5552. if (digit(key)) { 5553. cnt = 10L * cnt + (long) (key - '0'); 5554. if (cnt < 0) 5555. cnt = 0; 5556. else if (maxcount > 0 && cnt > maxcount) 5557. cnt = maxcount; 5558. } else if (cnt && (key == '\b' || key == STANDBY_erase_char)) { 5559. cnt = cnt / 10; 5560. backspaced = TRUE; 5561. } else if (key == Cmd.spkeys[NHKF_ESC]) { 5562. break; 5563. } else if (!allowchars || index(allowchars, key)) { 5564. *count = cnt; 5565. break; 5566. } 5567. 5568. if (cnt > 9 || backspaced) { 5569. clear_nhwindow(WIN_MESSAGE); 5570. if (backspaced && !cnt) { 5571. Sprintf(qbuf, "Count: "); 5572. } else { 5573. Sprintf(qbuf, "Count: %ld", cnt); 5574. backspaced = FALSE; 5575. } 5576. custompline(SUPPRESS_HISTORY, "%s", qbuf); 5577. mark_synch(); 5578. } 5579. } 5580. 5581. if (historical) { 5582. Sprintf(qbuf, "Count: %ld ", *count); 5583. (void) key2txt((uchar) key, eos(qbuf)); 5584. putmsghistory(qbuf, FALSE); 5585. } 5586. 5587. return key; 5588. } 5589. 5590. 5591. STATIC_OVL char * 5592. parse() 5593. { 5594. #ifdef LINT /* static char in_line[COLNO]; */ 5595. char in_line[COLNO]; 5596. #else 5597. static char in_line[COLNO]; 5598. #endif 5599. register int foo; 5600. 5601. iflags.in_parse = TRUE; 5602. multi = 0; 5603. context.move = 1; 5604. flush_screen(1); /* Flush screen buffer. Put the cursor on the hero. */ 5605. 5606. #ifdef ALTMETA 5607. alt_esc = iflags.altmeta; /* readchar() hack */ 5608. #endif 5609. if (!Cmd.num_pad || (foo = readchar()) == Cmd.spkeys[NHKF_COUNT]) { 5610. long tmpmulti = multi; 5611. 5612. foo = get_count((char *) 0, '\0', LARGEST_INT, &tmpmulti, FALSE); 5613. last_multi = multi = tmpmulti; 5614. } 5615. #ifdef ALTMETA 5616. alt_esc = FALSE; /* readchar() reset */ 5617. #endif 5618. 5619. if (iflags.debug_fuzzer /* if fuzzing, override '!' and ^Z */ 5620. && (Cmd.commands[foo & 0x0ff] 5621. && (Cmd.commands[foo & 0x0ff]->ef_funct == dosuspend_core 5622. || Cmd.commands[foo & 0x0ff]->ef_funct == dosh_core))) 5623. foo = Cmd.spkeys[NHKF_ESC]; 5624. 5625. if (foo == Cmd.spkeys[NHKF_ESC]) { /* esc cancels count (TH) */ 5626. clear_nhwindow(WIN_MESSAGE); 5627. multi = last_multi = 0; 5628. } else if (foo == Cmd.spkeys[NHKF_DOAGAIN] || in_doagain) { 5629. multi = last_multi; 5630. } else { 5631. last_multi = multi; 5632. savech(0); /* reset input queue */ 5633. savech((char) foo); 5634. } 5635. 5636. if (multi) { 5637. multi--; 5638. save_cm = in_line; 5639. } else { 5640. save_cm = (char *) 0; 5641. } 5642. /* in 3.4.3 this was in rhack(), where it was too late to handle M-5 */ 5643. if (Cmd.pcHack_compat) { 5644. /* This handles very old inconsistent DOS/Windows behaviour 5645. in a different way: earlier, the keyboard handler mapped 5646. these, which caused counts to be strange when entered 5647. from the number pad. Now do not map them until here. */ 5648. switch (foo) { 5649. case '5': 5650. foo = Cmd.spkeys[NHKF_RUSH]; 5651. break; 5652. case M('5'): 5653. foo = Cmd.spkeys[NHKF_RUN]; 5654. break; 5655. case M('0'): 5656. foo = Cmd.spkeys[NHKF_DOINV]; 5657. break; 5658. default: 5659. break; /* as is */ 5660. } 5661. } 5662. 5663. in_line[0] = foo; 5664. in_line[1] = '\0'; 5665. if (prefix_cmd(foo)) { 5666. foo = readchar(); 5667. savech((char) foo); 5668. in_line[1] = foo; 5669. in_line[2] = 0; 5670. } 5671. clear_nhwindow(WIN_MESSAGE); 5672. 5673. iflags.in_parse = FALSE; 5674. return in_line; 5675. } 5676. 5677. #ifdef HANGUPHANDLING 5678. /* some very old systems, or descendents of such systems, expect signal 5679. handlers to have return type `int', but they don't actually inspect 5680. the return value so we should be safe using `void' unconditionally */ 5681. /*ARGUSED*/ 5682. void 5683. hangup(sig_unused) /* called as signal() handler, so sent at least one arg */ 5684. int sig_unused UNUSED; 5685. { 5686. if (program_state.exiting) 5687. program_state.in_moveloop = 0; 5688. nhwindows_hangup(); 5689. #ifdef SAFERHANGUP 5690. /* When using SAFERHANGUP, the done_hup flag it tested in rhack 5691. and a couple of other places; actual hangup handling occurs then. 5692. This is 'safer' because it disallows certain cheats and also 5693. protects against losing objects in the process of being thrown, 5694. but also potentially riskier because the disconnected program 5695. must continue running longer before attempting a hangup save. */ 5696. program_state.done_hup++; 5697. /* defer hangup iff game appears to be in progress */ 5698. if (program_state.in_moveloop && program_state.something_worth_saving) 5699. return; 5700. #endif /* SAFERHANGUP */ 5701. end_of_input(); 5702. } 5703. 5704. void 5705. end_of_input() 5706. { 5707. #ifdef NOSAVEONHANGUP 5708. #ifdef INSURANCE 5709. if (flags.ins_chkpt && program_state.something_worth_saving) 5710. program_statue.preserve_locks = 1; /* keep files for recovery */ 5711. #endif 5712. program_state.something_worth_saving = 0; /* don't save */ 5713. #endif 5714. 5715. #ifndef SAFERHANGUP 5716. if (!program_state.done_hup++) 5717. #endif 5718. if (program_state.something_worth_saving) 5719. (void) dosave0(); 5720. if (iflags.window_inited) 5721. exit_nhwindows((char *) 0); 5722. clearlocks(); 5723. nh_terminate(EXIT_SUCCESS); 5724. /*NOTREACHED*/ /* not necessarily true for vms... */ 5725. return; 5726. } 5727. #endif /* HANGUPHANDLING */ 5728. 5729. char 5730. readchar() 5731. { 5732. register int sym; 5733. int x = u.ux, y = u.uy, mod = 0; 5734. 5735. if (iflags.debug_fuzzer) 5736. return randomkey(); 5737. if (*readchar_queue) 5738. sym = *readchar_queue++; 5739. else 5740. sym = in_doagain ? pgetchar() : nh_poskey(&x, &y, &mod); 5741. 5742. #ifdef NR_OF_EOFS 5743. if (sym == EOF) { 5744. register int cnt = NR_OF_EOFS; 5745. /* 5746. * Some SYSV systems seem to return EOFs for various reasons 5747. * (?like when one hits break or for interrupted systemcalls?), 5748. * and we must see several before we quit. 5749. */ 5750. do { 5751. clearerr(stdin); /* omit if clearerr is undefined */ 5752. sym = pgetchar(); 5753. } while (--cnt && sym == EOF); 5754. } 5755. #endif /* NR_OF_EOFS */ 5756. 5757. if (sym == EOF) { 5758. #ifdef HANGUPHANDLING 5759. hangup(0); /* call end_of_input() or set program_state.done_hup */ 5760. #endif 5761. sym = '\033'; 5762. #ifdef ALTMETA 5763. } else if (sym == '\033' && alt_esc) { 5764. /* iflags.altmeta: treat two character ``ESC c as single `M-c' */ 5765. sym = *readchar_queue ? *readchar_queue++ : pgetchar(); 5766. if (sym == EOF || sym == 0) 5767. sym = '\033'; 5768. else if (sym != '\033') 5769. sym |= 0200; /* force 8th bit on */ 5770. #endif /*ALTMETA*/ 5771. } else if (sym == 0) { 5772. /* click event */ 5773. readchar_queue = click_to_cmd(x, y, mod); 5774. sym = *readchar_queue++; 5775. } 5776. return (char) sym; 5777. } 5778. 5779. /* '_' command, #travel, via keyboard rather than mouse click */ 5780. STATIC_PTR int 5781. dotravel(VOID_ARGS) 5782. { 5783. static char cmd[2]; 5784. coord cc; 5785. 5786. /* [FIXME? Supporting the ability to disable traveling via mouse 5787. click makes some sense, depending upon overall mouse usage. 5788. Disabling '_' on a user by user basis makes no sense at all since 5789. even if it is typed by accident, aborting when picking a target 5790. destination is trivial. Travel via mouse predates travel via '_', 5791. and this use of OPTION=!travel is probably just a mistake....] */ 5792. if (!flags.travelcmd) 5793. return 0; 5794. 5795. cmd[1] = 0; 5796. cc.x = iflags.travelcc.x; 5797. cc.y = iflags.travelcc.y; 5798. if (cc.x == 0 && cc.y == 0) { 5799. /* No cached destination, start attempt from current position */ 5800. cc.x = u.ux; 5801. cc.y = u.uy; 5802. } 5803. iflags.getloc_travelmode = TRUE; 5804. if (iflags.menu_requested) { 5805. int gf = iflags.getloc_filter; 5806. iflags.getloc_filter = GFILTER_VIEW; 5807. if (!getpos_menu(&cc, GLOC_INTERESTING)) { 5808. iflags.getloc_filter = gf; 5809. iflags.getloc_travelmode = FALSE; 5810. return 0; 5811. } 5812. iflags.getloc_filter = gf; 5813. } else { 5814. pline("Where do you want to travel to?"); 5815. if (getpos(&cc, TRUE, "the desired destination") < 0) { 5816. /* user pressed ESC */ 5817. iflags.getloc_travelmode = FALSE; 5818. return 0; 5819. } 5820. } 5821. iflags.getloc_travelmode = FALSE; 5822. iflags.travelcc.x = u.tx = cc.x; 5823. iflags.travelcc.y = u.ty = cc.y; 5824. cmd[0] = Cmd.spkeys[NHKF_TRAVEL]; 5825. readchar_queue = cmd; 5826. return 0; 5827. } 5828. 5829. /* 5830. * Parameter validator for generic yes/no function to prevent 5831. * the core from sending too long a prompt string to the 5832. * window port causing a buffer overflow there. 5833. */ 5834. char 5835. yn_function(query, resp, def) 5836. const char *query, *resp; 5837. char def; 5838. { 5839. char res, qbuf[QBUFSZ]; 5840. #ifdef DUMPLOG 5841. extern unsigned saved_pline_index; /* pline.c */ 5842. unsigned idx = saved_pline_index; 5843. /* buffer to hold query+space+formatted_single_char_response */ 5844. char dumplog_buf[QBUFSZ + 1 + 15]; /* [QBUFSZ+1+7] should suffice */ 5845. #endif 5846. 5847. iflags.last_msg = PLNMSG_UNKNOWN; /* most recent pline is clobbered */ 5848. 5849. /* maximum acceptable length is QBUFSZ-1 */ 5850. if (strlen(query) >= QBUFSZ) { 5851. /* caller shouldn't have passed anything this long */ 5852. paniclog("Query truncated: ", query); 5853. (void) strncpy(qbuf, query, QBUFSZ - 1 - 3); 5854. Strcpy(&qbuf[QBUFSZ - 1 - 3], "..."); 5855. query = qbuf; 5856. } 5857. res = (*windowprocs.win_yn_function)(query, resp, def); 5858. #ifdef DUMPLOG 5859. if (idx == saved_pline_index) { 5860. /* when idx is still the same as saved_pline_index, the interface 5861. didn't put the prompt into saved_plines[]; we put a simplified 5862. version in there now (without response choices or default) */ 5863. Sprintf(dumplog_buf, "%s ", query); 5864. (void) key2txt((uchar) res, eos(dumplog_buf)); 5865. dumplogmsg(dumplog_buf); 5866. } 5867. #endif 5868. return res; 5869. } 5870. 5871. /* for paranoid_confirm:quit,die,attack prompting */ 5872. boolean 5873. paranoid_query(be_paranoid, prompt) 5874. boolean be_paranoid; 5875. const char *prompt; 5876. { 5877. boolean confirmed_ok; 5878. 5879. /* when paranoid, player must respond with "yes" rather than just 'y' 5880. to give the go-ahead for this query; default is "no" unless the 5881. ParanoidConfirm flag is set in which case there's no default */ 5882. if (be_paranoid) { 5883. char qbuf[QBUFSZ], ans[BUFSZ] = DUMMY; 5884. const char *promptprefix = "", *responsetype = ParanoidConfirm 5885. ? "(yes|no)" 5886. : "(yes) [no]"; 5887. int trylimit = 6; /* 1 normal, 5 more with "Yes or No:" prefix */ 5888. 5889. /* in addition to being paranoid about this particular 5890. query, we might be even more paranoid about all paranoia 5891. responses (ie, ParanoidConfirm is set) in which case we 5892. require "no" to reject in addition to "yes" to confirm 5893. (except we won't loop if response is ESC; it means no) */ 5894. do { 5895. Sprintf(qbuf, "%s%s %s", promptprefix, prompt, responsetype); 5896. getlin(qbuf, ans); 5897. (void) mungspaces(ans); 5898. confirmed_ok = !strcmpi(ans, "yes"); 5899. if (confirmed_ok || *ans == '\033') 5900. break; 5901. promptprefix = "\"Yes\" or \"No\": "; 5902. } while (ParanoidConfirm && strcmpi(ans, "no") && --trylimit); 5903. } else 5904. confirmed_ok = (yn(prompt) == 'y'); 5905. 5906. return confirmed_ok; 5907. } 5908. 5909. /* ^Z command, #suspend */ 5910. STATIC_PTR int 5911. dosuspend_core(VOID_ARGS) 5912. { 5913. #ifdef SUSPEND 5914. /* Does current window system support suspend? */ 5915. if ((*windowprocs.win_can_suspend)()) { 5916. /* NB: SYSCF SHELLERS handled in port code. */ 5917. dosuspend(); 5918. } else 5919. #endif 5920. Norep(cmdnotavail, "#suspend"); 5921. return 0; 5922. } 5923. 5924. /* '!' command, #shell */ 5925. STATIC_PTR int 5926. dosh_core(VOID_ARGS) 5927. { 5928. #ifdef SHELL 5929. /* access restrictions, if any, are handled in port code */ 5930. dosh(); 5931. #else 5932. Norep(cmdnotavail, "#shell"); 5933. #endif 5934. return 0; 5935. } 5936. 5937. /*cmd.c*/