--- deliantra/server/common/item.C 2006/12/20 12:13:48 1.12 +++ deliantra/server/common/item.C 2007/04/23 18:09:57 1.26 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The authors can be reached via e-mail at -*/ + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2002 Mark Wedel & Crossfire Development Team + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The authors can be reached via e-mail at + */ #include #include @@ -160,15 +161,10 @@ {SKILL_TOOL, "skill tool", "skill tools", 0, 0}, {LIGHTER, "lighter", "lighters", 0, 0}, {BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0}, - {LIGHT_SOURCE, "light source", "light sources", 0, 0}, {MISC_OBJECT, "bric-a-brac", "bric-a-brac", 0, 0}, - {MONSTER, "monster", "monsters", 0, 0}, - {SPAWN_GENERATOR, "monster generator", "monster generators", 0, 0}, {LAMP, "lamp", "lamps", 0, 0}, {DUPLICATOR, "duplicator", "duplicators", 0, 0}, - {TOOL, "tool", "tools", 0, 0}, {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0}, - {BUILDFAC, "building facility", "building facilities", 0, 0}, {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0}, {SPINNER, "spinner", "spinners", 0, 0}, {GATE, "gate", "gates", 0, 0}, @@ -185,8 +181,6 @@ {BRACERS, "bracers", "bracers", SK_SMITHERY, 0}, {POISONING, "poisoning", "poisonings", 0, 0}, {SAVEBED, "savebed", "savebeds", 0, 0}, - {POISONCLOUD, "poison cloud", "poison clouds", 0, 0}, - {FIREHOLES, "fireholes", "fireholes", 0, 0}, {WAND, "wand", "wands", SK_THAUMATURGY, 0}, {SCROLL, "scroll", "scrolls", SK_LITERACY, 0}, {DIRECTOR, "director", "directors", 0, 0}, @@ -395,7 +389,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]; @@ -424,8 +418,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]; @@ -433,10 +426,12 @@ if (op->weight < 0) return " "; + if (i % 1000) sprintf (buf, "%6.1f", i / 1000.0); else sprintf (buf, "%4d ", i / 1000); + return buf; } @@ -444,8 +439,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]; @@ -455,24 +449,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) @@ -499,7 +493,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]; @@ -622,7 +616,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]) { @@ -652,10 +646,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; @@ -692,6 +686,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 @@ -717,39 +712,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], " (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); } } + if (QUERY_FLAG (op, FLAG_UNPAID)) safe_strcat (buf[use_buf], " (unpaid)", &len, HUGE_BUF); - return buf[use_buf]; + return buf [use_buf]; } /* @@ -793,9 +789,10 @@ { #endif if (!plural) - strcpy (buf, op->name); + assign (buf, op->name); else - strcpy (buf, op->name_pl); + assign (buf, op->name_pl); + len = strlen (buf); #ifdef NEW_MATERIAL_CODE } @@ -809,50 +806,51 @@ switch (op->type) { - case SPELLBOOK: - case SCROLL: - case WAND: - case ROD: - if (QUERY_FLAG (op, FLAG_IDENTIFIED) || QUERY_FLAG (op, FLAG_BEEN_APPLIED)) - { - if (!op->title) - { - safe_strcat (buf, " of ", &len, MAX_BUF); - if (op->inv) - safe_strcat (buf, op->inv->name, &len, MAX_BUF); - else - LOG (llevError, "Spellbook %s lacks inventory\n", &op->name); - } - if (op->type != SPELLBOOK) - { - sprintf (buf2, " (lvl %d)", op->level); - safe_strcat (buf, buf2, &len, MAX_BUF); - } - } - break; + case SPELLBOOK: + case SCROLL: + case WAND: + case ROD: + if (QUERY_FLAG (op, FLAG_IDENTIFIED) || QUERY_FLAG (op, FLAG_BEEN_APPLIED)) + { + if (!op->title) + { + safe_strcat (buf, " of ", &len, MAX_BUF); + if (op->inv) + safe_strcat (buf, op->inv->name, &len, MAX_BUF); + else + LOG (llevError, "Spellbook %s lacks inventory\n", &op->name); + } + if (op->type != SPELLBOOK) + { + sprintf (buf2, " (lvl %d)", op->level); + safe_strcat (buf, buf2, &len, MAX_BUF); + } + } + break; - case SKILL: - case AMULET: - case RING: - if (!op->title) - { - /* If ring has a title, full description isn't so useful */ - char *s = ring_desc (op); + case SKILL: + case AMULET: + case RING: + if (!op->title) + { + /* If ring has a title, full description isn't so useful */ + const char *s = ring_desc (op); - if (s[0]) - { - safe_strcat (buf, " ", &len, MAX_BUF); - safe_strcat (buf, s, &len, MAX_BUF); - } - } - 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); - } + if (s[0]) + { + safe_strcat (buf, " ", &len, MAX_BUF); + safe_strcat (buf, s, &len, MAX_BUF); + } + } + 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); + } } + return buf; } @@ -862,7 +860,6 @@ * be called with monster & player objects. Returns a description * in a static buffer. */ - static char * describe_monster (const object *op) { @@ -876,7 +873,7 @@ * very good. Any player with a speed greater than .67 will * fall into the 'lightning fast movement' category. */ - if (FABS (op->speed) > MIN_ACTIVE_SPEED) + if (op->has_active_speed ()) { switch ((int) ((FABS (op->speed)) * 15)) { @@ -942,7 +939,7 @@ int first = 1; for (t = op->randomitems->items; t != NULL; t = t->next) - if (t->item && (t->item->clone.type == SPELL)) + if (t->item && t->item->clone.type == SPELL) { if (first) { @@ -998,29 +995,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; } @@ -1051,8 +1043,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]; @@ -1372,6 +1363,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. @@ -1532,7 +1529,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 ();