Source:NetHack 3.6.7/src/o init.c
Jump to navigation
Jump to search
Below is the full text to o_init.c from the source code of NetHack 3.6.7. To link to a particular line, write [[Source:NetHack 3.6.7/src/o_init.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 o_init.c $NHDT-Date: 1674864731 2023/01/28 00:12:11 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.27 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Robert Patrick Rankin, 2011. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. #include "hack.h" 7. #include "lev.h" /* save & restore info */ 8. 9. STATIC_DCL void FDECL(setgemprobs, (d_level *)); 10. STATIC_DCL void FDECL(shuffle, (int, int, BOOLEAN_P)); 11. STATIC_DCL void NDECL(shuffle_all); 12. STATIC_DCL boolean FDECL(interesting_to_discover, (int)); 13. STATIC_DCL void FDECL(disco_append_typename, (char *, int)); 14. STATIC_DCL char *FDECL(oclass_to_name, (CHAR_P, char *)); 15. 16. static NEARDATA short disco[NUM_OBJECTS] = DUMMY; 17. 18. #ifdef USE_TILES 19. STATIC_DCL void NDECL(shuffle_tiles); 20. extern short glyph2tile[]; /* from tile.c */ 21. 22. /* Shuffle tile assignments to match descriptions, so a red potion isn't 23. * displayed with a blue tile and so on. 24. * 25. * Tile assignments are not saved, and shouldn't be so that a game can 26. * be resumed on an otherwise identical non-tile-using binary, so we have 27. * to reshuffle the assignments from oc_descr_idx information when a game 28. * is restored. So might as well do that the first time instead of writing 29. * another routine. 30. */ 31. STATIC_OVL void 32. shuffle_tiles() 33. { 34. int i; 35. short tmp_tilemap[NUM_OBJECTS]; 36. 37. for (i = 0; i < NUM_OBJECTS; i++) 38. tmp_tilemap[i] = glyph2tile[objects[i].oc_descr_idx + GLYPH_OBJ_OFF]; 39. 40. for (i = 0; i < NUM_OBJECTS; i++) 41. glyph2tile[i + GLYPH_OBJ_OFF] = tmp_tilemap[i]; 42. } 43. #endif /* USE_TILES */ 44. 45. STATIC_OVL void 46. setgemprobs(dlev) 47. d_level *dlev; 48. { 49. int j, first, lev; 50. 51. if (dlev) 52. lev = (ledger_no(dlev) > maxledgerno()) ? maxledgerno() 53. : ledger_no(dlev); 54. else 55. lev = 0; 56. first = bases[GEM_CLASS]; 57. 58. for (j = 0; j < 9 - lev / 3; j++) 59. objects[first + j].oc_prob = 0; 60. first += j; 61. if (first > LAST_GEM || objects[first].oc_class != GEM_CLASS 62. || OBJ_NAME(objects[first]) == (char *) 0) { 63. raw_printf("Not enough gems? - first=%d j=%d LAST_GEM=%d", first, j, 64. LAST_GEM); 65. wait_synch(); 66. } 67. for (j = first; j <= LAST_GEM; j++) 68. objects[j].oc_prob = (171 + j - first) / (LAST_GEM + 1 - first); 69. } 70. 71. /* shuffle descriptions on objects o_low to o_high */ 72. STATIC_OVL void 73. shuffle(o_low, o_high, domaterial) 74. int o_low, o_high; 75. boolean domaterial; 76. { 77. int i, j, num_to_shuffle; 78. short sw; 79. int color; 80. 81. for (num_to_shuffle = 0, j = o_low; j <= o_high; j++) 82. if (!objects[j].oc_name_known) 83. num_to_shuffle++; 84. if (num_to_shuffle < 2) 85. return; 86. 87. for (j = o_low; j <= o_high; j++) { 88. if (objects[j].oc_name_known) 89. continue; 90. do 91. i = j + rn2(o_high - j + 1); 92. while (objects[i].oc_name_known); 93. sw = objects[j].oc_descr_idx; 94. objects[j].oc_descr_idx = objects[i].oc_descr_idx; 95. objects[i].oc_descr_idx = sw; 96. sw = objects[j].oc_tough; 97. objects[j].oc_tough = objects[i].oc_tough; 98. objects[i].oc_tough = sw; 99. color = objects[j].oc_color; 100. objects[j].oc_color = objects[i].oc_color; 101. objects[i].oc_color = color; 102. 103. /* shuffle material */ 104. if (domaterial) { 105. sw = objects[j].oc_material; 106. objects[j].oc_material = objects[i].oc_material; 107. objects[i].oc_material = sw; 108. } 109. } 110. } 111. 112. void 113. init_objects() 114. { 115. register int i, first, last, sum; 116. register char oclass; 117. #ifdef TEXTCOLOR 118. #define COPY_OBJ_DESCR(o_dst, o_src) \ 119. o_dst.oc_descr_idx = o_src.oc_descr_idx, o_dst.oc_color = o_src.oc_color 120. #else 121. #define COPY_OBJ_DESCR(o_dst, o_src) o_dst.oc_descr_idx = o_src.oc_descr_idx 122. #endif 123. 124. /* bug fix to prevent "initialization error" abort on Intel Xenix. 125. * reported by mikew@semike 126. */ 127. for (i = 0; i < MAXOCLASSES; i++) 128. bases[i] = 0; 129. /* initialize object descriptions */ 130. for (i = 0; i < NUM_OBJECTS; i++) 131. objects[i].oc_name_idx = objects[i].oc_descr_idx = i; 132. /* init base; if probs given check that they add up to 1000, 133. otherwise compute probs */ 134. first = 0; 135. while (first < NUM_OBJECTS) { 136. oclass = objects[first].oc_class; 137. last = first + 1; 138. while (last < NUM_OBJECTS && objects[last].oc_class == oclass) 139. last++; 140. bases[(int) oclass] = first; 141. 142. if (oclass == GEM_CLASS) { 143. setgemprobs((d_level *) 0); 144. 145. if (rn2(2)) { /* change turquoise from green to blue? */ 146. COPY_OBJ_DESCR(objects[TURQUOISE], objects[SAPPHIRE]); 147. } 148. if (rn2(2)) { /* change aquamarine from green to blue? */ 149. COPY_OBJ_DESCR(objects[AQUAMARINE], objects[SAPPHIRE]); 150. } 151. switch (rn2(4)) { /* change fluorite from violet? */ 152. case 0: 153. break; 154. case 1: /* blue */ 155. COPY_OBJ_DESCR(objects[FLUORITE], objects[SAPPHIRE]); 156. break; 157. case 2: /* white */ 158. COPY_OBJ_DESCR(objects[FLUORITE], objects[DIAMOND]); 159. break; 160. case 3: /* green */ 161. COPY_OBJ_DESCR(objects[FLUORITE], objects[EMERALD]); 162. break; 163. } 164. } 165. check: 166. sum = 0; 167. for (i = first; i < last; i++) 168. sum += objects[i].oc_prob; 169. if (sum == 0) { 170. for (i = first; i < last; i++) 171. objects[i].oc_prob = (1000 + i - first) / (last - first); 172. goto check; 173. } 174. if (sum != 1000) 175. error("init-prob error for class %d (%d%%)", oclass, sum); 176. first = last; 177. } 178. /* shuffle descriptions */ 179. shuffle_all(); 180. #ifdef USE_TILES 181. shuffle_tiles(); 182. #endif 183. objects[WAN_NOTHING].oc_dir = rn2(2) ? NODIR : IMMEDIATE; 184. } 185. 186. /* retrieve the range of objects that otyp shares descriptions with */ 187. void 188. obj_shuffle_range(otyp, lo_p, hi_p) 189. int otyp; /* input: representative item */ 190. int *lo_p, *hi_p; /* output: range that item belongs among */ 191. { 192. int i, ocls = objects[otyp].oc_class; 193. 194. /* default is just the object itself */ 195. *lo_p = *hi_p = otyp; 196. 197. switch (ocls) { 198. case ARMOR_CLASS: 199. if (otyp >= HELMET && otyp <= HELM_OF_TELEPATHY) 200. *lo_p = HELMET, *hi_p = HELM_OF_TELEPATHY; 201. else if (otyp >= LEATHER_GLOVES && otyp <= GAUNTLETS_OF_DEXTERITY) 202. *lo_p = LEATHER_GLOVES, *hi_p = GAUNTLETS_OF_DEXTERITY; 203. else if (otyp >= CLOAK_OF_PROTECTION && otyp <= CLOAK_OF_DISPLACEMENT) 204. *lo_p = CLOAK_OF_PROTECTION, *hi_p = CLOAK_OF_DISPLACEMENT; 205. else if (otyp >= SPEED_BOOTS && otyp <= LEVITATION_BOOTS) 206. *lo_p = SPEED_BOOTS, *hi_p = LEVITATION_BOOTS; 207. break; 208. case POTION_CLASS: 209. /* potion of water has the only fixed description */ 210. *lo_p = bases[POTION_CLASS]; 211. *hi_p = POT_WATER - 1; 212. break; 213. case AMULET_CLASS: 214. case SCROLL_CLASS: 215. case SPBOOK_CLASS: 216. /* exclude non-magic types and also unique ones */ 217. *lo_p = bases[ocls]; 218. for (i = *lo_p; objects[i].oc_class == ocls; i++) 219. if (objects[i].oc_unique || !objects[i].oc_magic) 220. break; 221. *hi_p = i - 1; 222. break; 223. case RING_CLASS: 224. case WAND_CLASS: 225. case VENOM_CLASS: 226. /* entire class */ 227. *lo_p = bases[ocls]; 228. for (i = *lo_p; objects[i].oc_class == ocls; i++) 229. continue; 230. *hi_p = i - 1; 231. break; 232. } 233. 234. /* artifact checking might ask about item which isn't part of any range 235. but fell within the classes that do have ranges specified above */ 236. if (otyp < *lo_p || otyp > *hi_p) 237. *lo_p = *hi_p = otyp; 238. return; 239. } 240. 241. /* randomize object descriptions */ 242. STATIC_OVL void 243. shuffle_all() 244. { 245. /* entire classes; obj_shuffle_range() handles their exceptions */ 246. static char shuffle_classes[] = { 247. AMULET_CLASS, POTION_CLASS, RING_CLASS, SCROLL_CLASS, 248. SPBOOK_CLASS, WAND_CLASS, VENOM_CLASS, 249. }; 250. /* sub-class type ranges (one item from each group) */ 251. static short shuffle_types[] = { 252. HELMET, LEATHER_GLOVES, CLOAK_OF_PROTECTION, SPEED_BOOTS, 253. }; 254. int first, last, idx; 255. 256. /* do whole classes (amulets, &c) */ 257. for (idx = 0; idx < SIZE(shuffle_classes); idx++) { 258. obj_shuffle_range(bases[(int) shuffle_classes[idx]], &first, &last); 259. shuffle(first, last, TRUE); 260. } 261. /* do type ranges (helms, &c) */ 262. for (idx = 0; idx < SIZE(shuffle_types); idx++) { 263. obj_shuffle_range(shuffle_types[idx], &first, &last); 264. shuffle(first, last, FALSE); 265. } 266. return; 267. } 268. 269. /* find the object index for snow boots; used [once] by slippery ice code */ 270. int 271. find_skates() 272. { 273. register int i; 274. register const char *s; 275. 276. for (i = SPEED_BOOTS; i <= LEVITATION_BOOTS; i++) 277. if ((s = OBJ_DESCR(objects[i])) != 0 && !strcmp(s, "snow boots")) 278. return i; 279. 280. impossible("snow boots not found?"); 281. return -1; /* not 0, or caller would try again each move */ 282. } 283. 284. /* level dependent initialization */ 285. void 286. oinit() 287. { 288. setgemprobs(&u.uz); 289. } 290. 291. void 292. savenames(fd, mode) 293. int fd, mode; 294. { 295. register int i; 296. unsigned int len; 297. 298. if (perform_bwrite(mode)) { 299. bwrite(fd, (genericptr_t) bases, sizeof bases); 300. bwrite(fd, (genericptr_t) disco, sizeof disco); 301. bwrite(fd, (genericptr_t) objects, 302. sizeof(struct objclass) * NUM_OBJECTS); 303. } 304. /* as long as we use only one version of Hack we 305. need not save oc_name and oc_descr, but we must save 306. oc_uname for all objects */ 307. for (i = 0; i < NUM_OBJECTS; i++) 308. if (objects[i].oc_uname) { 309. if (perform_bwrite(mode)) { 310. len = strlen(objects[i].oc_uname) + 1; 311. bwrite(fd, (genericptr_t) &len, sizeof len); 312. bwrite(fd, (genericptr_t) objects[i].oc_uname, len); 313. } 314. if (release_data(mode)) { 315. free((genericptr_t) objects[i].oc_uname); 316. objects[i].oc_uname = 0; 317. } 318. } 319. } 320. 321. void 322. restnames(fd) 323. register int fd; 324. { 325. register int i; 326. unsigned int len; 327. 328. mread(fd, (genericptr_t) bases, sizeof bases); 329. mread(fd, (genericptr_t) disco, sizeof disco); 330. mread(fd, (genericptr_t) objects, sizeof(struct objclass) * NUM_OBJECTS); 331. for (i = 0; i < NUM_OBJECTS; i++) 332. if (objects[i].oc_uname) { 333. mread(fd, (genericptr_t) &len, sizeof len); 334. objects[i].oc_uname = (char *) alloc(len); 335. mread(fd, (genericptr_t) objects[i].oc_uname, len); 336. } 337. #ifdef USE_TILES 338. shuffle_tiles(); 339. #endif 340. } 341. 342. void 343. discover_object(oindx, mark_as_known, credit_hero) 344. register int oindx; 345. boolean mark_as_known; 346. boolean credit_hero; 347. { 348. if (!objects[oindx].oc_name_known) { 349. register int dindx, acls = objects[oindx].oc_class; 350. 351. /* Loop thru disco[] 'til we find the target (which may have been 352. uname'd) or the next open slot; one or the other will be found 353. before we reach the next class... 354. */ 355. for (dindx = bases[acls]; disco[dindx] != 0; dindx++) 356. if (disco[dindx] == oindx) 357. break; 358. disco[dindx] = oindx; 359. 360. if (mark_as_known) { 361. objects[oindx].oc_name_known = 1; 362. if (credit_hero) 363. exercise(A_WIS, TRUE); 364. } 365. /* moves==1L => initial inventory, gameover => final disclosure */ 366. if (moves > 1L && !program_state.gameover) { 367. if (objects[oindx].oc_class == GEM_CLASS) 368. gem_learned(oindx); /* could affect price of unpaid gems */ 369. update_inventory(); 370. } 371. } 372. } 373. 374. /* if a class name has been cleared, we may need to purge it from disco[] */ 375. void 376. undiscover_object(oindx) 377. register int oindx; 378. { 379. if (!objects[oindx].oc_name_known) { 380. register int dindx, acls = objects[oindx].oc_class; 381. register boolean found = FALSE; 382. 383. /* find the object; shift those behind it forward one slot */ 384. for (dindx = bases[acls]; dindx < NUM_OBJECTS && disco[dindx] != 0 385. && objects[dindx].oc_class == acls; 386. dindx++) 387. if (found) 388. disco[dindx - 1] = disco[dindx]; 389. else if (disco[dindx] == oindx) 390. found = TRUE; 391. 392. /* clear last slot */ 393. if (found) 394. disco[dindx - 1] = 0; 395. else 396. impossible("named object not in disco"); 397. 398. if (objects[oindx].oc_class == GEM_CLASS) 399. gem_learned(oindx); /* ok, it's actually been unlearned */ 400. update_inventory(); 401. } 402. } 403. 404. STATIC_OVL boolean 405. interesting_to_discover(i) 406. register int i; 407. { 408. /* Pre-discovered objects are now printed with a '*' */ 409. return (boolean) (objects[i].oc_uname != (char *) 0 410. || (objects[i].oc_name_known 411. && OBJ_DESCR(objects[i]) != (char *) 0)); 412. } 413. 414. /* items that should stand out once they're known */ 415. static short uniq_objs[] = { 416. AMULET_OF_YENDOR, SPE_BOOK_OF_THE_DEAD, CANDELABRUM_OF_INVOCATION, 417. BELL_OF_OPENING, 418. }; 419. 420. /* append typename(dis) to buf[], possibly truncating in the process */ 421. STATIC_OVL void 422. disco_append_typename(buf, dis) 423. char *buf; 424. int dis; 425. { 426. unsigned len = (unsigned) strlen(buf); 427. char *p, *typnm = obj_typename(dis); 428. 429. if (len + (unsigned) strlen(typnm) < BUFSZ) { 430. /* ordinary */ 431. Strcat(buf, typnm); 432. } else if ((p = rindex(typnm, '(')) != 0 433. && p > typnm && p[-1] == ' ' && index(p, ')') != 0) { 434. /* typename() returned "really long user-applied name (actual type)" 435. and we want to truncate from "really long user-applied name" while 436. keeping " (actual type)" intact */ 437. --p; /* back up to space in front of open paren */ 438. (void) strncat(buf, typnm, BUFSZ - 1 - (len + (unsigned) strlen(p))); 439. Strcat(buf, p); 440. } else { 441. /* unexpected; just truncate from end of typename */ 442. (void) strncat(buf, typnm, BUFSZ - 1 - len); 443. } 444. } 445. 446. /* the '\' command - show discovered object types */ 447. int 448. dodiscovered() /* free after Robert Viduya */ 449. { 450. register int i, dis; 451. int ct = 0; 452. char *s, oclass, prev_class, classes[MAXOCLASSES], buf[BUFSZ]; 453. winid tmpwin; 454. 455. tmpwin = create_nhwindow(NHW_MENU); 456. putstr(tmpwin, 0, "Discoveries"); 457. putstr(tmpwin, 0, ""); 458. 459. /* gather "unique objects" into a pseudo-class; note that they'll 460. also be displayed individually within their regular class */ 461. for (i = dis = 0; i < SIZE(uniq_objs); i++) 462. if (objects[uniq_objs[i]].oc_name_known) { 463. if (!dis++) 464. putstr(tmpwin, iflags.menu_headings, "Unique items"); 465. Sprintf(buf, " %s", OBJ_NAME(objects[uniq_objs[i]])); 466. putstr(tmpwin, 0, buf); 467. ++ct; 468. } 469. /* display any known artifacts as another pseudo-class */ 470. ct += disp_artifact_discoveries(tmpwin); 471. 472. /* several classes are omitted from packorder; one is of interest here */ 473. Strcpy(classes, flags.inv_order); 474. if (!index(classes, VENOM_CLASS)) 475. (void) strkitten(classes, VENOM_CLASS); /* append char to string */ 476. 477. for (s = classes; *s; s++) { 478. oclass = *s; 479. prev_class = oclass + 1; /* forced different from oclass */ 480. for (i = bases[(int) oclass]; 481. i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { 482. if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { 483. ct++; 484. if (oclass != prev_class) { 485. putstr(tmpwin, iflags.menu_headings, 486. let_to_name(oclass, FALSE, FALSE)); 487. prev_class = oclass; 488. } 489. Strcpy(buf, objects[dis].oc_pre_discovered ? "* " : " "); 490. disco_append_typename(buf, dis); 491. putstr(tmpwin, 0, buf); 492. } 493. } 494. } 495. if (ct == 0) { 496. You("haven't discovered anything yet..."); 497. } else 498. display_nhwindow(tmpwin, TRUE); 499. destroy_nhwindow(tmpwin); 500. 501. return 0; 502. } 503. 504. /* lower case let_to_name() output, which differs from def_oc_syms[].name */ 505. STATIC_OVL char * 506. oclass_to_name(oclass, buf) 507. char oclass; 508. char *buf; 509. { 510. char *s; 511. 512. Strcpy(buf, let_to_name(oclass, FALSE, FALSE)); 513. for (s = buf; *s; ++s) 514. *s = lowc(*s); 515. return buf; 516. } 517. 518. /* the '`' command - show discovered object types for one class */ 519. int 520. doclassdisco() 521. { 522. static NEARDATA const char 523. prompt[] = "View discoveries for which sort of objects?", 524. havent_discovered_any[] = "haven't discovered any %s yet.", 525. unique_items[] = "unique items", 526. artifact_items[] = "artifacts"; 527. char *s, c, oclass, menulet, allclasses[MAXOCLASSES], 528. discosyms[2 + MAXOCLASSES + 1], buf[BUFSZ]; 529. int i, ct, dis, xtras; 530. boolean traditional; 531. winid tmpwin = WIN_ERR; 532. anything any; 533. menu_item *pick_list = 0; 534. 535. discosyms[0] = '\0'; 536. traditional = (flags.menu_style == MENU_TRADITIONAL 537. || flags.menu_style == MENU_COMBINATION); 538. if (!traditional) { 539. tmpwin = create_nhwindow(NHW_MENU); 540. start_menu(tmpwin); 541. } 542. any = zeroany; 543. menulet = 'a'; 544. 545. /* check whether we've discovered any unique objects */ 546. for (i = 0; i < SIZE(uniq_objs); i++) 547. if (objects[uniq_objs[i]].oc_name_known) { 548. Strcat(discosyms, "u"); 549. if (!traditional) { 550. any.a_int = 'u'; 551. add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE, 552. unique_items, MENU_UNSELECTED); 553. } 554. break; 555. } 556. 557. /* check whether we've discovered any artifacts */ 558. if (disp_artifact_discoveries(WIN_ERR) > 0) { 559. Strcat(discosyms, "a"); 560. if (!traditional) { 561. any.a_int = 'a'; 562. add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE, 563. artifact_items, MENU_UNSELECTED); 564. } 565. } 566. 567. /* collect classes with discoveries, in packorder ordering; several 568. classes are omitted from packorder and one is of interest here */ 569. Strcpy(allclasses, flags.inv_order); 570. if (!index(allclasses, VENOM_CLASS)) 571. (void) strkitten(allclasses, VENOM_CLASS); /* append char to string */ 572. /* construct discosyms[] */ 573. for (s = allclasses; *s; ++s) { 574. oclass = *s; 575. c = def_oc_syms[(int) oclass].sym; 576. for (i = bases[(int) oclass]; 577. i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) 578. if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { 579. if (!index(discosyms, c)) { 580. Sprintf(eos(discosyms), "%c", c); 581. if (!traditional) { 582. any.a_int = c; 583. add_menu(tmpwin, NO_GLYPH, &any, menulet++, c, 584. ATR_NONE, oclass_to_name(oclass, buf), 585. MENU_UNSELECTED); 586. } 587. } 588. } 589. } 590. 591. /* there might not be anything for us to do... */ 592. if (!discosyms[0]) { 593. You(havent_discovered_any, "items"); 594. if (tmpwin != WIN_ERR) 595. destroy_nhwindow(tmpwin); 596. return 0; 597. } 598. 599. /* have player choose a class */ 600. c = '\0'; /* class not chosen yet */ 601. if (traditional) { 602. /* we'll prompt even if there's only one viable class; we add all 603. nonviable classes as unseen acceptable choices so player can ask 604. for discoveries of any class whether it has discoveries or not */ 605. for (s = allclasses, xtras = 0; *s; ++s) { 606. c = def_oc_syms[(int) *s].sym; 607. if (!index(discosyms, c)) { 608. if (!xtras++) 609. (void) strkitten(discosyms, '\033'); 610. (void) strkitten(discosyms, c); 611. } 612. } 613. /* get the class (via its symbol character) */ 614. c = yn_function(prompt, discosyms, '\0'); 615. savech(c); 616. if (!c) 617. clear_nhwindow(WIN_MESSAGE); 618. } else { 619. /* menustyle:full or menustyle:partial */ 620. if (!discosyms[1] && flags.menu_style == MENU_PARTIAL) { 621. /* only one class; menustyle:partial normally jumps past class 622. filtering straight to final menu so skip class filter here */ 623. c = discosyms[0]; 624. } else { 625. /* more than one choice, or menustyle:full which normally has 626. an intermediate class selection menu before the final menu */ 627. end_menu(tmpwin, prompt); 628. i = select_menu(tmpwin, PICK_ONE, &pick_list); 629. if (i > 0) { 630. c = pick_list[0].item.a_int; 631. free((genericptr_t) pick_list); 632. } /* else c stays 0 */ 633. } 634. destroy_nhwindow(tmpwin); 635. } 636. if (!c) 637. return 0; /* player declined to make a selection */ 638. 639. /* 640. * show discoveries for object class c 641. */ 642. tmpwin = create_nhwindow(NHW_MENU); 643. ct = 0; 644. switch (c) { 645. case 'u': 646. putstr(tmpwin, iflags.menu_headings, 647. upstart(strcpy(buf, unique_items))); 648. for (i = 0; i < SIZE(uniq_objs); i++) 649. if (objects[uniq_objs[i]].oc_name_known) { 650. Sprintf(buf, " %s", OBJ_NAME(objects[uniq_objs[i]])); 651. putstr(tmpwin, 0, buf); 652. ++ct; 653. } 654. if (!ct) 655. You(havent_discovered_any, unique_items); 656. break; 657. case 'a': 658. /* disp_artifact_discoveries() includes a header */ 659. ct = disp_artifact_discoveries(tmpwin); 660. if (!ct) 661. You(havent_discovered_any, artifact_items); 662. break; 663. default: 664. oclass = def_char_to_objclass(c); 665. Sprintf(buf, "Discovered %s", let_to_name(oclass, FALSE, FALSE)); 666. putstr(tmpwin, iflags.menu_headings, buf); 667. for (i = bases[(int) oclass]; 668. i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) { 669. if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) { 670. Strcpy(buf, objects[dis].oc_pre_discovered ? "* " : " "); 671. disco_append_typename(buf, dis); 672. putstr(tmpwin, 0, buf); 673. ++ct; 674. } 675. } 676. if (!ct) 677. You(havent_discovered_any, oclass_to_name(oclass, buf)); 678. break; 679. } 680. if (ct) 681. display_nhwindow(tmpwin, TRUE); 682. destroy_nhwindow(tmpwin); 683. return 0; 684. } 685. 686. /* put up nameable subset of discoveries list as a menu */ 687. void 688. rename_disco() 689. { 690. register int i, dis; 691. int ct = 0, mn = 0, sl; 692. char *s, oclass, prev_class; 693. winid tmpwin; 694. anything any; 695. menu_item *selected = 0; 696. 697. any = zeroany; 698. tmpwin = create_nhwindow(NHW_MENU); 699. start_menu(tmpwin); 700. 701. /* 702. * Skip the "unique objects" section (each will appear within its 703. * regular class if it is nameable) and the artifacts section. 704. * We assume that classes omitted from packorder aren't nameable 705. * so we skip venom too. 706. */ 707. 708. /* for each class, show discoveries in that class */ 709. for (s = flags.inv_order; *s; s++) { 710. oclass = *s; 711. prev_class = oclass + 1; /* forced different from oclass */ 712. for (i = bases[(int) oclass]; 713. i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) { 714. dis = disco[i]; 715. if (!dis || !interesting_to_discover(dis)) 716. continue; 717. ct++; 718. if (!objtyp_is_callable(dis)) 719. continue; 720. mn++; 721. 722. if (oclass != prev_class) { 723. any.a_int = 0; 724. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, iflags.menu_headings, 725. let_to_name(oclass, FALSE, FALSE), 726. MENU_UNSELECTED); 727. prev_class = oclass; 728. } 729. any.a_int = dis; 730. add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, 731. obj_typename(dis), MENU_UNSELECTED); 732. } 733. } 734. if (ct == 0) { 735. You("haven't discovered anything yet..."); 736. } else if (mn == 0) { 737. pline("None of your discoveries can be assigned names..."); 738. } else { 739. end_menu(tmpwin, "Pick an object type to name"); 740. dis = STRANGE_OBJECT; 741. sl = select_menu(tmpwin, PICK_ONE, &selected); 742. if (sl > 0) { 743. dis = selected[0].item.a_int; 744. free((genericptr_t) selected); 745. } 746. if (dis != STRANGE_OBJECT) { 747. struct obj odummy; 748. 749. odummy = zeroobj; 750. odummy.otyp = dis; 751. odummy.oclass = objects[dis].oc_class; 752. odummy.quan = 1L; 753. odummy.known = !objects[dis].oc_uses_known; 754. odummy.dknown = 1; 755. docall(&odummy); 756. } 757. } 758. destroy_nhwindow(tmpwin); 759. return; 760. } 761. 762. /*o_init.c*/