Angband
Functions | Variables
obj-pile.c File Reference

Deal with piles of objects. More...

#include "angband.h"
#include "cave.h"
#include "effects.h"
#include "cmd-core.h"
#include "game-input.h"
#include "generate.h"
#include "grafmode.h"
#include "init.h"
#include "mon-make.h"
#include "mon-util.h"
#include "monster.h"
#include "obj-curse.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-ignore.h"
#include "obj-info.h"
#include "obj-knowledge.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-slays.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-history.h"
#include "player-spell.h"
#include "player-util.h"
#include "randname.h"
#include "z-queue.h"

Functions

void write_pile (ang_file *fff)
 
void pile_integrity_fail (struct object *pile, struct object *obj, char *file, int line)
 Quit on getting an object pile error, writing a diagnosis file. More...
 
void pile_check_integrity (const char *op, struct object *pile, struct object *hilight)
 Check the integrity of a linked - make sure it's not circular and that each entry in the chain has consistent next and prev pointers. More...
 
void pile_insert (struct object **pile, struct object *obj)
 Insert 'obj' into the pile 'pile'. More...
 
void pile_insert_end (struct object **pile, struct object *obj)
 Insert 'obj' at the end of pile 'pile'. More...
 
void pile_excise (struct object **pile, struct object *obj)
 Remove object 'obj' from pile 'pile'. More...
 
struct objectpile_last_item (struct object *const pile)
 Return the last item in pile 'pile'. More...
 
bool pile_contains (const struct object *top, const struct object *obj)
 Check if pile 'pile' contains object 'obj'. More...
 
struct objectobject_new (void)
 Create a new object and return it. More...
 
void object_free (struct object *obj)
 Free up an object. More...
 
void object_delete (struct object **obj_address)
 Delete an object and free its memory, and set its pointer to NULL. More...
 
void object_pile_free (struct object *obj)
 Free an entire object pile. More...
 
bool object_stackable (const struct object *obj1, const struct object *obj2, object_stack_t mode)
 Determine if an item can "absorb" a second item. More...
 
bool object_similar (const struct object *obj1, const struct object *obj2, object_stack_t mode)
 Return whether each stack of objects can be merged into one stack. More...
 
void object_origin_combine (struct object *obj1, const struct object *obj2)
 Combine the origins of two objects. More...
 
static void object_absorb_merge (struct object *obj1, const struct object *obj2)
 Allow one item to "absorb" another, assuming they are similar. More...
 
void object_absorb_partial (struct object *obj1, struct object *obj2)
 Merge a smaller stack into a larger stack, leaving two uneven stacks. More...
 
void object_absorb (struct object *obj1, struct object *obj2)
 Merge two stacks into one stack. More...
 
void object_wipe (struct object *obj)
 Wipe an object clean. More...
 
void object_copy (struct object *dest, const struct object *src)
 Prepare an object based on an existing object. More...
 
void object_copy_amt (struct object *dest, struct object *src, int amt)
 Prepare an object dst representing amt objects, based on an existing object src representing at least amt objects. More...
 
struct objectobject_split (struct object *src, int amt)
 Split off 'amt' items from 'src' and return. More...
 
struct objectfloor_object_for_use (struct object *obj, int num, bool message, bool *none_left)
 Remove an amount of an object from the floor, returning a detached object which can be used - it is assumed that the object is on the player grid. More...
 
static struct objectfloor_get_oldest_ignored (struct chunk *c, int y, int x)
 Find and return the oldest object on the given grid marked as "ignore". More...
 
bool floor_carry (struct chunk *c, int y, int x, struct object *drop, bool *note)
 Let the floor carry an object, deleting old ignored items if necessary. More...
 
static void floor_carry_fail (struct object *drop, bool broke)
 Delete an object when the floor fails to carry it, and attempt to remove it from the object list. More...
 
static void drop_find_grid (struct object *drop, int *y, int *x)
 Find a grid near the given one for an object to fall on. More...
 
void drop_near (struct chunk *c, struct object **dropped, int chance, int y, int x, bool verbose)
 Let an object fall to the ground at or near a location. More...
 
void push_object (int y, int x)
 This will push objects off a square. More...
 
void floor_item_charges (struct object *obj)
 Describe the charges on an item on the floor. More...
 
int scan_floor (struct object **items, int max_size, object_floor_t mode, item_tester tester)
 Get a list of the objects at the player's location. More...
 
int scan_distant_floor (struct object **items, int max_size, int y, int x)
 Get a list of the known objects at the given location. More...
 
