--- deliantra/server/common/item.C 2010/01/30 23:30:26 1.69 +++ deliantra/server/common/item.C 2010/04/04 02:57:10 1.80 @@ -1,9 +1,9 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team - * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team - * Copyright (©) 1992,2007 Frank Tore Johansen + * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2002 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992 Frank Tore Johansen * * 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 @@ -49,6 +49,7 @@ * Basically, for the use/nonuse, the code does something like: * "This item goes %s\n", with the use/nonuse values filling in the %s */ +// see include/object.h Body_Locations body_locations[NUM_BODY_LOCATIONS] = { {KW_body_skill , "You can use it as your skill" , "It is used as a skill"}, {KW_body_combat , "You can wield it as your weapon" , "It is used as a combat weapon"}, @@ -563,6 +564,7 @@ * * It is used extensively within messages, so should return only a prose * and short description of the item. + * It is also used by examine/ex and similar functions. */ const char * query_name (const object *op) @@ -626,10 +628,10 @@ case WAND: case ROD: case HORN: - buf << (op->env && op->env->current_weapon == op ? " (readied)" : " (applied)"); + buf << " (applied)"; break; case WEAPON: - buf << (op->env && op->env->current_weapon == op ? " (wielded)" : " (applied)"); + buf << " (applied)"; break; case ARMOUR: case HELMET: @@ -688,6 +690,7 @@ * * It is sometimes used to display messages, and usually only used to match stuff, * so maybe this function should be removed. + * It is also used for client-side inventory/item descriptions. */ const char * query_base_name (const object *op, int plural) @@ -695,7 +698,8 @@ if ((!plural && !op->name) || (plural && !op->name_pl)) return "(null)"; - if (!op->nrof && !op->weight && !op->title && !is_magical (op)) + if (!op->nrof && !op->weight && !op->title && !is_magical (op) + && op->type != EXIT) return op->name; /* To speed things up (or make things slower?) */ static dynbuf_text buf; buf.clear (); @@ -741,6 +745,14 @@ } break; + case EXIT: + // random map exits "unfortunately" get patched, so this only works before entering + if (EXIT_PATH (op) == shstr_random_map_exit) + buf << " (random map)"; + else if (!EXIT_PATH (op)) + buf << " (closed)"; + break; + default: if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED))) buf.printf (" %+d", op->magic); @@ -938,28 +950,30 @@ i = (op->stats.maxsp % 1000) / 100; if (i) - buf.printf ("(capacity %d.%dk). It is ", op->stats.maxsp / 1000, i); + buf.printf ("(capacity %d.%dk; it is ", op->stats.maxsp / 1000, i); else - buf.printf ("(capacity %dk). It is ", op->stats.maxsp / 1000); + buf.printf ("(capacity %dk; it is ", op->stats.maxsp / 1000); } else - buf.printf ("(capacity %d). It is ", op->stats.maxsp); + buf.printf ("(capacity %d; it is ", op->stats.maxsp); i = (op->stats.sp * 10) / op->stats.maxsp; if (op->stats.sp == 0) - buf << "empty."; + buf << "empty"; else if (i == 0) - buf << "almost empty."; + buf << "almost empty"; else if (i < 3) - buf << "partially filled."; + buf << "partially filled"; else if (i < 6) - buf << "half full."; + buf << "half full"; else if (i < 9) - buf << "well charged."; + buf << "well charged"; else if (op->stats.sp == op->stats.maxsp) - buf << "fully charged."; + buf << "fully charged"; else - buf << "almost full."; + buf << "almost full"; + + buf << ')'; break; case LAMP: @@ -1171,6 +1185,178 @@ return std::string (::describe_item (this, who)); } +static void +describe_dump_object (dynbuf &buf, object *ob) +{ + char *txt = dump_object (ob); + for (char *p = txt; *p; ++p) if (*p == '\n') *p = '\r'; + buf << "\n" << txt << "\n"; + + if (!ob->is_arch ()) + describe_dump_object (buf, ob->arch); +} + +std::string +object::describe (object *who) +{ + dynbuf_text buf (1024, 1024); + + buf.printf ("That is: %s.\r", long_desc (who).c_str ()); + + if (custom_name) + buf.printf ("You call it %s.\r", &custom_name); + + switch (type) + { + case SPELLBOOK: + if (flag [FLAG_IDENTIFIED] && inv) + buf.printf ("%s is a level %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill); + break; + + case BOOK: + if (msg) + buf << "Something is written in it.\r"; + break; + + case CONTAINER: + if (race) + { + if (weight_limit && stats.Str < 100) + buf.printf ("It can hold only %s and its weight limit is %.1f kg.\r", + &race, weight_limit / (10.0 * (100 - stats.Str))); + else + buf.printf ("It can hold only %s.\r", &race); + } + else if (weight_limit && stats.Str < 100) + buf.printf ("Its weight limit is %.1f kg.\r", weight_limit / (10.0 * (100 - stats.Str))); + break; + + case WAND: + if (flag [FLAG_IDENTIFIED]) + buf.printf ("It has %d %s left.\r", stats.food, stats.food == 1 ? "charge" : "charges"); + break; + } + + if (material != MATERIAL_NULL && !msg) + buf << (nrof > 1 ? "They are made of " : "It is made of ") + << material->description + << ".\r"; + + if (who) + /* Where to wear this item */ + for (int i = 0; i < NUM_BODY_LOCATIONS; i++) + if (slot[i].info) + { + buf << (who->slot[i].info ? body_locations[i].use_name : body_locations[i].nonuse_name); + + if (slot[i].info < -1 && who->slot[i].info) + buf.printf ("(%d)", -slot[i].info); + + buf << ".\r"; + } + + if (weight) + buf.printf ("%s %3.3f kg.\r", nrof > 1 ? "They weigh" : "It weighs", weight * (nrof ? nrof : 1) / 1000.0); + + if (flag [FLAG_STARTEQUIP]) + buf << (nrof > 1 ? "They were" : "It was") + << " given by a god and will vanish when dropped.\r"; + + if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who) + { + buf.printf ("You reckon %s worth %s.\r", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX)); + + if (who->is_in_shop ()) + { + if (flag [FLAG_UNPAID]) + buf.printf ("%s would cost you %s.\r", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP)); + else + buf.printf ("You are offered %s for %s.\r", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it"); + } + } + + if (flag [FLAG_MONSTER]) + buf << describe_monster (who); + + /* Is this item buildable? */ + if (flag [FLAG_IS_BUILDABLE]) + buf << "This is a buildable item.\r"; + + /* Does the object have a message? Don't show message for all object + * types - especially if the first entry is a match + */ + if (msg) + { + if (type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ()) + { + buf << '\r'; + + /* This is just a hack so when identifying the items, we print + * out the extra message + */ + if (need_identify (this) && flag [FLAG_IDENTIFIED]) + buf << "The object has a story:\r"; + + buf << msg << '\n'; + } + } + else if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED] + && (type == SPELLBOOK || type == ROD || type == WAND + || type == ROD || type == POTION || type == SCROLL)) + // for spellbooks and other stuff that contains spells, print the spell message, + // unless the object has a custom message handled above. + buf << '\r' << inv->msg << '\n'; + + // try to display the duration for some potions and scrolls + // this includes change ability potions and group spells, + // but does not handle protection potions + if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED] + && (type == POTION || type == SCROLL)) + { + object *spell = inv; + + if (spell->subtype == SP_PARTY_SPELL) + spell = spell->other_arch; + + if (spell->subtype == SP_CHANGE_ABILITY) + buf.printf ("\nH", + TICK2TIME (change_ability_duration (spell, this))); + } + + // some help text for skill tools + if (type == SKILL_TOOL) + buf << "\nH"; + + // Display a hint about inscribable items [empty books] + // This includes the amount of text they can hold. + if (type == INSCRIBABLE) + { + if (other_arch && other_arch->type == SCROLL) + buf.printf ("\nH"); + else + buf.printf ("\nH", + weight_limit); + } + + buf << '\n'; + + // the dungeon master additionally gets a complete dump + if (who && who->flag [FLAG_WIZLOOK]) + { + buf << "\nT\n"; + describe_dump_object (buf, this); + + if (inv) + { + buf << "\nT\n"; + describe_dump_object (buf, inv); + } + } + + return std::string (buf.linearise (), buf.size ()); +} + void examine (object *op, object *tmp) { @@ -1191,7 +1377,7 @@ for (object *tmp = inv; tmp; tmp = tmp->below) if (who && QUERY_FLAG (who, FLAG_WIZ)) - buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, tmp->query_name (), tmp->count, tmp->query_weight ()); + buf.printf ("%s- %-28.28s %-8s (%9d) %s\n", indent, tmp->query_name (), tmp->query_weight (), tmp->count, tmp->uuid.c_str ()); else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) buf.printf ("%s- %-36.36s %-8s\n", indent, tmp->query_name (), tmp->query_weight ());