Angband
Functions
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 "monster.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-identify.h"
#include "obj-ignore.h"
#include "obj-info.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-slays.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-history.h"
#include "player-spell.h"
#include "player-util.h"
#include "randname.h"
#include "z-queue.h"

Functions

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.
void pile_insert (struct object **pile, struct object *obj)
 Insert 'obj' into the pile 'pile'.
void pile_insert_end (struct object **pile, struct object *obj)
 Insert 'obj' at the end of pile 'pile'.
void pile_excise (struct object **pile, struct object *obj)
 Remove object 'obj' from pile 'pile'.
struct objectpile_last_item (struct object *const pile)
 Return the last item in pile 'pile'.
bool pile_contains (const struct object *top, const struct object *obj)
 Check if pile 'pile' contains object 'obj'.
struct objectobject_new (void)
 Create a new object and return it.
void object_delete (struct object *obj)
 Delete an object and free its memory.
void object_pile_free (struct object *obj)
 Free an entire object pile.
bool object_stackable (const struct object *o_ptr, const struct object *j_ptr, object_stack_t mode)
 Determine if an item can "absorb" a second item.
bool object_similar (const struct object *o_ptr, const struct object *j_ptr, object_stack_t mode)
 Return whether each stack of objects can be merged into one stack.
static void object_absorb_merge (struct object *o_ptr, const struct object *j_ptr)
 Allow one item to "absorb" another, assuming they are similar.
void object_absorb_partial (struct object *o_ptr, struct object *j_ptr)
 Merge a smaller stack into a larger stack, leaving two uneven stacks.
void object_absorb (struct object *o_ptr, struct object *j_ptr)
 Merge two stacks into one stack.
void object_wipe (struct object *obj)
 Wipe an object clean.
void object_copy (struct object *dest, const struct object *src)
 Prepare an object based on an existing object.
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.
struct objectobject_split (struct object *src, int amt)
 Split off 'amt' items from 'src' and return.
struct objectfloor_object_for_use (struct object *obj, int num, bool message)
 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.
static struct objectfloor_get_oldest_ignored (int y, int x)
 Find and return the oldest object on the given grid marked as "ignore".
bool floor_carry (struct chunk *c, int y, int x, struct object *drop, bool last)
 Let the floor carry an object, deleting old ignored items if necessary.
void drop_near (struct chunk *c, struct object *j_ptr, int chance, int y, int x, bool verbose)
 Let an object fall to the ground at or near a location.
void push_object (int y, int x)
 This will push objects off a square.
void floor_item_charges (struct object *obj)
 Describe the charges on an item on the floor.
int scan_floor (struct object **items, int max_size, int y, int x, int mode, item_tester tester)
 Get the indexes of objects at a given floor location.
int scan_items (struct object **item_list, size_t item_max, int mode, item_tester tester)
 Get a list of "valid" objects.
bool item_is_available (struct object *obj, bool(*tester)(const struct object *), int mode)
 Check if the given item is available for the player to use.

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