int scan_items (struct object **item_list, size_t item_max, int mode, item_tester tester)
 Get a list of "valid" objects. More...
 
bool item_is_available (struct object *obj)
 Check if the given item is available for the player to use. More...
 

Variables

static struct objectfail_pile
 
static struct objectfail_object
 
static bool fail_prev
 
static bool fail_next
 
static char * fail_file
 
static int fail_line
 

Detailed Description

Deal with piles of objects.

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.

Function Documentation

◆ drop_find_grid()

static void drop_find_grid ( struct object drop,
int y,
int x 
)
static

Find a grid near the given one for an object to fall on.

We check several locations to see if we can find a location at which the object can combine, stack, or be placed. Artifacts will try very hard to be placed, including "teleporting" to a useful grid if needed.

If no appropriate grid is found, the given grid is unchanged

References object::artifact, cave, floor_get_oldest_ignored(), angband_constants::floor_size, chunk::height, i, ignore_item_ok(), los(), object::next, object_similar(), one_in_, OPT, OSTACK_FLOOR, rand_spread, randint0, square_canputitem(), square_in_bounds_fully(), square_isfloor(), square_isplayertrap(), square_iswarded(), square_object(), chunk::width, and z_info.

Referenced by drop_near().

◆ drop_near()

void drop_near ( struct chunk c,
struct object **  dropped,
int  chance,
int  y,
int  x,
bool  verbose 
)

Let an object fall to the ground at or near a location.

The initial location is assumed to be "square_in_bounds_fully(cave, )".

This function takes a parameter "chance". This is the percentage chance that the item will "disappear" instead of drop. If the object has been thrown, then this is the chance of disappearance on contact.

This function will produce a description of a drop event under the player when "verbose" is true.

The calling function needs to deal with the consequences of the dropped object being destroyed or absorbed into an existing pile.

References cave, drop_find_grid(), floor_carry(), floor_carry_fail(), ignore_item_ok(), square::mon, msg, object_desc(), ODESC_BASE, randint0, sound(), and chunk::squares.

Referenced by acquirement(), chest_death(), inven_drop(), monster_death(), pack_overflow(), push_object(), ranged_helper(), refill_lamp(), wiz_create_item_drop_object(), and wiz_test_kind().

◆ floor_carry()

bool floor_carry ( struct chunk c,
int  y,
int  x,
struct object drop,
bool *  note 
)

Let the floor carry an object, deleting old ignored items if necessary.

The calling function must deal with the dropped object on failure.

Optionally put the object at the top or bottom of the pile

References delist_object(), floor_get_oldest_ignored(), angband_constants::floor_size, object::held_m_idx, ignore_item_ok(), object::ix, object::iy, list_object(), object::next, square::obj, object_absorb(), object_delete(), object_similar(), OPT, OSTACK_FLOOR, pile_insert(), square_excise_object(), square_isobjectholding(), square_light_spot(), square_note_spot(), square_object(), chunk::squares, and z_info.

Referenced by drop_near(), mon_create_mimicked_object(), place_gold(), and place_object().

◆ floor_carry_fail()

static void floor_carry_fail ( struct object drop,
bool  broke 
)
static

Delete an object when the floor fails to carry it, and attempt to remove it from the object list.

References cave, player::cave, delist_object(), object::ix, object::iy, object::known, msg, object::number, object_delete(), object_desc(), ODESC_BASE, square_excise_object(), and VERB_AGREEMENT.

Referenced by drop_near().

◆ floor_get_oldest_ignored()

static struct object* floor_get_oldest_ignored ( struct chunk c,
int  y,
int  x 
)
static

Find and return the oldest object on the given grid marked as "ignore".

References ignore_item_ok(), object::next, NULL, and square_object().

Referenced by drop_find_grid(), and floor_carry().

◆ floor_item_charges()

void floor_item_charges ( struct object obj)

Describe the charges on an item on the floor.

References msg, object_flavor_is_aware(), object::pval, and tval_can_have_charges().

Referenced by use_aux().

◆ floor_object_for_use()

struct object* floor_object_for_use ( struct object obj,
int  num,
bool  message,
bool *  none_left 
)

◆ item_is_available()

bool item_is_available ( struct object obj)

Check if the given item is available for the player to use.

References cave, object_is_carried(), player::px, player::py, and square_holds_object().

Referenced by do_cmd_fire().

◆ object_absorb()

void object_absorb ( struct object obj1,
struct object obj2 
)

◆ object_absorb_merge()

static void object_absorb_merge ( struct object obj1,
const struct object obj2 
)
static

