![]() |
Crossfire Server, Trunk
1.75.0
|
#include "global.h"
#include <assert.h>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include "living.h"
#include "spells.h"
Go to the source code of this file.
Functions | |
static int | bits_set (uint32_t x) |
int | calc_item_enhancement (const object *op) |
int | calc_item_power (const object *op) |
This takes an object 'op' and figures out what its item_power rating should be. More... | |
StringBuffer * | describe_item (const object *op, const object *owner, int use_media_tags, StringBuffer *buf) |
Describes an item, in all its details. More... | |
StringBuffer * | describe_monster (const object *op, int use_media_tags, StringBuffer *buf) |
Describes a monster. More... | |
StringBuffer * | describe_resistance (const object *op, int newline, int use_media_tags, StringBuffer *buf) |
Generates the visible naming for resistances. More... | |
int | get_power_from_ench (int ench) |
const typedata * | get_typedata (int itemtype) |
const typedata * | get_typedata_by_name (const char *name) |
object * | identify (object *op) |
Identifies an item. More... | |
int | is_identifiable_type (const object *op) |
Return true if this item's type is one that cares about whether or not it's been identified – e.g. More... | |
int | is_identified (const object *op) |
Return true if the item is identified, either because it is of a type that doesn't ever need identification (e.g. More... | |
int | is_magical (const object *op) |
Checks whether object is magical. More... | |
void | object_give_identified_properties (object *op) |
Ensure op has all its "identified" properties set. More... | |
uint64_t | price_base (const object *obj) |
Price an item based on its value or archetype value, type, identification/BUC status, and other heuristics. More... | |
void | query_base_name (const object *op, int plural, char *buf, size_t size) |
Query a short name for the item. More... | |
void | query_name (const object *op, char *buf, size_t size) |
Describes an item. More... | |
void | query_short_name (const object *op, char *buf, size_t size) |
query_short_name(object) is similar to query_name(), but doesn't contain any information about object status (worn/cursed/etc.) More... | |
void | query_weight (const object *op, char *buf, size_t size) |
Formats the item's weight. More... | |
static StringBuffer * | ring_desc (const object *op, int use_media_tags, StringBuffer *buf) |
Describes a ring or amulet, or a skill. More... | |
Variables | |
body_locations_struct | body_locations [NUM_BODY_LOCATIONS] |
The ordering of this is actually doesn't make a difference However, for ease of use, new entries should go at the end so those people that debug the code that get used to something being in the location 4 don't get confused. More... | |
static const int | enc_to_item_power [] |
This curve may be too steep. More... | |
static const typedata | item_types [] |
The following is a large table of item types, the fields are: item number, item name, item name (plural), and two numbers that are the skills used to identify them. More... | |
static const int | item_types_size = sizeof(item_types)/sizeof(*item_types) |
Number of items in item_types array. More... | |
Those functions deal with objects in general, including description, body location, and such.
Definition in file item.cpp.
|
static |
Definition at line 221 of file item.cpp.
Referenced by calc_item_enhancement().
int calc_item_enhancement | ( | const object * | op | ) |
Definition at line 226 of file item.cpp.
References AMULET, ARMOUR, object::attacktype, bits_set(), BOOTS, BRACERS, CLOAK, living::exp, FLAG_LIFESAVE, FLAG_MAKE_INVIS, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_SEE_IN_DARK, FLAG_STEALTH, FLAG_XRAYS, living::food, get_attr_value(), GIRDLE, GLOVES, living::grace, HELMET, living::hp, if(), INORGANIC, living::luck, object::magic, NROFATTACKS, NUM_STATS, object::path_attuned, object::path_denied, object::path_repelled, QUERY_FLAG, object::resist, RING, SHIELD, object::slaying, living::sp, object::stats, object::type, and WEAPON.
Referenced by calc_item_power(), and price_base().
int calc_item_power | ( | const object * | op | ) |
This takes an object 'op' and figures out what its item_power rating should be.
This should only really be used by the treasure generation code, and when loading legacy objects. It returns the item_power it calculates.
op | object of which to compute the item_power |
Definition at line 318 of file item.cpp.
References calc_item_enhancement(), and get_power_from_ench().
Referenced by add_one_item(), and fix_generated_item().
StringBuffer* describe_item | ( | const object * | op, |
const object * | owner, | ||
int | use_media_tags, | ||
StringBuffer * | buf | ||
) |
Describes an item, in all its details.
It would be really handy to actually pass another object pointer on who is examining this object. Then, you could reveal certain information depending on what the examiner knows, eg, wouldn't need to use the SEE_INVISIBLE flag to know it is a dragon player examining food. Could have things like a dwarven axe, in which the full abilities are only known to dwarves, etc.
Add 'owner' who is the person examining this object. owner can be null if no one is being associated with this item (eg, debug dump or the like)
op | object to describe. Must not be NULL. |
owner | player examining the object. |
use_media_tags | if non-zero, then media tags (colors and such) are inserted in the description. This enables the player to more easily see some things. |
buf | buffer that will contain the description. Can be NULL. |
Definition at line 958 of file item.cpp.
References living::ac, AMULET, ARMOUR, ARMOUR_SPEED, ARMOUR_SPELLS, ARROW, atnr_is_dragon_enabled(), object::attacktype, BOOTS, BOW, BRACERS, buf, change_resist_msg, CLOAK, living::dam, describe_attacktype(), describe_monster(), describe_resistance(), describe_spellpath_attenuation(), DRINK, living::exp, FLAG_BEEN_APPLIED, FLAG_CURSED, FLAG_LIFESAVE, FLAG_MONSTER, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_REFLECTING, FLAG_SEE_IN_DARK, FLAG_STEALTH, FLAG_XRAYS, FLESH, FMT64, living::food, FOOD, FORCE, get_attr_value(), GIRDLE, GLOVES, object::glow_radius, living::grace, HELMET, living::hp, is_dragon_pl(), is_identified(), object::item_power, LAMP, object::last_eat, object::level, living::luck, object::magic, MOVE_FLY_HIGH, MOVE_FLY_LOW, MOVE_SWIM, object::move_type, NUM_STATS, object::path_attuned, object::path_denied, object::path_repelled, PLAYER, QUERY_FLAG, RING, ring_desc(), ROD, SHIELD, short_stat_name, SKILL, SKILL_TOOL, object::slaying, living::sp, object::stats, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_new(), object::title, object::type, WAND, living::wc, WEAPON, and WEAPON_SPEED.
Referenced by artifact_describe(), cfapi_object_describe(), common_ob_describe(), dump_abilities(), knowledge_add_probe_monster(), knowledge_monster_detail(), mon_desc(), and perceive_self().
StringBuffer* describe_monster | ( | const object * | op, |
int | use_media_tags, | ||
StringBuffer * | buf | ||
) |
Describes a monster.
op | monster to describe. Must not be NULL, and must have FLAG_MONSTER or be a PLAYER. |
use_media_tags | if non-zero, then media tags (colors and such) are inserted in the description. This enables the player to more easily see some things. |
buf | buffer that will contain the description. Can be NULL. |
Definition at line 784 of file item.cpp.
References object::attacktype, buf, object::contr, describe_attacktype(), describe_resistance(), describe_spellpath_attenuation(), player::digestion, FABS, FLAG_CAN_USE_SKILL, FLAG_CAST_SPELL, FLAG_FRIENDLY, FLAG_HITBACK, FLAG_MONSTER, FLAG_SEE_INVISIBLE, FLAG_STEALTH, FLAG_UNAGGRESSIVE, FLAG_UNDEAD, FLAG_USE_ARMOUR, FLAG_USE_BOW, FLAG_USE_RANGE, FLAG_USE_RING, FLAG_USE_SCROLL, FLAG_USE_WEAPON, player::gen_grace, player::gen_hp, player::gen_sp, is_dragon_pl(), treasurelist::items, living::luck, MIN_ACTIVE_SPEED, object_find_by_type_and_name(), object::path_attuned, object::path_denied, object::path_repelled, PLAYER, QUERY_FLAG, object::randomitems, SKILL, object::speed, SPELL, object::stats, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_new(), t, and object::type.
Referenced by describe_item().
StringBuffer* describe_resistance | ( | const object * | op, |
int | newline, | ||
int | use_media_tags, | ||
StringBuffer * | buf | ||
) |
Generates the visible naming for resistances.
op | object we want information about. |
newline | If TRUE, we don't put parens around the description but do put a newline at the end. Useful when dumping to files |
use_media_tags | if non-zero, then media tags (colors and such) are inserted in the description. This enables the player to more easily see some things. |
buf | buffer that will receive the description. Can be NULL. |
Definition at line 377 of file item.cpp.
References atnr_is_dragon_enabled(), buf, FLESH, NROFATTACKS, object::resist, resist_color, resist_plus, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_new(), and object::type.
Referenced by describe_god(), describe_item(), describe_monster(), dump_gods(), and ring_desc().
int get_power_from_ench | ( | int | ench | ) |
Definition at line 213 of file item.cpp.
References enc_to_item_power.
Referenced by calc_item_power(), and fix_generated_item().
const typedata* get_typedata | ( | int | itemtype | ) |
itemtype | item type for which to return typedata. |
Definition at line 328 of file item.cpp.
References item_types, and item_types_size.
Referenced by cost_approx_str(), examine_autoidentify(), is_identifiable_type(), parse_shop_string(), price_approx(), and skill_ident().
const typedata* get_typedata_by_name | ( | const char * | name | ) |
name | item name for which to return typedata. Singular form is preferred. |
Definition at line 348 of file item.cpp.
References item_types, item_types_size, llevInfo, LOG(), and name.
Referenced by parse_shop_string().
Identifies an item.
Supposed to fix face-values as well here, but later. Note - this may merge op with other object, so this function returns either the merged object or the original if no merge happened.
op | item to identify. Can be already identified without ill effects. |
object | The identify object - this may vary from op if the object was merged. |
Definition at line 1449 of file item.cpp.
References add_refcount(), object::arch, archetype::clone, object::container, object::env, esrv_update_item(), FLAG_IDENTIFIED, free_string(), GET_MAP_TOP, object::inv, object::map, map_find_by_type(), object::name, object::name_pl, object_get_player_container(), object_give_identified_properties(), object_merge(), object_update(), PLAYER, POTION, object::randomitems, SET_FLAG, object::title, object::type, UP_OBJ_FACE, UPD_ALL, UPD_FACE, UPD_FLAGS, UPD_NAME, object::x, and object::y.
Referenced by apply_auto(), cast_create_food(), cast_identify(), cfapi_object_identify(), identify_altar_type_move_on(), identify_object_with_skill(), monster_do_talk_npc(), potion_type_apply(), scroll_type_apply(), sell_item(), and spellbook_type_apply().
int is_identifiable_type | ( | const object * | op | ) |
Return true if this item's type is one that cares about whether or not it's been identified – e.g.
money and walls don't care (they are considered to be "always identified" no matter what FLAG_IDENTIFIED says) but weapons and scrolls do. In practice, this means anything with at least one identifyskill in the typedata, or skill tools (which have no identifyskill, but can still be IDed using magic).
op | Object to check. |
Definition at line 1336 of file item.cpp.
References get_typedata(), typedata::identifyskill, SKILL_TOOL, and object::type.
Referenced by check_loaded_object(), command_create(), examine_fluff(), give_initial_items(), is_identified(), and object_give_identified_properties().
int is_identified | ( | const object * | op | ) |
Return true if the item is identified, either because it is of a type that doesn't ever need identification (e.g.
money), or because it has FLAG_IDENTIFIED set. Uses is_identifiable_type() to distinguish between the two cases.
op | Object to check. |
Definition at line 1360 of file item.cpp.
References FLAG_IDENTIFIED, is_identifiable_type(), and QUERY_FLAG.
Referenced by add_abilities(), cast_create_food(), cast_identify(), check_loaded_object(), describe_item(), examine(), examine_fluff(), examine_rod_charge_level(), examine_wand_charge_level(), identify_altar_type_move_on(), identify_object_with_skill(), make_item_from_recipe(), price_base(), query_base_name(), query_flags(), query_short_name(), and spellbook_type_describe().
int is_magical | ( | const object * | op | ) |
Checks whether object is magical.
A magical item is one that increases/decreases any abilities, provides a resistance, has a generic magical bonus, or is an artifact.
op | item to check. |
Definition at line 1239 of file item.cpp.
References living::ac, AMULET, ARMOUR, ATNR_PHYSICAL, BOOTS, living::dam, living::exp, FLAG_ALIVE, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_STEALTH, FLAG_XRAYS, living::food, get_attr_value(), GIRDLE, GLOVES, living::grace, HELMET, living::hp, living::luck, object::magic, object::move_type, NROFATTACKS, NUM_STATS, POTION, POWER_CRYSTAL, QUERY_FLAG, object::resist, RING, ROD, SCROLL, SHIELD, living::sp, SPELLBOOK, object::stats, object::title, object::type, WAND, and living::wc.
Referenced by cast_detection(), cfapi_object_get_property(), detect_magic_on_item(), query_base_name(), and query_short_name().
void object_give_identified_properties | ( | object * | op | ) |
Ensure op has all its "identified" properties set.
op | object to process. |
Definition at line 1368 of file item.cpp.
References object::anim_speed, animate_object(), object::animation, CLEAR_FLAG, object::face, object::facing, FLAG_ANIMATE, FLAG_BEEN_APPLIED, FLAG_BLESSED, FLAG_CLIENT_ANIM_RANDOM, FLAG_CLIENT_ANIM_SYNC, FLAG_CURSED, FLAG_DAMNED, FLAG_IS_TURNABLE, FLAG_KNOWN_BLESSED, FLAG_KNOWN_CURSED, FLAG_KNOWN_MAGICAL, FLAG_NO_SKILL_IDENT, FREE_AND_COPY, is_identifiable_type(), object::last_anim, object::name, object::name_pl, object_get_value(), object_set_value(), QUERY_FLAG, SET_FLAG, sstring, try_find_animation(), and try_find_face().
Referenced by add_abilities(), add_one_item(), check_loaded_object(), command_create(), identify(), make_item_from_recipe(), and recipe_get_face().
uint64_t price_base | ( | const object * | obj | ) |
Price an item based on its value or archetype value, type, identification/BUC status, and other heuristics.
Determine the base (intrinsic) value of an item.
Shopkeepers always know the BUC status of items. Adjust the base price of items based on their BUC status. Note that religious players can readily uncurse items, so don't make this too drastic.
Definition at line 1510 of file item.cpp.
References object::arch, calc_item_enhancement(), archetype::clone, FLAG_BLESSED, FLAG_CURSED, FLAG_DAMNED, living::food, GEM, is_identified(), object::magic, MONEY, NROF(), object_get_value(), QUERY_FLAG, object::stats, object::type, object::value, and WAND.
Referenced by alchemy_object(), attempt_do_alchemy(), check_pick(), do_single_item(), dump_alchemy(), dump_alchemy_costs(), price_approx(), shop_price_buy(), shop_price_sell(), and shopkeeper_move().
void query_base_name | ( | const object * | op, |
int | plural, | ||
char * | buf, | ||
size_t | size | ||
) |
Query a short name for the item.
This is a lot like query_name(), but we don't include the item count or item status. Used for inventory sorting and sending to client. If plural is set, we generate the plural name of this.
op | item we want the name of. |
plural | whether to get the singular or plural name |
buf | buffer that will contain the object's name. Must not be NULL. |
size | buffer's length |
Definition at line 695 of file item.cpp.
References AMULET, buf, FLAG_BEEN_APPLIED, FLAG_IDENTIFIED, object::inv, is_identified(), is_magical(), object::level, object::magic, object::name, object::name_pl, object::nrof, POTION, QUERY_FLAG, RING, ring_desc(), ROD, safe_strcat(), SCROLL, SKILL, SPELLBOOK, stringbuffer_finish(), strlcpy(), object::title, object::type, WAND, and object::weight.
Referenced by add_object_to_socklist(), add_shop_item(), cfapi_object_get_property(), command_rename_item(), esrv_update_item(), fire_misc_object(), matches_sacrifice(), object_matches_string(), rangetostring(), send_updated_shoottype(), and use_alchemy().
void query_name | ( | const object * | op, |
char * | buf, | ||
size_t | size | ||
) |
Describes an item.
op | item to describe. Must not be NULL. |
buf | buffer that will contain the description. |
size | size of buffer. |
Definition at line 594 of file item.cpp.
References AMULET, ARMOUR, BOOK, BOOTS, BOW, BRACERS, buf, CLOAK, CONTAINER, object::container, object::env, FLAG_APPLIED, FLAG_BLESSED, FLAG_CURSED, FLAG_DAMNED, FLAG_IDENTIFIED, FLAG_INV_LOCKED, FLAG_KNOWN_BLESSED, FLAG_KNOWN_CURSED, FLAG_KNOWN_MAGICAL, FLAG_NO_SKILL_IDENT, FLAG_UNPAID, GIRDLE, GLOVES, HELMET, QUERY_FLAG, query_short_name(), RING, ROD, safe_strcat(), SHIELD, SKILL, object::type, WAND, and WEAPON.
Referenced by animate_weapon(), apply_builder_item(), apply_builder_remove(), apply_by_living(), apply_check_apply_restrictions(), apply_check_race_restrictions(), apply_container(), apply_special(), apply_update_ranged_skill(), attack_hth(), attempt_jump(), attempt_steal(), blind_living(), cast_smite_spell(), cast_spell(), cfapi_object_find_archetype_inside(), cfapi_object_forget_spell(), cfapi_object_get_property(), command_insert_into(), command_mark(), command_remove(), common_ob_describe(), converter_type_move_on(), do_skill(), do_skill_attack(), do_throw(), drop_object(), empty_container(), exit_type_apply(), find_key(), find_player_options(), find_throw_ob(), god_examines_item(), hit_with_one_attacktype(), inventory(), kill_object(), knowledge_alchemy_detail(), lamp_type_describe(), leave(), legacy_ob_describe(), look_at(), make_formula_book(), mark_item_cmd(), mimic_type_apply(), monster_can_detect_enemy(), monster_find_throw_ob(), monster_format_say(), object_matches_string(), pick_up_object(), polymorph_melt(), power_crystal_describe(), power_crystal_type_apply(), put_object_in_sack(), recharge(), recursive_roll(), sack_can_hold(), save_life(), save_throw_object(), sell_item(), send_updated_shoottype(), shop_pay_unpaid_callback(), singing(), skillscroll_type_apply(), spellbook_type_apply(), spellbook_type_describe(), transport_type_apply(), treasure_type_apply(), unapply_for_ob(), unapply_special(), use_oratory(), and write_scroll().
void query_short_name | ( | const object * | op, |
char * | buf, | ||
size_t | size | ||
) |
query_short_name(object) is similar to query_name(), but doesn't contain any information about object status (worn/cursed/etc.)
op | object to describe. |
buf | buffer which will contain the name. Must not be NULL. |
size | buffer length. |
Definition at line 518 of file item.cpp.
References AMULET, buf, FLAG_BEEN_APPLIED, FLAG_IDENTIFIED, object::inv, is_identified(), is_magical(), object::level, object::magic, object::name, object::name_pl, object::nrof, POTION, QUERY_FLAG, RING, ring_desc(), ROD, safe_strcat(), SCROLL, SKILL, SPELLBOOK, stringbuffer_finish(), strlcpy(), object::title, object::type, WAND, and object::weight.
Referenced by cast_item_curse_or_bless(), cfapi_object_get_property(), command_lock_item(), dragon_ability_gain(), follower_remove_given_items(), god_gives_present(), lock_item_cmd(), object_matches_string(), player_attack_door(), query_name(), remove_force(), shopkeeper_move(), spellbook_type_apply(), transmute_item_to_flower(), and write_note().
void query_weight | ( | const object * | op, |
char * | buf, | ||
size_t | size | ||
) |
Formats the item's weight.
op | object we want the weight of. | |
[out] | buf | buffer to write to. |
size | buffer size. |
Definition at line 420 of file item.cpp.
References buf, object::carrying, NROF(), and object::weight.
Referenced by inventory().
|
static |
Describes a ring or amulet, or a skill.
op | item to describe, must be RING, AMULET or SKILL. |
use_media_tags | if non-zero, then media tags (colors and such) are inserted in the description. This enables the player to more easily see some things. |
buf | buffer that will contain the description. If NULL a new one is created. |
Definition at line 443 of file item.cpp.
References living::ac, AMULET, buf, living::dam, describe_resistance(), describe_spellpath_attenuation(), living::exp, FLAG_IDENTIFIED, FLAG_LIFESAVE, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_STEALTH, FMT64, living::food, get_attr_value(), object::glow_radius, living::grace, living::hp, living::luck, NUM_STATS, object::path_attuned, object::path_denied, object::path_repelled, QUERY_FLAG, RING, short_stat_name, SKILL, living::sp, object::stats, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_length(), stringbuffer_new(), object::type, and living::wc.
Referenced by describe_item(), query_base_name(), and query_short_name().
body_locations_struct body_locations[NUM_BODY_LOCATIONS] |
The ordering of this is actually doesn't make a difference However, for ease of use, new entries should go at the end so those people that debug the code that get used to something being in the location 4 don't get confused.
The ordering in save_name, use_name, nonuse_name. save_name is the name used to load/save it from files. It should match that of the doc/Developers/objects. The only real limitation is that it shouldn't have spaces or other characters that may mess up the match code. It must also start with body_ use_name is how we describe the location if we can use it. nonuse_name is how we describe it if we can't use it. I think the values below will make it pretty clear how those work out They are basically there to make life a little easier - if a character examines an item and it says it goes on 'your arm', its pretty clear they can use it. See the last sample (commented out) for a dragon Note that using the term 'human' may not be very accurate, humanoid may be better. Basically, for the use/nonuse, the code does something like: "This item goes %s\n", with the use/nonuse values filling in the s
Definition at line 56 of file item.cpp.
Referenced by command_body(), examine(), get_ob_diff(), and set_body_info().
|
static |
This curve may be too steep.
But the point is that there should be tough choices - there is no real point to this if everyone can wear whatever they want with no worries. Perhaps having the steep curve is good (maybe even steeper), but allowing players to have 2 * level instead. Ideally, top level characters should only be able to use 2-3 of the most powerful items. note that this table is only really used for program generated items - custom objects can use whatever they want.
Definition at line 206 of file item.cpp.
Referenced by get_power_from_ench().
|
static |
The following is a large table of item types, the fields are: item number, item name, item name (plural), and two numbers that are the skills used to identify them.
Anytime a new item type is added or removed, this list should be altered to reflect that. The defines for the numerical values are in define.h
Definition at line 80 of file item.cpp.
Referenced by get_typedata(), and get_typedata_by_name().
|
static |
Number of items in item_types array.
Definition at line 195 of file item.cpp.
Referenced by get_typedata(), and get_typedata_by_name().