void drop_near ( struct chunk c,
struct object j_ptr,
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.

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.

Objects which fail to be carried by the floor are deleted.

References object::artifact, cave, artifact::created, FALSE, flag, floor_carry(), floor_get_oldest_ignored(), angband_constants::floor_size, chunk::height, i, ignore_item_ok(), los(), square::mon, msg, object::next, object::number, object_desc(), object_similar(), ODESC_BASE, OPT, OSTACK_FLOOR, rand_spread, randint0, sound(), square_canputitem(), square_in_bounds_fully(), square_isfloor(), square_object(), chunk::squares, TRUE, VERB_AGREEMENT, chunk::width, player::wizard, and z_info.

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

bool floor_carry ( struct chunk c,
int  y,
int  x,
struct object drop,
bool  last 
)
static struct object* floor_get_oldest_ignored ( int  y,
int  x 
)
staticread

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

References cave, object::ignore, ignore_item_ok(), object::next, and square_object().

Referenced by drop_near(), and floor_carry().

void floor_item_charges ( struct object obj)

Describe the charges on an item on the floor.

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

Referenced by use_aux().

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

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.

Optionally describe what remains.

References cave, MIN, msg, player_upkeep::notice, object::number, object_desc(), object_split(), ODESC_FULL, ODESC_PREFIX, PN_COMBINE, PR_EQUIP, PR_INVEN, PU_BONUS, PU_INVEN, PU_MANA, player::px, player::py, player_upkeep::redraw, square_excise_object(), player_upkeep::update, and player::upkeep.

Referenced by effect_handler_RECHARGE(), ranged_helper(), refill_lamp(), and use_aux().

bool item_is_available ( struct object obj,
bool(*)(const struct object *)  tester,
int  mode 
)

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

'mode' defines which areas we should look at, a la scan_items().

References player::body, player_body::count, FALSE, angband_constants::floor_size, i, mem_free(), mem_zalloc(), angband_constants::pack_size, angband_constants::quiver_size, scan_items(), TRUE, and z_info.

Referenced by do_cmd_fire().

void object_absorb ( struct object o_ptr,
struct object j_ptr 
)
static void object_absorb_merge ( struct object o_ptr,
const struct object j_ptr 
)
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 FALSE, monster_race::flags, object::known_flags, MAX_PVAL, object::note, of_union, object::origin, object::origin_depth, object::origin_xtra, object::pval, r_info, rf_has, object::timeout, TRUE, tval_can_have_charges(), tval_can_have_timeout(), and tval_is_money().

Referenced by object_absorb(), and object_absorb_partial().

void object_absorb_partial ( struct object o_ptr,
struct object j_ptr 
)

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

References MAX, MIN, object::number, object_absorb_merge(), angband_constants::stack_size, and z_info.

Referenced by combine_pack().

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

Prepare an object based on an existing object.

References object::brands, copy_brand(), copy_slay(), object::next, object::prev, and object::slays.

Referenced by object_copy_amt(), object_split(), and wiz_reroll_item().

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

void object_delete ( struct object obj)
struct object* object_new ( void  )
read
void object_pile_free ( struct object obj)
bool object_similar ( const struct object o_ptr,
const struct object j_ptr,
object_stack_t  mode 
)
struct object* object_split ( struct object src,
int  amt 
)
read

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.

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

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

bool object_stackable ( const struct object o_ptr,
const struct object j_ptr,
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, object::dd, object::ds, object::ego, FALSE, object::flags, i, object::kind, MARK_AWARE, object::marked, MAX_PVAL, object::modifiers, object::note, OBJ_MOD_MAX, object_is_equipped(), object_is_known(), of_is_equal, OSTACK_LIST, object::pval, object::timeout, object::to_a, object::to_d, object::to_h, TRUE, tval_can_have_charges(), tval_is_armor(), tval_is_chest(), tval_is_food(), tval_is_jewelry(), tval_is_light(), tval_is_money(), tval_is_potion(), tval_is_rod(), tval_is_scroll(), and tval_is_weapon().

Referenced by inven_can_stack_partial(), and object_similar().

void object_wipe ( struct object obj)

Wipe an object clean.

Referenced by history_add_artifact(), and wiz_reroll_item().

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, prev, and object::prev.

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

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

Check if pile 'pile' contains object 'obj'.

References FALSE, object::next, and TRUE.

Referenced by do_cmd_buy(), do_cmd_retrieve(), object_is_carried(), pile_excise(), square_holds_object(), test_obj_piles(), and wield_item().

void pile_excise ( struct object **  pile,
struct object obj 
)
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, pile_check_integrity(), and object::prev.

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

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, pile_check_integrity(), pile_last_item(), and object::prev.

Referenced by floor_carry(), gear_insert_end(), test_obj_piles(), and wield_all().

struct object* pile_last_item ( struct object *const  pile)
read

Return the last item in pile 'pile'.

References object::next, and pile_check_integrity().

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

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(), FALSE, feature::fidx, angband_constants::floor_size, object::next, object::prev, q_free(), q_len(), q_new(), q_pop_ptr, q_push_ptr, square_add_door(), square_feat(), square_force_floor(), square_object(), square_set_feat(), and z_info.

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

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

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 items only 0x04 – Only the top item 0x08 – Visible items only

References cave, ignore_item_ok(), is_unknown(), object::marked, object::next, num, object_test(), square_in_bounds(), and square_object().

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

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, FALSE, angband_constants::floor_size, i, player_upkeep::inven, mem_free(), mem_zalloc(), object_test(), angband_constants::pack_size, player::px, player::py, player_upkeep::quiver, angband_constants::quiver_size, scan_floor(), slot_object(), TRUE, player::upkeep, USE_EQUIP, USE_FLOOR, USE_INVEN, USE_QUIVER, and z_info.

Referenced by item_is_available().