Allow one item to "absorb" another, assuming they are similar.

The blending of the "note" field assumes that either (1) one has an inscription and the other does not, or (2) neither has an inscription. In both these cases, we can simply use the existing note, unless the blending object has a note, in which case we use that note.

These assumptions are enforced by the "object_similar()" code.

References object::effect, object::known, MAX_PVAL, object::note, object_origin_combine(), player_know_object(), object::pval, object::timeout, tval_can_have_charges(), tval_can_have_timeout(), and tval_is_money().

Referenced by object_absorb(), and object_absorb_partial().

◆ object_absorb_partial()

void object_absorb_partial ( struct object obj1,
struct object obj2 
)

Merge a smaller stack into a larger stack, leaving two uneven stacks.

References object_kind::base, object::kind, MAX, object_base::max_stack, MIN, object::number, and object_absorb_merge().

Referenced by combine_pack().

◆ object_copy()

void object_copy ( struct object dest,
const struct object src 
)

◆ object_copy_amt()

void object_copy_amt ( struct object dest,
struct object src,
int  amt 
)

Prepare an object dst representing amt objects, based on an existing object src representing at least amt objects.

Takes care of the charge redistribution concerns of stacked items.

References AVERAGE, object::note, object::number, object_copy(), object::pval, randcalc(), object::time, object::timeout, tval_can_have_charges(), and tval_can_have_timeout().

Referenced by do_cmd_buy(), do_cmd_retrieve(), do_cmd_sell(), do_cmd_stash(), store_purchase(), and store_sell().

◆ object_delete()

void object_delete ( struct object **  obj_address)

◆ object_free()

void object_free ( struct object obj)

Free up an object.

This doesn't affect any game state outside of the object itself

References object::brands, object::curses, mem_free(), and object::slays.

Referenced by cleanup_player(), object_delete(), and test_obj_piles().

◆ object_new()

struct object* object_new ( void  )

◆ object_origin_combine()

void object_origin_combine ( struct object obj1,
const struct object obj2 
)

◆ object_pile_free()

void object_pile_free ( struct object obj)

◆ object_similar()

bool object_similar ( const struct object obj1,
const struct object obj2,
object_stack_t  mode 
)

◆ object_split()

struct object* object_split ( struct object src,
int  amt 
)

Split off 'amt' items from 'src' and return.

Where object_copy_amt() makes amt new objects, this function leaves the total number unchanged; otherwise the two functions are similar.

This function should only be used when amt < src->number

References distribute_charges(), object::known, object::note, object::number, object_copy(), object_new(), and object::oidx.

Referenced by floor_object_for_use(), gear_object_for_use(), refill_lamp(), and wield_all().

◆ object_stackable()

bool object_stackable ( const struct object obj1,
const struct object obj2,
object_stack_t  mode 
)

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

References object::ac, object::artifact, player::body, curses_are_equal(), object::dd, object::ds, object::ego, object::el_info, EL_INFO_HATES, EL_INFO_IGNORE, ELEM_MAX, element_info::flags, object::flags, i, object::kind, object::known, MAX_PVAL, object::modifiers, object::note, OBJ_MOD_MAX, object_fully_known(), object_is_equipped(), of_is_equal, OSTACK_LIST, object::pval, element_info::res_level, object::timeout, object::to_a, object::to_d, object::to_h, tval_can_have_charges(), tval_is_armor(), tval_is_chest(), tval_is_edible(), tval_is_jewelry(), tval_is_light(), tval_is_money(), tval_is_potion(), tval_is_rod(), tval_is_scroll(), and tval_is_weapon().

Referenced by find_stack_object_in_inventory(), inven_can_stack_partial(), inven_carry_num(), object_similar(), and quiver_absorb_num().

◆ object_wipe()

void object_wipe ( struct object obj)

◆ pile_check_integrity()

void pile_check_integrity ( const char *  op,
struct object pile,
struct object hilight 
)

Check the integrity of a linked - make sure it's not circular and that each entry in the chain has consistent next and prev pointers.

References i, object::next, NULL, pile_integrity_fail(), prev, and object::prev.

Referenced by pile_excise(), pile_insert(), pile_insert_end(), and pile_last_item().

◆ pile_contains()

bool pile_contains ( const struct object top,
const struct object obj 
)

◆ pile_excise()

void pile_excise ( struct object **  pile,
struct object obj 
)

◆ pile_insert()

void pile_insert ( struct object **  pile,
struct object obj 
)

Insert 'obj' into the pile 'pile'.

'obj' must not already be in any other lists.

