Crossfire Server, Branch 1.12  R12190
Functions | Variables
item.c File Reference

Those functions deal with objects in general, including description, body location, and such. More...

#include <stdio.h>
#include <global.h>
#include <living.h>
#include <spells.h>
Include dependency graph for item.c:

Go to the source code of this file.

Functions

int calc_item_power (const object *op, int flag)
 This takes an object 'op' and figures out what its item_power rating should be.
void describe_item (const object *op, const object *owner, char *retbuf, size_t size)
 Describes an item, in all its details.
void describe_monster (const object *op, char *retbuf, size_t size)
 Describes a monster.
void describe_resistance (const object *op, int newline, char *buf, size_t size)
 Generates the visible naming for resistances.
void get_levelnumber (int i, char *buf, size_t size)
 Formats a level.
int get_power_from_ench (int ench)
const typedataget_typedata (int itemtype)
const typedataget_typedata_by_name (const char *name)
void identify (object *op)
 Identifies an item.
int is_magical (const object *op)
 Checks whether object is magical.
int need_identify (const object *op)
 This function really should not exist - by default, any item not identified should need it.
void query_base_name (const object *op, int plural, char *buf, size_t size)
 Query a short name for the item.
void query_name (const object *op, char *buf, size_t size)
 Describes an item.
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.)
void query_weight (const object *op, char *buf, size_t size)
 Formats the item's weight.
static void ring_desc (const object *op, char *buf, size_t size)
 Describes a ring or amulet.

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.
static const int enc_to_item_power [21]
 This curve may be too steep.
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.
static const int item_types_size = sizeof(item_types)/sizeof(*item_types)
 Number of items in item_types array.
static const char levelnumbers [21][20]
 Levels as a full name and not a number.
static const char levelnumbers_10 [11][20]
 Tens for levels.
static const char numbers_10 [10][20]
 Tens.

Detailed Description

Those functions deal with objects in general, including description, body location, and such.

Todo:
put const char *instead of char *when possible.

Definition in file item.c.


Function Documentation

int calc_item_power ( const object *  op,
int  flag 
)

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. If flag is 1, we return the number of enchantment, and not the the power. This is used in the treasure code.

Parameters:
opobject of which to compute the item_power
flagunused
Todo:
fix function, and remove unused flag variable.

Definition at line 264 of file item.c.

References AMULET, ARMOUR, BOOTS, BRACERS, CLOAK, FLAG_LIFESAVE, FLAG_MAKE_INVIS, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_SEE_IN_DARK, FLAG_STEALTH, FLAG_XRAYS, get_attr_value(), get_power_from_ench(), GIRDLE, GLOVES, HELMET, NROFATTACKS, NRSPELLPATHS, NUM_STATS, QUERY_FLAG, RING, SHIELD, and WEAPON.

Referenced by add_one_item(), fix_generated_item(), and local_check_loaded_object().

Here is the call graph for this function:

Here is the caller graph for this function:

void describe_item ( const object *  op,
const object *  owner,
char *  retbuf,
size_t  size 
)

Describes an item, in all its details.

  • If it is a monster, lots of information about its abilities will be returned.
  • If it is an item, lots of information about which abilities will be gained about its user will be returned.
  • If it is a player, it writes out the current abilities of the player, which is usually gained by the items applied.

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)

Parameters:
opobject to describe. Must not be NULL.
ownerplayer examining the object.
retbufbuffer that will contain the description. Must not be NULL.
sizesize of buffer.
Note:
This function is really much more complicated than it should be, because different objects have different meanings for the same field (eg, wands use 'food' for charges). This means these special cases need to be worked out.
Todo:
Check whether owner is really needed. Use safe string functions. Check spurious food logic.

Definition at line 1018 of file item.c.

References AMULET, ARMOUR, ARMOUR_SPEED, ARMOUR_SPELLS, ARROW, atnr_is_dragon_enabled(), BOOTS, BOW, BRACERS, change_resist_msg, CLOAK, DESCRIBE_ABILITY_SAFE, describe_monster(), DESCRIBE_PATH_SAFE, describe_resistance(), DRINK, FLAG_BEEN_APPLIED, FLAG_CURSED, FLAG_IDENTIFIED, FLAG_LIFESAVE, FLAG_MONSTER, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_SEE_IN_DARK, FLAG_STEALTH, FLAG_XRAYS, FLESH, FOOD, FORCE, get_attr_value(), GIRDLE, GLOVES, HELMET, HORN, is_dragon_pl(), LAMP, MOVE_FLY_HIGH, MOVE_FLY_LOW, MOVE_SWIM, need_identify(), NUM_STATS, PLAYER, POWER_CRYSTAL, QUERY_FLAG, RING, ring_desc(), ROD, SHIELD, short_stat_name, SKILL, SKILL_TOOL, snprintf(), WAND, WEAPON, and WEAPON_SPEED.

