Angband
Macros | Enumerations | Functions
obj-pile.h File Reference

Deal with piles of objects. More...

#include "cave.h"
#include "player.h"

Go to the source code of this file.

Macros

#define OBJECT_LIST_SIZE   128
 
#define OBJECT_LIST_INCR   128
 

Enumerations

enum  object_stack_t {
  OSTACK_NONE = 0x00, OSTACK_STORE = 0x01, OSTACK_PACK = 0x02, OSTACK_LIST = 0x04,
  OSTACK_MONSTER = 0x08, OSTACK_FLOOR = 0x10, OSTACK_QUIVER = 0x20
}
 Modes for stacking by object_similar() More...
 
enum  object_floor_t {
  OFLOOR_NONE = 0x00, OFLOOR_TEST = 0x01, OFLOOR_SENSE = 0x02, OFLOOR_TOP = 0x04,
  OFLOOR_VISIBLE = 0x08
}
 Modes for floor scanning by scan_floor() More...
 

Functions

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...
 
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...
 
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...
 
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 *obj1, const struct object *obj2)
 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...
 
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. 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_list_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...
 

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.

Macro Definition Documentation

#define OBJECT_LIST_INCR   128

Referenced by list_object().

#define OBJECT_LIST_SIZE   128

Referenced by cave_new().

Enumeration Type Documentation

Modes for floor scanning by scan_floor()

Enumerator
OFLOOR_NONE 
OFLOOR_TEST 
OFLOOR_SENSE 
OFLOOR_TOP 
OFLOOR_VISIBLE 

Modes for stacking by object_similar()

Enumerator
OSTACK_NONE 
OSTACK_STORE 
OSTACK_PACK 
OSTACK_LIST 
OSTACK_MONSTER 
OSTACK_FLOOR 
OSTACK_QUIVER 

Function Documentation

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(), chunk::objects, 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().

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.

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, object::ix, object::iy, list_object(), object::next, square::obj, object_absorb(), object_delete(), object_similar(), OPT, OSTACK_FLOOR, pile_insert(), pile_insert_end(), square_excise_object(), square_isobjectholding(), square_light_spot(), square_note_spot(), square_object(), chunk::squares, and z_info.

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

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

struct object* floor_object_for_use ( struct object obj,
int  num,
bool  message,
bool *  none_left 
)
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().

void object_absorb ( struct object obj1,
struct object obj2 
)
void object_absorb_partial ( struct object obj1,
struct object obj2 
)

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 obj1,
const struct object obj2 
)
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_address)
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(), and object_delete().

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

Combine the origins of two objects.

References monster_race::flags, object::origin, object::origin_depth, object::origin_race, rf_has, and RF_UNIQUE.

Referenced by object_absorb_merge(), and store_object_absorb().

void object_pile_free ( struct object obj)
bool object_similar ( const struct object obj1,
const struct object obj2,
object_stack_t  mode 
)
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().

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 inven_can_stack_partial(), inven_carry_num(), object_similar(), and quiver_absorb_num().

void object_wipe ( struct object obj)
bool pile_contains ( const struct object top,
const struct object obj 
)
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, NULL, 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, NULL, pile_check_integrity(), pile_last_item(), and object::prev.

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

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

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

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

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

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