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