--- deliantra/server/common/item.C 2009/01/12 00:17:22 1.54 +++ deliantra/server/common/item.C 2009/11/07 18:30:05 1.65 @@ -5,18 +5,19 @@ * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * - * Deliantra 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 3 of the License, or - * (at your option) any later version. + * Deliantra is free software: you can redistribute it and/or modify it under + * the terms of the Affero GNU General Public License as published by the + * Free Software Foundation, either version 3 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, see . + * You should have received a copy of the Affero GNU General Public License + * and the GNU General Public License along with this program. If not, see + * . * * The authors can be reached via e-mail to */ @@ -66,12 +67,6 @@ /*{"body_dragon_torso", "your body", "a dragon's body"} */ }; -static char numbers[21][20] = { - "no", "", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", - "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", - "eighteen", "nineteen", "twenty" -}; - static char numbers_10[10][20] = { "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" @@ -171,7 +166,7 @@ {SPINNER, "spinner", "spinners", 0, 0}, {GATE, "gate", "gates", 0, 0}, {BUTTON, "button", "buttons", 0, 0}, - {CF_HANDLE, "cf handle", "cf handles", 0, 0}, + {T_HANDLE, "cf handle", "cf handles", 0, 0}, {HOLE, "hole", "holes", 0, 0}, {TRAPDOOR, "trapdoor", "trapdoors", 0, 0}, {SIGN, "sign", "signs", 0, 0}, @@ -208,7 +203,7 @@ {ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0}, }; -const int item_types_size = sizeof (item_types) / sizeof (*item_types); +static const int item_types_size = sizeof (item_types) / sizeof (*item_types); materialtype_t *materialt; @@ -329,20 +324,13 @@ enc--; } - if (QUERY_FLAG (op, FLAG_LIFESAVE)) - enc += 5; - if (QUERY_FLAG (op, FLAG_REFL_SPELL)) - enc += 3; - if (QUERY_FLAG (op, FLAG_REFL_MISSILE)) - enc += 2; - if (QUERY_FLAG (op, FLAG_STEALTH)) - enc += 1; - if (QUERY_FLAG (op, FLAG_XRAYS)) - enc += 2; - if (QUERY_FLAG (op, FLAG_SEE_IN_DARK)) - enc += 1; - if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) - enc += 1; + if (op->flag [FLAG_LIFESAVE ]) enc += 5; + if (op->flag [FLAG_REFL_SPELL ]) enc += 3; + if (op->flag [FLAG_REFL_MISSILE]) enc += 2; + if (op->flag [FLAG_XRAYS ]) enc += 2; + if (op->flag [FLAG_STEALTH ]) enc += 1; + if (op->flag [FLAG_SEE_IN_DARK ]) enc += 1; + if (op->flag [FLAG_MAKE_INVIS ]) enc += 1; return get_power_from_ench (enc); } @@ -352,9 +340,7 @@ const typedata * get_typedata (int itemtype) { - int i; - - for (i = 0; i < item_types_size; i++) + for (int i = 0; i < item_types_size; i++) if (item_types[i].number == itemtype) return &item_types[i]; @@ -367,13 +353,11 @@ const typedata * get_typedata_by_name (const char *name) { - int i; - - for (i = 0; i < item_types_size; i++) + for (int i = 0; i < item_types_size; i++) if (!strcmp (item_types[i].name, name)) return &item_types[i]; - for (i = 0; i < item_types_size; i++) + for (int i = 0; i < item_types_size; i++) if (!strcmp (item_types[i].name_pl, name)) { LOG (llevInfo, @@ -381,7 +365,7 @@ return &item_types[i]; } - return NULL; + return 0; } /* describe_resistance generates the visible naming for resistances. @@ -393,31 +377,21 @@ const char * describe_resistance (const object *op, int newline) { - static char buf[VERY_BIG_BUF]; - char buf1[VERY_BIG_BUF]; - int tmpvar; + static dynbuf_text buf; buf.clear (); - buf[0] = 0; - for (tmpvar = 0; tmpvar < NROFATTACKS; tmpvar++) - { - if (op->resist[tmpvar] && (op->type != FLESH || atnr_is_dragon_enabled (tmpvar) == 1)) - { - if (!newline) - sprintf (buf1, "(%s %+d)", resist_plus[tmpvar], op->resist[tmpvar]); - else - sprintf (buf1, "%s %d\n", resist_plus[tmpvar], op->resist[tmpvar]); + for (int i = 0; i < NROFATTACKS; i++) + if (op->resist[i] && (op->type != FLESH || atnr_is_dragon_enabled (i) == 1)) + buf.printf (newline ? "%s %d\n" : "(%s %+d)", resist_plus[i], op->resist[i]); - strcat (buf, buf1); - } - } return buf; } - /* * query_weight(object) returns a character pointer to a static buffer * containing the text-representation of the weight of the given object. * The buffer will be overwritten by the next call to query_weight(). + * + * Seems to be used only by unimportant stuff. Remove? */ const char * query_weight (const object *op) @@ -453,6 +427,7 @@ if (i < 21) return levelnumbers[i]; + if (!(i % 10)) return levelnumbers_10[i / 10]; @@ -462,26 +437,6 @@ } /* - * 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. - */ -const char * -get_number (int i) -{ - if (i <= 20) - return numbers[i]; - else - { - static char buf[MAX_BUF]; - - sprintf (buf, "%d", i); - return buf; - } -} - -/* * Returns pointer to static buffer containing ring's or amulet's * abilities * These are taken from old query_name(), but it would work better @@ -494,7 +449,7 @@ /* Aug 95 modified this slightly so that Skill tools don't have magic bonus * from stats.sp - b.t. */ -const char * +static const char * ring_desc (const object *op) { static dynbuf_text buf; buf.clear (); @@ -538,6 +493,8 @@ /* * query_short_name(object) is similar to query_name, but doesn't * contain any information about object status (worn/cursed/etc.) + * + * It is sometimes used when printing messages, so should fit well into a sentence. */ const char * query_short_name (const object *op) @@ -631,6 +588,8 @@ * returned is good forever.) However, it makes printing statements that * use several names much easier (don't need to store them to temp variables.) * + * It is used extensively within messages, so should return only a prose + * and short description of the item. */ const char * query_name (const object *op) @@ -653,7 +612,7 @@ if (QUERY_FLAG (op, FLAG_INV_LOCKED)) buf << " *"; - if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) + if (op->is_open_container ()) buf << " (open)"; if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) @@ -677,7 +636,7 @@ buf << " (magic)"; #if 0 - /* item_power will be returned in desribe_item - it shouldn't really + /* item_power will be returned in describe_item - it shouldn't really * be returned in the name. */ if (op->item_power) @@ -752,6 +711,9 @@ * 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. + * + * It is sometimes used to display messages, and usually only used to match stuff, + * so maybe this function should be removed. */ const char * query_base_name (const object *op, int plural) @@ -828,7 +790,7 @@ * fall into the 'lightning fast movement' category. */ if (op->has_active_speed ()) - switch ((int) ((FABS (op->speed)) * 15)) + switch ((int)((fabs (op->speed)) * 15.)) { case 0: buf << "(very slow movement)"; @@ -956,11 +918,6 @@ * a dwarven axe, in which the full abilities are only known to * dwarves, etc. * - * 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. - * * 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) @@ -1215,6 +1172,9 @@ if (op->slaying && op->type != FOOD) buf.printf ("(slay %s)", &op->slaying); + if (op->type == SKILL_TOOL && op->skill) + buf.printf ("(%s)", &op->skill); + buf.add_abilities ("Attacks", op->attacktype); /* resistance on flesh is only visible for quetzals. If * non flesh, everyone can see its resistances @@ -1240,6 +1200,7 @@ examine (object *op, object *tmp) { std::string info = tmp->describe (op); + op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ()); }