Referenced by artifact_msg(), cfapi_object_describe(), common_ob_describe(), dump_abilities(), mon_desc(), perceive_self(), and START_TEST().

Here is the call graph for this function:

Here is the caller graph for this function:

void describe_monster ( const object *  op,
char *  retbuf,
size_t  size 
)

Describes a monster.

Parameters:
opmonster to describe. Must not be NULL.
retbufbuffer that will contain the description. Must not be NULL.
sizebuffer size.
Note:
Break this off from describe_item - that function was way too long, making it difficult to read. This function deals with describing the monsters & players abilities. It should only be called with monster & player objects.
Todo:
Rename to describe_living (or equivalent) since called for player too. Use safe string functions. Fix weird sustenance logic.

Definition at line 840 of file item.c.

References DESCRIBE_ABILITY_SAFE, DESCRIBE_PATH_SAFE, FABS, FLAG_CAN_USE_SKILL, FLAG_CAST_SPELL, FLAG_FRIENDLY, FLAG_HITBACK, 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, is_dragon_pl(), treasurestruct::item, MIN_ACTIVE_SPEED, treasurestruct::next, NROFATTACKS, PLAYER, QUERY_FLAG, resist_plus, SKILL, snprintf(), and SPELL.

Referenced by describe_item().

Here is the call graph for this function:

Here is the caller graph for this function:

void describe_resistance ( const object *  op,
int  newline,
char *  buf,
size_t  size 
)

Generates the visible naming for resistances.

Parameters:
opobject we want information about.
newlineIf TRUE, we don't put parens around the description but do put a newline at the end. Useful when dumping to files
[out]bufbuffer that will receive the description.
sizebuffer size.

Definition at line 399 of file item.c.

References atnr_is_dragon_enabled(), FLESH, NROFATTACKS, resist_plus, and snprintf().

Referenced by describe_item(), dump_gods(), god_info_msg(), and ring_desc().

Here is the call graph for this function:

Here is the caller graph for this function:

void get_levelnumber ( int  i,
char *  buf,
size_t  size 
)

Formats a level.

Parameters:
ilevel to format.
[out]bufbuffer which will contain the level.
sizesize of the buffer.

Definition at line 444 of file item.c.

References levelnumbers, levelnumbers_10, numbers_10, and snprintf().

Referenced by examine(), and spellbook_type_apply().

Here is the call graph for this function:

Here is the caller graph for this function:

int get_power_from_ench ( int  ench)

Definition at line 240 of file item.c.

Referenced by calc_item_power(), and fix_generated_item().

Here is the caller graph for this function:

const typedata* get_typedata ( int  itemtype)
Parameters:
itemtypeitem type for which to return typedata.
Returns:
typedata that has a number equal to itemtype, if there isn't one, returns NULL

Definition at line 352 of file item.c.

References item_types_size.

Referenced by CREResourcesWindow::fillArtifacts(), parse_shop_string(), query_cost(), query_cost_string(), and CREFacePanel::setFace().

Here is the caller graph for this function:

const typedata* get_typedata_by_name ( const char *  name)
Parameters:
nameitem name for which to return typedata. Singular form is preferred.
Returns:
typedata that has a name equal to itemtype, if there isn't one, return the plural name that matches, if there still isn't one return NULL
Note:
will emit an Info if found by plural form.

Definition at line 372 of file item.c.

References item_types_size, llevInfo, and LOG().

Referenced by parse_shop_string().

Here is the call graph for this function:

Here is the caller graph for this function:

void identify ( object *  op)

Identifies an item.

Supposed to fix face-values as well here, but later.

Parameters:
opitem to identify. Can be already identified without ill effects.

Definition at line 1447 of file item.c.

References add_refcount(), CLEAR_FLAG, esrv_update_item(), FLAG_BLESSED, FLAG_CURSED, FLAG_DAMNED, FLAG_IDENTIFIED, FLAG_KNOWN_BLESSED, FLAG_KNOWN_CURSED, FLAG_KNOWN_MAGICAL, FLAG_NO_SKILL_IDENT, free_string(), get_player_container(), PLAYER, POTION, present(), QUERY_FLAG, SET_FLAG, UPD_ALL, UPD_FACE, UPD_NAME, and update_object().

Referenced by auto_apply(), cast_identify(), cfapi_object_identify(), do_skill_ident2(), identify_altar_type_move_on(), potion_type_apply(), scroll_type_apply(), sell_item(), and spellbook_type_apply().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
opitem to check.
Returns:
true if the item is magical.

