/src/obj-util.c
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
- /*
- * File: obj-util.c
- * Purpose: Object list maintenance and other object utilities
- *
- * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
- *
- * This work is free software; you can redistribute it and/or modify it
- * under the terms of either:
- *
- * a) the GNU General Public License as published by the Free Software
- * Foundation, version 2, or
- *
- * b) the "Angband licence":
- * This software may be copied and distributed for educational, research,
- * and not for profit purposes provided that this copyright and statement
- * are included in all such copies. Other copyrights may also apply.
- */
- #include "angband.h"
- #include "cave.h"
- #include "defines.h"
- #include "effects.h"
- #include "game-cmd.h"
- #include "generate.h"
- #include "history.h"
- #include "prefs.h"
- #include "randname.h"
- #include "spells.h"
- #include "squelch.h"
- #include "tvalsval.h"
- /*
- * Hold the titles of scrolls, 6 to 14 characters each, plus quotes.
- */
- char scroll_adj[MAX_TITLES][18];
- static void flavor_assign_fixed(void)
- {
- int i, j;
- for (i = 0; i < z_info->flavor_max; i++) {
- flavor_type *flavor_ptr = &flavor_info[i];
- /* Skip random flavors */
- if (flavor_ptr->sval == SV_UNKNOWN)
- continue;
- for (j = 0; j < z_info->k_max; j++) {
- /* Skip other objects */
- if ((k_info[j].tval == flavor_ptr->tval)
- && (k_info[j].sval == flavor_ptr->sval)) {
- /* Store the flavor index */
- k_info[j].flavor = i;
- }
- }
- }
- }
- static void flavor_assign_random(byte tval)
- {
- int i, j;
- int flavor_count = 0;
- int choice;
- /* Count the random flavors for the given tval */
- for (i = 0; i < z_info->flavor_max; i++) {
- if ((flavor_info[i].tval == tval)
- && (flavor_info[i].sval == SV_UNKNOWN)) {
- flavor_count++;
- }
- }
- for (i = 0; i < z_info->k_max; i++) {
- /* Skip other object types */
- if (k_info[i].tval != tval)
- continue;
- /* Skip objects that already are flavored */
- if (k_info[i].flavor != 0)
- continue;
- /* HACK - Ordinary food is "boring" */
- if ((tval == TV_FOOD) && (k_info[i].sval >= SV_FOOD_MIN_FOOD))
- continue;
- if (!flavor_count)
- quit_fmt("Not enough flavors for tval %d.", tval);
- /* Select a flavor */
- choice = randint0(flavor_count);
- /* Find and store the flavor */
- for (j = 0; j < z_info->flavor_max; j++) {
- /* Skip other tvals */
- if (flavor_info[j].tval != tval)
- continue;
- /* Skip assigned svals */
- if (flavor_info[j].sval != SV_UNKNOWN)
- continue;
- if (choice == 0) {
- /* Store the flavor index */
- k_info[i].flavor = j;
- /* Mark the flavor as used */
- flavor_info[j].sval = k_info[i].sval;
- /* Hack - set the scroll name if it's a scroll */
- if (tval == TV_SCROLL) {
- flavor_info[j].text = scroll_adj[k_info[i].sval];
- }
- /* One less flavor to choose from */
- flavor_count--;
- break;
- }
- choice--;
- }
- }
- }
- /*
- * Prepare the "variable" part of the "k_info" array.
- *
- * The "color"/"metal"/"type" of an item is its "flavor".
- * For the most part, flavors are assigned randomly each game.
- *
- * Initialize descriptions for the "colored" objects, including:
- * Rings, Amulets, Staffs, Wands, Rods, Food, Potions, Scrolls.
- *
- * The first 4 entries for potions are fixed (Water, Apple Juice,
- * Slime Mold Juice, Unused Potion).
- *
- * Scroll titles are always between 6 and 14 letters long. This is
- * ensured because every title is composed of whole words, where every
- * word is from 2 to 8 letters long, and that no scroll is finished
- * until it attempts to grow beyond 15 letters. The first time this
- * can happen is when the current title has 6 letters and the new word
- * has 8 letters, which would result in a 6 letter scroll title.
- *
- * Hack -- make sure everything stays the same for each saved game
- * This is accomplished by the use of a saved "random seed", as in
- * "town_gen()". Since no other functions are called while the special
- * seed is in effect, so this function is pretty "safe".
- */
- void flavor_init(void)
- {
- int i, j;
- /* Hack -- Use the "simple" RNG */
- Rand_quick = TRUE;
- /* Hack -- Induce consistant flavors */
- Rand_value = seed_flavor;
- flavor_assign_fixed();
- flavor_assign_random(TV_STAFF);
- flavor_assign_random(TV_WAND);
- flavor_assign_random(TV_ROD);
- flavor_assign_random(TV_FOOD);
- flavor_assign_random(TV_POTION);
- /* Scrolls (random titles, always white) */
- for (i = 0; i < MAX_TITLES; i++) {
- char buf[26] = "\"";
- char *end = buf + 1;
- int titlelen = 0;
- int wordlen;
- bool okay = TRUE;
- wordlen =
- randname_make(RANDNAME_SCROLL, 2, 8, end, 24, name_sections);
- while (titlelen + wordlen < (int) (sizeof(scroll_adj[0]) - 3)) {
- end[wordlen] = ' ';
- titlelen += wordlen + 1;
- end += wordlen + 1;
- wordlen =
- randname_make(RANDNAME_SCROLL, 2, 8, end, 24 - titlelen,
- name_sections);
- }
- buf[titlelen] = '"';
- buf[titlelen + 1] = '\0';
- /* Check the scroll name hasn't already been generated */
- for (j = 0; j < i; j++) {
- if (streq(buf, scroll_adj[j])) {
- okay = FALSE;
- break;
- }
- }
- if (okay) {
- my_strcpy(scroll_adj[i], buf, sizeof(scroll_adj[0]));
- } else {
- /* Have another go at making a name */
- i--;
- }
- }
- flavor_assign_random(TV_SCROLL);
- /* Hack -- Use the "complex" RNG */
- Rand_quick = FALSE;
- /* Analyze every object */
- for (i = 1; i < z_info->k_max; i++) {
- object_kind *k_ptr = &k_info[i];
- /* Skip "empty" objects */
- if (!k_ptr->name)
- continue;
- /* No flavor yields aware */
- if (!k_ptr->flavor)
- k_ptr->aware = TRUE;
- }
- }
- /**
- * Get the inventory color for an object.
- *
- * Hack - set the listing color of a spellbook with no useable spells
- * to grey -LM-
- */
- byte proc_list_color_hack(object_type * o_ptr)
- {
- /* Hack -- Spellbooks with no useable spells are grey. */
- if ((mp_ptr->spell_book == o_ptr->tval)
- && (mp_ptr->book_start_index[o_ptr->sval] ==
- mp_ptr->book_start_index[o_ptr->sval + 1])) {
- return (TERM_SLATE);
- }
- /* Otherwise, get the color normally. */
- else
- return (tval_to_attr[o_ptr->tval]);
- }
- #ifdef ALLOW_BORG_GRAPHICS
- extern void init_translate_visuals(void);
- #endif /* ALLOW_BORG_GRAPHICS */
- /*
- * Reset the "visual" lists
- *
- * This involves resetting various things to their "default" state.
- *
- * If the "prefs" flag is TRUE, then we will also load the appropriate
- * "user pref file" based on the current setting of the "use_graphics"
- * flag. This is useful for switching "graphics" on/off.
- */
- /* XXX this does not belong here */
- void reset_visuals(bool load_prefs)
- {
- int i;
- /* Extract default attr/char code for features */
- for (i = 0; i < z_info->f_max; i++) {
- int j;
- feature_type *f_ptr = &f_info[i];
- /* Assume we will use the underlying values */
- for (j = 0; j < FEAT_LIGHTING_MAX; j++) {
- f_ptr->x_attr[j] = f_ptr->d_attr;
- f_ptr->x_char[j] = f_ptr->d_char;
- }
- }
- /* Extract default attr/char code for objects */
- for (i = 0; i < z_info->k_max; i++) {
- object_kind *k_ptr = &k_info[i];
- /* Default attr/char */
- k_ptr->x_attr = k_ptr->d_attr;
- k_ptr->x_char = k_ptr->d_char;
- }
- /* Extract default attr/char code for monsters */
- for (i = 0; i < z_info->r_max; i++) {
- monster_race *r_ptr = &r_info[i];
- /* Default attr/char */
- r_ptr->x_attr = r_ptr->d_attr;
- r_ptr->x_char = r_ptr->d_char;
- }
- /* Extract default attr/char code for flavors */
- for (i = 0; i < z_info->flavor_max; i++) {
- flavor_type *flavor_ptr = &flavor_info[i];
- /* Default attr/char */
- flavor_ptr->x_attr = flavor_ptr->d_attr;
- flavor_ptr->x_char = flavor_ptr->d_char;
- }
- /* Extract attr/chars for inventory objects (by tval) */
- for (i = 0; i < (int) N_ELEMENTS(tval_to_attr); i++) {
- /* Default to white */
- tval_to_attr[i] = TERM_WHITE;
- }
- if (!load_prefs)
- return;
- /* Graphic symbols */
- if (use_graphics) {
- /* Process "graf.prf" */
- process_pref_file("graf.prf", FALSE, FALSE);
- }
- /* Normal symbols */
- else {
- /* Process "font.prf" */
- process_pref_file("font.prf", FALSE, FALSE);
- }
- #ifdef ALLOW_BORG_GRAPHICS
- /* Initialize the translation table for the borg */
- init_translate_visuals();
- #endif /* ALLOW_BORG_GRAPHICS */
- }
- /*
- * Convert an inventory index into a one character label.
- *
- * Note that the label does NOT distinguish inven/equip.
- */
- char index_to_label(int i)
- {
- /* Indexes for "inven" are easy */
- if (i < INVEN_WIELD)
- return (I2A(i));
- /* Indexes for "equip" are offset */
- return (I2A(i - INVEN_WIELD));
- }
- /*
- * Convert a label into the index of an item in the "inven".
- *
- * Return "-1" if the label does not indicate a real item.
- */
- s16b label_to_inven(int c)
- {
- int i;
- /* Convert */
- i = (islower((unsigned char) c) ? A2I(c) : -1);
- /* Verify the index */
- if ((i < 0) || (i > INVEN_PACK))
- return (-1);
- /* Empty slots can never be chosen */
- if (!p_ptr->inventory[i].k_idx)
- return (-1);
- /* Return the index */
- return (i);
- }
- /*
- * Convert a label into the index of a item in the "equip".
- *
- * Return "-1" if the label does not indicate a real item.
- */
- s16b label_to_equip(int c)
- {
- int i;
- /* Convert */
- i = (islower((unsigned char) c) ? A2I(c) : -1) + INVEN_WIELD;
- /* Verify the index */
- if ((i < INVEN_WIELD) || (i >= ALL_INVEN_TOTAL) || (i == INVEN_TOTAL))
- return (-1);
- /* Empty slots can never be chosen */
- if (!p_ptr->inventory[i].k_idx)
- return (-1);
- /* Return the index */
- return (i);
- }
- /*
- * Hack -- determine if an item is "wearable" (or a missile)
- */
- bool wearable_p(const object_type * o_ptr)
- {
- /* Valid "tval" codes */
- switch (o_ptr->tval) {
- case TV_SHOT:
- case TV_ARROW:
- case TV_BOLT:
- case TV_BOW:
- case TV_DIGGING:
- case TV_HAFTED:
- case TV_POLEARM:
- case TV_SWORD:
- case TV_BOOTS:
- case TV_GLOVES:
- case TV_HELM:
- case TV_CROWN:
- case TV_SHIELD:
- case TV_CLOAK:
- case TV_SOFT_ARMOR:
- case TV_HARD_ARMOR:
- case TV_DRAG_ARMOR:
- case TV_LIGHT:
- case TV_AMULET:
- case TV_RING:
- return (TRUE);
- }
- /* Nope */
- return (FALSE);
- }
- int get_inscribed_ammo_slot(const object_type * o_ptr)
- {
- char *s = NULL, *t = NULL;
- if (!o_ptr->note)
- return 0;
- s = strchr(quark_str(o_ptr->note), 'v');
- t = strchr(quark_str(o_ptr->note), 'f');
- /* Prefer throwing weapons */
- if (s && (s[1] >= '0') && (s[1] <= '9'))
- return QUIVER_START + (s[1] - '0');
- else if (t && (t[1] >= '0') && (t[1] <= '9'))
- return QUIVER_START + (t[1] - '0');
- return 0;
- }
- /**
- * Used by wield_slot() to find an appopriate slot for ammo. See wield_slot()
- * for information on what this returns.
- */
- s16b wield_slot_ammo(const object_type * o_ptr)
- {
- s16b i, open = 0;
- /* If the ammo is inscribed with a slot number, we'll try to put it in */
- /* that slot, if possible. */
- i = get_inscribed_ammo_slot(o_ptr);
- if (i && !p_ptr->inventory[i].k_idx)
- return i;
- for (i = QUIVER_START; i < QUIVER_END; i++) {
- if (!p_ptr->inventory[i].k_idx) {
- /* Save the open slot if we haven't found one already */
- if (!open)
- open = i;
- continue;
- }
- /* If ammo is cursed we can't stack it */
- if (cf_has(p_ptr->inventory[i].flags_curse, CF_STICKY_WIELD))
- continue;
- /* If they are stackable, we'll use this slot for sure */
- if (object_similar(&p_ptr->inventory[i], o_ptr, OSTACK_QUIVER))
- return i;
- }
- /* If not absorbed, return an open slot (or QUIVER_START if no room) */
- return open ? open : QUIVER_START;
- }
- /**
- * Determine which equipment slot (if any) an item likes. The slot might (or
- * might not) be open, but it is a slot which the object could be equipped in.
- *
- * For items where multiple slots could work (e.g. ammo or rings), the function
- * will try to a return a stackable slot first (only for ammo), then an open
- * slot if possible, and finally a used (but valid) slot if necessary.
- */
- s16b wield_slot(const object_type * o_ptr)
- {
- /* Slot for equipment */
- switch (o_ptr->tval) {
- case TV_DIGGING:
- case TV_HAFTED:
- case TV_POLEARM:
- case TV_SWORD:
- return (INVEN_WIELD);
- case TV_BOW:
- return (INVEN_BOW);
- case TV_RING:
- return p_ptr->inventory[INVEN_RIGHT].
- k_idx ? INVEN_LEFT : INVEN_RIGHT;
- case TV_AMULET:
- return (INVEN_NECK);
- case TV_LIGHT:
- return (INVEN_LIGHT);
- case TV_DRAG_ARMOR:
- case TV_HARD_ARMOR:
- case TV_SOFT_ARMOR:
- return (INVEN_BODY);
- case TV_CLOAK:
- return (INVEN_OUTER);
- case TV_SHIELD:
- return (INVEN_ARM);
- case TV_CROWN:
- case TV_HELM:
- return (INVEN_HEAD);
- case TV_GLOVES:
- return (INVEN_HANDS);
- case TV_BOOTS:
- return (INVEN_FEET);
- case TV_BOLT:
- case TV_ARROW:
- case TV_SHOT:
- return wield_slot_ammo(o_ptr);
- }
- /* No slot available */
- return (-1);
- }
- /*
- * \returns whether item o_ptr will fit in slot 'slot'
- */
- bool slot_can_wield_item(int slot, const object_type * o_ptr)
- {
- if (o_ptr->tval == TV_RING)
- return (slot == INVEN_LEFT || slot == INVEN_RIGHT) ? TRUE : FALSE;
- else if (obj_is_ammo(o_ptr))
- return (slot >= QUIVER_START && slot < QUIVER_END) ? TRUE : FALSE;
- else if (wield_slot(o_ptr) == slot)
- return TRUE;
- else if (of_has(o_ptr->flags_obj, OF_THROWING))
- return (slot >= QUIVER_START && slot < QUIVER_END) ? TRUE : FALSE;
- else
- return FALSE;
- }
- /*
- * Return a string mentioning how a given item is carried
- */
- const char *mention_use(int slot)
- {
- char tag[5] = "";
- if (slot >= QUIVER_START) {
- if (obj_is_ammo(&p_ptr->inventory[slot]))
- strnfmt(tag, sizeof(tag), "[f%d]", slot - QUIVER_START);
- else if (obj_is_quiver_obj(&p_ptr->inventory[slot]))
- strnfmt(tag, sizeof(tag), "[v%d]", slot - QUIVER_START);
- }
- switch (slot) {
- case INVEN_WIELD:
- {
- if (adj_str_hold[p_ptr->state.stat_ind[A_STR]] <
- p_ptr->inventory[slot].weight / 10)
- return "Just lifting";
- else
- return "Wielding";
- }
- case INVEN_BOW:{
- if (adj_str_hold[p_ptr->state.stat_ind[A_STR]] <
- p_ptr->inventory[slot].weight / 10)
- return "Just holding";
- else
- return "Shooting";
- }
- case INVEN_LEFT:
- return "On left hand";
- case INVEN_RIGHT:
- return "On right hand";
- case INVEN_NECK:
- return "Around neck";
- case INVEN_LIGHT:
- return "Light source";
- case INVEN_BODY:
- return "On body";
- case INVEN_OUTER:
- return "About body";
- case INVEN_ARM:
- return "On arm";
- case INVEN_HEAD:
- return "On head";
- case INVEN_HANDS:
- return "On hands";
- case INVEN_FEET:
- return "On feet";
- case QUIVER_START + 0:
- case QUIVER_START + 1:
- case QUIVER_START + 2:
- case QUIVER_START + 3:
- case QUIVER_START + 4:
- case QUIVER_START + 5:
- case QUIVER_START + 6:
- case QUIVER_START + 7:
- case QUIVER_START + 8:
- case QUIVER_START + 9:
- return format("In quiver %s", tag);
- }
- return "In pack";
- }
- /*
- * Return a string describing how a given item is being worn.
- * Currently, only used for items in the equipment, not inventory.
- */
- const char *describe_use(int i)
- {
- const char *p;
- switch (i) {
- case INVEN_WIELD:
- p = "attacking monsters with";
- break;
- case INVEN_BOW:
- p = "shooting missiles with";
- break;
- case INVEN_LEFT:
- p = "wearing on your left hand";
- break;
- case INVEN_RIGHT:
- p = "wearing on your right hand";
- break;
- case INVEN_NECK:
- p = "wearing around your neck";
- break;
- case INVEN_LIGHT:
- p = "using to light the way";
- break;
- case INVEN_BODY:
- p = "wearing on your body";
- break;
- case INVEN_OUTER:
- p = "wearing on your back";
- break;
- case INVEN_ARM:{
- if (p_ptr->state.shield_on_back)
- p = "carrying on your back";
- else
- p = "wearing on your arm";
- break;
- }
- case INVEN_HEAD:
- p = "wearing on your head";
- break;
- case INVEN_HANDS:
- p = "wearing on your hands";
- break;
- case INVEN_FEET:
- p = "wearing on your feet";
- break;
- case QUIVER_START + 0:
- case QUIVER_START + 1:
- case QUIVER_START + 2:
- case QUIVER_START + 3:
- case QUIVER_START + 4:
- case QUIVER_START + 5:
- case QUIVER_START + 6:
- case QUIVER_START + 7:
- case QUIVER_START + 8:
- case QUIVER_START + 9:
- {
- p = "have in your quiver";
- break;
- }
- default:
- p = "carrying in your pack";
- break;
- }
- /* Hack -- Heavy weapon */
- if (i == INVEN_WIELD) {
- object_type *o_ptr;
- o_ptr = &p_ptr->inventory[i];
- if (adj_str_hold[p_ptr->state.stat_ind[A_STR]] <
- o_ptr->weight / 10) {
- p = "just lifting";
- }
- }
- /* Hack -- Heavy bow */
- if (i == INVEN_BOW) {
- object_type *o_ptr;
- o_ptr = &p_ptr->inventory[i];
- if (adj_str_hold[p_ptr->state.stat_ind[A_STR]] <
- o_ptr->weight / 10) {
- p = "just holding";
- }
- }
- /* Return the result */
- return p;
- }
- /*
- * Check an item against the item tester info
- */
- bool item_tester_okay(const object_type * o_ptr)
- {
- /* Hack -- allow listing empty slots */
- if (item_tester_full)
- return (TRUE);
- /* Require an item */
- if (!o_ptr->k_idx)
- return (FALSE);
- /* Hack -- ignore "gold" */
- if (o_ptr->tval == TV_GOLD)
- return (FALSE);
- /* Check the tval */
- if (item_tester_tval) {
- if (item_tester_tval != o_ptr->tval)
- return (FALSE);
- }
- /* Check the hook */
- if (item_tester_hook) {
- if (!(*item_tester_hook) (o_ptr))
- return (FALSE);
- }
- /* Assume okay */
- return (TRUE);
- }
- /*
- * Get the indexes of objects at a given floor location. -TNB-
- *
- * Return the number of object indexes acquired.
- *
- * Valid flags are any combination of the bits:
- * 0x01 -- Verify item tester
- * 0x02 -- Marked/visible items only
- * 0x04 -- Only the top item
- */
- int scan_floor(int *items, int max_size, int y, int x, int mode)
- {
- int this_o_idx, next_o_idx;
- int num = 0;
- /* Sanity */
- if (!in_bounds(y, x))
- return 0;
- /* Scan all objects in the grid */
- for (this_o_idx = cave_o_idx[y][x]; this_o_idx;
- this_o_idx = next_o_idx) {
- object_type *o_ptr;
- /* XXX Hack -- Enforce limit */
- if (num >= max_size)
- break;
- /* Get the object */
- o_ptr = &o_list[this_o_idx];
- /* Get the next object */
- next_o_idx = o_ptr->next_o_idx;
- /* Item tester */
- if ((mode & 0x01) && !item_tester_okay(o_ptr))
- continue;
- /* Marked */
- if ((mode & 0x02) && (!o_ptr->marked || squelch_hide_item(o_ptr)))
- continue;
- /* Accept this item */
- items[num++] = this_o_idx;
- /* Only one */
- if (mode & 0x04)
- break;
- }
- return num;
- }
- /*
- * Excise a dungeon object from any stacks
- */
- void excise_object_idx(int o_idx)
- {
- object_type *j_ptr;
- s16b this_o_idx, next_o_idx = 0;
- s16b prev_o_idx = 0;
- /* Object */
- j_ptr = &o_list[o_idx];
- /* Monster */
- if (j_ptr->held_m_idx) {
- monster_type *m_ptr;
- /* Monster */
- m_ptr = &m_list[j_ptr->held_m_idx];
- /* Scan all objects in the grid */
- for (this_o_idx = m_ptr->hold_o_idx; this_o_idx;
- this_o_idx = next_o_idx) {
- object_type *o_ptr;
- /* Get the object */
- o_ptr = &o_list[this_o_idx];
- /* Get the next object */
- next_o_idx = o_ptr->next_o_idx;
- /* Done */
- if (this_o_idx == o_idx) {
- /* No previous */
- if (prev_o_idx == 0) {
- /* Remove from list */
- m_ptr->hold_o_idx = next_o_idx;
- }
- /* Real previous */
- else {
- object_type *i_ptr;
- /* Previous object */
- i_ptr = &o_list[prev_o_idx];
- /* Remove from list */
- i_ptr->next_o_idx = next_o_idx;
- }
- /* Forget next pointer */
- o_ptr->next_o_idx = 0;
- /* Done */
- break;
- }
- /* Save prev_o_idx */
- prev_o_idx = this_o_idx;
- }
- }
- /* Dungeon */
- else {
- int y = j_ptr->iy;
- int x = j_ptr->ix;
- /* Scan all objects in the grid */
- for (this_o_idx = cave_o_idx[y][x]; this_o_idx;
- this_o_idx = next_o_idx) {
- object_type *o_ptr;
- /* Get the object */
- o_ptr = &o_list[this_o_idx];
- /* Get the next object */
- next_o_idx = o_ptr->next_o_idx;
- /* Done */
- if (this_o_idx == o_idx) {
- /* No previous */
- if (prev_o_idx == 0) {
- /* Remove from list */
- cave_o_idx[y][x] = next_o_idx;
- }
- /* Real previous */
- else {
- object_type *i_ptr;
- /* Previous object */
- i_ptr = &o_list[prev_o_idx];
- /* Remove from list */
- i_ptr->next_o_idx = next_o_idx;
- }
- /* Forget next pointer */
- o_ptr->next_o_idx = 0;
- /* Done */
- break;
- }
- /* Save prev_o_idx */
- prev_o_idx = this_o_idx;
- }
- }
- }
- /*
- * Delete a dungeon object
- *
- * Handle "stacks" of objects correctly.
- */
- void delete_object_idx(int o_idx)
- {
- object_type *j_ptr;
- /* Excise */
- excise_object_idx(o_idx);
- /* Object */
- j_ptr = &o_list[o_idx];
- /* Dungeon floor */
- if (!(j_ptr->held_m_idx)) {
- int y, x;
- /* Location */
- y = j_ptr->iy;
- x = j_ptr->ix;
- /* Visual update */
- light_spot(y, x);
- }
- /* Wipe the object */
- object_wipe(j_ptr);
- /* Count objects */
- o_cnt--;
- }
- /*
- * Deletes all objects at given location
- */
- void delete_object(int y, int x)
- {
- s16b this_o_idx, next_o_idx = 0;
- /* Paranoia */
- if (!in_bounds(y, x))
- return;
- /* Scan all objects in the grid */
- for (this_o_idx = cave_o_idx[y][x]; this_o_idx;
- this_o_idx = next_o_idx) {
- object_type *o_ptr;
- /* Get the object */
- o_ptr = &o_list[this_o_idx];
- /* Get the next object */
- next_o_idx = o_ptr->next_o_idx;
- /* Wipe the object */
- object_wipe(o_ptr);
- /* Count objects */
- o_cnt--;
- }
- /* Objects are gone */ cave_o_idx[y][x] = 0;
- /* Visual update */
- light_spot(y, x);
- }
- /*
- * Move an object from index i1 to index i2 in the object list
- */
- static void compact_objects_aux(int i1, int i2)
- {
- int i;
- object_type *o_ptr;
- /* Do nothing */
- if (i1 == i2)
- return;
- /* Repair objects */
- for (i = 1; i < o_max; i++) {
- /* Get the object */
- o_ptr = &o_list[i];
- /* Skip "dead" objects */
- if (!o_ptr->k_idx)
- continue;
- /* Repair "next" pointers */
- if (o_ptr->next_o_idx == i1) {
- /* Repair */
- o_ptr->next_o_idx = i2;
- }
- }
- /* Get the object */ o_ptr = &o_list[i1];
- /* Monster */
- if (o_ptr->held_m_idx) {
- monster_type *m_ptr;
- /* Get the monster */
- m_ptr = &m_list[o_ptr->held_m_idx];
- /* Repair monster */
- if (m_ptr->hold_o_idx == i1) {
- /* Repair */
- m_ptr->hold_o_idx = i2;
- }
- }
- /* Dungeon */
- else {
- int y, x;
- /* Get location */
- y = o_ptr->iy;
- x = o_ptr->ix;
- /* Repair grid */
- if (cave_o_idx[y][x] == i1) {
- /* Repair */
- cave_o_idx[y][x] = i2;
- }
- }
- /* Hack -- move object */
- COPY(&o_list[i2], &o_list[i1], object_type);
- /* Hack -- wipe hole */
- object_wipe(o_ptr);
- }
- /*
- * Compact and reorder the object list
- *
- * This function can be very dangerous, use with caution!
- *
- * When compacting objects, we first destroy gold, on the basis that by the
- * time item compaction becomes an issue, the player really won't care.
- * We also nuke items marked as squelch.
- *
- * When compacting other objects, we base the saving throw on a combination of
- * object level, distance from player, and current "desperation".
- *
- * After compacting, we "reorder" the objects into a more compact order, and we
- * reset the allocation info, and the "live" array.
- */
- void compact_objects(int size)
- {
- int py = p_ptr->py;
- int px = p_ptr->px;
- int i, y, x, cnt;
- int cur_lev, cur_dis, chance;
- /* Reorder objects when not passed a size */
- if (!size) {
- /* Excise dead objects (backwards!) */
- for (i = o_max - 1; i >= 1; i--) {
- object_type *o_ptr = &o_list[i];
- /* Skip real objects */
- if (o_ptr->k_idx)
- continue;
- /* Move last object into open hole */
- compact_objects_aux(o_max - 1, i);
- /* Compress "o_max" */
- o_max--;
- }
- return;
- }
- /* Message */
- msg("Compacting objects...");
- /*** Try destroying objects ***/
- /* First do gold */
- for (i = 1; (i < o_max) && (size); i++) {
- object_type *o_ptr = &o_list[i];
- /* Nuke gold or squelched items */
- if (o_ptr->tval == TV_GOLD || squelch_item_ok(o_ptr)) {
- delete_object_idx(i);
- size--;
- }
- }
- /* Compact at least 'size' objects */
- for (cnt = 1; size; cnt++) {
- /* Get more vicious each iteration */
- cur_lev = 5 * cnt;
- /* Get closer each iteration */
- cur_dis = 5 * (20 - cnt);
- /* Examine the objects */
- for (i = 1; (i < o_max) && (size); i++) {
- object_type *o_ptr = &o_list[i];
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
- /* Skip dead objects */
- if (!o_ptr->k_idx)
- continue;
- /* Hack -- High level objects start out "immune" */
- if (k_ptr->level > cur_lev && !k_ptr->squelch)
- continue;
- /* Monster */
- if (o_ptr->held_m_idx) {
- monster_type *m_ptr;
- /* Get the monster */
- m_ptr = &m_list[o_ptr->held_m_idx];
- /* Get the location */
- y = m_ptr->fy;
- x = m_ptr->fx;
- /* Monsters protect their objects */
- if ((randint0(100) < 90) && !k_ptr->squelch)
- continue;
- }
- /* Dungeon */
- else {
- /* Get the location */
- y = o_ptr->iy;
- x = o_ptr->ix;
- }
- /* Nearby objects start out "immune" */
- if ((cur_dis > 0) && (distance(py, px, y, x) < cur_dis)
- && !k_ptr->squelch)
- continue;
- /* Saving throw */
- chance = 90;
- /* Hack -- only compact artifacts in emergencies */
- if (artifact_p(o_ptr) && (cnt < 1000))
- chance = 100;
- /* Apply the saving throw */
- if (randint0(100) < chance)
- continue;
- /* Delete the object */
- delete_object_idx(i);
- size--;
- }
- }
- /* Reorder objects */
- compact_objects(0);
- }
- /*
- * Delete all the items when player leaves the level
- *
- * Note -- we do NOT visually reflect these (irrelevant) changes
- *
- * Hack -- we clear the "cave_o_idx[y][x]" field for every grid,
- * and the "m_ptr->next_o_idx" field for every monster, since
- * we know we are clearing every object. Technically, we only
- * clear those fields for grids/monsters containing objects,
- * and we clear it once for every such object.
- */
- void wipe_o_list(void)
- {
- int i;
- /* Delete the existing objects */
- for (i = 1; i < o_max; i++) {
- object_type *o_ptr = &o_list[i];
- /* Skip dead objects */
- if (!o_ptr->k_idx)
- continue;
- /* Hack -- Preserve unknown artifacts */
- if (artifact_p(o_ptr) && !object_known_p(o_ptr)) {
- /* Mega-Hack -- Preserve the artifact */
- a_info[o_ptr->name1].created = FALSE;
- }
- /* Monster */
- if (o_ptr->held_m_idx) {
- monster_type *m_ptr;
- /* Monster */
- m_ptr = &m_list[o_ptr->held_m_idx];
- /* Hack -- see above */
- m_ptr->hold_o_idx = 0;
- }
- /* Dungeon */
- else {
- /* Get the location */
- int y = o_ptr->iy;
- int x = o_ptr->ix;
- /* Hack -- see above */
- cave_o_idx[y][x] = 0;
- }
- /* Wipe the object */
- (void) WIPE(o_ptr, object_type);
- }
- /* Reset "o_max" */
- o_max = 1;
- /* Reset "o_cnt" */
- o_cnt = 0;
- }
- /*
- * Get and return the index of a "free" object.
- *
- * This routine should almost never fail, but in case it does,
- * we must be sure to handle "failure" of this routine.
- */
- s16b o_pop(void)
- {
- int i;
- /* Initial allocation */
- if (o_max < z_info->o_max) {
- /* Get next space */
- i = o_max;
- /* Expand object array */
- o_max++;
- /* Count objects */
- o_cnt++;
- /* Use this object */
- return (i);
- }
- /* Recycle dead objects */
- for (i = 1; i < o_max; i++) {
- object_type *o_ptr;
- /* Get the object */
- o_ptr = &o_list[i];
- /* Skip live objects */
- if (o_ptr->k_idx)
- continue;
- /* Count objects */
- o_cnt++;
- /* Use this object */
- return (i);
- }
- /* Warn the player (except during dungeon creation) */
- if (character_dungeon)
- msg("Too many objects!");
- /* Oops */
- return (0);
- }
- /*
- * Get the first object at a dungeon location
- * or NULL if there isn't one.
- */
- object_type *get_first_object(int y, int x)
- {
- s16b o_idx = cave_o_idx[y][x];
- if (o_idx)
- return (&o_list[o_idx]);
- /* No object */
- return (NULL);
- }
- /*
- * Get the next object in a stack or NULL if there isn't one.
- */
- object_type *get_next_object(const object_type * o_ptr)
- {
- if (o_ptr->next_o_idx)
- return (&o_list[o_ptr->next_o_idx]);
- /* No more objects */
- return (NULL);
- }
- /**
- * Return the "value" of an "unknown" item
- * Make a guess at the value of non-aware items
- */
- static s32b object_value_base(const object_type * o_ptr)
- {
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
- /* For most items, the "aware" value is simply that of the object kind. */
- s32b aware_cost = k_ptr->cost;
- /* Because weapons and ammo may have enhanced damage dice, their aware
- * value may vary. -LM- */
- switch (o_ptr->tval) {
- case TV_SHOT:
- case TV_ARROW:
- case TV_BOLT:
- {
- if (o_ptr->ds > k_ptr->ds) {
- aware_cost +=
- (1 + o_ptr->ds - k_ptr->ds) * (2 + o_ptr->ds -
- k_ptr->ds) * 1L;
- }
- if (o_ptr->dd > k_ptr->dd) {
- aware_cost +=
- (1 + o_ptr->dd - k_ptr->dd) * (2 + o_ptr->dd -
- k_ptr->dd) * 1L;
- }
- break;
- }
- case TV_HAFTED:
- case TV_POLEARM:
- case TV_SWORD:
- {
- if (o_ptr->ds > k_ptr->ds) {
- aware_cost +=
- (o_ptr->ds - k_ptr->ds) * (o_ptr->ds -
- k_ptr->ds) * o_ptr->dd *
- o_ptr->dd * 16L;
- }
- if (o_ptr->dd > k_ptr->dd) {
- aware_cost +=
- (o_ptr->dd - k_ptr->dd) * (o_ptr->ds -
- k_ptr->dd) * o_ptr->ds *
- o_ptr->ds * 16L;
- }
- break;
- }
- }
- /* Aware item -- use template cost, modified by enhanced dice if needed. */
- if (object_aware_p(o_ptr))
- return (aware_cost);
- /* Analyze the type */
- switch (o_ptr->tval) {
- /* Un-aware Food */
- case TV_FOOD:
- return (5L);
- /* Un-aware Potions */
- case TV_POTION:
- return (20L);
- /* Un-aware Scrolls */
- case TV_SCROLL:
- return (20L);
- /* Un-aware Staffs */
- case TV_STAFF:
- return (80L);
- /* Un-aware Wands */
- case TV_WAND:
- return (80L);
- /* Un-aware Rods */
- case TV_ROD:
- return (200L);
- /* Un-aware Rings (shouldn't happen) */
- case TV_RING:
- return (45L);
- /* Un-aware Amulets (shouldn't happen) */
- case TV_AMULET:
- return (45L);
- }
- /* Paranoia -- Oops */
- return (0L);
- }
- /**
- * Return the "real" price of a "known" item, not including discounts
- *
- * Wand and staffs get cost for each charge
- *
- * Armor is worth an extra 100 gold per bonus point to armor class.
- *
- * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).
- *
- * Missiles are only worth 5 gold per bonus point, since they
- * usually appear in groups of 20, and we want the player to get
- * the same amount of cash for any "equivalent" item. Note that
- * missiles never have any of the "pval" flags, and in fact, they
- * only have a few of the available flags, primarily of the "slay"
- * and "brand" and "ignore" variety.
- *
- * Now reworked to handle all item properties -NRM-
- */
- static s32b object_value_real(const object_type * o_ptr)
- {
- int i;
- s32b value;
- object_kind *k_ptr = &k_info[o_ptr->k_idx];
- /* Hack -- "worthless" items */
- if (!k_ptr->cost)
- return (0L);
- /* Base cost */
- value = k_ptr->cost;
- /* Artifact */
- if (o_ptr->name1) {
- artifact_type *a_ptr = &a_info[o_ptr->name1];
- /* Hack -- Use the artifact cost instead */
- return (a_ptr->cost);
- }
- /* Ego-Item */
- else if (has_ego_properties(o_ptr)) {
- ego_item_type *e_ptr = &e_info[o_ptr->name2];
- /* Hack -- Reward the ego-item with a bonus */
- value += e_ptr->cost;
- }
- /* Analyze resists, bonuses and multiples */
- switch (o_ptr->tval) {
- case TV_BOW:
- case TV_DIGGING:
- case TV_HAFTED:
- case TV_POLEARM:
- case TV_SWORD:
- case TV_BOOTS:
- case TV_GLOVES:
- case TV_HELM:
- case TV_CROWN:
- case TV_SHIELD:
- case TV_CLOAK:
- case TV_SOFT_ARMOR:
- case TV_HARD_ARMOR:
- case TV_DRAG_ARMOR:
- case TV_LIGHT:
- case TV_AMULET:
- case TV_RING:
- {
- /* Give credit for resists */
- if (if_has(o_ptr->id_other, IF_RES_ACID))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_ACID]) * 60L;
- if (if_has(o_ptr->id_other, IF_RES_ELEC))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_ELEC]) * 60L;
- if (if_has(o_ptr->id_other, IF_RES_FIRE))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_FIRE]) * 60L;
- if (if_has(o_ptr->id_other, IF_RES_COLD))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_COLD]) * 60L;
- if (if_has(o_ptr->id_other, IF_RES_POIS))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_POIS]) * 120L;
- if (if_has(o_ptr->id_other, IF_RES_LIGHT))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_LIGHT]) * 60L;
- if (if_has(o_ptr->id_other, IF_RES_DARK))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_DARK]) * 60L;
- if (if_has(o_ptr->id_other, IF_RES_CONFU))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_CONFU]) * 90L;
- if (if_has(o_ptr->id_other, IF_RES_SOUND))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_SOUND]) * 60L;
- if (if_has(o_ptr->id_other, IF_RES_SHARD))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_SHARD]) * 60L;
- if (if_has(o_ptr->id_other, IF_RES_NEXUS))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_NEXUS]) * 60L;
- if (if_has(o_ptr->id_other, IF_RES_NETHR))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_NETHR]) * 90L;
- if (if_has(o_ptr->id_other, IF_RES_CHAOS))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_CHAOS]) * 90L;
- if (if_has(o_ptr->id_other, IF_RES_DISEN))
- value +=
- (RES_LEVEL_BASE -
- o_ptr->percent_res[P_RES_DISEN]) * 120L;
- /* Wearing shows all bonuses */
- if (o_ptr->ident & IDENT_WORN) {
- /* Give credit for stat bonuses. */
- for (i = 0; i < A_MAX; i++) {
- if (o_ptr->bonus_stat[i] > BONUS_BASE)
- value +=
- (((o_ptr->bonus_stat[i] +
- 1) * (o_ptr->bonus_stat[i] + 1)) * 100L);
- else if (o_ptr->bonus_stat[i] < BONUS_BASE)
- value -=
- (o_ptr->bonus_stat[i] * o_ptr->bonus_stat[i] *
- 100L);
- }
- /* Give credit for magic items bonus. */
- value += (o_ptr->bonus_other[P_BONUS_M_MASTERY] * 600L);
- /* Give credit for stealth and searching */
- value += (o_ptr->bonus_other[P_BONUS_STEALTH] * 100L);
- value += (o_ptr->bonus_other[P_BONUS_SEARCH] * 40L);
- /* Give credit for infra-vision */
- value += (o_ptr->bonus_other[P_BONUS_INFRA] * 50L);
- /* Give credit for tunneling bonus above that which a digger
- * possesses intrinsically. */
- value +=
- ((o_ptr->bonus_other[P_BONUS_TUNNEL] -
- k_ptr->bonus_other[P_BONUS_TUNNEL]) * 50L);
- /* Give credit for speed bonus. Formula changed to avoid
- * excessively valuable low-speed items. */
- if (o_ptr->bonus_other[P_BONUS_SPEED] > 0)
- value +=
- (o_ptr->bonus_other[P_BONUS_SPEED] *
- o_ptr->bonus_other[P_BONUS_SPEED] * 5000L);
- else if (o_ptr->bonus_other[P_BONUS_SPEED] < 0)
- value -=
- (o_ptr->bonus_other[P_BONUS_SPEED] *
- o_ptr->bonus_other[P_BONUS_SPEED] * 2000L);
- /* Give credit for extra shots */
- value += (o_ptr->bonus_other[P_BONUS_SHOTS] * 8000L);
- /* Give credit for extra might */
- value += (o_ptr->bonus_other[P_BONUS_MIGHT] * 6000L);
- }
- /* Give credit for slays */
- if (if_has(o_ptr->id_other, IF_SLAY_ANIMAL))
- value +=
- (o_ptr->multiple_slay[P_SLAY_ANIMAL] -
- MULTIPLE_BASE) * 150L;
- if (if_has(o_ptr->id_other, IF_SLAY_EVIL))
- value +=
- (o_ptr->multiple_slay[P_SLAY_EVIL] -
- MULTIPLE_BASE) * 500L;
- if (if_has(o_ptr->id_other, IF_SLAY_UNDEAD))
- value +=
- (o_ptr->multiple_slay[P_SLAY_UNDEAD] -
- MULTIPLE_BASE) * 200L;
- if (if_has(o_ptr->id_other, IF_SLAY_DEMON))
- value +=
- (o_ptr->multiple_slay[P_SLAY_DEMON] -
- MULTIPLE_BASE) * 200L;
- if (if_has(o_ptr->id_other, IF_SLAY_ORC))
- value +=
- (o_ptr->multiple_slay[P_SLAY_ORC] -
- MULTIPLE_BASE) * 100L;
- if (if_has(o_ptr->id_other, IF_SLAY_TROLL))
- value +=
- (o_ptr->multiple_slay[P_SLAY_TROLL] -
- MULTIPLE_BASE) * 150L;
- if (if_has(o_ptr->id_other, IF_SLAY_GIANT))
- value +=
- (o_ptr->multiple_slay[P_SLAY_GIANT] -
- MULTIPLE_BASE) * 100L;
- if (if_has(o_ptr->id_other, IF_SLAY_DRAGON))
- value +=
- (o_ptr->multiple_slay[P_SLAY_DRAGON] -
- MULTIPLE_BASE) * 200L;
- /* Give credit for brands */
- if (if_has(o_ptr->id_other, IF_BRAND_ACID))
- value +=
- (o_ptr->multiple_brand[P_BRAND_ACID] -
- MULTIPLE_BASE) * 300L;
- if (if_has(o_ptr->id_other, IF_BRAND_ELEC))
- value +=
- (o_ptr->multiple_brand[P_BRAND_ELEC] -
- MULTIPLE_BASE) * 300L;
- if (if_has(o_ptr->id_other, IF_BRAND_FIRE))
- value +=
- (o_ptr->multiple_brand[P_BRAND_FIRE] -
- MULTIPLE_BASE) * 200L;
- if (if_has(o_ptr->id_other, IF_BRAND_COLD))
- value +=
- (o_ptr->multiple_brand[P_BRAND_COLD] -
- MULTIPLE_BASE) * 200L;
- if (if_has(o_ptr->id_other, IF_BRAND_POIS))
- value +=
- (o_ptr->multiple_brand[P_BRAND_POIS] -
- MULTIPLE_BASE) * 150L;
- /* Give credit for object flags */
- if (of_has(o_ptr->id_obj, OF_SUSTAIN_STR))
- value += 500L;
- if (of_has(o_ptr->id_obj, OF_SUSTAIN_INT))
- value += 300L;
- if (of_has(o_ptr->id_obj, OF_SUSTAIN_WIS))
- value += 300L;
- if (of_has(o_ptr->id_obj, OF_SUSTAIN_DEX))
- value += 400L;
- if (of_has(o_ptr->id_obj, OF_SUSTAIN_CON))
- value += 400L;
- if (of_has(o_ptr->id_obj, OF_SUSTAIN_CHR))
- value += 50L;
- if (of_has(o_ptr->id_obj, OF_SLOW_DIGEST))
- value += 200L;
- if (of_has(o_ptr->id_obj, OF_FEATHER))
- value += 200L;
- if (of_has(o_ptr->id_obj, OF_REGEN))
- value += 400L;
- if (of_has(o_ptr->id_obj, OF_TELEPATHY))
- value += 5000L;
- if (of_has(o_ptr->id_obj, OF_SEE_INVIS))
- value += 700L;
- if (of_has(o_ptr->id_obj, OF_FREE_ACT))
- value += 800L;
- if (of_has(o_ptr->id_obj, OF_HOLD_LIFE))
- value += 700L;
- if (of_has(o_ptr->id_obj, OF_SEEING))
- value += 700L;
- if (of_has(o_ptr->id_obj, OF_FEARLESS))
- value += 500L;
- if (of_has(o_ptr->id_obj, OF_LIGHT))
- value += 300L;
- if (of_has(o_ptr->id_obj, OF_BLESSED))
- value += 1000L;
- if (of_has(o_ptr->id_obj, OF_IMPACT))
- value += 50L;
- if (of_has(o_ptr->id_obj, OF_ACID_PROOF))
- value += 100L;
- if (of_has(o_ptr->id_obj, OF_ELEC_PROOF))
- value += 100L;
- if (of_has(o_ptr->id_obj, OF_FIRE_PROOF))
- value += 100L;
- if (of_has(o_ptr->id_obj, OF_COLD_PROOF))
- value += 100L;
- if (of_has(o_ptr->id_obj, OF_DARKNESS))
- value += 1000L;
- /* Give 'credit' for curse flags */
- if (cf_has(o_ptr->id_curse, CF_TELEPORT))
- value -= 200L;
- if (cf_has(o_ptr->id_curse, CF_NO_TELEPORT))
- value -= 1000L;
- if (cf_has(o_ptr->id_curse, CF_AGGRO_PERM))
- value -= 2000L;
- if (cf_has(o_ptr->id_curse, CF_AGGRO_RAND))
- value -= 700L;
- if (cf_has(o_ptr->id_curse, CF_SLOW_REGEN))
- value -= 200L;
- if (cf_has(o_ptr->id_curse, CF_AFRAID))
- value -= 500L;
- if (cf_has(o_ptr->id_curse, CF_HUNGRY))
- value -= 200L;
- if (cf_has(o_ptr->id_curse, CF_POIS_RAND))
- value -= 200L;
- if (cf_has(o_ptr->id_curse, CF_POIS_RAND_BAD))
- value -= 500L;
- if (cf_has(o_ptr->id_curse, CF_CUT_RAND))
- value -= 200L;
- if (cf_has(o_ptr->id_curse, CF_CUT_RAND_BAD))
- value -= 400L;
- if (cf_has(o_ptr->id_curse, CF_HALLU_RAND))
- value -= 800L;
- if (cf_has(o_ptr->id_curse, CF_DROP_WEAPON))
- value -= 500L;
- if (cf_has(o_ptr->id_curse, CF_ATTRACT_DEMON))
- value -= 800L;
- if (cf_has(o_ptr->id_curse, CF_ATTRACT_UNDEAD))
- value -= 900L;
- if (cf_has(o_ptr->id_curse, CF_STICKY_WIELD))
- value -= 2500L;
- if (cf_has(o_ptr->id_curse, CF_STICKY_CARRY))
- value -= 1000L;
- if (cf_has(o_ptr->id_curse, CF_PARALYZE))
- value -= 800L;
- if (cf_has(o_ptr->id_curse, CF_PARALYZE_ALL))
- value -= 2000L;
- if (cf_has(o_ptr->id_curse, CF_DRAIN_EXP))
- value -= 800L;
- if (cf_has(o_ptr->id_curse, CF_DRAIN_MANA))
- value -= 1000L;
- if (cf_has(o_ptr->id_curse, CF_DRAIN_STAT))
- value -= 1500L;
- if (cf_has(o_ptr->id_curse, CF_DRAIN_CHARGE))
- value -= 1500L;
- break;
- }
- case TV_SHOT:
- case TV_ARROW:
- case TV_BOLT:
- {
- /* Give credit for slays */
- if (if_has(o_ptr->id_other, IF_SLAY_ANIMAL))
- value +=
- (o_ptr->multiple_slay[P_SLAY_ANIMAL] -
- MULTIPLE_BASE) * 15L;
- if (if_has(o_ptr->id_other, IF_SLAY_EVIL))
- value +=
- (o_ptr->multiple_slay[P_SLAY_EVIL] -
- MULTIPLE_BASE) * 50L;
- if (if_has(o_ptr->id_other, IF_SLAY_UNDEAD))
- value +=
- (o_ptr->multiple_slay[P_SLAY_UNDEAD] -
- MULTIPLE_BASE) * 20L;
- if (if_has(o_ptr->id_other, IF_SLAY_DEMON))
- value +=
- (o_ptr->multiple_slay[P_SLAY_DEMON] -
- MULTIPLE_BASE) * 20L;
- if (if_has(o_ptr->id_other, IF_SLAY_ORC))
- value +=
- (o_ptr->multiple_slay[P_SLAY_ORC] -
- MULTIPLE_BASE) * 10L;
- if (if_has(o_ptr->id_other, IF_SLAY_TROLL))
- value +=
- (o_ptr->multiple_slay[P_SLAY_TROLL] -
- MULTIPLE_BASE) * 15L;
- if (if_has(o_ptr->id_other, IF_SLAY_GIANT))
- value +=
- (o_ptr->multiple_slay[P_SLAY_GIANT] -
- MULTIPLE_BASE) * 10L;
- if (if_has(o_ptr->id_other, IF_SLAY_DRAGON))
- value +=
- (o_ptr->multiple_slay[P_SLAY_DRAGON] -
- MULTIPLE_BASE) * 20L;
- /* Give credit for brands */
- if (if_has(o_ptr->id_other, IF_BRAND_ACID))
- value +=
- (o_ptr->multiple_brand[P_BRAND_ACID] -
- MULTIPLE_BASE) * 30L;
- if (if_has(o_ptr->id_other, IF_BRAND_ELEC))
- value +=
- (o_ptr->multiple_brand[P_BRAND_ELEC] -
- MULTIPLE_BASE) * 30L;
- if (if_has(o_ptr->id_other, IF_BRAND_FIRE))
- value +=
- (o_ptr->multiple_brand[P_BRAND_FIRE] -
- MULTIPLE_BASE) * 20L;
- if (if_has(o_ptr->id_other, IF_BRAND_COLD))
- value +=
- (o_ptr->multiple_brand[P_BRAND_COLD] -
- MULTIPLE_BASE) * 20L;
- if (if_has(o_ptr->id_other, IF_BRAND_POIS))
- value +=
- (o_ptr->multiple_brand[P_BRAND_POIS] -
- MULTIPLE_BASE) * 15L;
- break;
- }
- }
- /* Analyze the item */
- switch (o_ptr->tval) {
- /* Wands/Staffs */
- case TV_WAND:
- {
- int temp_pval = randcalc(k_ptr->pval, k_ptr->level, RANDOMISE);
- /* Pay extra for charges, depending on standard number of charges.
- * Handle new-style wands correctly. */
- value +=
- (value * o_ptr->pval / o_ptr->number / (temp_pval * 2));
- /* Done */
- break;
- }
- case TV_STAFF:
- {
- /* Pay extra for charges, depending on standard number of charges */
- int temp_pval = randcalc(k_ptr->pval, k_ptr->level, RANDOMISE);
- value += (value * o_ptr->pval / (temp_pval * 2));
- /* Done */
- break;
- }
- /* Rings/Amulets */
- case TV_RING:
- case TV_AMULET:
- {
- /* Give credit for bonuses */
- if (if_has(o_ptr->id_other, IF_TO_H))
- value += o_ptr->to_h * 100L;
- if (if_has(o_ptr->id_other, IF_TO_D))
- value += o_ptr->to_d * 100L;
- if (if_has(o_ptr->id_other, IF_TO_A))
- value += o_ptr->to_a * 100L;
- /* Done */
- break;
- }
- /* Armor */
- case TV_BOOTS:
- case TV_GLOVES:
- case TV_CLOAK:
- case TV_CROWN:
- case TV_HELM:
- case TV_SHIELD:
- case TV_SOFT_ARMOR:
- case TV_HARD_ARMOR:
- case TV_DRAG_ARMOR:
- {
- /* If it differs from the object kind's base armour Skill penalty
- * (this penalty must be in the range +0 to -12), give a debit or
- * credit for any modification to Skill. -LM- */
- if (((o_ptr->to_h != k_ptr->to_h.base) || (o_ptr->to_h < -12)
- || (o_ptr->to_h > 0))
- && (if_has(o_ptr->id_other, IF_TO_H)))
- value += (o_ptr->to_h * 100L);
- /* Standard debit or credit for to_d and to_a bonuses. */
- if (if_has(o_ptr->id_other, IF_TO_D))
- value += (o_ptr->to_d) * 100L;
- if (if_has(o_ptr->id_other, IF_TO_A))
- value += (o_ptr->to_a) * 100L;
- /* Done */
- break;
- }
- /* Sharp weapons */
- case TV_DIGGING:
- case TV_SWORD:
- case TV_POLEARM:
- {
- /* Blessed */
- if (of_has(o_ptr->id_obj, OF_BLESSED))
- value += 400L;
- /* Fall through */
- }
- /* Bows/Weapons */
- case TV_BOW:
- case TV_HAFTED:
- {
- /* Because +to_hit and +to_dam work differently now, this formula
- * also needed to change. Although long, it now yields results
- * that match the increase in the weapon's combat power. -LM- */
- int hit = (if_has(o_ptr->id_other, IF_TO_H)) ? o_ptr->to_h : 0;
- int dam = (if_has(o_ptr->id_other, IF_TO_D)) ? o_ptr->to_d : 0;
- int arm = (if_has(o_ptr->id_other, IF_TO_A)) ? o_ptr->to_a : 0;
- value +=
- (((hit + 10) * (dam + 10) - 100) * (k_ptr->cost +
- 1000L) / 250) +
- (arm * 100);
- /* Hack -- Factor in improved damage dice. If you want to buy one
- * of the truly dangerous weapons, be prepared to pay for it. */
- if ((o_ptr->ds > k_ptr->ds) && (o_ptr->dd == k_ptr->dd)
- && (if_has(o_ptr->id_other, IF_DD_DS))) {
- value += (o_ptr->ds - k_ptr->ds) * (o_ptr->ds - k_ptr->ds)
- * o_ptr->dd * o_ptr->dd * 16L;
- /* Naturally, ego-items with high base dice should be very
- * expensive. */
- if (has_ego_properties(o_ptr)) {
- value += (5 * value / 2);
- }
- }
- /* Give credit for perfect balance. */
- if (of_has(o_ptr->id_obj, OF_PERFECT_BALANCE))
- value += o_ptr->dd * 200L;
- /* Done */
- break;
- }
- /* Ammo */
- case TV_SHOT:
- case TV_ARROW:
- case TV_BOLT:
- {
- /* Factor in the bonuses */
- if (if_has(o_ptr->id_other, IF_TO_H))
- value += o_ptr->to_h * 2L;
- if (if_has(o_ptr->id_other, IF_TO_D))
- value += o_ptr->to_d * 2L;
- /* Hack -- Factor in improved damage dice. -LM- */
- if ((o_ptr->ds > k_ptr->ds)
- && (if_has(o_ptr->id_other, IF_DD_DS))) {
- value +=
- (1 + o_ptr->ds - k_ptr->ds) * (2 + o_ptr->ds -
- k_ptr->ds) * 1L;
- /* Naturally, ego-items with high base dice should be
- * expensive. */
- if (has_ego_properties(o_ptr)) {
- value += (5 * value / 2);
- }
- }
- /* Done */
- break;
- }
- /* Who wants an empty chest? */
- case TV_CHEST:
- {
- if (o_ptr->pval == 0)
- return (0L);
- break;
- }
- }
- /* Return the value */
- return (value < 0 ? 0L : value);
- }
- /**
- * Return the price of an item including plusses (and charges)
- *
- * This function returns the "value" of the given item (qty one)
- *
- * Never notice "unknown" bonuses or properties, including "curses",
- * since that would give the player information he did not have.
- *
- * Note that discounted items stay discounted forever, even if
- * the discount is "forgotten" by the player via memory loss.
- */
- s32b object_value(const object_type * o_ptr)
- {
- s32b value;
- /* Known items -- acquire the actual value */
- if (object_known_p(o_ptr)
- || ((wield_slot(o_ptr) > 0) && !artifact_p(o_ptr))) {
- /* Real value (see above) */
- value = object_value_real(o_ptr);
- }
- /* Unknown items -- acquire a base value */
- else {
- /* Base value (see above) */
- value = object_value_base(o_ptr);
- }
- /* Apply discount (if any) */
- if (o_ptr->discount)
- value -= (value * o_ptr->discount / 100L);
- /* Return the final value */
- return (value);
- }
- /*
- * Determine if an item can "absorb" a second item
- *
- * See "object_absorb()" for the actual "absorption" code.
- *
- * If permitted, we allow weapons/armor to stack, if "known".
- *
- * Missiles will combine if both stacks have the same "known" status.
- * This is done to make unidentified stacks of missiles useful.
- *
- * Food, potions, scrolls, and "easy know" items always stack.
- *
- * Chests, and activatable items, except rods, never stack (for various
- * reasons).
- */
- bool object_similar(const object_type * o_ptr, const object_type * j_ptr,
- object_stack_t mode)
- {
- int i;
- int total = o_ptr->number + j_ptr->number;
- /* Check against stacking limit */
- if (total >= MAX_STACK_SIZE)
- return FALSE;
- /* Hack -- identical items cannot be stacked */
- if (o_ptr == j_ptr)
- return FALSE;
- /* Require identical object kinds */
- if (o_ptr->k_idx != j_ptr->k_idx)
- return FALSE;
- /* Require identical effects */
- if (o_ptr->effect != j_ptr->effect)
- return (FALSE);
- /* Different flags don't stack */
- if (!of_is_equal(o_ptr->flags_obj, j_ptr->flags_obj))
- return FALSE;
- if (!cf_is_equal(o_ptr->flags_curse, j_ptr->flags_curse))
- return FALSE;
- /* Require identical resists, etc */
- for (i = 0; i < MAX_P_RES; i++)
- if (o_ptr->percent_res[i] != j_ptr->percent_res[i])
- return (FALSE);
- for (i = 0; i < A_MAX; i++)
- if (o_ptr->bonus_stat[i] != j_ptr->bonus_stat[i])
- return (FALSE);
- for (i = 0; i < MAX_P_BONUS; i++)
- if (o_ptr->bonus_other[i] != j_ptr->bonus_other[i])
- return (FALSE);
- for (i = 0; i < MAX_P_SLAY; i++)
- if (o_ptr->multiple_slay[i] != j_ptr->multiple_slay[i])
- return (FALSE);
- for (i = 0; i < MAX_P_BRAND; i++)
- if (o_ptr->multiple_brand[i] != j_ptr->multiple_brand[i])
- return (FALSE);
- /* Artifacts never stack */
- if (o_ptr->name1 || j_ptr->name1)
- return FALSE;
- /* Analyze the items */
- switch (o_ptr->tval) {
- /* Chests never stack */
- case TV_CHEST:
- {
- /* Never okay */
- return FALSE;
- }
- /* Food, potions, scrolls and rods all stack nicely */
- case TV_FOOD:
- case TV_POTION:
- case TV_SCROLL:
- case TV_ROD:
- {
- /* Since the kinds are identical, either both will be aware or both
- * will be unaware */
- break;
- }
- /* Gold, staves and wands stack most of the time */
- case TV_STAFF:
- case TV_WAND:
- case TV_GOLD:
- {
- /* Too much gold or too many charges */
- if (o_ptr->pval + j_ptr->pval > MAX_PVAL)
- return FALSE;
- /* ... otherwise ok */
- else
- break;
- }
- /* Weapons, ammo, armour, jewelry, lights */
- case TV_BOW:
- case TV_DIGGING:
- case TV_HAFTED:
- case TV_POLEARM:
- case TV_SWORD:
- case TV_BOOTS:
- case TV_GLOVES:
- case TV_HELM:
- case TV_CROWN:
- case TV_SHIELD:
- case TV_CLOAK:
- case TV_SOFT_ARMOR:
- case TV_HARD_ARMOR:
- case TV_DRAG_ARMOR:
- case TV_RING:
- case TV_AMULET:
- case TV_LIGHT:
- case TV_BOLT:
- case TV_ARROW:
- case TV_SHOT:
- {
- /* Require identical values */
- if (o_ptr->ac != j_ptr->ac)
- return FALSE;
- if (o_ptr->dd != j_ptr->dd)
- return FALSE;
- if (o_ptr->ds != j_ptr->ds)
- return FALSE;
- /* Require identical bonuses */
- if (o_ptr->to_h != j_ptr->to_h)
- return FALSE;
- if (o_ptr->to_d != j_ptr->to_d)
- return FALSE;
- if (o_ptr->to_a != j_ptr->to_a)
- return FALSE;
- /* Require identical pval */
- if (o_ptr->pval != j_ptr->pval)
- return (FALSE);
- /* Require identical ego-item types */
- if (o_ptr->name2 != j_ptr->name2)
- return (FALSE);
- /* Hack - Never stack recharging wearables ... */
- if ((o_ptr->timeout || j_ptr->timeout)
- && (o_ptr->tval != TV_LIGHT))
- return FALSE;
- /* ... and lights must have same amount of fuel */
- else if ((o_ptr->timeout != j_ptr->timeout)
- && (o_ptr->tval == TV_LIGHT))
- return FALSE;
- /* Probably okay */
- break;
- }
- /* Anything else */
- default:
- {
- /* Require knowledge */
- //if (!object_known_p(o_ptr) || !object_known_p(j_ptr))
- //return (FALSE);
- /* Probably okay */
- break;
- }
- }
- /* Hack -- Require compatible inscriptions */
- …
Large files files are truncated, but you can click here to view the full file