Angband
Macros | Functions
obj-util.h File Reference

Object utilities. More...

Go to the source code of this file.

Macros

#define MAX_TITLES   50
 
#define MAX_PVAL   32767
 

Functions

void flavor_init (void)
 Prepare the "variable" part of the "k_info" array. More...
 
void object_flags (const struct object *obj, bitflag flags[OF_SIZE])
 Obtain the flags for an item. More...
 
void object_flags_known (const struct object *obj, bitflag flags[OF_SIZE])
 Obtain the flags for an item which are known to the player. More...
 
bool object_test (item_tester tester, const struct object *o)
 Apply a tester function, skipping all non-objects and gold. More...
 
bool item_test (item_tester tester, int item)
 
bool is_unknown (const struct object *obj)
 Return true if the item is unknown (has yet to be seen by the player). More...
 
unsigned check_for_inscrip (const struct object *obj, const char *inscrip)
 Looks if "inscrip" is present on the given object. More...
 
struct object_kindlookup_kind (int tval, int sval)
 Return the object kind with the given tval and sval, or NULL. More...
 
struct object_kindobjkind_byid (int kidx)
 
struct artifactlookup_artifact_name (const char *name)
 Return the a_idx of the artifact with the given name. More...
 
struct ego_itemlookup_ego_item (const char *name, int tval, int sval)
 
int lookup_sval (int tval, const char *name)
 Return the numeric sval of the object kind with the given tval and name name. More...
 
void object_short_name (char *buf, size_t max, const char *name)
 
int compare_items (const struct object *o1, const struct object *o2)
 Sort comparator for objects -1 if o1 should be first 1 if o2 should be first 0 if it doesn't matter. More...
 
bool obj_has_charges (const struct object *obj)
 Determine if an object has charges. More...
 
bool obj_can_zap (const struct object *obj)
 Determine if an object is zappable. More...
 
bool obj_is_activatable (const struct object *obj)
 Determine if an object is activatable. More...
 
bool obj_can_activate (const struct object *obj)
 Determine if an object can be activated now. More...
 
bool obj_can_refill (const struct object *obj)
 Check if an object can be used to refuel other objects. More...
 
bool obj_can_browse (const struct object *obj)
 
bool obj_can_cast_from (const struct object *obj)
 
bool obj_can_study (const struct object *obj)
 
bool obj_can_takeoff (const struct object *obj)
 
bool obj_can_wear (const struct object *obj)
 
bool obj_can_fire (const struct object *obj)
 
bool obj_has_inscrip (const struct object *obj)
 
bool obj_has_flag (const struct object *obj, int flag)
 
bool obj_is_useable (const struct object *obj)
 
struct effectobject_effect (const struct object *obj)
 Return an object's effect. More...
 
bool obj_needs_aim (struct object *obj)
 Does the given object need to be aimed? More...
 
bool obj_can_fail (const struct object *o)
 Can the object fail if used? More...
 
int get_use_device_chance (const struct object *obj)
 Returns the number of times in 1000 that @ will FAIL. More...
 
void distribute_charges (struct object *source, struct object *dest, int amt)
 Distribute charges of rods, staves, or wands. More...
 
int number_charging (const struct object *obj)
 Number of items (usually rods) charging. More...
 
bool recharge_timeout (struct object *obj)
 Allow a stack of charging objects to charge by one unit per charging object Return true if something recharged. More...
 
bool verify_object (const char *prompt, struct object *obj)
 Verify the choice of an item. More...
 

Detailed Description

Object utilities.

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 MAX_PVAL   32767
#define MAX_TITLES   50

Referenced by flavor_init().

Function Documentation

unsigned check_for_inscrip ( const struct object obj,
const char *  inscrip 
)

Looks if "inscrip" is present on the given object.

References i, object::note, and quark_str().

Referenced by auto_pickup_okay(), do_cmd_wield(), get_item_allow(), ignore_drop(), key_confirm_command(), and object_is_ignored().

int compare_items ( const struct object o1,
const struct object o2 
)

Sort comparator for objects -1 if o1 should be first 1 if o2 should be first 0 if it doesn't matter.

The sort order is designed with the "list items" command in mind.

References compare_types(), object_kind::cost, is_unknown(), object::kind, object_flavor_is_aware(), and object_is_known_artifact().

Referenced by object_list_standard_compare().

void distribute_charges ( struct object source,
struct object dest,
int  amt 
)

Distribute charges of rods, staves, or wands.

Parameters
sourceis the source item
destis the target item, must be of the same type as source
amtis the number of items that are transfered

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

Referenced by do_cmd_retrieve(), and object_split().

void flavor_init ( void  )

Prepare the "variable" part of the "k_info" array.

The "color"/"metal"/"type" of an item is its "flavor". For the most part, flavors are assigned randomly each game.

Initialize descriptions for the "colored" objects, including: Rings, Amulets, Staffs, Wands, Rods, Mushrooms, Potions, Scrolls.

Scroll titles are always between 6 and 14 letters long. This is ensured because every title is composed of whole words, where every word is from 2 to 8 letters long, and that no scroll is finished until it attempts to grow beyond 15 letters. The first time this can happen is when the current title has 6 letters and the new word has 8 letters, which would result in a 6 letter scroll title.