Definition at line 1312 of file item.c.

References AMULET, ARMOUR, ATNR_PHYSICAL, BOOTS, FLAG_ALIVE, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_STEALTH, FLAG_XRAYS, get_attr_value(), GIRDLE, GLOVES, HELMET, NROFATTACKS, NUM_STATS, POTION, POWER_CRYSTAL, QUERY_FLAG, RING, ROD, SCROLL, SHIELD, SPELLBOOK, and WAND.

Referenced by cast_detection(), cfapi_object_get_property(), do_skill_detect_magic(), query_base_name(), and query_short_name().

Here is the call graph for this function:

Here is the caller graph for this function:

int need_identify ( const object *  op)

This function really should not exist - by default, any item not identified should need it.

Parameters:
opitem to check.
Returns:
true if the item should be identified.
Todo:
either remove this function, or fix comment above :)

Definition at line 1401 of file item.c.

References AMULET, ARMOUR, ARROW, BOOK, BOOTS, BOW, BRACERS, CLOAK, CLOSE_CON, CONTAINER, DRINK, FLESH, FOOD, GEM, GIRDLE, GLOVES, HELMET, HORN, INORGANIC, POISON, POTION, POWER_CRYSTAL, RING, ROD, SCROLL, SHIELD, SKILL, SKILL_TOOL, SKILLSCROLL, SPELLBOOK, WAND, and WEAPON.

Referenced by cast_identify(), command_create(), describe_item(), do_skill_ident2(), examine(), give_initial_items(), identify_altar_type_move_on(), query_base_name(), query_cost(), and query_short_name().

Here is the caller graph for this function:

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.

Parameters:
opitem we want the name of.
pluralwhether to get the singular or plural name
bufbuffer that will contain the object's name. Must not be NULL.
sizebuffer's length

Definition at line 732 of file item.c.

References AMULET, _materialtype::description, FLAG_BEEN_APPLIED, FLAG_IDENTIFIED, IS_ARMOR, is_magical(), IS_WEAPON, llevError, LOG(), M_SPECIAL, MAX_BUF, _materialtype::name, name_to_material(), need_identify(), QUERY_FLAG, RING, ring_desc(), ROD, safe_strcat(), SCROLL, SKILL, snprintf(), SPELLBOOK, and WAND.

Referenced by add_object_to_socklist(), add_shop_item(), cfapi_object_get_property(), change_spell(), command_rename_item(), esrv_update_item(), fire_misc_object(), item_matched_string(), matches_sacrifice(), rangetostring(), and use_alchemy().

Here is the call graph for this function:

Here is the caller graph for this function:

void query_name ( const object *  op,
char *  buf,
size_t  size 
)

Describes an item.

Parameters:
opitem to describe. Must not be NULL.
bufbuffer that will contain the description.
sizesize of buffer.

Definition at line 628 of file item.c.

References AMULET, ARMOUR, BOOTS, BOW, BRACERS, CLOAK, CONTAINER, _materialtype::description, FLAG_APPLIED, FLAG_BLESSED, FLAG_CURSED, FLAG_DAMNED, FLAG_IDENTIFIED, FLAG_INV_LOCKED, FLAG_KNOWN_BLESSED, FLAG_KNOWN_CURSED, FLAG_KNOWN_MAGICAL, FLAG_UNPAID, GIRDLE, GLOVES, HELMET, HORN, IS_ARMOR, IS_SHIELD, IS_WEAPON, name_to_material(), QUERY_FLAG, query_short_name(), RING, ROD, safe_strcat(), SHIELD, SKILL, WAND, and WEAPON.

Referenced by animate_weapon(), apply_builder_item(), apply_builder_remove(), apply_container(), apply_special(), attack_hth(), attempt_steal(), blind_living(), cast_smite_spell(), cast_spell(), cfapi_object_find_archetype_inside(), cfapi_object_forget_spell(), cfapi_object_get_property(), change_exp(), change_spell(), check_race_restrictions(), 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_mon_throw_ob(), find_player(), find_throw_ob(), get_payment(), god_examines_item(), hit_with_one_attacktype(), inventory(), item_matched_string(), kill_object(), leave(), legacy_ob_describe(), look_at(), make_formula_book(), mark_item_cmd(), npc_say(), pick_up_object(), player_apply(), polymorph_melt(), put_object_in_sack(), recharge(), recursive_roll(), sack_can_hold(), save_life(), sell_item(), singing(), skillscroll_type_apply(), spellbook_type_apply(), transport_type_apply(), treasure_type_apply(), unapply_for_ob(), unapply_special(), use_oratory(), and write_scroll().