References object::next, NULL, pile_check_integrity(), pile_integrity_fail(), and object::prev.

Referenced by floor_carry(), home_carry(), monster_carry(), rd_monster(), store_carry(), test_obj_piles(), and wield_all().

◆ pile_insert_end()

void pile_insert_end ( struct object **  pile,
struct object obj 
)

Insert 'obj' at the end of pile 'pile'.

Unlike pile_insert(), obj can be the beginning of a new list of objects.

References object::next, NULL, pile_check_integrity(), pile_integrity_fail(), pile_last_item(), and object::prev.

Referenced by gear_insert_end(), object_see(), object_sense(), rd_objects_aux(), test_obj_piles(), and wield_all().

◆ pile_integrity_fail()

void pile_integrity_fail ( struct object pile,
struct object obj,
char *  file,
int  line 
)

◆ pile_last_item()

struct object* pile_last_item ( struct object *const  pile)

Return the last item in pile 'pile'.

References object::next, NULL, and pile_check_integrity().

Referenced by gear_last_item(), pile_insert_end(), and test_obj_piles().

◆ push_object()

void push_object ( int  y,
int  x 
)

This will push objects off a square.

The methodology is to load all objects on the square into a queue. Replace the previous square with a type that does not allow for objects. Drop the objects. Last, put the square back to its original type.

References cave, drop_near(), feature::fidx, angband_constants::floor_size, object::ix, object::iy, object::next, NULL, square::obj, object::prev, q_free(), q_len(), q_new(), q_pop_ptr, q_push_ptr, square_add_door(), square_add_ward(), square_feat(), square_force_floor(), square_iswarded(), square_object(), square_set_feat(), chunk::squares, and z_info.

Referenced by build_quest_stairs(), effect_handler_CREATE_STAIRS(), effect_handler_RUNE(), project_feature_handler_FIRE(), project_feature_handler_MAKE_DOOR(), project_feature_handler_PLASMA(), and use_aux().

◆ scan_distant_floor()

int scan_distant_floor ( struct object **  items,
int  max_size,
int  y,
int  x 
)

Get a list of the known objects at the given location.

Return the number of objects acquired.

References cave, player::cave, ignore_known_item_ok(), object::kind, object::next, num, chunk::objects, object::oidx, square_in_bounds(), square_object(), and unknown_item_kind.

Referenced by target_set_interactive_aux().

◆ scan_floor()

int scan_floor ( struct object **  items,
int  max_size,
object_floor_t  mode,
item_tester  tester 
)

Get a list of the objects at the player's location.

Return the number of objects acquired.

References cave, ignore_item_ok(), is_unknown(), object::known, object::next, num, object_test(), OFLOOR_SENSE, OFLOOR_TEST, OFLOOR_TOP, OFLOOR_VISIBLE, player::px, player::py, square_in_bounds(), and square_object().

Referenced by player_pickup_item(), scan_items(), see_floor_items(), and textui_get_item().

◆ scan_items()

int scan_items ( struct object **  item_list,
size_t  item_max,
int  mode,
item_tester  tester 
)

Get a list of "valid" objects.

Fills item_list[] with items that are "okay" as defined by the provided tester function, etc. mode determines what combination of inventory, equipment, quiver and player's floor location should be used when drawing up the list.

Returns the number of items placed into the list.

Maximum space that can be used is z_info->pack_size + z_info->quiver_size + player->body.count + z_info->floor_size, though practically speaking much smaller numbers are likely.

References player::body, player_body::count, floor_list, angband_constants::floor_size, i, player_upkeep::inven, mem_free(), mem_zalloc(), object_test(), OFLOOR_SENSE, OFLOOR_TEST, OFLOOR_VISIBLE, angband_constants::pack_size, player_upkeep::quiver, angband_constants::quiver_size, scan_floor(), slot_object(), player::upkeep, USE_EQUIP, USE_FLOOR, USE_INVEN, USE_QUIVER, and z_info.

Referenced by player_book_has_unlearned_spells().

◆ write_pile()

void write_pile ( ang_file fff)

Variable Documentation

◆ fail_file

char* fail_file
static

Referenced by pile_integrity_fail(), and write_pile().

◆ fail_line

int fail_line
static

Referenced by pile_integrity_fail(), and write_pile().

◆ fail_next

bool fail_next
static

Referenced by pile_integrity_fail(), and write_pile().

◆ fail_object

struct object* fail_object
static

◆ fail_pile

struct object* fail_pile
static

◆ fail_prev

bool fail_prev
static

Referenced by pile_integrity_fail(), and write_pile().