Angband
Data Structures | Macros | Functions | Variables
obj-gear.c File Reference

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 objectslot_object (struct player *p, int slot)
 
struct objectequipped_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 objectgear_last_item (void)
 
void gear_insert_end (struct object *obj)
 
struct objectgear_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 []
 

Detailed Description

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.

Macro Definition Documentation

#define EQUIP (   a,
  b,
  c,
  d,
  e,
 
)    { EQUIP_##a, b, c, d, e, f },

Function Documentation

void combine_pack ( void  )
const char* equip_describe ( struct player p,
int  slot 
)
const char* equip_mention ( struct player p,
int  slot 
)
struct object* equipped_item_by_slot_name ( struct player p,
const char *  name 
)
static bool gear_excise_object ( struct object obj)
static
void gear_insert_end ( struct object obj)
struct object* gear_last_item ( void  )

References player::gear, and pile_last_item().

Referenced by combine_pack(), and ignore_drop().

struct object* gear_object_for_use ( struct object obj,
int  num,
bool  message,
bool *  none_left 
)
char gear_to_label ( struct object obj)
static bool inven_can_stack_partial ( const struct object obj1,
const struct object obj2,
object_stack_t  mode 
)
static

Return whether each stack of objects can be merged into two uneven stacks.

References object::number, object_stackable(), OSTACK_STORE, angband_constants::stack_size, and z_info.

Referenced by combine_pack().

void inven_carry ( struct player p,
struct object obj,
bool  absorb,
bool  message 
)

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().

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.

Optionally only return a positive value if there is already a similar object.

References player::body, player::gear, i, player_upkeep::inven, MAX, object::next, object::number, object_is_equipped(), object_stackable(), OSTACK_PACK, angband_constants::pack_size, pack_slots_used(), quiver_absorb_num(), angband_constants::stack_size, 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().

bool inven_carry_okay ( const struct object obj)

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().

void inven_drop ( struct object obj,
int  amt 
)

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().

void inven_item_charges ( struct object obj)

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().

void inven_takeoff ( struct object obj)

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, slot_type_is(), player_body::slots, player_upkeep::update, and player::upkeep.

Referenced by do_cmd_takeoff(), and inven_drop().

void inven_wield ( struct object obj,
int  slot 
)
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().

bool object_is_carried ( struct player p,
const struct object obj 
)
bool object_is_equipped ( struct player_body  body,
const struct object obj 
)
static bool object_is_in_quiver ( struct player p,
const struct object obj 
)
static

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 
)
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().

void pack_overflow ( struct object obj)
int pack_slots_used ( struct player p)

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::stack_size, tval_is_ammo(), and z_info.

Referenced by inven_carry(), inven_carry_num(), pack_is_full(), and pack_is_overfull().

static int quiver_absorb_num ( const struct object obj)
static

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::stack_size, tval_is_ammo(), player::upkeep, and z_info.

Referenced by inven_carry_num().

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.

References player::body, player_body::count, i, NULL, equip_slot::obj, player_body::slots, and equip_slot::type.

Referenced by wield_slot().

struct object* slot_object ( struct player p,
int  slot 
)
bool slot_type_is ( int  slot,
int  type 
)
int wield_slot ( const struct object obj)

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().

Variable Documentation

const struct slot_info slot_table[]
static
Initial value:
= {
#define EQUIP(a, b, c, d, e, f)
{ EQUIP_MAX, false, false, NULL, NULL, NULL }
}
Definition: obj-gear.h:59
NULL
Definition: list-summon-types.h:18

Referenced by equip_describe(), and equip_mention().