Here is the call graph for this function:

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

Parameters:
opobject to describe.
bufbuffer which will contain the name. Must not be NULL.
sizebuffer length.

Definition at line 551 of file item.c.

References AMULET, FLAG_BEEN_APPLIED, FLAG_IDENTIFIED, is_magical(), llevError, LOG(), need_identify(), QUERY_FLAG, RING, ring_desc(), ROD, safe_strcat(), SCROLL, SKILL, snprintf(), SPELLBOOK, VERY_BIG_BUF, and WAND.

Referenced by cast_item_curse_or_curse(), cfapi_object_get_property(), command_lock_item(), dragon_ability_gain(), follower_remove_given_items(), god_gives_present(), item_matched_string(), player_attack_door(), query_name(), remove_force(), transmute_item_to_flower(), and write_note().

Here is the call graph for this function:

Here is the caller graph for this function:

void query_weight ( const object *  op,
char *  buf,
size_t  size 
)

Formats the item's weight.

Parameters:
opobject we want the weight of.
[out]bufbuffer to write to.
sizebuffer size.

Definition at line 424 of file item.c.

References snprintf().

Referenced by inventory().

Here is the call graph for this function:

Here is the caller graph for this function:

static void ring_desc ( const object *  op,
char *  buf,
size_t  size 
) [static]

Describes a ring or amulet.

Parameters:
opitem to describe.
bufbuffer that will contain the description.
sizesize of buffer.
Note:
These are taken from old query_name(), but it would work better if describle_item() would be called to get this information and caller would handle FULL_RING_DESCRIPTION definition. Or make FULL_RING_DESCRIPTION standard part of a game and let client handle names.
Aug 95 modified this slightly so that Skill tools don't have magic bonus from stats.sp - b.t.
Todo:
Use safe string functions. Check if really ring/amulet?

Definition at line 483 of file item.c.

References DESCRIBE_PATH_SAFE, describe_resistance(), FLAG_IDENTIFIED, FLAG_LIFESAVE, FLAG_REFL_MISSILE, FLAG_REFL_SPELL, FLAG_STEALTH, get_attr_value(), NUM_STATS, QUERY_FLAG, short_stat_name, SKILL, and snprintf().

Referenced by describe_item(), query_base_name(), and query_short_name().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

body_locations_struct body_locations[NUM_BODY_LOCATIONS]
Initial value:
 {
    { "body_range",    "in your range slot",     "in a human's range slot" },
    { "body_arm",      "on your arm",            "on a human's arm" },
    { "body_torso",    "on your body",           "on a human's torso" },
    { "body_head",     "on your head",           "on a human's head" },
    { "body_neck",     "around your neck",       "around a humans neck" },
    { "body_skill",    "in your skill slot",     "in a human's skill slot" },
    { "body_finger",   "on your finger",         "on a human's finger" },
    { "body_shoulder", "around your shoulders",  "around a human's shoulders" },
    { "body_foot",     "on your feet",           "on a human's feet" },
    { "body_hand",     "on your hands",          "on a human's hands" },
    { "body_wrist",    "around your wrists",     "around a human's wrist" },
    { "body_waist",    "around your waist",      "around a human's waist" },
    { "body_leg",      "around your legs",       "around a human's legs" },

    
}

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 64 of file item.c.

Referenced by command_body(), and examine().

const int enc_to_item_power[21] [static]
Initial value:
 {
    0, 0, 1, 2, 3, 4,    
    5, 7, 9, 11, 13,    
    15, 18, 21, 24, 27, 
    30, 35, 40, 45, 50  
}

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 233 of file item.c.

const typedata item_types[] [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 109 of file item.c.

const int item_types_size = sizeof(item_types)/sizeof(*item_types) [static]

Number of items in item_types array.

Definition at line 222 of file item.c.

Referenced by get_typedata(), and get_typedata_by_name().

const char levelnumbers[21][20] [static]
Initial value:
 {
    "zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh",
    "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth",
    "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteen",
    "nineteen", "twentieth"
}

Levels as a full name and not a number.

Definition at line 89 of file item.c.

Referenced by get_levelnumber().

const char levelnumbers_10[11][20] [static]
Initial value:
 {
    "zeroth", "tenth", "twentieth", "thirtieth", "fortieth", "fiftieth", "sixtieth",
    "seventieth", "eightieth", "ninetieth"
}

Tens for levels.

Definition at line 97 of file item.c.

Referenced by get_levelnumber().

const char numbers_10[10][20] [static]
Initial value:
 {
    "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
    "eighty", "ninety"
}

Tens.

Definition at line 83 of file item.c.

Referenced by get_levelnumber().