Angband
|
management of inventory, equipment and quiver More...
#include "angband.h"
#include "cmd-core.h"
#include "game-event.h"
#include "init.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-ignore.h"
#include "obj-knowledge.h"
#include "obj-pile.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-util.h"
#include "list-equip-slots.h"
Data Structures | |
struct | slot_info |
Macros | |
#define | EQUIP(a, b, c, d, e, f) { EQUIP_##a, b, c, d, e, f }, |
Functions | |
int | slot_by_name (struct player *p, const char *name) |
int | slot_by_type (struct player *p, int type, bool full) |
Gets a slot of the given type, preferentially empty unless full is true. More... | |
bool | slot_type_is (int slot, int type) |
struct object * | slot_object (struct player *p, int slot) |
struct object * | equipped_item_by_slot_name (struct player *p, const char *name) |
int | object_slot (struct player_body body, const struct object *obj) |
bool | object_is_equipped (struct player_body body, const struct object *obj) |
bool | object_is_carried (struct player *p, const struct object *obj) |
static bool | object_is_in_quiver (struct player *p, const struct object *obj) |
Check if an object is in the quiver. More... | |
int | pack_slots_used (struct player *p) |
Calculate the number of pack slots used by the current gear. More... | |
const char * | equip_mention (struct player *p, int slot) |
const char * | equip_describe (struct player *p, int slot) |
int | wield_slot (const struct object *obj) |
Determine which equipment slot (if any) an item likes. More... | |
bool | minus_ac (struct player *p) |
Acid has hit the player, attempt to affect some armor. More... | |
char | gear_to_label (struct object *obj) |
Convert a gear object into a one character label. More... | |
static bool | gear_excise_object (struct object *obj) |
Remove an object from the gear list, leaving it unattached. More... | |
struct object * | gear_last_item (void) |
void | gear_insert_end (struct object *obj) |
struct object * | gear_object_for_use (struct object *obj, int num, bool message, bool *none_left) |
Remove an amount of an object from the inventory or quiver, returning a detached object which can be used. More... | |
static int | quiver_absorb_num (const struct object *obj) |
Check how many missiles can be put in the quiver without increasing the number of pack slots used. More... | |
int | inven_carry_num (const struct object *obj, bool stack) |
Calculate how much of an item is can be carried in the inventory or quiver. More... | |
bool | inven_carry_okay (const struct object *obj) |
Check if we have space for some of an item in the pack, optionally requiring stacking. More... | |
void | inven_item_charges (struct object *obj) |
Describe the charges on an item in the inventory. More... | |
void | inven_carry (struct player *p, struct object *obj, bool absorb, bool message) |
Add an item to the players inventory. More... | |
void | inven_wield (struct object *obj, int slot) |
Wield or wear a single item from the pack or floor. More... | |
void | inven_takeoff (struct object *obj) |
Take off a non-cursed equipment item. More... | |
void | inven_drop (struct object *obj, int amt) |
Drop (some of) a non-cursed inventory/equipment item "near" the current location. More... | |
static bool | inven_can_stack_partial (const struct object *obj1, const struct object *obj2, object_stack_t mode) |
Return whether each stack of objects can be merged into two uneven stacks. More... | |
void | combine_pack (void) |
Combine items in the pack, confirming no blank objects or gold. More... | |
bool | pack_is_full (void) |
Returns whether the pack is holding the maximum number of items. More... | |
bool | pack_is_overfull (void) |
Returns whether the pack is holding the more than the maximum number of items. More... | |
void | pack_overflow (struct object *obj) |
Overflow an item from the pack, if it is overfull. More... | |
Variables | |
static const struct slot_info | slot_table [] |
management of inventory, equipment and quiver
Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke Copyright (c) 2014 Nick McConnell
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.
#define EQUIP | ( | a, | |
b, | |||
c, | |||
d, | |||
e, | |||
f | |||
) | { EQUIP_##a, b, c, d, e, f }, |
Combine items in the pack, confirming no blank objects or gold.
References player::body, calc_inventory(), cmd_disable_repeat(), display_message(), EVENT_EQUIPMENT, EVENT_INVENTORY, event_signal(), player::gear, gear_last_item(), inven_can_stack_partial(), object::kind, object::known, msg, object::next, NULL, object_absorb(), object_absorb_partial(), object_similar(), OSTACK_PACK, prev, object::prev, tval_is_money(), and player::upkeep.
Referenced by do_cmd_takeoff(), inven_wield(), and notice_stuff().
References player::body, NULL, slot_by_name(), slot_object(), and player_body::slots.
Referenced by calc_bonuses(), calc_mana(), describe_combat(), do_cmd_fire(), do_cmd_fire_at_nearest(), do_cmd_refill(), effect_handler_BRAND_WEAPON(), effect_handler_CURSE_ARMOR(), effect_handler_CURSE_WEAPON(), get_panel_combat(), lore_append_toughness(), make_ranged_shot(), obj_can_refill(), obj_known_damage(), obj_known_misc_combat(), player_can_fire(), player_can_refuel(), player_update_light(), py_attack_real(), and update_bonuses().
|
static |
Remove an object from the gear list, leaving it unattached.
obj | the object being tested |
References player::body, calc_inventory(), player_body::count, player_upkeep::equip_cnt, player::gear, player::gear_k, i, object::known, player_upkeep::notice, NULL, object::number, equip_slot::obj, pile_excise(), PN_COMBINE, PR_EQUIP, PR_INVEN, PU_BONUS, player_upkeep::redraw, slot_object(), player_body::slots, player_upkeep::total_weight, player_upkeep::update, player::upkeep, and object::weight.
Referenced by gear_object_for_use(), and pack_overflow().
References player::gear, player::gear_k, object::known, and pile_insert_end().
Referenced by inven_carry().
References player::gear, and pile_last_item().
Referenced by combine_pack(), and ignore_drop().
Remove an amount of an object from the inventory or quiver, returning a detached object which can be used.
Optionally describe what remains.
References object::artifact, cmd_disable_repeat(), gear_excise_object(), gear_to_label(), object::known, MIN, msg, player_upkeep::notice, NULL, num, object::number, object_desc(), object_split(), ODESC_FULL, ODESC_PREFIX, ODESC_SINGULAR, PN_COMBINE, PR_EQUIP, PR_INVEN, PU_BONUS, player_upkeep::redraw, player_upkeep::total_weight, track_object(), tracked_object_is(), player_upkeep::update, player::upkeep, and object::weight.
Referenced by do_cmd_sell(), do_cmd_stash(), effect_handler_RECHARGE(), inven_damage(), inven_drop(), inven_wield(), melee_effect_handler_EAT_FOOD(), melee_effect_handler_EAT_ITEM(), player_update_light(), ranged_helper(), refill_lamp(), uncurse_object(), and use_aux().
char gear_to_label | ( | struct object * | obj | ) |
Convert a gear object into a one character label.
References player::body, equipped_item_slot(), i, I2A, I2D, player_upkeep::inven, object_is_equipped(), angband_constants::pack_size, player_upkeep::quiver, angband_constants::quiver_size, player::upkeep, and z_info.
Referenced by do_cmd_sell(), do_cmd_stash(), do_cmd_wield(), gear_object_for_use(), inven_carry(), inven_damage(), inven_drop(), player_know_object(), and write_character_dump().
|
static |
Return whether each stack of objects can be merged into two uneven stacks.
References object_kind::base, object::kind, object_base::max_stack, object::number, object_stackable(), and OSTACK_STORE.
Referenced by combine_pack().
Add an item to the players inventory.
If the new item can combine with an existing item in the inventory, it will do so, using object_similar() and object_absorb(), else, the item will be placed into the first available gear array index.
This function can be used to "over-fill" the player's pack, but only once, and such an action must trigger the "overflow" code immediately. Note that when the pack is being "over-filled", the new item must be placed into the "overflow" slot, and the "overflow" must take place before the pack is reordered, but (optionally) after the pack is combined. This may be tricky. See "dungeon.c" for info.
Note that this code removes any location information from the object once it is placed into the inventory, but takes no responsibility for removing the object from any other pile it was in.
References apply_autoinscription(), player::body, player::gear, gear_insert_end(), gear_to_label(), object::held_m_idx, object::ix, object::iy, object::known, msg, object::next, player_upkeep::notice, NULL, object::number, object_absorb(), object_desc(), object_flavor_aware(), object_flavor_is_aware(), object_is_equipped(), object_is_in_quiver(), object_similar(), ODESC_FULL, ODESC_PREFIX, OSTACK_PACK, angband_constants::pack_size, pack_slots_used(), player_has, PN_COMBINE, PR_INVEN, PU_BONUS, PU_INVEN, player_upkeep::redraw, sound(), player_upkeep::total_weight, tval_is_mushroom(), tval_is_zapper(), player_upkeep::update, update_stuff(), player::upkeep, object::weight, and z_info.
Referenced by do_cmd_buy(), do_cmd_retrieve(), inven_wield(), player_outfit(), player_pickup_aux(), and refill_lamp().
Calculate how much of an item is can be carried in the inventory or quiver.
Optionally only return a positive value if there is already a similar object.
References object_kind::base, player::body, player::gear, i, player_upkeep::inven, object::kind, MAX, object_base::max_stack, object::next, object::number, object_is_equipped(), object_stackable(), OSTACK_PACK, angband_constants::pack_size, pack_slots_used(), quiver_absorb_num(), player::upkeep, and z_info.
Referenced by auto_pickup_okay(), do_autopickup(), do_cmd_buy(), do_cmd_retrieve(), inven_carry_okay(), player_pickup_aux(), and store_purchase().
Check if we have space for some of an item in the pack, optionally requiring stacking.
References inven_carry_num().
Referenced by auto_pickup_okay(), context_menu_object(), context_menu_player(), player_pickup_item(), see_floor_items(), and store_purchase().
Drop (some of) a non-cursed inventory/equipment item "near" the current location.
There are two cases here - a single object or entire stack is being dropped, or part of a stack is being split off and dropped
References object::artifact, player::body, cave, drop_near(), EVENT_EQUIPMENT, EVENT_INVENTORY, event_signal(), gear_object_for_use(), gear_to_label(), inven_takeoff(), msg, object::number, object_desc(), object_is_carried(), object_is_equipped(), object_is_in_quiver(), ODESC_FULL, ODESC_PREFIX, ODESC_SINGULAR, player::px, player::py, and sound().
Referenced by do_cmd_drop().
Describe the charges on an item in the inventory.
References msg, object_flavor_is_aware(), PLURAL, object::pval, and tval_can_have_charges().
Referenced by use_aux().
Take off a non-cursed equipment item.
Note that taking off an item when "full" may cause that item to fall to the ground.
Note also that this function does not try to combine the taken off item with other inventory items - that must be done by the calling function.
References player::body, player_body::count, player_upkeep::equip_cnt, equipped_item_slot(), I2A, msgt(), player_upkeep::notice, NULL, equip_slot::obj, object_desc(), ODESC_FULL, ODESC_PREFIX, PN_IGNORE, PU_BONUS, PU_INVEN, PU_UPDATE_VIEW, slot_type_is(), player_body::slots, player_upkeep::update, update_stuff(), and player::upkeep.
Referenced by do_cmd_takeoff(), and inven_drop().
Wield or wear a single item from the pack or floor.
References player::body, cmd_disable_repeat(), combine_pack(), player_upkeep::energy_use, player_upkeep::equip_cnt, object::flags, floor_object_for_use(), gear_object_for_use(), I2A, inven_carry(), object::known, angband_constants::move_energy, msgt(), object::next, player_upkeep::notice, NULL, object::number, equip_slot::obj, object_desc(), object_is_carried(), object_learn_on_wield(), ODESC_FULL, ODESC_PREFIX, of_has, pack_overflow(), PN_IGNORE, PR_ARMOR, PR_EQUIP, PR_HP, PR_INVEN, PR_MANA, PR_SPEED, PR_STATS, prev, object::prev, PU_BONUS, PU_INVEN, PU_UPDATE_VIEW, player_upkeep::redraw, player_body::slots, object::tval, tval_is_light(), tval_is_melee_weapon(), player_upkeep::update, update_stuff(), player::upkeep, and z_info.
Referenced by do_cmd_wield().
bool minus_ac | ( | struct player * | p | ) |
Acid has hit the player, attempt to affect some armor.
Note that the "base armor" of an object never changes. If any armor is damaged (or resists), the player takes less damage.
References object::ac, player::body, player_body::count, object::el_info, EL_INFO_IGNORE, element_info::flags, player::gear, i, object::known, msg, NULL, player::obj_k, object_desc(), ODESC_BASE, one_in_, PR_EQUIP, PU_BONUS, player_upkeep::redraw, slot_object(), slot_type_is(), object::to_a, player_upkeep::update, and player::upkeep.
Referenced by adjust_dam().
References player::gear, and pile_contains().
Referenced by apply_autoinscription(), context_menu_object(), do_cmd_wiz_play(), effect_handler_RECHARGE(), enchant_spell(), inven_drop(), inven_wield(), item_is_available(), player_know_object(), ranged_helper(), refill_lamp(), store_carry(), uncurse_object(), and use_aux().
bool object_is_equipped | ( | struct player_body | body, |
const struct object * | obj | ||
) |
References player_body::count, and object_slot().
Referenced by calc_inventory(), context_menu_object(), do_cmd_drop(), do_cmd_sell(), do_cmd_stash(), do_cmd_throw(), find_inven(), find_stack_object_in_inventory(), gear_to_label(), ignore_drop(), inven_carry(), inven_carry_num(), inven_damage(), inven_drop(), object_stackable(), pack_slots_used(), recharge_objects(), and store_sell().
Check if an object is in the quiver.
References i, player_upkeep::quiver, angband_constants::quiver_size, player::upkeep, and z_info.
Referenced by inven_carry(), and inven_drop().
int object_slot | ( | struct player_body | body, |
const struct object * | obj | ||
) |
References player_body::count, i, equip_slot::obj, and player_body::slots.
Referenced by object_is_equipped(), and wr_gear_aux().
bool pack_is_full | ( | void | ) |
Returns whether the pack is holding the maximum number of items.
References angband_constants::pack_size, pack_slots_used(), and z_info.
Referenced by store_purchase().
bool pack_is_overfull | ( | void | ) |
Returns whether the pack is holding the more than the maximum number of items.
If this is true, calling pack_overflow() will trigger a pack overflow.
References angband_constants::pack_size, pack_slots_used(), and z_info.
Referenced by pack_overflow().
Overflow an item from the pack, if it is overfull.
References object::artifact, cave, disturb(), drop_near(), gear_excise_object(), i, player_upkeep::inven, msg, player_upkeep::notice, notice_stuff(), NULL, object_desc(), ODESC_FULL, ODESC_PREFIX, pack_is_overfull(), angband_constants::pack_size, player::px, player::py, player_upkeep::redraw, redraw_stuff(), player_upkeep::update, update_stuff(), player::upkeep, and z_info.
Referenced by do_cmd_takeoff(), inven_wield(), and process_player().
Calculate the number of pack slots used by the current gear.
Note that this function does not check that there are adequate slots in the quiver, just the total quantity of missiles.
References player::body, player::gear, object::next, object::number, object_is_equipped(), angband_constants::quiver_slot_size, tval_is_ammo(), and z_info.
Referenced by inven_carry(), inven_carry_num(), pack_is_full(), and pack_is_overfull().
Check how many missiles can be put in the quiver without increasing the number of pack slots used.
Returns the quantity from a given stack of missiles that can be added.
References i, MIN, object::number, object_stackable(), OSTACK_PACK, player_upkeep::quiver, angband_constants::quiver_size, angband_constants::quiver_slot_size, tval_is_ammo(), player::upkeep, and z_info.
Referenced by inven_carry_num().
References player::body, player_body::count, i, equip_slot::name, player_body::slots, and streq.
Referenced by blow_color(), effect_handler_DRAIN_LIGHT(), equip_learn_on_melee_attack(), equip_learn_on_ranged_attack(), equipped_item_by_slot_name(), obj_known_blows(), obj_known_damage(), obj_known_misc_combat(), and spell_value_base_weapon_damage().
Gets a slot of the given type, preferentially empty unless full is true.
References player::body, player_body::count, i, NULL, equip_slot::obj, player_body::slots, and equip_slot::type.
Referenced by wield_slot().
References player::body, NULL, equip_slot::obj, and player_body::slots.
Referenced by blow_color(), build_obj_list(), calc_bonuses(), calc_mana(), calc_torch(), display_player_equippy(), display_player_sust_info(), display_resistance_panel(), do_cmd_wield(), effect_handler_DISENCHANT(), effect_handler_DRAIN_LIGHT(), equip_learn_after_time(), equip_learn_element(), equip_learn_flag(), equip_learn_on_defend(), equip_learn_on_melee_attack(), equip_learn_on_ranged_attack(), equipped_item_by_slot_name(), gear_excise_object(), key_confirm_command(), minus_ac(), obj_known_blows(), obj_known_damage(), obj_known_digging(), prt_equippy(), py_attack_real(), scan_items(), textui_get_item(), wield_all(), and write_character_dump().
References bodies, player::body, player_body::slots, true, and equip_slot::type.
Referenced by calc_bonuses(), calc_mana(), do_cmd_wield(), effect_handler_DISENCHANT(), inven_takeoff(), and minus_ac().
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. rings), the function will try to return an open slot if possible.
References slot_by_type(), object::tval, tval_is_body_armor(), tval_is_head_armor(), tval_is_light(), tval_is_melee_weapon(), and tval_is_ring().
Referenced by do_cmd_wield(), obj_can_fail(), obj_can_wear(), obj_known_digging(), and wield_all().
Referenced by equip_describe(), and equip_mention().