PageRenderTime 129ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 1ms

/src/obj-util.c

https://github.com/NickMcConnell/Beleriand
C | 5086 lines | 4994 code | 30 blank | 62 comment | 33 complexity | 92006bf21b23c76cd62e33dbe5efdab9 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * File: obj-util.c
  3. * Purpose: Object list maintenance and other object utilities
  4. *
  5. * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
  6. *
  7. * This work is free software; you can redistribute it and/or modify it
  8. * under the terms of either:
  9. *
  10. * a) the GNU General Public License as published by the Free Software
  11. * Foundation, version 2, or
  12. *
  13. * b) the "Angband licence":
  14. * This software may be copied and distributed for educational, research,
  15. * and not for profit purposes provided that this copyright and statement
  16. * are included in all such copies. Other copyrights may also apply.
  17. */
  18. #include "angband.h"
  19. #include "cave.h"
  20. #include "defines.h"
  21. #include "effects.h"
  22. #include "game-cmd.h"
  23. #include "generate.h"
  24. #include "history.h"
  25. #include "prefs.h"
  26. #include "randname.h"
  27. #include "spells.h"
  28. #include "squelch.h"
  29. #include "tvalsval.h"
  30. /*
  31. * Hold the titles of scrolls, 6 to 14 characters each, plus quotes.
  32. */
  33. char scroll_adj[MAX_TITLES][18];
  34. static void flavor_assign_fixed(void)
  35. {
  36. int i, j;
  37. for (i = 0; i < z_info->flavor_max; i++) {
  38. flavor_type *flavor_ptr = &flavor_info[i];
  39. /* Skip random flavors */
  40. if (flavor_ptr->sval == SV_UNKNOWN)
  41. continue;
  42. for (j = 0; j < z_info->k_max; j++) {
  43. /* Skip other objects */
  44. if ((k_info[j].tval == flavor_ptr->tval)
  45. && (k_info[j].sval == flavor_ptr->sval)) {
  46. /* Store the flavor index */
  47. k_info[j].flavor = i;
  48. }
  49. }
  50. }
  51. }
  52. static void flavor_assign_random(byte tval)
  53. {
  54. int i, j;
  55. int flavor_count = 0;
  56. int choice;
  57. /* Count the random flavors for the given tval */
  58. for (i = 0; i < z_info->flavor_max; i++) {
  59. if ((flavor_info[i].tval == tval)
  60. && (flavor_info[i].sval == SV_UNKNOWN)) {
  61. flavor_count++;
  62. }
  63. }
  64. for (i = 0; i < z_info->k_max; i++) {
  65. /* Skip other object types */
  66. if (k_info[i].tval != tval)
  67. continue;
  68. /* Skip objects that already are flavored */
  69. if (k_info[i].flavor != 0)
  70. continue;
  71. /* HACK - Ordinary food is "boring" */
  72. if ((tval == TV_FOOD) && (k_info[i].sval >= SV_FOOD_MIN_FOOD))
  73. continue;
  74. if (!flavor_count)
  75. quit_fmt("Not enough flavors for tval %d.", tval);
  76. /* Select a flavor */
  77. choice = randint0(flavor_count);
  78. /* Find and store the flavor */
  79. for (j = 0; j < z_info->flavor_max; j++) {
  80. /* Skip other tvals */
  81. if (flavor_info[j].tval != tval)
  82. continue;
  83. /* Skip assigned svals */
  84. if (flavor_info[j].sval != SV_UNKNOWN)
  85. continue;
  86. if (choice == 0) {
  87. /* Store the flavor index */
  88. k_info[i].flavor = j;
  89. /* Mark the flavor as used */
  90. flavor_info[j].sval = k_info[i].sval;
  91. /* Hack - set the scroll name if it's a scroll */
  92. if (tval == TV_SCROLL) {
  93. flavor_info[j].text = scroll_adj[k_info[i].sval];
  94. }
  95. /* One less flavor to choose from */
  96. flavor_count--;
  97. break;
  98. }
  99. choice--;
  100. }
  101. }
  102. }
  103. /*
  104. * Prepare the "variable" part of the "k_info" array.
  105. *
  106. * The "color"/"metal"/"type" of an item is its "flavor".
  107. * For the most part, flavors are assigned randomly each game.
  108. *
  109. * Initialize descriptions for the "colored" objects, including:
  110. * Rings, Amulets, Staffs, Wands, Rods, Food, Potions, Scrolls.
  111. *
  112. * The first 4 entries for potions are fixed (Water, Apple Juice,
  113. * Slime Mold Juice, Unused Potion).
  114. *
  115. * Scroll titles are always between 6 and 14 letters long. This is
  116. * ensured because every title is composed of whole words, where every
  117. * word is from 2 to 8 letters long, and that no scroll is finished
  118. * until it attempts to grow beyond 15 letters. The first time this
  119. * can happen is when the current title has 6 letters and the new word
  120. * has 8 letters, which would result in a 6 letter scroll title.
  121. *
  122. * Hack -- make sure everything stays the same for each saved game
  123. * This is accomplished by the use of a saved "random seed", as in
  124. * "town_gen()". Since no other functions are called while the special
  125. * seed is in effect, so this function is pretty "safe".
  126. */
  127. void flavor_init(void)
  128. {
  129. int i, j;
  130. /* Hack -- Use the "simple" RNG */
  131. Rand_quick = TRUE;
  132. /* Hack -- Induce consistant flavors */
  133. Rand_value = seed_flavor;
  134. flavor_assign_fixed();
  135. flavor_assign_random(TV_STAFF);
  136. flavor_assign_random(TV_WAND);
  137. flavor_assign_random(TV_ROD);
  138. flavor_assign_random(TV_FOOD);
  139. flavor_assign_random(TV_POTION);
  140. /* Scrolls (random titles, always white) */
  141. for (i = 0; i < MAX_TITLES; i++) {
  142. char buf[26] = "\"";
  143. char *end = buf + 1;
  144. int titlelen = 0;
  145. int wordlen;
  146. bool okay = TRUE;
  147. wordlen =
  148. randname_make(RANDNAME_SCROLL, 2, 8, end, 24, name_sections);
  149. while (titlelen + wordlen < (int) (sizeof(scroll_adj[0]) - 3)) {
  150. end[wordlen] = ' ';
  151. titlelen += wordlen + 1;
  152. end += wordlen + 1;
  153. wordlen =
  154. randname_make(RANDNAME_SCROLL, 2, 8, end, 24 - titlelen,
  155. name_sections);
  156. }
  157. buf[titlelen] = '"';
  158. buf[titlelen + 1] = '\0';
  159. /* Check the scroll name hasn't already been generated */
  160. for (j = 0; j < i; j++) {
  161. if (streq(buf, scroll_adj[j])) {
  162. okay = FALSE;
  163. break;
  164. }
  165. }
  166. if (okay) {
  167. my_strcpy(scroll_adj[i], buf, sizeof(scroll_adj[0]));
  168. } else {
  169. /* Have another go at making a name */
  170. i--;
  171. }
  172. }
  173. flavor_assign_random(TV_SCROLL);
  174. /* Hack -- Use the "complex" RNG */
  175. Rand_quick = FALSE;
  176. /* Analyze every object */
  177. for (i = 1; i < z_info->k_max; i++) {
  178. object_kind *k_ptr = &k_info[i];
  179. /* Skip "empty" objects */
  180. if (!k_ptr->name)
  181. continue;
  182. /* No flavor yields aware */
  183. if (!k_ptr->flavor)
  184. k_ptr->aware = TRUE;
  185. }
  186. }
  187. /**
  188. * Get the inventory color for an object.
  189. *
  190. * Hack - set the listing color of a spellbook with no useable spells
  191. * to grey -LM-
  192. */
  193. byte proc_list_color_hack(object_type * o_ptr)
  194. {
  195. /* Hack -- Spellbooks with no useable spells are grey. */
  196. if ((mp_ptr->spell_book == o_ptr->tval)
  197. && (mp_ptr->book_start_index[o_ptr->sval] ==
  198. mp_ptr->book_start_index[o_ptr->sval + 1])) {
  199. return (TERM_SLATE);
  200. }
  201. /* Otherwise, get the color normally. */
  202. else
  203. return (tval_to_attr[o_ptr->tval]);
  204. }
  205. #ifdef ALLOW_BORG_GRAPHICS
  206. extern void init_translate_visuals(void);
  207. #endif /* ALLOW_BORG_GRAPHICS */
  208. /*
  209. * Reset the "visual" lists
  210. *
  211. * This involves resetting various things to their "default" state.
  212. *
  213. * If the "prefs" flag is TRUE, then we will also load the appropriate
  214. * "user pref file" based on the current setting of the "use_graphics"
  215. * flag. This is useful for switching "graphics" on/off.
  216. */
  217. /* XXX this does not belong here */
  218. void reset_visuals(bool load_prefs)
  219. {
  220. int i;
  221. /* Extract default attr/char code for features */
  222. for (i = 0; i < z_info->f_max; i++) {
  223. int j;
  224. feature_type *f_ptr = &f_info[i];
  225. /* Assume we will use the underlying values */
  226. for (j = 0; j < FEAT_LIGHTING_MAX; j++) {
  227. f_ptr->x_attr[j] = f_ptr->d_attr;
  228. f_ptr->x_char[j] = f_ptr->d_char;
  229. }
  230. }
  231. /* Extract default attr/char code for objects */
  232. for (i = 0; i < z_info->k_max; i++) {
  233. object_kind *k_ptr = &k_info[i];
  234. /* Default attr/char */
  235. k_ptr->x_attr = k_ptr->d_attr;
  236. k_ptr->x_char = k_ptr->d_char;
  237. }
  238. /* Extract default attr/char code for monsters */
  239. for (i = 0; i < z_info->r_max; i++) {
  240. monster_race *r_ptr = &r_info[i];
  241. /* Default attr/char */
  242. r_ptr->x_attr = r_ptr->d_attr;
  243. r_ptr->x_char = r_ptr->d_char;
  244. }
  245. /* Extract default attr/char code for flavors */
  246. for (i = 0; i < z_info->flavor_max; i++) {
  247. flavor_type *flavor_ptr = &flavor_info[i];
  248. /* Default attr/char */
  249. flavor_ptr->x_attr = flavor_ptr->d_attr;
  250. flavor_ptr->x_char = flavor_ptr->d_char;
  251. }
  252. /* Extract attr/chars for inventory objects (by tval) */
  253. for (i = 0; i < (int) N_ELEMENTS(tval_to_attr); i++) {
  254. /* Default to white */
  255. tval_to_attr[i] = TERM_WHITE;
  256. }
  257. if (!load_prefs)
  258. return;
  259. /* Graphic symbols */
  260. if (use_graphics) {
  261. /* Process "graf.prf" */
  262. process_pref_file("graf.prf", FALSE, FALSE);
  263. }
  264. /* Normal symbols */
  265. else {
  266. /* Process "font.prf" */
  267. process_pref_file("font.prf", FALSE, FALSE);
  268. }
  269. #ifdef ALLOW_BORG_GRAPHICS
  270. /* Initialize the translation table for the borg */
  271. init_translate_visuals();
  272. #endif /* ALLOW_BORG_GRAPHICS */
  273. }
  274. /*
  275. * Convert an inventory index into a one character label.
  276. *
  277. * Note that the label does NOT distinguish inven/equip.
  278. */
  279. char index_to_label(int i)
  280. {
  281. /* Indexes for "inven" are easy */
  282. if (i < INVEN_WIELD)
  283. return (I2A(i));
  284. /* Indexes for "equip" are offset */
  285. return (I2A(i - INVEN_WIELD));
  286. }
  287. /*
  288. * Convert a label into the index of an item in the "inven".
  289. *
  290. * Return "-1" if the label does not indicate a real item.
  291. */
  292. s16b label_to_inven(int c)
  293. {
  294. int i;
  295. /* Convert */
  296. i = (islower((unsigned char) c) ? A2I(c) : -1);
  297. /* Verify the index */
  298. if ((i < 0) || (i > INVEN_PACK))
  299. return (-1);
  300. /* Empty slots can never be chosen */
  301. if (!p_ptr->inventory[i].k_idx)
  302. return (-1);
  303. /* Return the index */
  304. return (i);
  305. }
  306. /*
  307. * Convert a label into the index of a item in the "equip".
  308. *
  309. * Return "-1" if the label does not indicate a real item.
  310. */
  311. s16b label_to_equip(int c)
  312. {
  313. int i;
  314. /* Convert */
  315. i = (islower((unsigned char) c) ? A2I(c) : -1) + INVEN_WIELD;
  316. /* Verify the index */
  317. if ((i < INVEN_WIELD) || (i >= ALL_INVEN_TOTAL) || (i == INVEN_TOTAL))
  318. return (-1);
  319. /* Empty slots can never be chosen */
  320. if (!p_ptr->inventory[i].k_idx)
  321. return (-1);
  322. /* Return the index */
  323. return (i);
  324. }
  325. /*
  326. * Hack -- determine if an item is "wearable" (or a missile)
  327. */
  328. bool wearable_p(const object_type * o_ptr)
  329. {
  330. /* Valid "tval" codes */
  331. switch (o_ptr->tval) {
  332. case TV_SHOT:
  333. case TV_ARROW:
  334. case TV_BOLT:
  335. case TV_BOW:
  336. case TV_DIGGING:
  337. case TV_HAFTED:
  338. case TV_POLEARM:
  339. case TV_SWORD:
  340. case TV_BOOTS:
  341. case TV_GLOVES:
  342. case TV_HELM:
  343. case TV_CROWN:
  344. case TV_SHIELD:
  345. case TV_CLOAK:
  346. case TV_SOFT_ARMOR:
  347. case TV_HARD_ARMOR:
  348. case TV_DRAG_ARMOR:
  349. case TV_LIGHT:
  350. case TV_AMULET:
  351. case TV_RING:
  352. return (TRUE);
  353. }
  354. /* Nope */
  355. return (FALSE);
  356. }
  357. int get_inscribed_ammo_slot(const object_type * o_ptr)
  358. {
  359. char *s = NULL, *t = NULL;
  360. if (!o_ptr->note)
  361. return 0;
  362. s = strchr(quark_str(o_ptr->note), 'v');
  363. t = strchr(quark_str(o_ptr->note), 'f');
  364. /* Prefer throwing weapons */
  365. if (s && (s[1] >= '0') && (s[1] <= '9'))
  366. return QUIVER_START + (s[1] - '0');
  367. else if (t && (t[1] >= '0') && (t[1] <= '9'))
  368. return QUIVER_START + (t[1] - '0');
  369. return 0;
  370. }
  371. /**
  372. * Used by wield_slot() to find an appopriate slot for ammo. See wield_slot()
  373. * for information on what this returns.
  374. */
  375. s16b wield_slot_ammo(const object_type * o_ptr)
  376. {
  377. s16b i, open = 0;
  378. /* If the ammo is inscribed with a slot number, we'll try to put it in */
  379. /* that slot, if possible. */
  380. i = get_inscribed_ammo_slot(o_ptr);
  381. if (i && !p_ptr->inventory[i].k_idx)
  382. return i;
  383. for (i = QUIVER_START; i < QUIVER_END; i++) {
  384. if (!p_ptr->inventory[i].k_idx) {
  385. /* Save the open slot if we haven't found one already */
  386. if (!open)
  387. open = i;
  388. continue;
  389. }
  390. /* If ammo is cursed we can't stack it */
  391. if (cf_has(p_ptr->inventory[i].flags_curse, CF_STICKY_WIELD))
  392. continue;
  393. /* If they are stackable, we'll use this slot for sure */
  394. if (object_similar(&p_ptr->inventory[i], o_ptr, OSTACK_QUIVER))
  395. return i;
  396. }
  397. /* If not absorbed, return an open slot (or QUIVER_START if no room) */
  398. return open ? open : QUIVER_START;
  399. }
  400. /**
  401. * Determine which equipment slot (if any) an item likes. The slot might (or
  402. * might not) be open, but it is a slot which the object could be equipped in.
  403. *
  404. * For items where multiple slots could work (e.g. ammo or rings), the function
  405. * will try to a return a stackable slot first (only for ammo), then an open
  406. * slot if possible, and finally a used (but valid) slot if necessary.
  407. */
  408. s16b wield_slot(const object_type * o_ptr)
  409. {
  410. /* Slot for equipment */
  411. switch (o_ptr->tval) {
  412. case TV_DIGGING:
  413. case TV_HAFTED:
  414. case TV_POLEARM:
  415. case TV_SWORD:
  416. return (INVEN_WIELD);
  417. case TV_BOW:
  418. return (INVEN_BOW);
  419. case TV_RING:
  420. return p_ptr->inventory[INVEN_RIGHT].
  421. k_idx ? INVEN_LEFT : INVEN_RIGHT;
  422. case TV_AMULET:
  423. return (INVEN_NECK);
  424. case TV_LIGHT:
  425. return (INVEN_LIGHT);
  426. case TV_DRAG_ARMOR:
  427. case TV_HARD_ARMOR:
  428. case TV_SOFT_ARMOR:
  429. return (INVEN_BODY);
  430. case TV_CLOAK:
  431. return (INVEN_OUTER);
  432. case TV_SHIELD:
  433. return (INVEN_ARM);
  434. case TV_CROWN:
  435. case TV_HELM:
  436. return (INVEN_HEAD);
  437. case TV_GLOVES:
  438. return (INVEN_HANDS);
  439. case TV_BOOTS:
  440. return (INVEN_FEET);
  441. case TV_BOLT:
  442. case TV_ARROW:
  443. case TV_SHOT:
  444. return wield_slot_ammo(o_ptr);
  445. }
  446. /* No slot available */
  447. return (-1);
  448. }
  449. /*
  450. * \returns whether item o_ptr will fit in slot 'slot'
  451. */
  452. bool slot_can_wield_item(int slot, const object_type * o_ptr)
  453. {
  454. if (o_ptr->tval == TV_RING)
  455. return (slot == INVEN_LEFT || slot == INVEN_RIGHT) ? TRUE : FALSE;
  456. else if (obj_is_ammo(o_ptr))
  457. return (slot >= QUIVER_START && slot < QUIVER_END) ? TRUE : FALSE;
  458. else if (wield_slot(o_ptr) == slot)
  459. return TRUE;
  460. else if (of_has(o_ptr->flags_obj, OF_THROWING))
  461. return (slot >= QUIVER_START && slot < QUIVER_END) ? TRUE : FALSE;
  462. else
  463. return FALSE;
  464. }
  465. /*
  466. * Return a string mentioning how a given item is carried
  467. */
  468. const char *mention_use(int slot)
  469. {
  470. char tag[5] = "";
  471. if (slot >= QUIVER_START) {
  472. if (obj_is_ammo(&p_ptr->inventory[slot]))
  473. strnfmt(tag, sizeof(tag), "[f%d]", slot - QUIVER_START);
  474. else if (obj_is_quiver_obj(&p_ptr->inventory[slot]))
  475. strnfmt(tag, sizeof(tag), "[v%d]", slot - QUIVER_START);
  476. }
  477. switch (slot) {
  478. case INVEN_WIELD:
  479. {
  480. if (adj_str_hold[p_ptr->state.stat_ind[A_STR]] <
  481. p_ptr->inventory[slot].weight / 10)
  482. return "Just lifting";
  483. else
  484. return "Wielding";
  485. }
  486. case INVEN_BOW:{
  487. if (adj_str_hold[p_ptr->state.stat_ind[A_STR]] <
  488. p_ptr->inventory[slot].weight / 10)
  489. return "Just holding";
  490. else
  491. return "Shooting";
  492. }
  493. case INVEN_LEFT:
  494. return "On left hand";
  495. case INVEN_RIGHT:
  496. return "On right hand";
  497. case INVEN_NECK:
  498. return "Around neck";
  499. case INVEN_LIGHT:
  500. return "Light source";
  501. case INVEN_BODY:
  502. return "On body";
  503. case INVEN_OUTER:
  504. return "About body";
  505. case INVEN_ARM:
  506. return "On arm";
  507. case INVEN_HEAD:
  508. return "On head";
  509. case INVEN_HANDS:
  510. return "On hands";
  511. case INVEN_FEET:
  512. return "On feet";
  513. case QUIVER_START + 0:
  514. case QUIVER_START + 1:
  515. case QUIVER_START + 2:
  516. case QUIVER_START + 3:
  517. case QUIVER_START + 4:
  518. case QUIVER_START + 5:
  519. case QUIVER_START + 6:
  520. case QUIVER_START + 7:
  521. case QUIVER_START + 8:
  522. case QUIVER_START + 9:
  523. return format("In quiver %s", tag);
  524. }
  525. return "In pack";
  526. }
  527. /*
  528. * Return a string describing how a given item is being worn.
  529. * Currently, only used for items in the equipment, not inventory.
  530. */
  531. const char *describe_use(int i)
  532. {
  533. const char *p;
  534. switch (i) {
  535. case INVEN_WIELD:
  536. p = "attacking monsters with";
  537. break;
  538. case INVEN_BOW:
  539. p = "shooting missiles with";
  540. break;
  541. case INVEN_LEFT:
  542. p = "wearing on your left hand";
  543. break;
  544. case INVEN_RIGHT:
  545. p = "wearing on your right hand";
  546. break;
  547. case INVEN_NECK:
  548. p = "wearing around your neck";
  549. break;
  550. case INVEN_LIGHT:
  551. p = "using to light the way";
  552. break;
  553. case INVEN_BODY:
  554. p = "wearing on your body";
  555. break;
  556. case INVEN_OUTER:
  557. p = "wearing on your back";
  558. break;
  559. case INVEN_ARM:{
  560. if (p_ptr->state.shield_on_back)
  561. p = "carrying on your back";
  562. else
  563. p = "wearing on your arm";
  564. break;
  565. }
  566. case INVEN_HEAD:
  567. p = "wearing on your head";
  568. break;
  569. case INVEN_HANDS:
  570. p = "wearing on your hands";
  571. break;
  572. case INVEN_FEET:
  573. p = "wearing on your feet";
  574. break;
  575. case QUIVER_START + 0:
  576. case QUIVER_START + 1:
  577. case QUIVER_START + 2:
  578. case QUIVER_START + 3:
  579. case QUIVER_START + 4:
  580. case QUIVER_START + 5:
  581. case QUIVER_START + 6:
  582. case QUIVER_START + 7:
  583. case QUIVER_START + 8:
  584. case QUIVER_START + 9:
  585. {
  586. p = "have in your quiver";
  587. break;
  588. }
  589. default:
  590. p = "carrying in your pack";
  591. break;
  592. }
  593. /* Hack -- Heavy weapon */
  594. if (i == INVEN_WIELD) {
  595. object_type *o_ptr;
  596. o_ptr = &p_ptr->inventory[i];
  597. if (adj_str_hold[p_ptr->state.stat_ind[A_STR]] <
  598. o_ptr->weight / 10) {
  599. p = "just lifting";
  600. }
  601. }
  602. /* Hack -- Heavy bow */
  603. if (i == INVEN_BOW) {
  604. object_type *o_ptr;
  605. o_ptr = &p_ptr->inventory[i];
  606. if (adj_str_hold[p_ptr->state.stat_ind[A_STR]] <
  607. o_ptr->weight / 10) {
  608. p = "just holding";
  609. }
  610. }
  611. /* Return the result */
  612. return p;
  613. }
  614. /*
  615. * Check an item against the item tester info
  616. */
  617. bool item_tester_okay(const object_type * o_ptr)
  618. {
  619. /* Hack -- allow listing empty slots */
  620. if (item_tester_full)
  621. return (TRUE);
  622. /* Require an item */
  623. if (!o_ptr->k_idx)
  624. return (FALSE);
  625. /* Hack -- ignore "gold" */
  626. if (o_ptr->tval == TV_GOLD)
  627. return (FALSE);
  628. /* Check the tval */
  629. if (item_tester_tval) {
  630. if (item_tester_tval != o_ptr->tval)
  631. return (FALSE);
  632. }
  633. /* Check the hook */
  634. if (item_tester_hook) {
  635. if (!(*item_tester_hook) (o_ptr))
  636. return (FALSE);
  637. }
  638. /* Assume okay */
  639. return (TRUE);
  640. }
  641. /*
  642. * Get the indexes of objects at a given floor location. -TNB-
  643. *
  644. * Return the number of object indexes acquired.
  645. *
  646. * Valid flags are any combination of the bits:
  647. * 0x01 -- Verify item tester
  648. * 0x02 -- Marked/visible items only
  649. * 0x04 -- Only the top item
  650. */
  651. int scan_floor(int *items, int max_size, int y, int x, int mode)
  652. {
  653. int this_o_idx, next_o_idx;
  654. int num = 0;
  655. /* Sanity */
  656. if (!in_bounds(y, x))
  657. return 0;
  658. /* Scan all objects in the grid */
  659. for (this_o_idx = cave_o_idx[y][x]; this_o_idx;
  660. this_o_idx = next_o_idx) {
  661. object_type *o_ptr;
  662. /* XXX Hack -- Enforce limit */
  663. if (num >= max_size)
  664. break;
  665. /* Get the object */
  666. o_ptr = &o_list[this_o_idx];
  667. /* Get the next object */
  668. next_o_idx = o_ptr->next_o_idx;
  669. /* Item tester */
  670. if ((mode & 0x01) && !item_tester_okay(o_ptr))
  671. continue;
  672. /* Marked */
  673. if ((mode & 0x02) && (!o_ptr->marked || squelch_hide_item(o_ptr)))
  674. continue;
  675. /* Accept this item */
  676. items[num++] = this_o_idx;
  677. /* Only one */
  678. if (mode & 0x04)
  679. break;
  680. }
  681. return num;
  682. }
  683. /*
  684. * Excise a dungeon object from any stacks
  685. */
  686. void excise_object_idx(int o_idx)
  687. {
  688. object_type *j_ptr;
  689. s16b this_o_idx, next_o_idx = 0;
  690. s16b prev_o_idx = 0;
  691. /* Object */
  692. j_ptr = &o_list[o_idx];
  693. /* Monster */
  694. if (j_ptr->held_m_idx) {
  695. monster_type *m_ptr;
  696. /* Monster */
  697. m_ptr = &m_list[j_ptr->held_m_idx];
  698. /* Scan all objects in the grid */
  699. for (this_o_idx = m_ptr->hold_o_idx; this_o_idx;
  700. this_o_idx = next_o_idx) {
  701. object_type *o_ptr;
  702. /* Get the object */
  703. o_ptr = &o_list[this_o_idx];
  704. /* Get the next object */
  705. next_o_idx = o_ptr->next_o_idx;
  706. /* Done */
  707. if (this_o_idx == o_idx) {
  708. /* No previous */
  709. if (prev_o_idx == 0) {
  710. /* Remove from list */
  711. m_ptr->hold_o_idx = next_o_idx;
  712. }
  713. /* Real previous */
  714. else {
  715. object_type *i_ptr;
  716. /* Previous object */
  717. i_ptr = &o_list[prev_o_idx];
  718. /* Remove from list */
  719. i_ptr->next_o_idx = next_o_idx;
  720. }
  721. /* Forget next pointer */
  722. o_ptr->next_o_idx = 0;
  723. /* Done */
  724. break;
  725. }
  726. /* Save prev_o_idx */
  727. prev_o_idx = this_o_idx;
  728. }
  729. }
  730. /* Dungeon */
  731. else {
  732. int y = j_ptr->iy;
  733. int x = j_ptr->ix;
  734. /* Scan all objects in the grid */
  735. for (this_o_idx = cave_o_idx[y][x]; this_o_idx;
  736. this_o_idx = next_o_idx) {
  737. object_type *o_ptr;
  738. /* Get the object */
  739. o_ptr = &o_list[this_o_idx];
  740. /* Get the next object */
  741. next_o_idx = o_ptr->next_o_idx;
  742. /* Done */
  743. if (this_o_idx == o_idx) {
  744. /* No previous */
  745. if (prev_o_idx == 0) {
  746. /* Remove from list */
  747. cave_o_idx[y][x] = next_o_idx;
  748. }
  749. /* Real previous */
  750. else {
  751. object_type *i_ptr;
  752. /* Previous object */
  753. i_ptr = &o_list[prev_o_idx];
  754. /* Remove from list */
  755. i_ptr->next_o_idx = next_o_idx;
  756. }
  757. /* Forget next pointer */
  758. o_ptr->next_o_idx = 0;
  759. /* Done */
  760. break;
  761. }
  762. /* Save prev_o_idx */
  763. prev_o_idx = this_o_idx;
  764. }
  765. }
  766. }
  767. /*
  768. * Delete a dungeon object
  769. *
  770. * Handle "stacks" of objects correctly.
  771. */
  772. void delete_object_idx(int o_idx)
  773. {
  774. object_type *j_ptr;
  775. /* Excise */
  776. excise_object_idx(o_idx);
  777. /* Object */
  778. j_ptr = &o_list[o_idx];
  779. /* Dungeon floor */
  780. if (!(j_ptr->held_m_idx)) {
  781. int y, x;
  782. /* Location */
  783. y = j_ptr->iy;
  784. x = j_ptr->ix;
  785. /* Visual update */
  786. light_spot(y, x);
  787. }
  788. /* Wipe the object */
  789. object_wipe(j_ptr);
  790. /* Count objects */
  791. o_cnt--;
  792. }
  793. /*
  794. * Deletes all objects at given location
  795. */
  796. void delete_object(int y, int x)
  797. {
  798. s16b this_o_idx, next_o_idx = 0;
  799. /* Paranoia */
  800. if (!in_bounds(y, x))
  801. return;
  802. /* Scan all objects in the grid */
  803. for (this_o_idx = cave_o_idx[y][x]; this_o_idx;
  804. this_o_idx = next_o_idx) {
  805. object_type *o_ptr;
  806. /* Get the object */
  807. o_ptr = &o_list[this_o_idx];
  808. /* Get the next object */
  809. next_o_idx = o_ptr->next_o_idx;
  810. /* Wipe the object */
  811. object_wipe(o_ptr);
  812. /* Count objects */
  813. o_cnt--;
  814. }
  815. /* Objects are gone */ cave_o_idx[y][x] = 0;
  816. /* Visual update */
  817. light_spot(y, x);
  818. }
  819. /*
  820. * Move an object from index i1 to index i2 in the object list
  821. */
  822. static void compact_objects_aux(int i1, int i2)
  823. {
  824. int i;
  825. object_type *o_ptr;
  826. /* Do nothing */
  827. if (i1 == i2)
  828. return;
  829. /* Repair objects */
  830. for (i = 1; i < o_max; i++) {
  831. /* Get the object */
  832. o_ptr = &o_list[i];
  833. /* Skip "dead" objects */
  834. if (!o_ptr->k_idx)
  835. continue;
  836. /* Repair "next" pointers */
  837. if (o_ptr->next_o_idx == i1) {
  838. /* Repair */
  839. o_ptr->next_o_idx = i2;
  840. }
  841. }
  842. /* Get the object */ o_ptr = &o_list[i1];
  843. /* Monster */
  844. if (o_ptr->held_m_idx) {
  845. monster_type *m_ptr;
  846. /* Get the monster */
  847. m_ptr = &m_list[o_ptr->held_m_idx];
  848. /* Repair monster */
  849. if (m_ptr->hold_o_idx == i1) {
  850. /* Repair */
  851. m_ptr->hold_o_idx = i2;
  852. }
  853. }
  854. /* Dungeon */
  855. else {
  856. int y, x;
  857. /* Get location */
  858. y = o_ptr->iy;
  859. x = o_ptr->ix;
  860. /* Repair grid */
  861. if (cave_o_idx[y][x] == i1) {
  862. /* Repair */
  863. cave_o_idx[y][x] = i2;
  864. }
  865. }
  866. /* Hack -- move object */
  867. COPY(&o_list[i2], &o_list[i1], object_type);
  868. /* Hack -- wipe hole */
  869. object_wipe(o_ptr);
  870. }
  871. /*
  872. * Compact and reorder the object list
  873. *
  874. * This function can be very dangerous, use with caution!
  875. *
  876. * When compacting objects, we first destroy gold, on the basis that by the
  877. * time item compaction becomes an issue, the player really won't care.
  878. * We also nuke items marked as squelch.
  879. *
  880. * When compacting other objects, we base the saving throw on a combination of
  881. * object level, distance from player, and current "desperation".
  882. *
  883. * After compacting, we "reorder" the objects into a more compact order, and we
  884. * reset the allocation info, and the "live" array.
  885. */
  886. void compact_objects(int size)
  887. {
  888. int py = p_ptr->py;
  889. int px = p_ptr->px;
  890. int i, y, x, cnt;
  891. int cur_lev, cur_dis, chance;
  892. /* Reorder objects when not passed a size */
  893. if (!size) {
  894. /* Excise dead objects (backwards!) */
  895. for (i = o_max - 1; i >= 1; i--) {
  896. object_type *o_ptr = &o_list[i];
  897. /* Skip real objects */
  898. if (o_ptr->k_idx)
  899. continue;
  900. /* Move last object into open hole */
  901. compact_objects_aux(o_max - 1, i);
  902. /* Compress "o_max" */
  903. o_max--;
  904. }
  905. return;
  906. }
  907. /* Message */
  908. msg("Compacting objects...");
  909. /*** Try destroying objects ***/
  910. /* First do gold */
  911. for (i = 1; (i < o_max) && (size); i++) {
  912. object_type *o_ptr = &o_list[i];
  913. /* Nuke gold or squelched items */
  914. if (o_ptr->tval == TV_GOLD || squelch_item_ok(o_ptr)) {
  915. delete_object_idx(i);
  916. size--;
  917. }
  918. }
  919. /* Compact at least 'size' objects */
  920. for (cnt = 1; size; cnt++) {
  921. /* Get more vicious each iteration */
  922. cur_lev = 5 * cnt;
  923. /* Get closer each iteration */
  924. cur_dis = 5 * (20 - cnt);
  925. /* Examine the objects */
  926. for (i = 1; (i < o_max) && (size); i++) {
  927. object_type *o_ptr = &o_list[i];
  928. object_kind *k_ptr = &k_info[o_ptr->k_idx];
  929. /* Skip dead objects */
  930. if (!o_ptr->k_idx)
  931. continue;
  932. /* Hack -- High level objects start out "immune" */
  933. if (k_ptr->level > cur_lev && !k_ptr->squelch)
  934. continue;
  935. /* Monster */
  936. if (o_ptr->held_m_idx) {
  937. monster_type *m_ptr;
  938. /* Get the monster */
  939. m_ptr = &m_list[o_ptr->held_m_idx];
  940. /* Get the location */
  941. y = m_ptr->fy;
  942. x = m_ptr->fx;
  943. /* Monsters protect their objects */
  944. if ((randint0(100) < 90) && !k_ptr->squelch)
  945. continue;
  946. }
  947. /* Dungeon */
  948. else {
  949. /* Get the location */
  950. y = o_ptr->iy;
  951. x = o_ptr->ix;
  952. }
  953. /* Nearby objects start out "immune" */
  954. if ((cur_dis > 0) && (distance(py, px, y, x) < cur_dis)
  955. && !k_ptr->squelch)
  956. continue;
  957. /* Saving throw */
  958. chance = 90;
  959. /* Hack -- only compact artifacts in emergencies */
  960. if (artifact_p(o_ptr) && (cnt < 1000))
  961. chance = 100;
  962. /* Apply the saving throw */
  963. if (randint0(100) < chance)
  964. continue;
  965. /* Delete the object */
  966. delete_object_idx(i);
  967. size--;
  968. }
  969. }
  970. /* Reorder objects */
  971. compact_objects(0);
  972. }
  973. /*
  974. * Delete all the items when player leaves the level
  975. *
  976. * Note -- we do NOT visually reflect these (irrelevant) changes
  977. *
  978. * Hack -- we clear the "cave_o_idx[y][x]" field for every grid,
  979. * and the "m_ptr->next_o_idx" field for every monster, since
  980. * we know we are clearing every object. Technically, we only
  981. * clear those fields for grids/monsters containing objects,
  982. * and we clear it once for every such object.
  983. */
  984. void wipe_o_list(void)
  985. {
  986. int i;
  987. /* Delete the existing objects */
  988. for (i = 1; i < o_max; i++) {
  989. object_type *o_ptr = &o_list[i];
  990. /* Skip dead objects */
  991. if (!o_ptr->k_idx)
  992. continue;
  993. /* Hack -- Preserve unknown artifacts */
  994. if (artifact_p(o_ptr) && !object_known_p(o_ptr)) {
  995. /* Mega-Hack -- Preserve the artifact */
  996. a_info[o_ptr->name1].created = FALSE;
  997. }
  998. /* Monster */
  999. if (o_ptr->held_m_idx) {
  1000. monster_type *m_ptr;
  1001. /* Monster */
  1002. m_ptr = &m_list[o_ptr->held_m_idx];
  1003. /* Hack -- see above */
  1004. m_ptr->hold_o_idx = 0;
  1005. }
  1006. /* Dungeon */
  1007. else {
  1008. /* Get the location */
  1009. int y = o_ptr->iy;
  1010. int x = o_ptr->ix;
  1011. /* Hack -- see above */
  1012. cave_o_idx[y][x] = 0;
  1013. }
  1014. /* Wipe the object */
  1015. (void) WIPE(o_ptr, object_type);
  1016. }
  1017. /* Reset "o_max" */
  1018. o_max = 1;
  1019. /* Reset "o_cnt" */
  1020. o_cnt = 0;
  1021. }
  1022. /*
  1023. * Get and return the index of a "free" object.
  1024. *
  1025. * This routine should almost never fail, but in case it does,
  1026. * we must be sure to handle "failure" of this routine.
  1027. */
  1028. s16b o_pop(void)
  1029. {
  1030. int i;
  1031. /* Initial allocation */
  1032. if (o_max < z_info->o_max) {
  1033. /* Get next space */
  1034. i = o_max;
  1035. /* Expand object array */
  1036. o_max++;
  1037. /* Count objects */
  1038. o_cnt++;
  1039. /* Use this object */
  1040. return (i);
  1041. }
  1042. /* Recycle dead objects */
  1043. for (i = 1; i < o_max; i++) {
  1044. object_type *o_ptr;
  1045. /* Get the object */
  1046. o_ptr = &o_list[i];
  1047. /* Skip live objects */
  1048. if (o_ptr->k_idx)
  1049. continue;
  1050. /* Count objects */
  1051. o_cnt++;
  1052. /* Use this object */
  1053. return (i);
  1054. }
  1055. /* Warn the player (except during dungeon creation) */
  1056. if (character_dungeon)
  1057. msg("Too many objects!");
  1058. /* Oops */
  1059. return (0);
  1060. }
  1061. /*
  1062. * Get the first object at a dungeon location
  1063. * or NULL if there isn't one.
  1064. */
  1065. object_type *get_first_object(int y, int x)
  1066. {
  1067. s16b o_idx = cave_o_idx[y][x];
  1068. if (o_idx)
  1069. return (&o_list[o_idx]);
  1070. /* No object */
  1071. return (NULL);
  1072. }
  1073. /*
  1074. * Get the next object in a stack or NULL if there isn't one.
  1075. */
  1076. object_type *get_next_object(const object_type * o_ptr)
  1077. {
  1078. if (o_ptr->next_o_idx)
  1079. return (&o_list[o_ptr->next_o_idx]);
  1080. /* No more objects */
  1081. return (NULL);
  1082. }
  1083. /**
  1084. * Return the "value" of an "unknown" item
  1085. * Make a guess at the value of non-aware items
  1086. */
  1087. static s32b object_value_base(const object_type * o_ptr)
  1088. {
  1089. object_kind *k_ptr = &k_info[o_ptr->k_idx];
  1090. /* For most items, the "aware" value is simply that of the object kind. */
  1091. s32b aware_cost = k_ptr->cost;
  1092. /* Because weapons and ammo may have enhanced damage dice, their aware
  1093. * value may vary. -LM- */
  1094. switch (o_ptr->tval) {
  1095. case TV_SHOT:
  1096. case TV_ARROW:
  1097. case TV_BOLT:
  1098. {
  1099. if (o_ptr->ds > k_ptr->ds) {
  1100. aware_cost +=
  1101. (1 + o_ptr->ds - k_ptr->ds) * (2 + o_ptr->ds -
  1102. k_ptr->ds) * 1L;
  1103. }
  1104. if (o_ptr->dd > k_ptr->dd) {
  1105. aware_cost +=
  1106. (1 + o_ptr->dd - k_ptr->dd) * (2 + o_ptr->dd -
  1107. k_ptr->dd) * 1L;
  1108. }
  1109. break;
  1110. }
  1111. case TV_HAFTED:
  1112. case TV_POLEARM:
  1113. case TV_SWORD:
  1114. {
  1115. if (o_ptr->ds > k_ptr->ds) {
  1116. aware_cost +=
  1117. (o_ptr->ds - k_ptr->ds) * (o_ptr->ds -
  1118. k_ptr->ds) * o_ptr->dd *
  1119. o_ptr->dd * 16L;
  1120. }
  1121. if (o_ptr->dd > k_ptr->dd) {
  1122. aware_cost +=
  1123. (o_ptr->dd - k_ptr->dd) * (o_ptr->ds -
  1124. k_ptr->dd) * o_ptr->ds *
  1125. o_ptr->ds * 16L;
  1126. }
  1127. break;
  1128. }
  1129. }
  1130. /* Aware item -- use template cost, modified by enhanced dice if needed. */
  1131. if (object_aware_p(o_ptr))
  1132. return (aware_cost);
  1133. /* Analyze the type */
  1134. switch (o_ptr->tval) {
  1135. /* Un-aware Food */
  1136. case TV_FOOD:
  1137. return (5L);
  1138. /* Un-aware Potions */
  1139. case TV_POTION:
  1140. return (20L);
  1141. /* Un-aware Scrolls */
  1142. case TV_SCROLL:
  1143. return (20L);
  1144. /* Un-aware Staffs */
  1145. case TV_STAFF:
  1146. return (80L);
  1147. /* Un-aware Wands */
  1148. case TV_WAND:
  1149. return (80L);
  1150. /* Un-aware Rods */
  1151. case TV_ROD:
  1152. return (200L);
  1153. /* Un-aware Rings (shouldn't happen) */
  1154. case TV_RING:
  1155. return (45L);
  1156. /* Un-aware Amulets (shouldn't happen) */
  1157. case TV_AMULET:
  1158. return (45L);
  1159. }
  1160. /* Paranoia -- Oops */
  1161. return (0L);
  1162. }
  1163. /**
  1164. * Return the "real" price of a "known" item, not including discounts
  1165. *
  1166. * Wand and staffs get cost for each charge
  1167. *
  1168. * Armor is worth an extra 100 gold per bonus point to armor class.
  1169. *
  1170. * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).
  1171. *
  1172. * Missiles are only worth 5 gold per bonus point, since they
  1173. * usually appear in groups of 20, and we want the player to get
  1174. * the same amount of cash for any "equivalent" item. Note that
  1175. * missiles never have any of the "pval" flags, and in fact, they
  1176. * only have a few of the available flags, primarily of the "slay"
  1177. * and "brand" and "ignore" variety.
  1178. *
  1179. * Now reworked to handle all item properties -NRM-
  1180. */
  1181. static s32b object_value_real(const object_type * o_ptr)
  1182. {
  1183. int i;
  1184. s32b value;
  1185. object_kind *k_ptr = &k_info[o_ptr->k_idx];
  1186. /* Hack -- "worthless" items */
  1187. if (!k_ptr->cost)
  1188. return (0L);
  1189. /* Base cost */
  1190. value = k_ptr->cost;
  1191. /* Artifact */
  1192. if (o_ptr->name1) {
  1193. artifact_type *a_ptr = &a_info[o_ptr->name1];
  1194. /* Hack -- Use the artifact cost instead */
  1195. return (a_ptr->cost);
  1196. }
  1197. /* Ego-Item */
  1198. else if (has_ego_properties(o_ptr)) {
  1199. ego_item_type *e_ptr = &e_info[o_ptr->name2];
  1200. /* Hack -- Reward the ego-item with a bonus */
  1201. value += e_ptr->cost;
  1202. }
  1203. /* Analyze resists, bonuses and multiples */
  1204. switch (o_ptr->tval) {
  1205. case TV_BOW:
  1206. case TV_DIGGING:
  1207. case TV_HAFTED:
  1208. case TV_POLEARM:
  1209. case TV_SWORD:
  1210. case TV_BOOTS:
  1211. case TV_GLOVES:
  1212. case TV_HELM:
  1213. case TV_CROWN:
  1214. case TV_SHIELD:
  1215. case TV_CLOAK:
  1216. case TV_SOFT_ARMOR:
  1217. case TV_HARD_ARMOR:
  1218. case TV_DRAG_ARMOR:
  1219. case TV_LIGHT:
  1220. case TV_AMULET:
  1221. case TV_RING:
  1222. {
  1223. /* Give credit for resists */
  1224. if (if_has(o_ptr->id_other, IF_RES_ACID))
  1225. value +=
  1226. (RES_LEVEL_BASE -
  1227. o_ptr->percent_res[P_RES_ACID]) * 60L;
  1228. if (if_has(o_ptr->id_other, IF_RES_ELEC))
  1229. value +=
  1230. (RES_LEVEL_BASE -
  1231. o_ptr->percent_res[P_RES_ELEC]) * 60L;
  1232. if (if_has(o_ptr->id_other, IF_RES_FIRE))
  1233. value +=
  1234. (RES_LEVEL_BASE -
  1235. o_ptr->percent_res[P_RES_FIRE]) * 60L;
  1236. if (if_has(o_ptr->id_other, IF_RES_COLD))
  1237. value +=
  1238. (RES_LEVEL_BASE -
  1239. o_ptr->percent_res[P_RES_COLD]) * 60L;
  1240. if (if_has(o_ptr->id_other, IF_RES_POIS))
  1241. value +=
  1242. (RES_LEVEL_BASE -
  1243. o_ptr->percent_res[P_RES_POIS]) * 120L;
  1244. if (if_has(o_ptr->id_other, IF_RES_LIGHT))
  1245. value +=
  1246. (RES_LEVEL_BASE -
  1247. o_ptr->percent_res[P_RES_LIGHT]) * 60L;
  1248. if (if_has(o_ptr->id_other, IF_RES_DARK))
  1249. value +=
  1250. (RES_LEVEL_BASE -
  1251. o_ptr->percent_res[P_RES_DARK]) * 60L;
  1252. if (if_has(o_ptr->id_other, IF_RES_CONFU))
  1253. value +=
  1254. (RES_LEVEL_BASE -
  1255. o_ptr->percent_res[P_RES_CONFU]) * 90L;
  1256. if (if_has(o_ptr->id_other, IF_RES_SOUND))
  1257. value +=
  1258. (RES_LEVEL_BASE -
  1259. o_ptr->percent_res[P_RES_SOUND]) * 60L;
  1260. if (if_has(o_ptr->id_other, IF_RES_SHARD))
  1261. value +=
  1262. (RES_LEVEL_BASE -
  1263. o_ptr->percent_res[P_RES_SHARD]) * 60L;
  1264. if (if_has(o_ptr->id_other, IF_RES_NEXUS))
  1265. value +=
  1266. (RES_LEVEL_BASE -
  1267. o_ptr->percent_res[P_RES_NEXUS]) * 60L;
  1268. if (if_has(o_ptr->id_other, IF_RES_NETHR))
  1269. value +=
  1270. (RES_LEVEL_BASE -
  1271. o_ptr->percent_res[P_RES_NETHR]) * 90L;
  1272. if (if_has(o_ptr->id_other, IF_RES_CHAOS))
  1273. value +=
  1274. (RES_LEVEL_BASE -
  1275. o_ptr->percent_res[P_RES_CHAOS]) * 90L;
  1276. if (if_has(o_ptr->id_other, IF_RES_DISEN))
  1277. value +=
  1278. (RES_LEVEL_BASE -
  1279. o_ptr->percent_res[P_RES_DISEN]) * 120L;
  1280. /* Wearing shows all bonuses */
  1281. if (o_ptr->ident & IDENT_WORN) {
  1282. /* Give credit for stat bonuses. */
  1283. for (i = 0; i < A_MAX; i++) {
  1284. if (o_ptr->bonus_stat[i] > BONUS_BASE)
  1285. value +=
  1286. (((o_ptr->bonus_stat[i] +
  1287. 1) * (o_ptr->bonus_stat[i] + 1)) * 100L);
  1288. else if (o_ptr->bonus_stat[i] < BONUS_BASE)
  1289. value -=
  1290. (o_ptr->bonus_stat[i] * o_ptr->bonus_stat[i] *
  1291. 100L);
  1292. }
  1293. /* Give credit for magic items bonus. */
  1294. value += (o_ptr->bonus_other[P_BONUS_M_MASTERY] * 600L);
  1295. /* Give credit for stealth and searching */
  1296. value += (o_ptr->bonus_other[P_BONUS_STEALTH] * 100L);
  1297. value += (o_ptr->bonus_other[P_BONUS_SEARCH] * 40L);
  1298. /* Give credit for infra-vision */
  1299. value += (o_ptr->bonus_other[P_BONUS_INFRA] * 50L);
  1300. /* Give credit for tunneling bonus above that which a digger
  1301. * possesses intrinsically. */
  1302. value +=
  1303. ((o_ptr->bonus_other[P_BONUS_TUNNEL] -
  1304. k_ptr->bonus_other[P_BONUS_TUNNEL]) * 50L);
  1305. /* Give credit for speed bonus. Formula changed to avoid
  1306. * excessively valuable low-speed items. */
  1307. if (o_ptr->bonus_other[P_BONUS_SPEED] > 0)
  1308. value +=
  1309. (o_ptr->bonus_other[P_BONUS_SPEED] *
  1310. o_ptr->bonus_other[P_BONUS_SPEED] * 5000L);
  1311. else if (o_ptr->bonus_other[P_BONUS_SPEED] < 0)
  1312. value -=
  1313. (o_ptr->bonus_other[P_BONUS_SPEED] *
  1314. o_ptr->bonus_other[P_BONUS_SPEED] * 2000L);
  1315. /* Give credit for extra shots */
  1316. value += (o_ptr->bonus_other[P_BONUS_SHOTS] * 8000L);
  1317. /* Give credit for extra might */
  1318. value += (o_ptr->bonus_other[P_BONUS_MIGHT] * 6000L);
  1319. }
  1320. /* Give credit for slays */
  1321. if (if_has(o_ptr->id_other, IF_SLAY_ANIMAL))
  1322. value +=
  1323. (o_ptr->multiple_slay[P_SLAY_ANIMAL] -
  1324. MULTIPLE_BASE) * 150L;
  1325. if (if_has(o_ptr->id_other, IF_SLAY_EVIL))
  1326. value +=
  1327. (o_ptr->multiple_slay[P_SLAY_EVIL] -
  1328. MULTIPLE_BASE) * 500L;
  1329. if (if_has(o_ptr->id_other, IF_SLAY_UNDEAD))
  1330. value +=
  1331. (o_ptr->multiple_slay[P_SLAY_UNDEAD] -
  1332. MULTIPLE_BASE) * 200L;
  1333. if (if_has(o_ptr->id_other, IF_SLAY_DEMON))
  1334. value +=
  1335. (o_ptr->multiple_slay[P_SLAY_DEMON] -
  1336. MULTIPLE_BASE) * 200L;
  1337. if (if_has(o_ptr->id_other, IF_SLAY_ORC))
  1338. value +=
  1339. (o_ptr->multiple_slay[P_SLAY_ORC] -
  1340. MULTIPLE_BASE) * 100L;
  1341. if (if_has(o_ptr->id_other, IF_SLAY_TROLL))
  1342. value +=
  1343. (o_ptr->multiple_slay[P_SLAY_TROLL] -
  1344. MULTIPLE_BASE) * 150L;
  1345. if (if_has(o_ptr->id_other, IF_SLAY_GIANT))
  1346. value +=
  1347. (o_ptr->multiple_slay[P_SLAY_GIANT] -
  1348. MULTIPLE_BASE) * 100L;
  1349. if (if_has(o_ptr->id_other, IF_SLAY_DRAGON))
  1350. value +=
  1351. (o_ptr->multiple_slay[P_SLAY_DRAGON] -
  1352. MULTIPLE_BASE) * 200L;
  1353. /* Give credit for brands */
  1354. if (if_has(o_ptr->id_other, IF_BRAND_ACID))
  1355. value +=
  1356. (o_ptr->multiple_brand[P_BRAND_ACID] -
  1357. MULTIPLE_BASE) * 300L;
  1358. if (if_has(o_ptr->id_other, IF_BRAND_ELEC))
  1359. value +=
  1360. (o_ptr->multiple_brand[P_BRAND_ELEC] -
  1361. MULTIPLE_BASE) * 300L;
  1362. if (if_has(o_ptr->id_other, IF_BRAND_FIRE))
  1363. value +=
  1364. (o_ptr->multiple_brand[P_BRAND_FIRE] -
  1365. MULTIPLE_BASE) * 200L;
  1366. if (if_has(o_ptr->id_other, IF_BRAND_COLD))
  1367. value +=
  1368. (o_ptr->multiple_brand[P_BRAND_COLD] -
  1369. MULTIPLE_BASE) * 200L;
  1370. if (if_has(o_ptr->id_other, IF_BRAND_POIS))
  1371. value +=
  1372. (o_ptr->multiple_brand[P_BRAND_POIS] -
  1373. MULTIPLE_BASE) * 150L;
  1374. /* Give credit for object flags */
  1375. if (of_has(o_ptr->id_obj, OF_SUSTAIN_STR))
  1376. value += 500L;
  1377. if (of_has(o_ptr->id_obj, OF_SUSTAIN_INT))
  1378. value += 300L;
  1379. if (of_has(o_ptr->id_obj, OF_SUSTAIN_WIS))
  1380. value += 300L;
  1381. if (of_has(o_ptr->id_obj, OF_SUSTAIN_DEX))
  1382. value += 400L;
  1383. if (of_has(o_ptr->id_obj, OF_SUSTAIN_CON))
  1384. value += 400L;
  1385. if (of_has(o_ptr->id_obj, OF_SUSTAIN_CHR))
  1386. value += 50L;
  1387. if (of_has(o_ptr->id_obj, OF_SLOW_DIGEST))
  1388. value += 200L;
  1389. if (of_has(o_ptr->id_obj, OF_FEATHER))
  1390. value += 200L;
  1391. if (of_has(o_ptr->id_obj, OF_REGEN))
  1392. value += 400L;
  1393. if (of_has(o_ptr->id_obj, OF_TELEPATHY))
  1394. value += 5000L;
  1395. if (of_has(o_ptr->id_obj, OF_SEE_INVIS))
  1396. value += 700L;
  1397. if (of_has(o_ptr->id_obj, OF_FREE_ACT))
  1398. value += 800L;
  1399. if (of_has(o_ptr->id_obj, OF_HOLD_LIFE))
  1400. value += 700L;
  1401. if (of_has(o_ptr->id_obj, OF_SEEING))
  1402. value += 700L;
  1403. if (of_has(o_ptr->id_obj, OF_FEARLESS))
  1404. value += 500L;
  1405. if (of_has(o_ptr->id_obj, OF_LIGHT))
  1406. value += 300L;
  1407. if (of_has(o_ptr->id_obj, OF_BLESSED))
  1408. value += 1000L;
  1409. if (of_has(o_ptr->id_obj, OF_IMPACT))
  1410. value += 50L;
  1411. if (of_has(o_ptr->id_obj, OF_ACID_PROOF))
  1412. value += 100L;
  1413. if (of_has(o_ptr->id_obj, OF_ELEC_PROOF))
  1414. value += 100L;
  1415. if (of_has(o_ptr->id_obj, OF_FIRE_PROOF))
  1416. value += 100L;
  1417. if (of_has(o_ptr->id_obj, OF_COLD_PROOF))
  1418. value += 100L;
  1419. if (of_has(o_ptr->id_obj, OF_DARKNESS))
  1420. value += 1000L;
  1421. /* Give 'credit' for curse flags */
  1422. if (cf_has(o_ptr->id_curse, CF_TELEPORT))
  1423. value -= 200L;
  1424. if (cf_has(o_ptr->id_curse, CF_NO_TELEPORT))
  1425. value -= 1000L;
  1426. if (cf_has(o_ptr->id_curse, CF_AGGRO_PERM))
  1427. value -= 2000L;
  1428. if (cf_has(o_ptr->id_curse, CF_AGGRO_RAND))
  1429. value -= 700L;
  1430. if (cf_has(o_ptr->id_curse, CF_SLOW_REGEN))
  1431. value -= 200L;
  1432. if (cf_has(o_ptr->id_curse, CF_AFRAID))
  1433. value -= 500L;
  1434. if (cf_has(o_ptr->id_curse, CF_HUNGRY))
  1435. value -= 200L;
  1436. if (cf_has(o_ptr->id_curse, CF_POIS_RAND))
  1437. value -= 200L;
  1438. if (cf_has(o_ptr->id_curse, CF_POIS_RAND_BAD))
  1439. value -= 500L;
  1440. if (cf_has(o_ptr->id_curse, CF_CUT_RAND))
  1441. value -= 200L;
  1442. if (cf_has(o_ptr->id_curse, CF_CUT_RAND_BAD))
  1443. value -= 400L;
  1444. if (cf_has(o_ptr->id_curse, CF_HALLU_RAND))
  1445. value -= 800L;
  1446. if (cf_has(o_ptr->id_curse, CF_DROP_WEAPON))
  1447. value -= 500L;
  1448. if (cf_has(o_ptr->id_curse, CF_ATTRACT_DEMON))
  1449. value -= 800L;
  1450. if (cf_has(o_ptr->id_curse, CF_ATTRACT_UNDEAD))
  1451. value -= 900L;
  1452. if (cf_has(o_ptr->id_curse, CF_STICKY_WIELD))
  1453. value -= 2500L;
  1454. if (cf_has(o_ptr->id_curse, CF_STICKY_CARRY))
  1455. value -= 1000L;
  1456. if (cf_has(o_ptr->id_curse, CF_PARALYZE))
  1457. value -= 800L;
  1458. if (cf_has(o_ptr->id_curse, CF_PARALYZE_ALL))
  1459. value -= 2000L;
  1460. if (cf_has(o_ptr->id_curse, CF_DRAIN_EXP))
  1461. value -= 800L;
  1462. if (cf_has(o_ptr->id_curse, CF_DRAIN_MANA))
  1463. value -= 1000L;
  1464. if (cf_has(o_ptr->id_curse, CF_DRAIN_STAT))
  1465. value -= 1500L;
  1466. if (cf_has(o_ptr->id_curse, CF_DRAIN_CHARGE))
  1467. value -= 1500L;
  1468. break;
  1469. }
  1470. case TV_SHOT:
  1471. case TV_ARROW:
  1472. case TV_BOLT:
  1473. {
  1474. /* Give credit for slays */
  1475. if (if_has(o_ptr->id_other, IF_SLAY_ANIMAL))
  1476. value +=
  1477. (o_ptr->multiple_slay[P_SLAY_ANIMAL] -
  1478. MULTIPLE_BASE) * 15L;
  1479. if (if_has(o_ptr->id_other, IF_SLAY_EVIL))
  1480. value +=
  1481. (o_ptr->multiple_slay[P_SLAY_EVIL] -
  1482. MULTIPLE_BASE) * 50L;
  1483. if (if_has(o_ptr->id_other, IF_SLAY_UNDEAD))
  1484. value +=
  1485. (o_ptr->multiple_slay[P_SLAY_UNDEAD] -
  1486. MULTIPLE_BASE) * 20L;
  1487. if (if_has(o_ptr->id_other, IF_SLAY_DEMON))
  1488. value +=
  1489. (o_ptr->multiple_slay[P_SLAY_DEMON] -
  1490. MULTIPLE_BASE) * 20L;
  1491. if (if_has(o_ptr->id_other, IF_SLAY_ORC))
  1492. value +=
  1493. (o_ptr->multiple_slay[P_SLAY_ORC] -
  1494. MULTIPLE_BASE) * 10L;
  1495. if (if_has(o_ptr->id_other, IF_SLAY_TROLL))
  1496. value +=
  1497. (o_ptr->multiple_slay[P_SLAY_TROLL] -
  1498. MULTIPLE_BASE) * 15L;
  1499. if (if_has(o_ptr->id_other, IF_SLAY_GIANT))
  1500. value +=
  1501. (o_ptr->multiple_slay[P_SLAY_GIANT] -
  1502. MULTIPLE_BASE) * 10L;
  1503. if (if_has(o_ptr->id_other, IF_SLAY_DRAGON))
  1504. value +=
  1505. (o_ptr->multiple_slay[P_SLAY_DRAGON] -
  1506. MULTIPLE_BASE) * 20L;
  1507. /* Give credit for brands */
  1508. if (if_has(o_ptr->id_other, IF_BRAND_ACID))
  1509. value +=
  1510. (o_ptr->multiple_brand[P_BRAND_ACID] -
  1511. MULTIPLE_BASE) * 30L;
  1512. if (if_has(o_ptr->id_other, IF_BRAND_ELEC))
  1513. value +=
  1514. (o_ptr->multiple_brand[P_BRAND_ELEC] -
  1515. MULTIPLE_BASE) * 30L;
  1516. if (if_has(o_ptr->id_other, IF_BRAND_FIRE))
  1517. value +=
  1518. (o_ptr->multiple_brand[P_BRAND_FIRE] -
  1519. MULTIPLE_BASE) * 20L;
  1520. if (if_has(o_ptr->id_other, IF_BRAND_COLD))
  1521. value +=
  1522. (o_ptr->multiple_brand[P_BRAND_COLD] -
  1523. MULTIPLE_BASE) * 20L;
  1524. if (if_has(o_ptr->id_other, IF_BRAND_POIS))
  1525. value +=
  1526. (o_ptr->multiple_brand[P_BRAND_POIS] -
  1527. MULTIPLE_BASE) * 15L;
  1528. break;
  1529. }
  1530. }
  1531. /* Analyze the item */
  1532. switch (o_ptr->tval) {
  1533. /* Wands/Staffs */
  1534. case TV_WAND:
  1535. {
  1536. int temp_pval = randcalc(k_ptr->pval, k_ptr->level, RANDOMISE);
  1537. /* Pay extra for charges, depending on standard number of charges.
  1538. * Handle new-style wands correctly. */
  1539. value +=
  1540. (value * o_ptr->pval / o_ptr->number / (temp_pval * 2));
  1541. /* Done */
  1542. break;
  1543. }
  1544. case TV_STAFF:
  1545. {
  1546. /* Pay extra for charges, depending on standard number of charges */
  1547. int temp_pval = randcalc(k_ptr->pval, k_ptr->level, RANDOMISE);
  1548. value += (value * o_ptr->pval / (temp_pval * 2));
  1549. /* Done */
  1550. break;
  1551. }
  1552. /* Rings/Amulets */
  1553. case TV_RING:
  1554. case TV_AMULET:
  1555. {
  1556. /* Give credit for bonuses */
  1557. if (if_has(o_ptr->id_other, IF_TO_H))
  1558. value += o_ptr->to_h * 100L;
  1559. if (if_has(o_ptr->id_other, IF_TO_D))
  1560. value += o_ptr->to_d * 100L;
  1561. if (if_has(o_ptr->id_other, IF_TO_A))
  1562. value += o_ptr->to_a * 100L;
  1563. /* Done */
  1564. break;
  1565. }
  1566. /* Armor */
  1567. case TV_BOOTS:
  1568. case TV_GLOVES:
  1569. case TV_CLOAK:
  1570. case TV_CROWN:
  1571. case TV_HELM:
  1572. case TV_SHIELD:
  1573. case TV_SOFT_ARMOR:
  1574. case TV_HARD_ARMOR:
  1575. case TV_DRAG_ARMOR:
  1576. {
  1577. /* If it differs from the object kind's base armour Skill penalty
  1578. * (this penalty must be in the range +0 to -12), give a debit or
  1579. * credit for any modification to Skill. -LM- */
  1580. if (((o_ptr->to_h != k_ptr->to_h.base) || (o_ptr->to_h < -12)
  1581. || (o_ptr->to_h > 0))
  1582. && (if_has(o_ptr->id_other, IF_TO_H)))
  1583. value += (o_ptr->to_h * 100L);
  1584. /* Standard debit or credit for to_d and to_a bonuses. */
  1585. if (if_has(o_ptr->id_other, IF_TO_D))
  1586. value += (o_ptr->to_d) * 100L;
  1587. if (if_has(o_ptr->id_other, IF_TO_A))
  1588. value += (o_ptr->to_a) * 100L;
  1589. /* Done */
  1590. break;
  1591. }
  1592. /* Sharp weapons */
  1593. case TV_DIGGING:
  1594. case TV_SWORD:
  1595. case TV_POLEARM:
  1596. {
  1597. /* Blessed */
  1598. if (of_has(o_ptr->id_obj, OF_BLESSED))
  1599. value += 400L;
  1600. /* Fall through */
  1601. }
  1602. /* Bows/Weapons */
  1603. case TV_BOW:
  1604. case TV_HAFTED:
  1605. {
  1606. /* Because +to_hit and +to_dam work differently now, this formula
  1607. * also needed to change. Although long, it now yields results
  1608. * that match the increase in the weapon's combat power. -LM- */
  1609. int hit = (if_has(o_ptr->id_other, IF_TO_H)) ? o_ptr->to_h : 0;
  1610. int dam = (if_has(o_ptr->id_other, IF_TO_D)) ? o_ptr->to_d : 0;
  1611. int arm = (if_has(o_ptr->id_other, IF_TO_A)) ? o_ptr->to_a : 0;
  1612. value +=
  1613. (((hit + 10) * (dam + 10) - 100) * (k_ptr->cost +
  1614. 1000L) / 250) +
  1615. (arm * 100);
  1616. /* Hack -- Factor in improved damage dice. If you want to buy one
  1617. * of the truly dangerous weapons, be prepared to pay for it. */
  1618. if ((o_ptr->ds > k_ptr->ds) && (o_ptr->dd == k_ptr->dd)
  1619. && (if_has(o_ptr->id_other, IF_DD_DS))) {
  1620. value += (o_ptr->ds - k_ptr->ds) * (o_ptr->ds - k_ptr->ds)
  1621. * o_ptr->dd * o_ptr->dd * 16L;
  1622. /* Naturally, ego-items with high base dice should be very
  1623. * expensive. */
  1624. if (has_ego_properties(o_ptr)) {
  1625. value += (5 * value / 2);
  1626. }
  1627. }
  1628. /* Give credit for perfect balance. */
  1629. if (of_has(o_ptr->id_obj, OF_PERFECT_BALANCE))
  1630. value += o_ptr->dd * 200L;
  1631. /* Done */
  1632. break;
  1633. }
  1634. /* Ammo */
  1635. case TV_SHOT:
  1636. case TV_ARROW:
  1637. case TV_BOLT:
  1638. {
  1639. /* Factor in the bonuses */
  1640. if (if_has(o_ptr->id_other, IF_TO_H))
  1641. value += o_ptr->to_h * 2L;
  1642. if (if_has(o_ptr->id_other, IF_TO_D))
  1643. value += o_ptr->to_d * 2L;
  1644. /* Hack -- Factor in improved damage dice. -LM- */
  1645. if ((o_ptr->ds > k_ptr->ds)
  1646. && (if_has(o_ptr->id_other, IF_DD_DS))) {
  1647. value +=
  1648. (1 + o_ptr->ds - k_ptr->ds) * (2 + o_ptr->ds -
  1649. k_ptr->ds) * 1L;
  1650. /* Naturally, ego-items with high base dice should be
  1651. * expensive. */
  1652. if (has_ego_properties(o_ptr)) {
  1653. value += (5 * value / 2);
  1654. }
  1655. }
  1656. /* Done */
  1657. break;
  1658. }
  1659. /* Who wants an empty chest? */
  1660. case TV_CHEST:
  1661. {
  1662. if (o_ptr->pval == 0)
  1663. return (0L);
  1664. break;
  1665. }
  1666. }
  1667. /* Return the value */
  1668. return (value < 0 ? 0L : value);
  1669. }
  1670. /**
  1671. * Return the price of an item including plusses (and charges)
  1672. *
  1673. * This function returns the "value" of the given item (qty one)
  1674. *
  1675. * Never notice "unknown" bonuses or properties, including "curses",
  1676. * since that would give the player information he did not have.
  1677. *
  1678. * Note that discounted items stay discounted forever, even if
  1679. * the discount is "forgotten" by the player via memory loss.
  1680. */
  1681. s32b object_value(const object_type * o_ptr)
  1682. {
  1683. s32b value;
  1684. /* Known items -- acquire the actual value */
  1685. if (object_known_p(o_ptr)
  1686. || ((wield_slot(o_ptr) > 0) && !artifact_p(o_ptr))) {
  1687. /* Real value (see above) */
  1688. value = object_value_real(o_ptr);
  1689. }
  1690. /* Unknown items -- acquire a base value */
  1691. else {
  1692. /* Base value (see above) */
  1693. value = object_value_base(o_ptr);
  1694. }
  1695. /* Apply discount (if any) */
  1696. if (o_ptr->discount)
  1697. value -= (value * o_ptr->discount / 100L);
  1698. /* Return the final value */
  1699. return (value);
  1700. }
  1701. /*
  1702. * Determine if an item can "absorb" a second item
  1703. *
  1704. * See "object_absorb()" for the actual "absorption" code.
  1705. *
  1706. * If permitted, we allow weapons/armor to stack, if "known".
  1707. *
  1708. * Missiles will combine if both stacks have the same "known" status.
  1709. * This is done to make unidentified stacks of missiles useful.
  1710. *
  1711. * Food, potions, scrolls, and "easy know" items always stack.
  1712. *
  1713. * Chests, and activatable items, except rods, never stack (for various
  1714. * reasons).
  1715. */
  1716. bool object_similar(const object_type * o_ptr, const object_type * j_ptr,
  1717. object_stack_t mode)
  1718. {
  1719. int i;
  1720. int total = o_ptr->number + j_ptr->number;
  1721. /* Check against stacking limit */
  1722. if (total >= MAX_STACK_SIZE)
  1723. return FALSE;
  1724. /* Hack -- identical items cannot be stacked */
  1725. if (o_ptr == j_ptr)
  1726. return FALSE;
  1727. /* Require identical object kinds */
  1728. if (o_ptr->k_idx != j_ptr->k_idx)
  1729. return FALSE;
  1730. /* Require identical effects */
  1731. if (o_ptr->effect != j_ptr->effect)
  1732. return (FALSE);
  1733. /* Different flags don't stack */
  1734. if (!of_is_equal(o_ptr->flags_obj, j_ptr->flags_obj))
  1735. return FALSE;
  1736. if (!cf_is_equal(o_ptr->flags_curse, j_ptr->flags_curse))
  1737. return FALSE;
  1738. /* Require identical resists, etc */
  1739. for (i = 0; i < MAX_P_RES; i++)
  1740. if (o_ptr->percent_res[i] != j_ptr->percent_res[i])
  1741. return (FALSE);
  1742. for (i = 0; i < A_MAX; i++)
  1743. if (o_ptr->bonus_stat[i] != j_ptr->bonus_stat[i])
  1744. return (FALSE);
  1745. for (i = 0; i < MAX_P_BONUS; i++)
  1746. if (o_ptr->bonus_other[i] != j_ptr->bonus_other[i])
  1747. return (FALSE);
  1748. for (i = 0; i < MAX_P_SLAY; i++)
  1749. if (o_ptr->multiple_slay[i] != j_ptr->multiple_slay[i])
  1750. return (FALSE);
  1751. for (i = 0; i < MAX_P_BRAND; i++)
  1752. if (o_ptr->multiple_brand[i] != j_ptr->multiple_brand[i])
  1753. return (FALSE);
  1754. /* Artifacts never stack */
  1755. if (o_ptr->name1 || j_ptr->name1)
  1756. return FALSE;
  1757. /* Analyze the items */
  1758. switch (o_ptr->tval) {
  1759. /* Chests never stack */
  1760. case TV_CHEST:
  1761. {
  1762. /* Never okay */
  1763. return FALSE;
  1764. }
  1765. /* Food, potions, scrolls and rods all stack nicely */
  1766. case TV_FOOD:
  1767. case TV_POTION:
  1768. case TV_SCROLL:
  1769. case TV_ROD:
  1770. {
  1771. /* Since the kinds are identical, either both will be aware or both
  1772. * will be unaware */
  1773. break;
  1774. }
  1775. /* Gold, staves and wands stack most of the time */
  1776. case TV_STAFF:
  1777. case TV_WAND:
  1778. case TV_GOLD:
  1779. {
  1780. /* Too much gold or too many charges */
  1781. if (o_ptr->pval + j_ptr->pval > MAX_PVAL)
  1782. return FALSE;
  1783. /* ... otherwise ok */
  1784. else
  1785. break;
  1786. }
  1787. /* Weapons, ammo, armour, jewelry, lights */
  1788. case TV_BOW:
  1789. case TV_DIGGING:
  1790. case TV_HAFTED:
  1791. case TV_POLEARM:
  1792. case TV_SWORD:
  1793. case TV_BOOTS:
  1794. case TV_GLOVES:
  1795. case TV_HELM:
  1796. case TV_CROWN:
  1797. case TV_SHIELD:
  1798. case TV_CLOAK:
  1799. case TV_SOFT_ARMOR:
  1800. case TV_HARD_ARMOR:
  1801. case TV_DRAG_ARMOR:
  1802. case TV_RING:
  1803. case TV_AMULET:
  1804. case TV_LIGHT:
  1805. case TV_BOLT:
  1806. case TV_ARROW:
  1807. case TV_SHOT:
  1808. {
  1809. /* Require identical values */
  1810. if (o_ptr->ac != j_ptr->ac)
  1811. return FALSE;
  1812. if (o_ptr->dd != j_ptr->dd)
  1813. return FALSE;
  1814. if (o_ptr->ds != j_ptr->ds)
  1815. return FALSE;
  1816. /* Require identical bonuses */
  1817. if (o_ptr->to_h != j_ptr->to_h)
  1818. return FALSE;
  1819. if (o_ptr->to_d != j_ptr->to_d)
  1820. return FALSE;
  1821. if (o_ptr->to_a != j_ptr->to_a)
  1822. return FALSE;
  1823. /* Require identical pval */
  1824. if (o_ptr->pval != j_ptr->pval)
  1825. return (FALSE);
  1826. /* Require identical ego-item types */
  1827. if (o_ptr->name2 != j_ptr->name2)
  1828. return (FALSE);
  1829. /* Hack - Never stack recharging wearables ... */
  1830. if ((o_ptr->timeout || j_ptr->timeout)
  1831. && (o_ptr->tval != TV_LIGHT))
  1832. return FALSE;
  1833. /* ... and lights must have same amount of fuel */
  1834. else if ((o_ptr->timeout != j_ptr->timeout)
  1835. && (o_ptr->tval == TV_LIGHT))
  1836. return FALSE;
  1837. /* Probably okay */
  1838. break;
  1839. }
  1840. /* Anything else */
  1841. default:
  1842. {
  1843. /* Require knowledge */
  1844. //if (!object_known_p(o_ptr) || !object_known_p(j_ptr))
  1845. //return (FALSE);
  1846. /* Probably okay */
  1847. break;
  1848. }
  1849. }
  1850. /* Hack -- Require compatible inscriptions */

Large files files are truncated, but you can click here to view the full file