Hack – make sure everything stays the same for each saved game This is accomplished by the use of a saved "random seed", as in "town_gen()". Since no other functions are called while the special seed is in effect, so this function is pretty "safe".

References object_kind::aware, buf, object_kind::flavor, flavor_assign_fixed(), flavor_assign_random(), flavor_reset_fixed(), i, angband_constants::k_max, MAX_TITLES, my_strcpy(), object_kind::name, name_sections, OPT, Rand_quick, Rand_value, randname_make(), RANDNAME_SCROLL, scroll_adj, seed_flavor, streq, and z_info.

Referenced by do_cmd_accept_character(), and rd_misc().

int get_use_device_chance ( const struct object obj)

Returns the number of times in 1000 that @ will FAIL.

  • thanks to Ed Graham for the formula

References object::artifact, object::kind, object_kind::level, artifact::level, SKILL_DEVICE, player_state::skills, and player::state.

Referenced by check_devices(), obj_known_effect(), and show_obj().

bool is_unknown ( const struct object obj)
bool item_test ( item_tester  tester,
int  item 
)
struct artifact* lookup_artifact_name ( const char *  name)

Return the a_idx of the artifact with the given name.

References angband_constants::a_max, i, my_stristr(), artifact::name, NULL, streq, and z_info.

Referenced by parse_lore_drop_artifact(), parse_monster_drop_artifact(), rd_history(), and rd_item().

struct ego_item* lookup_ego_item ( const char *  name,
int  tval,
int  sval 
)
Parameters
nameego type name
tvalobject tval
svalobject sval
Returns
eidx of the ego item type

References angband_constants::e_max, i, object_kind::kidx, poss_item::kidx, lookup_kind(), ego_item::name, poss_item::next, NULL, ego_item::poss_items, streq, and z_info.

Referenced by rd_item().

struct object_kind* lookup_kind ( int  tval,
int  sval 
)
int lookup_sval ( int  tval,
const char *  name 
)
int number_charging ( const struct object obj)

Number of items (usually rods) charging.

References AVERAGE, object::number, randcalc(), object::time, and object::timeout.

Referenced by obj_can_zap(), obj_desc_charges(), recharge_objects(), and recharge_timeout().

bool obj_can_activate ( const struct object obj)

Determine if an object can be activated now.

References obj_is_activatable(), and object::timeout.

Referenced by context_menu_object(), and do_cmd_activate().

bool obj_can_browse ( const struct object obj)
bool obj_can_cast_from ( const struct object obj)
bool obj_can_fail ( const struct object o)

Can the object fail if used?

References tval_can_have_failure(), and wield_slot().

Referenced by show_obj().

bool obj_can_fire ( const struct object obj)
bool obj_can_refill ( const struct object obj)

Check if an object can be used to refuel other objects.

References equipped_item_by_slot_name(), object::flags, of_has, object::timeout, tval_is_fuel(), and tval_is_light().

Referenced by context_menu_object(), do_cmd_refill(), do_cmd_use(), and test_obj_can_refill().

bool obj_can_study ( const struct object obj)
bool obj_can_takeoff ( const struct object obj)
bool obj_can_wear ( const struct object obj)
bool obj_can_zap ( const struct object obj)

Determine if an object is zappable.

References object::number, number_charging(), and tval_can_have_timeout().

Referenced by context_menu_object(), and do_cmd_zap_rod().

bool obj_has_charges ( const struct object obj)

Determine if an object has charges.

References object::pval, and tval_can_have_charges().

Referenced by context_menu_object(), do_cmd_aim_wand(), and do_cmd_use_staff().

bool obj_has_flag ( const struct object obj,
int  flag 
)
bool obj_has_inscrip ( const struct object obj)

References object::note.

Referenced by context_menu_object(), and do_cmd_uninscribe().

bool obj_is_activatable ( const struct object obj)

Determine if an object is activatable.

References object_effect(), and tval_is_wearable().

Referenced by context_menu_object(), do_cmd_activate(), do_cmd_use(), and obj_can_activate().

bool obj_is_useable ( const struct object obj)
bool obj_needs_aim ( struct object obj)

Does the given object need to be aimed?

References effect_aim(), object_effect(), object_flavor_is_aware(), tval_is_ammo(), tval_is_rod(), and tval_is_wand().

Referenced by use_aux().

struct effect* object_effect ( const struct object obj)
void object_flags ( const struct object obj,
bitflag  flags[OF_SIZE] 
)
void object_flags_known ( const struct object obj,
bitflag  flags[OF_SIZE] 
)
void object_short_name ( char *  buf,
size_t  max,
const char *  name 
)
bool object_test ( item_tester  tester,
const struct object o 
)

Apply a tester function, skipping all non-objects and gold.

References tval_is_money().

Referenced by build_obj_list(), scan_floor(), scan_items(), and textui_get_item().

struct object_kind* objkind_byid ( int  kidx)
bool recharge_timeout ( struct object obj)

Allow a stack of charging objects to charge by one unit per charging object Return true if something recharged.

References MIN, number_charging(), and object::timeout.

Referenced by recharge_objects().

bool verify_object ( const char *  prompt,
struct object obj 
)

Verify the choice of an item.

The item can be negative to mean "item on floor".

References get_check(), object_desc(), ODESC_FULL, ODESC_PREFIX, and strnfmt().

Referenced by get_item_allow(), and ignore_drop().