--- deliantra/server/common/item.C 2007/02/05 01:39:05 1.21 +++ deliantra/server/common/item.C 2007/05/03 04:50:26 1.29 @@ -1,5 +1,5 @@ /* - * CrossFire, A Multiplayer game for X-windows + * CrossFire, A Multiplayer game * * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team * Copyright (C) 2002 Mark Wedel & Crossfire Development Team @@ -252,10 +252,9 @@ int get_power_from_ench (int ench) { - if (ench < 0) - ench = 0; - if (ench > 20) - ench = 20; + if (ench < 0) ench = 0; + if (ench > 20) ench = 20; + return enc_to_item_power[ench]; } @@ -344,12 +343,10 @@ enc += 1; return get_power_from_ench (enc); - } /* returns the typedata that has a number equal to itemtype, if there * isn't one, returns NULL */ - const typedata * get_typedata (int itemtype) { @@ -364,7 +361,6 @@ /* returns the 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 */ - const typedata * get_typedata_by_name (const char *name) { @@ -389,7 +385,7 @@ * if newline is true, we don't put parens around the description * but do put a newline at the end. Useful when dumping to files */ -char * +const char * describe_resistance (const object *op, int newline) { static char buf[VERY_BIG_BUF]; @@ -418,8 +414,7 @@ * containing the text-representation of the weight of the given object. * The buffer will be overwritten by the next call to query_weight(). */ - -char * +const char * query_weight (const object *op) { static char buf[10]; @@ -427,10 +422,12 @@ if (op->weight < 0) return " "; + if (i % 1000) sprintf (buf, "%6.1f", i / 1000.0); else sprintf (buf, "%4d ", i / 1000); + return buf; } @@ -438,8 +435,7 @@ * Returns the pointer to a static buffer containing * the number requested (of the form first, second, third...) */ - -char * +const char * get_levelnumber (int i) { static char buf[MAX_BUF]; @@ -449,24 +445,24 @@ sprintf (buf, "%d.", i); return buf; } + if (i < 21) return levelnumbers[i]; if (!(i % 10)) return levelnumbers_10[i / 10]; + strcpy (buf, numbers_10[i / 10]); strcat (buf, levelnumbers[i % 10]); return buf; } - /* * get_number(integer) returns the text-representation of the given number * in a static buffer. The buffer might be overwritten at the next * call to get_number(). * It is currently only used by the query_name() function. */ - -char * +const char * get_number (int i) { if (i <= 20) @@ -493,7 +489,7 @@ /* Aug 95 modified this slightly so that Skill tools don't have magic bonus * from stats.sp - b.t. */ -char * +const char * ring_desc (const object *op) { static char buf[VERY_BIG_BUF]; @@ -511,6 +507,7 @@ sprintf (buf + strlen (buf), "(%s%+d)", short_stat_name[attr], val); } } + if (op->stats.exp) sprintf (buf + strlen (buf), "(speed %+lld)", (long long) op->stats.exp); if (op->stats.wc) @@ -542,6 +539,7 @@ strcat (buf, "(reflect missiles)"); if (QUERY_FLAG (op, FLAG_STEALTH)) strcat (buf, "(stealth)"); + /* Shorten some of the names, so they appear better in the windows */ len = strlen (buf); DESCRIBE_PATH_SAFE (buf, op->path_attuned, "Attuned", &len, VERY_BIG_BUF); @@ -616,7 +614,7 @@ if (!op->title) { /* If ring has a title, full description isn't so useful */ - char *s = ring_desc (op); + const char *s = ring_desc (op); if (s[0]) { @@ -646,10 +644,10 @@ * use several names much easier (don't need to store them to temp variables.) * */ -char * +const char * query_name (const object *op) { - static char buf[5][HUGE_BUF]; + static char buf[5][HUGE_BUF]; // OMFG static int use_buf = 0; int len = 0; @@ -686,6 +684,7 @@ else if (QUERY_FLAG (op, FLAG_CURSED)) safe_strcat (buf[use_buf], " (cursed)", &len, HUGE_BUF); } + /* Basically, if the object is known magical (detect magic spell on it), * and it isn't identified, print out the fact that * it is magical. Assume that the detect magical spell will only set @@ -711,39 +710,40 @@ { switch (op->type) { - case BOW: - case WAND: - case ROD: - case HORN: - safe_strcat (buf[use_buf], " (readied)", &len, HUGE_BUF); - break; - case WEAPON: - safe_strcat (buf[use_buf], " (wielded)", &len, HUGE_BUF); - break; - case ARMOUR: - case HELMET: - case SHIELD: - case RING: - case BOOTS: - case GLOVES: - case AMULET: - case GIRDLE: - case BRACERS: - case CLOAK: - safe_strcat (buf[use_buf], " (worn)", &len, HUGE_BUF); - break; - case CONTAINER: - safe_strcat (buf[use_buf], " (active)", &len, HUGE_BUF); - break; - case SKILL: - default: - safe_strcat (buf[use_buf], " (applied)", &len, HUGE_BUF); + case BOW: + case WAND: + case ROD: + case HORN: + safe_strcat (buf[use_buf], op->env && op->env->current_weapon == op ? " (readied)" : " (applied)", &len, HUGE_BUF); + break; + case WEAPON: + safe_strcat (buf[use_buf], op->env && op->env->current_weapon == op ? " (wielded)" : " (applied)", &len, HUGE_BUF); + break; + case ARMOUR: + case HELMET: + case SHIELD: + case RING: + case BOOTS: + case GLOVES: + case AMULET: + case GIRDLE: + case BRACERS: + case CLOAK: + safe_strcat (buf[use_buf], " (worn)", &len, HUGE_BUF); + break; + case CONTAINER: + safe_strcat (buf[use_buf], " (active)", &len, HUGE_BUF); + break; + case SKILL: + default: + safe_strcat (buf[use_buf], " (applied)", &len, HUGE_BUF); } } + if (QUERY_FLAG (op, FLAG_UNPAID)) safe_strcat (buf[use_buf], " (unpaid)", &len, HUGE_BUF); - return buf[use_buf]; + return buf [use_buf]; } /* @@ -833,7 +833,7 @@ if (!op->title) { /* If ring has a title, full description isn't so useful */ - char *s = ring_desc (op); + const char *s = ring_desc (op); if (s[0]) { @@ -842,11 +842,10 @@ } } break; + default: if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED))) - { - sprintf (buf + strlen (buf), " %+d", op->magic); - } + sprintf (buf + strlen (buf), " %+d", op->magic); } return buf; @@ -993,24 +992,24 @@ break; if (tmp && tmp->attacktype != 0) - DESCRIBE_ABILITY (retbuf, tmp->attacktype, "Claws"); + { DESCRIBE_ABILITY (retbuf, tmp->attacktype, "Claws") } else - DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks"); + { DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks") } } else - DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks"); + { DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks") } DESCRIBE_PATH (retbuf, op->path_attuned, "Attuned"); DESCRIBE_PATH (retbuf, op->path_repelled, "Repelled"); DESCRIBE_PATH (retbuf, op->path_denied, "Denied"); + for (i = 0; i < NROFATTACKS; i++) - { - if (op->resist[i]) - { - sprintf (buf, "(%s %+d)", resist_plus[i], op->resist[i]); - strcat (retbuf, buf); - } - } + if (op->resist[i]) + { + sprintf (buf, "(%s %+d)", resist_plus[i], op->resist[i]); + strcat (retbuf, buf); + } + return retbuf; } @@ -1041,8 +1040,7 @@ * owner can be null if no one is being associated with this * item (eg, debug dump or the like) */ - -char * +const char * describe_item (const object *op, object *owner) { char buf[MAX_BUF]; @@ -1362,6 +1360,12 @@ return retbuf; } +std::string +object::describe_item (object *who) +{ + return std::string (::describe_item (this, who)); +} + /* Return true if the item is magical. A magical item is one that * increases/decreases any abilities, provides a resistance, * has a generic magical bonus, or is an artifact. @@ -1522,7 +1526,7 @@ /* If the object is on a map, make sure we update its face */ if (op->map) - update_object (op, UP_OBJ_FACE); + update_object (op, UP_OBJ_CHANGE); else { pl = op->in_player ();